Skip to content

Commit

Permalink
Merge pull request #557 from dolthub/aaron/join-condition-to-filter-f…
Browse files Browse the repository at this point in the history
…ix-topJoin

sql/analyzer/optimization_rules.go: moveJoinConditionsToFilter: Fix small inaccuracy where computed topJoin could be wrong.
  • Loading branch information
reltuk committed Sep 21, 2021
2 parents 52ff812 + 52973dc commit fe3a822
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sql/analyzer/optimization_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func moveJoinConditionsToFilter(ctx *sql.Context, a *Analyzer, n sql.Node, scope
}

if filtersMoved == 0 {
return n, nil
topJoin = n
return topJoin, nil
}

if len(condFilters) > 0 {
Expand Down
39 changes: 39 additions & 0 deletions sql/analyzer/optimization_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,45 @@ func TestMoveJoinConditionsToFilter(t *testing.T) {
)

assertNodesEqualWithDiff(t, expected, result)

node = plan.NewInnerJoin(
plan.NewResolvedTable(t1, nil, nil),
plan.NewInnerJoin(
plan.NewResolvedTable(t2, nil, nil),
plan.NewResolvedTable(t3, nil, nil),
expression.JoinAnd(
eq(col(0, "t2", "c"), col(0, "t3", "e")),
eq(col(0, "t3", "a"), lit(5)),
),
),
expression.JoinAnd(
eq(col(0, "t1", "c"), col(0, "t2", "e")),
),
)

result, err = rule.Apply(sql.NewEmptyContext(), NewDefault(nil), node, nil)
require.NoError(err)

expected = plan.NewFilter(
expression.JoinAnd(
eq(col(0, "t3", "a"), lit(5)),
),
plan.NewInnerJoin(
plan.NewResolvedTable(t1, nil, nil),
plan.NewInnerJoin(
plan.NewResolvedTable(t2, nil, nil),
plan.NewResolvedTable(t3, nil, nil),
expression.JoinAnd(
eq(col(0, "t2", "c"), col(0, "t3", "e")),
),
),
expression.JoinAnd(
eq(col(0, "t1", "c"), col(0, "t2", "e")),
),
),
)

assertNodesEqualWithDiff(t, expected, result)
}

func TestEvalFilter(t *testing.T) {
Expand Down

0 comments on commit fe3a822

Please sign in to comment.