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
55 changes: 55 additions & 0 deletions enginetest/join_op_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,61 @@ var EngineOnlyJoinOpTests = []joinOpTest{
}

var DefaultJoinOpTests = []joinOpTest{
{
// https://github.com/dolthub/dolt/issues/9807
name: "FULL OUTER JOIN fails with empty subquery",
setup: [][]string{
{
"CREATE TABLE t(c BOOLEAN);",
"INSERT INTO t VALUES (FALSE);",
},
},
tests: []JoinOpTests{
{
Query: "SELECT * FROM ( SELECT c FROM t WHERE c ) sub1 FULL OUTER JOIN ( SELECT 1 AS c ) sub2 ON 1=1;",
Expected: []sql.Row{
{nil, 1},
},
},
},
},
{
// https://github.com/dolthub/dolt/issues/9807
name: "FULL OUTER JOIN with empty tables",
setup: [][]string{
{
"CREATE TABLE t1 (i INT);",
"CREATE TABLE t2 (j INT);",
"INSERT INTO t2 VALUES (1);",
},
},
tests: []JoinOpTests{
{
Query: "SELECT i, j FROM t1 FULL OUTER JOIN t2 ON 1=1;",
Expected: []sql.Row{
{nil, 1},
},
},
{
Query: "SELECT j, i FROM t2 FULL OUTER JOIN t1 ON 1=1;",
Expected: []sql.Row{
{1, nil},
},
},
{
Query: "SELECT i, j FROM t1 FULL OUTER JOIN t2 ON 1=0;",
Expected: []sql.Row{
{nil, 1},
},
},
{
Query: "SELECT j, i FROM t2 FULL OUTER JOIN t1 ON 1=0;",
Expected: []sql.Row{
{1, nil},
},
},
},
},
{
name: "bug where transitive join edge drops filters",
setup: [][]string{
Expand Down
8 changes: 7 additions & 1 deletion sql/rowexec/join_iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
}
i.r = nil
i.leftRow = nil
continue
}
if err != nil {
return nil, err
}

row := i.buildRow(i.leftRow, rightRow)
Expand All @@ -512,7 +516,9 @@ func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {

for {
if i.r == nil {
iter, err := i.b.Build(ctx, i.rp, i.leftRow)
// Phase 2 of FULL OUTER JOIN: return unmatched right rows as (null, rightRow).
// Use parentRow instead of leftRow since leftRow is nil when left side is empty.
iter, err := i.b.Build(ctx, i.rp, i.parentRow)
if err != nil {
return nil, err
}
Expand Down
Loading