Skip to content

branch-4.0: [fix](nereids) Guard UniqueFunction in multiple filter/topn pushdown rules #62742 - #65259

Merged
morningman merged 3 commits into
apache:branch-4.0from
yujun777:pick-pr-62742
Jul 23, 2026
Merged

branch-4.0: [fix](nereids) Guard UniqueFunction in multiple filter/topn pushdown rules #62742#65259
morningman merged 3 commits into
apache:branch-4.0from
yujun777:pick-pr-62742

Conversation

@yujun777

Copy link
Copy Markdown
Contributor

cherry-pick: #62742

yujun777and others added 2 commits July 6, 2026 16:34
…rules (apache#62742)
Problem Summary:
Several Nereids rewrite rules still moved predicates
containing non-idempotent (unique) functions such as rand() / uuid() /
random_bytes() across operator boundaries in ways that changed query
semantics. The common root cause is that a predicate like `rand() > 0.5`
has an empty input-slot set, so the `containsAll(emptySet)` / `allMatch`
guards used by these rules silently returned true and allowed unsafe
push
down / elimination.
This PR adds `containsUniqueFunction()` guards to the following rules:
1. PushDownFilterThroughRepeat: skip conjuncts with unique functions.
Pushing `rand() > x` below Repeat changes which rows feed each
grouping set and alters aggregate results.
2. PushDownFilterThroughWindow: skip conjuncts with unique functions.
Pushing a unique predicate below a window operator re-samples the
base rows and changes every window-function value.
3. PushDownFilterThroughPartitionTopN: same as Window - skip unique
conjuncts in the split loop.
4. PushDownFilterThroughSetOperation: do not push volatile conjuncts
below `UNION DISTINCT`, `INTERSECT`, or `EXCEPT`; only `UNION ALL`
keeps the original row-to-row semantics.
5. PushDownJoinOtherCondition: keep volatile ON predicates in the join
when pushing them into a single child would change evaluation from
per joined pair to per input row.
6. AddProjectForVolatileExpression: when a volatile expression is
repeated after rewrites such as BETWEEN expansion, materialize it via
a child project so repeated references share one value instead of
being re-evaluated independently.
7. InferPredicates / JoinUtils.isHashJoinCondition: add the same unique
function guards to avoid deriving or classifying unsafe predicates.
Fix wrong results when predicates containing rand(), uuid(),
random_bytes(), or uuid_numeric() are pushed across Repeat, Window,
PartitionTopN, SetOperation, or Join boundaries, and when repeated
volatile expressions are materialized for reuse.
---------
Co-authored-by: yujun777 <yujun777@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 8255f94)
Backport the unique-function guard changes from apache#62742 onto branch-4.0 and align the affected rewrite rules with 4.0-specific unique-function semantics.
Key changes:
- replace the unsupported volatile-expression checks in the touched 4.0 rewrite paths with unique-function checks
- adapt AddProjectForUniqueFunction join rewriting to use UniqueFunction in 4.0
- keep PushDownFilterThroughSetOperation conservative on 4.0 by not pushing unique-function predicates through set operations, including UNION ALL
- update the affected regression suite/output for the 4.0 set-operation behavior
Unit Test:
- FE UT: AddProjectForUniqueFunctionTest, FindHashConditionForJoinTest, PushDownFilterThroughWindowTest, PushDownJoinOtherConditionTest, PushDownFilterThroughSetOperationTest, ProjectOtherJoinConditionForNestedLoopJoinTest, InferPredicatesTest, JoinUtilsTest
- Regression: regression-test/suites/nereids_rules_p0/unique_function with -forceGenOut
- Regression: regression-test/suites/nereids_rules_p0/infer_predicate/extend_infer_equal_predicate.groovy with -forceGenOut
@yujun777
yujun777 requested a review from morningman as a code ownerJuly 6, 2026 09:15
@yujun777

Copy link
Copy Markdown
ContributorAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@yujun777

Copy link
Copy Markdown
ContributorAuthor

run buildall

@yujun777

Copy link
Copy Markdown
ContributorAuthor

run cloud_p0

@github-actionsgithub-actionsBot added the approved Indicates a PR has been approved by one committer. label Jul 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@morningman
morningman merged commit 2149e46 into apache:branch-4.0Jul 23, 2026
27 of 31 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approvedIndicates a PR has been approved by one committer.reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@yujun777@hello-stephen@morningman