Skip to content

Commit 728e219

Browse files
committed
do not convert full outer joins to cross joins
1 parent 44f3d60 commit 728e219

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

enginetest/join_op_tests.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,7 @@ WHERE
21812181
},
21822182
{
21832183
// https://github.com/dolthub/dolt/issues/9782
2184+
// https://github.com/dolthub/dolt/issues/9973
21842185
name: "joining with subquery on empty table",
21852186
setup: [][]string{
21862187
{
@@ -2205,6 +2206,14 @@ WHERE
22052206
Query: "SELECT t.c FROM (SELECT t.c FROM t WHERE FALSE) AS subq NATURAL RIGHT JOIN t;",
22062207
Expected: []sql.Row{{1}},
22072208
},
2209+
{
2210+
Query: "SELECT t.c FROM t FULL OUTER JOIN (SELECT t.c FROM t WHERE FALSE) AS subq ON TRUE;",
2211+
Expected: []sql.Row{{1}},
2212+
},
2213+
{
2214+
Query: "SELECT t.c FROM (SELECT t.c FROM t WHERE FALSE) AS subq FULL OUTER JOIN t ON TRUE;",
2215+
Expected: []sql.Row{{1}},
2216+
},
22082217
},
22092218
},
22102219
{

sql/planbuilder/from.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ func (b *Builder) isUsingJoin(te *ast.JoinTableExpr) bool {
7979
}
8080

8181
func (b *Builder) canConvertToCrossJoin(te *ast.JoinTableExpr) bool {
82-
return !strings.EqualFold(te.Join, ast.LeftJoinStr) &&
83-
!strings.EqualFold(te.Join, ast.RightJoinStr) &&
84-
(te.Condition.On == nil || te.Condition.On == ast.BoolVal(true)) &&
85-
te.Condition.Using == nil
82+
switch te.Join {
83+
case ast.LeftJoinStr, ast.RightJoinStr, ast.FullOuterJoinStr:
84+
return false
85+
default:
86+
return (te.Condition.On == nil || te.Condition.On == ast.BoolVal(true)) &&
87+
te.Condition.Using == nil
88+
}
8689
}
8790

8891
func (b *Builder) buildJoin(inScope *scope, te *ast.JoinTableExpr) (outScope *scope) {

0 commit comments

Comments
 (0)