aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-03-27 19:06:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-03-27 19:06:23 +0000
commit707867e9fd9693f22034f3e71cc6efe3e90f1244 (patch)
tree28045f99d4f7d981fba67a4c554fb2eabfc0ed16 /src
parent1c0e618e174871676c7fa129034b2a0942b608b7 (diff)
downloadpostgresql-707867e9fd9693f22034f3e71cc6efe3e90f1244.tar.gz
postgresql-707867e9fd9693f22034f3e71cc6efe3e90f1244.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/plan/planner.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 0103ea826ca..6d6078c1380 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.226 2008/01/01 19:45:50 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.226.2.1 2008/03/27 19:06:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -943,6 +943,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
{