Problem
date_bin(interval, ts) is the standard time-series bucketing function (GROUP BY date_bin(INTERVAL '1 hour', ts)). Time-based interval strides (INTERVAL '1 hour', '1 day', '1 minute', ...) all carry months == 0 and take the nanosecond-stride path, which is the overwhelmingly common case for time-series workloads.
That path processes each value through a per-row hot loop with:
- an indirect call through a function pointer (
BinFunction),
- a chain of checked arithmetic (
checked_mul/checked_sub/checked_rem/
checked_add) with error closures,
- a
Result -> Option conversion per value.
None of this is needed: for a positive nanosecond stride the whole computation is equivalent to bin = origin + floor((value*scale - origin)/stride)*stride, i.e. a few plain integer ops.
Proposal
Add a vectorized fast path for the positive nanosecond-stride case: a single infallible pass of plain integer arithmetic, guarded by a whole-array min/max safety check (with a margin covering origin/stride), falling back to the existing per-value path for pathological inputs / month strides / TIME types.
Problem
date_bin(interval, ts)is the standard time-series bucketing function (GROUP BY date_bin(INTERVAL '1 hour', ts)). Time-based interval strides (INTERVAL '1 hour','1 day','1 minute', ...) all carrymonths == 0and take the nanosecond-stride path, which is the overwhelmingly common case for time-series workloads.That path processes each value through a per-row hot loop with:
BinFunction),checked_mul/checked_sub/checked_rem/checked_add) with error closures,Result -> Optionconversion per value.None of this is needed: for a positive nanosecond stride the whole computation is equivalent to
bin = origin + floor((value*scale - origin)/stride)*stride, i.e. a few plain integer ops.Proposal
Add a vectorized fast path for the positive nanosecond-stride case: a single infallible pass of plain integer arithmetic, guarded by a whole-array min/max safety check (with a margin covering
origin/stride), falling back to the existing per-value path for pathological inputs / month strides / TIME types.