englefly opened a new pull request, #66535:
URL: https://github.com/apache/doris/pull/66535
### What problem does this PR solve?
Issue Number: N/A
Problem Summary: For queries like
`select distinct a1.* from a1, a5 where a1.lot_id = a5.lot_id and a1.ope_no
= a5.ope_no and ...`
where the right side table of an inner join only appears in equal join
conditions
(never in the output or any other expression), the inner join acts purely as
an
existence filter: it only decides which left rows are kept. Such an inner
join can
be safely rewritten to a left semi join, which keeps the output row count at
the
left side cardinality instead of multiplying it by the average number of
right side
matches, and lets the right side scan/broadcast only the join key columns.
The conversion is guarded by three conditions, all checked by the new
`ConvertInnerJoinToSemiJoin` RBO rule:
1. the right side columns of the join are not referenced above the join
(the aggregate/project above only consumes left side columns);
2. all join conditions are equal conjuncts (hashJoinConjuncts non-empty,
otherJoinConjuncts empty; `<=>` NullSafeEqual is also covered since it is
an
EqualPredicate extracted into hashJoinConjuncts by
FindHashConditionForJoin);
3. there is a deduplication guarantee above the join (a DISTINCT-like
aggregate
whose group-by keys cover exactly its output columns), so the row
multiplication
of an inner join does not change the final result.
The rule is registered in the RBO rewrite phase "eliminate join according
unique or
foreign key" (after infer predicate / push down distinct, before push down
limit).
### Release note
None
### Check List (For Author)
- Test: Unit Test (ConvertInnerJoinToSemiJoinTest, 6 cases: convert with
DISTINCT,
convert with `<=>`, not convert when right columns leak / no distinct /
non-equi
condition / aggregate function; sibling join-rule tests pass, no
regression)
- Behavior changed: No
- Does this need documentation: No
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]