Skip to content

Cherry pick #121154 to 26.3: Fix wrong results when a predicate applies a NULL-handling function to a Nullable partition key - #130786

Merged
PedroTadim merged 1 commit into
backport/26.3/121154from
cherrypick/26.3/121154
Nov 12, 2026
Merged

PedroTadim merged 1 commit into
backport/26.3/121154from
cherrypick/26.3/121154

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #121154

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

@robot-ch-test-poll2 robot-ch-test-poll2 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 Nov 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The conflict is a context line: if (functions.empty()) return key_range; in KeyCondition::applyMonotonicFunctionsChainToRange came with #117054, which is not on 26.3. I did not take that line. The new check carries !functions.empty() in its condition instead, so an empty chain (key IN (...) with no wrapping function) still returns the range unchanged, as on master.

The test is the one from master, adapted to 26.3:

  • without its nullIf case, which checks Do not prune a partition when a function of the partition key returns NULL for it #124041 (not on 26.3) and fails there with or without this change;
  • without the settings 26.3 does not have: use_statistics_for_part_pruning, explain_query_plan_default, allow_key_condition_coalesce_rewrite;
  • the minmax index step is matched as MinMax, the name 26.3 prints;
  • the table with a reverse key sets allow_experimental_reverse_key = 1.

On the 26.3 tree (clang-21, debug) the test passes 50 of 50 with randomized settings. Without the KeyCondition.cpp change it fails 5 of 5: every case the change covers gets a wrong count (for example assumeNotNull(c0) = 0 counts 1 row instead of 3), and the control cases do not change. Against backport/26.3/121154 the merge changes KeyCondition.cpp (+5 lines) and adds the test, nothing else.

I cannot push to cherrypick/26.3/121154. The merge is on my fork and its first parent is this PR's head 27ebdb8120ef, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git groeneai/resolve-26.3-cherrypick-121154
git push origin FETCH_HEAD:cherrypick/26.3/121154

…o a `Nullable` partition key

Backport of #121154 to 26.3, applied onto the branch's `applyMonotonicFunctionsChainToRange`.
Its only caller already skips an empty chain, so the #117054 early return master has before
the new check is not needed here.

The test drops the settings 26.3 does not have (`allow_key_condition_coalesce_rewrite`,
`use_statistics_for_part_pruning`, `explain_query_plan_default`), enables
`allow_experimental_reverse_key` for the reverse-key table, and matches the `MinMax` step name
that the 26.3 `EXPLAIN` prints. Checked against the 26.3.60.2 release: only the lines the fix
changes differ from the reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim force-pushed the cherrypick/26.3/121154 branch from 27ebdb8 to 6df259f Compare November 12, 2026 08:29
@PedroTadim
PedroTadim merged commit 7ee1bf7 into backport/26.3/121154 Nov 12, 2026
1 check passed
@PedroTadim
PedroTadim deleted the cherrypick/26.3/121154 branch November 12, 2026 08:29
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