Skip to content

Test set skip index OR with LowCardinality(Nullable) (issue #105938) - #105990

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/test-105938-skip-index-or-lc-nullable
Jun 3, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/test-105938-skip-index-or-lc-nullable

Conversation

@groeneai

@groeneai groeneai commented May 27, 2026 •

Copy link
Copy Markdown
Collaborator

Regression test that locks down #105384 against the smaller reproducer reported on issue #105938.

The bug: 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. The same query with use_skip_indexes = 0 (or with assumeNotNull wrapped around the LC column) returned the correct count.

Root cause: MergeTreeIndexConditionSet::traverseDAG used to wrap every WHERE atom with __bitWrapperFunc. For LowCardinality(Nullable(String)) = String the atom result type is LowCardinality(Nullable(UInt8)). The pre-fix wrapper coerced a NULL granule value to 0, so the set index incorrectly concluded the granule could not match and the ORed ngrambf_v1 side could not override the decision: the granule was pruned.

The fix in #105384 detects that the atom result type is not integer after stripping Nullable (note: removeNullable does not peel through LowCardinality, so LC(Nullable(UInt8)) falls into the non-integer branch) and falls back to UNKNOWN_FIELD, so the set index does not attempt to prune the granule and the query goes through the regular filter path. @Avogar identified #105384 as the canonical fix in #105938 (comment).

Local validation:

Issue: #105938
Related fix PR: #105384

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Add a regression test for the skip index OR + LowCardinality(Nullable) wrong-result bug fixed by #105384.

Documentation entry for user-facing changes

  • Documentation is not required.

Version info

  • Merged into: 26.6.1.352

@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (session cron:clickhouse-ci-task-worker:20260527-171500):

(a) Deterministic repro: yes. The smaller reproducer from @den-crane on #105938 (100 + 10 rows, no random settings) returns 0 on a pre-fix binary and 100 on the post-fix binary every time. The test in this PR replays exactly that pattern.

(b) Root cause explained: yes. MergeTreeIndexConditionSet::traverseDAG used to wrap every WHERE atom with __bitWrapperFunc. For LowCardinality(Nullable(String)) = String the atom result type is LowCardinality(Nullable(UInt8)). The pre-fix wrapper coerced a NULL granule value to 0, so the set index concluded the granule definitely could not match, and the ORed ngrambf_v1 side could not override that decision: the granule was pruned. #105384 detects that the atom result type is not integer after stripping Nullable (removeNullable does not peel through LowCardinality, so LC(Nullable(UInt8)) enters the non-integer branch) and falls back to UNKNOWN_FIELD, keeping the granule and forcing the regular filter path.

(c) Fix matches root cause: N/A here, this PR is test-only locking down the existing fix in #105384.

(d) Test intent preserved: yes. The test asserts equality between use_skip_indexes = 1, use_skip_indexes = 0, and the assumeNotNull workaround referenced in the issue. All three must be 100. No no-random-* tags, no SETTINGS other than use_skip_indexes = 0 for the contrast row.

(e) Both directions demonstrated: yes. Locally reverted only the integer-type check hunk added by #105384 to src/Storages/MergeTree/MergeTreeIndexSet.cpp, rebuilt, and ran the test file via clickhouse local --multiquery against tests/queries/0_stateless/04295_set_skip_index_or_lc_nullable_issue_105938.sql: first SELECT returns 0 (expected 100). Restored HEAD and rebuilt: first SELECT returns 100. diff against the .reference exits 1 pre-fix and 0 post-fix.

(f) Fix is general, not a narrow patch: N/A (test-only PR). The fix in #105384 already covers all non-integer atom result types via the removeNullable + isInteger check.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze, could you review this? Test-only PR locking down the skip index set + LC(Nullable) fix from #105384 against the smaller reproducer reported on #105938.

@clickhouse-gh

clickhouse-gh Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [829f86d]

Summary: ✅


AI Review

Summary

This PR adds a focused stateless regression test for the set skip index + ngrambf_v1 disjunction wrong-result case involving LowCardinality(Nullable). The current version pins the settings needed to force the partial-disjunction skip-index path, so the earlier masking risk is addressed. I found no remaining review findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 27, 2026
@alexbakharew alexbakharew self-assigned this May 29, 2026
@CLAassistant

CLAassistant commented May 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 29, 2026
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.
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label May 29, 2026
groeneai added 2 commits June 2, 2026 18:54
…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.
@alexbakharew
alexbakharew force-pushed the groeneai/test-105938-skip-index-or-lc-nullable branch from bd165b8 to 829f86d Compare June 2, 2026 16:55
@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 331 line(s), 49 function(s) across 108 file(s) · Details

Top files
  • src/Storages/StorageReplicatedMergeTree.cpp: 41 line(s)
  • src/AggregateFunctions/AggregateFunctionIntervalLengthSum.cpp: 18 line(s), 40 function(s)
  • src/IO/S3/copyS3File.cpp: 13 line(s)
  • src/Functions/FunctionsBitmap.h: 11 line(s)
  • src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp: 9 line(s)

Full report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 3, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jun 3, 2026
Merged via the queue into ClickHouse:master with commit 5aac6ae Jun 3, 2026
166 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants