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
Open
branch-4.1: [fix](fe) Fix duplicate join nodes in PushDownAggThroughJoinOnPkFk tree reconstruction #65172#65466github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…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`.
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
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 #65172