diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-08-05 02:43:18 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-08-05 02:43:18 +0000 |
commit | be3b265c94443b75262e89149f148ace0fdf75da (patch) | |
tree | 198e00992b5716d917d3f900a98f742e1d8228b5 /src/backend/parser/parse_clause.c | |
parent | 4abd7b49f1e9eb1ccc934be5efabb6fd531d0141 (diff) | |
download | postgresql-be3b265c94443b75262e89149f148ace0fdf75da.tar.gz postgresql-be3b265c94443b75262e89149f148ace0fdf75da.zip |
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.
Diffstat (limited to 'src/backend/parser/parse_clause.c')
-rw-r--r-- | src/backend/parser/parse_clause.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 76e59c82d6e..2b04ee5e337 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.173 2008/08/03 19:10:52 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.174 2008/08/05 02:43:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1447,9 +1447,6 @@ transformDistinctClause(ParseState *pstate, /* * Now add any remaining non-resjunk tlist items, using default * sort/group semantics for their data types. - * - * XXX for now, the planner requires distinctClause to be sortable, - * so we have to insist on that here. */ foreach(tlitem, *targetlist) { @@ -1459,8 +1456,7 @@ transformDistinctClause(ParseState *pstate, continue; /* ignore junk */ result = addTargetToGroupList(pstate, tle, result, *targetlist, - true, /* XXX for now */ - true); + false, true); } return result; @@ -1555,8 +1551,7 @@ transformDistinctOnClause(ParseState *pstate, List *distinctlist, errmsg("SELECT DISTINCT ON expressions must match initial ORDER BY expressions"))); result = addTargetToGroupList(pstate, tle, result, *targetlist, - true, /* someday allow hash-only? */ - true); + false, true); } return result; |