X-Original-To: pgsql-sql@postgresql.org Received: from lucifer.oficina (unknown [200.69.203.237]) by postgresql.org (Postfix) with ESMTP id 0D3D54763A3; Fri, 14 Mar 2003 12:50:38 -0500 (EST) Received: from taz.oficina (taz.oficina [192.168.1.177]) (authenticated bits=0) by lucifer.oficina (8.12.8/8.12.8) with ESMTP id h2EHq1d4048653; Fri, 14 Mar 2003 14:52:01 -0300 (ART) (envelope-from franco@akyasociados.com.ar) From: Franco Bruno Borghesi Organization: AK y Asociados S.R.L. To: Tom Lane , Manfred Koizar Subject: Re: [HACKERS] What's wrong with this group by clause? Date: Thu, 6 Nov 2003 14:52:00 -0300 User-Agent: KMail/1.5 Cc: pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org References: <200311041828.13144.franco@akyasociados.com.ar> <6955.1047574975@sss.pgh.pa.us> In-Reply-To: <6955.1047574975@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Boundary-02=_Apoq/Ot5qsvRxt6"; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200311061452.00854.franco@akyasociados.com.ar> X-Archive-Number: 200303/369 X-Sequence-Number: 12408 --Boundary-02=_Apoq/Ot5qsvRxt6 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Description: signed data Content-Disposition: inline Thanks Tom, I applied the patch and it works perfect now. Thanks to you all. On Thursday 13 March 2003 14:02, Tom Lane wrote: > 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); --Boundary-02=_Apoq/Ot5qsvRxt6 Content-Type: application/pgp-signature Content-Description: signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQA/qopAz/PwDAvtu7oRAhvLAJsFK86NHsAAJQCdNtPJBWnebrgJtwCfcNjT 1bXJpiDTmF5YsgG0B8Ny7G4= =J/CF -----END PGP SIGNATURE----- --Boundary-02=_Apoq/Ot5qsvRxt6--