Re: BUG #3979: SELECT DISTINCT slow even on indexed column - Mailing list pgsql-bugs

From Simon Riggs
Subject Re: BUG #3979: SELECT DISTINCT slow even on indexed column
Date
Msg-id 1203934747.4252.10.camel@ebony.site
Whole thread Raw
In response to BUG #3979: SELECT DISTINCT slow even on indexed column  ("David Lee" <david_lee@bigfix.com>)
List 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

pgsql-bugs by date:

Previous
From: "Yann"
Date:
Subject: BUG #3986: Error ts_vector with UTF8 WS2003
Next
From: "chandra"
Date:
Subject: BUG #3987: Not checking the password