Commit bc1ceeb
committed
Support LEFT OUTER JOIN
This change introduces support for LEFT OUTER JOIN.
To this end we introduce a dedicated QGM box (`OuterJoinExpression`) to
represent one outer join. It is strictly binary (unlike the SELECT box)
and carries the join type (LEFT/RIGHT/FULL), the ON-clause predicates,
and a reference to the “preserved” and the “null-supplying” quantifier.
During planning, an exploration rule `RewriteOuterJoinRule` eliminates
the outer join box by rewriting it into two nested select boxes. The
preserved (left) side is connected to the outer `SelectExpression`
through a normal FOREACH quantifier. The null-supplying (right) side is
wrapped in an inner `SelectExpression` that carries the ON predicates
and is connected through a FOREACH quantifier with `nullOnEmpty` set to
true. This rewrite happens early during planning so that existing rules
(predicate push-down, join ordering, implementation) take care of
implementing the join and optimizing it without further modification.
Key changes:
* `OuterJoinExpression` represents the OUTER JOIN in the QGM.
* `QueryVisitor` parses the LEFT OUTER JOIN syntax and constructs
the logical `OuterJoinExpression` via `wrapOperandsForOuterJoin()`.
* `RewriteOuterJoinRule` rewrites the `OuterJoinExpression` into nested
`SelectExpression` boxes.
* Also extend `SelectMergeRule` to exclude `OuterJoinExpression` from
merge candidates. This prevents WHERE predicates from being absorbed
into the join and interfering with outer join semantics.
* Include `OuterJoinExpression` in `ExpressionCountProperty.selectCount`
so that branches containing outer joins are counted correctly when
evaluating merge candidates.
Testing:
* `join-tests-outer.yamsql` integration tests.1 parent c2f2e14 commit bc1ceeb
15 files changed
Lines changed: 2317 additions & 39 deletions
File tree
- fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades
- expressions
- matching/structure
- properties
- rules
- fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/query
- visitors
- yaml-tests/src/test
- java
- resources
Lines changed: 17 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
508 | 524 | | |
509 | 525 | | |
510 | 526 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
| 114 | + | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
0 commit comments