Skip to content

Cherry pick #123999 to 26.9: Fix rows skipped when a sub-second DateTime64 key is compared with an integer by > or < - #127228

Merged
yariks5s merged 6 commits into
backport/26.9/123999from
cherrypick/26.9/123999
Oct 22, 2026
Merged

yariks5s merged 6 commits into
backport/26.9/123999from
cherrypick/26.9/123999

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #123999

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 6 commits October 5, 2026 09:58
… integer by > or <

Since #98410, `cast_not_needed` in `KeyCondition::extractAtomFromTree` keeps an
integer constant (and a `DateTime` constant, whose `Field` is `UInt64` seconds)
as an integer `Field` against a `DateTime64(N)` key. The comparison is exact,
but `Range::createLeftBounded` / `createRightBounded` call
`shrinkToIncludedIfPossible`, which closes an open bound on an integer `Field`
by stepping it by one unit of the constant, i.e. one second rather than one key
tick. `dt > 1577836800` became `dt >= 1577836801` and `dt < 1577836801` became
`dt <= 1577836800`, so every granule, part or Parquet row group inside that
second was pruned (primary key, partition key, `minmax` skip index).

For a `DateTime64` key with scale > 0, store such a constant as
`DecimalField<Decimal256>(value, 0)`. `FieldVisitorAccurateLess` / `Equals`
already compared a decimal with an integer by building exactly that field, so
comparison results are unchanged and only the bogus step goes away.
`Decimal256` at scale 0 is used rather than the key's `Decimal64` at scale N
because `value * 10^N` overflows `Int64` for large constants and the decimal
comparison would throw `DECIMAL_OVERFLOW` during index analysis. `Bool` is
converted too, before `normalizeBoolFields` would turn it into a steppable
`UInt64`. `DateTime64(0)` keeps the integer form: its domain is whole seconds.
`Range` is unchanged, so integer keys and `numbers()` range extraction keep
their normalization.

Closes #101276
Closes #113993

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the DateTime64 integer-bound comment in KeyCondition to one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-bound

# Conflicts:
#	src/Storages/MergeTree/KeyCondition.cpp
…integer-strict-bound

Fix rows skipped when a sub-second `DateTime64` key is compared with an integer by `>` or `<`
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Oct 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The only conflict is in KeyCondition.cpp: on 26.9 the comparison-atom construction is still inline in the function-atom lambda, while master moved it into tryBuildComparisonAtom (#96225, not in 26.9). I put the 11-line hunk of this PR right after the same cast_not_needed computation there.

git fetch https://github.com/groeneai/ClickHouse resolve-26.9-cherrypick-123999 && git push origin FETCH_HEAD:cherrypick/26.9/123999
  • cf7fb1d28cdc is a fast-forward from the cherry-pick head e53e2e05d8a3. Compared with backport/26.9/123999 it changes only KeyCondition.cpp (+11, the master hunk re-indented) and adds 05325_datetime64_key_integer_strict_bound unchanged from master.
  • On a 26.9 build (clang-22, Debug) the test passes 50/50 with randomized settings. Without the change it returns the same wrong counts as the official 26.9.16.11 (pk > 2 instead of 3, minmax < 1 instead of 3).

@yariks5s

Copy link
Copy Markdown
Member

@groeneai please fix conflicts

@groeneai

Copy link
Copy Markdown
Collaborator

I can't push to cherrypick/26.9/123999 myself (I only have read access to this repository), so the resolution is on my fork. It is still a fast-forward of the current head e53e2e05d8a3 and merges the current backport/26.9/123999 tip efa5b75f2276, so this one line fixes the conflict:

git fetch https://github.com/groeneai/ClickHouse resolve-26.9-cherrypick-123999 && git push origin FETCH_HEAD:cherrypick/26.9/123999

The same applies to #127226 (26.7) and #127227 (26.8): the commands in my comments there are still current.

@yariks5s
yariks5s merged commit df0d11d into backport/26.9/123999 Oct 22, 2026
14 checks passed
@yariks5s
yariks5s deleted the cherrypick/26.9/123999 branch October 22, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants