Commit 6c4996fa authored by Tom Lane's avatar Tom Lane

GROUP BY got confused if there were multiple equal() GROUP BY items.

This bug has been latent since 7.0 or maybe even further back, but it
was only exposed when parse_clause.c stopped suppressing duplicate
items (see its rev 1.96 of 18-Aug-02).
parent 706a32cd
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.151 2003/03/10 03:53:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.152 2003/03/13 16:58:35 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1489,13 +1489,14 @@ make_groupsortplan(Query *parse, ...@@ -1489,13 +1489,14 @@ make_groupsortplan(Query *parse,
Plan *subplan) Plan *subplan)
{ {
List *sort_tlist = new_unsorted_tlist(subplan->targetlist); List *sort_tlist = new_unsorted_tlist(subplan->targetlist);
int grpno = 0;
int keyno = 0; int keyno = 0;
List *gl; List *gl;
foreach(gl, groupClause) foreach(gl, groupClause)
{ {
GroupClause *grpcl = (GroupClause *) lfirst(gl); GroupClause *grpcl = (GroupClause *) lfirst(gl);
TargetEntry *te = nth(grpColIdx[keyno] - 1, sort_tlist); TargetEntry *te = nth(grpColIdx[grpno] - 1, sort_tlist);
Resdom *resdom = te->resdom; Resdom *resdom = te->resdom;
/* /*
...@@ -1509,6 +1510,7 @@ make_groupsortplan(Query *parse, ...@@ -1509,6 +1510,7 @@ make_groupsortplan(Query *parse,
resdom->reskey = ++keyno; resdom->reskey = ++keyno;
resdom->reskeyop = grpcl->sortop; resdom->reskeyop = grpcl->sortop;
} }
grpno++;
} }
Assert(keyno > 0); Assert(keyno > 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment