Skip to content

Commit dd6bf06

Browse files
yibin87ti-chi-bot
authored andcommitted
executor: Fix push downed topN won't replace correlated column problem (pingcap#53097)
close pingcap#52777
1 parent 5216ddb commit dd6bf06

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

pkg/executor/builder.go

+6
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,12 @@ func (*executorBuilder) corColInDistPlan(plans []plannercore.PhysicalPlan) bool
28792879
return true
28802880
}
28812881
}
2882+
case *plannercore.PhysicalTopN:
2883+
for _, byItem := range x.ByItems {
2884+
if len(expression.ExtractCorColumns(byItem.Expr)) > 0 {
2885+
return true
2886+
}
2887+
}
28822888
case *plannercore.PhysicalTableScan:
28832889
for _, cond := range x.LateMaterializationFilterCondition {
28842890
if len(expression.ExtractCorColumns(cond)) > 0 {

pkg/executor/test/issuetest/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go_test(
88
"main_test.go",
99
],
1010
flaky = True,
11-
shard_count = 18,
11+
shard_count = 19,
1212
deps = [
1313
"//pkg/autoid_service",
1414
"//pkg/config",

pkg/executor/test/issuetest/executor_issue_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,20 @@ func TestIssue51874(t *testing.T) {
636636
tk.MustQuery("select (select sum(a) over () from t2 limit 1) from t;").Check(testkit.Rows("10", "2"))
637637
}
638638

639+
func TestIssue51777(t *testing.T) {
640+
store := testkit.CreateMockStore(t)
641+
tk := testkit.NewTestKit(t, store)
642+
tk.Session().GetSessionVars().AllowProjectionPushDown = true
643+
644+
tk.MustExec("use test")
645+
tk.MustExec("drop table if exists t0, t1")
646+
tk.MustExec("create table t0 (c_k int)")
647+
tk.MustExec("create table t1 (c_pv int)")
648+
tk.MustExec("insert into t0 values(-2127559046),(-190905159),(-171305020),(-59638845),(98004414),(2111663670),(2137868682),(2137868682),(2142611610)")
649+
tk.MustExec("insert into t1 values(-2123227448), (2131706870), (-2071508387), (2135465388), (2052805244), (-2066000113)")
650+
tk.MustQuery("SELECT ( select (ref_4.c_pv <= ref_3.c_k) as c0 from t1 as ref_4 order by c0 asc limit 1) as p2 FROM t0 as ref_3 order by p2;").Check(testkit.Rows("0", "0", "0", "0", "0", "0", "1", "1", "1"))
651+
}
652+
639653
func TestIssue52978(t *testing.T) {
640654
store := testkit.CreateMockStore(t)
641655
tk := testkit.NewTestKit(t, store)

0 commit comments

Comments
 (0)