{{ message }}
branch-4.0: [fix](nereids) Backport unique-function filter push-down guards (#62705)#62750
Open
yujun777 wants to merge 2 commits intoapache:branch-4.0from
Open
branch-4.0: [fix](nereids) Backport unique-function filter push-down guards (#62705)#62750yujun777 wants to merge 2 commits intoapache:branch-4.0from
yujun777 wants to merge 2 commits intoapache:branch-4.0from
Conversation
… through Generate and CTE consumer (apache#62705) Issue Number: close apache#25201, close apache#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. (cherry picked from commit 55ee1fa)
Keep the PR apache#62705 backport test compatible with branch-4.0 by using ExplodeNumbers instead of the newer Unnest generator. Key changes: - replace Unnest with ExplodeNumbers in PushDownFilterThroughGenerateTest Unit Test: - ./build.sh --fe --clean -j20 - ./run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.PushDownFilterThroughGenerateTest,org.apache.doris.nereids.rules.rewrite.CollectFilterAboveConsumerTest
Contributor
Author
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
/review |
Contributor
There was a problem hiding this comment.
Review summary:
- Correctness: no blocking issue found. The two changed rewrites now consistently leave
UniqueFunctionconjuncts aboveGenerate/ CTE-consumer boundaries, which matches the intended semantics and avoids the wrong-result cases described in the PR. - Backport fidelity: the code changes match upstream PR #62705, with the expected branch-4.0-only unit-test adaptation from
UnnesttoExplodeNumbers. - Tests: the new FE unit tests and regression shape tests cover the target scenarios (pure unique-function predicates and mixed deterministic/unique conjuncts). I could not fully execute the FE unit-test command in this runner because
thirdparty/installed/bin/protocis missing from the environment, so runtime verification here was limited to code inspection plus the added coverage. - Release note / docs: the PR body includes a release note, and I do not see additional documentation changes needed for this optimizer correctness fix.
- User focus: no additional user-provided review focus was supplied.
I did not find a critical blocking issue in this PR.
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
Author
|
run cloud_p0 |
Contributor
Author
|
run p0 |
Contributor
Author
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.

What problem does this PR solve?
Backport of #62705 to branch-4.0.
Problem Summary:
Release note
Fix wrong results on branch-4.0 when filters containing non-idempotent functions are pushed through Generate or CTE consumer.
Check List (For Author)