@@ -1451,28 +1451,12 @@ void
14511451ts_compute_inscribed_bucketed_refresh_window_variable (int64 * start , int64 * end ,
14521452 const ContinuousAggBucketFunction * bf )
14531453{
1454- Datum start_old , end_old , start_aligned , end_aliged ;
1455-
1456- /*
1457- * It's OK to use TIMESTAMPOID here. Variable-sized buckets can be used
1458- * only for dates, timestamps and timestamptz's. For all these types our
1459- * internal time representation is microseconds relative the UNIX epoch.
1460- * So the results will be correct regardless of the actual type used in
1461- * the CAGG. For more details see ts_internal_to_time_value() implementation.
1462- */
1463- start_old = ts_internal_to_time_value (* start , TIMESTAMPOID );
1464- end_old = ts_internal_to_time_value (* end , TIMESTAMPOID );
1465-
1466- start_aligned = generic_time_bucket (bf , start_old );
1467- end_aliged = generic_time_bucket (bf , end_old );
1468-
1469- if (DatumGetTimestamp (start_aligned ) != DatumGetTimestamp (start_old ))
1454+ int64 start_aligned = ts_cagg_variable_current_bucket_start (* start , bf );
1455+ if (start_aligned != * start )
14701456 {
1471- start_aligned = generic_add_interval ( bf , start_aligned );
1457+ * start = ts_cagg_variable_next_bucket_start ( * start , bf );
14721458 }
1473-
1474- * start = ts_time_value_to_internal (start_aligned , TIMESTAMPOID );
1475- * end = ts_time_value_to_internal (end_aliged , TIMESTAMPOID );
1459+ * end = ts_cagg_variable_current_bucket_start (* end , bf );
14761460}
14771461
14781462/*
@@ -1489,28 +1473,20 @@ void
14891473ts_compute_circumscribed_bucketed_refresh_window_variable (int64 * start , int64 * end ,
14901474 const ContinuousAggBucketFunction * bf )
14911475{
1492- Datum start_old , end_old , start_new , end_new ;
1493-
1494- /*
1495- * It's OK to use TIMESTAMPOID here.
1496- * See the comment in ts_compute_inscribed_bucketed_refresh_window_variable()
1497- */
1498- start_old = ts_internal_to_time_value (* start , TIMESTAMPOID );
1499- end_old = ts_internal_to_time_value (* end , TIMESTAMPOID );
1500- start_new = generic_time_bucket (bf , start_old );
1501- end_new = generic_time_bucket (bf , end_old );
1476+ * start = ts_cagg_variable_current_bucket_start (* start , bf );
1477+ int64 end_new = ts_cagg_variable_current_bucket_start (* end , bf );
15021478
15031479 /* Add interval to expand to next bucket if:
15041480 * 1. end wasn't at a bucket boundary (end moved during bucketing), OR
15051481 * 2. we have a single-point at a bucket boundary (start == end after bucketing) */
1506- if (DatumGetTimestamp (end_new ) != DatumGetTimestamp (end_old ) ||
1507- DatumGetTimestamp (start_new ) == DatumGetTimestamp (end_new ))
1482+ if (end_new != * end || * start == end_new )
15081483 {
1509- end_new = generic_add_interval (bf , end_new );
1484+ * end = ts_cagg_variable_next_bucket_start (* end , bf );
1485+ }
1486+ else
1487+ {
1488+ * end = end_new ;
15101489 }
1511-
1512- * start = ts_time_value_to_internal (start_new , TIMESTAMPOID );
1513- * end = ts_time_value_to_internal (end_new , TIMESTAMPOID );
15141490}
15151491
15161492/*
@@ -1521,15 +1497,14 @@ ts_compute_circumscribed_bucketed_refresh_window_variable(int64 *start, int64 *e
15211497 * val = time_bucket(bucket_size, val) + interval bucket_size
15221498 */
15231499int64
1524- ts_compute_beginning_of_the_next_bucket_variable (int64 timeval ,
1525- const ContinuousAggBucketFunction * bf )
1500+ ts_cagg_variable_next_bucket_start (int64 timeval , const ContinuousAggBucketFunction * bf )
15261501{
15271502 Datum val_new ;
15281503 Datum val_old ;
15291504
15301505 /*
15311506 * It's OK to use TIMESTAMPOID here.
1532- * See the comment in ts_compute_inscribed_bucketed_refresh_window_variable ()
1507+ * See the comment in ts_cagg_variable_current_bucket_start ()
15331508 */
15341509 val_old = ts_internal_to_time_value (timeval , TIMESTAMPOID );
15351510
@@ -1547,11 +1522,14 @@ ts_compute_beginning_of_the_next_bucket_variable(int64 timeval,
15471522 * val = time_bucket(bucket_size, val)
15481523 */
15491524int64
1550- ts_compute_start_of_current_bucket_variable (int64 timeval , const ContinuousAggBucketFunction * bf )
1525+ ts_cagg_variable_current_bucket_start (int64 timeval , const ContinuousAggBucketFunction * bf )
15511526{
15521527 /*
1553- * It's OK to use TIMESTAMPOID here.
1554- * See the comment in ts_compute_inscribed_bucketed_refresh_window_variable()
1528+ * It's OK to use TIMESTAMPOID here. Variable-sized buckets can be used
1529+ * only for dates, timestamps and timestamptz's. For all these types our
1530+ * internal time representation is microseconds relative the UNIX epoch.
1531+ * So the results will be correct regardless of the actual type used in
1532+ * the CAGG. For more details see ts_internal_to_time_value() implementation.
15551533 */
15561534 Datum val_beg = ts_internal_to_time_value (timeval , TIMESTAMPOID );
15571535 return ts_time_value_to_internal (generic_time_bucket (bf , val_beg ), TIMESTAMPOID );
0 commit comments