Skip to content

Fix set skip index not pruning granules over LowCardinality columns - #107868

Merged
thevar1able merged 5 commits into
masterfrom
fix-set-skip-index-lowcardinality-pruning
Jun 22, 2026
Merged

thevar1able merged 5 commits into
masterfrom
fix-set-skip-index-lowcardinality-pruning

Conversation

@thevar1able

@thevar1able thevar1able commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Caused by #105384
Closes #107881

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix set skip index not pruning granules over LowCardinality columns.

Version info

  • Merged into: 26.6.1.1128
  • Backported to: 26.5.4.8, 26.4.5.64, 26.3.16.2

@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b861998]

Summary: ✅


AI Review

Summary

This PR fixes set skip-index pruning for non-nullable LowCardinality(String) predicate atoms by allowing LowCardinality(UInt8) atoms to use __bitWrapperFunc again, while still rejecting the LowCardinality(Nullable(UInt8)) shape that caused the earlier nullable pruning regression. I did not find unresolved correctness, safety, or coverage issues in the current code.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 18, 2026
@thevar1able thevar1able added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jun 18, 2026
`MergeTreeIndexConditionSet::traverseDAG` wraps each WHERE atom with
`__bitWrapperFunc` to coerce it to a `BoolMask`. `__bitWrapperFunc` is
defined only for integer arguments, so #105384 started wrapping an atom
only when `WhichDataType(removeNullable(atom->result_type)).isInteger()`
and otherwise fell back to `UNKNOWN_FIELD` (the index keeps every
granule and the query goes through the regular filter path). That fix
correctly handles `Float` atoms (#105355) and `LowCardinality(Nullable)`
atoms (#105938), where wrapping would throw "It's a bug!" or coerce a
NULL granule value to `0` and wrongly prune.

But it strips only `Nullable`, not `LowCardinality`. Over a non-nullable
`LowCardinality(String)` column, function predicates such as `hasToken`,
`LIKE` or `match` produce `LowCardinality(UInt8)`, which is not "integer",
so every atom became `UNKNOWN_FIELD` and the `set` index stopped pruning
entirely -- turning an index lookup into a full scan with large read
amplification. A plain `String` column yields `UInt8` and was unaffected,
which is why the regression was specific to `LowCardinality`.

Look through `LowCardinality` before the integer check. The wrapper is
stripped only for `LowCardinality` types and, unlike the plain case,
`Nullable` is not stripped afterwards, so `LowCardinality(UInt8)` is
wrapped and prunes again while `LowCardinality(Nullable(...))` keeps
falling back to `UNKNOWN_FIELD` and the #105938 fix is preserved.
`__bitWrapperFunc` accepts `LowCardinality(UInt8)`, which is how these
predicates pruned before #105384.

Caused by: #105384
Closes: #107881

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thevar1able thevar1able changed the title Fix set skip index not pruning granules over LowCardinality columns Fix set skip index not pruning granules over LowCardinality columns Jun 18, 2026
@CurtizJ CurtizJ self-assigned this Jun 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.20% -0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.50% 77.40% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 7/7 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@thevar1able
thevar1able added this pull request to the merge queue Jun 22, 2026
Merged via the queue into master with commit a80b31e Jun 22, 2026
326 of 328 checks passed
@thevar1able
thevar1able deleted the fix-set-skip-index-lowcardinality-pruning branch June 22, 2026 16:47
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 22, 2026
robot-ch-test-poll added a commit that referenced this pull request Jun 22, 2026
Cherry pick #107868 to 26.3: Fix `set` skip index not pruning granules over `LowCardinality` columns
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
robot-ch-test-poll added a commit that referenced this pull request Jun 22, 2026
Cherry pick #107868 to 26.4: Fix `set` skip index not pruning granules over `LowCardinality` columns
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
robot-clickhouse added a commit that referenced this pull request Jun 22, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 22, 2026
robot-ch-test-poll2 added a commit that referenced this pull request Jun 23, 2026
Cherry pick #107868 to 25.8: Fix `set` skip index not pruning granules over `LowCardinality` columns
robot-clickhouse added a commit that referenced this pull request Jun 23, 2026
thevar1able added a commit that referenced this pull request Jun 23, 2026
Backport #107868 to 26.3: Fix `set` skip index not pruning granules over `LowCardinality` columns
thevar1able added a commit that referenced this pull request Jun 23, 2026
Backport #107868 to 26.4: Fix `set` skip index not pruning granules over `LowCardinality` columns
thevar1able added a commit that referenced this pull request Jun 23, 2026
Backport #107868 to 26.5: Fix `set` skip index not pruning granules over `LowCardinality` columns
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 23, 2026
@thevar1able thevar1able added v26.2-must-backport v26.3-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Jun 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 24, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 24, 2026
@thevar1able thevar1able added v26.2-affected v26.3-affected and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-synced-to-cloud The PR is synced to the cloud repo pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Jun 25, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 25, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 25, 2026
@zdyj3170101136

Copy link
Copy Markdown

Could you please expedite the backport of this MR (Matchmaking Service) update? I need to upgrade from ClickHouse Cloud version 25.12 to 26.2 as soon as possible.

@thevar1able

Copy link
Copy Markdown
Member Author

Could you please expedite the backport of this MR (Matchmaking Service) update? I need to upgrade from ClickHouse Cloud version 25.12 to 26.2 as soon as possible.

Backports are complete, which version is missing for you?

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

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR v26.2-affected v26.2-must-backport v26.3-affected v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

set skip index stops pruning granules for function predicates over LowCardinality columns

7 participants