RE: [HACKERS] SPI_prepare() doesn't work well ? - Mailing list pgsql-hackers

From Hiroshi Inoue
Subject RE: [HACKERS] SPI_prepare() doesn't work well ?
Date
Msg-id 001201be45d1$d2362dc0$2801007e@cadzone.tpf.co.jp
Whole thread Raw
In response to Re: [HACKERS] SPI_prepare() doesn't work well ?  (Bruce Momjian <maillist@candle.pha.pa.us>)
List pgsql-hackers

> -----Original Message-----
> From: Bruce Momjian [mailto:maillist@candle.pha.pa.us]
> Sent: Friday, January 22, 1999 1:38 PM
> To: Hiroshi Inoue
> Cc: jwieck@debis.com; pgsql-hackers@postgreSQL.org
> Subject: Re: [HACKERS] SPI_prepare() doesn't work well ?
>
>
[snip]

> > > >
> > > > 2. Aggregates in PL/pgSQL cause wrong results.
> > > >
[snip]

>
> It is my understanding that this has always been a problem.  I have
> never 100% been confident I understand it.
>
> As I remember, there used to be a:
>
>    Aggreg  **qry_agg
>
> that was a member of the Query structure, and cause all sorts of
> problems because the Agg was in the target list _and_ in the qry_agg.
> That was removed.  Looks like I did it, but I don't remember doing it:
>
>     revision 1.44
>     date: 1998/01/15 19:00:11;  author: momjian;  state: Exp;
> lines: +2 -4
>     Remove Query->qry_aggs and qry_numaggs and replace with
> Query->hasAggs.
>
>     Pass List* of Aggregs into executor, and create needed array there.
>     No longer need to double-processs Aggregs with second copy in Query.
>
> The removal of that fixed many problems.  Can you explain a little more
> on how multiple Agg references happen.  Perhaps we can get a good clean
> fix for this.  Maybe redesign is needed, as I did for the removal of
> qry_aggs.
>

Sorry,I don't know details.
The source tree I can trace is as follows..

1.Multiple references to Aggreg nodes  [ Fucntion union_planner() in src/backend/optimizer/plan/planner.c ]
       if (parse->hasAggs)       {               result_plan = (Plan *) make_agg(tlist, result_plan);
               /*                * set the varno/attno entries to the appropriate references
to                * the result tuple of the subplans.                */               ((Agg *) result_plan)->aggs =
                 set_agg_tlist_references((Agg *) result_plan);
 

  [ Function set_agg_tlist_references() in optimzer/opt/setrefs.c ]
               aggreg_list = nconc(                 replace_agg_clause(tle->expr, subplanTargetList),
aggreg_list)
;       }       return aggreg_list;

 [ Function replace_agg_clause() in optimizer/opt/setrefs.c ]
       else if (IsA(clause, Aggreg))       {               return lcons(clause,              ^^^^^^^
    replace_agg_clause(((Aggreg *) clause)->target,
 
subplanTargetList));

 clause is contained in the return of replace_agg_clause() and so contained in the return of
set_agg_tlist_references().

2.aggno's of aggs list members are set  [ Function ExecAgg() in executor/nodeAgg.c ]
               alist = node->aggs;               for (i = 0; i < nagg; i++)               {
aggregates[i]= lfirst(alist);                       aggregates[i]->aggno = i;                       alist =
lnext(alist);              }
 

3.aggno's are used  [ Function ExecEvalAggreg() in executor/execQual.c    called from ExecEvalExpr() ]

static Datum
ExecEvalAggreg(Aggreg *agg, ExprContext *econtext, bool *isNull)
{       *isNull = econtext->ecxt_nulls[agg->aggno];       return econtext->ecxt_values[agg->aggno];
}


Thanks.

Hiroshi Inoue
Inoue@tpf.co.jp



pgsql-hackers by date:

Previous
From: "Thomas G. Lockhart"
Date:
Subject: [Fwd: AWL: Re: Another unrecognized SQL clause in MySQL "WHERE CURRENT OF"]
Next
From: "Thomas G. Lockhart"
Date:
Subject: New CVSup static binaries for Linux