Re: DISTINCT is not quite distinct - Mailing list pgsql-general

From Tom Lane
Subject Re: DISTINCT is not quite distinct
Date
Msg-id 10738.1162824123@sss.pgh.pa.us
Whole thread Raw
In response to DISTINCT is not quite distinct  (Florian Weimer <fweimer@bfk.de>)
Responses Re: DISTINCT is not quite distinct  (Florian Weimer <fweimer@bfk.de>)
List pgsql-general
Florian Weimer <fweimer@bfk.de> writes:
> I run this innocent query
> CREATE TABLE foo AS SELECT DISTINCT bar FROM baz ORDER BY bar;
> and the resulting table contains duplicate rows. 8-(

> According to EXPLAIN, an index scan on the bar column is used (using
> the underlying B-tree index).

Do you mean an indexscan followed immediately by a Unique node?  If
so, yeah, that would depend entirely on correct ordering of the
indexscan output to produce distinct results.

> If I drop the DISTINCT, the output is not correctly ordered, either.
> Perhaps this is an index corruption issue?  The hardware itself seems
> fine.

Perhaps.  Do you want to save off a physical copy of the index and then
try REINDEXing?  If that fixes it, I'd be interested to compare the two
versions of the index.

            regards, tom lane

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: first steps in PhP and PostgreSQL
Next
From: Richard Broersma Jr
Date:
Subject: Re: select result / functions from another database in plpgsql