Skip to content

Commit

Permalink
Fix sub-second intervals in hierarchical caggs
Browse files Browse the repository at this point in the history
Previously we used date_part("epoch", interval) and integer division
internally to determine whether the top cagg's interval is a
multiple of its parent's.
This led to precision loss and wrong results
in the case of intervals with sub-second components.

Fixed by using the `ts_interval_value_to_internal` function to convert
intervals to appropriate integer representation for division.

Fixes #5277
  • Loading branch information
konskov committed Mar 7, 2023
1 parent 00b566d commit 5a3cacd
Show file tree
Hide file tree
Showing 6 changed files with 893 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -29,6 +29,7 @@ We recommend that you upgrade at the next available opportunity.
* #5367 Fix column name handling in old-style continuous aggregates
* #5378 Fix multinode DML HA performance regression
* #5384 Fix Hierarchical Continuous Aggregates chunk_interval_size
* #5304 Fix sub-second intervals in hierarchical caggs

**Thanks**
* @justinozavala for reporting an issue with PL/Python procedures in the background worker
Expand Down
9 changes: 4 additions & 5 deletions tsl/src/continuous_aggs/create.c
Expand Up @@ -1151,11 +1151,10 @@ get_bucket_width(CAggTimebucketInfo bucket_info)
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));
/* Cast float8 to int8. */
width = DatumGetInt64(DirectFunctionCall1(dtoi8, epoch));

/* Convert Interval to int64 */
width =
ts_interval_value_to_internal(IntervalPGetDatum(bucket_info.interval), INTERVALOID);
break;
}
default:
Expand Down

0 comments on commit 5a3cacd

Please sign in to comment.