Skip to content

Commit

Permalink
cherry pick pingcap#36105 to release-5.3
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
zyguan authored and ti-srebot committed Jul 13, 2022
1 parent e6c3d7a commit d9d4aac
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,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
}

Expand Down
75 changes: 75 additions & 0 deletions executor/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,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)

0 comments on commit d9d4aac

Please sign in to comment.