Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions enginetest/join_op_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,7 @@ WHERE
},
{
// https://github.com/dolthub/dolt/issues/9782
// https://github.com/dolthub/dolt/issues/9973
name: "joining with subquery on empty table",
setup: [][]string{
{
Expand All @@ -2205,6 +2206,14 @@ WHERE
Query: "SELECT t.c FROM (SELECT t.c FROM t WHERE FALSE) AS subq NATURAL RIGHT JOIN t;",
Expected: []sql.Row{{1}},
},
{
Query: "SELECT t.c FROM t FULL OUTER JOIN (SELECT t.c FROM t WHERE FALSE) AS subq ON TRUE;",
Expected: []sql.Row{{1}},
},
{
Query: "SELECT t.c FROM (SELECT t.c FROM t WHERE FALSE) AS subq FULL OUTER JOIN t ON TRUE;",
Expected: []sql.Row{{1}},
},
},
},
{
Expand Down
11 changes: 7 additions & 4 deletions sql/planbuilder/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ func (b *Builder) isUsingJoin(te *ast.JoinTableExpr) bool {
}

func (b *Builder) canConvertToCrossJoin(te *ast.JoinTableExpr) bool {
return !strings.EqualFold(te.Join, ast.LeftJoinStr) &&
!strings.EqualFold(te.Join, ast.RightJoinStr) &&
(te.Condition.On == nil || te.Condition.On == ast.BoolVal(true)) &&
te.Condition.Using == nil
switch te.Join {
case ast.LeftJoinStr, ast.RightJoinStr, ast.FullOuterJoinStr:
return false
default:
return (te.Condition.On == nil || te.Condition.On == ast.BoolVal(true)) &&
te.Condition.Using == nil
}
}

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