Skip to content

Commit

Permalink
executor: Fix push downed topN won't replace correlated column problem (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored May 10, 2024
1 parent 5678c38 commit 10c52d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2958,6 +2958,12 @@ func (*executorBuilder) corColInDistPlan(plans []plannercore.PhysicalPlan) bool
return true
}
}
case *plannercore.PhysicalTopN:
for _, byItem := range x.ByItems {
if len(expression.ExtractCorColumns(byItem.Expr)) > 0 {
return true
}
}
case *plannercore.PhysicalTableScan:
for _, cond := range x.LateMaterializationFilterCondition {
if len(expression.ExtractCorColumns(cond)) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/test/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"main_test.go",
],
flaky = True,
shard_count = 18,
shard_count = 19,
deps = [
"//pkg/autoid_service",
"//pkg/config",
Expand Down
14 changes: 14 additions & 0 deletions pkg/executor/test/issuetest/executor_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,20 @@ func TestIssue42662(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/util/servermemorylimit/issue42662_2"))
}

func TestIssue51777(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.Session().GetSessionVars().AllowProjectionPushDown = true

tk.MustExec("use test")
tk.MustExec("drop table if exists t0, t1")
tk.MustExec("create table t0 (c_k int)")
tk.MustExec("create table t1 (c_pv int)")
tk.MustExec("insert into t0 values(-2127559046),(-190905159),(-171305020),(-59638845),(98004414),(2111663670),(2137868682),(2137868682),(2142611610)")
tk.MustExec("insert into t1 values(-2123227448), (2131706870), (-2071508387), (2135465388), (2052805244), (-2066000113)")
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"))
}

func TestIssue52978(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down

0 comments on commit 10c52d6

Please sign in to comment.