Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#51414
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
guo-shaoge authored and ti-chi-bot committed Feb 29, 2024
1 parent 7d16cc7 commit 50fe2a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/executor/parallel_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ func TestApplyGoroutinePanic(t *testing.T) {
}
}

<<<<<<< HEAD
func TestIssue24930(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand All @@ -634,4 +635,20 @@ func TestIssue24930(t *testing.T) {
tk.MustQuery(`select case when t1.a is null
then (select t2.a from t2 where t2.a = t1.a limit 1) else t1.a end a
from t1 where t1.a=1 order by a limit 1`).Check(testkit.Rows()) // can return an empty result instead of hanging forever
=======
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"))
>>>>>>> ac7dad34563 (*: fix parallel apply wrong result (#51414))
}
6 changes: 6 additions & 0 deletions pkg/planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,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 50fe2a4

Please sign in to comment.