Re: [HACKERS] What's wrong with this group by clause?

From: Franco Bruno Borghesi <franco(at)akyasociados(dot)com(dot)ar>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Manfred Koizar <mkoi-pg(at)aon(dot)at>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] What's wrong with this group by clause?
Date: 2003-11-06 17:52:00
Message-ID: 200311061452.00854.franco@akyasociados.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

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 <mkoi-pg(at)aon(dot)at> 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(at)piscitella(dot)com(dot)
>
> 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);

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Carlos 2003-11-06 17:52:58 Install files for version 7.4
Previous Message Dave Page 2003-11-06 17:39:52 Re: [HACKERS] Changes to Contributor List

Browse pgsql-sql by date

  From Date Subject
Next Message sTesting 2003-11-06 22:43:17 Now() in a function
Previous Message Cris Carampa 2003-11-06 09:24:56 transaction management in plpgsql functions