Repository navigation
Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms - #105384
Conversation
`MergeTreeIndexConditionSet::traverseDAG` wrapped every WHERE atom with `__bitWrapperFunc` to coerce it to a `BoolMask`. `__bitWrapperFunc` is defined only for integer arguments and throws `BAD_ARGUMENTS` with the internal "It's a bug!" message when called with `Float`, `BFloat16`, or other non-integer types. For queries like `WHERE c0 + 0.1`, `WHERE log(c0)`, or a direct `Float` column predicate, this turned a normal full-scan fallback into a user-visible exception whenever a `TYPE set(N)` skip index was present on the table. Check the atom result type (after stripping `Nullable`) before wrapping. If it is not integer, fall back to `UNKNOWN_FIELD` so the index does not prune granules and the query goes through the regular filter path. Closes ClickHouse#105355
Pre-PR validation gatea) Deterministic repro: Yes. The 5-line repro from #105355 ( b) Root cause: c) Fix matches root cause: Check d) Test intent preserved + new test added: No existing tests modified. New regression test e) Both directions demonstrated:
f) Fix is general, not a narrow patch: The check is at the single wrap site in Session: |
|
cc @rschu1ze @alexey-milovidov for review (comp-skip-index, MergeTreeIndexSet wrapping logic). cc @PedroTadim — closes #105355 you tagged me on. Test-only change to verify: just runs the regression test added in this PR. C++ change is a single guarded fallback in |
|
Workflow [PR], commit [fdbffb4] Summary: ✅ AI ReviewSummaryThis PR fixes a real correctness regression in set skip index evaluation: non-integer WHERE atoms were being wrapped by Final Verdict
|
LLVM Coverage Report
Changed lines: 100.00% (10/10) · Uncovered code |
Cherry pick #105384 to 25.8: Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms
…n non-integer WHERE atoms
Cherry pick #105384 to 26.3: Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms
…n non-integer WHERE atoms
Cherry pick #105384 to 26.4: Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms
…n non-integer WHERE atoms
The first `SELECT count()` is the canonical bug trigger from ClickHouse#105938 / ClickHouse#105384. As written, the stateless runner randomizes `use_skip_indexes_on_data_read` and `use_skip_indexes_for_disjunctions` across runs. When either disables the partial-disjunction skip-index path in `MergeTreeDataSelectExecutor` / `ReadFromMergeTree`, the buggy `MergeTreeIndexConditionSet::traverseDAG` wrapping is never exercised and a pre-fix binary returns the same `100` as a post-fix binary, so the regression would silently slip through. Pin the four settings that gate the buggy path on that query directly via per-query `SETTINGS`, so the test always exercises the fix: use_skip_indexes = 1 use_skip_indexes_on_data_read = 0 use_skip_indexes_for_disjunctions = 1 use_query_condition_cache = 0 The other two queries are intentionally left alone: the second forces `use_skip_indexes = 0` as the no-index control, and the third uses `assumeNotNull(n)` so the atom result type is no longer `LowCardinality(Nullable(UInt8))` and the bug cannot trigger. Addresses bot review on PR ClickHouse#105990.
Backport #105384 to 26.3: Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms
…5-set-skip-index-float-bitwrapperfunc Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms
…issue ClickHouse#105938) Locks down the fix from ClickHouse#105384 against issue ClickHouse#105938, where a `WHERE` clause ORing a `set(N)` skip index predicate on a `LowCardinality(Nullable(String))` column with an `ngrambf_v1` predicate on a different column silently returned zero rows when the `LowCardinality(Nullable)` column contained only NULL values. `MergeTreeIndexConditionSet::traverseDAG` used to wrap every WHERE atom with `__bitWrapperFunc`. For `LowCardinality(Nullable(String)) = String` the atom result type is `LowCardinality(Nullable(UInt8))`, which the pre-fix wrapper coerced to `0` for NULL values, so the set index incorrectly concluded the granule could not match and the ORed `ngrambf_v1` side could not override the decision. PR ClickHouse#105384 detects that the atom result type is not integer after stripping `Nullable` and falls back to `UNKNOWN_FIELD`, keeping the granule. The new stateless test reproduces the smaller form reported by @den-crane on issue ClickHouse#105938 and asserts that the result with `use_skip_indexes = 1` matches the result with `use_skip_indexes = 0` (and the `assumeNotNull` workaround referenced in the issue). Verified locally that the test fails on a binary without ClickHouse#105384 (first SELECT returns `0`) and passes on master HEAD.
The first `SELECT count()` is the canonical bug trigger from ClickHouse#105938 / ClickHouse#105384. As written, the stateless runner randomizes `use_skip_indexes_on_data_read` and `use_skip_indexes_for_disjunctions` across runs. When either disables the partial-disjunction skip-index path in `MergeTreeDataSelectExecutor` / `ReadFromMergeTree`, the buggy `MergeTreeIndexConditionSet::traverseDAG` wrapping is never exercised and a pre-fix binary returns the same `100` as a post-fix binary, so the regression would silently slip through. Pin the four settings that gate the buggy path on that query directly via per-query `SETTINGS`, so the test always exercises the fix: use_skip_indexes = 1 use_skip_indexes_on_data_read = 0 use_skip_indexes_for_disjunctions = 1 use_query_condition_cache = 0 The other two queries are intentionally left alone: the second forces `use_skip_indexes = 0` as the no-index control, and the third uses `assumeNotNull(n)` so the atom result type is no longer `LowCardinality(Nullable(UInt8))` and the bug cannot trigger. Addresses bot review on PR ClickHouse#105990.
Backport #105384 to 26.4: Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms
`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]>
… a bug!" on non-integer WHERE atoms
…5384 Backport ClickHouse#105384 to 26.4: Fix set skip index throwing "It's a bug!" on non-integer WHERE atoms
STOR: set(N) skip index with a non-integer WHERE atom (Float etc.) -> exc BAD_ARGUMENTS `__bitWrapperFunc`. Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/105384.PROD263.txt). Upstream patch unchanged, with its test(s): 04258_set_skip_index_float_where_issue_105355. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #105355.
MergeTreeIndexConditionSet::traverseDAGwraps every WHERE atom in__bitWrapperFuncto coerce it to aBoolMask.__bitWrapperFuncis defined only for integer arguments and throwsBAD_ARGUMENTS("It's a bug!") onFloat,BFloat16, etc. Queries such asWHERE c0 + 0.1against aTYPE set(N)skip index hit that throw at execution time.Check the atom result type (after stripping
Nullable) before wrapping. If it is not integer, fall back toUNKNOWN_FIELDso the index does not prune granules and the query goes through the regular filter path. This matches the behavior the user gets when the index is absent.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
BAD_ARGUMENTSexception "It's a bug! Only integer types are supported by__bitWrapperFunc" thrown when aSELECTwith aTYPE set(N)skip index has a WHERE atom whose result type isFloat,BFloat16, or any other non-integer type (for exampleWHERE c0 + 0.1orWHERE log(c0)). The skip index now falls back to the regular filter path in that case.Version info
26.5.1.86626.3.13.19