Skip to content

Compile comparisons of date and time types - #128974

Draft
Manerone wants to merge 2 commits into
manerone-jit-function-rows-eventsfrom
manerone-jit-date-comparisons
Draft

Manerone wants to merge 2 commits into
manerone-jit-function-rows-eventsfrom
manerone-jit-date-comparisons

Conversation

@Manerone

@Manerone Manerone commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

equals, notEquals, less, greater, lessOrEquals and greaterOrEquals were never JIT-compiled when an argument is a Date, Date32, DateTime or DateTime64 (a "TODO support date/date32" in FunctionsComparison.h). This compiles the pairs that the interpreted comparison evaluates on the stored integers, with the same results:

  • two values of the same kind, including DateTime values with different time zones, which are absolute timestamps;
  • Date vs Date32, both day numbers from the same epoch;
  • DateTime vs a plain number;
  • DateTime64 vs DateTime64 of the same scale, and DateTime vs DateTime64, where the DateTime is multiplied by 10^scale, which cannot overflow.

Date vs DateTime needs the time zone, and DateTime64 values of different scales are rescaled with an overflow check that can throw, so both stay interpreted, as do Time and Time64.

Results

50M rows, Memory table, server-side medians of 9 interleaved runs, JIT on vs off:

Query 1 thread 16 threads
countIf with a DateTime range 1.45x 1.05x
countIf with a Date range and Date vs Date32 1.82x 1.17x
countIf with DateTime64 vs DateTime 1.61x 1.09x
sum(if(...)) time bucket 1.19x 1.02x

A new stateless test compares compiled and interpreted results for 3003 rows (edge values and generated values) × 16 type pairs × 6 operators, and checks that the compiled query runs every comparison compiled (CompiledFunctionRows).

Stacked on the PR for the profile events (#128973).

Related: #126979

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Comparisons of Date, Date32, DateTime and DateTime64 values of the same kind (and of DateTime with DateTime64) can now be JIT-compiled as part of expressions (compile_expressions), which makes date conditions inside expressions up to 1.8x faster.

`equals`, `notEquals`, `less`, `greater`, `lessOrEquals` and `greaterOrEquals`
were never JIT-compiled when an argument is a `Date`, `Date32`, `DateTime` or
`DateTime64`. Compile the pairs that the interpreted comparison evaluates on the
stored integers, with the same results:

- two values of the same kind, including `DateTime` values with different time
  zones, which are absolute timestamps;
- `Date` vs `Date32`, both day numbers from the same epoch;
- `DateTime` vs a plain number;
- `DateTime64` vs `DateTime64` of the same scale, and `DateTime` vs
  `DateTime64`, where the `DateTime` is multiplied by 10^scale, which cannot
  overflow.

`Date` vs `DateTime` needs the time zone, and `DateTime64` values of different
scales are rescaled with an overflow check that can throw, so both stay
interpreted, as do `Time` and `Time64`.

Date conditions inside expressions get faster, for example 1.45x for
`countIf(ts >= ... AND ts < ... AND value > 500)` and 1.82x for a `Date` range
with `Date` vs `Date32`, on one thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... label Nov 3, 2026
@scanhex12 scanhex12 self-assigned this Nov 4, 2026
scanhex12 added a commit that referenced this pull request Nov 4, 2026
It is done, and for more types, by
#128974, which the device's
expressions are to take once it is merged. Until then, a predicate with a
comparison of dates is evaluated on the CPU.

`05447_gpu_filtered_read` checks the plans of reads filtered by numbers rather than by dates.
scanhex12 added a commit that referenced this pull request Nov 4, 2026
It is done, and for more types, by
#128974, which the device's
expressions are to take once it is merged. Until then, a predicate with a
comparison of dates is evaluated on the CPU.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants