Thread: pgsql: Have the planner consider Incremental Sort for DISTINCT
Have the planner consider Incremental Sort for DISTINCT Prior to this, we only considered a full sort on the cheapest input path and uniquifying any path which was already sorted in the required sort order. Here we adjust create_final_distinct_paths() so that it also adds an Incremental Sort path on any path which has presorted keys. Additionally, this adjusts the parallel distinct code so that we now consider sorting the cheapest partial path and incrementally sorting any partial paths with presorted keys. Previously we didn't consider any sorting for parallel distinct and only added a unique path atop any path which had the required pathkeys already. Author: David Rowley Reviewed-by: Richard Guo Discussion: https://postgr.es/m/CAApHDvo8Lz2H=42urBbfP65LTcEUOh288MT7DsG2_EWtW1AXHQ@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/3c6fc58209f24b959ee18f5d19ef96403d08f15c Modified Files -------------- src/backend/optimizer/plan/planner.c | 222 ++++++++++++++----------- src/test/regress/expected/incremental_sort.out | 13 +- src/test/regress/expected/select_distinct.out | 31 +++- src/test/regress/expected/window.out | 10 +- src/test/regress/sql/select_distinct.sql | 8 + 5 files changed, 173 insertions(+), 111 deletions(-)