Re: BUG #3979: SELECT DISTINCT slow even on indexed column

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: David Lee <david_lee(at)bigfix(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3979: SELECT DISTINCT slow even on indexed column
Date: 2008-02-25 10:19:07
Message-ID: 1203934747.4252.10.camel@ebony.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, 2008-02-21 at 23:34 +0000, David Lee wrote:

> I ran EXPLAIN and it showed that the path did not use the index, so I ran:

Your expectation that this would use an index is unfortunately not
correct.

We need to check visibility on the table rows to do the query. We choose
to do this by doing a sort and then a unique operation. That's the most
efficient plan when there are potentially many unique values.

In the case you mention it would be faster for us to skip through the
index retrieving at most one row from each value in the index. We don't
currently do that, but we could. However that plan would be restricted
only to queries of the form
SELECT DISTINCT column-list-of-index FROM table;

so its probably not going to be optimised anytime soon.

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message chandra 2008-02-25 11:53:46 BUG #3987: Not checking the password
Previous Message Yann 2008-02-25 00:36:07 BUG #3986: Error ts_vector with UTF8 WS2003