Re: Infinite Interval
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>,
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-16T00:00:00Z
Lists: pgsql-hackers
Attachments
- v20-0005-doc-for-special-interval-value.patch (text/x-patch) patch v20-0005
- v20-0004-Revert-Remove-dead-code-in-DecodeInterval.patch (text/x-patch) patch v20-0004
- v20-0002-Check-for-overflow-in-make_interval.patch (text/x-patch) patch v20-0002
- v20-0003-Add-infinite-interval-values.patch (text/x-patch) patch v20-0003
- v20-0001-Move-integer-helper-function-to-int.h.patch (text/x-patch) patch v20-0001
- v20-0006-refactor-avg-interval-sum-interval-aggregate.patch (text/x-patch) patch v20-0006
hi.
fixed the doc special value inf/-inf reference. didn't fix the EXTRACT
function doc issue.
I refactor the avg(interval), sum(interval), so moving aggregate,
plain aggregate both work with +inf/-inf.
no performance degradation, in fact, some performance gains.
--setup for test performance.
create unlogged table interval_aggtest AS
select g::int as a
,make_interval(years => g % 100, days => g % 100, hours => g %
200 , secs => random()::numeric(3,2) *100 ) as b
from generate_series(1, 100_000) g;
--use foreign data wrapper to copy exact content to interval_aggtest_no_patch
create unlogged table interval_aggtest_no_patch AS
select * from interval_aggtest;
--queryA
explain (analyze, costs off, buffers)
SELECT a, avg(b) OVER(ROWS BETWEEN 1 preceding AND 2 FOLLOWING)
from interval_aggtest \watch i=0.1 c=10
--queryB
explain (analyze, costs off, buffers)
SELECT a, avg(b) OVER(ROWS BETWEEN 1 preceding AND 2 FOLLOWING)
from interval_aggtest_no_patch \watch i=0.1 c=10
--queryC
explain (analyze, costs off, buffers)
SELECT a, sum(b) OVER(ROWS BETWEEN 1 preceding AND 2 FOLLOWING)
from interval_aggtest \watch i=0.1 c=10
--queryD
explain (analyze, costs off, buffers)
SELECT a, sum(b) OVER(ROWS BETWEEN 1 preceding AND 2 FOLLOWING)
from interval_aggtest_no_patch \watch i=0.1 c=10
--queryE
explain (analyze, costs off, buffers)
SELECT sum(b), avg(b)
from interval_aggtest \watch i=0.1 c=10
--queryF
explain (analyze, costs off, buffers)
SELECT sum(b), avg(b)
from interval_aggtest_no_patch \watch i=0.1 c=10
queryA execute 10 time, last executed time(ms) 748.258
queryB execute 10 time, last executed time(ms) 1059.750
queryC execute 10 time, last executed time(ms) 697.887
queryD execute 10 time, last executed time(ms) 708.462
queryE execute 10 time, last executed time(ms) 156.237
queryF execute 10 time, last executed time(ms) 405.451
---------------------------------------------------------------------
The result seems right, I am not %100 sure the code it's correct.
That's the best I can think of. You can work based on that.
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