Repository navigation
Conversation
A read with `apply_deleted_mask = 0` sees lightweight-deleted rows, so a granule whose only matching rows are deleted is "no match" for an ordinary read and "may match" for that one. The two verdicts are not interchangeable, yet they shared a cache key: `(table uuid, part name, condition hash)`. Give the two their own key spaces instead. The salt is mixed in only when the mask is off, so the keys of ordinary reads are unchanged and no entry is invalidated. `read` and `write` take the flag explicitly so every call site has to name what it means; file- and object-storage tables have no deleted rows and pass true. This also makes it unnecessary to keep such queries out of the cache altogether, which is what #112947 does as the cheap, backportable version of the same guarantee.
Contributor
|
Workflow [PR], commit [a239b7c] Summary: ❌
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #112947
Related: #107145
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Query condition cache entries are now keyed by
apply_deleted_mask, so reads that show lightweight-deleted rows and ordinary reads no longer share entries.Description
A read with
apply_deleted_mask = 0sees lightweight-deleted rows. A granule whose only matching rows are deleted is therefore "no match" for an ordinary read and "may match" for that one, and the two verdicts are not interchangeable. They shared a cache key all the same:(table uuid, part name, condition hash).Only one direction is unsound. An entry written by an ordinary read, consumed by an
apply_deleted_mask = 0read, makes it skip a granule holding exactly the deleted rows it was asked to return. The reverse is conservative: the writer saw a superset of the rows, so its "no match" still holds.The fix
QueryConditionCache::makeKeymixes the flag into the key, so the two get separate key spaces. The salt is added only when the mask is off, which leaves the keys of ordinary reads byte-identical and invalidates nothing on upgrade.readandwritetake the flag explicitly rather than each site salting its own condition hash. Three places compute a condition hash independently (index analysis inReadFromMergeTree, the PREWHERE write inMergeTreeSelectProcessor, the consult inMergeTreeDataSelectExecutor) and a fourth writes throughMarkRangesInfoattached to the chunk. Salting at each of them means a missed site is a silent wrong-results bug; making it a parameter means a missed site does not compile.MarkRangesInfocarries the flag fromMergeTreeSelectProcessortoFilterTransformfor the WHERE write.File- and object-storage tables have no deleted rows and pass
true.Relationship to #112947
That PR needs the same guarantee and takes the cheap route: queries with
apply_deleted_mask = 0neither read nor write the cache. That is the right shape for a backport (it is three lines and cannot regress anything), and it is what should ship to 26.3/26.4/26.5.This is the version for
master: nothing has to be excluded, soapply_deleted_mask = 0keeps its pruning. The two are not independent at the end state, and the order matters. Whichever of them merges second has to remove #112947's two gates (inMergeTreeIOSettingsandMergeTreeDataSelectExecutor) and flip the block in04669_query_condition_cache_lightweight_deletethat pins the no-caching behaviour. Left in place, those gates keepapply_deleted_mask = 0out of the cache and the last assertion of04700_query_condition_cache_apply_deleted_mask(a repeatedapply_deleted_mask = 0query prunes) fails. Landing #112947 first and removing its gates here is the cleaner sequence.Tests
New
04700_query_condition_cache_apply_deleted_mask:apply_deleted_mask = 0entry (fails before this change: it hits and prunes)apply_deleted_mask = 0read still prunes on a repeat within its own key space