Re: [HACKERS] More on GROUP BY - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] More on GROUP BY
Date
Msg-id 199905111801.OAA20529@candle.pha.pa.us
Whole thread Raw
In response to More on GROUP BY  (jwieck@debis.com (Jan Wieck))
List 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@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] problem compiling 6.5 cvs (Linux, gcc 2.7.2, egcs 1.12)
Next
From: Brian P Millett
Date:
Subject: Re: [HACKERS] Re: SIGBUS in AllocSetAlloc & jdbc