Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rowexec] full outer join rightIter exhaust #2814

Merged
merged 2 commits into from
Jan 13, 2025
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
29 changes: 29 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,35 @@ type ScriptTestAssertion struct {
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
// the tests.
var ScriptTests = []ScriptTest{
{
Name: "outer join finish unmatched right side",
SetUpScript: []string{
`
CREATE TABLE teams (
team VARCHAR(100),
namespace VARCHAR(100)
);`,
"INSERT INTO teams(team, namespace) VALUES ('sam', 'sam1');",
"INSERT INTO teams(team, namespace) VALUES ('sam', 'sam2');",
"INSERT INTO teams(team, namespace) VALUES ('janos', 'janos1');",
`CREATE TABLE traces (
namespace VARCHAR(100),
value INT
);`,
"INSERT INTO traces(namespace, value) VALUES ('janos1', '400');",
"INSERT INTO traces(namespace, value) VALUES ('0', '500');",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT team, sum(value) FROM traces FULL OUTER JOIN teams ON teams.namespace = traces.namespace GROUP BY team;",
Expected: []sql.Row{{"sam", nil}, {"janos", float64(400)}, {nil, float64(500)}},
},
{
Query: "SELECT team, sum(value) FROM teams FULL OUTER JOIN traces ON teams.namespace = traces.namespace GROUP BY team;",
Expected: []sql.Row{{"sam", nil}, {"janos", float64(400)}, {nil, float64(500)}},
},
},
},
{
Name: "keyless reverse index",
SetUpScript: []string{
Expand Down
9 changes: 7 additions & 2 deletions sql/rowexec/join_iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ func newFullJoinIter(ctx *sql.Context, b sql.NodeExecBuilder, j *plan.JoinNode,
rowSize: len(row) + len(j.Left().Schema()) + len(j.Right().Schema()),
seenLeft: make(map[uint64]struct{}),
seenRight: make(map[uint64]struct{}),
leftLen: len(j.Left().Schema()),
rightLen: len(j.Right().Schema()),
b: b,
}, nil
}
Expand All @@ -422,6 +424,8 @@ type fullJoinIter struct {
leftRow sql.Row
scopeLen int
rowSize int
leftLen int
rightLen int

leftDone bool
seenLeft map[uint64]struct{}
Expand All @@ -439,6 +443,7 @@ func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
i.leftDone = true
i.l = nil
i.r = nil
continue
}
if err != nil {
return nil, err
Expand All @@ -463,7 +468,7 @@ func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
}
if _, ok := i.seenLeft[key]; !ok {
// (left, null) only if we haven't matched left
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still correct? It says null but you've replaced the nil in the LoC below.

ret := i.buildRow(i.leftRow, nil)
ret := i.buildRow(i.leftRow, make(sql.Row, i.rightLen))
i.r = nil
i.leftRow = nil
return i.removeParentRow(ret), nil
Expand Down Expand Up @@ -520,7 +525,7 @@ func (i *fullJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
continue
}
// (null, right) only if we haven't matched right
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still correct? It says null but you've replaced the nil in the LoC below.

ret := i.buildRow(nil, rightRow)
ret := i.buildRow(make(sql.Row, i.leftLen), rightRow)
return i.removeParentRow(ret), nil
}
}
Expand Down
Loading