X-Original-To: pgsql-hackers@postgresql.org Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 3A3CC474E5C; Thu, 13 Mar 2003 12:03:02 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.8/8.12.8) with ESMTP id h2DH2tub006956; Thu, 13 Mar 2003 12:02:56 -0500 (EST) To: Manfred Koizar Cc: Franco Bruno Borghesi , pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: [SQL] What's wrong with this group by clause? In-reply-to: References: <200311041828.13144.franco@akyasociados.com.ar> Comments: In-reply-to Manfred Koizar message dated "Thu, 13 Mar 2003 16:16:29 +0100" Date: Thu, 13 Mar 2003 12:02:55 -0500 Message-ID: <6955.1047574975@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200303/548 X-Sequence-Number: 36794 Manfred Koizar writes: > ISTM you have found a Postgres 7.3 bug. Yeah. Actually, the planner bug has been there a long time, but it was only latent until the parser stopped suppressing duplicate GROUP BY items: 2002-08-18 14:46 tgl * src/backend/parser/parse_clause.c: Remove optimization whereby parser would make only one sort-list entry when two equal() targetlist items were to be added to an ORDER BY or DISTINCT list. Although indeed this would make sorting fractionally faster by sometimes saving a comparison, it confuses the heck out of later stages of processing, because it makes it look like the user wrote DISTINCT ON rather than DISTINCT. Bug reported by joe@piscitella.com. 7.3 patch is attached if you need it. regards, tom lane *** src/backend/optimizer/plan/planner.c.orig Wed Mar 5 13:38:26 2003 --- src/backend/optimizer/plan/planner.c Thu Mar 13 11:21:16 2003 *************** *** 1498,1510 **** * are just dummies with no extra execution cost.) */ List *sort_tlist = new_unsorted_tlist(subplan->targetlist); int keyno = 0; List *gl; foreach(gl, groupClause) { GroupClause *grpcl = (GroupClause *) lfirst(gl); ! TargetEntry *te = nth(grpColIdx[keyno] - 1, sort_tlist); Resdom *resdom = te->resdom; /* --- 1498,1511 ---- * are just dummies with no extra execution cost.) */ List *sort_tlist = new_unsorted_tlist(subplan->targetlist); + int grpno = 0; int keyno = 0; List *gl; foreach(gl, groupClause) { GroupClause *grpcl = (GroupClause *) lfirst(gl); ! TargetEntry *te = nth(grpColIdx[grpno] - 1, sort_tlist); Resdom *resdom = te->resdom; /* *************** *** 1518,1523 **** --- 1519,1525 ---- resdom->reskey = ++keyno; resdom->reskeyop = grpcl->sortop; } + grpno++; } Assert(keyno > 0);