]> granicus.if.org Git - postgresql/commit
Improve SELECT DISTINCT to consider hash aggregation, as well as sort/uniq,
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 5 Aug 2008 02:43:18 +0000 (02:43 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 5 Aug 2008 02:43:18 +0000 (02:43 +0000)
commitbe3b265c94443b75262e89149f148ace0fdf75da
tree198e00992b5716d917d3f900a98f742e1d8228b5
parent4abd7b49f1e9eb1ccc934be5efabb6fd531d0141
Improve SELECT DISTINCT to consider hash aggregation, as well as sort/uniq,
as methods for implementing the DISTINCT step.  This eliminates the former
performance gap between DISTINCT and GROUP BY, and also makes it possible
to do SELECT DISTINCT on datatypes that only support hashing not sorting.

SELECT DISTINCT ON is still always implemented by sorting; it would take
executor changes to support hashing that, and it's not clear it's worth
the trouble.

This is a release-note-worthy incompatibility from previous PG versions,
since SELECT DISTINCT can no longer be counted on to deliver sorted output
without explicitly saying ORDER BY.  (Anyone who can't cope with that
can consider turning off enable_hashagg.)

Several regression test queries needed to have ORDER BY added to preserve
stable output order.  I fixed the ones that manifested here, but there
might be some other cases that show up on other platforms.
13 files changed:
src/backend/nodes/outfuncs.c
src/backend/optimizer/plan/planmain.c
src/backend/optimizer/plan/planner.c
src/backend/parser/parse_clause.c
src/include/nodes/relation.h
src/test/regress/expected/numerology.out
src/test/regress/expected/opr_sanity.out
src/test/regress/expected/select_distinct.out
src/test/regress/input/misc.source
src/test/regress/output/misc.source
src/test/regress/sql/numerology.sql
src/test/regress/sql/opr_sanity.sql
src/test/regress/sql/select_distinct.sql