Skip to content

Commit

Permalink
Fix year not multiple of day/month in nested CAgg
Browse files Browse the repository at this point in the history
Previously all intervals were converted to seconds using "epoch"
with date_part. However, this treats a year as 365.25 days to
account for leap years, leading to the unexpected situation that
a year is not a multiple of a day or a month.

Fixed by treating month-only intervals as multiples of 30 days.

Fixes #5231
  • Loading branch information
konskov committed Feb 2, 2023
1 parent 9133319 commit 6bc8980
Show file tree
Hide file tree
Showing 6 changed files with 861 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ accidentally triggering the load of a previous DB version.**
* #5218 Add role-level security to job error log
* #5214 Fix use of prepared statement in async module
* #5259 Lock down search_path in SPI calls
* #5255 Fix year not multiple of day/month in nested CAgg

## 2.9.2 (2023-01-26)

Expand Down
11 changes: 11 additions & 0 deletions tsl/src/continuous_aggs/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,17 @@ get_bucket_width(CAggTimebucketInfo bucket_info)
break;
case INTERVALOID:
{
/*
* epoch will treat year as 365.25 days. This leads to the unexpected
* result that year is not multiple of day or month, which is perceived
* as a bug. For that reason, we treat all months as 30 days regardless of year
*/
if (bucket_info.interval->month && !bucket_info.interval->day &&
!bucket_info.interval->time)
{
bucket_info.interval->day = bucket_info.interval->month * DAYS_PER_MONTH;
bucket_info.interval->month = 0;
}
Datum epoch = DirectFunctionCall2(interval_part,
PointerGetDatum(cstring_to_text("epoch")),
IntervalPGetDatum(bucket_info.interval));
Expand Down

0 comments on commit 6bc8980

Please sign in to comment.