From 075a1fe9c311ad1dff58ba88c11627fd4d6b754f Mon Sep 17 00:00:00 2001 From: zyguan Date: Wed, 13 Jul 2022 19:45:05 +0800 Subject: [PATCH] cherry pick #36105 to release-5.2 Signed-off-by: ti-srebot --- executor/adapter.go | 2 +- executor/explain_test.go | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/executor/adapter.go b/executor/adapter.go index 2907c7d3032f5..773fbf5c7060b 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -417,7 +417,7 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) { return a.handlePessimisticSelectForUpdate(ctx, e) } - if handled, result, err := a.handleNoDelay(ctx, e, isPessimistic); handled { + if handled, result, err := a.handleNoDelay(ctx, e, isPessimistic); handled || err != nil { return result, err } diff --git a/executor/explain_test.go b/executor/explain_test.go index ca7923e11049b..291c3c5ba9777 100644 --- a/executor/explain_test.go +++ b/executor/explain_test.go @@ -372,3 +372,78 @@ func (s *testSuite) TestFix29401(c *C) { ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`) tk.MustExec(" explain select /*+ inl_hash_join(t1) */ * from tt123 t1 join tt123 t2 on t1.b=t2.e;") } +<<<<<<< HEAD +======= + +func TestIssue35296(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b int , c int, d int, e int,index ia(a), index ib(b), index ic(c), index idd(d), index ie(e));") + + rows := tk.MustQuery("explain analyze select * from t where a = 10 or b = 30 or c = 10 or d = 1 or e = 90;").Rows() + + require.Contains(t, rows[0][0], "IndexMerge") + require.NotRegexp(t, "^time:0s", rows[1][5]) + require.NotRegexp(t, "^time:0s", rows[2][5]) + require.NotRegexp(t, "^time:0s", rows[3][5]) + require.NotRegexp(t, "^time:0s", rows[4][5]) + require.NotRegexp(t, "^time:0s", rows[5][5]) +} + +func TestIssue35911(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("drop table if exists t2") + tk.MustExec("create table t1(a int, b int);") + tk.MustExec("create table t2(a int, b int, index ia(a));") + tk.MustExec("insert into t1 value (1,1), (2,2), (3,3), (4,4), (5,5), (6,6);") + tk.MustExec("insert into t2 value (1,1), (2,2), (3,3), (4,4), (5,5), (6,6);") + tk.MustExec("set @@tidb_executor_concurrency = 5;") + + // case 1 of #35911 + tk.MustExec("set @@tidb_enable_parallel_apply = 0;") + rows := tk.MustQuery("explain analyze select * from t1 where exists (select tt1.* from (select * from t2 where a = t1.b) as tt1 join (select * from t2 where a = t1.b) as tt2 on tt1.b = tt2.b);").Rows() + + extractTime, err := regexp.Compile("^time:(.*?),") + require.NoError(t, err) + timeStr1 := extractTime.FindStringSubmatch(rows[4][5].(string))[1] + time1, err := time.ParseDuration(timeStr1) + require.NoError(t, err) + timeStr2 := extractTime.FindStringSubmatch(rows[5][5].(string))[1] + time2, err := time.ParseDuration(timeStr2) + require.NoError(t, err) + // The duration of IndexLookUp should be longer than its build side child + require.LessOrEqual(t, time2, time1) + + // case 2 of #35911 + tk.MustExec("set @@tidb_enable_parallel_apply = 1;") + rows = tk.MustQuery("explain analyze select * from t1 where exists (select tt1.* from (select * from t2 where a = t1.b) as tt1 join (select * from t2 where a = t1.b) as tt2 on tt1.b = tt2.b);").Rows() + + extractConcurrency, err := regexp.Compile(`table_task: [{].*concurrency: (\d+)[}]`) + require.NoError(t, err) + concurrencyStr := extractConcurrency.FindStringSubmatch(rows[4][5].(string))[1] + concurrency, err := strconv.ParseInt(concurrencyStr, 10, 64) + require.NoError(t, err) + // To be consistent with other operators, we should not aggregate the concurrency in the runtime stats. + require.EqualValues(t, 5, concurrency) +} + +func TestIssue35105(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a int primary key)") + tk.MustExec("insert into t values (2)") + tk.MustExec("set @@tidb_constraint_check_in_place=1") + require.Error(t, tk.ExecToErr("explain analyze insert into t values (1), (2), (3)")) + tk.MustQuery("select * from t").Check(testkit.Rows("2")) +} +>>>>>>> 28c96008a... executor: check the error returned by `handleNoDelay` (#36105)