Repository navigation
Fix key condition analysis for DateTime64 compared with integer constants - #98410
Merged
alexey-milovidov merged 1 commit intoMar 1, 2026
Merged
Conversation
Contributor
…ants The cast_not_needed check in KeyCondition::extractAtomFromTree only recognized DateTime but not DateTime64, causing key analysis to fall through to type casting logic which produced 'Condition: true' (no pruning). This meant DateTime64 primary key columns could not benefit from granule pruning when compared against integer constants (epoch values), leading to full table scans. Fix by replacing isDateTime() with isDateTimeOrDateTime64() in the cast_not_needed check, consistent with the existing treatment of DateTime.
amosbird
force-pushed
the
datetime64-key-analysis
branch
from
March 1, 2026 13:29
5194ee8 to
101cffe
Compare
Member
|
Although it was still uncertain to me, if DateTime64 should be compared with an integer or with floating point... |
Contributor
|
Hi @amosbird @alexey-milovidov — while reviewing this PR I found the following:
Happy to discuss — close anything that's wrong or already addressed. |
EmeraldShift
added a commit
to EmeraldShift/ClickHouse
that referenced
this pull request
Aug 9, 2026
Range previously tightened every Int64 or UInt64 endpoint without knowing the key type. Move normalization into KeyCondition, where the key type is available, and apply it only to types whose values are represented as integers. Related: ClickHouse#113993 Caused by: ClickHouse#98410
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KeyCondition::extractAtomFromTreehas acast_not_neededoptimization that recognizes when a key column and a constant can be compared directly without casting (e.g.,DateTimevs native integer). However, it only checked forDateTimeand missedDateTime64. This caused key analysis to fall through to the type casting path, which producedCondition: true— meaning no granule pruning forDateTime64primary keys compared against integer constants.The fix replaces
isDateTimewithisDateTimeOrDateTime64in both sides of the check.Changes:
isDateTimewithisDateTimeOrDateTime64inKeyCondition.cppcast_not_neededcheck03400_datetime64_key_condition_with_numberverifying correct pruningChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix key condition analysis for
DateTime64primary keys compared with integer constants, which previously resulted in no granule pruning.Documentation entry for user-facing changes
Version info
26.3.1.219