Skip to content

Commit aec77f3

Browse files
committed
add fix for 9807
1 parent e787e8e commit aec77f3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

enginetest/queries/join_queries.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,22 @@ on w = 0;`,
792792
}
793793

794794
var JoinScriptTests = []ScriptTest{
795+
{
796+
// https://github.com/dolthub/dolt/issues/9807
797+
Name: "FULL OUTER JOIN fails with empty subquery",
798+
SetUpScript: []string{
799+
"CREATE TABLE t(c BOOLEAN);",
800+
"INSERT INTO t VALUES (FALSE);",
801+
},
802+
Assertions: []ScriptTestAssertion{
803+
{
804+
Query: "SELECT * FROM ( SELECT c FROM t WHERE c ) sub1 FULL OUTER JOIN ( SELECT 1 AS c ) sub2 ON 1=1;",
805+
Expected: []sql.Row{
806+
{nil, 1},
807+
},
808+
},
809+
},
810+
},
795811
{
796812
Name: "Simple join query",
797813
SetUpScript: []string{},

sql/rowexec/join_iters.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"io"
2121
"reflect"
2222

23+
"github.com/sirupsen/logrus"
2324
"go.opentelemetry.io/otel/attribute"
2425
"go.opentelemetry.io/otel/trace"
2526

@@ -405,6 +406,7 @@ func (i *existsIter) Close(ctx *sql.Context) (err error) {
405406
}
406407

407408
func newFullJoinIter(ctx *sql.Context, b sql.NodeExecBuilder, j *plan.JoinNode, row sql.Row) (sql.RowIter, error) {
409+
logrus.Info("full_join_prefix: Creating new full join iterator")
408410
leftIter, err := b.Build(ctx, j.Left(), row)
409411
if err != nil {
410412
return nil, err
@@ -447,11 +449,13 @@ type fullJoinIter struct {
447449
func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
448450
for {
449451
if i.leftDone {
452+
logrus.Info("full_join_prefix: Left side finished, entering right-only phase")
450453
break
451454
}
452455
if i.leftRow == nil {
453456
r, err := i.l.Next(ctx)
454457
if errors.Is(err, io.EOF) {
458+
logrus.Info("full_join_prefix: Left side exhausted, no more left rows")
455459
i.leftDone = true
456460
i.l = nil
457461
i.r = nil
@@ -487,6 +491,10 @@ func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
487491
}
488492
i.r = nil
489493
i.leftRow = nil
494+
continue
495+
}
496+
if err != nil {
497+
return nil, err
490498
}
491499

492500
row := i.buildRow(i.leftRow, rightRow)
@@ -512,7 +520,8 @@ func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
512520

513521
for {
514522
if i.r == nil {
515-
iter, err := i.b.Build(ctx, i.rp, i.leftRow)
523+
logrus.Info("full_join_prefix: Building right iterator for unmatched right rows")
524+
iter, err := i.b.Build(ctx, i.rp, i.parentRow)
516525
if err != nil {
517526
return nil, err
518527
}

0 commit comments

Comments
 (0)