Repository navigation
Conversation
|
The per-part guard here structurally misses the rename shape of the same bug, which I have just filed as #117323 (verified on 26.8 and a current master build): with a pending Two reasons the fix as written cannot catch it:
Since the guard machinery is being introduced here, it may be worth widening it in the same change: also skip pruning for a part when |
ddcfc6e to
2dc59d9
Compare
Thanks for catching this — the rename shape was indeed outside the per-part guard. |
|
Workflow [PR], commit [80a2a76b] Summary: ❌
AI ReviewSummaryThis PR broadens the stale-part fail-open handling across statistics pruning, skip-index pruning, text-index direct reads, trivial-count defaultness stats, and the query condition cache for pending Findings
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 80a2a76b.
Changed lines: Changed C/C++ lines covered: 168/175 (96.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units374 translation units recompiled, 3414 s compile time in total, 374 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…me, or drop mutations
2dc59d9 to
404e524
Compare
…o fix-statistics-part-pruning-pending-alter-mutation
…t path The read-time top-k path (`use_skip_indexes_for_top_k` + `use_skip_indexes_on_data_read`, both on by default) fills `MergeTreeIndexReadResult::min_max_index_for_top_k` unconditionally in `MergeTreeSkipIndexReader::read` and lets `canSkipMark` drop granules against the running threshold. A pending ALTER that touches the indexed column leaves the part's minmax stale, so the granule holding the live top rows can be silently dropped once another part establishes the threshold. Reuse `MergeTreeDataSelectExecutor::canUseIndex` — the same per-part staleness check the upfront top-k path (`partHasStaleTopKIndex`) and the regular skip-index path in the same function already use — to skip the minmax build for stale parts. Without a minmax, `canSkipMark` leaves the part alone and the read returns correct results. Covers the two-command pending ALTER shape `(DROP COLUMN x), (RENAME COLUMN y TO x)`, where the read-time path would otherwise return the live part's smaller value instead of the decoy's true top value. Regression test: 05056_skip_index_stale_top_k_pending_alter.
…o fix-statistics-part-pruning-pending-alter-mutation
`filterPartsByQueryConditionCache` consulted entries primed before a pending ALTER because its gate only covered data mutations and patch parts. A pending metadata mutation (DROP / RENAME / ADD reusing a name) rewrites the rows a part holds under an unchanged name, so a stale verdict could erase parts before the live read path sees the new rows. Gate the index-analysis consult and both `reader_settings` enables in `ReadFromMergeTree` on any pending mutations, mirroring the existing data-mutation handling. The reader-side gate also stops priming new entries during the pending window. Covered by 05077: priming the cache with the pre-ALTER predicate, then rerunning it under a pending (DROP + re-ADD) and (DROP + RENAME).
The gate added in the previous commit disabled cache reads and writes for any pending mutation, including data mutations. Priming under a pending mutation of an unread column must keep working: `filterMutationCommands` drops UPDATE commands touching none of the columns the query reads, so such a mutation produces no on-fly mutation steps and the per-part write gate (`appliesMutationsBeforePrewhere`) correctly allows cache writes. The broad gate broke that contract and failed 04669_query_condition_cache_lightweight_delete. Keep the write-side gate (both `reader_settings` sites in `ReadFromMergeTree`) to metadata and alter mutations only: DROP / RENAME / ADD reuse names without producing on-fly mutation steps, so the per-part gate never fires for them. The consult gate in `filterPartsByQueryConditionCache` keeps bailing out on any pending mutation. Verified: 04669 5/5 OK (failed 5/5 before the fix, same diff as CI), 05077 5/5 OK, 05045 / 05055 / 05056 / 05058 / 05076 OK. CI: https://github.com/ClickHouse/ClickHouse/actions/runs/34188868167/job/101942890874 PR: ClickHouse#117320
| if (dynamic_skip_index_filter && !dynamic_skip_index_filter(*index_helper)) | ||
| continue; | ||
| if (auto can_use = MergeTreeDataSelectExecutor::canUseIndex(index_helper, metadata_snapshot, all_updated_columns); !can_use) | ||
| if (auto can_use = MergeTreeDataSelectExecutor::canUseIndex(index_helper, metadata_snapshot, alter_conversions); !can_use) |
There was a problem hiding this comment.
This new canUseIndex(..., alter_conversions) check hardens the runtime skip-index branch, but the sibling prune_primary_key block just above still prunes on the physical PK without consulting alter_conversions.
That leaves a wrong-result path for Cloud masking policies. buildReadTaskInfo already turns those policies into synthetic READ_COLUMN conversions, so the dynamic skip-index path now correctly fails open here, but markRangesFromPKRange still sees the unmasked key. A concrete trace is a table ORDER BY x with a masking policy rewriting x to 0 for the querying user and a join runtime filter x IN (0): the query should keep every row, but the runtime PK pruning drops the part because the stored PK contains only the original non-zero values.
Please either disable runtime_prune_primary_key when part->storage.hasEnabledMaskingPolicies(context) is true, or teach the PK path to apply the same stale-column contract before calling markRangesFromPKRange.
Closes: #116627
Closes: #117323
Statistics- and skip-index-based part pruning look up a part's min/max by the queried column name. That is only valid while the part's data behind that name is what a read of the name returns. Three pending on-the-fly mutations break this assumption, and the original guard covered just the first one:
ALTER MODIFY COLUMNconverts values on read, so the stored min/max describe the old type.ALTER RENAME COLUMNre-points the name at a different column, so the statistics describe another column.ALTER DROP COLUMNmakes the part's data for the name invisible on read. The name is only visible to the query because it was re-added after the drop, so the statistics describe a column the query cannot see.RENAME and DROP do not enter
all_updated_columns, and pure metadata mutations do not sethasAlterMutations(), so the two extra forms slipped through every pruning path built on those checks.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix silently missing rows when pruning parts by statistics or skip indexes on a column with a pending ALTER.
Workflow [PR]
Sync PR [sync-upstream/pr/117320]