Skip to content

branch-4.1: [fix](fe) Fix duplicate join nodes in PushDownAggThroughJoinOnPkFk tree reconstruction #65172#65466

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-65172-branch-4.1
Open

branch-4.1: [fix](fe) Fix duplicate join nodes in PushDownAggThroughJoinOnPkFk tree reconstruction #65172#65466
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-65172-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #65172

…ee reconstruction (#65172)

### What problem does this PR solve?

Related PR: #36035

Problem Summary:
This PR fixes two bugs in the PushDownAggThroughJoinOnPkFk rule that handles
pushing aggregates through joins using PK-FK constraints on multi-table joins.

**Bug 1: Duplicate join nodes in tree reconstruction**

When `constructPlan` rebuilt a subtree from flattened inner joins, the merge
path did `currentPlan.withChildren(currentPlan, entryJoin)`, which inserted
`currentPlan` as a child of itself and also kept `entryJoin` with its original
two children. This produced duplicate join nodes and duplicate leaf references
in the resulting plan tree. The fix computes the new leaf set (`newBits
= entryBitset - currentBitset`) and only attaches the genuinely new child,
using `entryJoin.withChildren(newChild, currentPlan)` instead.

**Bug 2: First ineligible PK-FK edge aborts the entire rule**

`pushAgg` iterates all flattened PK-FK edges, but when `eliminatePrimaryOutput`
returned null for an earlier edge, the code did `return null` — aborting
the whole rule instead of continuing to try later edges. Since
`HashMap<BitSet>` iteration order on Java 17 visits the lower `{t_primary, t_foreign1}`
edge before the root `{t_other_primary, t_primary}` edge, a query aggregating
a primary-side column (e.g., `SUM(t_primary.pk_id)`) would fail on the
first edge and never reach the valid root edge. Fixed by changing `return
null` to `continue`.
@github-actions github-actions Bot requested a review from yiguolei as a code owner July 10, 2026 10:22
@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?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

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.

2 participants