Skip to content

branch-4.1: [fix](nereids) Block push-down of filters containing unique functions through Generate and CTE consumer #62705#62734

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-62705-branch-4.1
Apr 23, 2026
Merged

branch-4.1: [fix](nereids) Block push-down of filters containing unique functions through Generate and CTE consumer #62705#62734
yiguolei merged 1 commit into
branch-4.1from
auto-pick-62705-branch-4.1

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Cherry-picked from #62705

… 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.
@github-actions github-actions Bot requested a review from yiguolei as a code owner April 23, 2026 02:36
@Thearas
Copy link
Copy Markdown
Contributor

Thearas commented Apr 23, 2026

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?

@dataroaring dataroaring reopened this Apr 23, 2026
@Thearas
Copy link
Copy Markdown
Contributor

Thearas commented Apr 23, 2026

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 3.33% (4/120) 🎉
Increment coverage report
Complete coverage report

@yiguolei yiguolei merged commit 33baee5 into branch-4.1 Apr 23, 2026
29 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants