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)
commitbf069f4b0e1203903e9f1fa9e3585c155394e849
tree7fd250f691a8b588123f98a2e439f0890ab27845
parenta29372de346c337fa8beacf6fe54cfe4d96f871d
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