From 5ac833e7751abac6736457e995b8a87189faad5b Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Mon, 20 Nov 2023 11:32:41 +0800 Subject: [PATCH] test: fix unstable test `TestIndexMergeRuntimeStats` (#48700) --- pkg/executor/test/executor/executor_test.go | 25 ------------------- .../r/executor/executor.result | 15 +++++++++++ .../integrationtest/r/session/variable.result | 15 ----------- .../integrationtest/t/executor/executor.test | 11 ++++++++ tests/integrationtest/t/session/variable.test | 11 -------- 5 files changed, 26 insertions(+), 51 deletions(-) diff --git a/pkg/executor/test/executor/executor_test.go b/pkg/executor/test/executor/executor_test.go index a3eef3ea32336..54a3c0a1b79e7 100644 --- a/pkg/executor/test/executor/executor_test.go +++ b/pkg/executor/test/executor/executor_test.go @@ -794,31 +794,6 @@ func TestHashAggRuntimeStats(t *testing.T) { require.Regexp(t, pattern, explain) } -func TestIndexMergeRuntimeStats(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@tidb_enable_index_merge = 1") - tk.MustExec("create table t1(id int primary key, a int, b int, c int, d int)") - tk.MustExec("create index t1a on t1(a)") - tk.MustExec("create index t1b on t1(b)") - tk.MustExec("insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5)") - rows := tk.MustQuery("explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4;").Rows() - require.Len(t, rows, 4) - explain := fmt.Sprintf("%v", rows[0]) - pattern := ".*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.*" - require.Regexp(t, pattern, explain) - tableRangeExplain := fmt.Sprintf("%v", rows[1]) - indexExplain := fmt.Sprintf("%v", rows[2]) - tableExplain := fmt.Sprintf("%v", rows[3]) - require.Regexp(t, ".*time:.*loops:.*cop_task:.*", tableRangeExplain) - require.Regexp(t, ".*time:.*loops:.*cop_task:.*", indexExplain) - require.Regexp(t, ".*time:.*loops:.*cop_task:.*", tableExplain) - tk.MustExec("set @@tidb_enable_collect_execution_info=0;") - tk.MustQuery("select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a").Check(testkit.Rows("1 1 1 1 1", "5 5 5 5 5")) -} - func TestPrevStmtDesensitization(t *testing.T) { store := testkit.CreateMockStore(t) diff --git a/tests/integrationtest/r/executor/executor.result b/tests/integrationtest/r/executor/executor.result index 9ea883175b80e..c7f2c7bde73e0 100644 --- a/tests/integrationtest/r/executor/executor.result +++ b/tests/integrationtest/r/executor/executor.result @@ -4390,3 +4390,18 @@ Original_sql Bind_sql Default_db Status Create_time Update_time Charset Collatio select * from `executor__executor` . `testbind` SELECT * FROM `executor__executor`.`testbind` USE INDEX FOR JOIN (`index_t`) executor__executor enabled utf8mb4 utf8mb4_general_ci manual a2fa907992be17801e5976df09b5b3a0d205f4c4aff39a14ab3bc8642026f527 drop session binding for select * from testbind using select * from testbind use index for join(index_t); drop global binding for select * from testbind using select * from testbind use index for join(index_t); +drop table if EXISTS t1; +create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; +id estRows actRows task access object execution info operator info memory disk +IndexMerge_8 3334.67 2 root NULL .*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.* type: union KB N/A +├─TableRangeScan_5(Build) 3333.33 1 cop[tikv] table:t1 .*time:.*loops:.*cop_task:.* range:[-inf,2), keep order:false, stats:pseudo Bytes N/A +├─IndexRangeScan_6(Build) 3333.33 1 cop[tikv] table:t1, index:t1a(a) .*time:.*loops:.*cop_task:.* range:(4,+inf], keep order:false, stats:pseudo N/A N/A +└─TableRowIDScan_7(Probe) 3334.67 2 cop[tikv] table:t1 .*time:.*loops:.*cop_task:.* keep order:false, stats:pseudo N/A N/A +set @@tidb_enable_collect_execution_info=0; +select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; +id a b c d +1 1 1 1 1 +5 5 5 5 5 +set @@tidb_enable_collect_execution_info=default; diff --git a/tests/integrationtest/r/session/variable.result b/tests/integrationtest/r/session/variable.result index 8997e73b96c94..c76c3776da9c4 100644 --- a/tests/integrationtest/r/session/variable.result +++ b/tests/integrationtest/r/session/variable.result @@ -240,18 +240,3 @@ set @@group_concat_max_len='hello'; Error 1232 (42000): Incorrect argument type to variable 'group_concat_max_len' set global group_concat_max_len = default; set @@session.group_concat_max_len = default; -drop table if EXISTS t1; -create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); -insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); -explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; -id estRows actRows task access object execution info operator info memory disk -IndexMerge_8 3334.67 2 root NULL time:, loops:, RU:, index_task:{fetch_handle:, merge:}, table_task:{num:, concurrency:, fetch_row:, wait_time:} type: union KB N/A -├─TableRangeScan_5(Build) 3333.33 1 cop[tikv] table:t1 time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:}, tikv_task:{time:, loops:} range:[-inf,2), keep order:false, stats:pseudo Bytes N/A -├─IndexRangeScan_6(Build) 3333.33 1 cop[tikv] table:t1, index:t1a(a) time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:}, tikv_task:{time:, loops:} range:(4,+inf], keep order:false, stats:pseudo N/A N/A -└─TableRowIDScan_7(Probe) 3334.67 2 cop[tikv] table:t1 time:, loops:, cop_task: {num:, max:, min:, avg:, p95:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, max_extra_concurrency:}, tikv_task:{proc max:, min:, avg:, p80:, p95:, iters:, tasks:} keep order:false, stats:pseudo N/A N/A -set @@tidb_enable_collect_execution_info=0; -select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; -id a b c d -1 1 1 1 1 -5 5 5 5 5 -set @@tidb_enable_collect_execution_info=default; diff --git a/tests/integrationtest/t/executor/executor.test b/tests/integrationtest/t/executor/executor.test index b20282084a9b8..dde049d75536f 100644 --- a/tests/integrationtest/t/executor/executor.test +++ b/tests/integrationtest/t/executor/executor.test @@ -2660,3 +2660,14 @@ show session bindings where default_db='executor__executor'; drop session binding for select * from testbind using select * from testbind use index for join(index_t); drop global binding for select * from testbind using select * from testbind use index for join(index_t); + +# TestIndexMergeRuntimeStats +drop table if EXISTS t1; +create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +--replace_regex /.*time:.*loops:.*cop_task:.*/.*time:.*loops:.*cop_task:.*/ /.*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.*/.*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.*/ /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ +explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; +set @@tidb_enable_collect_execution_info=0; +select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; +set @@tidb_enable_collect_execution_info=default; + diff --git a/tests/integrationtest/t/session/variable.test b/tests/integrationtest/t/session/variable.test index e3f26fc254166..18e5923a8af32 100644 --- a/tests/integrationtest/t/session/variable.test +++ b/tests/integrationtest/t/session/variable.test @@ -178,14 +178,3 @@ set @@group_concat_max_len = 18446744073709551616; set @@group_concat_max_len='hello'; set global group_concat_max_len = default; set @@session.group_concat_max_len = default; - -# TestIndexMergeRuntimeStats -drop table if EXISTS t1; -create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); -insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); ---replace_regex /:[ ]?[.0-9]+[µms]*/:/ /, scan_detail: {.*}// / max_proc_keys:.*?, p95_proc_keys:.*?,// / tot_proc:.*?, tot_wait:.*?,// /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ -explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; -set @@tidb_enable_collect_execution_info=0; -select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; -set @@tidb_enable_collect_execution_info=default; -