From 728e219b776e1ee93918d012dd7da22a3658507d Mon Sep 17 00:00:00 2001 From: Angela Xie Date: Mon, 20 Oct 2025 11:25:22 -0700 Subject: [PATCH] do not convert full outer joins to cross joins --- enginetest/join_op_tests.go | 9 +++++++++ sql/planbuilder/from.go | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/enginetest/join_op_tests.go b/enginetest/join_op_tests.go index 22bb667e1a..e2095c4448 100644 --- a/enginetest/join_op_tests.go +++ b/enginetest/join_op_tests.go @@ -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{ { @@ -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}}, + }, }, }, { diff --git a/sql/planbuilder/from.go b/sql/planbuilder/from.go index d125e8914a..8df135a69e 100644 --- a/sql/planbuilder/from.go +++ b/sql/planbuilder/from.go @@ -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) {