Skip to content

branch-4.0: [fix](mark join) Fix invalid semi-join transpose when the bottom join is a mark join #66574 - #66621

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

branch-4.0: [fix](mark join) Fix invalid semi-join transpose when the bottom join is a mark join #66574#66621
github-actions[bot] wants to merge 1 commit into
branch-4.0from
auto-pick-66574-branch-4.0

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #66574

… is a mark join (#66574)

### What problem does this PR solve?

Problem Summary:
A query with a subquery inside the ON condition of an anti join failed at
physical planning with "A expression contains slot not from children", e.g.:

```sql
SELECT t1.* FROM t1 LEFT ANTI JOIN t2
    ON t1.k2 = t2.k3 AND t1.k1 NOT IN (SELECT t3.k1 FROM t3 WHERE t1.k2 = t3.k2);
```

The subquery is unnested into a mark join `(t1 LEFT ANTI JOIN t3)` that produces
a mark slot, and the outer anti join references the mark slot in its conjuncts.
Root cause: the exploration rule `SemiJoinSemiJoinTransposeProject` transposes
two nested left semi/anti joins `(A ⟕̸ B) ⟕̸ C` into `(A ⟕̸ C) ⟕̸ B`. 
When the bottom join `(A ⟕̸ B)` is a mark join, the transposed plan builds
`newBottomSemi = (A ⟕̸ C)` from the top join, inheriting the top join's conjuncts
that reference the bottom mark slot, while the mark slot is now produced above by
the new top mark join. The mark slot is therefore referenced by a join whose
children don't output it, and physical planning fails with "slot not from children". 

The fix rejects the transpose when the bottom semi join is a mark join and the
top semi join references the bottom mark slot in its conjuncts, so the mark join
is always kept below the join that consumes the mark slot. After the fix the
query above executes correctly and returns the expected result.
@github-actions
github-actions Bot requested a review from morningman as a code owner August 10, 2026 11:50
@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

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (9/9) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (9/9) 🎉
Increment coverage report
Complete coverage report

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