Re: [HACKERS] More on GROUP BY

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: Jan Wieck <jwieck(at)debis(dot)com>
Cc: PostgreSQL HACKERS <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] More on GROUP BY
Date: 1999-05-11 18:01:31
Message-ID: 199905111801.OAA20529@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> While looking at all these parsetrees I wonder why the hell
> the GroupClause contains a complete copy of the TLE at all?
> The planner depends on finding a corresponding entry in the
> targetlist which should contain the same expression. At least
> it needs an equal junk TLE. For the query
>
> SELECT a, b FROM t1 GROUP BY b + 1;
>
> the parser in fact creates 3 TLE's where the last one is a
> junk result named "resjunk" for the "b + 1" expression and
> the GroupClause contains a totally equal TLE.
>
> Could someone explain that please?
>
> Wouldn't it be better to have another field (resgroupno e.g.)
> in the resdom which the GroupClause can reference? Then
> changing the resno's or even replacing the entire expression
> wouldn't hurt because make_subplanTargetList() could match
> them this way and the expressions for the subplans can be
> pulled out directly from the targetlist. And it would save
> processing the group clauses in the rewriting because they
> cannot contain Var nodes anymore and the entire list can be
> ignored.

I think I can comment on this. Aggregates had the similar problem. It
was so long ago, I don't remember the solution, but it was a pain to
keep the aggs up-to-date with the target list and varno changes. If you
think a redesign will fix the problem, go ahead.

I think the old problem may have been that the old Aggreg's kept
pointers to matching target list entries, so there was the aggregate in
the target list, and another separate list of aggregates in the Query
structure. I think I removed the second copy, and just generated it in
the executor, where it was needed.

Please see parser/parse_agg.c for a description of how count(*) is
handled differently than other aggregates.

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Brian P Millett 1999-05-11 18:03:11 Re: [HACKERS] Re: SIGBUS in AllocSetAlloc & jdbc
Previous Message Tom Lane 1999-05-11 17:53:34 Re: [HACKERS] problem compiling 6.5 cvs (Linux, gcc 2.7.2, egcs 1.12)