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

planner: outer join elimination doesn't consider the ORDER BY items from the agg func (#38380) #38385

Merged
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
15 changes: 15 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6649,3 +6649,18 @@ func TestIssue31609(t *testing.T) {
" └─MemTableScan_9 10000.00 root table:TABLES ",
))
}

func TestOuterJoinEliminationForIssue18216(t *testing.T) {
store, _, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2;")
tk.MustExec("create table t1 (a int, c int);")
tk.MustExec("insert into t1 values (1, 1), (1, 2), (2, 3), (2, 4);")
tk.MustExec("create table t2 (a int, c int);")
tk.MustExec("insert into t2 values (1, 1), (1, 2), (2, 3), (2, 4);")
// The output might be unstable.
tk.MustExec("select group_concat(c order by (select group_concat(c order by a) from t2 where a=t1.a)) from t1; ")
tk.MustQuery("select group_concat(c order by (select group_concat(c order by c) from t2 where a=t1.a), c desc) from t1;").Check(testkit.Rows("2,1,4,3"))
}
3 changes: 3 additions & 0 deletions planner/core/rule_join_elimination.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ func (o *outerJoinEliminator) doOptimize(p LogicalPlan, aggCols []*expression.Co
for _, expr := range aggDesc.Args {
parentCols = append(parentCols, expression.ExtractColumns(expr)...)
}
for _, byItem := range aggDesc.OrderByItems {
parentCols = append(parentCols, expression.ExtractColumns(byItem.Expr)...)
}
}
default:
parentCols = append(parentCols[:0], p.Schema().Columns...)
Expand Down