Skip to content

Add regression test for set skip index with IS TRUE / IS FALSE / IS UNKNOWN - #105865

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/follow-up-99997-set-index-truth-predicates
Jun 2, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/follow-up-99997-set-index-truth-predicates

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Follow-up to #99997 (which added the SQL truth-value predicates IS TRUE, IS FALSE, IS UNKNOWN, and their IS NOT variants). @PedroTadim asked on the inline review whether the set skip index is used for these predicates on a Nullable(Bool) column.

The answer is yes, the set index already prunes granules in all six cases because the new predicates lower to functions the set index recognises at the atom level (isNotDistinctFrom(b, true|false), isNull(b), isDistinctFrom(b, true|false), isNotNull(b)). This PR pins that behaviour with a regression test.

The test creates a MergeTree table with index_granularity = 8 and inserts 24 rows arranged so the three granules contain only true, only false, and only NULL values respectively. For each predicate it asserts:

  • count() returns the right number of matching rows.
  • ProfileEvents['SelectedMarks'] shows the set index dropped the two unrelated granules for IS TRUE / IS FALSE / IS UNKNOWN (1/3 granules read) and the matching granule for the IS NOT forms (2/3 granules read).

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):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

…NKNOWN

Verifies that the set skip index prunes granules for the new truth-value
predicates from ClickHouse#99997 on a `Nullable(Bool)` column. The new test populates
three granules of eight rows each (only true, only false, only NULL) and
checks via `ProfileEvents['SelectedMarks']` that the index drops the two
unrelated granules for each positive form and the matching granule for
each `IS NOT` form.

Follow-up to ClickHouse#99997.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (test-only PR):

  • New test added (a-f items mostly N/A since there is no bug to fix): tests/queries/0_stateless/04290_set_index_is_true_false_unknown.sql.
  • Regression catch: the reference asserts SelectedMarks = 1/3 for every positive form and 2/3 for every negative form. A change that stops the set index from recognising isNotDistinctFrom(b, true|false), isNull(b), isDistinctFrom(b, true|false), or isNotNull(b) would bump those counts to 3/3 and fail.
  • 100/100 passes under default runner randomization, 10/10 under enable_analyzer = 0, 10/10 under enable_parallel_replicas = 2 with cluster_for_parallel_replicas = parallel_replicas. Per-query SETTINGS enable_parallel_replicas = 0 on each measured SELECT keeps system.query_log deterministic.
  • No code changes, no production behavior change. The set index already prunes correctly via MergeTreeIndexConditionSet::atomFromDAG and mayBeTrueOnGranule; this just documents that with a regression test as @PedroTadim asked on Implements SQL truth-value predicates IS TRUE, IS FALSE, IS UNKNOWN and their IS NOT variants. Closes ClickHouse/ClickHouse#99597. #99997.

session: cron:clickhouse-ci-task-worker:20260526-144500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ for review (comp-skip-index): tiny regression test pinning the set-skip-index pruning that the existing predicate lowering already gives us for the new IS TRUE / IS FALSE / IS UNKNOWN forms. Follow-up to #99997.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label May 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8de2d98]

Summary: ✅


AI Review

Summary

This PR adds stateless regression coverage for Nullable(Bool) truth-value predicates with a set skip index, plus a companion MergeTree primary-key coverage test that documents current KeyCondition behavior. I did not find correctness, isolation, or metadata issues that require changes.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 26, 2026
@PedroTadim
PedroTadim enabled auto-merge May 26, 2026 15:20
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai can you check the test failures?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Triaged both failures. Both are chronic trunk issues unrelated to this PR.

This PR is test-only: 2 files in tests/queries/0_stateless/ (04290_set_index_is_true_false_unknown.sql and its .reference), no C++ changes. Our test ran and passed (116 passed in the stateless lane).

1. Stress test (arm_release) -- Logical error: Coordination mode mismatch for stream A: got B, expected C

Origin: DB::ParallelReplicasReadingCoordinator::handleInitialAllRangesAnnouncement raising "got Default, expected WithOrder" (or vice versa). Chronic ParallelReplicasReadingCoordinator race tracked under STID 6117-726a + sibling STIDs (7334-5b92, 7334-48d5, 6117-68e9):

This PR cannot affect parallel-replicas coordination.

2. Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential) -- Server died / Lost connection

clickhouse-server.err.log shows the cascade clearly: system.<X>_log_sender.DistributedInsertQueue repeatedly hitting TOO_MANY_PARTS and MEMORY_LIMIT_EXCEEDED (30.03 GiB attempt vs 29.80 GiB max), then core.MergeMutate.1574-3816.zst produced by a MergeMutate worker. No sanitizer report, no LOGICAL_ERROR in server.log. Tests reported as failing (03716_mutations_parts_postpone_reasons_rmt, 03714_queries_escaping_3) are downstream of the server crash, not the cause.

Chronic on this exact lane:

  • 30+ distinct unrelated PRs hit Server died on Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential) in last 14 days, 4 master hits on 2026-05-22.
  • Same shape across runs: distributed-insert backlog under random_settings + db disk + ASAN -> memory wall -> MergeMutate crash -> remaining tests get "Lost connection".

Not reproducible from anything this PR adds.

Recommendation

Both failures are infra/trunk, not PR-caused. The bot AI approval from 2026-05-26 stands; the test file passes consistently on every other lane. Happy to rerun if you would like a fresh set of CI runs.

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai can you add a primary key test to check that it is also used with these predicates?

Sibling of `04290_set_index_is_true_false_unknown` covering the leading
primary-key path on a `Nullable(Bool)` column. `KeyCondition` recognises
the `isNull` / `isNotNull` lowered forms and drops one granule for
`IS UNKNOWN` and `IS NOT UNKNOWN`. The other four predicates lower to
`isNotDistinctFrom` / `isDistinctFrom`, which are not recognised by
`KeyCondition`, so the test pins this current behaviour.

Follow-up to ClickHouse#99997. Requested in ClickHouse#105865.
auto-merge was automatically disabled June 1, 2026 16:20

Head branch was pushed to by a user without write access

@groeneai

groeneai commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

@PedroTadim added tests/queries/0_stateless/04304_primary_key_is_true_false_unknown.sql in 8de2d98.

Same 24-row, three-granule layout (false/true/NULL × 8) but b Nullable(Bool) is the leading primary-key column (ORDER BY (b, id), allow_nullable_key = 1). Trivial-count and implicit-projection optimisations are disabled per query so SelectedMarks reflects actual granule reads.

Observed KeyCondition behaviour (locally, 50/50 runs with random settings + random MergeTree settings):

predicate granules read / total
IS UNKNOWN 2 / 3
IS NOT UNKNOWN 2 / 3
IS TRUE / IS FALSE / IS NOT TRUE / IS NOT FALSE 3 / 3

KeyCondition only special-cases isNull / isNotNull (see src/Storages/MergeTree/KeyCondition.cpp around line 642). The other four predicates lower to isNotDistinctFrom / isDistinctFrom, which it treats as the trivial true condition — so the test pins current behaviour and will flag any change. Happy to file a follow-up if you think KeyCondition should also recognise the distinct-from forms.

@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 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: 345 line(s), 19 function(s) across 121 file(s) · Details

Top files
  • src/AggregateFunctions/AggregateFunctionQuantileGK.cpp: 14 line(s)
  • src/AggregateFunctions/AggregateFunctionWindowFunnel.cpp: 11 line(s), 6 function(s)
  • src/Databases/DatabaseFactory.cpp: 11 line(s)
  • src/Backups/BackupCoordinationStageSync.cpp: 10 line(s)
  • src/IO/S3/copyS3File.cpp: 10 line(s)

Full report

@PedroTadim
PedroTadim added this pull request to the merge queue Jun 2, 2026
Merged via the queue into ClickHouse:master with commit edddce5 Jun 2, 2026
166 of 167 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 2, 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 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.

3 participants