Repository navigation
Fix missing rows from JOIN runtime filter index analysis when the probe key nests a CAST - #128128
Conversation
…ast keys With `ON CAST(p.k AS UInt8) = b.k` and `b.k UInt64`, the analyzer unifies the key types and the probe key becomes `_CAST(CAST(k, 'UInt8'), 'UInt64')`. `findAppliedRuntimeFilters` looked through every cast and reported the bare column `k`, while `convertRuntimeFilterToKeyConditionDAG` re-applies at most one cast, to the filter's target type. The read-time pruning predicate was then `k IN (16)` instead of `CAST(k, 'UInt8') IN (16)`, and every granule without the raw value 16 was dropped. This affected read-time primary key pruning, skip indexes and seal-gated reading, which all consume the same descriptors. The outermost cast on the `__applyFilter` argument always has the filter's element type, so a key under zero or one cast is rebuilt exactly. Count the casts and do not report a key under more than one: such a key is not used for index pruning, and the row-level filter still applies. Common type-mismatch keys (`UInt32` vs `UInt64`, `Date` vs `DateTime`, `LowCardinality(String)` vs `String`) carry one cast and keep their pruning. Closes ClickHouse#124679 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (1 more nit). No blocker or major findings.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261029-093100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261029-090700 |
|
cc @KochetovNicolai @davenger, could you review this and add the |
|
Workflow [PR], commit [0d11118] Summary: ✅
AI ReviewSummaryPR #128128 fixes missing Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - fd81ec3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261029-160007 |
- Drop the nested-cast flag from RuntimeFilterIndexAnalysisDescriptor: ClickHouse#128128 leaves a key under two casts out of findAppliedRuntimeFilters for every reader, so the object storage read needs no special case. - Annotate RuntimeFilterFilePruning state with TSA_GUARDED_BY, split the pruner emplace, rename unusable to no_pruning_predicate. - Add the RuntimeFilterIndexAnalysisDescriptors alias. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Yes. Both change the same cast-stripping loop in The rules differ:
So whichever lands second has to change one test: 05457 My suggestion: merge #128128 as the bug fix (it has |
Backport #128128 to 26.10: Fix missing rows from JOIN runtime filter index analysis when the probe key nests a CAST
…index analysis when the probe key nests a CAST
Closes: #124679
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed missing rows in a
JOINwhose probe-side key is a narrowingCASTof an indexed column compared with a key of a wider type, for exampleON CAST(t.k AS UInt8) = d.kwithd.kof typeUInt64: the JOIN runtime filter pruned granules by the column value without the inner cast. Such keys are no longer used for primary key, skip index or seal-gated pruning.Description
On 26.9.19.9 with
enable_join_runtime_filters_index_analysis = 1(the default in 26.10),SELECT count() FROM probe AS p JOIN build AS b ON CAST(p.k AS UInt8) = b.k, withprobeordered byk UInt64(values 0..4095) and one build rowb.k = 16of typeUInt64, returns 1 instead of 16.CAST(p.ts AS Date) = b.dwith aDateTimebuild key loses rows the same way.The analyzer unifies the key types, so the probe key becomes
_CAST(CAST(k, 'UInt8'), 'UInt64').findAppliedRuntimeFilterslooked through every cast and reported the bare columnk, and the read-time pruning predicate re-applies at most one cast, to the filter type (none here), so it pruned byk IN (16)instead ofCAST(k, 'UInt8') IN (16). The row-level__applyFilterwas correct; only the index pruning was wrong.findAppliedRuntimeFiltersnow counts the casts it looks through and does not report a key under more than one. That covers every consumer: read-time primary key pruning, skip indexes and seal-gated reading. A single cast to the filter type is rebuilt exactly, so keys likeUInt32vsUInt64,DatevsDateTime,LowCardinality(String)vsStringandNullablekeys keep their pruning.Validation: the new test fails on master (20/20 randomized runs) and passes with the fix (50/50); its last arm checks that a single-cast key still prunes granules, and fails if no cast is allowed. The existing runtime filter tests behave as on master.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128128]
Version info
26.11.1.1824-master(included in26.11and later)