Skip to content

Commit

Permalink
*: fix parallel apply wrong result (#51414) (#51429)
Browse files Browse the repository at this point in the history
close #51372
  • Loading branch information
ti-chi-bot authored Mar 1, 2024
1 parent 11c815c commit 4f3c415
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions executor/parallel_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,22 @@ func TestApplyGoroutinePanic(t *testing.T) {
}
}

func TestParallelApplyCorrectness(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1 (c1 bigint, c2 int, c3 int, c4 int, primary key(c1, c2), index (c3));")
tk.MustExec("insert into t1 values(1, 1, 1, 1), (1, 2, 3, 3), (2, 1, 4, 4), (2, 2, 2, 2);")

tk.MustExec("set tidb_enable_parallel_apply=true")
sql := "select (select /*+ NO_DECORRELATE() */ sum(c4) from t1 where t1.c3 = alias.c3) from t1 alias where alias.c1 = 1;"
tk.MustQuery(sql).Sort().Check(testkit.Rows("1", "3"))

tk.MustExec("set tidb_enable_parallel_apply=false")
tk.MustQuery(sql).Sort().Check(testkit.Rows("1", "3"))
}

func TestIssue24930(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
6 changes: 6 additions & 0 deletions planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ func (p *PhysicalIndexLookUpReader) Clone() (PhysicalPlan, error) {
if p.PushedLimit != nil {
cloned.PushedLimit = p.PushedLimit.Clone()
}
if len(p.CommonHandleCols) != 0 {
cloned.CommonHandleCols = make([]*expression.Column, 0, len(p.CommonHandleCols))
for _, col := range p.CommonHandleCols {
cloned.CommonHandleCols = append(cloned.CommonHandleCols, col.Clone().(*expression.Column))
}
}
return cloned, nil
}

Expand Down

0 comments on commit 4f3c415

Please sign in to comment.