branch-4.1: [fix](nereids) Block push-down of filters containing unique functions through Generate and CTE consumer #62705#62734
Merged
Conversation
… through Generate and CTE consumer (#62705) Issue Number: close #25201, close #25202 Problem Summary: Two Nereids rewrite rules moved filter conjuncts that contain non-idempotent `UniqueFunction` calls (`rand` / `uuid` / `random_bytes` / `uuid_numeric`) across operators that change how many times the unique function is evaluated, producing wrong results. 1. `PushDownFilterThroughGenerate` pushed a conjunct like `t1.id + rand(1,100) > 5` below `LogicalGenerate`. Before the push, `rand` is evaluated per generated row; after, it is evaluated per base row and then the result is duplicated for every row produced by generate, so groups of N generated rows share a single rand value instead of N independent ones. 2. `CollectFilterAboveConsumer` registered filter conjuncts above a CTE consumer into `cascadesContext.putConsumerIdToFilter(...)`, after which `RewriteCteChildren.tryToConstructFilter` would OR them up and push them into the CTE producer. For a conjunct like `rand() > 0.1`, that causes the random filter to run on both the producer scan and each consumer filter, and different consumers would see inconsistent rows. Fix: in both rules, skip conjuncts whose `containsUniqueFunction()` is true so they stay above the operator and are evaluated once per output row. Adjacent rules (`PushDownFilterThroughRepeat/Window/PartitionTopN/SetOperation`, `PullUpPredicates` and its consumers) have the same class of bug but are out of scope for this PR and will be addressed separately.
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
FE Regression Coverage ReportIncrement line coverage |
yiguolei
approved these changes
Apr 23, 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.
Cherry-picked from #62705