time_bucket_ng() bugfix

time_bucket_ng() may return wrong results for monthly buckets with overwritten
origin. As an example:

time_bucket_ng('1 month', '2001-01-01' :: date, origin => '2000-06-01')

... returns 2000-01-01 instead of 2001-01-01. In fact, our tests showed this
but we overlooked the fact that the results are incorrect. The reason is that
the month of the origin is not accounted for when calculating the resulting
year.

This patch fixes this.

Also it updates linux-32bit-build-and-test.yaml workflow due to todays
14.2/13.6/12.10 releases. "Memoize" test doesn't pass on 14.2 thus the patch
adds it to the list of skipped tests. The patch doesn't rename the checks
because we list "PG14.1 Debug linux-i386" etc as required checks on GitHub.
This will be addressed in the follow-up patches.
This commit is contained in:
Aleksander Alekseev 2022-02-11 00:21:25 +03:00 committed by Aleksander Alekseev
parent d3d0b8d943
commit ee9b9ad318
3 changed files with 9 additions and 9 deletions

View File

@ -29,7 +29,7 @@ jobs:
ignores: append-13 debug_notice transparent_decompression-13 transparent_decompress_chunk-13 pg_dump
pg_major: 13
- pg: "14.1"
ignores: append-14 debug_notice transparent_decompression-14 transparent_decompress_chunk-14 pg_dump
ignores: append-14 debug_notice transparent_decompression-14 transparent_decompress_chunk-14 pg_dump memoize
pg_major: 14
steps:

View File

@ -438,7 +438,7 @@ ts_time_bucket_ng_date(PG_FUNCTION_ARGS)
delta = (year * 12 + month) - (origin_year * 12 + origin_month);
bucket_number = delta / interval->month;
year = origin_year + (bucket_number * interval->month) / 12;
year = origin_year + (origin_month - 1 + bucket_number * interval->month) / 12;
month =
(((origin_year * 12 + (origin_month - 1)) + (bucket_number * interval->month)) % 12) +
1;

View File

@ -1630,13 +1630,13 @@ FROM generate_series('2020-01-01' :: date, '2020-12-01', '1 month') AS ts,
unnest(array[ts :: date]) AS d;
d | m1 | m2 | m3 | m4 | m5
------------+------------+------------+------------+------------+------------
2020-01-01 | 2019-01-01 | 2019-01-01 | 2019-11-01 | 2019-01-01 | 2019-10-01
2020-02-01 | 2019-02-01 | 2019-01-01 | 2019-02-01 | 2019-01-01 | 2019-10-01
2020-03-01 | 2019-03-01 | 2019-03-01 | 2019-02-01 | 2019-01-01 | 2019-03-01
2020-04-01 | 2019-04-01 | 2019-03-01 | 2019-02-01 | 2019-01-01 | 2019-03-01
2020-05-01 | 2020-05-01 | 2020-05-01 | 2020-05-01 | 2020-05-01 | 2019-03-01
2020-06-01 | 2020-06-01 | 2020-05-01 | 2020-05-01 | 2020-05-01 | 2019-03-01
2020-07-01 | 2020-07-01 | 2020-07-01 | 2020-05-01 | 2020-05-01 | 2019-03-01
2020-01-01 | 2020-01-01 | 2020-01-01 | 2019-11-01 | 2020-01-01 | 2019-10-01
2020-02-01 | 2020-02-01 | 2020-01-01 | 2020-02-01 | 2020-01-01 | 2019-10-01
2020-03-01 | 2020-03-01 | 2020-03-01 | 2020-02-01 | 2020-01-01 | 2020-03-01
2020-04-01 | 2020-04-01 | 2020-03-01 | 2020-02-01 | 2020-01-01 | 2020-03-01
2020-05-01 | 2020-05-01 | 2020-05-01 | 2020-05-01 | 2020-05-01 | 2020-03-01
2020-06-01 | 2020-06-01 | 2020-05-01 | 2020-05-01 | 2020-05-01 | 2020-03-01
2020-07-01 | 2020-07-01 | 2020-07-01 | 2020-05-01 | 2020-05-01 | 2020-03-01
2020-08-01 | 2020-08-01 | 2020-07-01 | 2020-08-01 | 2020-05-01 | 2020-08-01
2020-09-01 | 2020-09-01 | 2020-09-01 | 2020-08-01 | 2020-09-01 | 2020-08-01
2020-10-01 | 2020-10-01 | 2020-09-01 | 2020-08-01 | 2020-09-01 | 2020-08-01