Re: Infinite Interval
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
To: jian he <jian.universality@gmail.com>,
Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Joseph Koshakow <koshy44@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, "Gregory Stark (as CFM)" <stark.cfm@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-09-22T07:48:51Z
Lists: pgsql-hackers
Attachments
- 0005-Support-infinite-interval-values-in-sum-and-20230922.patch (text/x-patch) patch 0005
- 0004-Introduce-infinity-interval-specification-i-20230922.patch (text/x-patch) patch 0004
- 0006-Use-integer-overflow-checking-routines-to-a-20230922.patch (text/x-patch) patch 0006
- 0003-Add-infinite-interval-values-20230922.patch (text/x-patch) patch 0003
- 0007-Implement-serialization-functions-for-inter-20230922.patch (text/x-patch) patch 0007
- 0001-Move-integer-helper-function-to-int.h-20230922.patch (text/x-patch) patch 0001
- 0002-Check-for-overflow-in-make_interval-20230922.patch (text/x-patch) patch 0002
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
Commits
-
Support +/- infinity in the interval data type.
- 519fc1bd9e9d 17.0 landed
-
Avoid integer overflow hazard in interval_time().
- 3850d4dec1d9 17.0 landed
-
Guard against overflow in make_interval().
- b2d55447a563 17.0 landed
-
Fix minmax-multi on infinite date/timestamp values
- 8da86d62a112 17.0 cited
-
Optimize various aggregate deserialization functions, take 2
- 0c882a298881 17.0 cited
-
Remove dead code in DecodeInterval()
- d6d1430f4043 17.0 cited
-
Accept "+infinity" in date and timestamp[tz] input.
- 2ceea5adb026 16.0 cited
-
Fix overflow hazards in interval input and output conversions.
- e39f99046710 15.0 cited