Re: What would AggrefExprState nodes' args contain?

From: Vaibhav Kaushal <vaibhavkaushal123(at)gmail(dot)com>
To: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: What would AggrefExprState nodes' args contain?
Date: 2011-04-29 09:52:07
Message-ID: BANLkTiki3qUZ0-G8oY=yRPN2hJeuKfD_Ow@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I tried all aggregates - min,max,sum,count and avg. all are working. What do
you suggest now?

On Fri, Apr 29, 2011 at 11:30 AM, Ashutosh Bapat <
ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:

>
>
> On Thu, Apr 28, 2011 at 4:21 PM, Vaibhav Kaushal <
> vaibhavkaushal123(at)gmail(dot)com> wrote:
>
>> Thanks a lot. I was browsing the code and was thinking this would be the
>> most probable scenario.
>>
>> But, the point is that even after removing the args initialization part in
>> the ExecInitExpr for AggrefState, the sum() function is working. I believe
>> that is also a aggregate function! If yes, then how is it working if I dd
>> not allow the args to be initialized. The debugger says that ExecEvalAggref
>> was called and the results returned are true.
>>
>>
> Did you check the same thing with avg, or any statistical aggregates. Sum
> does not need all the aggregate infrastructure in place, for example
> finalisation function. May be after removing initialization part you want to
> run regression (or at least aggregates.sql) to see what it breaks.
>
>
>> Regards,
>> Vaibhav
>>
>>
>> On Thu, Apr 28, 2011 at 2:38 PM, Ashutosh Bapat <
>> ashutosh(dot)bapat(at)enterprisedb(dot)com> wrote:
>>
>>> The args in AggrefExprState, are used in the functions ExecAgg,
>>> ExecInitAgg and their minions to evaluate the aggregates. The
>>> ExecEvalAggref() merely retrieves the results of aggregation calculated
>>> during ExecAgg.
>>>
>>>
>>> On Tue, Apr 26, 2011 at 12:04 PM, Vaibhav Kaushal <
>>> vaibhavkaushal123(at)gmail(dot)com> wrote:
>>>
>>>> Hello all,
>>>>
>>>> While examining the executor, I was wondering what the *args part of
>>>> AggrefExprState nodes contain. I found that the Aggref (Expr)'s args list
>>>> is a list of TargetEntry nodes. But the state node's args is initialized in
>>>> ExecInitExpr as:
>>>>
>>>> astate->args = (List *) ExecInitExpr((Expr *) aggref->args,
>>>> parent);
>>>>
>>>> This would mean that the args is actually a ExprState node list with one
>>>> single item (the ExprState node / tree). I believe it potentially contains
>>>> the execution tree to determine the state / value of the aggref
>>>> (sub)expression. But then in the ExecEvalAggref function I do not see the
>>>> args coming into picture at all! I am also unable to find a call to some
>>>> function for executing the state node created in the args list. Also, no
>>>> value is being extracted from that node! Why is it so?
>>>>
>>>> For quick reference I am adding the function (may be you don't need it
>>>> but still... its a small one):
>>>>
>>>> /* ----------------------------------------------------------------
>>>> * ExecEvalAggref
>>>> *
>>>> * Returns a Datum whose value is the value of the precomputed
>>>> * aggregate found in the given expression context.
>>>> * ----------------------------------------------------------------
>>>> */
>>>> static Datum
>>>> ExecEvalAggref(AggrefExprState *aggref, ExprContext *econtext,
>>>> bool *isNull, ExprDoneCond *isDone)
>>>> {
>>>> if (isDone)
>>>> *isDone = ExprSingleResult;
>>>>
>>>> if (econtext->ecxt_aggvalues == NULL) /* safety check */
>>>> elog(ERROR, "no aggregates in this expression context");
>>>>
>>>> *isNull = econtext->ecxt_aggnulls[aggref->aggno];
>>>> return econtext->ecxt_aggvalues[aggref->aggno];
>>>> }
>>>>
>>>>
>>>> What is the use of args in AggrefExprState node here? Is it there just
>>>> for some historical reason?
>>>>
>>>> Regards,
>>>> Vaibhav
>>>>
>>>
>>>
>>>
>>> --
>>> Best Wishes,
>>> Ashutosh Bapat
>>> EntepriseDB Corporation
>>> The Enterprise Postgres Company
>>>
>>>
>>
>
>
> --
> Best Wishes,
> Ashutosh Bapat
> EntepriseDB Corporation
> The Enterprise Postgres Company
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2011-04-29 10:01:05 Re: What would AggrefExprState nodes' args contain?
Previous Message Joel Jacobson 2011-04-29 08:22:53 Re: SQLERRD and dump of variables