mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
When we have successfully optimized a MIN or MAX aggregate into an indexscan,
the query result must be exactly one row (since we don't do this when there's any GROUP BY). Therefore any ORDER BY or DISTINCT attached to the query is useless and can be dropped. Aside from saving useless cycles, this protects us against problems with matching the hacked-up tlist entries to sort clauses, as seen in a bug report from Taiki Yamaguchi. We might need to work harder if we ever try to optimize grouped queries with this approach, but this solution will do for now.
This commit is contained in:
parent
39627b1ae6
commit
ff72280c9e
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.227 2008/03/18 22:04:14 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.228 2008/03/27 19:06:14 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -950,6 +950,17 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
|
||||
* right tlist, and it has no sort order.
|
||||
*/
|
||||
current_pathkeys = NIL;
|
||||
/*
|
||||
* In fact, since we don't optimize grouped aggregates, it
|
||||
* needs no sort order --- there must be exactly one output row,
|
||||
* and so any ORDER BY or DISTINCT attached to the query is
|
||||
* useless and can be dropped. Aside from saving useless cycles,
|
||||
* this protects us against problems with matching the hacked-up
|
||||
* tlist entries to sort clauses.
|
||||
*/
|
||||
Assert(!parse->groupClause);
|
||||
parse->sortClause = NULL;
|
||||
parse->distinctClause = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user