Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f9J1dZP01060 for ; Thu, 18 Oct 2001 21:39:35 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f9J1dVc09112; Thu, 18 Oct 2001 21:39:31 -0400 (EDT) To: Joseph Shraibman cc: pgsql-sql Subject: Re: index question In-reply-to: <3BCF7308.4060302@selectacast.net> References: <3BCF7308.4060302@selectacast.net> Comments: In-reply-to Joseph Shraibman message dated "Thu, 18 Oct 2001 20:25:44 -0400" Date: Thu, 18 Oct 2001 21:39:30 -0400 Message-ID: <9109.1003455570@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200110/267 X-Sequence-Number: 5221 Joseph Shraibman 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