pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joseph Shraibman <jks@selectacast.net>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: index question
Date: Thu, 18 Oct 2001 21:39:30 -0400
Message-ID: <9109.1003455570@sss.pgh.pa.us> (raw)
In-Reply-To: <3BCF7308.4060302@selectacast.net>
References: <3BCF7308.4060302@selectacast.net>

Joseph Shraibman <jks@selectacast.net> writes:
> Lets say I have a table with columns a and b.  I want to do a query like
> SELECT count(distinct b) WHERE a = 2;

> Should I have an index on a or an index on (a,b)?

At present, only an index on a will help any.  Our implementation of
count(distinct ...) isn't bright enough to make use of indexes.

Now an index on (a,b) can substitute for an index on a, so if you
have other queries that could use both columns of the (a,b) index
then it might be worth making that instead of an index on a.

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <9109.1003455570@sss.pgh.pa.us>
Permalink:  ../9109.1003455570@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9109.1003455570@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jks@selectacast.net
  Subject: Re: index question
  In-Reply-To: <9109.1003455570@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox