Re: Infinite Interval - Mailing list pgsql-hackers

From Ashutosh Bapat
Subject Re: Infinite Interval
Date
Msg-id CAExHW5uXrVPdh=2a=1y_jbcrjiiG_8MygieDQ_SAkw72pd2HyQ@mail.gmail.com
Whole thread Raw
In response to Re: Infinite Interval  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
Responses Re: Infinite Interval
Re: Infinite Interval
List pgsql-hackers
On Thu, Sep 21, 2023 at 7:21 PM Ashutosh Bapat
<ashutosh.bapat.oss@gmail.com> wrote:
>
> One thing I didn't understand though is the use of
> makeIntervalAggState() in interval_avg_deserialize(). In all other
> deserialization functions like numeric_avg_deserialize() we create the
> Agg State in CurrentMemoryContext but makeIntervalAggState() creates
> it in aggcontext. And it works. We could change the code to allocate
> agg state in aggcontext. Not a big change. But I did not find any
> explanation as to why we use CurrentMemoryContext in other places.
> Dean, do you have any idea?

Following code in ExecInterpExpr makes it clear that the
deserialization function is be executed in per tuple memory context.
Whereas the aggregate's context is different from this context and may
lives longer that the context in which deserialization is expected to
happen.

/* evaluate aggregate deserialization function (non-strict portion) */
EEO_CASE(EEOP_AGG_DESERIALIZE)
{
FunctionCallInfo fcinfo = op->d.agg_deserialize.fcinfo_data;
AggState *aggstate = castNode(AggState, state->parent);
MemoryContext oldContext;

/*
* We run the deserialization functions in per-input-tuple memory
* context.
*/
oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
fcinfo->isnull = false;
*op->resvalue = FunctionCallInvoke(fcinfo);
*op->resnull = fcinfo->isnull;
MemoryContextSwitchTo(oldContext);

Hence I have changed interval_avg_deserialize() in 0007 to use
CurrentMemoryContext instead of aggcontext. Rest of the patches are
same as previous set.

--
Best Wishes,
Ashutosh Bapat

Attachment

pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: pg_ctl start may return 0 even if the postmaster has been already started on Windows
Next
From: Dean Rasheed
Date:
Subject: Re: Infinite Interval