Allow DISTINCT to use Incremental Sort
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2023-01-07T09:46:43Z
Lists: pgsql-hackers
Attachments
- incremental_sort_for_distinct.patch (text/plain) patch
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
Commits
-
Have the planner consider Incremental Sort for DISTINCT
- 3c6fc58209f2 16.0 landed