feat(query): push Row Access Policy predicates into prewhere for storage-level pruning#19875
Merged
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0fec6b30b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
94f38be to
02f6ab1
Compare
b41sh
approved these changes
May 19, 2026
When row access policy predicates are pushed into storage-level filtering, EXPLAIN output now shows "secure_filters: REDACTED" to indicate their participation without leaking the policy expression. Previously the secure predicates were completely hidden from EXPLAIN, making it impossible to tell whether RAP was participating in pushdown.
zhang2014
requested changes
May 20, 2026
Member
zhang2014
left a comment
There was a problem hiding this comment.
Relevant tests need to be added to prevent regressions.
zhang2014
approved these changes
May 20, 2026
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.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Enable Row Access Policy (RAP) predicates to participate in storage-level pushdown optimizations (range pruning, bloom pruning, prewhere row selection) instead of being enforced only by a post-scan Filter [SECURE] operator.
Previously, secure predicates were merged into a single combined
filtersfield inPushDownInfo, which made them invisible in EXPLAIN and prevented fine-grained control. This PR separates them into a dedicatedsecure_filtersfield, useseffective_filters()to combine them at the storage layer for pruning, and introduceshas_secure_predicates_not_applied_by_prewhere()as the safety gate for limit/sort pushdown.Changes
Optimizer
RulePushDownPrewherenow matches bareScannodes (not justFilter -> Scan) and pushes secure predicates into prewhere viasecure_prewhere_optimize().RulePushDownLimitScan,RulePushDownSortScan,RulePushDownLimitFilterScan,RulePushDownSortFilterScan) usehas_secure_predicates_not_applied_by_prewhere()instead of blanket bail-out.Physical plan
PushDownInfogains asecure_filters: Option<Filters>field, kept separate from userfiltersfor display redaction.effective_filters()combines user + secure filters with AND for storage-layer consumption (range pruner, bloom pruner).is_deterministicis now derived from individual user/secure computations instead of a redundant combined call.Storage
FusePrunerandread_partitionsuseeffective_filters()for range/bloom pruning, ensuring RAP expressions participate in block-level index pruning.secure_filters.is_none()to maintain correctness (same behavior as with regular WHERE filters).Display
secure_filters: REDACTEDto indicate RAP participation without leaking policy expressions.Other
ResultCacheWriter::append_blockcallsmaybe_gc()to reclaim memory from filtered blocks before caching.Tests
Type of change
This change is