Allow DISTINCT to use Incremental Sort - Mailing list pgsql-hackers

From David Rowley
Subject Allow DISTINCT to use Incremental Sort
Date
Msg-id CAApHDvo8Lz2H=42urBbfP65LTcEUOh288MT7DsG2_EWtW1AXHQ@mail.gmail.com
Whole thread Raw
Responses Re: Allow DISTINCT to use Incremental Sort
List pgsql-hackers
While working on the regression tests added in a14a58329, I noticed
that DISTINCT does not make use of Incremental Sort.  It'll only ever
do full sorts on the cheapest input path or make use of a path that's
already got the required pathkeys.  Also, I see that
create_final_distinct_paths() is a little quirky and if the cheapest
input path happens to be sorted, it'll add_path() the same path twice,
which seems like a bit of a waste of effort. That could happen if say
enable_seqscan is off or if a Merge Join is the cheapest join method.

Additionally, the parallel DISTINCT code looks like it should also get
the same treatment.  I see that I'd coded this to only add a unique
path atop of a presorted path and it never considers sorting the
cheapest partial path.  I've adjusted that in the attached and also
made it consider incremental sorting any path with presorted keys.

Please see the attached patch.

David

Attachment

pgsql-hackers by date:

Previous
From: Esteban Zimanyi
Date:
Subject: How to define template types in PostgreSQL
Next
From: Amit Kapila
Date:
Subject: Re: Notify downstream to discard the streamed transaction which was aborted due to crash.