Skip to content

Commit

Permalink
test: fix unstable test TestIndexMergeRuntimeStats (#48700)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored Nov 20, 2023
1 parent 1d87cb9 commit 5ac833e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 51 deletions.
25 changes: 0 additions & 25 deletions pkg/executor/test/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 15 additions & 0 deletions tests/integrationtest/r/executor/executor.result
Original file line number Diff line number Diff line change
Expand Up @@ -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 <create_time> <update_time> 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 <num> 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 <num> 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;
15 changes: 0 additions & 15 deletions tests/integrationtest/r/session/variable.result
Original file line number Diff line number Diff line change
Expand Up @@ -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:<num>, loops:<num>, RU:<num>, index_task:{fetch_handle:<num>, merge:<num>}, table_task:{num:<num>, concurrency:<num>, fetch_row:<num>, wait_time:<num>} type: union <num> KB N/A
├─TableRangeScan_5(Build) 3333.33 1 cop[tikv] table:t1 time:<num>, loops:<num>, cop_task: {num:<num>, max:<num>, proc_keys:<num>, rpc_num:<num>, rpc_time:<num>, copr_cache_hit_ratio:<num>, build_task_duration:<num>, max_distsql_concurrency:<num>}, tikv_task:{time:<num>, loops:<num>} range:[-inf,2), keep order:false, stats:pseudo <num> Bytes N/A
├─IndexRangeScan_6(Build) 3333.33 1 cop[tikv] table:t1, index:t1a(a) time:<num>, loops:<num>, cop_task: {num:<num>, max:<num>, proc_keys:<num>, rpc_num:<num>, rpc_time:<num>, copr_cache_hit_ratio:<num>, build_task_duration:<num>, max_distsql_concurrency:<num>}, tikv_task:{time:<num>, loops:<num>} range:(4,+inf], keep order:false, stats:pseudo N/A N/A
└─TableRowIDScan_7(Probe) 3334.67 2 cop[tikv] table:t1 time:<num>, loops:<num>, cop_task: {num:<num>, max:<num>, min:<num>, avg:<num>, p95:<num>, rpc_num:<num>, rpc_time:<num>, copr_cache_hit_ratio:<num>, build_task_duration:<num>, max_distsql_concurrency:<num>, max_extra_concurrency:<num>}, tikv_task:{proc max:<num>, min:<num>, avg:<num>, p80:<num>, p95:<num>, iters:<num>, tasks:<num>} 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;
11 changes: 11 additions & 0 deletions tests/integrationtest/t/executor/executor.test
Original file line number Diff line number Diff line change
Expand Up @@ -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/<num> Bytes/ /[.0-9]+ KB/<num> 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;

11 changes: 0 additions & 11 deletions tests/integrationtest/t/session/variable.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]*/:<num>/ /, scan_detail: {.*}// / max_proc_keys:.*?, p95_proc_keys:.*?,// / tot_proc:.*?, tot_wait:.*?,// /[0-9]+ Bytes/<num> Bytes/ /[.0-9]+ KB/<num> 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;

0 comments on commit 5ac833e

Please sign in to comment.