From 64ef4ddb04070a2f8f7e540b7d7be77845f384b3 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Sat, 19 Oct 2024 10:13:56 +0800 Subject: [PATCH] tests: move one strange flaky test back to unit test (#56729) --- pkg/planner/core/casetest/BUILD.bazel | 2 +- pkg/planner/core/casetest/integration_test.go | 23 +++++++++++++++++++ .../r/planner/core/indexmerge_path.result | 21 ++--------------- .../t/planner/core/indexmerge_path.test | 11 --------- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/pkg/planner/core/casetest/BUILD.bazel b/pkg/planner/core/casetest/BUILD.bazel index 07fb082507..3b0bd7eed7 100644 --- a/pkg/planner/core/casetest/BUILD.bazel +++ b/pkg/planner/core/casetest/BUILD.bazel @@ -12,7 +12,7 @@ go_test( ], data = glob(["testdata/**"]), flaky = True, - shard_count = 26, + shard_count = 27, deps = [ "//pkg/domain", "//pkg/errno", diff --git a/pkg/planner/core/casetest/integration_test.go b/pkg/planner/core/casetest/integration_test.go index d887c3e2ec..1aedce1d9e 100644 --- a/pkg/planner/core/casetest/integration_test.go +++ b/pkg/planner/core/casetest/integration_test.go @@ -492,3 +492,26 @@ func TestTiFlashExtraColumnPrune(t *testing.T) { tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...)) } } + +func TestIndexMergeJSONMemberOf2FlakyPart(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + // The following tests are flaky, we add it in unit test to have more chance to debug the issue. + tk.MustExec(`use test`) + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a int, b int, c int, d json, index iad(a, (cast(d->'$.b' as signed array))));`) + tk.MustExec(`insert into t value(1,1,1, '{"b":[1,2,3,4]}');`) + tk.MustExec(`insert into t value(2,2,2, '{"b":[3,4,5,6]}');`) + tk.MustExec(`set tidb_analyze_version=2;`) + tk.MustExec(`analyze table t all columns;`) + tk.MustQuery("explain select * from t use index (iad) where a = 1;").Check(testkit.Rows( + "TableReader_7 1.00 root data:Selection_6", + "└─Selection_6 1.00 cop[tikv] eq(test.t.a, 1)", + " └─TableFullScan_5 2.00 cop[tikv] table:t keep order:false", + )) + tk.MustQuery("explain select * from t use index (iad) where a = 1 and (2 member of (d->'$.b'));").Check(testkit.Rows( + "IndexMerge_7 1.00 root type: union", + "├─IndexRangeScan_5(Build) 1.00 cop[tikv] table:t, index:iad(a, cast(json_extract(`d`, _utf8mb4'$.b') as signed array)) range:[1 2,1 2], keep order:false, stats:partial[d:unInitialized]", + "└─TableRowIDScan_6(Probe) 1.00 cop[tikv] table:t keep order:false, stats:partial[d:unInitialized]", + )) +} diff --git a/tests/integrationtest/r/planner/core/indexmerge_path.result b/tests/integrationtest/r/planner/core/indexmerge_path.result index b36d507346..41810e6255 100644 --- a/tests/integrationtest/r/planner/core/indexmerge_path.result +++ b/tests/integrationtest/r/planner/core/indexmerge_path.result @@ -668,23 +668,6 @@ a select /*+ use_index_merge(t, j0_0) */ a from t where ('1' member of (j0->'$.path0')); a drop table if exists t; -create table t(a int, b int, c int, d json, index iad(a, (cast(d->'$.b' as signed array)))); -insert into t value(1,1,1, '{"b":[1,2,3,4]}'); -insert into t value(2,2,2, '{"b":[3,4,5,6]}'); -set tidb_analyze_version=2; -analyze table t all columns; -set @@tidb_stats_load_sync_wait=1000; -explain select * from t use index (iad) where a = 1; -id estRows task access object operator info -TableReader_7 1.00 root data:Selection_6 -└─Selection_6 1.00 cop[tikv] eq(planner__core__indexmerge_path.t.a, 1) - └─TableFullScan_5 2.00 cop[tikv] table:t keep order:false -explain select * from t use index (iad) where a = 1 and (2 member of (d->'$.b')); -id estRows task access object operator info -IndexMerge_7 1.00 root type: union -├─IndexRangeScan_5(Build) 1.00 cop[tikv] table:t, index:iad(a, cast(json_extract(`d`, _utf8mb4'$.b') as signed array)) range:[1 2,1 2], keep order:false, stats:partial[d:unInitialized] -└─TableRowIDScan_6(Probe) 1.00 cop[tikv] table:t keep order:false, stats:partial[d:unInitialized] -drop table if exists t; create table t(a int, d json, index iad(a, (cast(d->'$.b' as signed array)))); insert into t value(1,'{"b":[]}'), (2,'{"b":[]}'); select * from t use index (iad) where a = 1; @@ -713,8 +696,8 @@ alter table t add index ibb( (cast(b->'$.b' as signed array)) ); explain select /*+ use_index_merge(t) */ * from t where 10 member of (b->'$.b'); id estRows task access object operator info IndexMerge_7 1.00 root type: union -├─IndexRangeScan_5(Build) 1.00 cop[tikv] table:t, index:ibb(cast(json_extract(`b`, _utf8mb4'$.b') as signed array)) range:[10,10], keep order:false, stats:partial[ibb:missing, b:unInitialized] -└─TableRowIDScan_6(Probe) 1.00 cop[tikv] table:t keep order:false, stats:partial[ibb:missing, b:unInitialized] +├─IndexRangeScan_5(Build) 1.00 cop[tikv] table:t, index:ibb(cast(json_extract(`b`, _utf8mb4'$.b') as signed array)) range:[10,10], keep order:false, stats:partial[ibb:missing] +└─TableRowIDScan_6(Probe) 1.00 cop[tikv] table:t keep order:false, stats:partial[ibb:missing] drop table if exists t, t1; create table t (j json, i bigint(20) not null primary key, key mvi((cast(j as unsigned array)))); insert into t values ('[1,2,3]', 1); diff --git a/tests/integrationtest/t/planner/core/indexmerge_path.test b/tests/integrationtest/t/planner/core/indexmerge_path.test index 47f9fac32b..1d29657dee 100644 --- a/tests/integrationtest/t/planner/core/indexmerge_path.test +++ b/tests/integrationtest/t/planner/core/indexmerge_path.test @@ -224,17 +224,6 @@ select /*+ no_index_merge() */ a from t where ('1' member of (j0->'$.path0')); select /*+ use_index_merge(t, j0_0) */ a from t where (1 member of (j0->'$.path0')); select /*+ use_index_merge(t, j0_0) */ a from t where ('1' member of (j0->'$.path0')); -drop table if exists t; -create table t(a int, b int, c int, d json, index iad(a, (cast(d->'$.b' as signed array)))); -insert into t value(1,1,1, '{"b":[1,2,3,4]}'); -insert into t value(2,2,2, '{"b":[3,4,5,6]}'); -set tidb_analyze_version=2; -analyze table t all columns; -# The below explain is flaky, try to increase the timeout of sync load first. -set @@tidb_stats_load_sync_wait=1000; -explain select * from t use index (iad) where a = 1; -explain select * from t use index (iad) where a = 1 and (2 member of (d->'$.b')); - # TestMultiValuedIndexWithoutRelatedColumnCondition drop table if exists t; create table t(a int, d json, index iad(a, (cast(d->'$.b' as signed array))));