Skip to content

Use skip indexes through lossless conversions of the indexed column - #123239

Merged
CurtizJ merged 3 commits into
ClickHouse:masterfrom
CurtizJ:skip-index-lossless-conversion
Oct 2, 2026
Merged

CurtizJ merged 3 commits into
ClickHouse:masterfrom
CurtizJ:skip-index-lossless-conversion

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Related: #120220

Changelog category (leave one):

  • Improvement

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

Skip indexes (bloom_filter, tokenbf_v1, ngrambf_v1, minmax) and the primary key are now used when the indexed column is wrapped into a conversion that does not change its value, such as toLowCardinality, toNullable or a CAST to Nullable or LowCardinality.


Workflow [PR]
Sync PR [sync-upstream/pr/123239]

Version info

  • Merged into: 26.10.1.1340-master (included in 26.10 and later)
  • Backported to: 26.9.10.2, 26.8.17.2, 26.7.21.2

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [78fd6ec]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Logical error: Part A intersects previous part B. It is a bug or a result of manual intervention (STID: 3562-39cd) FAIL cidb IGNORED

AI Review

Summary

This PR teaches index analysis to look through lossless wrappers around the indexed expression (toNullable, toLowCardinality, and lossless CAST forms), moves that unwrapping logic into the shared RPNBuilder utility, and marks toLowCardinality as monotonic so primary-key / minmax analysis can use the same identity conversion. I did not find a correctness, safety, or compatibility issue in the current diff during static review.

Missing context / blind spots
  • ⚠️ I reviewed the current code, patch, PR metadata, and prior discussion, but this checkout has no ready local build, so I did not execute the new stateless tests here.
Final Verdict

✅ No new inline findings.

LLVM Coverage Report

Measured on commit 78fd6ec.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.40% 79.50% +0.10%

Changed lines: Changed C/C++ lines covered: 65/65 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Oct 1, 2026
The `bloom_filter`, `tokenbf_v1` and `ngrambf_v1` indexes now look through
`CAST`, `_CAST`, `toNullable` and `toLowCardinality` around the indexed
expression when the conversion never changes the value and never throws
(adding or dropping `LowCardinality`, adding `Nullable`, at any depth of
`Array`), the same as the text index does since
ClickHouse#120220. Such wrappers come
from explicit casts, from `join_use_nulls` in pushed-down filters, and from
casts of typed JSON paths, e.g. `has(['a'], json.Name::Nullable(String))`.

`unwrapLosslessConversion` moves from the text index condition to
`RPNBuilder` so that all index conditions share it.

`toLowCardinality` now declares itself monotonic, like `toNullable`, so
`KeyCondition` (primary key, `minmax`) accepts it in the monotonic chain.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@CurtizJ
CurtizJ force-pushed the skip-index-lossless-conversion branch from 306cb6b to ad5e5cf Compare October 1, 2026 12:28
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 78fd6ece945560c35e320238e43b810c3998a9a6 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

CurtizJ and others added 2 commits October 2, 2026 10:17
…ss-conversion

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The AST form of `RPNBuilderTreeNode` was removed in master, so `getDAGNode` is never null.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@CurtizJ CurtizJ self-assigned this Oct 2, 2026
@CurtizJ
CurtizJ added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit e5fdb03 Oct 2, 2026
147 of 149 checks passed
@CurtizJ
CurtizJ deleted the skip-index-lossless-conversion branch October 2, 2026 22:32
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
@CurtizJ CurtizJ added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 3, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 3, 2026
robot-ch-test-poll added a commit that referenced this pull request Oct 3, 2026
Cherry pick #123239 to 26.7: Use skip indexes through lossless conversions of the indexed column
robot-clickhouse added a commit that referenced this pull request Oct 3, 2026
robot-ch-test-poll added a commit that referenced this pull request Oct 3, 2026
Cherry pick #123239 to 26.8: Use skip indexes through lossless conversions of the indexed column
robot-clickhouse added a commit that referenced this pull request Oct 3, 2026
robot-ch-test-poll added a commit that referenced this pull request Oct 3, 2026
Cherry pick #123239 to 26.9: Use skip indexes through lossless conversions of the indexed column
robot-clickhouse added a commit that referenced this pull request Oct 3, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 3, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 3, 2026
Backport #123239 to 26.8: Use skip indexes through lossless conversions of the indexed column
clickhouse-gh Bot added a commit that referenced this pull request Oct 3, 2026
Backport #123239 to 26.9: Use skip indexes through lossless conversions of the indexed column
clickhouse-gh Bot added a commit that referenced this pull request Oct 3, 2026
Backport #123239 to 26.7: Use skip indexes through lossless conversions of the indexed column
@clickgapai

Copy link
Copy Markdown
Contributor

@CurtizJ — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 15, 2026
Since ClickHouse#123239, a query can use a text index on `s` through a lossless
conversion of it, e.g. `CAST(s, 'String') LIKE ...` over a
`LowCardinality(String)` column, or `toLowCardinality(s)` / `toNullable(s)`.
The conversion stays in the fallback expression, so evaluating it once per
read materializes a converted copy of the whole read instead of one granule.

Fall back to the per-granule evaluation when a fallback expression applies a
lossless conversion function directly to an input column. Measured on a debug
build (1M rows, `max_threads = 1`, `max_block_size = 65536`):
`CAST(lc, 'String') LIKE '%clickhouse%'` peak 36.84 MiB -> 33.10 MiB (same as
the unwrapped query), while `message LIKE '%clickhouse%'` keeps the per-read
path (FunctionExecute 80 vs 615 per granule).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements 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 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.

bloom_filter / tokenbf_v1 / ngrambf_v1 indexes are not used when the indexed column is wrapped in a lossless CAST

4 participants