From 5c4d4b7e1fb3ab8d796802a4635aa45d67d70ffa Mon Sep 17 00:00:00 2001 From: YangKeao Date: Wed, 27 Sep 2023 17:52:46 +0800 Subject: [PATCH] tests, planner: migrate tests for indexmerge_path, integration and partition in planner (#47330) close pingcap/tidb#47329 --- planner/core/BUILD.bazel | 1 - planner/core/indexmerge_path_test.go | 315 -- planner/core/integration_partition_test.go | 1197 ----- planner/core/integration_test.go | 2829 ------------ planner/core/partition_pruner_test.go | 606 --- .../core/testdata/index_merge_suite_in.json | 101 - .../core/testdata/index_merge_suite_out.json | 720 --- tests/integrationtest/r/black_list.result | 3 + .../r/expression/issues.result | 3 + .../r/planner/core/indexmerge_path.result | 658 +++ .../r/planner/core/integration.result | 3969 +++++++++++++++++ .../planner/core/integration_partition.result | 1290 ++++++ .../r/planner/core/partition_pruner.result | 3645 +++++++++++++++ tests/integrationtest/t/black_list.test | 4 + .../integrationtest/t/expression/issues.test | 2 + .../t/planner/core/indexmerge_path.test | 232 + .../t/planner/core/integration.test | 2092 +++++++++ .../t/planner/core/integration_partition.test | 848 ++++ .../t/planner/core/partition_pruner.test | 1014 +++++ 19 files changed, 13760 insertions(+), 5769 deletions(-) delete mode 100644 planner/core/partition_pruner_test.go create mode 100644 tests/integrationtest/r/planner/core/indexmerge_path.result create mode 100644 tests/integrationtest/r/planner/core/integration.result create mode 100644 tests/integrationtest/r/planner/core/integration_partition.result create mode 100644 tests/integrationtest/r/planner/core/partition_pruner.result create mode 100644 tests/integrationtest/t/planner/core/indexmerge_path.test create mode 100644 tests/integrationtest/t/planner/core/integration.test create mode 100644 tests/integrationtest/t/planner/core/integration_partition.test create mode 100644 tests/integrationtest/t/planner/core/partition_pruner.test diff --git a/planner/core/BUILD.bazel b/planner/core/BUILD.bazel index f547b533ca..508102adee 100644 --- a/planner/core/BUILD.bazel +++ b/planner/core/BUILD.bazel @@ -202,7 +202,6 @@ go_test( "main_test.go", "memtable_predicate_extractor_test.go", "optimizer_test.go", - "partition_pruner_test.go", "partition_pruning_test.go", "physical_plan_test.go", "physical_plan_trace_test.go", diff --git a/planner/core/indexmerge_path_test.go b/planner/core/indexmerge_path_test.go index bbf59f80e0..ea16652369 100644 --- a/planner/core/indexmerge_path_test.go +++ b/planner/core/indexmerge_path_test.go @@ -15,315 +15,14 @@ package core_test import ( - "context" "fmt" "math/rand" "strings" "testing" - "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/testkit" - "github.com/pingcap/tidb/testkit/testdata" - "github.com/stretchr/testify/require" ) -func TestAnalyzeMVIndexWarnings(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(a int, b int, c int, j json, -index(a), index(b), -index idx(a, b, (cast(j as signed array)), c), -index idx2(a, b, (cast(j->'$.str' as char(10) array)), c))`) - - tk.MustExec("set tidb_analyze_version=2") - tk.MustExec("analyze table t") - tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\"", - )) - tk.MustExec("analyze table t index idx") - tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is \"TiDB assumes that the table is empty, use sample-rate=1\"", - "Warning 1105 The version 2 would collect all statistics not only the selected indexes", - )) - - tk.MustExec("set tidb_analyze_version=1") - tk.MustExec("analyze table t") - tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Warning 1105 analyzing multi-valued indexes is not supported, skip idx", - "Warning 1105 analyzing multi-valued indexes is not supported, skip idx2")) - tk.MustExec("analyze table t index idx") - tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Warning 1105 analyzing multi-valued indexes is not supported, skip idx")) - tk.MustExec("analyze table t index a") - tk.MustQuery("show warnings").Sort().Check(testkit.Rows()) - tk.MustExec("analyze table t index a, idx, idx2") - tk.MustQuery("show warnings").Sort().Check(testkit.Rows( - "Warning 1105 analyzing multi-valued indexes is not supported, skip idx", - "Warning 1105 analyzing multi-valued indexes is not supported, skip idx2")) -} - -func TestIndexMergeJSONMemberOf(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t( -a int, j0 json, j1 json, -index j0_0((cast(j0->'$.path0' as signed array))), -index j0_1((cast(j0->'$.path1' as signed array))), -index j0_string((cast(j0->'$.path_string' as char(10) array))), -index j0_date((cast(j0->'$.path_date' as date array))), -index j1((cast(j1 as signed array))))`) - - var input []string - var output []struct { - SQL string - Plan []string - } - planSuiteData := core.GetIndexMergeSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, query := range input { - testdata.OnRecord(func() { - output[i].SQL = query - }) - result := tk.MustQuery("explain format = 'brief' " + query) - testdata.OnRecord(func() { - output[i].Plan = testdata.ConvertRowsToStrings(result.Rows()) - }) - result.Check(testkit.Rows(output[i].Plan...)) - } -} - -func TestDNFOnMVIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(a int, b int, c int, j json, -index idx1((cast(j as signed array))), -index idx2(a, b, (cast(j as signed array)), c))`) - - var input []string - var output []struct { - SQL string - Plan []string - } - planSuiteData := core.GetIndexMergeSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, query := range input { - testdata.OnRecord(func() { - output[i].SQL = query - }) - result := tk.MustQuery("explain format = 'brief' " + query) - testdata.OnRecord(func() { - output[i].Plan = testdata.ConvertRowsToStrings(result.Rows()) - }) - result.Check(testkit.Rows(output[i].Plan...)) - } -} - -func TestCompositeMVIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(a int, b int , c int, j json, -index idx(a, b, (cast(j as signed array)), c), -index idx2(a, b, (cast(j->'$.str' as char(10) array)), c))`) - - var input []string - var output []struct { - SQL string - Plan []string - } - planSuiteData := core.GetIndexMergeSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, query := range input { - testdata.OnRecord(func() { - output[i].SQL = query - }) - result := tk.MustQuery("explain format = 'brief' " + query) - testdata.OnRecord(func() { - output[i].Plan = testdata.ConvertRowsToStrings(result.Rows()) - }) - result.Check(testkit.Rows(output[i].Plan...)) - } -} - -func TestMVIndexSelection(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(a int, j json, -index i_int((cast(j->'$.int' as signed array))))`) - - var input []string - var output []struct { - SQL string - Plan []string - } - planSuiteData := core.GetIndexMergeSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, query := range input { - testdata.OnRecord(func() { - output[i].SQL = query - }) - result := tk.MustQuery("explain format = 'brief' " + query) - testdata.OnRecord(func() { - output[i].Plan = testdata.ConvertRowsToStrings(result.Rows()) - }) - result.Check(testkit.Rows(output[i].Plan...)) - } -} - -func TestMVIndexIndexMergePlanCache(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(j json, index kj((cast(j as signed array))))`) - - tk.MustExec("prepare st from 'select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j))'") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip prepared plan-cache: query accesses generated columns is un-cacheable")) - tk.MustExec("execute st") - tk.MustExec("execute st") - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) -} - -func TestMVIndexPointGet(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(j json, unique kj((cast(j as signed array))))`) - - for _, sql := range []string{ - "select j from t where j=1", - "select j from t where j=1 or j=2", - "select j from t where j in (1, 2)", - } { - plan := tk.MustQuery("explain " + sql).Rows() - hasPointGet := false - for _, line := range plan { - if strings.Contains(strings.ToLower(line[0].(string)), "point") { - hasPointGet = true - } - } - require.True(t, !hasPointGet) // no point-get plan - } -} - -func TestEnforceMVIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(a int, j json, index kj((cast(j as signed array))))`) - - var input []string - var output []struct { - SQL string - Plan []string - Err string - } - planSuiteData := core.GetIndexMergeSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, query := range input { - testdata.OnRecord(func() { - output[i].SQL = query - }) - rs, err := tk.Exec("explain format = 'brief' " + query) - if err != nil { - testdata.OnRecord(func() { - output[i].Err = err.Error() - output[i].Plan = nil - }) - require.Equal(t, output[i].Err, err.Error()) - } else { - result := tk.ResultSetToResultWithCtx(context.Background(), rs, "") - testdata.OnRecord(func() { - output[i].Err = "" - output[i].Plan = testdata.ConvertRowsToStrings(result.Rows()) - }) - result.Check(testkit.Rows(output[i].Plan...)) - } - } -} - -func TestMVIndexInvisible(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec(`create table t(a int, j json, index kj((cast(j as signed array))))`) - tk.MustQuery(`explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j))`).Check(testkit.Rows( - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo", - )) - - tk.MustExec(`ALTER TABLE t ALTER INDEX kj INVISIBLE`) - tk.MustQuery(`explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j))`).Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] json_memberof(cast(1, json BINARY), test.t.j)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo")) - tk.MustQuery(`explain format='brief' select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j))`).Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] json_memberof(cast(1, json BINARY), test.t.j)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo")) - - tk.MustExec(`ALTER TABLE t ALTER INDEX kj VISIBLE`) - tk.MustQuery(`explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j))`).Check(testkit.Rows( - `IndexMerge 10.00 root type: union`, - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - `└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo`)) -} - -func TestMVIndexFullScan(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec(`create table t(j json, index kj((cast(j as signed array))))`) - tk.MustExec(`insert into t values ('[1]')`) - tk.MustExec(`insert into t values ('[1, 2]')`) - tk.MustExec(`insert into t values ('[]')`) - tk.MustExec(`insert into t values (NULL)`) - - tk.MustQuery(`select /*+ use_index_merge(t, kj) */ count(*) from t`).Check(testkit.Rows("4")) - tk.MustQuery(`select /*+ use_index_merge(t, kj) */ count(*) from t where (1 member of (j))`).Check(testkit.Rows("2")) - tk.MustQuery(`select /*+ use_index_merge(t, kj) */ count(*) from t where json_contains((j), '[1]')`).Check(testkit.Rows("2")) - tk.MustQuery(`select /*+ use_index_merge(t, kj) */ count(*) from t where json_overlaps((j), '[1]')`).Check(testkit.Rows("2")) - - // Forbid IndexMerge+IndexFullScan since IndexFullScan on MVIndex cannot read all rows some cases. - tk.MustGetErrMsg(`select /*+ use_index(t, kj) */ count(*) from t`, "[planner:1815]Internal : Can't find a proper physical plan for this query") -} - -func TestMVIndexEmptyArray(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t(j json, index kj((cast(j as signed array))))`) - tk.MustExec(`insert into t values ('[1]')`) - tk.MustExec(`insert into t values ('[1, 2]')`) - tk.MustExec(`insert into t values ('[]')`) - tk.MustExec(`insert into t values (NULL)`) - - for _, cond := range []string{ - "json_contains(j, '[]')", - "json_contains(j, '[1]')", - "json_contains(j, '[1, 2]')", - "json_contains(j, '[1, 10]')", - "json_overlaps(j, '[]')", - "json_overlaps(j, '[1]')", - "json_overlaps(j, '[1, 2]')", - "json_overlaps(j, '[1, 10]')", - } { - tk.MustQuery(fmt.Sprintf("select /*+ use_index_merge(t) */ * from t where %v", cond)).Sort().Check( - tk.MustQuery(fmt.Sprintf("select /*+ ignore_index(t, kj) */ * from t where %v", cond)).Sort().Rows()) - } -} - func TestMVIndexRandom(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -422,17 +121,3 @@ func randMVIndexValue(opts randMVIndexValOpts) string { } return "" } - -func TestIndexMergeJSONMemberOf2(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t( -a int, j0 json, j1 json, -index j0_0((cast(j0->'$.path0' as signed array))));`) - tk.MustExec("insert into t values(1, '{\"path0\" : [1,2,3]}', null ); ") - tk.MustQuery("select /*+ no_index_merge() */ a from t where (1 member of (j0->'$.path0')); ").Check(testkit.Rows("1")) - tk.MustQuery("select /*+ no_index_merge() */ a from t where ('1' member of (j0->'$.path0')); ").Check(testkit.Rows()) - tk.MustQuery("select /*+ use_index_merge(t, j0_0) */ a from t where (1 member of (j0->'$.path0')); ").Check(testkit.Rows("1")) - tk.MustQuery("select /*+ use_index_merge(t, j0_0) */ a from t where ('1' member of (j0->'$.path0')); ").Check(testkit.Rows()) -} diff --git a/planner/core/integration_partition_test.go b/planner/core/integration_partition_test.go index f2d30d9a11..3a2ec93520 100644 --- a/planner/core/integration_partition_test.go +++ b/planner/core/integration_partition_test.go @@ -17,13 +17,10 @@ package core_test import ( "bytes" "fmt" - "math" "math/rand" "strconv" - "strings" "testing" - "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/parser/auth" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/testkit" @@ -147,267 +144,6 @@ func TestListPartitionAgg(t *testing.T) { } } -func TestListPartitionDML(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_dml") - tk.MustExec("use list_partition_dml") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`create table tlist (a int) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - tk.MustExec("insert into tlist partition(p0) values (0), (1)") - tk.MustExec("insert into tlist partition(p0, p1) values (2), (3), (8), (9)") - - err := tk.ExecToErr("insert into tlist partition(p0) values (9)") - require.Error(t, err) - require.Contains(t, err.Error(), "Found a row not matching the given partition set") - - err = tk.ExecToErr("insert into tlist partition(p3) values (20)") - require.Error(t, err) - require.Contains(t, err.Error(), "Unknown partition") - - tk.MustExec("update tlist partition(p0) set a=a+1") - tk.MustQuery("select a from tlist order by a").Check(testkit.Rows("1", "2", "3", "4", "8", "9")) - tk.MustExec("update tlist partition(p0, p1) set a=a-1") - tk.MustQuery("select a from tlist order by a").Check(testkit.Rows("0", "1", "2", "3", "7", "8")) - - tk.MustExec("delete from tlist partition(p1)") - tk.MustQuery("select a from tlist order by a").Check(testkit.Rows("0", "1", "2", "3")) - tk.MustExec("delete from tlist partition(p0, p2)") - tk.MustQuery("select a from tlist order by a").Check(testkit.Rows()) - - tk.MustExec(`create table tcollist (a int) partition by list columns(a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - tk.MustExec("insert into tcollist partition(p0) values (0), (1)") - tk.MustExec("insert into tcollist partition(p0, p1) values (2), (3), (8), (9)") - - err = tk.ExecToErr("insert into tcollist partition(p0) values (9)") - require.Error(t, err) - require.Contains(t, err.Error(), "Found a row not matching the given partition set") - - err = tk.ExecToErr("insert into tcollist partition(p3) values (20)") - require.Error(t, err) - require.Contains(t, err.Error(), "Unknown partition") - - tk.MustExec("update tcollist partition(p0) set a=a+1") - tk.MustQuery("select a from tcollist order by a").Check(testkit.Rows("1", "2", "3", "4", "8", "9")) - tk.MustExec("update tcollist partition(p0, p1) set a=a-1") - tk.MustQuery("select a from tcollist order by a").Check(testkit.Rows("0", "1", "2", "3", "7", "8")) - - tk.MustExec("delete from tcollist partition(p1)") - tk.MustQuery("select a from tcollist order by a").Check(testkit.Rows("0", "1", "2", "3")) - tk.MustExec("delete from tcollist partition(p0, p2)") - tk.MustQuery("select a from tcollist order by a").Check(testkit.Rows()) -} - -func TestListPartitionCreation(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_cre") - tk.MustExec("use list_partition_cre") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - // with UK - tk.MustExec("create table tuk1 (a int, b int, unique key(a)) partition by list (a) (partition p0 values in (0))") - - err := tk.ExecToErr("create table tuk2 (a int, b int, unique key(a)) partition by list (b) (partition p0 values in (0))") - require.Error(t, err) - require.Contains(t, err.Error(), "UNIQUE INDEX must include all columns") - - err = tk.ExecToErr("create table tuk2 (a int, b int, unique key(a), unique key(b)) partition by list (a) (partition p0 values in (0))") - require.Error(t, err) - require.Contains(t, err.Error(), "UNIQUE INDEX must include all columns") - - tk.MustExec("create table tcoluk1 (a int, b int, unique key(a)) partition by list columns(a) (partition p0 values in (0))") - - err = tk.ExecToErr("create table tcoluk2 (a int, b int, unique key(a)) partition by list columns(b) (partition p0 values in (0))") - require.Error(t, err) - require.Contains(t, err.Error(), "UNIQUE INDEX must include all columns") - - err = tk.ExecToErr("create table tcoluk2 (a int, b int, unique key(a), unique key(b)) partition by list columns(a) (partition p0 values in (0))") - require.Error(t, err) - require.Contains(t, err.Error(), "UNIQUE INDEX must include all columns") - - // with PK - tk.MustExec("create table tpk1 (a int, b int, primary key(a)) partition by list (a) (partition p0 values in (0))") - tk.MustExec("create table tpk2 (a int, b int, primary key(a, b)) partition by list (a) (partition p0 values in (0))") - - tk.MustExec("create table tcolpk1 (a int, b int, primary key(a)) partition by list columns(a) (partition p0 values in (0))") - tk.MustExec("create table tcolpk2 (a int, b int, primary key(a, b)) partition by list columns(a) (partition p0 values in (0))") - - // with IDX - tk.MustExec("create table tidx1 (a int, b int, key(a), key(b)) partition by list (a) (partition p0 values in (0))") - tk.MustExec("create table tidx2 (a int, b int, key(a, b), key(b)) partition by list (a) (partition p0 values in (0))") - - tk.MustExec("create table tcolidx1 (a int, b int, key(a), key(b)) partition by list columns(a) (partition p0 values in (0))") - tk.MustExec("create table tcolidx2 (a int, b int, key(a, b), key(b)) partition by list columns(a) (partition p0 values in (0))") - - // with expression - tk.MustExec("create table texp1 (a int, b int) partition by list(a-10000) (partition p0 values in (0))") - tk.MustExec("create table texp2 (a int, b int) partition by list(a%b) (partition p0 values in (0))") - tk.MustExec("create table texp3 (a int, b int) partition by list(a*b) (partition p0 values in (0))") - - err = tk.ExecToErr("create table texp4 (a int, b int) partition by list(a|b) (partition p0 values in (0))") - require.Error(t, err) - require.Contains(t, err.Error(), "This partition function is not allowed") - - err = tk.ExecToErr("create table texp4 (a int, b int) partition by list(a^b) (partition p0 values in (0))") - require.Error(t, err) - require.Contains(t, err.Error(), "This partition function is not allowed") - - err = tk.ExecToErr("create table texp4 (a int, b int) partition by list(a&b) (partition p0 values in (0))") - require.Error(t, err) - require.Contains(t, err.Error(), "This partition function is not allowed") -} - -func TestListPartitionDDL(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_ddl") - tk.MustExec("use list_partition_ddl") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - // index - tk.MustExec(`create table tlist (a int, b int) partition by list (a) (partition p0 values in (0))`) - err := tk.ExecToErr(`alter table tlist add primary key (b)`) // add pk - require.Error(t, err) - require.Contains(t, err.Error(), "must include all") - tk.MustExec(`alter table tlist add primary key (a)`) - err = tk.ExecToErr(`alter table tlist add unique key (b)`) // add uk - require.Error(t, err) - require.Contains(t, err.Error(), "must include all") - tk.MustExec(`alter table tlist add key (b)`) // add index - tk.MustExec(`alter table tlist rename index b to bb`) - tk.MustExec(`alter table tlist drop index bb`) - - tk.MustExec(`create table tcollist (a int, b int) partition by list columns (a) (partition p0 values in (0))`) - err = tk.ExecToErr(`alter table tcollist add primary key (b)`) // add pk - require.Error(t, err) - require.Contains(t, err.Error(), "must include all") - tk.MustExec(`alter table tcollist add primary key (a)`) - err = tk.ExecToErr(`alter table tcollist add unique key (b)`) // add uk - require.Error(t, err) - require.Contains(t, err.Error(), "must include all") - tk.MustExec(`alter table tcollist add key (b)`) // add index - tk.MustExec(`alter table tcollist rename index b to bb`) - tk.MustExec(`alter table tcollist drop index bb`) - - // column - tk.MustExec(`alter table tlist add column c varchar(8)`) - tk.MustExec(`alter table tlist rename column c to cc`) - tk.MustExec(`alter table tlist drop column cc`) - - tk.MustExec(`alter table tcollist add column c varchar(8)`) - tk.MustExec(`alter table tcollist rename column c to cc`) - tk.MustExec(`alter table tcollist drop column cc`) - - // table - tk.MustExec(`alter table tlist rename to tlistxx`) - tk.MustExec(`truncate tlistxx`) - tk.MustExec(`drop table tlistxx`) - - tk.MustExec(`alter table tcollist rename to tcollistxx`) - tk.MustExec(`truncate tcollistxx`) - tk.MustExec(`drop table tcollistxx`) -} - -func TestListPartitionOperations(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_op") - tk.MustExec("use list_partition_op") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - tk.MustExec(`create table tlist (a int) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14), - partition p3 values in (15, 16, 17, 18, 19))`) - tk.MustExec(`create table tcollist (a int) partition by list columns(a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14), - partition p3 values in (15, 16, 17, 18, 19))`) - - // truncate - tk.MustExec("insert into tlist values (0), (5), (10), (15)") - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("0", "10", "15", "5")) - tk.MustExec("alter table tlist truncate partition p0") - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("10", "15", "5")) - tk.MustExec("alter table tlist truncate partition p1, p2") - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("15")) - - tk.MustExec("insert into tcollist values (0), (5), (10), (15)") - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("0", "10", "15", "5")) - tk.MustExec("alter table tcollist truncate partition p0") - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("10", "15", "5")) - tk.MustExec("alter table tcollist truncate partition p1, p2") - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("15")) - - // drop partition - tk.MustExec("insert into tlist values (0), (5), (10)") - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("0", "10", "15", "5")) - tk.MustExec("alter table tlist drop partition p0") - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("10", "15", "5")) - err := tk.ExecToErr("select * from tlist partition (p0)") - require.Error(t, err) - require.Contains(t, err.Error(), "Unknown partition") - tk.MustExec("alter table tlist drop partition p1, p2") - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("15")) - err = tk.ExecToErr("select * from tlist partition (p1)") - require.Error(t, err) - require.Contains(t, err.Error(), "Unknown partition") - err = tk.ExecToErr("alter table tlist drop partition p3") - require.Error(t, err) - require.Contains(t, err.Error(), "Cannot remove all partitions") - - tk.MustExec("insert into tcollist values (0), (5), (10)") - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("0", "10", "15", "5")) - tk.MustExec("alter table tcollist drop partition p0") - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("10", "15", "5")) - err = tk.ExecToErr("select * from tcollist partition (p0)") - require.Error(t, err) - require.Contains(t, err.Error(), "Unknown partition") - tk.MustExec("alter table tcollist drop partition p1, p2") - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("15")) - err = tk.ExecToErr("select * from tcollist partition (p1)") - require.Error(t, err) - require.Contains(t, err.Error(), "Unknown partition") - err = tk.ExecToErr("alter table tcollist drop partition p3") - require.Error(t, err) - require.Contains(t, err.Error(), "Cannot remove all partitions") - - // add partition - tk.MustExec("alter table tlist add partition (partition p0 values in (0, 1, 2, 3, 4))") - tk.MustExec("alter table tlist add partition (partition p1 values in (5, 6, 7, 8, 9), partition p2 values in (10, 11, 12, 13, 14))") - tk.MustExec("insert into tlist values (0), (5), (10)") - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("0", "10", "15", "5")) - err = tk.ExecToErr("alter table tlist add partition (partition pxxx values in (4))") - require.Error(t, err) - require.Contains(t, err.Error(), "Multiple definition") - - tk.MustExec("alter table tcollist add partition (partition p0 values in (0, 1, 2, 3, 4))") - tk.MustExec("alter table tcollist add partition (partition p1 values in (5, 6, 7, 8, 9), partition p2 values in (10, 11, 12, 13, 14))") - tk.MustExec("insert into tcollist values (0), (5), (10)") - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("0", "10", "15", "5")) - err = tk.ExecToErr("alter table tcollist add partition (partition pxxx values in (4))") - require.Error(t, err) - require.Contains(t, err.Error(), "Multiple definition") -} - func TestListPartitionPrivilege(t *testing.T) { store := testkit.CreateMockStore(t) @@ -446,68 +182,6 @@ func TestListPartitionPrivilege(t *testing.T) { require.Contains(t, err.Error(), "denied") } -func TestListPartitionShardBits(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_shard_bits") - tk.MustExec("use list_partition_shard_bits") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - tk.MustExec(`create table tlist (a int) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - tk.MustExec("insert into tlist values (0), (1), (5), (6), (10), (12)") - - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("0", "1", "10", "12", "5", "6")) - tk.MustQuery("select * from tlist partition (p0)").Sort().Check(testkit.Rows("0", "1")) - tk.MustQuery("select * from tlist partition (p1, p2)").Sort().Check(testkit.Rows("10", "12", "5", "6")) - - tk.MustExec(`create table tcollist (a int) partition by list columns (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - tk.MustExec("insert into tcollist values (0), (1), (5), (6), (10), (12)") - - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("0", "1", "10", "12", "5", "6")) - tk.MustQuery("select * from tcollist partition (p0)").Sort().Check(testkit.Rows("0", "1")) - tk.MustQuery("select * from tcollist partition (p1, p2)").Sort().Check(testkit.Rows("10", "12", "5", "6")) -} - -func TestListPartitionSplitRegion(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_split_region") - tk.MustExec("use list_partition_split_region") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - tk.MustExec(`create table tlist (a int, key(a)) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - tk.MustExec("insert into tlist values (0), (1), (5), (6), (10), (12)") - - tk.MustExec(`split table tlist index a between (2) and (15) regions 10`) - tk.MustQuery("select * from tlist").Sort().Check(testkit.Rows("0", "1", "10", "12", "5", "6")) - tk.MustQuery("select * from tlist partition (p0)").Sort().Check(testkit.Rows("0", "1")) - tk.MustQuery("select * from tlist partition (p1, p2)").Sort().Check(testkit.Rows("10", "12", "5", "6")) - - tk.MustExec(`create table tcollist (a int, key(a)) partition by list columns (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - tk.MustExec("insert into tcollist values (0), (1), (5), (6), (10), (12)") - - tk.MustExec(`split table tcollist index a between (2) and (15) regions 10`) - tk.MustQuery("select * from tcollist").Sort().Check(testkit.Rows("0", "1", "10", "12", "5", "6")) - tk.MustQuery("select * from tcollist partition (p0)").Sort().Check(testkit.Rows("0", "1")) - tk.MustQuery("select * from tcollist partition (p1, p2)").Sort().Check(testkit.Rows("10", "12", "5", "6")) -} - func TestListPartitionView(t *testing.T) { store := testkit.CreateMockStore(t) @@ -551,169 +225,6 @@ func TestListPartitionView(t *testing.T) { r1.Check(r2.Rows()) } -func TestListPartitionAutoIncre(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_auto_incre") - tk.MustExec("use list_partition_auto_incre") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - tk.MustExec(`create table tlist1 (a int, b int AUTO_INCREMENT) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - tk.MustExec(`create table tlist (a int, b int AUTO_INCREMENT, key(b)) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - tk.MustExec(`insert into tlist (a) values (0)`) - tk.MustExec(`insert into tlist (a) values (5)`) - tk.MustExec(`insert into tlist (a) values (10)`) - tk.MustExec(`insert into tlist (a) values (1)`) - - tk.MustExec(`create table tcollist1 (a int, b int AUTO_INCREMENT) partition by list columns (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - tk.MustExec(`create table tcollist (a int, b int AUTO_INCREMENT, key(b)) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - tk.MustExec(`insert into tcollist (a) values (0)`) - tk.MustExec(`insert into tcollist (a) values (5)`) - tk.MustExec(`insert into tcollist (a) values (10)`) - tk.MustExec(`insert into tcollist (a) values (1)`) -} - -func TestListPartitionAutoRandom(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_auto_rand") - tk.MustExec("use list_partition_auto_rand") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - err := tk.ExecToErr(`create table tlist (a int, b bigint AUTO_RANDOM) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - require.Error(t, err) - require.Contains(t, err.Error(), "Invalid auto random") - - tk.MustExec(`create table tlist (a bigint auto_random, primary key(a)) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - err = tk.ExecToErr(`create table tcollist (a int, b bigint AUTO_RANDOM) partition by list columns (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - require.Error(t, err) - require.Contains(t, err.Error(), "Invalid auto random") - - tk.MustExec(`create table tcollist (a bigint auto_random, primary key(a)) partition by list columns (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) -} - -func TestListPartitionInvisibleIdx(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_invisible_idx") - tk.MustExec("use list_partition_invisible_idx") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - tk.MustExec(`create table tlist (a int, b int, key(a)) partition by list (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5))`) - tk.MustExec(`alter table tlist alter index a invisible`) - tk.MustHavePlan(`select a from tlist where a>=0 and a<=5`, "TableFullScan") - - tk.MustExec(`create table tcollist (a int, b int, key(a)) partition by list columns (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5))`) - tk.MustExec(`alter table tcollist alter index a invisible`) - tk.MustHavePlan(`select a from tcollist where a>=0 and a<=5`, "TableFullScan") -} - -func TestListPartitionCTE(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_cte") - tk.MustExec("use list_partition_cte") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - - tk.MustExec(`create table tlist (a int) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - tk.MustExec(`insert into tlist values (0), (1), (5), (6), (10)`) - tk.MustQuery(`with tmp as (select a+1 as a from tlist) select * from tmp`).Sort().Check(testkit.Rows("1", "11", "2", "6", "7")) - - tk.MustExec(`create table tcollist (a int) partition by list columns (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - - tk.MustExec(`insert into tcollist values (0), (1), (5), (6), (10)`) - tk.MustQuery(`with tmp as (select a+1 as a from tcollist) select * from tmp`).Sort().Check(testkit.Rows("1", "11", "2", "6", "7")) -} - -func TestListPartitionTempTable(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_temp_table") - tk.MustExec("use list_partition_temp_table") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - err := tk.ExecToErr("create global temporary table t(a int, b int) partition by list(a) (partition p0 values in (0)) on commit delete rows") - require.Error(t, err) - require.Contains(t, err.Error(), "Cannot create temporary table with partitions") - err = tk.ExecToErr("create global temporary table t(a int, b int) partition by list columns (a) (partition p0 values in (0)) on commit delete rows") - require.Error(t, err) - require.Contains(t, err.Error(), "Cannot create temporary table with partitions") -} - -func TestListPartitionAlterPK(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database list_partition_alter_pk") - tk.MustExec("use list_partition_alter_pk") - tk.MustExec("drop table if exists tlist") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`create table tlist (a int, b int) partition by list (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - tk.MustExec(`alter table tlist add primary key(a)`) - tk.MustExec(`alter table tlist drop primary key`) - err := tk.ExecToErr(`alter table tlist add primary key(b)`) - require.Error(t, err) - require.Contains(t, err.Error(), "must include all columns") - - tk.MustExec(`create table tcollist (a int, b int) partition by list columns (a) ( - partition p0 values in (0, 1, 2, 3, 4), - partition p1 values in (5, 6, 7, 8, 9), - partition p2 values in (10, 11, 12, 13, 14))`) - tk.MustExec(`alter table tcollist add primary key(a)`) - tk.MustExec(`alter table tcollist drop primary key`) - err = tk.ExecToErr(`alter table tcollist add primary key(b)`) - require.Error(t, err) - require.Contains(t, err.Error(), "must include all columns") -} - func TestListPartitionRandomTransaction(t *testing.T) { store := testkit.CreateMockStore(t) @@ -766,172 +277,6 @@ func TestListPartitionRandomTransaction(t *testing.T) { } } -func TestIssue27018(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27018") - tk.MustExec("use issue_27018") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`CREATE TABLE PK_LP9326 ( - COL1 tinyint(45) NOT NULL DEFAULT '30' COMMENT 'NUMERIC PK', - PRIMARY KEY (COL1) /*T![clustered_index] CLUSTERED */ -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY LIST COLUMNS(col1) ( - PARTITION P0 VALUES IN (56,127,-128,-125,-40,-18,-10,-5,49,51), - PARTITION P1 VALUES IN (-107,-97,-57,-37,4,43,99,-9,-6,45), - PARTITION P2 VALUES IN (108,114,-85,-72,-38,-11,29,97,40,107), - PARTITION P3 VALUES IN (-112,-95,-42,24,28,47,-103,-94,7,64), - PARTITION P4 VALUES IN (-115,-101,-76,-47,1,19,-114,-23,-19,11), - PARTITION P5 VALUES IN (44,95,-92,-89,-26,-21,25,-117,-116,27), - PARTITION P6 VALUES IN (50,61,118,-110,-32,-1,111,125,-90,74), - PARTITION P7 VALUES IN (75,121,-96,-87,-14,-13,37,-68,-58,81), - PARTITION P8 VALUES IN (126,30,48,68) -)`) - tk.MustExec(`insert into PK_LP9326 values(30),(48),(56)`) - tk.MustQuery(`SELECT COL1 FROM PK_LP9326 WHERE COL1 NOT IN (621579514938,-17333745845828,2777039147338)`).Sort().Check(testkit.Rows("30", "48", "56")) -} - -func TestIssue27017(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27017") - tk.MustExec("use issue_27017") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`CREATE TABLE PK_LP9465 ( - COL1 mediumint(45) NOT NULL DEFAULT '77' COMMENT 'NUMERIC PK', - PRIMARY KEY (COL1) /*T![clustered_index] CLUSTERED */ -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY LIST COLUMNS(col1) ( - PARTITION P0 VALUES IN (-5237720,2949267,6047247,-8317208,-6854239,-6612749,-6578207,-5649321,2450483,2953765), - PARTITION P1 VALUES IN (5884439,-7816703,-6716210,-6050369,-5691207,6836620,5769359,-8237127,-1294367,-1228621), - PARTITION P2 VALUES IN (-976130,-8351227,-8294140,-4800605,1370685,-7351802,-6447779,77,1367409,5965199), - PARTITION P3 VALUES IN (7347944,7397124,8013414,-5737292,-3938813,-3687304,1307396,444598,1216072,1603451), - PARTITION P4 VALUES IN (2518402,-8388608,-5291256,-3796824,121011,8388607,39191,2323510,3386861,4886727), - PARTITION P5 VALUES IN (-6512367,-5922779,-3272589,-1313463,5751641,-3974640,2605656,3336269,4416436,-7975238), - PARTITION P6 VALUES IN (-6693544,-6023586,-4201506,6416586,-3254125,-205332,1072201,2679754,1963191,2077718), - PARTITION P7 VALUES IN (4205081,5170051,-8087893,-5805143,-1202286,1657202,8330979,5042855,7578575,-5830439), - PARTITION P8 VALUES IN (-5244013,3837781,4246485,670906,5644986,5843443,7794811,7831812,-7704740,-2222984), - PARTITION P9 VALUES IN (764108,3406142,8263677,248997,6129417,7556305,7939455,3526998,8239485,-5195482), - PARTITION P10 VALUES IN (-3625794,69270,377245) -)`) - tk.MustExec(`insert into PK_LP9465 values(8263677)`) - tk.MustQuery(`SELECT COL1 FROM PK_LP9465 HAVING COL1>=-12354348921530`).Sort().Check(testkit.Rows("8263677")) -} - -func TestIssue27544(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27544") - tk.MustExec("use issue_27544") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`create table t3 (a datetime) partition by list (mod( year(a) - abs(weekday(a) + dayofweek(a)), 4) + 1) ( - partition p0 values in (2), - partition p1 values in (3), - partition p3 values in (4))`) - tk.MustExec(`insert into t3 values ('1921-05-10 15:20:10')`) // success without any error - tk.MustExec(`insert into t3 values ('1921-05-10 15:20:20')`) - tk.MustExec(`insert into t3 values ('1921-05-10 15:20:30')`) -} - -func TestIssue27012(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27012") - tk.MustExec("use issue_27012") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`CREATE TABLE IDT_LP24306 ( - COL1 tinyint(16) DEFAULT '41' COMMENT 'NUMERIC UNIQUE INDEX', - KEY UK_COL1 (COL1) /*!80000 INVISIBLE */ -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY LIST COLUMNS(col1) ( - PARTITION P0 VALUES IN (-126,-36,-96,-6,-83,-123,-5,-52,-98,-124), - PARTITION P1 VALUES IN (-2,-22,-88,-100,-60,-39,-69,-38,-11,-30), - PARTITION P2 VALUES IN (-119,-13,-67,-91,-65,-16,0,-128,-73,-118), - PARTITION P3 VALUES IN (-99,-56,-76,-110,-93,-114,-78,NULL) -)`) - tk.MustExec(`insert into IDT_LP24306 values(-128)`) - tk.MustQuery(`select * from IDT_LP24306 where col1 not between 12021 and 99 and col1 <= -128`).Sort().Check(testkit.Rows("-128")) - - tk.MustExec(`drop table if exists IDT_LP24306`) - tk.MustExec(`CREATE TABLE IDT_LP24306 ( - COL1 tinyint(16) DEFAULT '41' COMMENT 'NUMERIC UNIQUE INDEX', - KEY UK_COL1 (COL1) /*!80000 INVISIBLE */ -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`) - tk.MustExec(`insert into IDT_LP24306 values(-128)`) - tk.MustQuery(`select * from IDT_LP24306 where col1 not between 12021 and 99 and col1 <= -128`).Sort().Check(testkit.Rows("-128")) -} - -func TestIssue27030(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27030") - tk.MustExec("use issue_27030") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`CREATE TABLE PK_LCP9290 ( - COL1 varbinary(10) NOT NULL, - PRIMARY KEY (COL1) /*T![clustered_index] NONCLUSTERED */ -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY LIST COLUMNS(col1) ( - PARTITION P5 VALUES IN (x'32d8fb9da8b63508a6b8'), - PARTITION P6 VALUES IN (x'ffacadeb424179bc4b5c'), - PARTITION P8 VALUES IN (x'ae9f733168669fa900be') -)`) - tk.MustExec(`insert into PK_LCP9290 values(0xffacadeb424179bc4b5c),(0xae9f733168669fa900be),(0x32d8fb9da8b63508a6b8)`) - tk.MustQuery(`SELECT COL1 FROM PK_LCP9290 WHERE COL1!=x'9f7ebdc957a36f2531b5' AND COL1 IN (x'ffacadeb424179bc4b5c',x'ae9f733168669fa900be',x'32d8fb9da8b63508a6b8')`).Sort().Check(testkit.Rows("2\xd8\xfb\x9d\xa8\xb65\b\xa6\xb8", "\xae\x9fs1hf\x9f\xa9\x00\xbe", "\xff\xac\xad\xebBAy\xbcK\\")) - tk.MustQuery(`SELECT COL1 FROM PK_LCP9290 WHERE COL1 IN (x'ffacadeb424179bc4b5c',x'ae9f733168669fa900be',x'32d8fb9da8b63508a6b8')`).Sort().Check(testkit.Rows("2\xd8\xfb\x9d\xa8\xb65\b\xa6\xb8", "\xae\x9fs1hf\x9f\xa9\x00\xbe", "\xff\xac\xad\xebBAy\xbcK\\")) -} - -func TestIssue27070(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27070") - tk.MustExec("use issue_27070") - tk.MustExec("set @@tidb_enable_list_partition = OFF") - tk.MustExec(`create table if not exists t (id int, create_date date NOT NULL DEFAULT '2000-01-01', PRIMARY KEY (id,create_date) ) PARTITION BY list COLUMNS(create_date) ( PARTITION p20210506 VALUES IN ("20210507"), PARTITION p20210507 VALUES IN ("20210508") )`) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 8200 Unsupported partition type LIST, treat as normal table")) -} - -func TestIssue27031(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27031") - tk.MustExec("use issue_27031") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`CREATE TABLE NT_LP27390 ( - COL1 mediumint(28) DEFAULT '114' COMMENT 'NUMERIC NO INDEX' -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY LIST COLUMNS(col1) ( - PARTITION P9 VALUES IN (3376825,-7753310,-4123498,6483048,6953968,-996842,-7542484,320451,-8322717,-2426029) -)`) - tk.MustExec(`insert into NT_LP27390 values(-4123498)`) - tk.MustQuery(`SELECT COL1 FROM NT_LP27390 WHERE COL1 IN (46015556,-4123498,54419751)`).Sort().Check(testkit.Rows("-4123498")) -} - -func TestIssue27493(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27493") - tk.MustExec("use issue_27493") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`CREATE TABLE UK_LP17321 ( - COL1 mediumint(16) DEFAULT '82' COMMENT 'NUMERIC UNIQUE INDEX', - COL3 bigint(20) DEFAULT NULL, - UNIQUE KEY UM_COL (COL1,COL3) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY LIST (COL1 DIV COL3) ( - PARTITION P0 VALUES IN (NULL,0) -)`) - tk.MustQuery(`select * from UK_LP17321 where col1 is null`).Check(testkit.Rows()) // without any error -} - func genListPartition(begin, end int) string { buf := &bytes.Buffer{} buf.WriteString("(") @@ -942,474 +287,6 @@ func genListPartition(begin, end int) string { return buf.String() } -func TestIssue27532(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue_27532") - defer tk.MustExec(`drop database issue_27532`) - tk.MustExec("use issue_27532") - tk.MustExec(`set tidb_enable_list_partition = 1`) - tk.MustExec(`create table t2 (c1 int primary key, c2 int, c3 int, c4 int, key k2 (c2), key k3 (c3)) partition by hash(c1) partitions 10`) - tk.MustExec(`insert into t2 values (1,1,1,1),(2,2,2,2),(3,3,3,3),(4,4,4,4)`) - tk.MustExec(`set @@tidb_partition_prune_mode="dynamic"`) - tk.MustExec(`set autocommit = 0`) - tk.MustQuery(`select * from t2`).Sort().Check(testkit.Rows("1 1 1 1", "2 2 2 2", "3 3 3 3", "4 4 4 4")) - tk.MustQuery(`select * from t2`).Sort().Check(testkit.Rows("1 1 1 1", "2 2 2 2", "3 3 3 3", "4 4 4 4")) - tk.MustExec(`drop table t2`) -} - -func TestIssue37508(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'") - tk.MustQuery("select @@tidb_partition_prune_mode").Check(testkit.Rows("dynamic")) - tk.MustExec(`create table t1 (id int, c date) partition by range (to_days(c)) -(partition p0 values less than (to_days('2022-01-11')), -partition p1 values less than (to_days('2022-02-11')), -partition p2 values less than (to_days('2022-03-11')));`) - tk.MustExec("analyze table t1") - - tk.MustPartition("select * from t1 where c in ('2022-01-23', '2022-01-22');", "p1").Sort().Check(testkit.Rows()) - tk.MustPartition("select * from t1 where c in (NULL, '2022-01-23');", "p0,p1").Sort().Check(testkit.Rows()) - tk.MustExec(`drop table t1`) -} - -func TestRangeColumnsMultiColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database RangeColumnsMulti") - tk.MustExec("use RangeColumnsMulti") - - tk.MustGetErrCode(`create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)`+ - `(partition p0 values less than (NULL,NULL,NULL))`, - errno.ErrParse) - tk.MustGetErrCode(`create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)`+ - `(partition p1 values less than (`+strconv.FormatInt(math.MinInt32-1, 10)+`,'0000-00-00',""))`, - errno.ErrWrongTypeColumnValue) - tk.MustExec(`create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)` + - `(partition p1 values less than (` + strconv.FormatInt(math.MinInt32, 10) + `,'0000-00-00',""),` + - `partition p2 values less than (10,'2022-01-01',"Wow"),` + - `partition p3 values less than (11,'2022-01-01',MAXVALUE),` + - `partition p4 values less than (MAXVALUE,'2022-01-01',"Wow"))`) - tk.MustGetErrCode(`insert into t values (`+strconv.FormatInt(math.MinInt32, 10)+`,'0000-00-00',null)`, errno.ErrTruncatedWrongValue) - tk.MustExec(`insert into t values (NULL,NULL,NULL)`) - tk.MustExec(`set @@sql_mode = ''`) - tk.MustExec(`insert into t values (` + strconv.FormatInt(math.MinInt32, 10) + `,'0000-00-00',null)`) - tk.MustExec(`insert into t values (` + strconv.FormatInt(math.MinInt32, 10) + `,'0000-00-00',"")`) - tk.MustExec(`insert into t values (5,'0000-00-00',null)`) - tk.MustQuery(`show warnings`).Check(testkit.Rows()) - tk.MustExec(`insert into t values (5,'0000-00-00',"Hi")`) - tk.MustQuery(`show warnings`).Check(testkit.Rows()) - tk.MustExec(`set @@sql_mode = DEFAULT`) - tk.MustExec(`insert into t values (10,'2022-01-01',"Hi")`) - tk.MustExec(`insert into t values (10,'2022-01-01',"Wow")`) - tk.MustExec(`insert into t values (10,'2022-01-01',"Wowe")`) - tk.MustExec(`insert into t values (11,'2022-01-01',"Wow")`) - tk.MustExec(`insert into t values (1,null,"Wow")`) - tk.MustExec(`insert into t values (NULL,'2022-01-01',"Wow")`) - tk.MustExec(`insert into t values (11,null,"Wow")`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select a,b,c from t partition(p1)`).Sort().Check(testkit.Rows( - "-2147483648 0000-00-00 00:00:00 ", - " 2022-01-01 00:00:00 Wow", - " ")) - tk.MustQuery(`select a,b,c from t partition(p2)`).Sort().Check(testkit.Rows( - "-2147483648 0000-00-00 00:00:00 ", - "1 Wow", - "10 2022-01-01 00:00:00 Hi", - "5 0000-00-00 00:00:00 ", - "5 0000-00-00 00:00:00 Hi")) - tk.MustQuery(`select a,b,c from t partition(p3)`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Wow", - "10 2022-01-01 00:00:00 Wowe", - "11 2022-01-01 00:00:00 Wow", - "11 Wow")) - tk.MustQuery(`select * from t where a = 10 and b = "2022-01-01" and c = "Wow"`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Wow")) - tk.MustQuery(`select * from t where a = 10 and b = "2022-01-01" and c <= "Wow"`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Hi", - "10 2022-01-01 00:00:00 Wow")) - tk.MustQuery(`select * from t where a = 10 and b = "2022-01-01" and c < "Wow"`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Hi")) - tk.MustQuery(`select * from t where a = 10 and b = "2022-01-01" and c > "Wow"`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Wowe")) - tk.MustQuery(`select * from t where a = 10 and b = "2022-01-01" and c >= "Wow"`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Wow", - "10 2022-01-01 00:00:00 Wowe")) - tk.MustQuery(`explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c = "Wow"`).Check(testkit.Rows( - "TableReader 0.52 root partition:p3 data:Selection", - `└─Selection 0.52 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), eq(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c <= "Wow"`).Check(testkit.Rows( - `TableReader 0.83 root partition:p2,p3 data:Selection`, - `└─Selection 0.83 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), le(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c < "Wow"`).Check(testkit.Rows( - `TableReader 0.31 root partition:p2 data:Selection`, - `└─Selection 0.31 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c > "Wow"`).Check(testkit.Rows( - `TableReader 0.10 root partition:p3 data:Selection`, - `└─Selection 0.10 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), gt(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c >= "Wow"`).Check(testkit.Rows( - `TableReader 0.62 root partition:p3 data:Selection`, - `└─Selection 0.62 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), ge(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"`).Sort().Check(testkit.Rows( - "-2147483648 0000-00-00 00:00:00 ", - "10 2022-01-01 00:00:00 Hi", - "5 0000-00-00 00:00:00 Hi")) - tk.MustQuery(`select * from t where a = 10 and b = "2022-01-01" and c = "Wow"`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Wow")) - tk.MustQuery(`select * from t where a <= 10 and b <= '2022-01-01' and c <= "Wow"`).Sort().Check(testkit.Rows( - "-2147483648 0000-00-00 00:00:00 ", - "10 2022-01-01 00:00:00 Hi", - "10 2022-01-01 00:00:00 Wow", - "5 0000-00-00 00:00:00 Hi")) - tk.MustQuery(`explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"`).Check(testkit.Rows( - `TableReader 1.50 root partition:p1,p2,p3 data:Selection`, - `└─Selection 1.50 cop[tikv] le(rangecolumnsmulti.t.a, 10), le(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`select * from t where a <= 11 and b <= '2022-01-01' and c < "Wow"`).Sort().Check(testkit.Rows( - "-2147483648 0000-00-00 00:00:00 ", - "10 2022-01-01 00:00:00 Hi", - "5 0000-00-00 00:00:00 Hi")) - // Possible optimization: p3 should not be included!!! The range optimizer will just use a <= 10 here - // But same with non-partitioned index, so the range optimizer needs to be improved. - tk.MustQuery(`explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"`).Check(testkit.Rows( - `TableReader 1.50 root partition:p1,p2,p3 data:Selection`, - `└─Selection 1.50 cop[tikv] le(rangecolumnsmulti.t.a, 10), le(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustExec(`create table tref (a int, b datetime, c varchar(255), key (a,b,c))`) - tk.MustExec(`set @@sql_mode = ''`) - tk.MustExec(`insert into tref select * from t`) - tk.MustExec(`set @@sql_mode = DEFAULT`) - tk.MustQuery(`explain format = 'brief' select * from tref where a <= 10 and b <= '2022-01-01' and c < "Wow"`).Check(testkit.Rows( - `IndexReader 367.05 root index:Selection`, - `└─Selection 367.05 cop[tikv] le(rangecolumnsmulti.tref.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.tref.c, "Wow")`, - ` └─IndexRangeScan 3323.33 cop[tikv] table:tref, index:a(a, b, c) range:[-inf,10], keep order:false, stats:pseudo`)) - tk.MustQuery(`explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c <= "Wow"`).Check(testkit.Rows( - `TableReader 4.00 root partition:p1,p2,p3 data:Selection`, - `└─Selection 4.00 cop[tikv] le(rangecolumnsmulti.t.a, 10), le(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), le(rangecolumnsmulti.t.c, "Wow")`, - ` └─TableFullScan 12.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`select * from t where a = 2 and b = "2022-01-02" and c = "Hi" or b = '2022-01-01' and c = "Wow"`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00 Wow", - "11 2022-01-01 00:00:00 Wow", - " 2022-01-01 00:00:00 Wow")) - tk.MustQuery(`select * from t where a = 2 and b = "2022-01-02" and c = "Hi" or a = 10 and b = '2022-01-01' and c = "Wow"`).Sort().Check(testkit.Rows("10 2022-01-01 00:00:00 Wow")) - tk.MustQuery(`select * from t where a = 2 and b = "2022-01-02" and c = "Hi"`).Sort().Check(testkit.Rows()) - tk.MustQuery(`select * from t where a = 2 and b = "2022-01-02" and c < "Hi"`).Sort().Check(testkit.Rows()) - tk.MustQuery(`select * from t where a < 2`).Sort().Check(testkit.Rows( - "-2147483648 0000-00-00 00:00:00 ", - "-2147483648 0000-00-00 00:00:00 ", - "1 Wow")) - tk.MustQuery(`select * from t where a <= 2 and b <= "2022-01-02" and c < "Hi"`).Sort().Check(testkit.Rows( - "-2147483648 0000-00-00 00:00:00 ")) - tk.MustQuery(`explain format = 'brief' select * from t where a < 2`).Check(testkit.Rows( - "TableReader 3.00 root partition:p1,p2 data:Selection", - "└─Selection 3.00 cop[tikv] lt(rangecolumnsmulti.t.a, 2)", - " └─TableFullScan 12.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from t where a < 2 and a > -22`).Sort().Check(testkit.Rows( - "1 Wow")) - tk.MustQuery(`explain format = 'brief' select * from t where a < 2 and a > -22`).Check(testkit.Rows( - "TableReader 1.00 root partition:p2 data:Selection", - "└─Selection 1.00 cop[tikv] gt(rangecolumnsmulti.t.a, -22), lt(rangecolumnsmulti.t.a, 2)", - " └─TableFullScan 12.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from t where c = ""`).Sort().Check(testkit.Rows("-2147483648 0000-00-00 00:00:00 ")) - tk.MustQuery(`explain format = 'brief' select * from t where c = ""`).Check(testkit.Rows( - "TableReader 1.00 root partition:all data:Selection", - `└─Selection 1.00 cop[tikv] eq(rangecolumnsmulti.t.c, "")`, - " └─TableFullScan 12.00 cop[tikv] table:t keep order:false")) -} - -func TestRangeMultiColumnsPruning(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database RColumnsMulti") - tk.MustExec("use RColumnsMulti") - tk.MustExec(`create table t (a int, b datetime, c varchar(255), key (a,b,c))` + - ` partition by range columns (a,b,c) ` + - `(partition p0 values less than (-2147483648, '0000-01-01', ""),` + - ` partition p1 values less than (-2147483648, '0001-01-01', ""),` + - ` partition p2 values less than (-2, '0001-01-01', ""),` + - ` partition p3 values less than (0, '0001-01-01', ""),` + - ` partition p4 values less than (0, '2031-01-01', ""),` + - ` partition p5 values less than (0, '2031-01-01', "Wow"),` + - ` partition p6 values less than (0, '2031-01-01', MAXVALUE),` + - ` partition p7 values less than (0, MAXVALUE, MAXVALUE),` + - ` partition p8 values less than (MAXVALUE, MAXVALUE, MAXVALUE))`) - tk.MustGetErrCode(`insert into t values (`+strconv.FormatInt(math.MinInt32, 10)+`,'0000-00-00',null)`, errno.ErrTruncatedWrongValue) - tk.MustExec(`insert into t values (NULL,NULL,NULL)`) - tk.MustExec(`set @@sql_mode = ''`) - tk.MustExec(`insert into t values (` + strconv.FormatInt(math.MinInt32, 10) + `,'0000-00-00',null)`) - tk.MustExec(`insert into t values (` + strconv.FormatInt(math.MinInt32, 10) + `,'0000-00-00',"")`) - tk.MustExec(`insert into t values (5,'0000-00-00',null)`) - tk.MustQuery(`show warnings`).Check(testkit.Rows()) - tk.MustExec(`insert into t values (5,'0000-00-00',"Hi")`) - tk.MustQuery(`show warnings`).Check(testkit.Rows()) - tk.MustExec(`set @@sql_mode = DEFAULT`) - tk.MustExec(`insert into t values (10,'2022-01-01',"Hi")`) - tk.MustExec(`insert into t values (10,'2022-01-01',"Wow")`) - tk.MustExec(`insert into t values (11,'2022-01-01',"Wow")`) - tk.MustExec(`insert into t values (0,'2020-01-01',"Wow")`) - tk.MustExec(`insert into t values (1,null,"Wow")`) - tk.MustExec(`insert into t values (NULL,'2022-01-01',"Wow")`) - tk.MustExec(`insert into t values (11,null,"Wow")`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select a,b from t where b = '2022-01-01'`).Sort().Check(testkit.Rows( - "10 2022-01-01 00:00:00", - "10 2022-01-01 00:00:00", - "11 2022-01-01 00:00:00", - " 2022-01-01 00:00:00")) - tk.MustQuery(`select a,b,c from t where a = 1`).Check(testkit.Rows("1 Wow")) - tk.MustQuery(`select a,b,c from t where a = 1 AND c = "Wow"`).Check(testkit.Rows("1 Wow")) - tk.MustQuery(`explain format = 'brief' select a,b,c from t where a = 1 AND c = "Wow"`).Check(testkit.Rows( - `IndexReader 0.50 root partition:p8 index:Selection`, - `└─Selection 0.50 cop[tikv] eq(rcolumnsmulti.t.c, "Wow")`, - ` └─IndexRangeScan 1.00 cop[tikv] table:t, index:a(a, b, c) range:[1,1], keep order:false`)) - // WAS HERE, Why is the start return TRUE making this to work and FALSE disapear? - tk.MustQuery(`select a,b,c from t where a = 0 AND c = "Wow"`).Check(testkit.Rows("0 2020-01-01 00:00:00 Wow")) - tk.MustQuery(`explain format = 'brief' select a,b,c from t where a = 0 AND c = "Wow"`).Check(testkit.Rows( - `IndexReader 0.50 root partition:p3,p4,p5,p6,p7 index:Selection`, - `└─Selection 0.50 cop[tikv] eq(rcolumnsmulti.t.c, "Wow")`, - ` └─IndexRangeScan 1.00 cop[tikv] table:t, index:a(a, b, c) range:[0,0], keep order:false`)) -} - -func TestRangeColumnsExpr(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`create database rce`) - tk.MustExec(`use rce`) - tk.MustExec(`create table tref (a int unsigned, b int, c int)`) - tk.MustExec(`create table t (a int unsigned, b int, c int) partition by range columns (a,b) ` + - `(partition p0 values less than (3, MAXVALUE), ` + - ` partition p1 values less than (4, -2147483648), ` + - ` partition p2 values less than (4, 1), ` + - ` partition p3 values less than (4, 4), ` + - ` partition p4 values less than (4, 7), ` + - ` partition p5 values less than (4, 11), ` + - ` partition p6 values less than (4, 14), ` + - ` partition p7 values less than (4, 17), ` + - ` partition p8 values less than (4, MAXVALUE), ` + - ` partition p9 values less than (7, 0), ` + - ` partition p10 values less than (11, MAXVALUE), ` + - ` partition p11 values less than (14, -2147483648), ` + - ` partition p12 values less than (17, 17), ` + - ` partition p13 values less than (MAXVALUE, -2147483648))`) - allRows := []string{ - "0 0 0", - "11 2147483647 2147483647", - "14 10 4", - "14 2", - "14 ", - "17 16 16", - "17 17 17", - "3 2147483647 9", - "4 -2147483648 -2147483648", - "4 1 1", - "4 10 3", - "4 13 1", - "4 14 2", - "4 2147483647 2147483647", - "4 4 4", - "4 5 6", - "4 4", - "5 0 0", - "7 0 0", - " -2147483648 ", - " ", - } - insertStr := []string{} - for _, row := range allRows { - s := strings.ReplaceAll(row, " ", ",") - s = strings.ReplaceAll(s, "", "NULL") - insertStr = append(insertStr, "("+s+")") - } - tk.MustExec(`insert into t values ` + strings.Join(insertStr, ",")) - tk.MustExec(`insert into tref select * from t`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select * from tref`).Sort().Check(testkit.Rows(allRows...)) - tk.MustQuery(`select * from t`).Sort().Check(testkit.Rows(allRows...)) - tk.MustQuery(`select * from t partition (p0)`).Sort().Check(testkit.Rows( - "0 0 0", - "3 2147483647 9", - " -2147483648 ", - " ")) - tk.MustQuery(`select * from t partition (p1)`).Sort().Check(testkit.Rows( - "4 4")) - tk.MustQuery(`select * from t partition (p2)`).Sort().Check(testkit.Rows( - "4 -2147483648 -2147483648")) - tk.MustQuery(`select * from t partition (p3)`).Sort().Check(testkit.Rows( - "4 1 1")) - tk.MustQuery(`select * from t partition (p4)`).Sort().Check(testkit.Rows( - "4 4 4", - "4 5 6")) - tk.MustQuery(`select * from t partition (p5)`).Sort().Check(testkit.Rows( - "4 10 3")) - tk.MustQuery(`select * from t partition (p6)`).Sort().Check(testkit.Rows( - "4 13 1")) - tk.MustQuery(`select * from t partition (p7)`).Sort().Check(testkit.Rows( - "4 14 2")) - tk.MustQuery(`select * from t partition (p8)`).Sort().Check(testkit.Rows( - "4 2147483647 2147483647")) - tk.MustQuery(`select * from t partition (p9)`).Sort().Check(testkit.Rows( - "5 0 0")) - tk.MustQuery(`select * from t partition (p10)`).Sort().Check(testkit.Rows( - "11 2147483647 2147483647", - "7 0 0")) - tk.MustQuery(`select * from t partition (p11)`).Sort().Check(testkit.Rows( - "14 2", - "14 ")) - tk.MustQuery(`select * from t partition (p12)`).Sort().Check(testkit.Rows( - "14 10 4", - "17 16 16")) - tk.MustQuery(`select * from t partition (p13)`).Sort().Check(testkit.Rows( - "17 17 17")) - tk.MustQuery(`explain format = 'brief' select * from t where c = 3`).Check(testkit.Rows( - "TableReader 1.00 root partition:all data:Selection", - "└─Selection 1.00 cop[tikv] eq(rce.t.c, 3)", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`explain format = 'brief' select * from t where b > 3 and c = 3`).Check(testkit.Rows( - "TableReader 0.52 root partition:all data:Selection", - "└─Selection 0.52 cop[tikv] eq(rce.t.c, 3), gt(rce.t.b, 3)", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`explain format = 'brief' select * from t where a = 5 and c = 3`).Check(testkit.Rows( - "TableReader 0.05 root partition:p9 data:Selection", - "└─Selection 0.05 cop[tikv] eq(rce.t.a, 5), eq(rce.t.c, 3)", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`explain format = 'brief' select * from t where a = 4 and c = 3`).Check(testkit.Rows( - "TableReader 0.43 root partition:p1,p2,p3,p4,p5,p6,p7,p8 data:Selection", - "└─Selection 0.43 cop[tikv] eq(rce.t.a, 4), eq(rce.t.c, 3)", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`explain format = 'brief' select * from t where a in (4,14) and c = 3`).Check(testkit.Rows( - "TableReader 0.57 root partition:p1,p2,p3,p4,p5,p6,p7,p8,p11,p12 data:Selection", - "└─Selection 0.57 cop[tikv] eq(rce.t.c, 3), in(rce.t.a, 4, 14)", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`explain format = 'brief' select * from t where a in (4,14) and b in (null,10)`).Check(testkit.Rows( - "TableReader 1.14 root partition:p5,p12 data:Selection", - "└─Selection 1.14 cop[tikv] in(rce.t.a, 4, 14), in(rce.t.b, NULL, 10)", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from tref where a in (4,14) and b in (null,10)`).Sort().Check(testkit.Rows( - "14 10 4", - "4 10 3")) - tk.MustQuery(`select * from t where a in (4,14) and b in (null,10)`).Sort().Check(testkit.Rows( - "14 10 4", - "4 10 3")) - tk.MustQuery(`explain format = 'brief' select * from t where a in (4,14) and (b in (11,10) OR b is null)`).Check(testkit.Rows( - "TableReader 3.43 root partition:p1,p5,p6,p11,p12 data:Selection", - "└─Selection 3.43 cop[tikv] in(rce.t.a, 4, 14), or(in(rce.t.b, 11, 10), isnull(rce.t.b))", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from tref where a in (4,14) and (b in (11,10) OR b is null)`).Sort().Check(testkit.Rows( - "14 10 4", - "14 2", - "14 ", - "4 10 3", - "4 4")) - tk.MustQuery(`select * from t where a in (4,14) and (b in (11,10) OR b is null)`).Sort().Check(testkit.Rows( - "14 10 4", - "14 2", - "14 ", - "4 10 3", - "4 4")) -} - -func TestPartitionRangePrunerCharWithCollation(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`create database cwc`) - tk.MustExec(`use cwc`) - // "'c'", "'F'", "'h'", "'L'", "'t'", "MAXVALUE" - tk.MustExec( - `create table t (a char(32) collate utf8mb4_unicode_ci) ` + - `partition by range columns (a) ` + - `(partition p0 values less than ('c'),` + - ` partition p1 values less than ('F'),` + - ` partition p2 values less than ('h'),` + - ` partition p3 values less than ('L'),` + - ` partition p4 values less than ('t'),` + - ` partition p5 values less than (MAXVALUE))`) - - tk.MustExec(`insert into t values ('a'),('A'),('c'),('C'),('f'),('F'),('h'),('H'),('l'),('L'),('t'),('T'),('z'),('Z')`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select * from t partition(p0)`).Sort().Check(testkit.Rows("A", "a")) - tk.MustQuery(`select * from t partition(p1)`).Sort().Check(testkit.Rows("C", "c")) - tk.MustQuery(`select * from t partition(p2)`).Sort().Check(testkit.Rows("F", "f")) - tk.MustQuery(`select * from t partition(p3)`).Sort().Check(testkit.Rows("H", "h")) - tk.MustQuery(`select * from t partition(p4)`).Sort().Check(testkit.Rows("L", "l")) - tk.MustQuery(`select * from t partition(p5)`).Sort().Check(testkit.Rows("T", "Z", "t", "z")) - tk.MustQuery(`select * from t where a > 'C' and a < 'q'`).Sort().Check(testkit.Rows("F", "H", "L", "f", "h", "l")) - tk.MustQuery(`select * from t where a > 'c' and a < 'Q'`).Sort().Check(testkit.Rows("F", "H", "L", "f", "h", "l")) - tk.MustQuery(`explain format = 'brief' select * from t where a > 'C' and a < 'q'`).Check(testkit.Rows( - `TableReader 6.00 root partition:p1,p2,p3,p4 data:Selection`, - `└─Selection 6.00 cop[tikv] gt(cwc.t.a, "C"), lt(cwc.t.a, "q")`, - ` └─TableFullScan 14.00 cop[tikv] table:t keep order:false`)) - tk.MustQuery(`explain format = 'brief' select * from t where a > 'c' and a < 'Q'`).Check(testkit.Rows( - `TableReader 6.00 root partition:p1,p2,p3,p4 data:Selection`, - `└─Selection 6.00 cop[tikv] gt(cwc.t.a, "c"), lt(cwc.t.a, "Q")`, - ` └─TableFullScan 14.00 cop[tikv] table:t keep order:false`)) -} - -func TestPartitionRangePrunerDate(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`create database rcd`) - tk.MustExec(`use rcd`) - tk.MustExec(`set @@tidb_partition_prune_mode = 'dynamic'`) - tk.MustExec(`create table i (a int, b int, key (a,b))`) - tk.MustQuery(`select * from i where a < 1 and a > 2`).Check(testkit.Rows()) - tk.MustQuery(`explain format = 'brief' select * from i where a < 1 and a > 2`).Check(testkit.Rows("TableDual 0.00 root rows:0")) - tk.MustExec( - `create table t (a date) ` + - `partition by range columns (a) ` + - `(partition p0 values less than ('19990601'),` + - ` partition p1 values less than ('2000-05-01'),` + - ` partition p2 values less than ('20080401'),` + - ` partition p3 values less than ('2010-03-01'),` + - ` partition p4 values less than ('20160201'),` + - ` partition p5 values less than ('2020-01-01'),` + - ` partition p6 values less than (MAXVALUE))`) - tk.MustQuery(`show create table t`).Check(testkit.Rows( - "t CREATE TABLE `t` (\n" + - " `a` date DEFAULT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" + - "PARTITION BY RANGE COLUMNS(`a`)\n" + - "(PARTITION `p0` VALUES LESS THAN ('19990601'),\n" + - " PARTITION `p1` VALUES LESS THAN ('2000-05-01'),\n" + - " PARTITION `p2` VALUES LESS THAN ('20080401'),\n" + - " PARTITION `p3` VALUES LESS THAN ('2010-03-01'),\n" + - " PARTITION `p4` VALUES LESS THAN ('20160201'),\n" + - " PARTITION `p5` VALUES LESS THAN ('2020-01-01'),\n" + - " PARTITION `p6` VALUES LESS THAN (MAXVALUE))")) - tk.MustExec(`insert into t values ('19990101'),('1999-06-01'),('2000-05-01'),('20080401'),('2010-03-01'),('2016-02-01'),('2020-01-01')`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select * from t partition(p0)`).Sort().Check(testkit.Rows("1999-01-01")) - tk.MustQuery(`select * from t partition(p1)`).Sort().Check(testkit.Rows("1999-06-01")) - tk.MustQuery(`select * from t partition(p2)`).Sort().Check(testkit.Rows("2000-05-01")) - tk.MustQuery(`select * from t partition(p3)`).Sort().Check(testkit.Rows("2008-04-01")) - tk.MustQuery(`select * from t partition(p4)`).Sort().Check(testkit.Rows("2010-03-01")) - tk.MustQuery(`select * from t partition(p5)`).Sort().Check(testkit.Rows("2016-02-01")) - tk.MustQuery(`select * from t partition(p6)`).Sort().Check(testkit.Rows("2020-01-01")) - tk.UsedPartitions(`select * from t where a < '1943-02-12'`).Check(testkit.Rows("p0")) - tk.UsedPartitions(`select * from t where a >= '19690213'`).Check(testkit.Rows("all")) - tk.UsedPartitions(`select * from t where a > '2003-03-13'`).Check(testkit.Rows("p2 p3 p4 p5 p6")) - tk.UsedPartitions(`select * from t where a < '2006-02-03'`).Check(testkit.Rows("p0 p1 p2")) - tk.UsedPartitions(`select * from t where a = '20070707'`).Check(testkit.Rows("p2")) - tk.UsedPartitions(`select * from t where a > '1949-10-10'`).Check(testkit.Rows("all")) - tk.UsedPartitions(`select * from t where a > '2016-02-01' AND a < '20000103'`).Check(testkit.Rows("dual")) - tk.UsedPartitions(`select * from t where a < '19691112' or a >= '2019-09-18'`).Check(testkit.Rows("p0 p5 p6")) - tk.UsedPartitions(`select * from t where a is null`).Check(testkit.Rows("p0")) - tk.UsedPartitions(`select * from t where '2003-02-27' >= a`).Check(testkit.Rows("p0 p1 p2")) - tk.UsedPartitions(`select * from t where '20141024' < a`).Check(testkit.Rows("p4 p5 p6")) - tk.UsedPartitions(`select * from t where '2003-03-30' > a`).Check(testkit.Rows("p0 p1 p2")) - tk.UsedPartitions(`select * from t where a between '2003-03-30' AND '2014-01-01'`).Check(testkit.Rows("p2 p3 p4")) -} - func BenchmarkPartitionRangeColumns(b *testing.B) { store := testkit.CreateMockStore(b) @@ -1436,77 +313,3 @@ func TestBenchDaily(t *testing.T) { BenchmarkPartitionRangeColumns, ) } - -func TestPartitionRangeColumnPruning(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`create database rcd`) - tk.MustExec(`use rcd`) - tk.MustExec(`create table t1 (a char, b char, c char) ` + - `partition by range columns (a,b,c) ` + - `( partition p0 values less than ('a','b','c'),` + - ` partition p1 values less than ('b','c','d'),` + - ` partition p2 values less than ('d','e','f'))`) - tk.MustExec(`insert into t1 values ('a', NULL, 'd')`) - tk.MustExec(`analyze table t1`) - tk.MustQuery(`explain format=brief select * from t1 where a = 'a' AND c = 'd'`).Check(testkit.Rows( - `TableReader 1.00 root partition:p0,p1 data:Selection`, - `└─Selection 1.00 cop[tikv] eq(rcd.t1.a, "a"), eq(rcd.t1.c, "d")`, - ` └─TableFullScan 1.00 cop[tikv] table:t1 keep order:false`)) - tk.MustQuery(`select * from t1 where a = 'a' AND c = 'd'`).Check(testkit.Rows("a d")) - tk.MustExec(`drop table t1`) -} - -func TestPartitionProcessorWithUninitializedTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(" create table q1(a int, b int, key (a)) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20));") - tk.MustExec(" create table q2(a int, b int, key (a)) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20));") - - rows := [][]interface{}{ - {"HashJoin"}, - {"├─PartitionUnion(Build)"}, - {"│ ├─TableReader"}, - {"│ │ └─TableFullScan"}, - {"│ └─TableReader"}, - {"│ └─TableFullScan"}, - {"└─PartitionUnion(Probe)"}, - {" ├─TableReader"}, - {" │ └─TableFullScan"}, - {" └─TableReader"}, - {" └─TableFullScan"}, - } - tk.MustQuery("explain format=brief select * from q1,q2").CheckAt([]int{0}, rows) - - tk.MustExec("analyze table q1") - tk.MustQuery("explain format=brief select * from q1,q2").CheckAt([]int{0}, rows) - - tk.MustExec("analyze table q2") - rows = [][]interface{}{ - {"HashJoin"}, - {"├─TableReader(Build)"}, - {"│ └─TableFullScan"}, - {"└─TableReader(Probe)"}, - {" └─TableFullScan"}, - } - tk.MustQuery("explain format=brief select * from q1,q2").CheckAt([]int{0}, rows) -} - -func TestIssue42323(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue42323") - defer tk.MustExec("drop database issue42323") - - tk.MustExec("use issue42323") - tk.MustExec("set @@session.tidb_partition_prune_mode = 'dynamic';") - tk.MustExec(`CREATE TABLE t(col1 int(11) NOT NULL DEFAULT '0' ) PARTITION BY RANGE (FLOOR(col1))( - PARTITION p2021 VALUES LESS THAN (202200), - PARTITION p2022 VALUES LESS THAN (202300), - PARTITION p2023 VALUES LESS THAN (202400))`) - tk.MustExec("insert into t values(202303)") - tk.MustExec("analyze table t") - tk.MustQuery(`select * from t where col1 = 202303`).Check(testkit.Rows("202303")) - tk.MustQuery(`select * from t where col1 = floor(202303)`).Check(testkit.Rows("202303")) -} diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index ff0b2b0e4e..23880458f7 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -27,13 +27,11 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" - "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/parser/auth" "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/parser/mysql" - "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/sessionctx/variable" @@ -43,258 +41,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestShowSubquery(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=2") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varchar(10), b int, c int)") - tk.MustQuery("show columns from t where true").Check(testkit.Rows( - "a varchar(10) YES ", - "b int(11) YES ", - "c int(11) YES ", - )) - tk.MustQuery("show columns from t where field = 'b'").Check(testkit.Rows( - "b int(11) YES ", - )) - tk.MustQuery("show columns from t where field in (select 'b')").Check(testkit.Rows( - "b int(11) YES ", - )) - tk.MustQuery("show columns from t where field in (select 'b') and true").Check(testkit.Rows( - "b int(11) YES ", - )) - tk.MustQuery("show columns from t where field in (select 'b') and false").Check(testkit.Rows()) - tk.MustExec("insert into t values('c', 0, 0)") - tk.MustQuery("show columns from t where field < all (select a from t)").Sort().Check(testkit.Rows( - "a varchar(10) YES ", - "b int(11) YES ", - )) - tk.MustExec("insert into t values('b', 0, 0)") - tk.MustQuery("show columns from t where field < all (select a from t)").Check(testkit.Rows( - "a varchar(10) YES ", - )) -} - -func TestJoinOperatorRightAssociative(t *testing.T) { - store := testkit.CreateMockStore(t) - 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)") - tk.MustExec("insert into t values(1,10),(2,20)") - // make sure this join won't rewrite as left-associative join like (t0 join t1) join t2 when explicit parent existed. - // mysql will detect the t0.a is out of it's join parent scope and errors like ERROR 1054 (42S22): Unknown column 't0.a' in 'on clause' - err := tk.ExecToErr("select t1.* from t t0 cross join (t t1 join t t2 on 100=t0.a);") - require.Error(t, err) - require.EqualError(t, err, "[planner:1054]Unknown column 't0.a' in 'on clause'") -} - -func TestPpdWithSetVar(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(c1 int, c2 varchar(255))") - tk.MustExec("insert into t values(1,'a'),(2,'d'),(3,'c')") - - tk.MustQuery("select t01.c1,t01.c2,t01.c3 from (select t1.*,@c3:=@c3+1 as c3 from (select t.*,@c3:=0 from t order by t.c1)t1)t01 where t01.c3=1 and t01.c2='d'").Check(testkit.Rows()) - tk.MustQuery("select t01.c1,t01.c2,t01.c3 from (select t1.*,@c3:=@c3+1 as c3 from (select t.*,@c3:=0 from t order by t.c1)t1)t01 where t01.c3=2 and t01.c2='d'").Check(testkit.Rows("2 d 2")) -} - -func TestBitColErrorMessage(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists bit_col_t") - tk.MustExec("create table bit_col_t (a bit(64))") - tk.MustExec("drop table bit_col_t") - tk.MustExec("create table bit_col_t (a bit(1))") - tk.MustExec("drop table bit_col_t") - tk.MustGetErrCode("create table bit_col_t (a bit(0))", mysql.ErrInvalidFieldSize) - tk.MustGetErrCode("create table bit_col_t (a bit(65))", mysql.ErrTooBigDisplaywidth) -} - -func TestAggPushDownLeftJoin(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=2") - tk.MustExec("drop table if exists customer") - tk.MustExec("create table customer (C_CUSTKEY bigint(20) NOT NULL, C_NAME varchar(25) NOT NULL, " + - "C_ADDRESS varchar(25) NOT NULL, PRIMARY KEY (`C_CUSTKEY`) /*T![clustered_index] CLUSTERED */)") - tk.MustExec("drop table if exists orders") - tk.MustExec("create table orders (O_ORDERKEY bigint(20) NOT NULL, O_CUSTKEY bigint(20) NOT NULL, " + - "O_TOTALPRICE decimal(15,2) NOT NULL, PRIMARY KEY (`O_ORDERKEY`) /*T![clustered_index] CLUSTERED */)") - tk.MustExec("insert into customer values (6, \"xiao zhang\", \"address1\");") - tk.MustExec("set @@tidb_opt_agg_push_down=1;") - - tk.MustQuery("select c_custkey, count(o_orderkey) as c_count from customer left outer join orders " + - "on c_custkey = o_custkey group by c_custkey").Check(testkit.Rows("6 0")) - tk.MustQuery("explain format='brief' select c_custkey, count(o_orderkey) as c_count from customer left outer join orders " + - "on c_custkey = o_custkey group by c_custkey").Check(testkit.Rows( - "Projection 8000.00 root test.customer.c_custkey, Column#7", - "└─HashAgg 8000.00 root group by:test.customer.c_custkey, funcs:count(Column#8)->Column#7, funcs:firstrow(test.customer.c_custkey)->test.customer.c_custkey", - " └─HashJoin 10000.00 root left outer join, equal:[eq(test.customer.c_custkey, test.orders.o_custkey)]", - " ├─HashAgg(Build) 8000.00 root group by:test.orders.o_custkey, funcs:count(Column#9)->Column#8, funcs:firstrow(test.orders.o_custkey)->test.orders.o_custkey", - " │ └─TableReader 8000.00 root data:HashAgg", - " │ └─HashAgg 8000.00 cop[tikv] group by:test.orders.o_custkey, funcs:count(test.orders.o_orderkey)->Column#9", - " │ └─TableFullScan 10000.00 cop[tikv] table:orders keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:customer keep order:false, stats:pseudo")) - - tk.MustQuery("select c_custkey, count(o_orderkey) as c_count from orders right outer join customer " + - "on c_custkey = o_custkey group by c_custkey").Check(testkit.Rows("6 0")) - tk.MustQuery("explain format='brief' select c_custkey, count(o_orderkey) as c_count from orders right outer join customer " + - "on c_custkey = o_custkey group by c_custkey").Check(testkit.Rows( - "Projection 8000.00 root test.customer.c_custkey, Column#7", - "└─HashAgg 8000.00 root group by:test.customer.c_custkey, funcs:count(Column#8)->Column#7, funcs:firstrow(test.customer.c_custkey)->test.customer.c_custkey", - " └─HashJoin 10000.00 root right outer join, equal:[eq(test.orders.o_custkey, test.customer.c_custkey)]", - " ├─HashAgg(Build) 8000.00 root group by:test.orders.o_custkey, funcs:count(Column#9)->Column#8, funcs:firstrow(test.orders.o_custkey)->test.orders.o_custkey", - " │ └─TableReader 8000.00 root data:HashAgg", - " │ └─HashAgg 8000.00 cop[tikv] group by:test.orders.o_custkey, funcs:count(test.orders.o_orderkey)->Column#9", - " │ └─TableFullScan 10000.00 cop[tikv] table:orders keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:customer keep order:false, stats:pseudo")) -} - -func TestIssue22298(t *testing.T) { - store := testkit.CreateMockStore(t) - 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);`) - tk.MustGetErrMsg(`select * from t where 0 and c = 10;`, "[planner:1054]Unknown column 'c' in 'where clause'") -} - -func TestIssue24571(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create view v as select 1 as b;`) - tk.MustExec(`create table t (a int);`) - tk.MustExec(`update v, t set a=2;`) - tk.MustGetErrCode(`update v, t set b=2;`, mysql.ErrNonUpdatableTable) - tk.MustExec("create database db1") - tk.MustExec("use db1") - tk.MustExec("update test.t, (select 1 as a) as t set test.t.a=1;") - // bug in MySQL: ERROR 1288 (HY000): The target table t of the UPDATE is not updatable - tk.MustExec("update (select 1 as a) as t, test.t set test.t.a=1;") -} - -func TestBuildUpdateListResolver(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // For issue https://github.com/pingcap/tidb/issues/24567 - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(a int)") - tk.MustExec("create table t1(b int)") - tk.MustGetErrCode("update (select 1 as a) as t set a=1", mysql.ErrNonUpdatableTable) - tk.MustGetErrCode("update (select 1 as a) as t, t1 set a=1", mysql.ErrNonUpdatableTable) - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - - // For issue https://github.com/pingcap/tidb/issues/30031 - tk.MustExec("create table t(a int default -1, c int as (a+10) stored)") - tk.MustExec("insert into t(a) values(1)") - tk.MustExec("update test.t, (select 1 as b) as t set test.t.a=default") - tk.MustQuery("select * from t").Check(testkit.Rows("-1 9")) - tk.MustExec("drop table if exists t") -} - -func TestIssue22828(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t1;`) - tk.MustExec(`create table t (c int);`) - tk.MustGetErrMsg(`select group_concat((select concat(c,group_concat(c)) FROM t where xxx=xxx)) FROM t;`, "[planner:1054]Unknown column 'xxx' in 'where clause'") -} - -func TestIssue35623(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t1;`) - tk.MustExec(`drop view if exists v1;`) - tk.MustExec(`CREATE TABLE t1(c0 INT UNIQUE);`) - tk.MustExec("CREATE definer='root'@'localhost' VIEW v1(c0) AS SELECT 1 FROM t1;") - err := tk.ExecToErr("SELECT v1.c0 FROM v1 WHERE (true)LIKE(v1.c0);") - require.NoError(t, err) - - err = tk.ExecToErr("SELECT v2.c0 FROM (select 1 as c0 from t1) v2 WHERE (v2.c0)like(True);") - require.NoError(t, err) -} - -func TestIssue37971(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists t3;`) - tk.MustExec(`CREATE TABLE t3(c0 INT, primary key(c0));`) - err := tk.ExecToErr("SELECT v2.c0 FROM (select 1 as c0 from t3) v2 WHERE (v2.c0)like(True);") - require.NoError(t, err) -} - -func TestJoinNotNullFlag(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(x int not null)") - tk.MustExec("create table t2(x int)") - tk.MustExec("insert into t2 values (1)") - - tk.MustQuery("select IFNULL((select t1.x from t1 where t1.x = t2.x), 'xxx') as col1 from t2").Check(testkit.Rows("xxx")) - tk.MustQuery("select ifnull(t1.x, 'xxx') from t2 left join t1 using(x)").Check(testkit.Rows("xxx")) - tk.MustQuery("select ifnull(t1.x, 'xxx') from t2 natural left join t1").Check(testkit.Rows("xxx")) -} - -func TestAntiJoinConstProp(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(a int not null, b int not null)") - tk.MustExec("insert into t1 values (1,1)") - tk.MustExec("create table t2(a int not null, b int not null)") - tk.MustExec("insert into t2 values (2,2)") - - tk.MustQuery("select * from t1 where t1.a not in (select a from t2 where t2.a = t1.a and t2.a > 1)").Check(testkit.Rows( - "1 1", - )) - tk.MustQuery("select * from t1 where t1.a not in (select a from t2 where t2.b = t1.b and t2.a > 1)").Check(testkit.Rows( - "1 1", - )) - tk.MustQuery("select * from t1 where t1.a not in (select a from t2 where t2.b = t1.b and t2.b > 1)").Check(testkit.Rows( - "1 1", - )) - tk.MustQuery("select q.a in (select count(*) from t1 s where not exists (select 1 from t1 p where q.a > 1 and p.a = s.a)) from t1 q").Check(testkit.Rows( - "1", - )) - tk.MustQuery("select q.a in (select not exists (select 1 from t1 p where q.a > 1 and p.a = s.a) from t1 s) from t1 q").Check(testkit.Rows( - "1", - )) - - tk.MustExec("drop table t1, t2") - tk.MustExec("create table t1(a int not null, b int)") - tk.MustExec("insert into t1 values (1,null)") - tk.MustExec("create table t2(a int not null, b int)") - tk.MustExec("insert into t2 values (2,2)") - - tk.MustQuery("select * from t1 where t1.a not in (select a from t2 where t2.b > t1.b)").Check(testkit.Rows( - "1 ", - )) - tk.MustQuery("select * from t1 where t1.a not in (select a from t2 where t1.a = 2)").Check(testkit.Rows( - "1 ", - )) -} - func TestNoneAccessPathsFoundByIsolationRead(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -325,45 +71,6 @@ func TestNoneAccessPathsFoundByIsolationRead(t *testing.T) { tk.MustExec("select * from t") } -func TestPartitionTableDynamicModeUnderNewCollation(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database test_new_collation") - tk.MustExec("use test_new_collation") - tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'") - - // hash + range partition - tk.MustExec(`CREATE TABLE thash (a int, c varchar(20) charset utf8mb4 collate utf8mb4_general_ci, key(a)) partition by hash(a) partitions 4`) - tk.MustExec(`CREATE TABLE trange (a int, c varchar(20) charset utf8mb4 collate utf8mb4_general_ci, key(a)) partition by range(a) ( - partition p0 values less than (10), - partition p1 values less than (20), - partition p2 values less than (30), - partition p3 values less than (40))`) - tk.MustExec(`insert into thash values (1, 'a'), (1, 'A'), (11, 'a'), (11, 'A'), (21, 'a'), (21, 'A'), (31, 'a'), (31, 'A')`) - tk.MustExec(`insert into trange values (1, 'a'), (1, 'A'), (11, 'a'), (11, 'A'), (21, 'a'), (21, 'A'), (31, 'a'), (31, 'A')`) - tk.MustQuery(`select * from thash use index(a) where a in (1, 11, 31) and c='a'`).Sort().Check(testkit.Rows("1 A", "1 a", "11 A", "11 a", "31 A", "31 a")) - tk.MustQuery(`select * from thash ignore index(a) where a in (1, 11, 31) and c='a'`).Sort().Check(testkit.Rows("1 A", "1 a", "11 A", "11 a", "31 A", "31 a")) - tk.MustQuery(`select * from trange use index(a) where a in (1, 11, 31) and c='a'`).Sort().Check(testkit.Rows("1 A", "1 a", "11 A", "11 a", "31 A", "31 a")) - tk.MustQuery(`select * from trange ignore index(a) where a in (1, 11, 31) and c='a'`).Sort().Check(testkit.Rows("1 A", "1 a", "11 A", "11 a", "31 A", "31 a")) - - // range partition and partitioned by utf8mb4_general_ci - tk.MustExec(`create table strrange(a varchar(10) charset utf8mb4 collate utf8mb4_general_ci, b int) partition by range columns(a) ( - partition p0 values less than ('a'), - partition p1 values less than ('k'), - partition p2 values less than ('z'))`) - tk.MustExec("insert into strrange values ('a', 1), ('A', 1), ('y', 1), ('Y', 1), ('q', 1)") - tk.MustQuery("select * from strrange where a in ('a', 'y')").Sort().Check(testkit.Rows("A 1", "Y 1", "a 1", "y 1")) - - // list partition and partitioned by utf8mb4_general_ci - tk.MustExec(`create table strlist(a varchar(10) charset utf8mb4 collate utf8mb4_general_ci, b int) partition by list columns (a) ( - partition p0 values in ('a', 'b'), - partition p1 values in ('c', 'd'), - partition p2 values in ('e', 'f'))`) - tk.MustExec("insert into strlist values ('a', 1), ('A', 1), ('d', 1), ('D', 1), ('e', 1)") - tk.MustQuery(`select * from strlist where a='a'`).Sort().Check(testkit.Rows("A 1", "a 1")) - tk.MustQuery(`select * from strlist where a in ('D', 'e')`).Sort().Check(testkit.Rows("D 1", "d 1", "e 1")) -} - func TestAggPushDownEngine(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -439,45 +146,6 @@ func TestIssue15110(t *testing.T) { tk.MustExec("explain format = 'brief' SELECT count(*) FROM crm_rd_150m dataset_48 WHERE (CASE WHEN (month(dataset_48.customer_first_date)) <= 30 THEN '新客' ELSE NULL END) IS NOT NULL;") } -func TestIssue40910(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, index idx_a(a), index idx_b(b));`) - - tk.MustExec("select * from t where a > 1 and a < 10 order by b;") - tk.MustQuery("select @@last_plan_from_binding").Check(testkit.Rows("0")) - tk.MustExec("create session binding for select * from t where a > 1 and a < 10 order by b using select /*+ use_index(t, idx_a) */ * from t where a > 1 and a < 10 order by b;") - tk.MustExec("select * from t where a > 1 and a < 10 order by b;") - tk.MustQuery("select @@last_plan_from_binding").Check(testkit.Rows("1")) - - tk.MustExec("select /*+ use_index(t, idx_b) */ * from t where a > 1 and a < 10 order by b;") - tk.MustQuery("select @@last_plan_from_binding").Check(testkit.Rows("1")) - - tk.MustExec("select /*+ use_index(t, idx_b) */ * from t where a > 1 and a < 10 order by b;") - tk.MustQuery("show warnings").Check(testkit.Rows( - "Warning 1105 The system ignores the hints in the current query and uses the hints specified in the bindSQL: SELECT /*+ use_index(`t` `idx_a`)*/ * FROM `test`.`t` WHERE `a` > 1 AND `a` < 10 ORDER BY `b`")) -} - -func TestSplitJoinHint(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, index idx_a(a), index idx_b(b));`) - - tk.MustExec(`set @@tidb_opt_advanced_join_hint=0`) - tk.MustExec("select /*+ hash_join(t1) merge_join(t2) */ * from t t1 join t t2 join t t3 where t1.a = t2.a and t2.a=t3.a") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1815 Join hints are conflict, you can only specify one type of join")) - - tk.MustExec(`set @@tidb_opt_advanced_join_hint=1`) - tk.MustExec("select /*+ hash_join(t1) merge_join(t2) */ * from t t1 join t t2 join t t3 where t1.a = t2.a and t2.a=t3.a") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join")) - - tk.MustExec(`set @@tidb_opt_advanced_join_hint=0`) -} - func TestKeepOrderHintWithBinding(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -607,502 +275,6 @@ func TestErrNoDB(t *testing.T) { tk.MustExec("grant select on test1111 to test@'%'") } -func TestINLJHintSmallTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(a int not null, b int, key(a))") - tk.MustExec("insert into t1 values(1,1),(2,2)") - tk.MustExec("create table t2(a int not null, b int, key(a))") - tk.MustExec("insert into t2 values(1,1),(2,2),(3,3),(4,4),(5,5)") - tk.MustExec("analyze table t1, t2") - tk.MustExec("explain format = 'brief' select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a = t2.a") -} - -func TestIssue46580(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`CREATE TABLE t0(c0 INT);`) - tk.MustExec(`CREATE TABLE t1(c0 BOOL, c1 BOOL);`) - tk.MustExec(`INSERT INTO t1 VALUES (false, true);`) - tk.MustExec(`INSERT INTO t1 VALUES (true, true);`) - tk.MustExec(`CREATE definer='root'@'localhost' VIEW v0(c0, c1, c2) AS SELECT t1.c0, LOG10(t0.c0), t1.c0 FROM t0, t1;`) - tk.MustExec(`INSERT INTO t0(c0) VALUES (3);`) - tk.MustQuery(`SELECT /*+ MERGE_JOIN(t1, t0, v0)*/v0.c2, t1.c0 FROM v0, t0 CROSS JOIN t1 ORDER BY -v0.c1;`).Sort().Check( - testkit.Rows(`0 0`, `0 1`, `1 0`, `1 1`)) -} - -func TestInvisibleIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - - // Optimizer cannot see invisible indexes. - tk.MustExec("create table t(a int, b int, unique index i_a (a) invisible, unique index i_b(b))") - tk.MustExec("insert into t values (1,2)") - - // For issue 26217, can't use invisible index after admin check table. - tk.MustExec("admin check table t") - - // Optimizer cannot use invisible indexes. - tk.MustQuery("select a from t order by a").Check(testkit.Rows("1")) - require.False(t, tk.MustUseIndex("select a from t order by a", "i_a")) - tk.MustQuery("select a from t where a > 0").Check(testkit.Rows("1")) - require.False(t, tk.MustUseIndex("select a from t where a > 1", "i_a")) - - // If use invisible indexes in index hint and sql hint, throw an error. - errStr := "[planner:1176]Key 'i_a' doesn't exist in table 't'" - tk.MustGetErrMsg("select * from t use index(i_a)", errStr) - tk.MustGetErrMsg("select * from t force index(i_a)", errStr) - tk.MustGetErrMsg("select * from t ignore index(i_a)", errStr) - tk.MustQuery("select /*+ USE_INDEX(t, i_a) */ * from t") - require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 1) - require.EqualError(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings()[0].Err, errStr) - tk.MustQuery("select /*+ IGNORE_INDEX(t, i_a), USE_INDEX(t, i_b) */ a from t order by a") - require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 1) - require.EqualError(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings()[0].Err, errStr) - tk.MustQuery("select /*+ FORCE_INDEX(t, i_a), USE_INDEX(t, i_b) */ a from t order by a") - require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 1) - require.EqualError(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings()[0].Err, errStr) - // For issue 15519 - inapplicableErrStr := "[planner:1815]force_index(test.aaa) is inapplicable, check whether the table(test.aaa) exists" - tk.MustQuery("select /*+ FORCE_INDEX(aaa) */ * from t") - require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 1) - require.EqualError(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings()[0].Err, inapplicableErrStr) - - tk.MustExec("admin check table t") - tk.MustExec("admin check index t i_a") -} - -func TestTopNByConstFunc(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustQuery("select max(t.col) from (select 'a' as col union all select '' as col) as t").Check(testkit.Rows( - "a", - )) -} - -func TestIssue32672(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - for _, agg := range []string{"stream", "hash"} { - rs := tk.MustQuery(fmt.Sprintf("explain format='verbose' select /*+ %v_agg() */ count(*) from t", agg)).Rows() - // cols: id, estRows, estCost, ... - operator := rs[0][0].(string) - cost, err := strconv.ParseFloat(rs[0][2].(string), 64) - require.NoError(t, err) - require.True(t, strings.Contains(strings.ToLower(operator), agg)) - require.True(t, cost > 0) - } -} - -func TestIssue15546(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t, pt, vt") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("insert into t values(1, 1)") - tk.MustExec("create table pt(a int primary key, b int) partition by range(a) (" + - "PARTITION `p0` VALUES LESS THAN (10), PARTITION `p1` VALUES LESS THAN (20), PARTITION `p2` VALUES LESS THAN (30))") - tk.MustExec("insert into pt values(1, 1), (11, 11), (21, 21)") - tk.MustExec("create definer='root'@'localhost' view vt(a, b) as select a, b from t") - tk.MustQuery("select * from pt, vt where pt.a = vt.a").Check(testkit.Rows("1 1 1 1")) -} - -func TestApproxCountDistinctInPartitionTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int(11), b int) partition by range (a) (partition p0 values less than (3), partition p1 values less than maxvalue);") - tk.MustExec("insert into t values(1, 1), (2, 1), (3, 1), (4, 2), (4, 2)") - tk.MustExec("set session tidb_opt_agg_push_down=1") - tk.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`) - tk.MustQuery("explain format = 'brief' select approx_count_distinct(a), b from t group by b order by b desc").Check(testkit.Rows("Sort 16000.00 root test.t.b:desc", - "└─HashAgg 16000.00 root group by:test.t.b, funcs:approx_count_distinct(Column#5)->Column#4, funcs:firstrow(Column#6)->test.t.b", - " └─PartitionUnion 16000.00 root ", - " ├─HashAgg 8000.00 root group by:test.t.b, funcs:approx_count_distinct(test.t.a)->Column#5, funcs:firstrow(test.t.b)->Column#6, funcs:firstrow(test.t.b)->test.t.b", - " │ └─TableReader 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t, partition:p0 keep order:false, stats:pseudo", - " └─HashAgg 8000.00 root group by:test.t.b, funcs:approx_count_distinct(test.t.a)->Column#5, funcs:firstrow(test.t.b)->Column#6, funcs:firstrow(test.t.b)->test.t.b", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t, partition:p1 keep order:false, stats:pseudo")) - tk.MustQuery("select approx_count_distinct(a), b from t group by b order by b desc").Check(testkit.Rows("1 2", "3 1")) -} - -func TestIssue17813(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists hash_partition_overflow") - tk.MustExec("create table hash_partition_overflow (c0 bigint unsigned) partition by hash(c0) partitions 3") - tk.MustExec("insert into hash_partition_overflow values (9223372036854775808)") - tk.MustQuery("select * from hash_partition_overflow where c0 = 9223372036854775808").Check(testkit.Rows("9223372036854775808")) - tk.MustQuery("select * from hash_partition_overflow where c0 in (1, 9223372036854775808)").Check(testkit.Rows("9223372036854775808")) -} - -func TestIssue15813(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t0, t1") - tk.MustExec("create table t0(c0 int primary key)") - tk.MustExec("create table t1(c0 int primary key)") - tk.MustExec("CREATE INDEX i0 ON t0(c0)") - tk.MustExec("CREATE INDEX i0 ON t1(c0)") - tk.MustQuery("select /*+ MERGE_JOIN(t0, t1) */ * from t0, t1 where t0.c0 = t1.c0").Check(testkit.Rows()) -} - -func TestIssue31261(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec(`use test`) - tk.MustExec(`drop table if exists PK_MULTI_COL_5177`) - tk.MustExec(` CREATE TABLE PK_MULTI_COL_5177 ( - COL1 binary(10) NOT NULL, - COL2 varbinary(10) NOT NULL, - COL3 smallint(45) NOT NULL, - PRIMARY KEY (COL1(5),COL2,COL3), - UNIQUE KEY UIDXM (COL1(5),COL2), - UNIQUE KEY UIDX (COL2), - KEY IDX3 (COL3), - KEY IDXM (COL3,COL2))`) - tk.MustExec(`insert into PK_MULTI_COL_5177(col1, col2, col3) values(0x00000000000000000000, 0x002B200DF5BA03E59F82, 1)`) - require.Len(t, tk.MustQuery(`select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 in (0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82)`).Rows(), 1) - require.Len(t, tk.MustQuery(`select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 = 0x002B200DF5BA03E59F82`).Rows(), 1) -} - -func TestFullGroupByOrderBy(t *testing.T) { - store := testkit.CreateMockStore(t) - 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)") - tk.MustQuery("select count(a) as b from t group by a order by b").Check(testkit.Rows()) - err := tk.ExecToErr("select count(a) as cnt from t group by a order by b") - require.True(t, terror.ErrorEqual(err, core.ErrFieldNotInGroupBy)) -} - -func TestIssue15858(t *testing.T) { - store := testkit.CreateMockStore(t) - 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("select * from t t1, (select a from t order by a+1) t2 where t1.a = t2.a") -} - -func TestIssue15846(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0, t1") - tk.MustExec("CREATE TABLE t0(t0 INT UNIQUE);") - tk.MustExec("CREATE TABLE t1(c0 FLOAT);") - tk.MustExec("INSERT INTO t1(c0) VALUES (0);") - tk.MustExec("INSERT INTO t0(t0) VALUES (NULL), (NULL);") - tk.MustQuery("SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1;").Check(testkit.Rows("0", "0")) - - tk.MustExec("drop table if exists t0, t1") - tk.MustExec("CREATE TABLE t0(t0 INT);") - tk.MustExec("CREATE TABLE t1(c0 FLOAT);") - tk.MustExec("INSERT INTO t1(c0) VALUES (0);") - tk.MustExec("INSERT INTO t0(t0) VALUES (NULL), (NULL);") - tk.MustQuery("SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1;").Check(testkit.Rows("0", "0")) - - tk.MustExec("drop table if exists t0, t1") - tk.MustExec("CREATE TABLE t0(t0 INT);") - tk.MustExec("CREATE TABLE t1(c0 FLOAT);") - tk.MustExec("create unique index idx on t0(t0);") - tk.MustExec("INSERT INTO t1(c0) VALUES (0);") - tk.MustExec("INSERT INTO t0(t0) VALUES (NULL), (NULL);") - tk.MustQuery("SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1;").Check(testkit.Rows("0", "0")) -} - -func TestFloorUnixTimestampPruning(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists floor_unix_timestamp") - tk.MustExec(`create table floor_unix_timestamp (ts timestamp(3)) -partition by range (floor(unix_timestamp(ts))) ( -partition p0 values less than (unix_timestamp('2020-04-05 00:00:00')), -partition p1 values less than (unix_timestamp('2020-04-12 00:00:00')), -partition p2 values less than (unix_timestamp('2020-04-15 00:00:00')))`) - tk.MustExec("insert into floor_unix_timestamp values ('2020-04-04 00:00:00')") - tk.MustExec("insert into floor_unix_timestamp values ('2020-04-04 23:59:59.999')") - tk.MustExec("insert into floor_unix_timestamp values ('2020-04-05 00:00:00')") - tk.MustExec("insert into floor_unix_timestamp values ('2020-04-05 00:00:00.001')") - tk.MustExec("insert into floor_unix_timestamp values ('2020-04-12 01:02:03.456')") - tk.MustExec("insert into floor_unix_timestamp values ('2020-04-14 00:00:42')") - tk.MustQuery("select count(*) from floor_unix_timestamp where '2020-04-05 00:00:00.001' = ts").Check(testkit.Rows("1")) - tk.MustQuery("select * from floor_unix_timestamp where ts > '2020-04-05 00:00:00' order by ts").Check(testkit.Rows("2020-04-05 00:00:00.001", "2020-04-12 01:02:03.456", "2020-04-14 00:00:42.000")) - tk.MustQuery("select count(*) from floor_unix_timestamp where ts <= '2020-04-05 23:00:00'").Check(testkit.Rows("4")) - tk.MustQuery("select * from floor_unix_timestamp partition(p1, p2) where ts > '2020-04-14 00:00:00'").Check(testkit.Rows("2020-04-14 00:00:42.000")) -} - -func TestIssue16290And16292(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, primary key(a));") - tk.MustExec("insert into t values(1, 1);") - - for i := 0; i <= 1; i++ { - tk.MustExec(fmt.Sprintf("set session tidb_opt_agg_push_down = %v", i)) - - tk.MustQuery("select avg(a) from (select * from t ta union all select * from t tb) t;").Check(testkit.Rows("1.0000")) - tk.MustQuery("select avg(b) from (select * from t ta union all select * from t tb) t;").Check(testkit.Rows("1.0000")) - tk.MustQuery("select count(distinct a) from (select * from t ta union all select * from t tb) t;").Check(testkit.Rows("1")) - tk.MustQuery("select count(distinct b) from (select * from t ta union all select * from t tb) t;").Check(testkit.Rows("1")) - } -} - -func TestTableDualWithRequiredProperty(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (a int, b int) partition by range(a) " + - "(partition p0 values less than(10), partition p1 values less than MAXVALUE)") - tk.MustExec("create table t2 (a int, b int)") - tk.MustExec("select /*+ MERGE_JOIN(t1, t2) */ * from t1 partition (p0), t2 where t1.a > 100 and t1.a = t2.a") -} - -func TestIssue16837(t *testing.T) { - store := testkit.CreateMockStore(t) - 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,unique key idx_ab(a,b),unique key(c),unique key(d))") - tk.MustQuery("explain format = 'brief' select /*+ use_index_merge(t,c,idx_ab) */ * from t where a = 1 or (e = 1 and c = 1)").Check(testkit.Rows( - "IndexMerge 0.01 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx_ab(a, b) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:c(c) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.01 cop[tikv] or(eq(test.t.a, 1), and(eq(test.t.e, 1), eq(test.t.c, 1)))", - " └─TableRowIDScan 11.00 cop[tikv] table:t keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustExec("insert into t values (2, 1, 1, 1, 2)") - tk.MustQuery("select /*+ use_index_merge(t,c,idx_ab) */ * from t where a = 1 or (e = 1 and c = 1)").Check(testkit.Rows()) -} - -func TestIndexMergePartialScansClusteredIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, primary key (a, b) clustered, key idx_c(c));") - tk.MustExec("insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100);") - const queryTemplate = "select /*+ use_index_merge(t) */ %s from t where %s order by a, b;" - projections := [][]string{{"a"}, {"b"}, {"c"}, {"a", "b"}, {"b", "c"}, {"c", "a"}, {"b", "a", "c"}} - cases := []struct { - condition string - expected []string - }{ - { - // 1 table scan + 1 index scan - "a < 2 or c > 10000", []string{"1"}, - }, - { - // 2 table scans + 1 index scan - "a < 2 or a > 88 or c > 10000", []string{"1", "100"}, - }, - { - // 2 table scans + 2 index scans - "a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1", []string{"1", "10", "100"}, - }, - { - // 3 table scans + 2 index scans - "a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1", []string{"1", "10", "100"}, - }, - } - for _, p := range projections { - for _, ca := range cases { - query := fmt.Sprintf(queryTemplate, strings.Join(p, ","), ca.condition) - tk.MustHavePlan(query, "IndexMerge") - expected := make([]string, 0, len(ca.expected)) - for _, datum := range ca.expected { - row := strings.Repeat(datum+" ", len(p)) - expected = append(expected, row[:len(row)-1]) - } - tk.MustQuery(query).Check(testkit.Rows(expected...)) - } - } -} - -func TestIndexMergePartialScansTiDBRowID(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, unique key (a, b), key idx_c(c));") - tk.MustExec("insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100);") - const queryTemplate = "select /*+ use_index_merge(t) */ %s from t where %s order by a;" - projections := [][]string{{"a"}, {"b"}, {"c"}, {"a", "b"}, {"b", "c"}, {"c", "a"}, {"b", "a", "c"}} - cases := []struct { - condition string - expected []string - }{ - { - // 2 index scans - "c < 10 or a < 2", []string{"1"}, - }, - { - // 1 table scan + 1 index scan - "_tidb_rowid < 2 or c > 10000", []string{"1"}, - }, - { - // 2 table scans + 1 index scan - "_tidb_rowid < 2 or _tidb_rowid < 10 or c > 11", []string{"1", "10", "100"}, - }, - { - // 1 table scans + 3 index scans - "_tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1", []string{"1", "10", "100"}, - }, - { - // 1 table scans + 4 index scans - "_tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1", []string{"1", "10", "100"}, - }, - } - for _, p := range projections { - for _, ca := range cases { - query := fmt.Sprintf(queryTemplate, strings.Join(p, ","), ca.condition) - tk.MustHavePlan(query, "IndexMerge") - expected := make([]string, 0, len(ca.expected)) - for _, datum := range ca.expected { - row := strings.Repeat(datum+" ", len(p)) - expected = append(expected, row[:len(row)-1]) - } - tk.MustQuery(query).Check(testkit.Rows(expected...)) - } - } -} - -func TestIndexMergePartialScansPKIsHandle(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, primary key (a), unique key (b), key idx_c(c));") - tk.MustExec("insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100);") - const queryTemplate = "select /*+ use_index_merge(t) */ %s from t where %s order by b;" - projections := [][]string{{"a"}, {"b"}, {"c"}, {"a", "b"}, {"b", "c"}, {"c", "a"}, {"b", "a", "c"}} - cases := []struct { - condition string - expected []string - }{ - { - // 3 index scans - "b < 10 or c < 11 or c > 50", []string{"1", "10", "100"}, - }, - { - // 1 table scan + 1 index scan - "a < 2 or c > 10000", []string{"1"}, - }, - { - // 2 table scans + 1 index scan - "a < 2 or a < 10 or b > 11", []string{"1", "100"}, - }, - { - // 1 table scans + 3 index scans - "a < 2 or b >= 10 or c > 100 or c < 1", []string{"1", "10", "100"}, - }, - { - // 3 table scans + 2 index scans - "a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1", []string{"1", "10", "100"}, - }, - } - for _, p := range projections { - for _, ca := range cases { - query := fmt.Sprintf(queryTemplate, strings.Join(p, ","), ca.condition) - tk.MustHavePlan(query, "IndexMerge") - expected := make([]string, 0, len(ca.expected)) - for _, datum := range ca.expected { - row := strings.Repeat(datum+" ", len(p)) - expected = append(expected, row[:len(row)-1]) - } - tk.MustQuery(query).Check(testkit.Rows(expected...)) - } - } -} - -func TestIssue23919(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - - // Test for the minimal reproducible case. - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t (a int, b int, index(a), index(b)) partition by hash (a) partitions 2;") - tk.MustExec("insert into t values (1, 5);") - tk.MustQuery("select /*+ use_index_merge( t ) */ * from t where a in (3) or b in (5) order by a;"). - Check(testkit.Rows("1 5")) - - // Test for the original case. - tk.MustExec("drop table if exists t;") - tk.MustExec(`CREATE TABLE t ( - col_5 text NOT NULL, - col_6 tinyint(3) unsigned DEFAULT NULL, - col_7 float DEFAULT '4779.165058537128', - col_8 smallint(6) NOT NULL DEFAULT '-24790', - col_9 date DEFAULT '2031-01-15', - col_37 int(11) DEFAULT '1350204687', - PRIMARY KEY (col_5(6),col_8) /*T![clustered_index] NONCLUSTERED */, - UNIQUE KEY idx_6 (col_9,col_7,col_8), - KEY idx_8 (col_8,col_6,col_5(6),col_9,col_7), - KEY idx_9 (col_9,col_7,col_8) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY RANGE ( col_8 ) ( - PARTITION p0 VALUES LESS THAN (-17650), - PARTITION p1 VALUES LESS THAN (-13033), - PARTITION p2 VALUES LESS THAN (2521), - PARTITION p3 VALUES LESS THAN (7510) -);`) - tk.MustExec("insert into t values ('', NULL, 6304.0146, -24790, '2031-01-15', 1350204687);") - tk.MustQuery("select var_samp(col_7) aggCol from (select /*+ use_index_merge( t ) */ * from t where " + - "t.col_9 in ( '2002-06-22' ) or t.col_5 in ( 'PkfzI' ) or t.col_8 in ( -24874 ) and t.col_6 > null and " + - "t.col_5 > 'r' and t.col_9 in ( '1979-09-04' ) and t.col_7 < 8143.667552769195 or " + - "t.col_5 in ( 'iZhfEjRWci' , 'T' , '' ) or t.col_9 <> '1976-09-11' and t.col_7 = 8796.436181615773 and " + - "t.col_8 = 7372 order by col_5,col_8 ) ordered_tbl group by col_6;").Check(testkit.Rows("")) -} - -func TestIssue16407(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int,b char(100),key(a),key(b(10)))") - tk.MustQuery("explain format = 'brief' select /*+ use_index_merge(t) */ * from t where a=10 or b='x'").Check(testkit.Rows( - "IndexMerge 0.04 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[10,10], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[\"x\",\"x\"], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.04 cop[tikv] or(eq(test.t.a, 10), eq(test.t.b, \"x\"))", - " └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows()) - tk.MustExec("insert into t values (1, 'xx')") - tk.MustQuery("select /*+ use_index_merge(t) */ * from t where a=10 or b='x'").Check(testkit.Rows()) -} - func TestNotReadOnlySQLOnTiFlash(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1136,141 +308,6 @@ func TestNotReadOnlySQLOnTiFlash(t *testing.T) { require.EqualError(t, err, `[planner:1815]Internal : No access path for table 't' is found with 'tidb_isolation_read_engines' = 'tiflash', valid values can be 'tiflash, tikv'. Please check tiflash replica or check if the query is not readonly and sql mode is strict.`) } -func TestSelectLimit(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=2") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - tk.MustExec("insert into t values(1),(1),(2)") - - // normal test - tk.MustExec("set @@session.sql_select_limit=1") - result := tk.MustQuery("select * from t order by a") - require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 0) - result.Check(testkit.Rows("1")) - result = tk.MustQuery("select * from t order by a limit 2") - result.Check(testkit.Rows("1", "1")) - tk.MustExec("set @@session.sql_select_limit=default") - result = tk.MustQuery("select * from t order by a") - result.Check(testkit.Rows("1", "1", "2")) - - // test for subquery - tk.MustExec("set @@session.sql_select_limit=1") - result = tk.MustQuery("select * from (select * from t) s order by a") - result.Check(testkit.Rows("1")) - result = tk.MustQuery("select * from (select * from t limit 2) s order by a") // limit write in subquery, has no effect. - result.Check(testkit.Rows("1")) - result = tk.MustQuery("select (select * from t limit 1) s") // limit write in subquery, has no effect. - result.Check(testkit.Rows("1")) - result = tk.MustQuery("select * from t where t.a in (select * from t) limit 3") // select_limit will not effect subquery - result.Sort().Check(testkit.Rows("1", "1", "2")) - result = tk.MustQuery("select * from (select * from t) s limit 3") // select_limit will not effect subquery - result.Sort().Check(testkit.Rows("1", "1", "2")) - - // test for union - result = tk.MustQuery("select * from t union all select * from t limit 2") // limit outside subquery - result.Check(testkit.Rows("1", "1")) - result = tk.MustQuery("select * from t union all (select * from t limit 2)") // limit inside subquery - result.Check(testkit.Rows("1")) - - // test for prepare & execute - tk.MustExec("prepare s1 from 'select * from t where a = ?'") - tk.MustExec("set @a = 1") - result = tk.MustQuery("execute s1 using @a") - result.Check(testkit.Rows("1")) - tk.MustExec("set @@session.sql_select_limit=default") - result = tk.MustQuery("execute s1 using @a") - result.Check(testkit.Rows("1", "1")) - tk.MustExec("set @@session.sql_select_limit=1") - tk.MustExec("prepare s2 from 'select * from t where a = ? limit 3'") - result = tk.MustQuery("execute s2 using @a") // if prepare stmt has limit, select_limit takes no effect. - result.Check(testkit.Rows("1", "1")) - - // test for create view - tk.MustExec("set @@session.sql_select_limit=1") - tk.MustExec("create definer='root'@'localhost' view s as select * from t") // select limit should not effect create view - result = tk.MustQuery("select * from s") - result.Check(testkit.Rows("1")) - tk.MustExec("set @@session.sql_select_limit=default") - result = tk.MustQuery("select * from s") - result.Sort().Check(testkit.Rows("1", "1", "2")) - - // test for DML - tk.MustExec("set @@session.sql_select_limit=1") - tk.MustExec("create table b (a int)") - tk.MustExec("insert into b select * from t") // all values are inserted - result = tk.MustQuery("select * from b limit 3") - result.Sort().Check(testkit.Rows("1", "1", "2")) - tk.MustExec("update b set a = 2 where a = 1") // all values are updated - result = tk.MustQuery("select * from b limit 3") - result.Check(testkit.Rows("2", "2", "2")) - result = tk.MustQuery("select * from b") - result.Check(testkit.Rows("2")) - tk.MustExec("delete from b where a = 2") // all values are deleted - result = tk.MustQuery("select * from b") - result.Check(testkit.Rows()) -} - -func TestHintParserWarnings(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, key(a), key(b));") - tk.MustExec("select /*+ use_index_merge() */ * from t where a = 1 or b = 1;") - rows := tk.MustQuery("show warnings;").Rows() - require.Len(t, rows, 1) -} - -func TestIssue16935(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0;") - tk.MustExec("CREATE TABLE t0(c0 INT);") - tk.MustExec("INSERT INTO t0(c0) VALUES (1), (1), (1), (1), (1), (1);") - tk.MustExec("CREATE definer='root'@'localhost' VIEW v0(c0) AS SELECT NULL FROM t0;") - tk.MustQuery("SELECT * FROM t0 LEFT JOIN v0 ON TRUE WHERE v0.c0 IS NULL;") -} - -func TestClusterIndexUniqueDoubleRead(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database cluster_idx_unique_double_read;") - tk.MustExec("use cluster_idx_unique_double_read;") - defer tk.MustExec("drop database cluster_idx_unique_double_read;") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - tk.MustExec("drop table if exists t") - - tk.MustExec("create table t (a varchar(64), b varchar(64), uk int, v int, primary key(a, b), unique key uuk(uk));") - tk.MustExec("insert t values ('a', 'a1', 1, 11), ('b', 'b1', 2, 22), ('c', 'c1', 3, 33);") - tk.MustQuery("select * from t use index (uuk);").Check(testkit.Rows("a a1 1 11", "b b1 2 22", "c c1 3 33")) -} - -func TestIssue18984(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t2") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - tk.MustExec("create table t(a int, b int, c int, primary key(a, b))") - tk.MustExec("create table t2(a int, b int, c int, d int, primary key(a,b), index idx(c))") - tk.MustExec("insert into t values(1,1,1), (2,2,2), (3,3,3)") - tk.MustExec("insert into t2 values(1,2,3,4), (2,4,3,5), (1,3,1,1)") - tk.MustQuery("select /*+ INL_MERGE_JOIN(t) */ * from t right outer join t2 on t.a=t2.c").Check(testkit.Rows( - "1 1 1 1 3 1 1", - "3 3 3 1 2 3 4", - "3 3 3 2 4 3 5")) - tk.MustQuery("select /*+ INL_MERGE_JOIN(t2) */ * from t left outer join t2 on t.a=t2.c").Check(testkit.Rows( - "1 1 1 1 3 1 1", - "2 2 2 ", - "3 3 3 1 2 3 4", - "3 3 3 2 4 3 5")) -} - func TestTimeToSecPushDownToTiFlash(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1746,18 +783,6 @@ func TestScalarFunctionPushDown(t *testing.T) { CheckAt([]int{0, 3, 6}, rows) } -func TestDistinctScalarFunctionPushDown(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int not null, b int not null, c int not null, primary key (a,c)) partition by range (c) (partition p0 values less than (5), partition p1 values less than (10))") - tk.MustExec("insert into t values(1,1,1),(2,2,2),(3,1,3),(7,1,7),(8,2,8),(9,2,9)") - tk.MustQuery("select count(distinct b+1) as col from t").Check(testkit.Rows( - "2", - )) -} - func TestReverseUTF8PushDownToTiFlash(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -2007,153 +1032,6 @@ func TestExplainAnalyzeDML2(t *testing.T) { } } -func TestPartialBatchPointGet(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c_int int, c_str varchar(40), primary key(c_int, c_str))") - tk.MustExec("insert into t values (3, 'bose')") - tk.MustQuery("select * from t where c_int in (3)").Check(testkit.Rows( - "3 bose", - )) - tk.MustQuery("select * from t where c_int in (3) or c_str in ('yalow') and c_int in (1, 2)").Check(testkit.Rows( - "3 bose", - )) -} - -func TestIssue19926(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists ta;") - tk.MustExec("drop table if exists tb;") - tk.MustExec("drop table if exists tc;") - tk.MustExec("drop view if exists v;") - tk.MustExec("CREATE TABLE `ta` (\n `id` varchar(36) NOT NULL ,\n `status` varchar(1) NOT NULL \n);") - tk.MustExec("CREATE TABLE `tb` (\n `id` varchar(36) NOT NULL ,\n `status` varchar(1) NOT NULL \n);") - tk.MustExec("CREATE TABLE `tc` (\n `id` varchar(36) NOT NULL ,\n `status` varchar(1) NOT NULL \n);") - tk.MustExec("insert into ta values('1','1');") - tk.MustExec("insert into tb values('1','1');") - tk.MustExec("insert into tc values('1','1');") - tk.MustExec("create definer='root'@'localhost' view v as\nselect \nconcat(`ta`.`status`,`tb`.`status`) AS `status`, \n`ta`.`id` AS `id` from (`ta` join `tb`) \nwhere (`ta`.`id` = `tb`.`id`);") - tk.MustQuery("SELECT tc.status,v.id FROM tc, v WHERE tc.id = v.id AND v.status = '11';").Check(testkit.Rows("1 1")) -} - -func TestDeleteUsingJoin(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(a int primary key, b int)") - tk.MustExec("create table t2(a int primary key, b int)") - tk.MustExec("insert into t1 values(1,1),(2,2)") - tk.MustExec("insert into t2 values(2,2)") - tk.MustExec("delete t1.* from t1 join t2 using (a)") - tk.MustQuery("select * from t1").Check(testkit.Rows("1 1")) - tk.MustQuery("select * from t2").Check(testkit.Rows("2 2")) -} - -func Test19942(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn - tk.MustExec("CREATE TABLE test.`t` (" + - " `a` int(11) NOT NULL," + - " `b` varchar(10) COLLATE utf8_general_ci NOT NULL," + - " `c` varchar(50) COLLATE utf8_general_ci NOT NULL," + - " `d` char(10) NOT NULL," + - " PRIMARY KEY (`c`)," + - " UNIQUE KEY `a_uniq` (`a`)," + - " UNIQUE KEY `b_uniq` (`b`)," + - " UNIQUE KEY `d_uniq` (`d`)," + - " KEY `a_idx` (`a`)," + - " KEY `b_idx` (`b`)," + - " KEY `d_idx` (`d`)" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;") - tk.MustExec("INSERT INTO test.t (a, b, c, d) VALUES (1, '1', '0', '1');") - tk.MustExec("INSERT INTO test.t (a, b, c, d) VALUES (2, ' 2', ' 0', ' 2');") - tk.MustExec("INSERT INTO test.t (a, b, c, d) VALUES (3, ' 3 ', ' 3 ', ' 3 ');") - tk.MustExec("INSERT INTO test.t (a, b, c, d) VALUES (4, 'a', 'a ', 'a');") - tk.MustExec("INSERT INTO test.t (a, b, c, d) VALUES (5, ' A ', ' A ', ' A ');") - tk.MustExec("INSERT INTO test.t (a, b, c, d) VALUES (6, ' E', 'é ', ' E');") - - mkr := func() [][]interface{} { - return testkit.RowsWithSep("|", - "3| 3 | 3 | 3", - "2| 2 0| 2", - "5| A | A | A", - "1|1|0|1", - "4|a|a |a", - "6| E|é | E") - } - tk.MustQuery("SELECT * FROM `test`.`t` FORCE INDEX(`a_uniq`);").Check(mkr()) - tk.MustQuery("SELECT * FROM `test`.`t` FORCE INDEX(`b_uniq`);").Check(mkr()) - tk.MustQuery("SELECT * FROM `test`.`t` FORCE INDEX(`d_uniq`);").Check(mkr()) - tk.MustQuery("SELECT * FROM `test`.`t` FORCE INDEX(`a_idx`);").Check(mkr()) - tk.MustQuery("SELECT * FROM `test`.`t` FORCE INDEX(`b_idx`);").Check(mkr()) - tk.MustQuery("SELECT * FROM `test`.`t` FORCE INDEX(`d_idx`);").Check(mkr()) - tk.MustExec("admin check table t") -} - -func TestPartitionUnionWithPPruningColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("CREATE TABLE `t` (\n `fid` bigint(36) NOT NULL,\n `oty` varchar(30) DEFAULT NULL,\n `oid` int(11) DEFAULT NULL,\n `pid` bigint(20) DEFAULT NULL,\n `bid` int(11) DEFAULT NULL,\n `r5` varchar(240) DEFAULT '',\n PRIMARY KEY (`fid`)\n)PARTITION BY HASH( `fid` ) PARTITIONS 4;") - - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (59, 'm', 441, 1, 2143, 'LE1264_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (135, 'm', 1121, 1, 2423, 'LE2008_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (139, 'm', 1125, 1, 2432, 'LE2005_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (143, 'm', 1129, 1, 2438, 'LE2006_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (147, 'm', 1133, 1, 2446, 'LE2014_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (167, 'm', 1178, 1, 2512, 'LE2055_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (171, 'm', 1321, 1, 2542, 'LE1006_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (179, 'm', 1466, 1, 2648, 'LE2171_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (187, 'm', 1567, 1, 2690, 'LE1293_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (57, 'm', 341, 1, 2102, 'LE1001_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (137, 'm', 1123, 1, 2427, 'LE2003_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (145, 'm', 1131, 1, 2442, 'LE2048_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (138, 'm', 1124, 1, 2429, 'LE2004_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (142, 'm', 1128, 1, 2436, 'LE2049_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (174, 'm', 1381, 1, 2602, 'LE2170_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (28, 'm', 81, 1, 2023, 'LE1009_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (60, 'm', 442, 1, 2145, 'LE1263_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (136, 'm', 1122, 1, 2425, 'LE2002_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (140, 'm', 1126, 1, 2434, 'LE2001_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (168, 'm', 1179, 1, 2514, 'LE2052_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (196, 'm', 3380, 1, 2890, 'LE1300_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (208, 'm', 3861, 1, 3150, 'LE1323_r5');") - tk.MustExec("INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (432, 'm', 4060, 1, 3290, 'LE1327_r5');") - - tk.MustQuery("SELECT DISTINCT t.bid, t.r5 FROM t left join t parent on parent.oid = t.pid WHERE t.oty = 'm';").Sort().Check( - testkit.Rows("2023 LE1009_r5", - "2102 LE1001_r5", - "2143 LE1264_r5", - "2145 LE1263_r5", - "2423 LE2008_r5", - "2425 LE2002_r5", - "2427 LE2003_r5", - "2429 LE2004_r5", - "2432 LE2005_r5", - "2434 LE2001_r5", - "2436 LE2049_r5", - "2438 LE2006_r5", - "2442 LE2048_r5", - "2446 LE2014_r5", - "2512 LE2055_r5", - "2514 LE2052_r5", - "2542 LE1006_r5", - "2602 LE2170_r5", - "2648 LE2171_r5", - "2690 LE1293_r5", - "2890 LE1300_r5", - "3150 LE1323_r5", - "3290 LE1327_r5")) -} - func TestIssue20139(t *testing.T) { failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`) defer failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune") @@ -2173,333 +1051,6 @@ func TestIssue20139(t *testing.T) { tk.MustExec("drop table t") } -func TestIssue14481(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int default null, b int default null, c int default null)") - plan := tk.MustQuery("explain format = 'brief' select * from t where a = 1 and a = 2") - plan.Check(testkit.Rows("TableDual 0.00 root rows:0")) - tk.MustExec("drop table t") -} - -func TestQueryBlockTableAliasInHint(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustHavePlan("select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2", "HashJoin") - tk.MustQuery("select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2").Check(testkit.Rows( - "1 2", - )) - require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 0) -} - -func TestIssue10448(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - - tk.MustExec("create table t(pk int(11) primary key)") - tk.MustExec("insert into t values(1),(2),(3)") - tk.MustQuery("select a from (select pk as a from t) t1 where a = 18446744073709551615").Check(testkit.Rows()) -} - -func TestMultiUpdateOnPrimaryKey(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int not null primary key)") - tk.MustExec("insert into t values (1)") - tk.MustGetErrMsg(`UPDATE t m, t n SET m.a = m.a + 10, n.a = n.a + 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'.`) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a varchar(10) not null primary key)") - tk.MustExec("insert into t values ('abc')") - tk.MustGetErrMsg(`UPDATE t m, t n SET m.a = 'def', n.a = 'xyz'`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'.`) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int, b int, primary key (a, b))") - tk.MustExec("insert into t values (1, 2)") - tk.MustGetErrMsg(`UPDATE t m, t n SET m.a = m.a + 10, n.b = n.b + 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'.`) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int primary key, b int)") - tk.MustExec("insert into t values (1, 2)") - tk.MustGetErrMsg(`UPDATE t m, t n SET m.a = m.a + 10, n.a = n.a + 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'.`) - - tk.MustExec(`UPDATE t m, t n SET m.b = m.b + 10, n.b = n.b + 10`) - tk.MustQuery("SELECT * FROM t").Check(testkit.Rows("1 12")) - - tk.MustGetErrMsg(`UPDATE t m, t n SET m.a = m.a + 1, n.b = n.b + 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'.`) - tk.MustGetErrMsg(`UPDATE t m, t n, t q SET m.a = m.a + 1, n.b = n.b + 10, q.b = q.b - 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'.`) - tk.MustGetErrMsg(`UPDATE t m, t n, t q SET m.b = m.b + 1, n.a = n.a + 10, q.b = q.b - 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'.`) - tk.MustGetErrMsg(`UPDATE t m, t n, t q SET m.b = m.b + 1, n.b = n.b + 10, q.a = q.a - 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'm' and 'q'.`) - tk.MustGetErrMsg(`UPDATE t q, t n, t m SET m.b = m.b + 1, n.b = n.b + 10, q.a = q.a - 10`, - `[planner:1706]Primary key/partition key update is not allowed since the table is updated both as 'q' and 'n'.`) - - tk.MustExec("update t m, t n set m.a = n.a+10 where m.a=n.a") - tk.MustQuery("select * from t").Check(testkit.Rows("11 12")) -} - -func TestOrderByHavingNotInSelect(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists ttest") - tk.MustExec("create table ttest (v1 int, v2 int)") - tk.MustExec("insert into ttest values(1, 2), (4,6), (1, 7)") - tk.MustGetErrMsg("select v1 from ttest order by count(v2)", - "[planner:3029]Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query") - tk.MustGetErrMsg("select v1 from ttest having count(v2)", - "[planner:8123]In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'v1'; this is incompatible with sql_mode=only_full_group_by") - tk.MustGetErrMsg("select v2, v1 from (select * from ttest) t1 join (select 1, 2) t2 group by v1", - "[planner:1055]Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t1.v2' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by") - tk.MustGetErrMsg("select v2, v1 from (select t1.v1, t2.v2 from ttest t1 join ttest t2) t3 join (select 1, 2) t2 group by v1", - "[planner:1055]Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t3.v2' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by") -} - -func TestUpdateSetDefault(t *testing.T) { - store := testkit.CreateMockStore(t) - // #20598 - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table tt (x int, z int as (x+10) stored)") - tk.MustExec("insert into tt(x) values (1)") - tk.MustExec("update tt set x=2, z = default") - tk.MustExec("update tt set x=2, z = default(z)") - tk.MustQuery("select * from tt").Check(testkit.Rows("2 12")) - - tk.MustGetErrMsg("update tt set x=2, z = default(x)", - "[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.") - tk.MustGetErrMsg("update tt set z = 123", - "[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.") - tk.MustGetErrMsg("update tt as ss set z = 123", - "[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.") - tk.MustGetErrMsg("update tt as ss set x = 3, z = 13", - "[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.") - tk.MustGetErrMsg("update tt as s1, tt as s2 set s1.z = default, s2.z = 456", - "[planner:3105]The value specified for generated column 'z' in table 'tt' is not allowed.") -} - -func TestExtendedStatsSwitch(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int not null, b int not null, key(a), key(b))") - tk.MustExec("insert into t values(1,1),(2,2),(3,3),(4,4),(5,5),(6,6)") - - tk.MustExec("set session tidb_enable_extended_stats = off") - tk.MustGetErrMsg("alter table t add stats_extended s1 correlation(a,b)", - "Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF") - tk.MustGetErrMsg("alter table t drop stats_extended s1", - "Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF") - tk.MustGetErrMsg("admin reload stats_extended", - "Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF") - - tk.MustExec("set session tidb_enable_extended_stats = on") - tk.MustExec("alter table t add stats_extended s1 correlation(a,b)") - tk.MustQuery("select stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows( - " 0", - )) - tk.MustExec("set session tidb_enable_extended_stats = off") - // Analyze should not collect extended stats. - tk.MustExec("analyze table t") - tk.MustQuery("select stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows( - " 0", - )) - tk.MustExec("set session tidb_enable_extended_stats = on") - // Analyze would collect extended stats. - tk.MustExec("analyze table t") - tk.MustQuery("select stats, status from mysql.stats_extended where name = 's1'").Check(testkit.Rows( - "1.000000 1", - )) - - // Estimated index scan count is 4 using extended stats. - tk.MustQuery("explain format = 'brief' select * from t use index(b) where a > 3 order by b limit 1").Check(testkit.Rows( - "Limit 1.00 root offset:0, count:1", - "└─Projection 1.00 root test.t.a, test.t.b", - " └─IndexLookUp 1.00 root ", - " ├─IndexFullScan(Build) 4.00 cop[tikv] table:t, index:b(b) keep order:true", - " └─Selection(Probe) 1.00 cop[tikv] gt(test.t.a, 3)", - " └─TableRowIDScan 4.00 cop[tikv] table:t keep order:false", - )) - tk.MustExec("set session tidb_enable_extended_stats = off") - // Estimated index scan count is 2 using independent assumption. - tk.MustQuery("explain format = 'brief' select * from t use index(b) where a > 3 order by b limit 1").Check(testkit.Rows( - "Limit 1.00 root offset:0, count:1", - "└─Projection 1.00 root test.t.a, test.t.b", - " └─IndexLookUp 1.00 root ", - " ├─IndexFullScan(Build) 2.00 cop[tikv] table:t, index:b(b) keep order:true", - " └─Selection(Probe) 1.00 cop[tikv] gt(test.t.a, 3)", - " └─TableRowIDScan 2.00 cop[tikv] table:t keep order:false", - )) -} - -func TestOrderByNotInSelectDistinct(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // #12442 - tk.MustExec("drop table if exists ttest") - tk.MustExec("create table ttest (v1 int, v2 int)") - tk.MustExec("insert into ttest values(1, 2), (4,6), (1, 7)") - - tk.MustGetErrMsg("select distinct v1 from ttest order by v2", - "[planner:3065]Expression #1 of ORDER BY clause is not in SELECT list, references column 'test.ttest.v2' which is not in SELECT list; this is incompatible with DISTINCT") - tk.MustGetErrMsg("select distinct v1+1 from ttest order by v1", - "[planner:3065]Expression #1 of ORDER BY clause is not in SELECT list, references column 'test.ttest.v1' which is not in SELECT list; this is incompatible with DISTINCT") - tk.MustGetErrMsg("select distinct v1+1 from ttest order by 1+v1", - "[planner:3065]Expression #1 of ORDER BY clause is not in SELECT list, references column 'test.ttest.v1' which is not in SELECT list; this is incompatible with DISTINCT") - tk.MustGetErrMsg("select distinct v1+1 from ttest order by v1+2", - "[planner:3065]Expression #1 of ORDER BY clause is not in SELECT list, references column 'test.ttest.v1' which is not in SELECT list; this is incompatible with DISTINCT") - tk.MustGetErrMsg("select distinct count(v1) from ttest group by v2 order by sum(v1)", - "[planner:3066]Expression #1 of ORDER BY clause is not in SELECT list, contains aggregate function; this is incompatible with DISTINCT") - tk.MustGetErrMsg("select distinct sum(v1)+1 from ttest group by v2 order by sum(v1)", - "[planner:3066]Expression #1 of ORDER BY clause is not in SELECT list, contains aggregate function; this is incompatible with DISTINCT") - - // Expressions in ORDER BY whole match some fields in DISTINCT. - tk.MustQuery("select distinct v1+1 from ttest order by v1+1").Check(testkit.Rows("2", "5")) - tk.MustQuery("select distinct count(v1) from ttest order by count(v1)").Check(testkit.Rows("3")) - tk.MustQuery("select distinct count(v1) from ttest group by v2 order by count(v1)").Check(testkit.Rows("1")) - tk.MustQuery("select distinct sum(v1) from ttest group by v2 order by sum(v1)").Check(testkit.Rows("1", "4")) - tk.MustQuery("select distinct v1, v2 from ttest order by 1, 2").Check(testkit.Rows("1 2", "1 7", "4 6")) - tk.MustQuery("select distinct v1, v2 from ttest order by 2, 1").Check(testkit.Rows("1 2", "4 6", "1 7")) - - // Referenced columns of expressions in ORDER BY whole match some fields in DISTINCT, - // both original expression and alias can be referenced. - tk.MustQuery("select distinct v1 from ttest order by v1+1").Check(testkit.Rows("1", "4")) - tk.MustQuery("select distinct v1, v2 from ttest order by v1+1, v2").Check(testkit.Rows("1 2", "1 7", "4 6")) - tk.MustQuery("select distinct v1+1 as z, v2 from ttest order by v1+1, z+v2").Check(testkit.Rows("2 2", "2 7", "5 6")) - tk.MustQuery("select distinct sum(v1) as z from ttest group by v2 order by z+1").Check(testkit.Rows("1", "4")) - tk.MustQuery("select distinct sum(v1)+1 from ttest group by v2 order by sum(v1)+1").Check(testkit.Rows("2", "5")) - tk.MustQuery("select distinct v1 as z from ttest order by v1+z").Check(testkit.Rows("1", "4")) -} - -func TestInvalidNamedWindowSpec(t *testing.T) { - store := testkit.CreateMockStore(t) - // #12356 - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE IF EXISTS temptest") - tk.MustExec("create table temptest (val int, val1 int)") - tk.MustQuery("SELECT val FROM temptest WINDOW w AS (ORDER BY val RANGE 1 PRECEDING)").Check(testkit.Rows()) - tk.MustGetErrMsg("SELECT val FROM temptest WINDOW w AS (ORDER BY val, val1 RANGE 1 PRECEDING)", - "[planner:3587]Window 'w' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type") - tk.MustGetErrMsg("select val1, avg(val1) as a from temptest group by val1 window w as (order by a)", - "[planner:1054]Unknown column 'a' in 'window order by'") - tk.MustGetErrMsg("select val1, avg(val1) as a from temptest group by val1 window w as (partition by a)", - "[planner:1054]Unknown column 'a' in 'window partition by'") -} - -func TestCorrelatedAggregate(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // #18350 - tk.MustExec("DROP TABLE IF EXISTS tab, tab2") - tk.MustExec("CREATE TABLE tab(i INT)") - tk.MustExec("CREATE TABLE tab2(j INT)") - tk.MustExec("insert into tab values(1),(2),(3)") - tk.MustExec("insert into tab2 values(1),(2),(3),(15)") - tk.MustQuery(`SELECT m.i, - (SELECT COUNT(n.j) - FROM tab2 WHERE j=15) AS o - FROM tab m, tab2 n GROUP BY 1 order by m.i`).Check(testkit.Rows("1 4", "2 4", "3 4")) - tk.MustQuery(`SELECT - (SELECT COUNT(n.j) - FROM tab2 WHERE j=15) AS o - FROM tab m, tab2 n order by m.i`).Check(testkit.Rows("12")) - - // #17748 - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1 (a int, b int)") - tk.MustExec("create table t2 (m int, n int)") - tk.MustExec("insert into t1 values (2,2), (2,2), (3,3), (3,3), (3,3), (4,4)") - tk.MustExec("insert into t2 values (1,11), (2,22), (3,32), (4,44), (4,44)") - tk.MustExec("set @@sql_mode='TRADITIONAL'") - - tk.MustQuery(`select count(*) c, a, - ( select group_concat(count(a)) from t2 where m = a ) - from t1 group by a order by a`). - Check(testkit.Rows("2 2 2", "3 3 3", "1 4 1,1")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int, b int)") - tk.MustExec("insert into t values (1,1),(2,1),(2,2),(3,1),(3,2),(3,3)") - - // Sub-queries in SELECT fields - // from SELECT fields - tk.MustQuery("select (select count(a)) from t").Check(testkit.Rows("6")) - tk.MustQuery("select (select (select (select count(a)))) from t").Check(testkit.Rows("6")) - tk.MustQuery("select (select (select count(n.a)) from t m order by count(m.b)) from t n").Check(testkit.Rows("6")) - // from WHERE - tk.MustQuery("select (select count(n.a) from t where count(n.a)=3) from t n").Check(testkit.Rows("")) - tk.MustQuery("select (select count(a) from t where count(distinct n.a)=3) from t n").Check(testkit.Rows("6")) - // from HAVING - tk.MustQuery("select (select count(n.a) from t having count(n.a)=6 limit 1) from t n").Check(testkit.Rows("6")) - tk.MustQuery("select (select count(n.a) from t having count(distinct n.b)=3 limit 1) from t n").Check(testkit.Rows("6")) - tk.MustQuery("select (select sum(distinct n.a) from t having count(distinct n.b)=3 limit 1) from t n").Check(testkit.Rows("6")) - tk.MustQuery("select (select sum(distinct n.a) from t having count(distinct n.b)=6 limit 1) from t n").Check(testkit.Rows("")) - // from ORDER BY - tk.MustQuery("select (select count(n.a) from t order by count(n.b) limit 1) from t n").Check(testkit.Rows("6")) - tk.MustQuery("select (select count(distinct n.b) from t order by count(n.b) limit 1) from t n").Check(testkit.Rows("3")) - // from TableRefsClause - tk.MustQuery("select (select cnt from (select count(a) cnt) s) from t").Check(testkit.Rows("6")) - tk.MustQuery("select (select count(cnt) from (select count(a) cnt) s) from t").Check(testkit.Rows("1")) - // from sub-query inside aggregate - tk.MustQuery("select (select sum((select count(a)))) from t").Check(testkit.Rows("6")) - tk.MustQuery("select (select sum((select count(a))+sum(a))) from t").Check(testkit.Rows("20")) - // from GROUP BY - tk.MustQuery("select (select count(a) from t group by count(n.a)) from t n").Check(testkit.Rows("6")) - tk.MustQuery("select (select count(distinct a) from t group by count(n.a)) from t n").Check(testkit.Rows("3")) - - // Sub-queries in HAVING - tk.MustQuery("select sum(a) from t having (select count(a)) = 0").Check(testkit.Rows()) - tk.MustQuery("select sum(a) from t having (select count(a)) > 0").Check(testkit.Rows("14")) - - // Sub-queries in ORDER BY - tk.MustQuery("select count(a) from t group by b order by (select count(a))").Check(testkit.Rows("1", "2", "3")) - tk.MustQuery("select count(a) from t group by b order by (select -count(a))").Check(testkit.Rows("3", "2", "1")) - - // Nested aggregate (correlated aggregate inside aggregate) - tk.MustQuery("select (select sum(count(a))) from t").Check(testkit.Rows("6")) - tk.MustQuery("select (select sum(sum(a))) from t").Check(testkit.Rows("14")) - - // Combining aggregates - tk.MustQuery("select count(a), (select count(a)) from t").Check(testkit.Rows("6 6")) - tk.MustQuery("select sum(distinct b), count(a), (select count(a)), (select cnt from (select sum(distinct b) as cnt) n) from t"). - Check(testkit.Rows("6 6 6 6")) -} - -func TestCorrelatedColumnAggFuncPushDown(t *testing.T) { - store := testkit.CreateMockStore(t) - 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);") - tk.MustExec("insert into t values (1,1);") - tk.MustQuery("select (select count(n.a + a) from t) from t n;").Check(testkit.Rows( - "1", - )) -} - // Test for issue https://github.com/pingcap/tidb/issues/21607. func TestConditionColPruneInPhysicalUnionScan(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2522,51 +1073,6 @@ func TestConditionColPruneInPhysicalUnionScan(t *testing.T) { Check(testkit.Rows("0")) } -// Test for issue https://github.com/pingcap/tidb/issues/18320 -func TestNonaggregateColumnWithSingleValueInOnlyFullGroupByMode(t *testing.T) { - store := testkit.CreateMockStore(t) - 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)") - tk.MustExec("insert into t values (1, 2, 3), (4, 5, 6), (7, 8, 9)") - tk.MustQuery("select a, count(b) from t where a = 1").Check(testkit.Rows("1 1")) - tk.MustQuery("select a, count(b) from t where a = 10").Check(testkit.Rows(" 0")) - tk.MustQuery("select a, c, sum(b) from t where a = 1 group by c").Check(testkit.Rows("1 3 2")) - tk.MustGetErrMsg("select a from t where a = 1 order by count(b)", "[planner:3029]Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query") - tk.MustQuery("select a from t where a = 1 having count(b) > 0").Check(testkit.Rows("1")) -} - -func TestIssue22040(t *testing.T) { - store := testkit.CreateMockStore(t) - // #22040 - 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, primary key(a,b))") - // valid case - tk.MustExec("select * from t where (a,b) in ((1,2),(1,2))") - // invalid case, column count doesn't match - { - err := tk.ExecToErr("select * from t where (a,b) in (1,2)") - require.IsType(t, expression.ErrOperandColumns, errors.Cause(err)) - } - { - err := tk.ExecToErr("select * from t where (a,b) in ((1,2),1)") - require.IsType(t, expression.ErrOperandColumns, errors.Cause(err)) - } -} - -func TestIssue22071(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t (a int);") - tk.MustExec("insert into t values(1),(2),(5)") - tk.MustQuery("select n in (1,2) from (select a in (1,2) as n from t) g;").Sort().Check(testkit.Rows("0", "1", "1")) - tk.MustQuery("select n in (1,n) from (select a in (1,2) as n from t) g;").Check(testkit.Rows("1", "1", "1")) -} - func TestCreateViewIsolationRead(t *testing.T) { store := testkit.CreateMockStore(t) se, err := session.CreateSession4Test(store) @@ -2586,353 +1092,6 @@ func TestCreateViewIsolationRead(t *testing.T) { tk.MustQuery("select * from v0;").Check(testkit.Rows()) } -func TestIssue22199(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(i int primary key, j int, index idx_j(j))") - tk.MustExec("create table t2(i int primary key, j int, index idx_j(j))") - tk.MustGetErrMsg("select t1.*, (select t2.* from t1) from t1", "[planner:1051]Unknown table 't2'") -} - -func TestIssue22892(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@tidb_partition_prune_mode='static'") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(a int) partition by hash (a) partitions 5;") - tk.MustExec("insert into t1 values (0);") - tk.MustQuery("select * from t1 where a not between 1 and 2;").Check(testkit.Rows("0")) - - tk.MustExec("set @@tidb_partition_prune_mode='dynamic'") - tk.MustExec("drop table if exists t2") - tk.MustExec("create table t2(a int) partition by hash (a) partitions 5;") - tk.MustExec("insert into t2 values (0);") - tk.MustQuery("select * from t2 where a not between 1 and 2;").Check(testkit.Rows("0")) -} - -func TestIssue26719(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table tx (a int) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20))`) - tk.MustExec(`insert into tx values (1)`) - tk.MustExec("set @@tidb_partition_prune_mode='dynamic'") - - tk.MustExec(`begin`) - tk.MustExec(`delete from tx where a in (1)`) - tk.MustQuery(`select * from tx PARTITION(p0)`).Check(testkit.Rows()) - tk.MustQuery(`select * from tx`).Check(testkit.Rows()) - tk.MustExec(`rollback`) -} - -func TestIssue32428(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table `t1` (`a` enum('aa') DEFAULT NULL, KEY `k` (`a`))") - tk.MustExec("insert into t1 values('aa')") - tk.MustExec("insert into t1 values(null)") - tk.MustQuery("select a from t1 where a<=>'aa'").Check(testkit.Rows("aa")) - tk.MustQuery("select a from t1 where a<=>null").Check(testkit.Rows("")) - - tk.MustExec(`CREATE TABLE IDT_MULTI15860STROBJSTROBJ ( - COL1 enum('aa') DEFAULT NULL, - COL2 int(41) DEFAULT NULL, - COL3 year(4) DEFAULT NULL, - KEY U_M_COL4 (COL1,COL2), - KEY U_M_COL5 (COL3,COL2))`) - tk.MustExec(`insert into IDT_MULTI15860STROBJSTROBJ values("aa", 1013610488, 1982)`) - tk.MustQuery(`SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = "aa"`).Check(testkit.Rows()) // empty result - tk.MustExec(`prepare stmt from "SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = ?"`) - tk.MustExec(`set @a="aa"`) - tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows()) // empty result -} - -func TestDeleteStmt(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int)") - tk.MustExec("delete t from t;") - tk.MustExec("delete t from test.t as t;") - tk.MustGetErrCode("delete test.t from test.t as t;", mysql.ErrUnknownTable) - tk.MustExec("delete test.t from t;") - tk.MustExec("create database db1") - tk.MustExec("use db1") - tk.MustExec("create table t(a int)") - tk.MustGetErrCode("delete test.t from t;", mysql.ErrUnknownTable) -} - -func TestIndexMergeConstantTrue(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, b int not null, key(b))") - tk.MustExec("delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (b < SOME (SELECT /*+ use_index_merge(t)*/ b FROM t WHERE a<2 OR b<2))") - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int not null, b int not null, key(a), key(b))") - tk.MustExec("delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (b < SOME (SELECT /*+ use_index_merge(t)*/ b FROM t WHERE a<2 OR b<2))") - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int primary key, b int not null, c int, key(a), key(b,c))") - tk.MustExec("delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (a<2 and b<2)") -} - -func TestIndexMergeTableFilter(t *testing.T) { - store := testkit.CreateMockStore(t) - 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, key(a), key(b));") - tk.MustExec("insert into t values(10,1,1,10)") - - tk.MustQuery("explain format = 'brief' select /*+ use_index_merge(t) */ * from t where a=10 or (b=10 and c=10)").Check(testkit.Rows( - "IndexMerge 0.02 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[10,10], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[10,10], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.02 cop[tikv] or(eq(test.t.a, 10), and(eq(test.t.b, 10), eq(test.t.c, 10)))", - " └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo", - )) - tk.MustQuery("select /*+ use_index_merge(t) */ * from t where a=10 or (b=10 and c=10)").Check(testkit.Rows( - "10 1 1 10", - )) - tk.MustQuery("explain format = 'brief' select /*+ use_index_merge(t) */ * from t where (a=10 and d=10) or (b=10 and c=10)").Check(testkit.Rows( - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[10,10], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[10,10], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.00 cop[tikv] or(and(eq(test.t.a, 10), eq(test.t.d, 10)), and(eq(test.t.b, 10), eq(test.t.c, 10)))", - " └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo", - )) - tk.MustQuery("select /*+ use_index_merge(t) */ * from t where (a=10 and d=10) or (b=10 and c=10)").Check(testkit.Rows( - "10 1 1 10", - )) -} - -func TestIssue22850(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.MustExec("CREATE TABLE t1 (a int(11))") - tk.MustQuery("SELECT @v:=(SELECT 1 FROM t1 t2 LEFT JOIN t1 ON t1.a GROUP BY t1.a) FROM t1").Check(testkit.Rows()) // work fine -} - -func TestJoinSchemaChange(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(a int(11))") - tk.MustExec("create table t2(a decimal(40,20) unsigned, b decimal(40,20))") - tk.MustQuery("select count(*) as x from t1 group by a having x not in (select a from t2 where x = t2.b)").Check(testkit.Rows()) -} - -// #22949: test HexLiteral Used in GetVar expr -func TestGetVarExprWithHexLiteral(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1_no_idx;") - tk.MustExec("create table t1_no_idx(id int, col_bit bit(16));") - tk.MustExec("insert into t1_no_idx values(1, 0x3135);") - tk.MustExec("insert into t1_no_idx values(2, 0x0f);") - - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit = ?';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // same test, but use IN expr - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit in (?)';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // same test, but use table with index on col_bit - tk.MustExec("drop table if exists t2_idx;") - tk.MustExec("create table t2_idx(id int, col_bit bit(16), key(col_bit));") - tk.MustExec("insert into t2_idx values(1, 0x3135);") - tk.MustExec("insert into t2_idx values(2, 0x0f);") - - tk.MustExec("prepare stmt from 'select id from t2_idx where col_bit = ?';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // same test, but use IN expr - tk.MustExec("prepare stmt from 'select id from t2_idx where col_bit in (?)';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // test col varchar with GetVar - tk.MustExec("drop table if exists t_varchar;") - tk.MustExec("create table t_varchar(id int, col_varchar varchar(100), key(col_varchar));") - tk.MustExec("insert into t_varchar values(1, '15');") - tk.MustExec("prepare stmt from 'select id from t_varchar where col_varchar = ?';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) -} - -// test BitLiteral used with GetVar -func TestGetVarExprWithBitLiteral(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1_no_idx;") - tk.MustExec("create table t1_no_idx(id int, col_bit bit(16));") - tk.MustExec("insert into t1_no_idx values(1, 0x3135);") - tk.MustExec("insert into t1_no_idx values(2, 0x0f);") - - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit = ?';") - // 0b11000100110101 is 0x3135 - tk.MustExec("set @a = 0b11000100110101;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - - // same test, but use IN expr - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit in (?)';") - tk.MustExec("set @a = 0b11000100110101;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) -} - -func TestIndexMergeClusterIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c1 float, c2 int, c3 int, primary key (c1) /*T![clustered_index] CLUSTERED */, key idx_1 (c2), key idx_2 (c3))") - tk.MustExec("insert into t values(1.0,1,2),(2.0,2,1),(3.0,1,1),(4.0,2,2)") - tk.MustQuery("select /*+ use_index_merge(t) */ c3 from t where c3 = 1 or c2 = 1").Sort().Check(testkit.Rows( - "1", - "1", - "2", - )) - tk.MustExec("drop table t") - tk.MustExec("create table t (a int, b int, c int, primary key (a,b) /*T![clustered_index] CLUSTERED */, key idx_c(c))") - tk.MustExec("insert into t values (0,1,2)") - tk.MustQuery("select /*+ use_index_merge(t) */ c from t where c > 10 or a < 1").Check(testkit.Rows( - "2", - )) -} - -func TestIssue23736(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t0, t1") - tk.MustExec("create table t0(a int, b int, c int as (a + b) virtual, unique index (c) invisible);") - tk.MustExec("create table t1(a int, b int, c int as (a + b) virtual);") - tk.MustExec("insert into t0(a, b) values (12, -1), (8, 7);") - tk.MustExec("insert into t1(a, b) values (12, -1), (8, 7);") - tk.MustQuery("select /*+ stream_agg() */ count(1) from t0 where c > 10 and b < 2;").Check(testkit.Rows("1")) - tk.MustQuery("select /*+ stream_agg() */ count(1) from t1 where c > 10 and b < 2;").Check(testkit.Rows("1")) - tk.MustExec("delete from t0") - tk.MustExec("insert into t0(a, b) values (5, 1);") - tk.MustQuery("select /*+ nth_plan(3) */ count(1) from t0 where c > 10 and b < 2;").Check(testkit.Rows("0")) - - // Should not use invisible index - require.False(t, tk.MustUseIndex("select /*+ stream_agg() */ count(1) from t0 where c > 10 and b < 2", "c")) -} - -// https://github.com/pingcap/tidb/issues/23802 -func TestPanicWhileQueryTableWithIsNull(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists NT_HP27193") - tk.MustExec("CREATE TABLE `NT_HP27193` ( `COL1` int(20) DEFAULT NULL, `COL2` varchar(20) DEFAULT NULL, `COL4` datetime DEFAULT NULL, `COL3` bigint(20) DEFAULT NULL, `COL5` float DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH ( `COL1`%`COL3` ) PARTITIONS 10;") - rs, err := tk.Exec("select col1 from NT_HP27193 where col1 is null;") - require.NoError(t, err) - rs.Close() - tk.MustExec("INSERT INTO NT_HP27193 (COL2, COL4, COL3, COL5) VALUES ('m', '2020-05-04 13:15:27', 8, 2602)") - rs, err = tk.Exec("select col1 from NT_HP27193 where col1 is null;") - require.NoError(t, err) - rs.Close() - tk.MustExec("drop table if exists NT_HP27193") -} - -func TestIssue23846(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varbinary(10),UNIQUE KEY(a))") - tk.MustExec("insert into t values(0x00A4EEF4FA55D6706ED5)") - tk.MustQuery("select count(*) from t where a=0x00A4EEF4FA55D6706ED5").Check(testkit.Rows("1")) - tk.MustQuery("select * from t where a=0x00A4EEF4FA55D6706ED5").Check(testkit.Rows("\x00\xa4\xee\xf4\xfaU\xd6pn\xd5")) // not empty -} - -func TestIssue23839(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists BB") - tk.MustExec("CREATE TABLE `BB` (\n" + - " `col_int` int(11) DEFAULT NULL,\n" + - " `col_varchar_10` varchar(10) DEFAULT NULL,\n" + - " `pk` int(11) NOT NULL AUTO_INCREMENT,\n" + - " `col_int_not_null` int(11) NOT NULL,\n" + - " `col_decimal` decimal(10,0) DEFAULT NULL,\n" + - " `col_datetime` datetime DEFAULT NULL,\n" + - " `col_decimal_not_null` decimal(10,0) NOT NULL,\n" + - " `col_datetime_not_null` datetime NOT NULL,\n" + - " `col_varchar_10_not_null` varchar(10) NOT NULL,\n" + - " PRIMARY KEY (`pk`) /*T![clustered_index] CLUSTERED */\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000001") - tk.Exec("explain SELECT OUTR . col2 AS X FROM (SELECT INNR . col1 as col1, SUM( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR2 INNER JOIN (SELECT INNR . col1 as col1, MAX( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR ON OUTR2.col1 = OUTR.col1 GROUP BY OUTR . col1, OUTR2 . col1 HAVING X <> 'b'") -} - -func TestIssue24281(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists member, agent, deposit, view_member_agents") - tk.MustExec("create table member(login varchar(50) NOT NULL, agent_login varchar(100) DEFAULT NULL, PRIMARY KEY(login))") - tk.MustExec("create table agent(login varchar(50) NOT NULL, data varchar(100) DEFAULT NULL, share_login varchar(50) NOT NULL, PRIMARY KEY(login))") - tk.MustExec("create table deposit(id varchar(50) NOT NULL, member_login varchar(50) NOT NULL, transfer_amount int NOT NULL, PRIMARY KEY(id), KEY midx(member_login, transfer_amount))") - tk.MustExec("create definer='root'@'localhost' view view_member_agents (member, share_login) as select m.login as member, a.share_login AS share_login from member as m join agent as a on m.agent_login = a.login") - - tk.MustExec(" select s.member_login as v1, SUM(s.transfer_amount) AS v2 " + - "FROM deposit AS s " + - "JOIN view_member_agents AS v ON s.member_login = v.member " + - "WHERE 1 = 1 AND v.share_login = 'somevalue' " + - "GROUP BY s.member_login " + - "UNION select 1 as v1, 2 as v2") -} - -func TestIssue25799(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec(`create table t1 (a float default null, b smallint(6) DEFAULT NULL)`) - tk.MustExec(`insert into t1 values (1, 1)`) - tk.MustExec(`create table t2 (a float default null, b tinyint(4) DEFAULT NULL, key b (b))`) - tk.MustExec(`insert into t2 values (null, 1)`) - tk.MustHavePlan(`select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b)`, `IndexJoin`) - tk.MustQuery(`select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b)`).Check(testkit.Rows()) -} - -func TestLimitWindowColPrune(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - tk.MustExec("insert into t values(1)") - tk.MustQuery("select count(a) f1, row_number() over (order by count(a)) as f2 from t limit 1").Check(testkit.Rows("1 1")) -} - func TestIncrementalAnalyzeStatsVer2(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -2995,56 +1154,6 @@ func TestConflictReadFromStorage(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1815 Storage hints are conflict, you can only specify one storage type of table test.t")) } -func TestIssue27167(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set names utf8mb4") - tk.MustExec("use test") - tk.MustExec("drop table if exists all_types") - - tk.MustExec("CREATE TABLE `all_types` (" + - "`id` int(11) NOT NULL," + - "`d_tinyint` tinyint(4) DEFAULT NULL," + - "`d_smallint` smallint(6) DEFAULT NULL," + - "`d_int` int(11) DEFAULT NULL," + - "`d_bigint` bigint(20) DEFAULT NULL," + - "`d_float` float DEFAULT NULL," + - "`d_double` double DEFAULT NULL," + - "`d_decimal` decimal(10,2) DEFAULT NULL," + - "`d_bit` bit(10) DEFAULT NULL," + - "`d_binary` binary(10) DEFAULT NULL," + - "`d_date` date DEFAULT NULL," + - "`d_datetime` datetime DEFAULT NULL," + - "`d_timestamp` timestamp NULL DEFAULT NULL," + - "`d_varchar` varchar(20) NULL default NULL," + - "PRIMARY KEY (`id`));", - ) - - tk.MustQuery("select @@collation_connection;").Check(testkit.Rows("utf8mb4_bin")) - - tk.MustExec(`insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123');`) - - tk.MustQuery("select collation(c) from (select d_date c from all_types union select d_int c from all_types) t").Check(testkit.Rows("utf8mb4_bin", "utf8mb4_bin")) - tk.MustQuery("select collation(c) from (select d_date c from all_types union select d_int collate binary c from all_types) t").Check(testkit.Rows("binary", "binary")) - tk.MustQuery("select collation(c) from (select d_date c from all_types union select d_float c from all_types) t").Check(testkit.Rows("utf8mb4_bin", "utf8mb4_bin")) - // timestamp also OK - tk.MustQuery("select collation(c) from (select d_timestamp c from all_types union select d_float c from all_types) t").Check(testkit.Rows("utf8mb4_bin", "utf8mb4_bin")) -} - -func TestIssue25300(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`create table t (a char(65) collate utf8_unicode_ci, b text collate utf8_general_ci not null);`) - tk.MustExec(`insert into t values ('a', 'A');`) - tk.MustExec(`insert into t values ('b', 'B');`) - tk.MustGetErrCode(`(select a from t) union ( select b from t);`, mysql.ErrCantAggregateNcollations) - tk.MustGetErrCode(`(select 'a' collate utf8mb4_unicode_ci) union (select 'b' collate utf8mb4_general_ci);`, mysql.ErrCantAggregateNcollations) - tk.MustGetErrCode(`(select a from t) union ( select b from t) union all select 'a';`, mysql.ErrCantAggregateNcollations) - tk.MustGetErrCode(`(select a from t) union ( select b from t) union select 'a';`, mysql.ErrCantAggregateNcollations) - tk.MustGetErrCode(`(select a from t) union ( select b from t) union select 'a' except select 'd';`, mysql.ErrCantAggregateNcollations) -} - func TestSelectIgnoreTemporaryTableInView(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3074,175 +1183,6 @@ func TestSelectIgnoreTemporaryTableInView(t *testing.T) { tk.MustQuery("select * from v5").Check(testkit.Rows("1 2", "3 4")) } -func TestIssue26250(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table tp (id int primary key) partition by range (id) (partition p0 values less than (100));") - tk.MustExec("create table tn (id int primary key);") - tk.MustExec("insert into tp values(1),(2);") - tk.MustExec("insert into tn values(1),(2);") - tk.MustQuery("select * from tp,tn where tp.id=tn.id and tn.id=1 for update;").Check(testkit.Rows("1 1")) -} - -func TestCorrelationAdjustment4Limit(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (pk int primary key auto_increment, year int, c varchar(256), index idx_year(year))") - - insertWithYear := func(n, year int) { - for i := 0; i < n; i++ { - tk.MustExec(fmt.Sprintf("insert into t (year, c) values (%v, space(256))", year)) - } - } - insertWithYear(10, 2000) - insertWithYear(10, 2001) - insertWithYear(10, 2002) - tk.MustExec("analyze table t") - - // case 1 - tk.MustExec("set @@tidb_opt_enable_correlation_adjustment = false") - // the estRow for TableFullScan is under-estimated since we have to scan through 2000 and 2001 to access 2002, - // but the formula(LimitNum / Selectivity) based on uniform-assumption cannot consider this factor. - tk.MustQuery("explain format=brief select * from t use index(primary) where year=2002 limit 1").Check(testkit.Rows( - "Limit 1.00 root offset:0, count:1", - "└─TableReader 1.00 root data:Limit", - " └─Limit 1.00 cop[tikv] offset:0, count:1", - " └─Selection 1.00 cop[tikv] eq(test.t.year, 2002)", - " └─TableFullScan 3.00 cop[tikv] table:t keep order:false")) - - // case 2: after enabling correlation adjustment, this factor can be considered. - tk.MustExec("set @@tidb_opt_enable_correlation_adjustment = true") - tk.MustQuery("explain format=brief select * from t use index(primary) where year=2002 limit 1").Check(testkit.Rows( - "Limit 1.00 root offset:0, count:1", - "└─TableReader 1.00 root data:Limit", - " └─Limit 1.00 cop[tikv] offset:0, count:1", - " └─Selection 1.00 cop[tikv] eq(test.t.year, 2002)", - " └─TableFullScan 21.00 cop[tikv] table:t keep order:false")) - - tk.MustExec("truncate table t") - for y := 2000; y <= 2050; y++ { - insertWithYear(2, y) - } - tk.MustExec("analyze table t") - - // case 3: correlation adjustment is only allowed to update the upper-bound, so estRow = max(1/selectivity, adjustedCount); - // 1/sel = 1/(1/NDV) is around 50, adjustedCount is 1 since the first row can meet the requirement `year=2000`; - // in this case the estRow is over-estimated, but it's safer that can avoid to convert IndexScan to TableScan incorrectly in some cases. - tk.MustQuery("explain format=brief select * from t use index(primary) where year=2000 limit 1").Check(testkit.Rows( - "Limit 1.00 root offset:0, count:1", - "└─TableReader 1.00 root data:Limit", - " └─Limit 1.00 cop[tikv] offset:0, count:1", - " └─Selection 1.00 cop[tikv] eq(test.t.year, 2000)", - " └─TableFullScan 51.00 cop[tikv] table:t keep order:false")) -} - -func TestCTESelfJoin(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2, t3") - tk.MustExec("create table t1(t1a int, t1b int, t1c int)") - tk.MustExec("create table t2(t2a int, t2b int, t2c int)") - tk.MustExec("create table t3(t3a int, t3b int, t3c int)") - tk.MustExec(` - with inv as - (select t1a , t3a, sum(t2c) - from t1, t2, t3 - where t2a = t1a - and t2b = t3b - and t3c = 1998 - group by t1a, t3a) - select inv1.t1a, inv2.t3a - from inv inv1, inv inv2 - where inv1.t1a = inv2.t1a - and inv1.t3a = 4 - and inv2.t3a = 4+1`) -} - -// https://github.com/pingcap/tidb/issues/26214 -func TestIssue26214(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table `t` (`a` int(11) default null, `b` int(11) default null, `c` int(11) default null, key `expression_index` ((case when `a` < 0 then 1 else 2 end)))") - _, err := tk.Exec("select * from t where case when a < 0 then 1 else 2 end <= 1 order by 4;") - require.True(t, core.ErrUnknownColumn.Equal(err)) -} - -func TestCreateViewWithWindowFunc(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t6;") - tk.MustExec("CREATE TABLE t6(t TIME, ts TIMESTAMP);") - tk.MustExec("INSERT INTO t6 VALUES ('12:30', '2016-07-05 08:30:42');") - tk.MustExec("drop view if exists v;") - tk.MustExec("CREATE definer='root'@'localhost' VIEW v AS SELECT COUNT(*) OVER w0, COUNT(*) OVER w from t6 WINDOW w0 AS (), w AS (w0 ORDER BY t);") - rows := tk.MustQuery("select * from v;") - rows.Check(testkit.Rows("1 1")) -} - -func TestIssue29834(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists IDT_MC21814;") - tk.MustExec("CREATE TABLE `IDT_MC21814` (`COL1` year(4) DEFAULT NULL,`COL2` year(4) DEFAULT NULL,KEY `U_M_COL` (`COL1`,`COL2`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("insert into IDT_MC21814 values(1901, 2119), (2155, 2000);") - tk.MustQuery("SELECT/*+ INL_JOIN(t1, t2), nth_plan(1) */ t2.* FROM IDT_MC21814 t1 LEFT JOIN IDT_MC21814 t2 ON t1.col1 = t2.col1 WHERE t2.col2 BETWEEN 2593 AND 1971 AND t1.col1 IN (2155, 1901, 1967);").Check(testkit.Rows()) - tk.MustQuery("SELECT/*+ INL_JOIN(t1, t2), nth_plan(2) */ t2.* FROM IDT_MC21814 t1 LEFT JOIN IDT_MC21814 t2 ON t1.col1 = t2.col1 WHERE t2.col2 BETWEEN 2593 AND 1971 AND t1.col1 IN (2155, 1901, 1967);").Check(testkit.Rows()) - // Only can generate one index join plan. Because the index join inner child can not be tableDual. - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 The parameter of nth_plan() is out of range")) -} - -func TestLimitPushDown(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - - tk.MustExec(`create table t (a int)`) - tk.MustExec(`insert into t values (1)`) - tk.MustExec(`analyze table t`) - - tk.MustExec(`set tidb_opt_limit_push_down_threshold=0`) - tk.MustQuery(`explain format=brief select a from t order by a desc limit 10`).Check(testkit.Rows( - `TopN 1.00 root test.t.a:desc, offset:0, count:10`, - `└─TableReader 1.00 root data:TableFullScan`, - ` └─TableFullScan 1.00 cop[tikv] table:t keep order:false`)) - - tk.MustExec(`set tidb_opt_limit_push_down_threshold=10`) - tk.MustQuery(`explain format=brief select a from t order by a desc limit 10`).Check(testkit.Rows( - `TopN 1.00 root test.t.a:desc, offset:0, count:10`, - `└─TableReader 1.00 root data:TopN`, - ` └─TopN 1.00 cop[tikv] test.t.a:desc, offset:0, count:10`, - ` └─TableFullScan 1.00 cop[tikv] table:t keep order:false`)) - - tk.MustQuery(`explain format=brief select a from t order by a desc limit 11`).Check(testkit.Rows( - `TopN 1.00 root test.t.a:desc, offset:0, count:11`, - `└─TableReader 1.00 root data:TableFullScan`, - ` └─TableFullScan 1.00 cop[tikv] table:t keep order:false`)) - - tk.MustQuery(`explain format=brief select /*+ limit_to_cop() */ a from t order by a desc limit 11`).Check(testkit.Rows( - `TopN 1.00 root test.t.a:desc, offset:0, count:11`, - `└─TableReader 1.00 root data:TopN`, - ` └─TopN 1.00 cop[tikv] test.t.a:desc, offset:0, count:11`, - ` └─TableFullScan 1.00 cop[tikv] table:t keep order:false`)) -} - -func TestIssue26559(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a timestamp, b datetime);") - tk.MustExec("insert into t values('2020-07-29 09:07:01', '2020-07-27 16:57:36');") - tk.MustQuery("select greatest(a, b) from t union select null;").Sort().Check(testkit.Rows("2020-07-29 09:07:01", "")) -} - func TestIssue29503(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3260,58 +1200,6 @@ func TestIssue29503(t *testing.T) { require.Len(t, res.Rows(), 2) } -func TestIssues27130(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t1") - tk.MustExec("set tidb_cost_model_version=2") - tk.MustExec("create table t1( a enum('y','b','Abc','null'),b enum('y','b','Abc','null'),key(a));") - tk.MustQuery(`explain format=brief select * from t1 where a like "A%"`).Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] like(test.t1.a, \"A%\", 92)", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - )) - tk.MustQuery(`explain format=brief select * from t1 where b like "A%"`).Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] like(test.t1.b, \"A%\", 92)", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - )) - - tk.MustExec("drop table if exists t2") - tk.MustExec("create table t2( a enum('y','b','Abc','null'),b enum('y','b','Abc','null'),key(a, b));") - tk.MustQuery(`explain format=brief select * from t2 where a like "A%"`).Check(testkit.Rows( - "IndexReader 8000.00 root index:Selection", - "└─Selection 8000.00 cop[tikv] like(test.t2.a, \"A%\", 92)", - " └─IndexFullScan 10000.00 cop[tikv] table:t2, index:a(a, b) keep order:false, stats:pseudo", - )) - tk.MustQuery(`explain format=brief select * from t2 where a like "A%" and b like "A%"`).Check(testkit.Rows( - "IndexReader 8000.00 root index:Selection", - "└─Selection 8000.00 cop[tikv] like(test.t2.a, \"A%\", 92), like(test.t2.b, \"A%\", 92)", - " └─IndexFullScan 10000.00 cop[tikv] table:t2, index:a(a, b) keep order:false, stats:pseudo", - )) - - tk.MustExec("drop table if exists t3") - tk.MustExec("create table t3( a int,b enum('y','b','Abc','null'), c enum('y','b','Abc','null'),key(a, b, c));") - tk.MustQuery(`explain format=brief select * from t3 where a = 1 and b like "A%"`).Check(testkit.Rows( - "IndexReader 8.00 root index:Selection", - "└─Selection 8.00 cop[tikv] like(test.t3.b, \"A%\", 92)", - " └─IndexRangeScan 10.00 cop[tikv] table:t3, index:a(a, b, c) range:[1,1], keep order:false, stats:pseudo", - )) -} - -func TestIssue27242(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists UK_MU16407") - tk.MustExec("CREATE TABLE UK_MU16407 (COL3 timestamp NULL DEFAULT NULL, UNIQUE KEY U3(COL3));") - defer tk.MustExec("DROP TABLE UK_MU16407") - tk.MustExec(`insert into UK_MU16407 values("1985-08-31 18:03:27");`) - tk.MustExec(`SELECT COL3 FROM UK_MU16407 WHERE COL3>_utf8mb4'2039-1-19 3:14:40';`) -} - func verifyTimestampOutOfRange(tk *testkit.TestKit) { tk.MustQuery(`select * from t28424 where t != "2038-1-19 3:14:08"`).Sort().Check(testkit.Rows("1970-01-01 00:00:01]\n[2038-01-19 03:14:07")) tk.MustQuery(`select * from t28424 where t < "2038-1-19 3:14:08"`).Sort().Check(testkit.Rows("1970-01-01 00:00:01]\n[2038-01-19 03:14:07")) @@ -3325,85 +1213,6 @@ func verifyTimestampOutOfRange(tk *testkit.TestKit) { tk.MustQuery(`select * from t28424 where t > "1970-1-1 0:0:0"`).Sort().Check(testkit.Rows("1970-01-01 00:00:01]\n[2038-01-19 03:14:07")) } -func TestIssue28424(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t28424, dt28242") - - tk.MustExec(`set time_zone='+00:00'`) - tk.MustExec(`drop table if exists t28424,dt28424`) - tk.MustExec(`create table t28424 (t timestamp)`) - defer tk.MustExec("DROP TABLE t28424") - tk.MustExec(`insert into t28424 values ("2038-01-19 03:14:07"), ("1970-01-01 00:00:01")`) - - verifyTimestampOutOfRange(tk) - tk.MustExec(`alter table t28424 add unique index (t)`) - verifyTimestampOutOfRange(tk) - tk.MustExec(`create table dt28424 (dt datetime)`) - defer tk.MustExec("DROP TABLE dt28424") - tk.MustExec(`insert into dt28424 values ("2038-01-19 03:14:07"), ("1970-01-01 00:00:01")`) - tk.MustExec(`insert into dt28424 values ("1969-12-31 23:59:59"), ("1970-01-01 00:00:00"), ("2038-03-19 03:14:08")`) - tk.MustQuery(`select * from t28424 right join dt28424 on t28424.t = dt28424.dt`).Sort().Check(testkit.Rows( - "1970-01-01 00:00:01 1970-01-01 00:00:01]\n" + - "[2038-01-19 03:14:07 2038-01-19 03:14:07]\n" + - "[ 1969-12-31 23:59:59]\n" + - "[ 1970-01-01 00:00:00]\n" + - "[ 2038-03-19 03:14:08")) -} - -func TestTemporaryTableForCte(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("create temporary table tmp1(a int, b int, c int);") - tk.MustExec("insert into tmp1 values (1,1,1),(2,2,2),(3,3,3),(4,4,4);") - rows := tk.MustQuery("with cte1 as (with cte2 as (select * from tmp1) select * from cte2) select * from cte1 left join tmp1 on cte1.c=tmp1.c;") - rows.Check(testkit.Rows("1 1 1 1 1 1", "2 2 2 2 2 2", "3 3 3 3 3 3", "4 4 4 4 4 4")) - rows = tk.MustQuery("with cte1 as (with cte2 as (select * from tmp1) select * from cte2) select * from cte1 t1 left join cte1 t2 on t1.c=t2.c;") - rows.Check(testkit.Rows("1 1 1 1 1 1", "2 2 2 2 2 2", "3 3 3 3 3 3", "4 4 4 4 4 4")) - rows = tk.MustQuery("WITH RECURSIVE cte(a) AS (SELECT 1 UNION SELECT a+1 FROM tmp1 WHERE a < 5) SELECT * FROM cte order by a;") - rows.Check(testkit.Rows("1", "2", "3", "4", "5")) -} - -func TestIssue27797(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - origin := tk.MustQuery("SELECT @@session.tidb_partition_prune_mode") - originStr := origin.Rows()[0][0].(string) - defer func() { - tk.MustExec("set @@session.tidb_partition_prune_mode = '" + originStr + "'") - }() - tk.MustExec("set @@session.tidb_partition_prune_mode = 'static'") - tk.MustExec("use test") - tk.MustExec("drop table if exists t27797") - tk.MustExec("create table t27797(a int, b int, c int, d int) " + - "partition by range columns(d) (" + - "partition p0 values less than (20)," + - "partition p1 values less than(40)," + - "partition p2 values less than(60));") - tk.MustExec("insert into t27797 values(1,1,1,1), (2,2,2,2), (22,22,22,22), (44,44,44,44);") - tk.MustExec("set sql_mode='';") - result := tk.MustQuery("select count(*) from (select a, b from t27797 where d > 1 and d < 60 and b > 0 group by b, c) tt;") - result.Check(testkit.Rows("3")) - - tk.MustExec("drop table if exists IDT_HP24172") - tk.MustExec("CREATE TABLE `IDT_HP24172` ( " + - "`COL1` mediumint(16) DEFAULT NULL, " + - "`COL2` varchar(20) DEFAULT NULL, " + - "`COL4` datetime DEFAULT NULL, " + - "`COL3` bigint(20) DEFAULT NULL, " + - "`COL5` float DEFAULT NULL, " + - "KEY `UM_COL` (`COL1`,`COL3`) " + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin " + - "PARTITION BY HASH( `COL1`+`COL3` ) " + - "PARTITIONS 8;") - tk.MustExec("insert into IDT_HP24172(col1) values(8388607);") - result = tk.MustQuery("select col2 from IDT_HP24172 where col1 = 8388607 and col1 in (select col1 from IDT_HP24172);") - result.Check(testkit.Rows("")) -} - func TestIssue27949(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3434,126 +1243,6 @@ func TestIssue27949(t *testing.T) { tk.MustQuery("select @@last_plan_from_binding;").Check(testkit.Rows("1")) } -func TestIssue28154(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - defer func() { - tk.MustExec("drop table if exists t") - }() - tk.MustExec("create table t(a TEXT)") - tk.MustExec("insert into t values('abc')") - result := tk.MustQuery("select * from t where from_base64('')") - result.Check(testkit.Rows()) - _, err := tk.Exec("update t set a = 'def' where from_base64('')") - require.EqualError(t, err, "[types:1292]Truncated incorrect DOUBLE value: ''") - result = tk.MustQuery("select * from t where from_base64('invalidbase64')") - result.Check(testkit.Rows()) - tk.MustExec("update t set a = 'hig' where from_base64('invalidbase64')") - result = tk.MustQuery("select * from t where from_base64('test')") - result.Check(testkit.Rows()) - _, err = tk.Exec("update t set a = 'xyz' where from_base64('test')") - require.Error(t, err) - require.Regexp(t, "\\[types:1292\\]Truncated incorrect DOUBLE value.*", err.Error()) - result = tk.MustQuery("select * from t") - result.Check(testkit.Rows("abc")) -} - -func TestIssues29711(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists tbl_29711") - tk.MustExec("CREATE TABLE `tbl_29711` (" + - "`col_250` text COLLATE utf8_unicode_ci NOT NULL," + - "`col_251` enum('Alice','Bob','Charlie','David') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Charlie'," + - "PRIMARY KEY (`col_251`,`col_250`(1)) NONCLUSTERED);") - tk.MustQuery("explain format=brief " + - "select col_250,col_251 from tbl_29711 where col_251 between 'Bob' and 'David' order by col_250,col_251 limit 6;"). - Check(testkit.Rows( - "TopN 6.00 root test.tbl_29711.col_250, test.tbl_29711.col_251, offset:0, count:6", - "└─IndexLookUp 6.00 root ", - " ├─IndexRangeScan(Build) 30.00 cop[tikv] table:tbl_29711, index:PRIMARY(col_251, col_250) range:[\"Bob\",\"Bob\"], [\"Charlie\",\"Charlie\"], [\"David\",\"David\"], keep order:false, stats:pseudo", - " └─TopN(Probe) 6.00 cop[tikv] test.tbl_29711.col_250, test.tbl_29711.col_251, offset:0, count:6", - " └─TableRowIDScan 30.00 cop[tikv] table:tbl_29711 keep order:false, stats:pseudo", - )) - - tk.MustExec("drop table if exists t29711") - tk.MustExec("CREATE TABLE `t29711` (" + - "`a` varchar(10) DEFAULT NULL," + - "`b` int(11) DEFAULT NULL," + - "`c` int(11) DEFAULT NULL," + - "KEY `ia` (`a`(2)))") - tk.MustQuery("explain format=brief select * from t29711 use index (ia) order by a limit 10;"). - Check(testkit.Rows( - "TopN 10.00 root test.t29711.a, offset:0, count:10", - "└─IndexLookUp 10.00 root ", - " ├─IndexFullScan(Build) 10000.00 cop[tikv] table:t29711, index:ia(a) keep order:false, stats:pseudo", - " └─TopN(Probe) 10.00 cop[tikv] test.t29711.a, offset:0, count:10", - " └─TableRowIDScan 10000.00 cop[tikv] table:t29711 keep order:false, stats:pseudo", - )) -} - -func TestIssue27313(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varchar(100), b int, c int, index idx1(a(2), b), index idx2(a))") - tk.MustExec("explain format = 'verbose' select * from t where a = 'abcdefghijk' and b > 4") - // no warning indicates that idx2 is not pruned by idx1. - tk.MustQuery("show warnings").Check(testkit.Rows()) -} - -func TestIssue30094(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec(`drop table if exists t30094;`) - tk.MustExec(`create table t30094(a varchar(10));`) - tk.MustQuery(`explain format = 'brief' select * from t30094 where cast(a as float) and cast(a as char);`).Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] cast(test.t30094.a, float BINARY), cast(test.t30094.a, var_string(5))", - " └─TableFullScan 10000.00 cop[tikv] table:t30094 keep order:false, stats:pseudo", - )) - tk.MustQuery(`explain format = 'brief' select * from t30094 where concat(a,'1') = _binary 0xe59388e59388e59388 collate binary and concat(a,'1') = _binary 0xe598bfe598bfe598bf collate binary;`).Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] eq(concat(test.t30094.a, \"1\"), \"0xe59388e59388e59388\"), eq(concat(test.t30094.a, \"1\"), \"0xe598bfe598bfe598bf\")", - " └─TableFullScan 10000.00 cop[tikv] table:t30094 keep order:false, stats:pseudo", - )) -} - -func TestIssue29705(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - origin := tk.MustQuery("SELECT @@session.tidb_partition_prune_mode") - originStr := origin.Rows()[0][0].(string) - defer func() { - tk.MustExec("set @@session.tidb_partition_prune_mode = '" + originStr + "'") - }() - tk.MustExec("set @@session.tidb_partition_prune_mode = 'static'") - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(id int) partition by hash(id) partitions 4;") - tk.MustExec("insert into t values(1);") - result := tk.MustQuery("SELECT COUNT(1) FROM ( SELECT COUNT(1) FROM t b GROUP BY id) a;") - result.Check(testkit.Rows("1")) -} - -func TestIssue30271(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b char(10), c char(10), index (a, b, c)) collate utf8mb4_bin;") - tk.MustExec("insert into t values ('b', 'a', '1'), ('b', 'A', '2'), ('c', 'a', '3');") - tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;") - tk.MustQuery("select * from t where (a>'a' and b='a') or (b = 'A' and a < 'd') order by a,c;").Check(testkit.Rows("b a 1", "b A 2", "c a 3")) -} - func TestIssue30804(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -3569,113 +1258,6 @@ func TestIssue30804(t *testing.T) { tk.MustExec("select avg(0) over w1 from t1 where b > (select sum(t2.a) over w2 from t2 window w2 as (partition by t2.b)) window w1 as (partition by t1.b)") } -func TestIndexMergeWarning(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(c1 int, c2 int)") - tk.MustExec("select /*+ use_index_merge(t1) */ * from t1 where c1 < 1 or c2 < 1") - warningMsg := "Warning 1105 IndexMerge is inapplicable or disabled. No available filter or available index." - tk.MustQuery("show warnings").Check(testkit.Rows(warningMsg)) - - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(c1 int, c2 int, key(c1), key(c2))") - tk.MustExec("select /*+ use_index_merge(t1), no_index_merge() */ * from t1 where c1 < 1 or c2 < 1") - warningMsg = "Warning 1105 IndexMerge is inapplicable or disabled. Got no_index_merge hint or tidb_enable_index_merge is off." - tk.MustQuery("show warnings").Check(testkit.Rows(warningMsg)) - - tk.MustExec("drop table if exists t1") - tk.MustExec("create temporary table t1(c1 int, c2 int, key(c1), key(c2))") - tk.MustExec("select /*+ use_index_merge(t1) */ * from t1 where c1 < 1 or c2 < 1") - warningMsg = "Warning 1105 IndexMerge is inapplicable or disabled. Cannot use IndexMerge on temporary table." - tk.MustQuery("show warnings").Check(testkit.Rows(warningMsg)) -} - -func TestIssue20510(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("CREATE TABLE t1 (a int PRIMARY KEY, b int)") - tk.MustExec("CREATE TABLE t2 (a int PRIMARY KEY, b int)") - tk.MustExec("INSERT INTO t1 VALUES (1,1), (2,1), (3,1), (4,2)") - tk.MustExec("INSERT INTO t2 VALUES (1,2), (2,2)") - - tk.MustQuery("explain format=brief SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE not(0+(t1.a=30 and t2.b=1));").Check(testkit.Rows( - "Selection 8000.00 root not(plus(0, and(eq(test.t1.a, 30), eq(test.t2.b, 1))))", - "└─MergeJoin 10000.00 root left outer join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 8000.00 root data:Selection", - " │ └─Selection 8000.00 cop[tikv] not(istrue_with_null(plus(0, and(eq(test.t2.a, 30), eq(test.t2.b, 1)))))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo")) - tk.MustQuery("SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE not(0+(t1.a=30 and t2.b=1));").Check(testkit.Rows( - "1 1 1 2", - "2 1 2 2", - "3 1 ", - "4 2 ", - )) -} - -func TestIssue31035(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(c1 longtext, c2 decimal(37, 4), unique key(c1(10)), unique key(c2));") - tk.MustExec("insert into t1 values('眐', -962541614831459.7458);") - tk.MustQuery("select * from t1 order by c2 + 10;").Check(testkit.Rows("眐 -962541614831459.7458")) -} - -// TestDNFCondSelectivityWithConst test selectivity calculation with DNF conditions with one is const. -// Close https://github.com/pingcap/tidb/issues/31096 -func TestDNFCondSelectivityWithConst(t *testing.T) { - store := testkit.CreateMockStore(t) - testKit := testkit.NewTestKit(t, store) - testKit.MustExec("use test") - testKit.MustExec("drop table if exists t1") - testKit.MustExec("create table t1(a int, b int, c int);") - testKit.MustExec("insert into t1 value(10,10,10)") - for i := 0; i < 7; i++ { - testKit.MustExec("insert into t1 select * from t1") - } - testKit.MustExec("insert into t1 value(1,1,1)") - testKit.MustExec("analyze table t1") - - testKit.MustQuery("explain format = 'brief' select * from t1 where a=1 or b=1;").Check(testkit.Rows( - "TableReader 1.99 root data:Selection", - "└─Selection 1.99 cop[tikv] or(eq(test.t1.a, 1), eq(test.t1.b, 1))", - " └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false")) - testKit.MustQuery("explain format = 'brief' select * from t1 where 0=1 or a=1 or b=1;").Check(testkit.Rows( - "TableReader 1.99 root data:Selection", - "└─Selection 1.99 cop[tikv] or(0, or(eq(test.t1.a, 1), eq(test.t1.b, 1)))", - " └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false")) - testKit.MustQuery("explain format = 'brief' select * from t1 where null or a=1 or b=1;").Check(testkit.Rows( - "TableReader 1.99 root data:Selection", - "└─Selection 1.99 cop[tikv] or(0, or(eq(test.t1.a, 1), eq(test.t1.b, 1)))", - " └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false")) - testKit.MustQuery("explain format = 'brief' select * from t1 where a=1 or false or b=1;").Check(testkit.Rows( - "TableReader 1.99 root data:Selection", - "└─Selection 1.99 cop[tikv] or(eq(test.t1.a, 1), or(0, eq(test.t1.b, 1)))", - " └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false")) - testKit.MustQuery("explain format = 'brief' select * from t1 where a=1 or b=1 or \"false\";").Check(testkit.Rows( - "TableReader 1.99 root data:Selection", - "└─Selection 1.99 cop[tikv] or(eq(test.t1.a, 1), or(eq(test.t1.b, 1), 0))", - " └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false")) - testKit.MustQuery("explain format = 'brief' select * from t1 where 1=1 or a=1 or b=1;").Check(testkit.Rows( - "TableReader 129.00 root data:Selection", - "└─Selection 129.00 cop[tikv] or(1, or(eq(test.t1.a, 1), eq(test.t1.b, 1)))", - " └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false")) - testKit.MustQuery("explain format = 'brief' select * from t1 where a=1 or b=1 or 1=1;").Check(testkit.Rows( - "TableReader 129.00 root data:Selection", - "└─Selection 129.00 cop[tikv] or(eq(test.t1.a, 1), or(eq(test.t1.b, 1), 1))", - " └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false")) - testKit.MustExec("drop table if exists t1") -} - func TestIssue31202(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) @@ -3923,74 +1505,6 @@ func TestIssue33175(t *testing.T) { tk.MustQuery("select * from tmp2 where id <= -1 or id > 0 order by id asc;").Check(testkit.Rows("-2", "-1", "1", "2")) } -func TestIssue33042(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("create table t1(id int primary key, col1 int)") - tk.MustExec("create table t2(id int primary key, col1 int)") - tk.MustQuery("explain format='brief' SELECT /*+ merge_join(t1, t2)*/ * FROM (t1 LEFT JOIN t2 ON t1.col1=t2.id) order by t2.id;").Check( - testkit.Rows( - "Sort 12500.00 root test.t2.id", - "└─MergeJoin 12500.00 root left outer join, left key:test.t1.col1, right key:test.t2.id", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo", - " └─Sort(Probe) 10000.00 root test.t1.col1", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - ), - ) -} - -func TestIssue29663(t *testing.T) { - store := testkit.CreateMockStore(t) - 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 (c int, d int)") - tk.MustExec("insert into t1 values(1, 1), (1,2),(2,1),(2,2)") - tk.MustExec("insert into t2 values(1, 3), (1,4),(2,5),(2,6)") - - tk.MustQuery("explain select one.a from t1 one order by (select two.d from t2 two where two.c = one.b)").Check(testkit.Rows( - "Projection_16 10000.00 root test.t1.a", - "└─Sort_17 10000.00 root test.t2.d", - " └─Apply_20 10000.00 root CARTESIAN left outer join", - " ├─TableReader_22(Build) 10000.00 root data:TableFullScan_21", - " │ └─TableFullScan_21 10000.00 cop[tikv] table:one keep order:false, stats:pseudo", - " └─MaxOneRow_23(Probe) 10000.00 root ", - " └─TableReader_26 20000.00 root data:Selection_25", - " └─Selection_25 20000.00 cop[tikv] eq(test.t2.c, test.t1.b)", - " └─TableFullScan_24 20000000.00 cop[tikv] table:two keep order:false, stats:pseudo")) -} - -func TestIssue31609(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustQuery("explain select rank() over (partition by table_name) from information_schema.tables").Check(testkit.Rows( - "Projection_7 10000.00 root Column#27->Column#28", - "└─Shuffle_11 10000.00 root execution info: concurrency:5, data sources:[MemTableScan_9]", - " └─Window_8 10000.00 root rank()->Column#27 over(partition by Column#3)", - " └─Sort_10 10000.00 root Column#3", - " └─MemTableScan_9 10000.00 root table:TABLES ", - )) -} - -func TestDecimalOverflow(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table deci (a decimal(65,30),b decimal(65,0))") - tk.MustExec("insert into deci values (1234567890.123456789012345678901234567890,987654321098765432109876543210987654321098765432109876543210)") - tk.MustQuery("select a from deci union ALL select b from deci;").Sort().Check(testkit.Rows("1234567890.123456789012345678901234567890", "99999999999999999999999999999999999.999999999999999999999999999999")) -} - func TestIssue35083(t *testing.T) { defer func() { variable.SetSysVar(variable.TiDBOptProjectionPushDown, variable.BoolToOnOff(config.GetGlobalConfig().Performance.ProjectionPushDown)) @@ -4011,24 +1525,6 @@ func TestIssue35083(t *testing.T) { " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) } -func TestIssue25813(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a json);") - tk.MustExec("insert into t values('{\"id\": \"ish\"}');") - tk.MustQuery("select t2.a from t t1 left join t t2 on t1.a=t2.a where t2.a->'$.id'='ish';").Check(testkit.Rows("{\"id\": \"ish\"}")) - - tk.MustQuery("explain format = 'brief' select * from t t1 left join t t2 on t1.a=t2.a where t2.a->'$.id'='ish';").Check(testkit.Rows( - "Selection 8000.00 root eq(json_extract(test.t.a, \"$.id\"), cast(\"ish\", json BINARY))", - "└─HashJoin 10000.00 root left outer join, equal:[eq(test.t.a, test.t.a)]", - " ├─TableReader(Build) 8000.00 root data:Selection", - " │ └─Selection 8000.00 cop[tikv] not(isnull(cast(test.t.a, var_string(4294967295))))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) -} - func TestRepeatPushDownToTiFlash(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -4505,58 +2001,6 @@ func TestLeastGretestStringPushDownToTiFlash(t *testing.T) { tk.MustQuery("explain select greatest(a, b) from t;").CheckAt([]int{0, 2, 4}, rows) } -func TestPartitionTableFallBackStatic(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@tidb_partition_prune_mode='static'") - tk.MustExec("CREATE TABLE t (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6),PARTITION p1 VALUES LESS THAN (11));") - tk.MustExec("insert into t values (1),(2),(3),(4),(7),(8),(9),(10)") - tk.MustExec("analyze table t") - - // use static plan in static mode - rows := [][]interface{}{ - {"PartitionUnion", "", ""}, - {"├─TableReader", "", "data:TableFullScan"}, - {"│ └─TableFullScan", "table:t, partition:p0", "keep order:false"}, - {"└─TableReader", "", "data:TableFullScan"}, - {" └─TableFullScan", "table:t, partition:p1", "keep order:false"}, - } - tk.MustQuery("explain format='brief' select * from t").CheckAt([]int{0, 3, 4}, rows) - - tk.MustExec("CREATE TABLE t2 (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6),PARTITION p1 VALUES LESS THAN (11));") - tk.MustExec("insert into t2 values (1),(2),(3),(4),(7),(8),(9),(10)") - tk.MustExec("analyze table t2") - tk.MustExec("set @@tidb_partition_prune_mode='dynamic'") - - // use static plan in dynamic mode due to having not global stats - tk.MustQuery("explain format='brief' select * from t").CheckAt([]int{0, 3, 4}, rows) - tk.MustExec("analyze table t") - - // use dynamic plan in dynamic mode with global stats - rows = [][]interface{}{ - {"TableReader", "partition:all", "data:TableFullScan"}, - {"└─TableFullScan", "table:t", "keep order:false"}, - } - tk.MustQuery("explain format='brief' select * from t").CheckAt([]int{0, 3, 4}, rows) - - rows = [][]interface{}{ - {"Union", "", ""}, - {"├─PartitionUnion", "", ""}, - {"│ ├─TableReader", "", "data:TableFullScan"}, - {"│ │ └─TableFullScan", "table:t, partition:p0", "keep order:false"}, - {"│ └─TableReader", "", "data:TableFullScan"}, - {"│ └─TableFullScan", "table:t, partition:p1", "keep order:false"}, - {"└─PartitionUnion", "", ""}, - {" ├─TableReader", "", "data:TableFullScan"}, - {" │ └─TableFullScan", "table:t2, partition:p0", "keep order:false"}, - {" └─TableReader", "", "data:TableFullScan"}, - {" └─TableFullScan", "table:t2, partition:p1", "keep order:false"}, - } - // use static plan in dynamic mode due to t2 has no global stats - tk.MustQuery("explain format='brief' select * from t union all select * from t2;").CheckAt([]int{0, 3, 4}, rows) -} - func TestTiFlashReadForWriteStmt(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) @@ -4680,137 +2124,6 @@ func TestPointGetWithSelectLock(t *testing.T) { } } -func TestTableRangeFallback(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1 (a int primary key, b int)") - tk.MustExec("create table t2 (c int)") - tk.MustQuery("explain format='brief' select * from t1 where a in (10, 20, 30, 40, 50) and b > 1").Check(testkit.Rows( - "Selection 1.67 root gt(test.t1.b, 1)", - "└─Batch_Point_Get 5.00 root table:t1 handle:[10 20 30 40 50], keep order:false, desc:false")) - tk.MustQuery("explain format='brief' select * from t1 join t2 on t1.b = t2.c where t1.a in (10, 20, 30, 40, 50)").Check(testkit.Rows( - "HashJoin 6.24 root inner join, equal:[eq(test.t1.b, test.t2.c)]", - "├─Selection(Build) 5.00 root not(isnull(test.t1.b))", - "│ └─Batch_Point_Get 5.00 root table:t1 handle:[10 20 30 40 50], keep order:false, desc:false", - "└─TableReader(Probe) 9990.00 root data:Selection", - " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.c))", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo")) - tk.MustExec("set @@tidb_opt_range_max_size=10") - tk.MustQuery("explain format='brief' select * from t1 where a in (10, 20, 30, 40, 50) and b > 1").Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] gt(test.t1.b, 1), in(test.t1.a, 10, 20, 30, 40, 50)", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Memory capacity of 10 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen")) - tk.MustQuery("explain format='brief' select * from t1 join t2 on t1.b = t2.c where t1.a in (10, 20, 30, 40, 50)").Check(testkit.Rows( - "HashJoin 10000.00 root inner join, equal:[eq(test.t1.b, test.t2.c)]", - "├─TableReader(Build) 8000.00 root data:Selection", - "│ └─Selection 8000.00 cop[tikv] not(isnull(test.t2.c))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - "└─TableReader(Probe) 8000.00 root data:Selection", - " └─Selection 8000.00 cop[tikv] in(test.t1.a, 10, 20, 30, 40, 50), not(isnull(test.t1.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Memory capacity of 10 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen")) -} - -func TestIndexRangeFallback(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1 (a varchar(10), b varchar(10), c varchar(10), index idx_a_b(a(2), b(2)))") - tk.MustExec("create table t2 (d varchar(10))") - tk.MustExec("create table t3 (pk int primary key, a int, key(a))") - tk.MustExec("create table t4 (a int, b int, c int, index idx_a_b(a, b))") - - // Simple index range fallback case. - tk.MustExec("set @@tidb_opt_range_max_size=0") - tk.MustQuery("explain format='brief' select * from t1 where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff')").Check(testkit.Rows( - "IndexLookUp 0.90 root ", - "├─IndexRangeScan(Build) 0.90 cop[tikv] table:t1, index:idx_a_b(a, b) range:[\"aa\" \"dd\",\"aa\" \"dd\"], [\"aa\" \"ee\",\"aa\" \"ee\"], [\"aa\" \"ff\",\"aa\" \"ff\"], [\"bb\" \"dd\",\"bb\" \"dd\"], [\"bb\" \"ee\",\"bb\" \"ee\"], [\"bb\" \"ff\",\"bb\" \"ff\"], [\"cc\" \"dd\",\"cc\" \"dd\"], [\"cc\" \"ee\",\"cc\" \"ee\"], [\"cc\" \"ff\",\"cc\" \"ff\"], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.90 cop[tikv] in(test.t1.a, \"aaa\", \"bbb\", \"ccc\"), in(test.t1.b, \"ddd\", \"eee\", \"fff\")", - " └─TableRowIDScan 0.90 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustExec("set @@tidb_opt_range_max_size=1000") - tk.MustQuery("explain format='brief' select * from t1 where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff')").Check(testkit.Rows( - "IndexLookUp 0.09 root ", - "├─IndexRangeScan(Build) 30.00 cop[tikv] table:t1, index:idx_a_b(a, b) range:[\"aa\",\"aa\"], [\"bb\",\"bb\"], [\"cc\",\"cc\"], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.09 cop[tikv] in(test.t1.a, \"aaa\", \"bbb\", \"ccc\"), in(test.t1.b, \"ddd\", \"eee\", \"fff\")", - " └─TableRowIDScan 30.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen")) - - // Index range fallback under join. - tk.MustExec("set @@tidb_opt_range_max_size=0") - tk.MustQuery("explain format='brief' select * from t1 join t2 on t1.c = t2.d where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff')").Check(testkit.Rows( - "HashJoin 1.12 root inner join, equal:[eq(test.t1.c, test.t2.d)]", - "├─IndexLookUp(Build) 0.90 root ", - "│ ├─IndexRangeScan(Build) 0.90 cop[tikv] table:t1, index:idx_a_b(a, b) range:[\"aa\" \"dd\",\"aa\" \"dd\"], [\"aa\" \"ee\",\"aa\" \"ee\"], [\"aa\" \"ff\",\"aa\" \"ff\"], [\"bb\" \"dd\",\"bb\" \"dd\"], [\"bb\" \"ee\",\"bb\" \"ee\"], [\"bb\" \"ff\",\"bb\" \"ff\"], [\"cc\" \"dd\",\"cc\" \"dd\"], [\"cc\" \"ee\",\"cc\" \"ee\"], [\"cc\" \"ff\",\"cc\" \"ff\"], keep order:false, stats:pseudo", - "│ └─Selection(Probe) 0.90 cop[tikv] in(test.t1.a, \"aaa\", \"bbb\", \"ccc\"), in(test.t1.b, \"ddd\", \"eee\", \"fff\"), not(isnull(test.t1.c))", - "│ └─TableRowIDScan 0.90 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9990.00 root data:Selection", - " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.d))", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo")) - tk.MustExec("set @@tidb_opt_range_max_size=1000") - tk.MustQuery("explain format='brief' select * from t1 join t2 on t1.c = t2.d where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff')").Check(testkit.Rows( - "HashJoin 0.11 root inner join, equal:[eq(test.t1.c, test.t2.d)]", - "├─IndexLookUp(Build) 0.09 root ", - "│ ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t1, index:idx_a_b(a, b) range:[\"aa\",\"aa\"], [\"bb\",\"bb\"], [\"cc\",\"cc\"], keep order:false, stats:pseudo", - "│ └─Selection(Probe) 0.09 cop[tikv] in(test.t1.a, \"aaa\", \"bbb\", \"ccc\"), in(test.t1.b, \"ddd\", \"eee\", \"fff\"), not(isnull(test.t1.c))", - "│ └─TableRowIDScan 30.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9990.00 root data:Selection", - " └─Selection 9990.00 cop[tikv] not(isnull(test.t2.d))", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen")) - - // Index range fallback in index column + pk column schema. - tk.MustExec("set @@tidb_opt_range_max_size=0") - tk.MustQuery("explain format='brief' select /*+ use_index(t3, a) */ * from t3 where a in (1, 3, 5) and pk in (2, 4, 6)").Check(testkit.Rows( - "IndexReader 0.90 root index:IndexRangeScan", - "└─IndexRangeScan 0.90 cop[tikv] table:t3, index:a(a) range:[1 2,1 2], [1 4,1 4], [1 6,1 6], [3 2,3 2], [3 4,3 4], [3 6,3 6], [5 2,5 2], [5 4,5 4], [5 6,5 6], keep order:false, stats:pseudo")) - tk.MustExec("set @@tidb_opt_range_max_size=1000") - tk.MustQuery("explain format='brief' select /*+ use_index(t3, a) */ * from t3 where a in (1, 3, 5) and pk in (2, 4, 6)").Check(testkit.Rows( - "IndexReader 0.01 root index:Selection", - "└─Selection 0.01 cop[tikv] in(test.t3.pk, 2, 4, 6)", - " └─IndexRangeScan 30.00 cop[tikv] table:t3, index:a(a) range:[1,1], [3,3], [5,5], keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen")) - - // Index range fallback for idx_col1 in (?, ?, ?) and idx_col2 = ? conditions. Prevent SplitCorColAccessCondFromFilters - // adding idx_col2 = ? back to access conditions. - tk.MustExec("set @@tidb_opt_range_max_size=0") - tk.MustQuery("explain format='brief' select /*+ use_index(t4, idx_a_b) */ * from t4 where a in (1, 3, 5) and b = 2").Check(testkit.Rows( - "IndexLookUp 0.30 root ", - "├─IndexRangeScan(Build) 0.30 cop[tikv] table:t4, index:idx_a_b(a, b) range:[1 2,1 2], [3 2,3 2], [5 2,5 2], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.30 cop[tikv] table:t4 keep order:false, stats:pseudo")) - tk.MustExec("set @@tidb_opt_range_max_size=1000") - tk.MustQuery("explain format='brief' select /*+ use_index(t4, idx_a_b) */ * from t4 where a in (1, 3, 5) and b = 2").Check(testkit.Rows( - "IndexLookUp 0.03 root ", - "├─Selection(Build) 0.03 cop[tikv] eq(test.t4.b, 2)", - "│ └─IndexRangeScan 30.00 cop[tikv] table:t4, index:idx_a_b(a, b) range:[1,1], [3,3], [5,5], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.03 cop[tikv] table:t4 keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen")) -} - -func TestPlanCacheForTableRangeFallback(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("set @@tidb_enable_prepared_plan_cache=1") - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (a int primary key, b int)") - tk.MustExec("set @@tidb_opt_range_max_size=10") - tk.MustExec("prepare stmt from 'select * from t where a in (?, ?, ?, ?, ?) and b > 1'") - tk.MustExec("set @a=10, @b=20, @c=30, @d=40, @e=50") - tk.MustExec("execute stmt using @a, @b, @c, @d, @e") - tk.MustQuery("show warnings").Sort().Check(testkit.Rows("Warning 1105 Memory capacity of 10 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen", - "Warning 1105 skip prepared plan-cache: in-list is too long")) - tk.MustExec("execute stmt using @a, @b, @c, @d, @e") - // The plan with range fallback is not cached. - tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) -} - func TestPlanCacheForIndexRangeFallback(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -4905,18 +2218,6 @@ func TestCorColRangeWithRangeMaxSize(t *testing.T) { tk.MustQuery("select * from t1 where exists (select * from t3 where t3.a = t1.a)").Check(testkit.Rows("2", "4")) } -func TestIssue37760(t *testing.T) { - store := testkit.CreateMockStore(t) - 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), (4), (6)") - tk.MustExec("set @@tidb_opt_range_max_size=1") - tk.MustQuery("select * from t where a").Check(testkit.Rows("2", "4", "6")) - tk.MustQuery("show warnings").CheckContain("Memory capacity of 1 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen") -} - // TestExplainAnalyzeDMLCommit covers the issue #37373. func TestExplainAnalyzeDMLCommit(t *testing.T) { store := testkit.CreateMockStore(t) @@ -4981,54 +2282,6 @@ func TestPlanCacheForIndexJoinRangeFallback(t *testing.T) { tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) } -// https://github.com/pingcap/tidb/issues/38295. -func TestIssue38295(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE t0(c0 BLOB(298) , c1 BLOB(182) , c2 NUMERIC);") - tk.MustExec("CREATE VIEW v0(c0) AS SELECT t0.c1 FROM t0;") - tk.MustExec("INSERT INTO t0 VALUES (-1, 'a', '2046549365');") - tk.MustExec("CREATE INDEX i0 ON t0(c2);") - tk.MustGetErrCode("SELECT t0.c1, t0.c2 FROM t0 GROUP BY MOD(t0.c0, DEFAULT(t0.c2));", errno.ErrFieldNotInGroupBy) - tk.MustExec("UPDATE t0 SET c2=1413;") -} - -func TestOuterJoinEliminationForIssue18216(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (a int, c int);") - tk.MustExec("insert into t1 values (1, 1), (1, 2), (2, 3), (2, 4);") - tk.MustExec("create table t2 (a int, c int);") - tk.MustExec("insert into t2 values (1, 1), (1, 2), (2, 3), (2, 4);") - // The output might be unstable. - tk.MustExec("select group_concat(c order by (select group_concat(c order by a) from t2 where a=t1.a)) from t1; ") - tk.MustQuery("select group_concat(c order by (select group_concat(c order by c) from t2 where a=t1.a), c desc) from t1;").Check(testkit.Rows("2,1,4,3")) -} - -// https://github.com/pingcap/tidb/issues/36888. -func TestIssue36888(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE t0(c0 INT);") - tk.MustExec("CREATE TABLE t1(c0 INT);") - - tk.MustExec("INSERT INTO t0 VALUES (NULL);") - tk.MustQuery("SELECT t0.c0 FROM t0 LEFT JOIN t1 ON t0.c0>=t1.c0 WHERE (CONCAT_WS(t0.c0, t1.c0) IS NULL);").Check(testkit.Rows("")) -} - -// https://github.com/pingcap/tidb/issues/40285. -func TestIssue40285(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE t(col1 enum('p5', '9a33x') NOT NULL DEFAULT 'p5',col2 tinyblob DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = latin1 COLLATE = latin1_bin;") - tk.MustQuery("(select last_value(col1) over () as r0 from t) union all (select col2 as r0 from t);") -} - // https://github.com/pingcap/tidb/issues/41273 func TestIssue41273(t *testing.T) { store := testkit.CreateMockStore(t) @@ -5200,88 +2453,6 @@ func TestVirtualExprPushDown(t *testing.T) { tk.MustQuery("explain select * from t where c2 > 1;").CheckAt([]int{0, 2, 4}, rows) } -// https://github.com/pingcap/tidb/issues/41458 -func TestIssue41458(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil)) - tk.MustExec("use test") - tk.MustExec(`create table t (a int, b int, c int, index ia(a));`) - tk.MustExec("select * from t t1 join t t2 on t1.b = t2.b join t t3 on t2.b=t3.b join t t4 on t3.b=t4.b where t3.a=1 and t2.a=2;") - rawRows := tk.MustQuery("select plan from information_schema.statements_summary where SCHEMA_NAME = 'test' and STMT_TYPE = 'Select';").Sort().Rows() - plan := rawRows[0][0].(string) - rows := strings.Split(plan, "\n") - rows = rows[1:] - expectedRes := []string{ - "Projection", - "└─HashJoin", - " ├─HashJoin", - " │ ├─HashJoin", - " │ │ ├─IndexLookUp", - " │ │ │ ├─IndexRangeScan", - " │ │ │ └─Selection", - " │ │ │ └─TableRowIDScan", - " │ │ └─IndexLookUp", - " │ │ ├─IndexRangeScan", - " │ │ └─Selection", - " │ │ └─TableRowIDScan", - " │ └─TableReader", - " │ └─Selection", - " │ └─TableFullScan", - " └─TableReader", - " └─Selection", - " └─TableFullScan", - } - for i, row := range rows { - fields := strings.Split(row, "\t") - fields = strings.Split(fields[1], "_") - op := fields[0] - require.Equalf(t, expectedRes[i], op, fmt.Sprintf("Mismatch at index %d.", i)) - } -} - -func TestIssue43116(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("CREATE TABLE `sbtest1` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `k` int(11) NOT NULL DEFAULT '0', `c` char(120) NOT NULL DEFAULT '', `pad` char(60) NOT NULL DEFAULT '', PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ , KEY `k_1` (`k`) )") - tk.MustExec("set @@tidb_opt_range_max_size = 111") - tk.MustQuery("explain format='brief' select * from test.sbtest1 a where pad in ('1','1','1','1','1') and id in (1,1,1,1,1)").Check(testkit.Rows( - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] in(test.sbtest1.id, 1, 1, 1, 1, 1), in(test.sbtest1.pad, \"1\", \"1\", \"1\", \"1\", \"1\")", - " └─TableFullScan 10000.00 cop[tikv] table:a keep order:false, stats:pseudo")) - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Memory capacity of 111 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen")) -} - -func TestIssue45033(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2, t3, t4;") - tk.MustExec("create table t1 (c1 int, c2 int, c3 int, primary key(c1, c2));") - tk.MustExec("create table t2 (c2 int, c1 int, primary key(c2, c1));") - tk.MustExec("create table t3 (c4 int, key(c4));") - tk.MustExec("create table t4 (c2 varchar(20) , test_col varchar(50), gen_col varchar(50) generated always as(concat(test_col,'')) virtual not null, unique key(gen_col));") - tk.MustQuery(`select count(1) - from (select ( case - when count(1) - over( - partition by a.c2) >= 50 then 1 - else 0 - end ) alias1, - b.c2 as alias_col1 - from t1 a - left join (select c2 - from t4 f) k - on k.c2 = a.c2 - inner join t2 b - on b.c1 = a.c3) alias2 - where exists (select 1 - from (select distinct alias3.c4 as c2 - from t3 alias3) alias4 - where alias4.c2 = alias2.alias_col1);`).Check(testkit.Rows("0")) -} - func TestWindowRangeFramePushDownTiflash(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) diff --git a/planner/core/partition_pruner_test.go b/planner/core/partition_pruner_test.go deleted file mode 100644 index 4692dfd37c..0000000000 --- a/planner/core/partition_pruner_test.go +++ /dev/null @@ -1,606 +0,0 @@ -// Copyright 2019 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package core_test - -import ( - "fmt" - "strings" - "testing" - - "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/planner/core/internal" - "github.com/pingcap/tidb/testkit" - "github.com/pingcap/tidb/testkit/testdata" - "github.com/stretchr/testify/require" -) - -func TestRangeColumnPartitionPruningForIn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_cost_model_version=2") - tk.MustExec("drop database if exists test_range_col_in") - tk.MustExec("create database test_range_col_in") - tk.MustExec("use test_range_col_in") - tk.MustExec("set @@session.tidb_partition_prune_mode='static'") - - // case in issue-26739 - tk.MustExec(`CREATE TABLE t1 ( - id bigint(20) NOT NULL AUTO_INCREMENT, - dt date, - PRIMARY KEY (id,dt) NONCLUSTERED) - PARTITION BY RANGE COLUMNS(dt) ( - PARTITION p20201125 VALUES LESS THAN ("20201126"), - PARTITION p20201126 VALUES LESS THAN ("20201127"), - PARTITION p20201127 VALUES LESS THAN ("20201128"), - PARTITION p20201128 VALUES LESS THAN ("20201129"), - PARTITION p20201129 VALUES LESS THAN ("20201130"))`) - tk.MustQuery(`explain format='brief' select /*+ HASH_AGG() */ count(1) from t1 where dt in ('2020-11-27','2020-11-28')`).Check( - testkit.Rows("HashAgg 1.00 root funcs:count(Column#5)->Column#4", - "└─PartitionUnion 2.00 root ", - " ├─HashAgg 1.00 root funcs:count(Column#7)->Column#5", - " │ └─IndexReader 1.00 root index:HashAgg", - " │ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#7", - " │ └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000)", - " │ └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201127, index:PRIMARY(id, dt) keep order:false, stats:pseudo", - " └─HashAgg 1.00 root funcs:count(Column#10)->Column#5", - " └─IndexReader 1.00 root index:HashAgg", - " └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#10", - " └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000)", - " └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201128, index:PRIMARY(id, dt) keep order:false, stats:pseudo")) - - tk.MustExec(`insert into t1 values (1, "2020-11-25")`) - tk.MustExec(`insert into t1 values (2, "2020-11-26")`) - tk.MustExec(`insert into t1 values (3, "2020-11-27")`) - tk.MustExec(`insert into t1 values (4, "2020-11-28")`) - tk.MustQuery(`select id from t1 where dt in ('2020-11-27','2020-11-28') order by id`).Check(testkit.Rows("3", "4")) - tk.MustQuery(`select id from t1 where dt in (20201127,'2020-11-28') order by id`).Check(testkit.Rows("3", "4")) - tk.MustQuery(`select id from t1 where dt in (20201127,20201128) order by id`).Check(testkit.Rows("3", "4")) - tk.MustQuery(`select id from t1 where dt in (20201127,20201128,null) order by id`).Check(testkit.Rows("3", "4")) - tk.MustQuery(`select id from t1 where dt in ('2020-11-26','2020-11-25','2020-11-28') order by id`).Check(testkit.Rows("1", "2", "4")) - tk.MustQuery(`select id from t1 where dt in ('2020-11-26','wrong','2020-11-28') order by id`).Check(testkit.Rows("2", "4")) - - // int - tk.MustExec(`create table t2 (a int) partition by range columns(a) ( - partition p0 values less than (0), - partition p1 values less than (10), - partition p2 values less than (20))`) - tk.MustExec(`insert into t2 values (-1), (1), (11), (null)`) - tk.MustQuery(`select a from t2 where a in (-1, 1) order by a`).Check(testkit.Rows("-1", "1")) - tk.MustQuery(`select a from t2 where a in (1, 11, null) order by a`).Check(testkit.Rows("1", "11")) - tk.MustQuery(`explain format='brief' select a from t2 where a in (-1, 1)`).Check(testkit.Rows("PartitionUnion 40.00 root ", - "├─TableReader 20.00 root data:Selection", - "│ └─Selection 20.00 cop[tikv] in(test_range_col_in.t2.a, -1, 1)", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo", - "└─TableReader 20.00 root data:Selection", - " └─Selection 20.00 cop[tikv] in(test_range_col_in.t2.a, -1, 1)", - " └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo")) - - tk.MustExec(`create table t3 (a varchar(10)) partition by range columns(a) ( - partition p0 values less than ("aaa"), - partition p1 values less than ("bbb"), - partition p2 values less than ("ccc"))`) - tk.MustQuery(`explain format='brief' select a from t3 where a in ('aaa', 'aab')`).Check(testkit.Rows( - `TableReader 20.00 root data:Selection`, - `└─Selection 20.00 cop[tikv] in(test_range_col_in.t3.a, "aaa", "aab")`, - ` └─TableFullScan 10000.00 cop[tikv] table:t3, partition:p1 keep order:false, stats:pseudo`)) - tk.MustQuery(`explain format='brief' select a from t3 where a in ('aaa', 'bu')`).Check(testkit.Rows( - `PartitionUnion 40.00 root `, - `├─TableReader 20.00 root data:Selection`, - `│ └─Selection 20.00 cop[tikv] in(test_range_col_in.t3.a, "aaa", "bu")`, - `│ └─TableFullScan 10000.00 cop[tikv] table:t3, partition:p1 keep order:false, stats:pseudo`, - `└─TableReader 20.00 root data:Selection`, - ` └─Selection 20.00 cop[tikv] in(test_range_col_in.t3.a, "aaa", "bu")`, - ` └─TableFullScan 10000.00 cop[tikv] table:t3, partition:p2 keep order:false, stats:pseudo`)) -} - -func TestRangeColumnPartitionPruningForInString(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("drop database if exists test_range_col_in_string") - tk.MustExec("create database test_range_col_in_string") - - tk.MustExec("use test_range_col_in_string") - tk.MustExec("set names utf8mb4 collate utf8mb4_bin") - tk.MustExec("set @@session.tidb_partition_prune_mode='static'") - - type testStruct struct { - sql string - partitions string - rows []string - } - - extractPartitions := func(res *testkit.Result) string { - planStrings := testdata.ConvertRowsToStrings(res.Rows()) - partitions := []string{} - for _, s := range planStrings { - parts := internal.GetFieldValue("partition:", s) - if parts != "" { - partitions = append(partitions, strings.Split(parts, ",")...) - } - } - out := strings.Join(partitions, ",") - if out == "pNull,pAAAA,pCCC,pShrimpsandwich,paaa,pSushi,pMax" { - out = "all" - } - return out - } - checkColumnStringPruningTests := func(tests []testStruct) { - modes := []string{"dynamic", "static"} - for _, mode := range modes { - tk.MustExec(`set @@tidb_partition_prune_mode = '` + mode + `'`) - for _, test := range tests { - explainResult := tk.MustQuery("explain format = 'brief' " + test.sql) - partitions := extractPartitions(explainResult) - require.Equal(t, test.partitions, partitions, "Mode: %s sql: %s", mode, test.sql) - tk.MustQuery(test.sql).Sort().Check(testkit.Rows(test.rows...)) - } - } - } - tk.MustExec("create table t (a varchar(255) charset utf8mb4 collate utf8mb4_bin) partition by range columns(a)" + - `( partition pNull values less than (""),` + - `partition pAAAA values less than ("AAAA"),` + - `partition pCCC values less than ("CCC"),` + - `partition pShrimpsandwich values less than ("Räksmörgås"),` + - `partition paaa values less than ("aaa"),` + - `partition pSushi values less than ("🍣🍣🍣"),` + - `partition pMax values less than (MAXVALUE))`) - tk.MustExec(`insert into t values (NULL), ("a"), ("Räkmacka"), ("🍣 is life"), ("🍺 after work?"), ("🍺🍺🍺🍺🍺 for oktoberfest"),("AA"),("aa"),("AAA"),("aaa")`) - tests := []testStruct{ - {sql: `select * from t where a IS NULL`, partitions: "pNull", rows: []string{""}}, - {sql: `select * from t where a = 'AA'`, partitions: "pAAAA", rows: []string{"AA"}}, - {sql: `select * from t where a = 'AA' collate utf8mb4_general_ci`, partitions: "all", rows: []string{"AA", "aa"}}, - {sql: `select * from t where a = 'aa'`, partitions: "paaa", rows: []string{"aa"}}, - {sql: `select * from t where a = 'aa' collate utf8mb4_general_ci`, partitions: "all", rows: []string{"AA", "aa"}}, - {sql: `select * from t where a collate utf8mb4_general_ci = 'aa'`, partitions: "all", rows: []string{"AA", "aa"}}, - {sql: `select * from t where a = 'AAA'`, partitions: "pAAAA", rows: []string{"AAA"}}, - {sql: `select * from t where a = 'AB'`, partitions: "pCCC", rows: []string{}}, - {sql: `select * from t where a = 'aB'`, partitions: "paaa", rows: []string{}}, - {sql: `select * from t where a = '🍣'`, partitions: "pSushi", rows: []string{}}, - {sql: `select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?")`, partitions: "pShrimpsandwich,pSushi,pMax", rows: []string{"Räkmacka", "🍣 is life"}}, - {sql: `select * from t where a in ('AAA', 'aa')`, partitions: "pAAAA,paaa", rows: []string{"AAA", "aa"}}, - {sql: `select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa')`, partitions: "all", rows: []string{"AA", "AAA", "aa", "aaa"}}, - {sql: `select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci)`, partitions: "all", rows: []string{"AA", "AAA", "aa", "aaa"}}, - {sql: `select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa')`, partitions: "all", rows: []string{"AA", "AAA", "aa", "aaa"}}, - } - checkColumnStringPruningTests(tests) - tk.MustExec(`set names utf8mb4 collate utf8mb4_general_ci`) - checkColumnStringPruningTests(tests) - tk.MustExec(`set names utf8mb4 collate utf8mb4_unicode_ci`) - checkColumnStringPruningTests(tests) - tk.MustExec("drop table t") - tk.MustExec("create table t (a varchar(255) charset utf8mb4 collate utf8mb4_general_ci) partition by range columns(a)" + - `( partition pNull values less than (""),` + - `partition paaa values less than ("aaa"),` + - `partition pAAAA values less than ("AAAA"),` + - `partition pCCC values less than ("CCC"),` + - `partition pShrimpsandwich values less than ("Räksmörgås"),` + - `partition pSushi values less than ("🍣🍣🍣"),` + - `partition pMax values less than (MAXVALUE))`) - tk.MustExec(`insert into t values (NULL), ("a"), ("Räkmacka"), ("🍣 is life"), ("🍺 after work?"), ("🍺🍺🍺🍺🍺 for oktoberfest"),("AA"),("aa"),("AAA"),("aaa")`) - - tests = []testStruct{ - {sql: `select * from t where a IS NULL`, partitions: "pNull", rows: []string{""}}, - {sql: `select * from t where a = 'AA'`, partitions: "paaa", rows: []string{"AA", "aa"}}, - {sql: `select * from t where a = 'AA' collate utf8mb4_bin`, partitions: "paaa", rows: []string{"AA"}}, - {sql: `select * from t where a = 'AAA'`, partitions: "pAAAA", rows: []string{"AAA", "aaa"}}, - {sql: `select * from t where a = 'AAA' collate utf8mb4_bin`, partitions: "pAAAA", rows: []string{"AAA"}}, - {sql: `select * from t where a = 'AB'`, partitions: "pCCC", rows: []string{}}, - {sql: `select * from t where a = 'aB'`, partitions: "pCCC", rows: []string{}}, - {sql: `select * from t where a = '🍣'`, partitions: "pSushi", rows: []string{}}, - {sql: `select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?")`, partitions: "pShrimpsandwich,pSushi,pMax", rows: []string{"Räkmacka", "🍣 is life"}}, - {sql: `select * from t where a in ('AA', 'aaa')`, partitions: "paaa,pAAAA", rows: []string{"AA", "AAA", "aa", "aaa"}}, - {sql: `select * from t where a in ('AAA' collate utf8mb4_bin, 'aa')`, partitions: "paaa,pAAAA", rows: []string{"AAA", "aa"}}, - {sql: `select * from t where a in ('AAA', 'aa' collate utf8mb4_bin)`, partitions: "paaa,pAAAA", rows: []string{"AAA", "aa"}}, - } - - tk.MustExec(`set names utf8mb4 collate utf8mb4_bin`) - checkColumnStringPruningTests(tests) - tk.MustExec(`set names utf8mb4 collate utf8mb4_general_ci`) - checkColumnStringPruningTests(tests) - tk.MustExec(`set names utf8mb4 collate utf8mb4_unicode_ci`) - checkColumnStringPruningTests(tests) -} - -func TestListColumnsPartitionPrunerRandom(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - valueNum := 10 - // Create table. - tk.MustExec("drop database if exists test_partition;") - tk.MustExec("create database test_partition") - tk.MustExec("use test_partition") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec("create table t1 (id int, a int, b int ) partition by list columns (b, id, a) (partition p0 values in ((1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0)),partition p1 values in ((1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2)),partition p2 values in ((0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2)))") - - tk1 := testkit.NewTestKit(t, store) - tk1.MustExec("drop database if exists test_partition_1;") - tk1.MustExec("create database test_partition_1") - tk1.MustExec("use test_partition_1") - tk1.MustExec("create table t1 (id int, a int, b int)") - - inserts := []string{ - "insert into t1 (b,id,a) values (1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0)", - "insert into t1 (b,id,a) values (1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2)", - "insert into t1 (b,id,a) values (0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2)", - } - // prepare data. - for _, insert := range inserts { - tk.MustExec(insert) - tk1.MustExec(insert) - - // Test query without condition - query := "select * from t1 order by id,a,b" - tk.MustQuery(query).Check(tk1.MustQuery(query).Rows()) - } - - // Test for single column condition. - for i := 0; i < valueNum+1; i++ { - query := fmt.Sprintf("select * from t1 where id = %v order by id,a,b", i) - tk.MustQuery(query).Check(tk1.MustQuery(query).Rows()) - query = fmt.Sprintf("select * from t1 where a = %v order by id,a,b", i) - tk.MustQuery(query).Check(tk1.MustQuery(query).Rows()) - query = fmt.Sprintf("select * from t1 where b = %v order by id,a,b", i) - tk.MustQuery(query).Check(tk1.MustQuery(query).Rows()) - } - // Test for multi-columns condition. - multiColumns := []string{ - "select * from t1 where 0 = a or 4 = b order by id,a,b", - "select * from t1 where b in (3,4,3,1) and b = 0 order by id,a,b", - "select * from t1 where 1 = b and id = 3 and 1 = id and b in (1,0,1,3,4,0,4,4) order by id,a,b", - "select * from t1 where 1 = b and id in (1,1,4,4,1,0,3) order by id,a,b", - "select * from t1 where 1 = b and b = 4 order by id,a,b", - } - for _, multi := range multiColumns { - tk.MustQuery(multi).Check(tk1.MustQuery(multi).Rows()) - } -} - -func TestIssue22635(t *testing.T) { - failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`) - defer func() { - failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune") - }() - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("DROP TABLE IF EXISTS t1") - tk.MustExec(` -CREATE TABLE t1 ( - a int(11) DEFAULT NULL, - b int(11) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin -PARTITION BY HASH( a ) -PARTITIONS 4`) - tk.MustQuery("SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa").Check(testkit.Rows()) // work fine without any error - - tk.MustExec("insert into t1 values (1, 1)") - tk.MustQuery("SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa").Check(testkit.Rows("1 1")) - - tk.MustExec("insert into t1 values (2, 2), (2, 2)") - tk.MustQuery("SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa").Check(testkit.Rows("1 2")) - - tk.MustExec("insert into t1 values (3, 3), (3, 3), (3, 3)") - tk.MustQuery("SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa").Check(testkit.Rows("1 3")) - - tk.MustExec("insert into t1 values (4, 4), (4, 4), (4, 4), (4, 4)") - tk.MustQuery("SELECT (SELECT tt.a FROM t1 tt ORDER BY a DESC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa").Check(testkit.Rows("4 4")) -} - -func TestIssue22898(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("DROP TABLE IF EXISTS test;") - tk.MustExec("CREATE TABLE NT_RP3763 (COL1 TINYINT(8) SIGNED COMMENT \"NUMERIC NO INDEX\" DEFAULT 41,COL2 VARCHAR(20),COL3 DATETIME,COL4 BIGINT,COL5 FLOAT) PARTITION BY RANGE (COL1 * COL3) (PARTITION P0 VALUES LESS THAN (0),PARTITION P1 VALUES LESS THAN (10),PARTITION P2 VALUES LESS THAN (20),PARTITION P3 VALUES LESS THAN (30),PARTITION P4 VALUES LESS THAN (40),PARTITION P5 VALUES LESS THAN (50),PARTITION PMX VALUES LESS THAN MAXVALUE);") - tk.MustExec("insert into NT_RP3763 (COL1,COL2,COL3,COL4,COL5) values(-82,\"夐齏醕皆磹漋甓崘潮嵙燷渏艂朼洛炷鉢儝鱈肇\",\"5748\\-06\\-26\\ 20:48:49\",-3133527360541070260,-2.624880003397658e+38);") - tk.MustExec("insert into NT_RP3763 (COL1,COL2,COL3,COL4,COL5) values(48,\"簖鹩筈匹眜赖泽騈爷詵赺玡婙Ɇ郝鮙廛賙疼舢\",\"7228\\-12\\-13\\ 02:59:54\",-6181009269190017937,2.7731105531290494e+38);") - tk.MustQuery("select * from `NT_RP3763` where `COL1` in (10, 48, -82);").Sort().Check(testkit.Rows("-82 夐齏醕皆磹漋甓崘潮嵙燷渏艂朼洛炷鉢儝鱈肇 5748-06-26 20:48:49 -3133527360541070260 -262488000000000000000000000000000000000", "48 簖鹩筈匹眜赖泽騈爷詵赺玡婙Ɇ郝鮙廛賙疼舢 7228-12-13 02:59:54 -6181009269190017937 277311060000000000000000000000000000000")) - tk.MustQuery("select * from `NT_RP3763` where `COL1` in (48);").Check(testkit.Rows("48 簖鹩筈匹眜赖泽騈爷詵赺玡婙Ɇ郝鮙廛賙疼舢 7228-12-13 02:59:54 -6181009269190017937 277311060000000000000000000000000000000")) -} - -func TestIssue23622(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t2 (a int, b int) partition by range (a) (partition p0 values less than (0), partition p1 values less than (5));") - tk.MustExec("insert into t2(a) values (-1), (1);") - tk.MustQuery("select * from t2 where a > 10 or b is NULL order by a;").Check(testkit.Rows("-1 ", "1 ")) -} - -func Test22396(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - tk.MustExec("DROP TABLE IF EXISTS test;") - tk.MustExec("CREATE TABLE test(a INT, b INT, PRIMARY KEY(a, b)) PARTITION BY RANGE (a + b) (PARTITION p0 VALUES LESS THAN (20),PARTITION p1 VALUES LESS THAN MAXVALUE);") - tk.MustExec("INSERT INTO test(a, b) VALUES(1, 11),(2, 22),(3, 33),(10, 44),(9, 55);") - tk.MustQuery("SELECT * FROM test WHERE a = 1;") - tk.MustQuery("SELECT * FROM test WHERE b = 1;") - tk.MustQuery("SELECT * FROM test WHERE a = 1 AND b = 1;") - tk.MustQuery("SELECT * FROM test WHERE a + b = 2;") -} - -func TestIssue23608(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@tidb_partition_prune_mode='static'") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(a int) partition by hash (a) partitions 10") - tk.MustExec("insert into t1 values (1), (2), (12), (3), (11), (13)") - tk.MustQuery("select * from t1 where a not between 2 and 2").Sort().Check(testkit.Rows("1", "11", "12", "13", "3")) - tk.MustQuery("select * from t1 where not (a < -20 or a > 20)").Sort().Check(testkit.Rows("1", "11", "12", "13", "2", "3")) - tk.MustQuery("select * from t1 where not (a > 0 and a < 10)").Sort().Check(testkit.Rows("11", "12", "13")) - tk.MustQuery("select * from t1 where not (a < -20)").Sort().Check(testkit.Rows("1", "11", "12", "13", "2", "3")) - tk.MustQuery("select * from t1 where not (a > 20)").Sort().Check(testkit.Rows("1", "11", "12", "13", "2", "3")) - tk.MustQuery("select * from t1 where not (a = 1)").Sort().Check(testkit.Rows("11", "12", "13", "2", "3")) - tk.MustQuery("select * from t1 where not (a != 1)").Check(testkit.Rows("1")) - - tk.MustExec("drop table if exists t2") - tk.MustExec(` -create table t2(a int) -partition by range (a) ( - partition p0 values less than (0), - partition p1 values less than (10), - partition p2 values less than (20) -)`) - tk.MustQuery("explain format = 'brief' select * from t2 where not (a < 5)").Check(testkit.Rows( - "PartitionUnion 6666.67 root ", - "├─TableReader 3333.33 root data:Selection", - "│ └─Selection 3333.33 cop[tikv] ge(test.t2.a, 5)", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo", - "└─TableReader 3333.33 root data:Selection", - " └─Selection 3333.33 cop[tikv] ge(test.t2.a, 5)", - " └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo")) - - tk.MustExec("set @@tidb_partition_prune_mode='dynamic'") - tk.MustExec("drop table if exists t3") - tk.MustExec("create table t3(a int) partition by hash (a) partitions 10") - tk.MustExec("insert into t3 values (1), (2), (12), (3), (11), (13)") - tk.MustQuery("select * from t3 where a not between 2 and 2").Sort().Check(testkit.Rows("1", "11", "12", "13", "3")) - tk.MustQuery("select * from t3 where not (a < -20 or a > 20)").Sort().Check(testkit.Rows("1", "11", "12", "13", "2", "3")) - tk.MustQuery("select * from t3 where not (a > 0 and a < 10)").Sort().Check(testkit.Rows("11", "12", "13")) - tk.MustQuery("select * from t3 where not (a < -20)").Sort().Check(testkit.Rows("1", "11", "12", "13", "2", "3")) - tk.MustQuery("select * from t3 where not (a > 20)").Sort().Check(testkit.Rows("1", "11", "12", "13", "2", "3")) - tk.MustQuery("select * from t3 where not (a = 1)").Sort().Check(testkit.Rows("11", "12", "13", "2", "3")) - tk.MustQuery("select * from t3 where not (a != 1)").Check(testkit.Rows("1")) -} - -func TestHashPartitionPruning(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_partition_prune_mode='static'") - tk.MustExec("USE test;") - tk.MustExec("DROP TABLE IF EXISTS t;") - tk.MustExec("CREATE TABLE t (`COL1` int, `COL3` bigint) PARTITION BY HASH ((`COL1` * `COL3`))PARTITIONS 13;") - tk.MustQuery("SELECT * FROM t WHERE col3 =2659937067964964513 and col1 = 783367513002;").Check(testkit.Rows()) - tk.MustExec("drop table if exists t;") - tk.MustExec("CREATE TABLE `t` (" + - "`COL1` int NOT NULL DEFAULT '25' COMMENT 'NUMERIC PK'," + - "`COL3` bigint NOT NULL," + - "PRIMARY KEY (`COL1`,`COL3`)" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin " + - "PARTITION BY HASH ((`COL1` * `COL3`))" + - "PARTITIONS 13;") - tk.MustExec("insert into t(col1, col3) values(0, 3522101843073676459);") - tk.MustQuery("SELECT col1, COL3 FROM t WHERE COL1 IN (0,14158354938390,0) AND COL3 IN (3522101843073676459,-2846203247576845955,838395691793635638);").Check(testkit.Rows("0 3522101843073676459")) -} - -func TestIssue32815(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_partition_prune_mode='dynamic'") - tk.MustExec("USE test;") - tk.MustExec("DROP TABLE IF EXISTS t;") - tk.MustExec("create table t (a int primary key, b int, key (b)) partition by hash(a) (partition P0, partition p1, partition P2)") - tk.MustExec("insert into t values (1, 1),(2, 2),(3, 3)") - tk.MustQuery("explain select * from t where a IN (1, 2)").Check(testkit.Rows( - "Batch_Point_Get_1 2.00 root table:t, partition:p1,P2 handle:[1 2], keep order:false, desc:false")) - tk.MustQuery("explain select * from t where a IN (1, 2, 1)").Check(testkit.Rows( - "Batch_Point_Get_1 3.00 root table:t, partition:p1,P2 handle:[1 2 1], keep order:false, desc:false")) -} - -func TestIssue32007(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database Issue32007") - tk.MustExec("USE Issue32007") - tk.MustExec("create table t1 (a int, b tinyint, primary key (a)) partition by range (a) (" + - "partition p0 values less than (5)," + - "partition p1 values less than (20)," + - "partition p2 values less than (30)," + - "partition p3 values less than (40)," + - "partition p4 values less than MAXVALUE)") - tk.MustExec("insert into t1 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (40, 40), (50, 50), (80, 80), (90, 90), (100, 100)") - tk.MustExec("create table t3 (a int, b mediumint, primary key (a))") - tk.MustExec("insert into t3 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23)") - - tk.MustExec("set @@tidb_partition_prune_mode='static'") - tk.MustQuery("select * from t3 where t3.a <> ALL (select t1.a from t1 partition (p0)) order by t3.a").Sort().Check(testkit.Rows("10 10", "11 11", "12 12", "13 13", "14 14", "15 15", "16 16", "17 17", "18 18", "19 19", "20 20", "21 21", "22 22", "23 23", "5 5", "6 6", "7 7", "8 8", "9 9")) - tk.MustExec("set @@tidb_partition_prune_mode='dynamic'") - tk.MustQuery("select * from t3 where t3.a <> ALL (select t1.a from t1 partition (p0)) order by t3.a").Sort().Check(testkit.Rows("10 10", "11 11", "12 12", "13 13", "14 14", "15 15", "16 16", "17 17", "18 18", "19 19", "20 20", "21 21", "22 22", "23 23", "5 5", "6 6", "7 7", "8 8", "9 9")) -} - -func TestIssue33231(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue33231") - tk.MustExec("use issue33231") - tk.MustExec("set @@session.tidb_partition_prune_mode = 'dynamic';") - tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) clustered, key(c_int) ) partition by hash (c_int) partitions 4;") - tk.MustExec("create table t2 like t1;") - tk.MustExec("insert into t1 values(6, 'beautiful curran');") - tk.MustExec("insert into t1 values(7, 'epic kalam');") - tk.MustExec("insert into t1 values(7, 'affectionate curie');") - tk.MustExec("insert into t2 values(6, 'vigorous rhodes');") - tk.MustExec("insert into t2 values(7, 'sweet aryabhata');") - tk.MustQuery("select /*+ INL_JOIN(t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_str <= t2.c_str and t2.c_int in (6, 7, 6);"). - Sort(). - Check(testkit.Rows("6 beautiful curran 6 vigorous rhodes", "7 affectionate curie 7 sweet aryabhata", "7 epic kalam 7 sweet aryabhata")) -} - -func TestListDefaultPruning(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database ListDefaultPrune") - tk.MustExec("use ListDefaultPrune") - tk.MustExec(`create table t (a int, b int) partition by list columns (a,b) (partition p1 values in ((1,1)), partition p2 values in ((2,2)), partition pDef default)`) - tk.MustExec(`insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4)`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select * from t where a in (1,2) and b in (1,2)`).Sort().Check(testkit.Rows("1 1", "1 2", "2 1", "2 2")) - tk.MustQuery(`select * from t where a in (1,2) and b in (3,4)`).Sort().Check(testkit.Rows("1 4", "2 3")) - tk.MustQuery(`explain format='brief' select * from t where a in (1,2) and b in (3,4)`).Check(testkit.Rows(""+ - `TableReader 2.57 root partition:pDef data:Selection`, - `└─Selection 2.57 cop[tikv] in(listdefaultprune.t.a, 1, 2), in(listdefaultprune.t.b, 3, 4)`, - ` └─TableFullScan 7.00 cop[tikv] table:t keep order:false`)) - - tk.MustQuery(`select * from t where a in (1,2) and b in (1,2)`).Sort().Check(testkit.Rows("1 1", "1 2", "2 1", "2 2")) - tk.MustQuery(`explain format='brief' select * from t where a in (1,2) and b in (1,2)`).Check(testkit.Rows(""+ - "TableReader 3.43 root partition:p1,p2,pDef data:Selection", - "└─Selection 3.43 cop[tikv] in(listdefaultprune.t.a, 1, 2), in(listdefaultprune.t.b, 1, 2)", - " └─TableFullScan 7.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from t where a in (1) and b in (1)`).Sort().Check(testkit.Rows("1 1")) - - // TODO: if exact match with multiple columns, do not include the default partition. - // Currently the LIST pruning needs refactoring, to use the Range optimizer for all conditions - // instead of per column only, which makes it hard to see if all combination are covered or not. - tk.MustQuery(`explain format='brief' select * from t where a in (1) and b in (1)`).Check(testkit.Rows(""+ - "TableReader 0.86 root partition:p1,pDef data:Selection", - "└─Selection 0.86 cop[tikv] eq(listdefaultprune.t.a, 1), eq(listdefaultprune.t.b, 1)", - " └─TableFullScan 7.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from t where a = 1 and b = 1`).Sort().Check(testkit.Rows("1 1")) - tk.MustQuery(`explain format='brief' select * from t where a = 1 and b = 1`).Check(testkit.Rows(""+ - "TableReader 0.86 root partition:p1,pDef data:Selection", - "└─Selection 0.86 cop[tikv] eq(listdefaultprune.t.a, 1), eq(listdefaultprune.t.b, 1)", - " └─TableFullScan 7.00 cop[tikv] table:t keep order:false")) - tk.MustExec(`drop table t`) - - tk.MustExec(`create table t (a int, b int) partition by list columns (a,b) (partition p1 values in ((1,1), (1,2)), partition p2 values in ((2,2),(2,1)), partition pDef default)`) - tk.MustExec(`insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4)`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select * from t where a in (1,2) and b in (1,2)`).Sort().Check(testkit.Rows("1 1", "1 2", "2 1", "2 2")) - tk.MustQuery(`explain format='brief' select * from t where a in (1,2) and b in (1,2)`).Check(testkit.Rows(""+ - "TableReader 3.43 root partition:p1,p2,pDef data:Selection", - "└─Selection 3.43 cop[tikv] in(listdefaultprune.t.a, 1, 2), in(listdefaultprune.t.b, 1, 2)", - " └─TableFullScan 7.00 cop[tikv] table:t keep order:false")) - tk.MustExec(`drop table t`) - - // Single column LIST COLUMNS pruning is OK on exact match! - tk.MustExec(`create table t (a int, b int) partition by list columns (a) (partition p1 values in (1), partition p2 values in (2), partition pDef default)`) - tk.MustExec(`insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4)`) - tk.MustExec(`analyze table t`) - tk.MustQuery(`select * from t where a in (1,2)`).Sort().Check(testkit.Rows("1 1", "1 2", "1 4", "2 1", "2 2", "2 3")) - tk.MustQuery(`explain format='brief' select * from t where a in (1,2)`).Check(testkit.Rows(""+ - "TableReader 6.00 root partition:p1,p2 data:Selection", - "└─Selection 6.00 cop[tikv] in(listdefaultprune.t.a, 1, 2)", - " └─TableFullScan 7.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from t where a = 1`).Sort().Check(testkit.Rows("1 1", "1 2", "1 4")) - tk.MustQuery(`explain format='brief' select * from t where a = 1`).Check(testkit.Rows(""+ - "TableReader 3.00 root partition:p1 data:Selection", - "└─Selection 3.00 cop[tikv] eq(listdefaultprune.t.a, 1)", - " └─TableFullScan 7.00 cop[tikv] table:t keep order:false")) -} - -func TestIssue42273(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue42273") - defer tk.MustExec("drop database issue42273") - - tk.MustExec("use issue42273") - tk.MustExec(`CREATE TABLE t(a tinyint unsigned, b tinyint unsigned) PARTITION BY RANGE COLUMNS (a,b)( - PARTITION p0 VALUES LESS THAN (10,255), - PARTITION p1 VALUES LESS THAN (20,MAXVALUE), - PARTITION p2 VALUES LESS THAN (30,255), - PARTITION p3 VALUES LESS THAN (MAXVALUE, 0))`) - tk.MustExec("insert into t values(20, 30)") - tk.MustExec(`analyze table t`) // Creates global stats for the table and enables the dynamic pruning - tk.MustQuery(`explain format='brief' select * from t where a = 20`).Check(testkit.Rows( - "TableReader 1.00 root partition:p1 data:Selection", - "└─Selection 1.00 cop[tikv] eq(issue42273.t.a, 20)", - " └─TableFullScan 1.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`explain format='brief' select * from t where a > 10 and a <= 20`).Check(testkit.Rows( - "TableReader 1.00 root partition:p1 data:Selection", - "└─Selection 1.00 cop[tikv] gt(issue42273.t.a, 10), le(issue42273.t.a, 20)", - " └─TableFullScan 1.00 cop[tikv] table:t keep order:false")) - tk.MustQuery(`select * from t where a = 20`).Check(testkit.Rows("20 30")) - tk.MustQuery(`select * from t where a > 10 and a <= 20`).Check(testkit.Rows("20 30")) -} - -func TestIssue43459(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("create database issue43459") - defer tk.MustExec("drop database issue43459") - tk.MustExec("use issue43459") - tk.MustExec("set @@session.tidb_partition_prune_mode = 'dynamic';") - tk.MustExec(`CREATE TABLE test1 (ID varchar(50) NOT NULL, - PARTITION_NO int(11) NOT NULL DEFAULT '0', - CREATE_TIME datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (ID,PARTITION_NO,CREATE_TIME), - KEY index_partition_no (PARTITION_NO) - ) PARTITION BY RANGE COLUMNS(PARTITION_NO,CREATE_TIME) - (PARTITION 2023p1 VALUES LESS THAN (200000,'2023-01-01 00:00:00'), - PARTITION 2023p2 VALUES LESS THAN (300000,'2023-01-01 00:00:00')) `) - checkFn := func() { - tk.MustExec(`insert into test1 values("1", 200000, "2022-12-29 12:00:00"), ("2",200000,"2023-01-01")`) - tk.MustExec(`analyze table test1`) - tk.MustQuery(`explain select * from test1 where partition_no > 199999`).CheckContain(`partition:all`) - tk.MustQuery(`explain select * from test1 where partition_no = 200000`).CheckContain("partition:all") - tk.MustQuery(`explain select * from test1 where partition_no >= 200000`).CheckContain("partition:all") - tk.MustQuery(`explain select * from test1 where partition_no < 200000`).CheckContain("partition:2023p1") - tk.MustQuery(`explain select * from test1 where partition_no <= 200000`).CheckContain("partition:all") - tk.MustQuery(`explain select * from test1 where partition_no > 200000`).CheckContain("partition:2023p2") - } - checkFn() - tk.MustQuery(`select * from test1 partition (2023p1)`).Check(testkit.Rows("" + - "1 200000 2022-12-29 12:00:00")) - tk.MustQuery(`select * from test1 partition (2023p2)`).Check(testkit.Rows("" + - "2 200000 2023-01-01 00:00:00")) - tk.MustQuery(`select * from test1`).Sort().Check(testkit.Rows(""+ - "1 200000 2022-12-29 12:00:00", - "2 200000 2023-01-01 00:00:00")) - tk.MustQuery(`select * from test1 where partition_no = 200000`).Sort().Check(testkit.Rows(""+ - "1 200000 2022-12-29 12:00:00", - "2 200000 2023-01-01 00:00:00")) - tk.MustQuery(`select * from test1 where partition_no >= 200000`).Sort().Check(testkit.Rows(""+ - "1 200000 2022-12-29 12:00:00", - "2 200000 2023-01-01 00:00:00")) - tk.MustExec(`drop table test1`) - tk.MustExec(`CREATE TABLE test1 (ID varchar(50) NOT NULL, - PARTITION_NO int(11) NOT NULL DEFAULT '0', - CREATE_TIME date NOT NULL DEFAULT CURRENT_DATE, - PRIMARY KEY (ID,PARTITION_NO,CREATE_TIME), - KEY index_partition_no (PARTITION_NO) - ) PARTITION BY RANGE COLUMNS(PARTITION_NO,CREATE_TIME) - (PARTITION 2023p1 VALUES LESS THAN (200000,'2023-01-01 00:00:00'), - PARTITION 2023p2 VALUES LESS THAN (300000,'2023-01-01 00:00:00')) `) - checkFn() - tk.MustQuery(`select * from test1 partition (2023p1)`).Check(testkit.Rows("" + - "1 200000 2022-12-29")) - tk.MustQuery(`select * from test1 partition (2023p2)`).Check(testkit.Rows("" + - "2 200000 2023-01-01")) - tk.MustQuery(`select * from test1`).Sort().Check(testkit.Rows(""+ - "1 200000 2022-12-29", - "2 200000 2023-01-01")) - tk.MustQuery(`select * from test1 where partition_no = 200000`).Sort().Check(testkit.Rows(""+ - "1 200000 2022-12-29", - "2 200000 2023-01-01")) - tk.MustQuery(`select * from test1 where partition_no >= 200000`).Sort().Check(testkit.Rows(""+ - "1 200000 2022-12-29", - "2 200000 2023-01-01")) -} diff --git a/planner/core/testdata/index_merge_suite_in.json b/planner/core/testdata/index_merge_suite_in.json index d660364305..db7ebacdb2 100644 --- a/planner/core/testdata/index_merge_suite_in.json +++ b/planner/core/testdata/index_merge_suite_in.json @@ -1,105 +1,4 @@ [ - { - "name": "TestEnforceMVIndex", - "cases": [ - "select /*+ use_index(t, kj) */ * from t", - "select /*+ use_index(t, kj) */ a from t", - "select /*+ use_index(t, kj) */ * from t where a<10", - "select /*+ use_index(t, kj) */ * from t where (1 member of (j))", - "select /*+ use_index(t, kj) */ * from t where (1 member of (j)) and a=10", - "select /*+ use_index(t, kj) */ * from t where (1 member of (j)) or a=10", - "select /*+ use_index_merge(t, kj) */ * from t", - "select /*+ use_index_merge(t, kj) */ a from t", - "select /*+ use_index_merge(t, kj) */ * from t where a<10", - "select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j)) or a=10" - ] - }, - { - "name": "TestIndexMergeJSONMemberOf", - "cases": [ - "select /*+ use_index_merge(t, j0_0) */ * from t where (1 member of (j0->'$.path0'))", - "select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10", - "select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.XXX')) and a<10", - "select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10", - "select /*+ use_index(t, j0_0) */ * from t where (1 member of (j0->'$.path0'))", - "select /*+ use_index(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10", - "select * from t use index(j0_0) where (1 member of (j0->'$.path0'))", - "select * from t use index(j0_1) where (1 member of (j0->'$.path1')) and a<10", - "select * from t force index(j0_0) where (1 member of (j0->'$.path0'))", - "select * from t force index(j0_1) where (1 member of (j0->'$.path1')) and a<10", - "select /*+ use_index_merge(t, j1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]')", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]')", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0'))", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]') and a<10", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]') and a<10", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0')) and a<10", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1')", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1')", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0'))", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1') and a<10", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1') and a<10", - "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0')) and a<10", - "select /*+ use_index_merge(t, j0_string) */ * from t where (\"a\" member of (j0->'$.path_string'))", - "select /*+ use_index_merge(t, j0_string) */ * from t where (\"a\" member of (j0->'$.path_string')) and a<10", - "select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]')", - "select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]') and a<10", - "select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]')", - "select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]') and a<10", - "select /*+ use_index_merge(t, j0_date) */ * from t where (\"2023-01-01\" member of (j0->'$.path_date'))", - "select /*+ use_index_merge(t, j0_date) */ * from t where (\"2023-01-01\" member of (j0->'$.path_date')) and a<10", - "select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date)))", - "select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10", - "select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date)))", - "select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10" - ] - }, - { - "name": "TestCompositeMVIndex", - "cases": [ - "select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4", - "select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j))", - "select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2", - "select /*+ use_index_merge(t, idx) */ * from t where a=1", - "select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str')) and c=4", - "select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str'))", - "select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2", - "select /*+ use_index_merge(t, idx2) */ * from t where a=1", - "select /*+ use_index(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4", - "select * from t use index(idx) where a=1 and b=2 and (3 member of (j))", - "select /*+ use_index(t, idx) */ * from t where a=1 and b=2", - "select * from t use index(idx) where a=1", - "select * from t force index(idx) where a=1 and b=2 and (3 member of (j))", - "select * from t force index(idx) where a=1" - ] - }, - { - "name": "TestDNFOnMVIndex", - "cases": [ - "select /*+ use_index_merge(t, idx1) */ * from t where (1 member of (j)) or (2 member of (j))", - "select /*+ use_index_merge(t, idx1) */ * from t where ((1 member of (j)) or (2 member of (j))) and (a > 10)", - "select /*+ use_index_merge(t, idx1) */ * from t where (json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]'))", - "select /*+ use_index_merge(t, idx1) */ * from t where ((json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]'))) and (a > 10)", - "select /*+ use_index_merge(t, idx1) */ * from t where (json_contains(j, '[1, 2]')) or (json_contains(j, '[3, 4]'))", - "select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)))", - "select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)) and c=14)", - "select /*+ use_index_merge(t, idx2) */ * from t where ((a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)))) and (c > 10)" - ] - }, - { - "name": "TestMVIndexSelection", - "cases": [ - "select (j->'$.int') from t where (1 member of (j->'$.int'))", - "select * from t where (1 member of (j->'$.int'))", - "select * from t where (1 member of (j->'$.int')) and a<10", - "select (j->'$.int') from t where json_contains((j->'$.int'), '[1, 2, 3]')", - "select * from t where json_contains((j->'$.int'), '[1, 2, 3]')", - "select * from t where json_contains((j->'$.int'), '[1, 2, 3]') and a<10", - "select (j->'$.int') from t where json_overlaps((j->'$.int'), '[1, 2, 3]')", - "select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]')", - "select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]') and a<10" - ] - }, { "name": "TestIndexMergePathGeneration", "cases": [ diff --git a/planner/core/testdata/index_merge_suite_out.json b/planner/core/testdata/index_merge_suite_out.json index 12a1064c23..3d67e5e372 100644 --- a/planner/core/testdata/index_merge_suite_out.json +++ b/planner/core/testdata/index_merge_suite_out.json @@ -1,724 +1,4 @@ [ - { - "Name": "TestEnforceMVIndex", - "Cases": [ - { - "SQL": "select /*+ use_index(t, kj) */ * from t", - "Plan": null, - "Err": "[planner:1815]Internal : Can't find a proper physical plan for this query" - }, - { - "SQL": "select /*+ use_index(t, kj) */ a from t", - "Plan": null, - "Err": "[planner:1815]Internal : Can't find a proper physical plan for this query" - }, - { - "SQL": "select /*+ use_index(t, kj) */ * from t where a<10", - "Plan": null, - "Err": "[planner:1815]Internal : Can't find a proper physical plan for this query" - }, - { - "SQL": "select /*+ use_index(t, kj) */ * from t where (1 member of (j))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Err": "" - }, - { - "SQL": "select /*+ use_index(t, kj) */ * from t where (1 member of (j)) and a=10", - "Plan": [ - "IndexMerge 0.01 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.01 cop[tikv] eq(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Err": "" - }, - { - "SQL": "select /*+ use_index(t, kj) */ * from t where (1 member of (j)) or a=10", - "Plan": null, - "Err": "[planner:1815]Internal : Can't find a proper physical plan for this query" - }, - { - "SQL": "select /*+ use_index_merge(t, kj) */ * from t", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Err": "" - }, - { - "SQL": "select /*+ use_index_merge(t, kj) */ a from t", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Err": "" - }, - { - "SQL": "select /*+ use_index_merge(t, kj) */ * from t where a<10", - "Plan": [ - "TableReader 3323.33 root data:Selection", - "└─Selection 3323.33 cop[tikv] lt(test.t.a, 10)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Err": "" - }, - { - "SQL": "select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j)) or a=10", - "Plan": [ - "TableReader 8002.00 root data:Selection", - "└─Selection 8002.00 cop[tikv] or(json_memberof(cast(1, json BINARY), test.t.j), eq(test.t.a, 10))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Err": "" - } - ] - }, - { - "Name": "TestIndexMergeJSONMemberOf", - "Cases": [ - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where (1 member of (j0->'$.path0'))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10", - "Plan": [ - "IndexMerge 3.32 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.XXX')) and a<10", - "Plan": [ - "TableReader 2658.67 root data:Selection", - "└─Selection 2658.67 cop[tikv] json_memberof(cast(1, json BINARY), json_extract(test.t.j0, \"$.XXX\")), lt(test.t.a, 10)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10", - "Plan": [ - "IndexMerge 2.66 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 2.66 cop[tikv] json_memberof(cast(2, json BINARY), test.t.j1), lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index(t, j0_0) */ * from t where (1 member of (j0->'$.path0'))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10", - "Plan": [ - "IndexMerge 3.32 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t use index(j0_0) where (1 member of (j0->'$.path0'))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t use index(j0_1) where (1 member of (j0->'$.path1')) and a<10", - "Plan": [ - "IndexMerge 3.32 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t force index(j0_0) where (1 member of (j0->'$.path0'))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t force index(j0_1) where (1 member of (j0->'$.path1')) and a<10", - "Plan": [ - "IndexMerge 3.32 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10", - "Plan": [ - "IndexMerge 2.66 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 2.66 cop[tikv] json_memberof(cast(2, json BINARY), test.t.j1), lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]')", - "Plan": [ - "IndexMerge 10.00 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]')", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path0\"), cast(\"[1, 2, 3]\", json BINARY))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0'))", - "Plan": [ - "Selection 8.00 root json_overlaps(cast(\"[1, 2, 3]\", json BINARY), json_extract(test.t.j0, \"$.path0\"))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]') and a<10", - "Plan": [ - "IndexMerge 3.32 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]') and a<10", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path0\"), cast(\"[1, 2, 3]\", json BINARY))", - "└─IndexMerge 3.32 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0')) and a<10", - "Plan": [ - "Selection 8.00 root json_overlaps(cast(\"[1, 2, 3]\", json BINARY), json_extract(test.t.j0, \"$.path0\"))", - "└─IndexMerge 3.32 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1')", - "Plan": [ - "IndexMerge 10.00 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1')", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path0\"), cast(\"1\", json BINARY))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0'))", - "Plan": [ - "Selection 8.00 root json_overlaps(cast(\"1\", json BINARY), json_extract(test.t.j0, \"$.path0\"))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1') and a<10", - "Plan": [ - "IndexMerge 3.32 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1') and a<10", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path0\"), cast(\"1\", json BINARY))", - "└─IndexMerge 3.32 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0')) and a<10", - "Plan": [ - "Selection 8.00 root json_overlaps(cast(\"1\", json BINARY), json_extract(test.t.j0, \"$.path0\"))", - "└─IndexMerge 3.32 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_string) */ * from t where (\"a\" member of (j0->'$.path_string'))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_string) */ * from t where (\"a\" member of (j0->'$.path_string')) and a<10", - "Plan": [ - "IndexMerge 3.32 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]')", - "Plan": [ - "IndexMerge 10.00 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]') and a<10", - "Plan": [ - "IndexMerge 3.32 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]')", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path_string\"), cast(\"[\"a\", \"b\", \"c\"]\", json BINARY))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '[\"a\", \"b\", \"c\"]') and a<10", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path_string\"), cast(\"[\"a\", \"b\", \"c\"]\", json BINARY))", - "└─IndexMerge 3.32 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_date) */ * from t where (\"2023-01-01\" member of (j0->'$.path_date'))", - "Plan": [ - "TableReader 8000.00 root data:Selection", - "└─Selection 8000.00 cop[tikv] json_memberof(cast(\"2023-01-01\", json BINARY), json_extract(test.t.j0, \"$.path_date\"))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_date) */ * from t where (\"2023-01-01\" member of (j0->'$.path_date')) and a<10", - "Plan": [ - "TableReader 2658.67 root data:Selection", - "└─Selection 2658.67 cop[tikv] json_memberof(cast(\"2023-01-01\", json BINARY), json_extract(test.t.j0, \"$.path_date\")), lt(test.t.a, 10)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date)))", - "Plan": [ - "IndexMerge 10.00 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10", - "Plan": [ - "IndexMerge 3.32 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date)))", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path_date\"), json_array(cast(2023-01-01, json BINARY), cast(2023-01-02, json BINARY), cast(2023-01-03, json BINARY)))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10", - "Plan": [ - "Selection 8.00 root json_overlaps(json_extract(test.t.j0, \"$.path_date\"), json_array(cast(2023-01-01, json BINARY), cast(2023-01-02, json BINARY), cast(2023-01-03, json BINARY)))", - "└─IndexMerge 3.32 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestCompositeMVIndex", - "Cases": [ - { - "SQL": "select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3 4,1 2 3 4], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j))", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2", - "Plan": [ - "IndexMerge 0.10 root type: union", - "├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2,1 2], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx) */ * from t where a=1", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str')) and c=4", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(json_extract(`j`, _utf8mb4'$.str') as char(10) array), c) range:[1 2 0x33 4,1 2 0x33 4], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str'))", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(json_extract(`j`, _utf8mb4'$.str') as char(10) array), c) range:[1 2 0x33,1 2 0x33], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2", - "Plan": [ - "IndexMerge 0.10 root type: union", - "├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2,1 2], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx2) */ * from t where a=1", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3 4,1 2 3 4], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t use index(idx) where a=1 and b=2 and (3 member of (j))", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index(t, idx) */ * from t where a=1 and b=2", - "Plan": [ - "IndexMerge 0.10 root type: union", - "├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2,1 2], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t use index(idx) where a=1", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t force index(idx) where a=1 and b=2 and (3 member of (j))", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t force index(idx) where a=1", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestDNFOnMVIndex", - "Cases": [ - { - "SQL": "select /*+ use_index_merge(t, idx1) */ * from t where (1 member of (j)) or (2 member of (j))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx1) */ * from t where ((1 member of (j)) or (2 member of (j))) and (a > 10)", - "Plan": [ - "IndexMerge 3.33 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.33 cop[tikv] gt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx1) */ * from t where (json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]'))", - "Plan": [ - "Selection 8.00 root or(json_overlaps(test.t.j, cast(\"[1, 2]\", json BINARY)), json_overlaps(test.t.j, cast(\"[3, 4]\", json BINARY)))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[4,4], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx1) */ * from t where ((json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]'))) and (a > 10)", - "Plan": [ - "Selection 8.00 root or(json_overlaps(test.t.j, cast(\"[1, 2]\", json BINARY)), json_overlaps(test.t.j, cast(\"[3, 4]\", json BINARY)))", - "└─IndexMerge 3.33 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[4,4], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.33 cop[tikv] gt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx1) */ * from t where (json_contains(j, '[1, 2]')) or (json_contains(j, '[3, 4]'))", - "Plan": [ - "TableReader 9600.00 root data:Selection", - "└─Selection 9600.00 cop[tikv] or(json_contains(test.t.j, cast(\"[1, 2]\", json BINARY)), json_contains(test.t.j, cast(\"[3, 4]\", json BINARY)))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)))", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[11 12 13,11 12 13], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)) and c=14)", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[11 12 13 14,11 12 13 14], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+ use_index_merge(t, idx2) */ * from t where ((a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)))) and (c > 10)", - "Plan": [ - "IndexMerge 0.00 root type: union", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[11 12 13,11 12 13], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.00 cop[tikv] gt(test.t.c, 10)", - " └─TableRowIDScan 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestMVIndexSelection", - "Cases": [ - { - "SQL": "select (j->'$.int') from t where (1 member of (j->'$.int'))", - "Plan": [ - "Projection 8000.00 root json_extract(test.t.j, $.int)->Column#5", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where (1 member of (j->'$.int'))", - "Plan": [ - "IndexMerge 10.00 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where (1 member of (j->'$.int')) and a<10", - "Plan": [ - "IndexMerge 3.32 root type: union", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select (j->'$.int') from t where json_contains((j->'$.int'), '[1, 2, 3]')", - "Plan": [ - "Projection 8000.00 root json_extract(test.t.j, $.int)->Column#5", - "└─IndexMerge 10.00 root type: intersection", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where json_contains((j->'$.int'), '[1, 2, 3]')", - "Plan": [ - "IndexMerge 10.00 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where json_contains((j->'$.int'), '[1, 2, 3]') and a<10", - "Plan": [ - "IndexMerge 3.32 root type: intersection", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo", - "└─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select (j->'$.int') from t where json_overlaps((j->'$.int'), '[1, 2, 3]')", - "Plan": [ - "Projection 8000.00 root json_extract(test.t.j, $.int)->Column#5", - "└─Selection 8000.00 root json_overlaps(json_extract(test.t.j, \"$.int\"), cast(\"[1, 2, 3]\", json BINARY))", - " └─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]')", - "Plan": [ - "Selection 8000.00 root json_overlaps(json_extract(test.t.j, \"$.int\"), cast(\"[1, 2, 3]\", json BINARY))", - "└─IndexMerge 10.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]') and a<10", - "Plan": [ - "Selection 2658.67 root json_overlaps(json_extract(test.t.j, \"$.int\"), cast(\"[1, 2, 3]\", json BINARY))", - "└─IndexMerge 3.32 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─Selection(Probe) 3.32 cop[tikv] lt(test.t.a, 10)", - " └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - } - ] - }, { "Name": "TestIndexMergePathGeneration", "Cases": [ diff --git a/tests/integrationtest/r/black_list.result b/tests/integrationtest/r/black_list.result index d9f3f6a606..66c81ddc01 100644 --- a/tests/integrationtest/r/black_list.result +++ b/tests/integrationtest/r/black_list.result @@ -54,3 +54,6 @@ id estRows task access object operator info TableReader 3323.33 root data:Selection └─Selection 3323.33 cop[tikv] lt(black_list.t.a, 1) └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; + diff --git a/tests/integrationtest/r/expression/issues.result b/tests/integrationtest/r/expression/issues.result index 93097ba429..d6f99175b7 100644 --- a/tests/integrationtest/r/expression/issues.result +++ b/tests/integrationtest/r/expression/issues.result @@ -901,6 +901,9 @@ j "" null "0" +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; + drop table if exists t0; CREATE TABLE t0(c0 int); INSERT INTO t0 VALUES (1); diff --git a/tests/integrationtest/r/planner/core/indexmerge_path.result b/tests/integrationtest/r/planner/core/indexmerge_path.result new file mode 100644 index 0000000000..253eb2c8b2 --- /dev/null +++ b/tests/integrationtest/r/planner/core/indexmerge_path.result @@ -0,0 +1,658 @@ +drop table if exists t; +create table t(a int, b int, c int, j json, +index(a), index(b), +index idx(a, b, (cast(j as signed array)), c), +index idx2(a, b, (cast(j->'$.str' as char(10) array)), c)); +set tidb_analyze_version=2; +analyze table t; +Level Code Message +Note 1105 Analyze use auto adjusted sample rate 1.000000 for table planner__core__indexmerge_path.t, reason to use this rate is "use min(1, 110000/10000) as the sample-rate=1" +analyze table t index idx; +Level Code Message +Note 1105 Analyze use auto adjusted sample rate 1.000000 for table planner__core__indexmerge_path.t, reason to use this rate is "TiDB assumes that the table is empty, use sample-rate=1" +Warning 1105 The version 2 would collect all statistics not only the selected indexes +set tidb_analyze_version=1; +analyze table t; +Level Code Message +Warning 1105 analyzing multi-valued indexes is not supported, skip idx +Warning 1105 analyzing multi-valued indexes is not supported, skip idx2 +analyze table t index idx; +Level Code Message +Warning 1105 analyzing multi-valued indexes is not supported, skip idx +analyze table t index a; +analyze table t index a, idx, idx2; +Level Code Message +Warning 1105 analyzing multi-valued indexes is not supported, skip idx +Warning 1105 analyzing multi-valued indexes is not supported, skip idx2 +drop table if exists t; +create table t( +a int, j0 json, j1 json, +index j0_0((cast(j0->'$.path0' as signed array))), +index j0_1((cast(j0->'$.path1' as signed array))), +index j0_string((cast(j0->'$.path_string' as char(10) array))), +index j0_date((cast(j0->'$.path_date' as date array))), +index j1((cast(j1 as signed array)))); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where (1 member of (j0->'$.path0')); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.XXX')) and a<10; +id estRows task access object operator info +TableReader 2658.67 root data:Selection +└─Selection 2658.67 cop[tikv] json_memberof(cast(1, json BINARY), json_extract(planner__core__indexmerge_path.t.j0, "$.XXX")), lt(planner__core__indexmerge_path.t.a, 10) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10; +id estRows task access object operator info +IndexMerge 2.66 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 2.66 cop[tikv] json_memberof(cast(2, json BINARY), planner__core__indexmerge_path.t.j1), lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index(t, j0_0) */ * from t where (1 member of (j0->'$.path0')); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t use index(j0_0) where (1 member of (j0->'$.path0')); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t use index(j0_1) where (1 member of (j0->'$.path1')) and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t force index(j0_0) where (1 member of (j0->'$.path0')); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t force index(j0_1) where (1 member of (j0->'$.path1')) and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10; +id estRows task access object operator info +IndexMerge 2.66 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_1(cast(json_extract(`j0`, _utf8mb4'$.path1') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 2.66 cop[tikv] json_memberof(cast(2, json BINARY), planner__core__indexmerge_path.t.j1), lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]'); +id estRows task access object operator info +IndexMerge 10.00 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]'); +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path0"), cast("[1, 2, 3]", json BINARY)) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0')); +id estRows task access object operator info +Selection 8.00 root json_overlaps(cast("[1, 2, 3]", json BINARY), json_extract(planner__core__indexmerge_path.t.j0, "$.path0")) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]') and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]') and a<10; +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path0"), cast("[1, 2, 3]", json BINARY)) +└─IndexMerge 3.32 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0')) and a<10; +id estRows task access object operator info +Selection 8.00 root json_overlaps(cast("[1, 2, 3]", json BINARY), json_extract(planner__core__indexmerge_path.t.j0, "$.path0")) +└─IndexMerge 3.32 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1'); +id estRows task access object operator info +IndexMerge 10.00 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1'); +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path0"), cast("1", json BINARY)) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0')); +id estRows task access object operator info +Selection 8.00 root json_overlaps(cast("1", json BINARY), json_extract(planner__core__indexmerge_path.t.j0, "$.path0")) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1') and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1') and a<10; +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path0"), cast("1", json BINARY)) +└─IndexMerge 3.32 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + └─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0')) and a<10; +id estRows task access object operator info +Selection 8.00 root json_overlaps(cast("1", json BINARY), json_extract(planner__core__indexmerge_path.t.j0, "$.path0")) +└─IndexMerge 3.32 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_0(cast(json_extract(`j0`, _utf8mb4'$.path0') as signed array)) range:[1,1], keep order:false, stats:pseudo + └─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where ("a" member of (j0->'$.path_string')); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where ("a" member of (j0->'$.path_string')) and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '["a", "b", "c"]'); +id estRows task access object operator info +IndexMerge 10.00 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '["a", "b", "c"]') and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '["a", "b", "c"]'); +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path_string"), cast("["a", "b", "c"]", json BINARY)) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '["a", "b", "c"]') and a<10; +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path_string"), cast("["a", "b", "c"]", json BINARY)) +└─IndexMerge 3.32 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x61,0x61], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x62,0x62], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_string(cast(json_extract(`j0`, _utf8mb4'$.path_string') as char(10) array)) range:[0x63,0x63], keep order:false, stats:pseudo + └─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where ("2023-01-01" member of (j0->'$.path_date')); +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] json_memberof(cast("2023-01-01", json BINARY), json_extract(planner__core__indexmerge_path.t.j0, "$.path_date")) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where ("2023-01-01" member of (j0->'$.path_date')) and a<10; +id estRows task access object operator info +TableReader 2658.67 root data:Selection +└─Selection 2658.67 cop[tikv] json_memberof(cast("2023-01-01", json BINARY), json_extract(planner__core__indexmerge_path.t.j0, "$.path_date")), lt(planner__core__indexmerge_path.t.a, 10) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))); +id estRows task access object operator info +IndexMerge 10.00 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))); +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path_date"), json_array(cast(2023-01-01, json BINARY), cast(2023-01-02, json BINARY), cast(2023-01-03, json BINARY))) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10; +id estRows task access object operator info +Selection 8.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j0, "$.path_date"), json_array(cast(2023-01-01, json BINARY), cast(2023-01-02, json BINARY), cast(2023-01-03, json BINARY))) +└─IndexMerge 3.32 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-01,2023-01-01], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-02,2023-01-02], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:j0_date(cast(json_extract(`j0`, _utf8mb4'$.path_date') as date array)) range:[2023-01-03,2023-01-03], keep order:false, stats:pseudo + └─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t; +create table t(a int, b int, c int, j json, +index idx1((cast(j as signed array))), +index idx2(a, b, (cast(j as signed array)), c)); +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where (1 member of (j)) or (2 member of (j)); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where ((1 member of (j)) or (2 member of (j))) and (a > 10); +id estRows task access object operator info +IndexMerge 3.33 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo +└─Selection(Probe) 3.33 cop[tikv] gt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where (json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]')); +id estRows task access object operator info +Selection 8.00 root or(json_overlaps(planner__core__indexmerge_path.t.j, cast("[1, 2]", json BINARY)), json_overlaps(planner__core__indexmerge_path.t.j, cast("[3, 4]", json BINARY))) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[4,4], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where ((json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]'))) and (a > 10); +id estRows task access object operator info +Selection 8.00 root or(json_overlaps(planner__core__indexmerge_path.t.j, cast("[1, 2]", json BINARY)), json_overlaps(planner__core__indexmerge_path.t.j, cast("[3, 4]", json BINARY))) +└─IndexMerge 3.33 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx1(cast(`j` as signed array)) range:[4,4], keep order:false, stats:pseudo + └─Selection(Probe) 3.33 cop[tikv] gt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where (json_contains(j, '[1, 2]')) or (json_contains(j, '[3, 4]')); +id estRows task access object operator info +TableReader 9600.00 root data:Selection +└─Selection 9600.00 cop[tikv] or(json_contains(planner__core__indexmerge_path.t.j, cast("[1, 2]", json BINARY)), json_contains(planner__core__indexmerge_path.t.j, cast("[3, 4]", json BINARY))) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j))); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[11 12 13,11 12 13], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)) and c=14); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[11 12 13 14,11 12 13 14], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where ((a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)))) and (c > 10); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(`j` as signed array), c) range:[11 12 13,11 12 13], keep order:false, stats:pseudo +└─Selection(Probe) 0.00 cop[tikv] gt(planner__core__indexmerge_path.t.c, 10) + └─TableRowIDScan 0.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t; +create table t(a int, b int , c int, j json, +index idx(a, b, (cast(j as signed array)), c), +index idx2(a, b, (cast(j->'$.str' as char(10) array)), c)); +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4; +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3 4,1 2 3 4], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2; +id estRows task access object operator info +IndexMerge 0.10 root type: union +├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2,1 2], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1; +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str')) and c=4; +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(json_extract(`j`, _utf8mb4'$.str') as char(10) array), c) range:[1 2 0x33 4,1 2 0x33 4], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str')); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx2(a, b, cast(json_extract(`j`, _utf8mb4'$.str') as char(10) array), c) range:[1 2 0x33,1 2 0x33], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2; +id estRows task access object operator info +IndexMerge 0.10 root type: union +├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2,1 2], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1; +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4; +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3 4,1 2 3 4], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t use index(idx) where a=1 and b=2 and (3 member of (j)); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index(t, idx) */ * from t where a=1 and b=2; +id estRows task access object operator info +IndexMerge 0.10 root type: union +├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2,1 2], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t use index(idx) where a=1; +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t force index(idx) where a=1 and b=2 and (3 member of (j)); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1 2 3,1 2 3], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t force index(idx) where a=1; +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, b, cast(`j` as signed array), c) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t; +create table t(a int, j json, +index i_int((cast(j->'$.int' as signed array)))); +explain format = 'brief' select (j->'$.int') from t where (1 member of (j->'$.int')); +id estRows task access object operator info +Projection 8000.00 root json_extract(planner__core__indexmerge_path.t.j, $.int)->Column#5 +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t where (1 member of (j->'$.int')); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t where (1 member of (j->'$.int')) and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select (j->'$.int') from t where json_contains((j->'$.int'), '[1, 2, 3]'); +id estRows task access object operator info +Projection 8000.00 root json_extract(planner__core__indexmerge_path.t.j, $.int)->Column#5 +└─IndexMerge 10.00 root type: intersection + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t where json_contains((j->'$.int'), '[1, 2, 3]'); +id estRows task access object operator info +IndexMerge 10.00 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t where json_contains((j->'$.int'), '[1, 2, 3]') and a<10; +id estRows task access object operator info +IndexMerge 3.32 root type: intersection +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo +└─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select (j->'$.int') from t where json_overlaps((j->'$.int'), '[1, 2, 3]'); +id estRows task access object operator info +Projection 8000.00 root json_extract(planner__core__indexmerge_path.t.j, $.int)->Column#5 +└─Selection 8000.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j, "$.int"), cast("[1, 2, 3]", json BINARY)) + └─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]'); +id estRows task access object operator info +Selection 8000.00 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j, "$.int"), cast("[1, 2, 3]", json BINARY)) +└─IndexMerge 10.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]') and a<10; +id estRows task access object operator info +Selection 2658.67 root json_overlaps(json_extract(planner__core__indexmerge_path.t.j, "$.int"), cast("[1, 2, 3]", json BINARY)) +└─IndexMerge 3.32 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:i_int(cast(json_extract(`j`, _utf8mb4'$.int') as signed array)) range:[3,3], keep order:false, stats:pseudo + └─Selection(Probe) 3.32 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t; +create table t(j json, index kj((cast(j as signed array)))); +prepare st from 'select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j))'; +Level Code Message +Warning 1105 skip prepared plan-cache: query accesses generated columns is un-cacheable +execute st; +j +execute st; +j +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +drop table if exists t; +create table t(j json, unique kj((cast(j as signed array)))); +explain select j from t where j=1; +id estRows task access object operator info +TableReader_7 8000.00 root data:Selection_6 +└─Selection_6 8000.00 cop[tikv] eq(planner__core__indexmerge_path.t.j, cast(1, json BINARY)) + └─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain select j from t where j=1 or j=2; +id estRows task access object operator info +TableReader_7 9600.00 root data:Selection_6 +└─Selection_6 9600.00 cop[tikv] or(eq(planner__core__indexmerge_path.t.j, cast(1, json BINARY)), eq(planner__core__indexmerge_path.t.j, cast(2, json BINARY))) + └─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain select j from t where j in (1, 2); +id estRows task access object operator info +TableReader_7 8000.00 root data:Selection_6 +└─Selection_6 8000.00 cop[tikv] in(planner__core__indexmerge_path.t.j, cast(1, json BINARY), cast(2, json BINARY)) + └─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t; +create table t(a int, j json, index kj((cast(j as signed array)))); +explain format = 'brief' select /*+ use_index(t, kj) */ * from t; +Error 1815 (HY000): Internal : Can't find a proper physical plan for this query +explain format = 'brief' select /*+ use_index(t, kj) */ a from t; +Error 1815 (HY000): Internal : Can't find a proper physical plan for this query +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where a<10; +Error 1815 (HY000): Internal : Can't find a proper physical plan for this query +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) and a=10; +id estRows task access object operator info +IndexMerge 0.01 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(planner__core__indexmerge_path.t.a, 10) + └─TableRowIDScan 10.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) or a=10; +Error 1815 (HY000): Internal : Can't find a proper physical plan for this query +explain format = 'brief' select /*+ use_index_merge(t, kj) */ * from t; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, kj) */ a from t; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, kj) */ * from t where a<10; +id estRows task access object operator info +TableReader 3323.33 root data:Selection +└─Selection 3323.33 cop[tikv] lt(planner__core__indexmerge_path.t.a, 10) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j)) or a=10; +id estRows task access object operator info +TableReader 8002.00 root data:Selection +└─Selection 8002.00 cop[tikv] or(json_memberof(cast(1, json BINARY), planner__core__indexmerge_path.t.j), eq(planner__core__indexmerge_path.t.a, 10)) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t; +create table t(a int, j json, index kj((cast(j as signed array)))); +explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +ALTER TABLE t ALTER INDEX kj INVISIBLE; +explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] json_memberof(cast(1, json BINARY), planner__core__indexmerge_path.t.j) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format='brief' select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j)); +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] json_memberof(cast(1, json BINARY), planner__core__indexmerge_path.t.j) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +ALTER TABLE t ALTER INDEX kj VISIBLE; +explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); +id estRows task access object operator info +IndexMerge 10.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t; +create table t(j json, index kj((cast(j as signed array)))); +insert into t values ('[1]'); +insert into t values ('[1, 2]'); +insert into t values ('[]'); +insert into t values (NULL); +select /*+ use_index_merge(t, kj) */ count(*) from t; +count(*) +4 +select /*+ use_index_merge(t, kj) */ count(*) from t where (1 member of (j)); +count(*) +2 +select /*+ use_index_merge(t, kj) */ count(*) from t where json_contains((j), '[1]'); +count(*) +2 +select /*+ use_index_merge(t, kj) */ count(*) from t where json_overlaps((j), '[1]'); +count(*) +2 +select /*+ use_index(t, kj) */ count(*) from t; +Error 1815 (HY000): Internal : Can't find a proper physical plan for this query +drop table if exists t; +create table t(j json, index kj((cast(j as signed array)))); +insert into t values ('[1]'); +insert into t values ('[1, 2]'); +insert into t values ('[]'); +insert into t values (NULL); +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[]'); +j +[1, 2] +[1] +[] +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[]'); +j +[1, 2] +[1] +[] +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[1]'); +j +[1, 2] +[1] +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[1]'); +j +[1, 2] +[1] +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[1, 2]'); +j +[1, 2] +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[1, 2]'); +j +[1, 2] +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[1, 10]'); +j +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[1, 10]'); +j +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[]'); +j +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[]'); +j +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[1]'); +j +[1, 2] +[1] +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[1]'); +j +[1, 2] +[1] +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[1, 2]'); +j +[1, 2] +[1] +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[1, 2]'); +j +[1, 2] +[1] +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[1, 10]'); +j +[1, 2] +[1] +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[1, 10]'); +j +[1, 2] +[1] +drop table if exists t; +create table t( +a int, j0 json, j1 json, +index j0_0((cast(j0->'$.path0' as signed array)))); +insert into t values(1, '{"path0" : [1,2,3]}', null ); +select /*+ no_index_merge() */ a from t where (1 member of (j0->'$.path0')); +a +1 +select /*+ no_index_merge() */ a from t where ('1' member of (j0->'$.path0')); +a +select /*+ use_index_merge(t, j0_0) */ a from t where (1 member of (j0->'$.path0')); +a +1 +select /*+ use_index_merge(t, j0_0) */ a from t where ('1' member of (j0->'$.path0')); +a diff --git a/tests/integrationtest/r/planner/core/integration.result b/tests/integrationtest/r/planner/core/integration.result new file mode 100644 index 0000000000..4240b73220 --- /dev/null +++ b/tests/integrationtest/r/planner/core/integration.result @@ -0,0 +1,3969 @@ +set tidb_cost_model_version=2; +drop table if exists t; +create table t(a varchar(10), b int, c int); +show columns from t where true; +Field Type Null Key Default Extra +a varchar(10) YES NULL +b int(11) YES NULL +c int(11) YES NULL +show columns from t where field = 'b'; +Field Type Null Key Default Extra +b int(11) YES NULL +show columns from t where field in (select 'b'); +Field Type Null Key Default Extra +b int(11) YES NULL +show columns from t where field in (select 'b') and true; +Field Type Null Key Default Extra +b int(11) YES NULL +show columns from t where field in (select 'b') and false; +Field Type Null Key Default Extra +insert into t values('c', 0, 0); +show columns from t where field < all (select a from t); +Field Type Null Key Default Extra +b int(11) YES NULL +a varchar(10) YES NULL +insert into t values('b', 0, 0); +show columns from t where field < all (select a from t); +Field Type Null Key Default Extra +a varchar(10) YES NULL +drop table if exists t; +create table t(a int, b int); +insert into t values(1,10),(2,20); +select t1.* from t t0 cross join (t t1 join t t2 on 100=t0.a); +Error 1054 (42S22): Unknown column 't0.a' in 'on clause' +drop table if exists t; +create table t(c1 int, c2 varchar(255)); +insert into t values(1,'a'),(2,'d'),(3,'c'); +select t01.c1,t01.c2,t01.c3 from (select t1.*,@c3:=@c3+1 as c3 from (select t.*,@c3:=0 from t order by t.c1)t1)t01 where t01.c3=1 and t01.c2='d'; +c1 c2 c3 +select t01.c1,t01.c2,t01.c3 from (select t1.*,@c3:=@c3+1 as c3 from (select t.*,@c3:=0 from t order by t.c1)t1)t01 where t01.c3=2 and t01.c2='d'; +c1 c2 c3 +2 d 2 +drop table if exists bit_col_t; +create table bit_col_t (a bit(64)); +drop table bit_col_t; +create table bit_col_t (a bit(1)); +drop table bit_col_t; +create table bit_col_t (a bit(0)); +Error 3013 (HY000): Invalid size for column 'a'. +create table bit_col_t (a bit(65)); +Error 1439 (42000): Display width out of range for column 'a' (max = 64) +set tidb_cost_model_version=2; +drop table if exists customer; +create table customer (C_CUSTKEY bigint(20) NOT NULL, C_NAME varchar(25) NOT NULL, C_ADDRESS varchar(25) NOT NULL, PRIMARY KEY (`C_CUSTKEY`) /*T![clustered_index] CLUSTERED */); +drop table if exists orders; +create table orders (O_ORDERKEY bigint(20) NOT NULL, O_CUSTKEY bigint(20) NOT NULL, O_TOTALPRICE decimal(15,2) NOT NULL, PRIMARY KEY (`O_ORDERKEY`) /*T![clustered_index] CLUSTERED */); +insert into customer values (6, "xiao zhang", "address1"); +set @@tidb_opt_agg_push_down=1; +select c_custkey, count(o_orderkey) as c_count from customer left outer join orders on c_custkey = o_custkey group by c_custkey; +c_custkey c_count +6 0 +explain format='brief' select c_custkey, count(o_orderkey) as c_count from customer left outer join orders on c_custkey = o_custkey group by c_custkey; +id estRows task access object operator info +Projection 8000.00 root planner__core__integration.customer.c_custkey, Column#7 +└─HashAgg 8000.00 root group by:planner__core__integration.customer.c_custkey, funcs:count(Column#8)->Column#7, funcs:firstrow(planner__core__integration.customer.c_custkey)->planner__core__integration.customer.c_custkey + └─HashJoin 10000.00 root left outer join, equal:[eq(planner__core__integration.customer.c_custkey, planner__core__integration.orders.o_custkey)] + ├─HashAgg(Build) 8000.00 root group by:planner__core__integration.orders.o_custkey, funcs:count(Column#9)->Column#8, funcs:firstrow(planner__core__integration.orders.o_custkey)->planner__core__integration.orders.o_custkey + │ └─TableReader 8000.00 root data:HashAgg + │ └─HashAgg 8000.00 cop[tikv] group by:planner__core__integration.orders.o_custkey, funcs:count(planner__core__integration.orders.o_orderkey)->Column#9 + │ └─TableFullScan 10000.00 cop[tikv] table:orders keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:customer keep order:false, stats:pseudo +select c_custkey, count(o_orderkey) as c_count from orders right outer join customer on c_custkey = o_custkey group by c_custkey; +c_custkey c_count +6 0 +explain format='brief' select c_custkey, count(o_orderkey) as c_count from orders right outer join customer on c_custkey = o_custkey group by c_custkey; +id estRows task access object operator info +Projection 8000.00 root planner__core__integration.customer.c_custkey, Column#7 +└─HashAgg 8000.00 root group by:planner__core__integration.customer.c_custkey, funcs:count(Column#8)->Column#7, funcs:firstrow(planner__core__integration.customer.c_custkey)->planner__core__integration.customer.c_custkey + └─HashJoin 10000.00 root right outer join, equal:[eq(planner__core__integration.orders.o_custkey, planner__core__integration.customer.c_custkey)] + ├─HashAgg(Build) 8000.00 root group by:planner__core__integration.orders.o_custkey, funcs:count(Column#9)->Column#8, funcs:firstrow(planner__core__integration.orders.o_custkey)->planner__core__integration.orders.o_custkey + │ └─TableReader 8000.00 root data:HashAgg + │ └─HashAgg 8000.00 cop[tikv] group by:planner__core__integration.orders.o_custkey, funcs:count(planner__core__integration.orders.o_orderkey)->Column#9 + │ └─TableFullScan 10000.00 cop[tikv] table:orders keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:customer keep order:false, stats:pseudo +drop table if exists t; +create table t(a int, b int); +select * from t where 0 and c = 10; +Error 1054 (42S22): Unknown column 'c' in 'where clause' +create view v as select 1 as b; +drop table if exists t; +create table t (a int); +update v, t set a=2; +update v, t set b=2; +Error 1288 (HY000): The target table v of the UPDATE is not updatable +create database db1; +use db1; +update planner__core__integration.t, (select 1 as a) as t set planner__core__integration.t.a=1; +update (select 1 as a) as t, planner__core__integration.t set planner__core__integration.t.a=1; +drop table if exists t; +drop table if exists t1; +create table t(a int); +create table t1(b int); +update (select 1 as a) as t set a=1; +Error 1288 (HY000): The target table t of the UPDATE is not updatable +update (select 1 as a) as t, t1 set a=1; +Error 1288 (HY000): The target table t of the UPDATE is not updatable +drop table if exists t; +drop table if exists t1; +create table t(a int default -1, c int as (a+10) stored); +insert into t(a) values(1); +update planner__core__integration.t, (select 1 as b) as t set planner__core__integration.t.a=default; +select * from t; +a c +1 11 +drop table if exists t; +drop table if exists t1; +create table t (c int); +select group_concat((select concat(c,group_concat(c)) FROM t where xxx=xxx)) FROM t; +Error 1054 (42S22): Unknown column 'xxx' in 'where clause' +drop table if exists t1; +drop view if exists v1; +CREATE TABLE t1(c0 INT UNIQUE); +CREATE definer='root'@'localhost' VIEW v1(c0) AS SELECT 1 FROM t1; +SELECT v1.c0 FROM v1 WHERE (true)LIKE(v1.c0); +c0 +SELECT v2.c0 FROM (select 1 as c0 from t1) v2 WHERE (v2.c0)like(True); +c0 +drop table if exists t3; +CREATE TABLE t3(c0 INT, primary key(c0)); +SELECT v2.c0 FROM (select 1 as c0 from t3) v2 WHERE (v2.c0)like(True); +c0 +drop table if exists t1, t2; +create table t1(x int not null); +create table t2(x int); +insert into t2 values (1); +select IFNULL((select t1.x from t1 where t1.x = t2.x), 'xxx') as col1 from t2; +col1 +xxx +select ifnull(t1.x, 'xxx') from t2 left join t1 using(x); +ifnull(t1.x, 'xxx') +xxx +select ifnull(t1.x, 'xxx') from t2 natural left join t1; +ifnull(t1.x, 'xxx') +xxx +drop table if exists t1, t2; +create table t1(a int not null, b int not null); +insert into t1 values (1,1); +create table t2(a int not null, b int not null); +insert into t2 values (2,2); +select * from t1 where t1.a not in (select a from t2 where t2.a = t1.a and t2.a > 1); +a b +1 1 +select * from t1 where t1.a not in (select a from t2 where t2.b = t1.b and t2.a > 1); +a b +1 1 +select * from t1 where t1.a not in (select a from t2 where t2.b = t1.b and t2.b > 1); +a b +1 1 +select q.a in (select count(*) from t1 s where not exists (select 1 from t1 p where q.a > 1 and p.a = s.a)) from t1 q; +q.a in (select count(*) from t1 s where not exists (select 1 from t1 p where q.a > 1 and p.a = s.a)) +1 +select q.a in (select not exists (select 1 from t1 p where q.a > 1 and p.a = s.a) from t1 s) from t1 q; +q.a in (select not exists (select 1 from t1 p where q.a > 1 and p.a = s.a) from t1 s) +1 +drop table t1, t2; +create table t1(a int not null, b int); +insert into t1 values (1,null); +create table t2(a int not null, b int); +insert into t2 values (2,2); +select * from t1 where t1.a not in (select a from t2 where t2.b > t1.b); +a b +1 NULL +select * from t1 where t1.a not in (select a from t2 where t1.a = 2); +a b +1 NULL +create database test_new_collation; +use test_new_collation; +set @@tidb_partition_prune_mode = 'dynamic'; +CREATE TABLE thash (a int, c varchar(20) charset utf8mb4 collate utf8mb4_general_ci, key(a)) partition by hash(a) partitions 4; +CREATE TABLE trange (a int, c varchar(20) charset utf8mb4 collate utf8mb4_general_ci, key(a)) partition by range(a) ( +partition p0 values less than (10), +partition p1 values less than (20), +partition p2 values less than (30), +partition p3 values less than (40)); +insert into thash values (1, 'a'), (1, 'A'), (11, 'a'), (11, 'A'), (21, 'a'), (21, 'A'), (31, 'a'), (31, 'A'); +insert into trange values (1, 'a'), (1, 'A'), (11, 'a'), (11, 'A'), (21, 'a'), (21, 'A'), (31, 'a'), (31, 'A'); +select * from thash use index(a) where a in (1, 11, 31) and c='a'; +a c +1 A +1 a +11 A +11 a +31 A +31 a +select * from thash ignore index(a) where a in (1, 11, 31) and c='a'; +a c +1 A +1 a +11 A +11 a +31 A +31 a +select * from trange use index(a) where a in (1, 11, 31) and c='a'; +a c +1 A +1 a +11 A +11 a +31 A +31 a +select * from trange ignore index(a) where a in (1, 11, 31) and c='a'; +a c +1 A +1 a +11 A +11 a +31 A +31 a +create table strrange(a varchar(10) charset utf8mb4 collate utf8mb4_general_ci, b int) partition by range columns(a) ( +partition p0 values less than ('a'), +partition p1 values less than ('k'), +partition p2 values less than ('z')); +insert into strrange values ('a', 1), ('A', 1), ('y', 1), ('Y', 1), ('q', 1); +select * from strrange where a in ('a', 'y'); +a b +A 1 +Y 1 +a 1 +y 1 +create table strlist(a varchar(10) charset utf8mb4 collate utf8mb4_general_ci, b int) partition by list columns (a) ( +partition p0 values in ('a', 'b'), +partition p1 values in ('c', 'd'), +partition p2 values in ('e', 'f')); +insert into strlist values ('a', 1), ('A', 1), ('d', 1), ('D', 1), ('e', 1); +select * from strlist where a='a'; +a b +A 1 +a 1 +select * from strlist where a in ('D', 'e'); +a b +D 1 +d 1 +e 1 +use planner__core__integration; +drop table if exists t; +create table t(a int, b int, index idx_a(a), index idx_b(b)); +select * from t where a > 1 and a < 10 order by b; +a b +select @@last_plan_from_binding; +@@last_plan_from_binding +0 +create session binding for select * from t where a > 1 and a < 10 order by b using select /*+ use_index(t, idx_a) */ * from t where a > 1 and a < 10 order by b; +select * from t where a > 1 and a < 10 order by b; +a b +select @@last_plan_from_binding; +@@last_plan_from_binding +0 +select /*+ use_index(t, idx_b) */ * from t where a > 1 and a < 10 order by b; +a b +select @@last_plan_from_binding; +@@last_plan_from_binding +0 +select /*+ use_index(t, idx_b) */ * from t where a > 1 and a < 10 order by b; +a b +Level Code Message +Warning 1105 The system ignores the hints in the current query and uses the hints specified in the bindSQL: SELECT /*+ use_index(`t` `idx_a`)*/ * FROM `planner__core__integration`.`t` WHERE `a` > 1 AND `a` < 10 ORDER BY `b` +drop table if exists t; +create table t(a int, b int, index idx_a(a), index idx_b(b)); +set @@tidb_opt_advanced_join_hint=0; +select /*+ hash_join(t1) merge_join(t2) */ * from t t1 join t t2 join t t3 where t1.a = t2.a and t2.a=t3.a; +a b a b a b +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +set @@tidb_opt_advanced_join_hint=1; +select /*+ hash_join(t1) merge_join(t2) */ * from t t1 join t t2 join t t3 where t1.a = t2.a and t2.a=t3.a; +a b a b a b +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +set @@tidb_opt_advanced_join_hint=DEFAULT; +drop table if exists t1, t2; +create table t1(a int not null, b int, key(a)); +insert into t1 values(1,1),(2,2); +create table t2(a int not null, b int, key(a)); +insert into t2 values(1,1),(2,2),(3,3),(4,4),(5,5); +analyze table t1, t2; +explain format = 'brief' select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a = t2.a; +id estRows task access object operator info +IndexJoin 2.00 root inner join, inner:IndexLookUp, outer key:planner__core__integration.t2.a, inner key:planner__core__integration.t1.a, equal cond:eq(planner__core__integration.t2.a, planner__core__integration.t1.a) +├─TableReader(Build) 5.00 root data:TableFullScan +│ └─TableFullScan 5.00 cop[tikv] table:t2 keep order:false +└─IndexLookUp(Probe) 2.00 root + ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t1, index:a(a) range: decided by [eq(planner__core__integration.t1.a, planner__core__integration.t2.a)], keep order:false + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t1 keep order:false +drop table if exists t0,t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 BOOL, c1 BOOL); +INSERT INTO t1 VALUES (false, true); +INSERT INTO t1 VALUES (true, true); +CREATE definer='root'@'localhost' VIEW v0(c0, c1, c2) AS SELECT t1.c0, LOG10(t0.c0), t1.c0 FROM t0, t1; +INSERT INTO t0(c0) VALUES (3); +SELECT /*+ MERGE_JOIN(t1, t0, v0)*/v0.c2, t1.c0 FROM v0, t0 CROSS JOIN t1 ORDER BY -v0.c1; +c2 c0 +1 0 +0 0 +1 1 +0 1 +drop table if exists t; +create table t(a int, b int, unique index i_a (a) invisible, unique index i_b(b)); +insert into t values (1,2); +admin check table t; + +select a from t order by a; +a +1 +explain select a from t order by a; +id estRows task access object operator info +Sort_4 10000.00 root planner__core__integration.t.a +└─TableReader_8 10000.00 root data:TableFullScan_7 + └─TableFullScan_7 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +select a from t where a > 0; +a +1 +explain select a from t where a > 1; +id estRows task access object operator info +TableReader_7 3333.33 root data:Selection_6 +└─Selection_6 3333.33 cop[tikv] gt(planner__core__integration.t.a, 1) + └─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +select * from t use index(i_a); +Error 1176 (42000): Key 'i_a' doesn't exist in table 't' +select * from t force index(i_a); +Error 1176 (42000): Key 'i_a' doesn't exist in table 't' +select * from t ignore index(i_a); +Error 1176 (42000): Key 'i_a' doesn't exist in table 't' +select /*+ USE_INDEX(t, i_a) */ * from t; +a b +1 2 +Level Code Message +Warning 1176 Key 'i_a' doesn't exist in table 't' +select /*+ IGNORE_INDEX(t, i_a), USE_INDEX(t, i_b) */ a from t order by a; +a +1 +Level Code Message +Warning 1176 Key 'i_a' doesn't exist in table 't' +select /*+ FORCE_INDEX(t, i_a), USE_INDEX(t, i_b) */ a from t order by a; +a +1 +Level Code Message +Warning 1176 Key 'i_a' doesn't exist in table 't' +select /*+ FORCE_INDEX(aaa) */ * from t; +a b +1 2 +Level Code Message +Warning 1815 force_index(planner__core__integration.aaa) is inapplicable, check whether the table(planner__core__integration.aaa) exists +admin check table t; + +admin check index t i_a; + +select max(t.col) from (select 'a' as col union all select '' as col) as t; +max(t.col) +a +drop table if exists t; +create table t(a int); +explain format='verbose' select /*+ stream_agg() */ count(*) from t; +id estRows estCost task access object operator info +StreamAgg_14 1.00 168985.35 root funcs:count(Column#4)->Column#3 +└─TableReader_15 1.00 168935.45 root data:StreamAgg_8 + └─StreamAgg_8 1.00 2534000.00 cop[tikv] funcs:count(1)->Column#4 + └─TableFullScan_13 10000.00 2035000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format='verbose' select /*+ hash_agg() */ count(*) from t; +id estRows estCost task access object operator info +HashAgg_9 1.00 150603.19 root funcs:count(Column#4)->Column#3 +└─TableReader_10 1.00 149075.93 root data:HashAgg_5 + └─HashAgg_5 1.00 2236107.30 cop[tikv] funcs:count(1)->Column#4 + └─TableFullScan_8 10000.00 2035000.00 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t, pt, vt; +create table t(a int, b int); +insert into t values(1, 1); +create table pt(a int primary key, b int) partition by range(a) (PARTITION `p0` VALUES LESS THAN (10), PARTITION `p1` VALUES LESS THAN (20), PARTITION `p2` VALUES LESS THAN (30)); +insert into pt values(1, 1), (11, 11), (21, 21); +create definer='root'@'localhost' view vt(a, b) as select a, b from t; +select * from pt, vt where pt.a = vt.a; +a b a b +1 1 1 1 +drop table if exists t; +create table t(a int(11), b int) partition by range (a) (partition p0 values less than (3), partition p1 values less than maxvalue); +insert into t values(1, 1), (2, 1), (3, 1), (4, 2), (4, 2); +set session tidb_opt_agg_push_down=1; +set @@tidb_partition_prune_mode='static'; +explain format = 'brief' select approx_count_distinct(a), b from t group by b order by b desc; +id estRows task access object operator info +Sort 16000.00 root planner__core__integration.t.b:desc +└─HashAgg 16000.00 root group by:planner__core__integration.t.b, funcs:approx_count_distinct(Column#5)->Column#4, funcs:firstrow(Column#6)->planner__core__integration.t.b + └─PartitionUnion 16000.00 root + ├─HashAgg 8000.00 root group by:planner__core__integration.t.b, funcs:approx_count_distinct(planner__core__integration.t.a)->Column#5, funcs:firstrow(planner__core__integration.t.b)->Column#6, funcs:firstrow(planner__core__integration.t.b)->planner__core__integration.t.b + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t, partition:p0 keep order:false, stats:pseudo + └─HashAgg 8000.00 root group by:planner__core__integration.t.b, funcs:approx_count_distinct(planner__core__integration.t.a)->Column#5, funcs:firstrow(planner__core__integration.t.b)->Column#6, funcs:firstrow(planner__core__integration.t.b)->planner__core__integration.t.b + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t, partition:p1 keep order:false, stats:pseudo +select approx_count_distinct(a), b from t group by b order by b desc; +approx_count_distinct(a) b +1 2 +3 1 +drop table if exists hash_partition_overflow; +create table hash_partition_overflow (c0 bigint unsigned) partition by hash(c0) partitions 3; +insert into hash_partition_overflow values (9223372036854775808); +select * from hash_partition_overflow where c0 = 9223372036854775808; +c0 +9223372036854775808 +select * from hash_partition_overflow where c0 in (1, 9223372036854775808); +c0 +9223372036854775808 +drop table if exists t0, t1; +create table t0(c0 int primary key); +create table t1(c0 int primary key); +CREATE INDEX i0 ON t0(c0); +CREATE INDEX i0 ON t1(c0); +select /*+ MERGE_JOIN(t0, t1) */ * from t0, t1 where t0.c0 = t1.c0; +c0 c0 +drop table if exists PK_MULTI_COL_5177; +CREATE TABLE PK_MULTI_COL_5177 ( +COL1 binary(10) NOT NULL, +COL2 varbinary(10) NOT NULL, +COL3 smallint(45) NOT NULL, +PRIMARY KEY (COL1(5),COL2,COL3), +UNIQUE KEY UIDXM (COL1(5),COL2), +UNIQUE KEY UIDX (COL2), +KEY IDX3 (COL3), +KEY IDXM (COL3,COL2)); +insert into PK_MULTI_COL_5177(col1, col2, col3) values(0x00000000000000000000, 0x002B200DF5BA03E59F82, 1); +select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 in (0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82); +col1 col2 + + 埂 +select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 = 0x002B200DF5BA03E59F82; +col1 col2 + + 埂 +drop table if exists t; +create table t(a int, b int); +select count(a) as b from t group by a order by b; +b +select count(a) as cnt from t group by a order by b; +Error 1055 (42000): Expression #1 of ORDER BY is not in GROUP BY clause and contains nonaggregated column '' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by +drop table if exists t; +create table t(a int primary key); +select * from t t1, (select a from t order by a+1) t2 where t1.a = t2.a; +a a +drop table if exists t0, t1; +CREATE TABLE t0(t0 INT UNIQUE); +CREATE TABLE t1(c0 FLOAT); +INSERT INTO t1(c0) VALUES (0); +INSERT INTO t0(t0) VALUES (NULL), (NULL); +SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1; +c0 +0 +0 +drop table if exists t0, t1; +CREATE TABLE t0(t0 INT); +CREATE TABLE t1(c0 FLOAT); +INSERT INTO t1(c0) VALUES (0); +INSERT INTO t0(t0) VALUES (NULL), (NULL); +SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1; +c0 +0 +0 +drop table if exists t0, t1; +CREATE TABLE t0(t0 INT); +CREATE TABLE t1(c0 FLOAT); +create unique index idx on t0(t0); +INSERT INTO t1(c0) VALUES (0); +INSERT INTO t0(t0) VALUES (NULL), (NULL); +SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1; +c0 +0 +0 +drop table if exists floor_unix_timestamp; +create table floor_unix_timestamp (ts timestamp(3)) +partition by range (floor(unix_timestamp(ts))) ( +partition p0 values less than (unix_timestamp('2020-04-05 00:00:00')), +partition p1 values less than (unix_timestamp('2020-04-12 00:00:00')), +partition p2 values less than (unix_timestamp('2020-04-15 00:00:00'))); +insert into floor_unix_timestamp values ('2020-04-04 00:00:00'); +insert into floor_unix_timestamp values ('2020-04-04 23:59:59.999'); +insert into floor_unix_timestamp values ('2020-04-05 00:00:00'); +insert into floor_unix_timestamp values ('2020-04-05 00:00:00.001'); +insert into floor_unix_timestamp values ('2020-04-12 01:02:03.456'); +insert into floor_unix_timestamp values ('2020-04-14 00:00:42'); +select count(*) from floor_unix_timestamp where '2020-04-05 00:00:00.001' = ts; +count(*) +1 +select * from floor_unix_timestamp where ts > '2020-04-05 00:00:00' order by ts; +ts +2020-04-05 00:00:00.001 +2020-04-12 01:02:03.456 +2020-04-14 00:00:42.000 +select count(*) from floor_unix_timestamp where ts <= '2020-04-05 23:00:00'; +count(*) +4 +select * from floor_unix_timestamp partition(p1, p2) where ts > '2020-04-14 00:00:00'; +ts +2020-04-14 00:00:42.000 +drop table if exists t; +create table t(a int, b int, primary key(a)); +insert into t values(1, 1); +set session tidb_opt_agg_push_down = 0; +select avg(a) from (select * from t ta union all select * from t tb) t; +avg(a) +1.0000 +select avg(b) from (select * from t ta union all select * from t tb) t; +avg(b) +1.0000 +select count(distinct a) from (select * from t ta union all select * from t tb) t; +count(distinct a) +1 +select count(distinct b) from (select * from t ta union all select * from t tb) t; +count(distinct b) +1 +set session tidb_opt_agg_push_down = 1; +select avg(a) from (select * from t ta union all select * from t tb) t; +avg(a) +1.0000 +select avg(b) from (select * from t ta union all select * from t tb) t; +avg(b) +1.0000 +select count(distinct a) from (select * from t ta union all select * from t tb) t; +count(distinct a) +1 +select count(distinct b) from (select * from t ta union all select * from t tb) t; +count(distinct b) +1 +drop table if exists t1, t2; +create table t1 (a int, b int) partition by range(a) (partition p0 values less than(10), partition p1 values less than MAXVALUE); +create table t2 (a int, b int); +select /*+ MERGE_JOIN(t1, t2) */ * from t1 partition (p0), t2 where t1.a > 100 and t1.a = t2.a; +a b a b +drop table if exists t; +create table t(a int,b int,c int,d int,e int,unique key idx_ab(a,b),unique key(c),unique key(d)); +explain format = 'brief' select /*+ use_index_merge(t,c,idx_ab) */ * from t where a = 1 or (e = 1 and c = 1); +id estRows task access object operator info +IndexMerge 0.01 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx_ab(a, b) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:c(c) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] or(eq(planner__core__integration.t.a, 1), and(eq(planner__core__integration.t.e, 1), eq(planner__core__integration.t.c, 1))) + └─TableRowIDScan 11.00 cop[tikv] table:t keep order:false, stats:pseudo +insert into t values (2, 1, 1, 1, 2); +select /*+ use_index_merge(t,c,idx_ab) */ * from t where a = 1 or (e = 1 and c = 1); +a b c d e +drop table if exists t; +create table t (a int, b int, c int, primary key (a, b) clustered, key idx_c(c)); +insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100); +explain select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 5548.89 root planner__core__integration.t.a +└─Sort_7 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 5548.89 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5548.89 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by a, b; +a +1 +explain select /*+ use_index_merge(t) */ a from t where a < 2 or a > 88 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 7771.11 root planner__core__integration.t.a +└─Sort_7 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_13 7771.11 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:(88,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.11 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or a > 88 or c > 10000 order by a, b; +a +1 +100 +explain select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8015.79 root planner__core__integration.t.a +└─Sort_7 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_16 7119.80 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_15(Probe) 7119.80 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1))) + └─TableRowIDScan_14 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8235.60 root planner__core__integration.t.a +└─Sort_7 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_18 7315.03 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─TableRangeScan_12 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_17(Probe) 7315.03 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(and(ge(planner__core__integration.t.a, 20), lt(planner__core__integration.t.b, 10)), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1)))) + └─TableRowIDScan_16 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 5548.89 root planner__core__integration.t.b +└─Sort_7 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 5548.89 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5548.89 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by a, b; +b +1 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or a > 88 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 7771.11 root planner__core__integration.t.b +└─Sort_7 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_13 7771.11 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:(88,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.11 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or a > 88 or c > 10000 order by a, b; +b +1 +100 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8015.79 root planner__core__integration.t.b +└─Sort_7 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_16 7119.80 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_15(Probe) 7119.80 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1))) + └─TableRowIDScan_14 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8235.60 root planner__core__integration.t.b +└─Sort_7 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_18 7315.03 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─TableRangeScan_12 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_17(Probe) 7315.03 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(and(ge(planner__core__integration.t.a, 20), lt(planner__core__integration.t.b, 10)), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1)))) + └─TableRowIDScan_16 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 5548.89 root planner__core__integration.t.c +└─Sort_7 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 5548.89 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5548.89 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by a, b; +c +1 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or a > 88 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 7771.11 root planner__core__integration.t.c +└─Sort_7 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_13 7771.11 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:(88,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.11 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or a > 88 or c > 10000 order by a, b; +c +1 +100 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8015.79 root planner__core__integration.t.c +└─Sort_7 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_16 7119.80 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_15(Probe) 7119.80 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1))) + └─TableRowIDScan_14 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8235.60 root planner__core__integration.t.c +└─Sort_7 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_18 7315.03 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─TableRangeScan_12 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_17(Probe) 7315.03 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(and(ge(planner__core__integration.t.a, 20), lt(planner__core__integration.t.b, 10)), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1)))) + └─TableRowIDScan_16 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by a, b; +id estRows task access object operator info +Sort_5 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_11 5548.89 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 5548.89 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by a, b; +a b +1 1 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or a > 88 or c > 10000 order by a, b; +id estRows task access object operator info +Sort_5 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 7771.11 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:(88,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 7771.11 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or a > 88 or c > 10000 order by a, b; +a b +1 1 +100 100 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Sort_5 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_15 7119.80 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_9 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_14(Probe) 7119.80 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1))) + └─TableRowIDScan_13 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Sort_5 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_17 7315.03 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_9 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_12(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─TableRangeScan_11 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_16(Probe) 7315.03 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(and(ge(planner__core__integration.t.a, 20), lt(planner__core__integration.t.b, 10)), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1)))) + └─TableRowIDScan_15 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 5548.89 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 5548.89 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5548.89 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by a, b; +b c +1 1 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 7771.11 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_13 7771.11 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:(88,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.11 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +b c +1 1 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8015.79 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_16 7119.80 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_15(Probe) 7119.80 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1))) + └─TableRowIDScan_14 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8235.60 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_18 7315.03 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─TableRangeScan_12 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_17(Probe) 7315.03 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(and(ge(planner__core__integration.t.a, 20), lt(planner__core__integration.t.b, 10)), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1)))) + └─TableRowIDScan_16 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 5548.89 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 5548.89 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5548.89 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by a, b; +c a +1 1 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or a > 88 or c > 10000 order by a, b; +id estRows task access object operator info +Projection_6 7771.11 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_13 7771.11 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:(88,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.11 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or a > 88 or c > 10000 order by a, b; +c a +1 1 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8015.79 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_16 7119.80 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_15(Probe) 7119.80 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1))) + └─TableRowIDScan_14 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Projection_6 8235.60 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_18 7315.03 root type: union + ├─TableRangeScan_9(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_10 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─TableRangeScan_12 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_17(Probe) 7315.03 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(and(ge(planner__core__integration.t.a, 20), lt(planner__core__integration.t.b, 10)), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1)))) + └─TableRowIDScan_16 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by a, b; +id estRows task access object operator info +Sort_5 5548.89 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 5548.89 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_11 5548.89 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 5548.89 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by a, b; +b a c +1 1 1 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +id estRows task access object operator info +Sort_5 7771.11 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 7771.11 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_12 7771.11 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:(88,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 7771.11 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +b a c +1 1 1 +100 100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Sort_5 8015.79 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 8015.79 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_15 7119.80 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_9 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_14(Probe) 7119.80 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1))) + └─TableRowIDScan_13 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +b a c +1 1 1 +10 10 10 +100 100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +id estRows task access object operator info +Sort_5 8235.60 root planner__core__integration.t.a, planner__core__integration.t.b +└─Projection_7 8235.60 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_17 7315.03 root type: union + ├─TableRangeScan_8(Build) 3323.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─TableRangeScan_9 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_12(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─TableRangeScan_11 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─Selection_16(Probe) 7315.03 cop[tikv] or(or(lt(planner__core__integration.t.a, 2), and(ge(planner__core__integration.t.a, 10), ge(planner__core__integration.t.b, 10))), or(and(ge(planner__core__integration.t.a, 20), lt(planner__core__integration.t.b, 10)), or(gt(planner__core__integration.t.c, 100), lt(planner__core__integration.t.c, 1)))) + └─TableRowIDScan_15 8882.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +b a c +1 1 1 +10 10 10 +100 100 100 +drop table if exists t; +create table t (a int, b int, c int, unique key (a, b), key idx_c(c)); +insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100); +explain select /*+ use_index_merge(t) */ a from t where c < 10 or a < 2 order by a; +id estRows task access object operator info +Sort_5 5542.21 root planner__core__integration.t.a +└─Projection_7 5542.21 root planner__core__integration.t.a + └─IndexMerge_11 5542.21 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:a(a, b) range:[-inf,2), keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 5542.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where c < 10 or a < 2 order by a; +a +1 +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or c > 10000 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_11 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or c > 10000 order by a; +a +1 +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_12 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_14 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_16 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_12(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_11 3333.33 cop[tikv] table:t, index:a(a, b) range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where c < 10 or a < 2 order by a; +id estRows task access object operator info +Projection_6 5542.21 root planner__core__integration.t.b +└─Sort_7 5542.21 root planner__core__integration.t.a + └─IndexMerge_12 5542.21 root type: union + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3323.33 cop[tikv] table:t, index:a(a, b) range:[-inf,2), keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5542.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where c < 10 or a < 2 order by a; +b +1 +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or c > 10000 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_12 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or c > 10000 order by a; +b +1 +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_13 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_15 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_10 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_17 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_10 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_12 3333.33 cop[tikv] table:t, index:a(a, b) range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_16(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where c < 10 or a < 2 order by a; +id estRows task access object operator info +Projection_6 5542.21 root planner__core__integration.t.c +└─Sort_7 5542.21 root planner__core__integration.t.a + └─IndexMerge_12 5542.21 root type: union + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3323.33 cop[tikv] table:t, index:a(a, b) range:[-inf,2), keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5542.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where c < 10 or a < 2 order by a; +c +1 +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or c > 10000 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_12 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or c > 10000 order by a; +c +1 +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_13 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_15 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_10 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_17 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_10 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_12 3333.33 cop[tikv] table:t, index:a(a, b) range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_16(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ a,b from t where c < 10 or a < 2 order by a; +id estRows task access object operator info +Sort_5 5542.21 root planner__core__integration.t.a +└─Projection_7 5542.21 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_11 5542.21 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:a(a, b) range:[-inf,2), keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 5542.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where c < 10 or a < 2 order by a; +a b +1 1 +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or c > 10000 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_11 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or c > 10000 order by a; +a b +1 1 +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_14 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_16 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_12(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_11 3333.33 cop[tikv] table:t, index:a(a, b) range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where c < 10 or a < 2 order by a; +id estRows task access object operator info +Projection_6 5542.21 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 5542.21 root planner__core__integration.t.a + └─IndexMerge_12 5542.21 root type: union + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3323.33 cop[tikv] table:t, index:a(a, b) range:[-inf,2), keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 5542.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where c < 10 or a < 2 order by a; +b c +1 1 +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or c > 10000 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_12 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or c > 10000 order by a; +b c +1 1 +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_13 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_15 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_10 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Projection_6 8000.00 root planner__core__integration.t.b, planner__core__integration.t.c +└─Sort_7 8000.00 root planner__core__integration.t.a + └─IndexMerge_17 8000.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_11(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_10 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_13(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_12 3333.33 cop[tikv] table:t, index:a(a, b) range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_15(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_16(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where c < 10 or a < 2 order by a; +id estRows task access object operator info +Sort_5 5542.21 root planner__core__integration.t.a +└─Projection_7 5542.21 root planner__core__integration.t.c, planner__core__integration.t.a + └─IndexMerge_11 5542.21 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:a(a, b) range:[-inf,2), keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 5542.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where c < 10 or a < 2 order by a; +c a +1 1 +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or c > 10000 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.c, planner__core__integration.t.a + └─IndexMerge_11 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or c > 10000 order by a; +c a +1 1 +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.c, planner__core__integration.t.a + └─IndexMerge_12 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.c, planner__core__integration.t.a + └─IndexMerge_14 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.c, planner__core__integration.t.a + └─IndexMerge_16 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_12(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_11 3333.33 cop[tikv] table:t, index:a(a, b) range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where c < 10 or a < 2 order by a; +id estRows task access object operator info +Sort_5 5542.21 root planner__core__integration.t.a +└─Projection_7 5542.21 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_11 5542.21 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:a(a, b) range:[-inf,2), keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 5542.21 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where c < 10 or a < 2 order by a; +b a c +1 1 1 +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or c > 10000 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_11 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or c > 10000 order by a; +b a c +1 1 1 +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_12 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +b a c +1 1 1 +10 10 10 +100 100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_14 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +b a c +1 1 1 +10 10 10 +100 100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +id estRows task access object operator info +Sort_5 8000.00 root planner__core__integration.t.a +└─Projection_7 8000.00 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_16 8000.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─Selection_10(Build) 1111.11 cop[tikv] ge(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_9 3333.33 cop[tikv] table:t, index:a(a, b) range:[10,+inf], keep order:false, stats:pseudo + ├─Selection_12(Build) 1107.78 cop[tikv] lt(planner__core__integration.t.b, 10) + │ └─IndexRangeScan_11 3333.33 cop[tikv] table:t, index:a(a, b) range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_15(Probe) 8000.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +b a c +1 1 1 +10 10 10 +100 100 100 +drop table if exists t; +create table t (a int, b int, c int, primary key (a), unique key (b), key idx_c(c)); +insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100); +explain select /*+ use_index_merge(t) */ a from t where b < 10 or c < 11 or c > 50 order by b; +id estRows task access object operator info +Projection_6 7767.77 root planner__core__integration.t.a +└─Sort_7 7767.77 root planner__core__integration.t.b + └─IndexMerge_13 7767.77 root type: union + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,11), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(50,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7767.77 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where b < 10 or c < 11 or c > 50 order by b; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by b; +id estRows task access object operator info +Projection_6 3334.67 root planner__core__integration.t.a +└─Sort_7 3334.67 root planner__core__integration.t.b + └─IndexMerge_12 3334.67 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 3334.67 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by b; +a +1 +explain select /*+ use_index_merge(t) */ a from t where a < 2 or a < 10 or b > 11 order by b; +id estRows task access object operator info +Projection_6 3340.00 root planner__core__integration.t.a +└─Sort_7 3340.00 root planner__core__integration.t.b + └─IndexMerge_13 3340.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:b(b) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 3340.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or a < 10 or b > 11 order by b; +a +1 +100 +explain select /*+ use_index_merge(t) */ a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +id estRows task access object operator info +Projection_6 7771.56 root planner__core__integration.t.a +└─Sort_7 7771.56 root planner__core__integration.t.b + └─IndexMerge_14 7771.56 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:b(b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 7771.56 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +id estRows task access object operator info +Projection_6 7033.48 root planner__core__integration.t.a +└─Sort_7 7033.48 root planner__core__integration.t.b + └─IndexMerge_15 7033.48 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─TableRangeScan_11(Build) 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 7033.48 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +a +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where b < 10 or c < 11 or c > 50 order by b; +id estRows task access object operator info +Sort_5 7767.77 root planner__core__integration.t.b +└─Projection_7 7767.77 root planner__core__integration.t.b + └─IndexMerge_12 7767.77 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,11), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(50,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 7767.77 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where b < 10 or c < 11 or c > 50 order by b; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by b; +id estRows task access object operator info +Sort_5 3334.67 root planner__core__integration.t.b +└─Projection_7 3334.67 root planner__core__integration.t.b + └─IndexMerge_11 3334.67 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 3334.67 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by b; +b +1 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or a < 10 or b > 11 order by b; +id estRows task access object operator info +Sort_5 3340.00 root planner__core__integration.t.b +└─Projection_7 3340.00 root planner__core__integration.t.b + └─IndexMerge_12 3340.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:b(b) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 3340.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or a < 10 or b > 11 order by b; +b +1 +100 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +id estRows task access object operator info +Sort_5 7771.56 root planner__core__integration.t.b +└─Projection_7 7771.56 root planner__core__integration.t.b + └─IndexMerge_13 7771.56 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:b(b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.56 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +id estRows task access object operator info +Sort_5 7033.48 root planner__core__integration.t.b +└─Projection_7 7033.48 root planner__core__integration.t.b + └─IndexMerge_14 7033.48 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 7033.48 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +b +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where b < 10 or c < 11 or c > 50 order by b; +id estRows task access object operator info +Projection_6 7767.77 root planner__core__integration.t.c +└─Sort_7 7767.77 root planner__core__integration.t.b + └─IndexMerge_13 7767.77 root type: union + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,11), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(50,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7767.77 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where b < 10 or c < 11 or c > 50 order by b; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by b; +id estRows task access object operator info +Projection_6 3334.67 root planner__core__integration.t.c +└─Sort_7 3334.67 root planner__core__integration.t.b + └─IndexMerge_12 3334.67 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 3334.67 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by b; +c +1 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or a < 10 or b > 11 order by b; +id estRows task access object operator info +Projection_6 3340.00 root planner__core__integration.t.c +└─Sort_7 3340.00 root planner__core__integration.t.b + └─IndexMerge_13 3340.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:b(b) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 3340.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or a < 10 or b > 11 order by b; +c +1 +100 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +id estRows task access object operator info +Projection_6 7771.56 root planner__core__integration.t.c +└─Sort_7 7771.56 root planner__core__integration.t.b + └─IndexMerge_14 7771.56 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:b(b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 7771.56 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +id estRows task access object operator info +Projection_6 7033.48 root planner__core__integration.t.c +└─Sort_7 7033.48 root planner__core__integration.t.b + └─IndexMerge_15 7033.48 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─TableRangeScan_11(Build) 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 7033.48 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +c +1 +10 +100 +explain select /*+ use_index_merge(t) */ a,b from t where b < 10 or c < 11 or c > 50 order by b; +id estRows task access object operator info +Sort_5 7767.77 root planner__core__integration.t.b +└─Projection_7 7767.77 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_12 7767.77 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,11), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(50,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 7767.77 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where b < 10 or c < 11 or c > 50 order by b; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by b; +id estRows task access object operator info +Sort_5 3334.67 root planner__core__integration.t.b +└─Projection_7 3334.67 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_11 3334.67 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 3334.67 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by b; +a b +1 1 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or a < 10 or b > 11 order by b; +id estRows task access object operator info +Sort_5 3340.00 root planner__core__integration.t.b +└─IndexMerge_12 3340.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:b(b) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 3340.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or a < 10 or b > 11 order by b; +a b +1 1 +100 100 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +id estRows task access object operator info +Sort_5 7771.56 root planner__core__integration.t.b +└─Projection_7 7771.56 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_13 7771.56 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:b(b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.56 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +id estRows task access object operator info +Sort_5 7033.48 root planner__core__integration.t.b +└─Projection_7 7033.48 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexMerge_14 7033.48 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 7033.48 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ a,b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +a b +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where b < 10 or c < 11 or c > 50 order by b; +id estRows task access object operator info +Sort_5 7767.77 root planner__core__integration.t.b +└─IndexMerge_12 7767.77 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,11), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(50,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 7767.77 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where b < 10 or c < 11 or c > 50 order by b; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by b; +id estRows task access object operator info +Sort_5 3334.67 root planner__core__integration.t.b +└─Projection_7 3334.67 root planner__core__integration.t.b, planner__core__integration.t.c + └─IndexMerge_11 3334.67 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 3334.67 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by b; +b c +1 1 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or a < 10 or b > 11 order by b; +id estRows task access object operator info +Sort_5 3340.00 root planner__core__integration.t.b +└─Projection_7 3340.00 root planner__core__integration.t.b, planner__core__integration.t.c + └─IndexMerge_12 3340.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:b(b) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 3340.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or a < 10 or b > 11 order by b; +b c +1 1 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +id estRows task access object operator info +Sort_5 7771.56 root planner__core__integration.t.b +└─Projection_7 7771.56 root planner__core__integration.t.b, planner__core__integration.t.c + └─IndexMerge_13 7771.56 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:b(b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.56 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +id estRows task access object operator info +Sort_5 7033.48 root planner__core__integration.t.b +└─Projection_7 7033.48 root planner__core__integration.t.b, planner__core__integration.t.c + └─IndexMerge_14 7033.48 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 7033.48 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +b c +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where b < 10 or c < 11 or c > 50 order by b; +id estRows task access object operator info +Projection_6 7767.77 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 7767.77 root planner__core__integration.t.b + └─IndexMerge_13 7767.77 root type: union + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,11), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(50,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7767.77 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where b < 10 or c < 11 or c > 50 order by b; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by b; +id estRows task access object operator info +Projection_6 3334.67 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 3334.67 root planner__core__integration.t.b + └─IndexMerge_12 3334.67 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 3334.67 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by b; +c a +1 1 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or a < 10 or b > 11 order by b; +id estRows task access object operator info +Projection_6 3340.00 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 3340.00 root planner__core__integration.t.b + └─IndexMerge_13 3340.00 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:b(b) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 3340.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or a < 10 or b > 11 order by b; +c a +1 1 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +id estRows task access object operator info +Projection_6 7771.56 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 7771.56 root planner__core__integration.t.b + └─IndexMerge_14 7771.56 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:b(b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 7771.56 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +id estRows task access object operator info +Projection_6 7033.48 root planner__core__integration.t.c, planner__core__integration.t.a +└─Sort_7 7033.48 root planner__core__integration.t.b + └─IndexMerge_15 7033.48 root type: union + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─TableRangeScan_11(Build) 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_13(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_14(Probe) 7033.48 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ c,a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +c a +1 1 +10 10 +100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where b < 10 or c < 11 or c > 50 order by b; +id estRows task access object operator info +Sort_5 7767.77 root planner__core__integration.t.b +└─Projection_7 7767.77 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_12 7767.77 root type: union + ├─IndexRangeScan_8(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,11), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(50,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 7767.77 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where b < 10 or c < 11 or c > 50 order by b; +b a c +1 1 1 +10 10 10 +100 100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by b; +id estRows task access object operator info +Sort_5 3334.67 root planner__core__integration.t.b +└─Projection_7 3334.67 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_11 3334.67 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(10000,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 3334.67 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by b; +b a c +1 1 1 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a < 10 or b > 11 order by b; +id estRows task access object operator info +Sort_5 3340.00 root planner__core__integration.t.b +└─Projection_7 3340.00 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_12 3340.00 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[-inf,10), keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:b(b) range:(11,+inf], keep order:false, stats:pseudo + └─TableRowIDScan_11(Probe) 3340.00 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a < 10 or b > 11 order by b; +b a c +1 1 1 +100 100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +id estRows task access object operator info +Sort_5 7771.56 root planner__core__integration.t.b +└─Projection_7 7771.56 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_13 7771.56 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─IndexRangeScan_9(Build) 3333.33 cop[tikv] table:t, index:b(b) range:[10,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3323.33 cop[tikv] table:t, index:idx_c(c) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_12(Probe) 7771.56 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +b a c +1 1 1 +10 10 10 +100 100 100 +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +id estRows task access object operator info +Sort_5 7033.48 root planner__core__integration.t.b +└─Projection_7 7033.48 root planner__core__integration.t.b, planner__core__integration.t.a, planner__core__integration.t.c + └─IndexMerge_14 7033.48 root type: union + ├─TableRangeScan_8(Build) 3333.33 cop[tikv] table:t range:[-inf,2), keep order:false, stats:pseudo + ├─TableRangeScan_9(Build) 3333.33 cop[tikv] table:t range:[10,+inf], keep order:false, stats:pseudo + ├─TableRangeScan_10(Build) 3333.33 cop[tikv] table:t range:[20,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_11(Build) 3333.33 cop[tikv] table:t, index:idx_c(c) range:(100,+inf], keep order:false, stats:pseudo + ├─IndexRangeScan_12(Build) 3323.33 cop[tikv] table:t, index:b(b) range:[-inf,1), keep order:false, stats:pseudo + └─TableRowIDScan_13(Probe) 7033.48 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +b a c +1 1 1 +10 10 10 +100 100 100 +drop table if exists t; +create table t (a int, b int, index(a), index(b)) partition by hash (a) partitions 2; +insert into t values (1, 5); +select /*+ use_index_merge( t ) */ * from t where a in (3) or b in (5) order by a; +a b +1 5 +drop table if exists t; +CREATE TABLE t ( +col_5 text NOT NULL, +col_6 tinyint(3) unsigned DEFAULT NULL, +col_7 float DEFAULT '4779.165058537128', +col_8 smallint(6) NOT NULL DEFAULT '-24790', +col_9 date DEFAULT '2031-01-15', +col_37 int(11) DEFAULT '1350204687', +PRIMARY KEY (col_5(6),col_8) /*T![clustered_index] NONCLUSTERED */, +UNIQUE KEY idx_6 (col_9,col_7,col_8), +KEY idx_8 (col_8,col_6,col_5(6),col_9,col_7), +KEY idx_9 (col_9,col_7,col_8) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY RANGE ( col_8 ) ( +PARTITION p0 VALUES LESS THAN (-17650), +PARTITION p1 VALUES LESS THAN (-13033), +PARTITION p2 VALUES LESS THAN (2521), +PARTITION p3 VALUES LESS THAN (7510) +); +insert into t values ('', NULL, 6304.0146, -24790, '2031-01-15', 1350204687); +select var_samp(col_7) aggCol from (select /*+ use_index_merge( t ) */ * from t where t.col_9 in ( '2002-06-22' ) or t.col_5 in ( 'PkfzI' ) or t.col_8 in ( -24874 ) and t.col_6 > null and t.col_5 > 'r' and t.col_9 in ( '1979-09-04' ) and t.col_7 < 8143.667552769195 or t.col_5 in ( 'iZhfEjRWci' , 'T' , '' ) or t.col_9 <> '1976-09-11' and t.col_7 = 8796.436181615773 and t.col_8 = 7372 order by col_5,col_8 ) ordered_tbl group by col_6; +aggCol +NULL +drop table if exists t; +create table t(a int,b char(100),key(a),key(b(10))); +explain format = 'brief' select /*+ use_index_merge(t) */ * from t where a=10 or b='x'; +id estRows task access object operator info +IndexMerge 0.04 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[10,10], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:["x","x"], keep order:false, stats:pseudo +└─Selection(Probe) 0.04 cop[tikv] or(eq(planner__core__integration.t.a, 10), eq(planner__core__integration.t.b, "x")) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +insert into t values (1, 'xx'); +select /*+ use_index_merge(t) */ * from t where a=10 or b='x'; +a b +set tidb_cost_model_version=2; +drop table if exists t; +create table t(a int); +insert into t values(1),(1),(2); +set @@session.sql_select_limit=1; +select * from t order by a; +a +1 +select * from t order by a limit 2; +a +1 +1 +set @@session.sql_select_limit=default; +select * from t order by a; +a +1 +1 +2 +set @@session.sql_select_limit=1; +select * from (select * from t) s order by a; +a +1 +select * from (select * from t limit 2) s order by a; +a +1 +select (select * from t limit 1) s; +s +1 +select * from t where t.a in (select * from t) limit 3; +a +1 +1 +2 +select * from (select * from t) s limit 3; +a +1 +1 +2 +select * from t union all select * from t limit 2; +a +1 +1 +select * from t union all (select * from t limit 2); +a +1 +prepare s1 from 'select * from t where a = ?'; +set @a = 1; +execute s1 using @a; +a +1 +set @@session.sql_select_limit=default; +execute s1 using @a; +a +1 +1 +set @@session.sql_select_limit=1; +prepare s2 from 'select * from t where a = ? limit 3'; +execute s2 using @a; +a +1 +1 +set @@session.sql_select_limit=1; +create definer='root'@'localhost' view s as select * from t; +select * from s; +a +1 +set @@session.sql_select_limit=default; +select * from s; +a +1 +1 +2 +set @@session.sql_select_limit=1; +create table b (a int); +insert into b select * from t; +select * from b limit 3; +a +1 +1 +2 +update b set a = 2 where a = 1; +select * from b limit 3; +a +2 +2 +2 +select * from b; +a +2 +delete from b where a = 2; +select * from b; +a +set @@session.sql_select_limit=DEFAULT; +drop table if exists t; +create table t(a int, b int, key(a), key(b)); +select /*+ use_index_merge() */ * from t where a = 1 or b = 1; +a b +Level Code Message +Warning 1064 Optimizer hint syntax error at line 1 column 28 near ") */" +drop table if exists t0; +drop view if exists v0; +CREATE TABLE t0(c0 INT); +INSERT INTO t0(c0) VALUES (1), (1), (1), (1), (1), (1); +CREATE definer='root'@'localhost' VIEW v0(c0) AS SELECT NULL FROM t0; +SELECT * FROM t0 LEFT JOIN v0 ON TRUE WHERE v0.c0 IS NULL; +c0 c0 +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +1 NULL +create database cluster_idx_unique_double_read; +use cluster_idx_unique_double_read; +set @@tidb_enable_clustered_index = 'ON'; +drop table if exists t; +create table t (a varchar(64), b varchar(64), uk int, v int, primary key(a, b), unique key uuk(uk)); +insert t values ('a', 'a1', 1, 11), ('b', 'b1', 2, 22), ('c', 'c1', 3, 33); +select * from t use index (uuk); +a b uk v +a a1 1 11 +b b1 2 22 +c c1 3 33 +drop database cluster_idx_unique_double_read; +set @@tidb_enable_clustered_index = DEFAULT; +use planner__core__integration +drop table if exists t, t2; +set @@tidb_enable_clustered_index = 'ON'; +create table t(a int, b int, c int, primary key(a, b)); +create table t2(a int, b int, c int, d int, primary key(a,b), index idx(c)); +insert into t values(1,1,1), (2,2,2), (3,3,3); +insert into t2 values(1,2,3,4), (2,4,3,5), (1,3,1,1); +select /*+ INL_MERGE_JOIN(t) */ * from t right outer join t2 on t.a=t2.c; +a b c a b c d +1 1 1 1 3 1 1 +3 3 3 1 2 3 4 +3 3 3 2 4 3 5 +select /*+ INL_MERGE_JOIN(t2) */ * from t left outer join t2 on t.a=t2.c; +a b c a b c d +1 1 1 1 3 1 1 +2 2 2 NULL NULL NULL NULL +3 3 3 1 2 3 4 +3 3 3 2 4 3 5 +set @@tidb_enable_clustered_index = DEFAULT; +drop table if exists t; +create table t (a int not null, b int not null, c int not null, primary key (a,c)) partition by range (c) (partition p0 values less than (5), partition p1 values less than (10)); +insert into t values(1,1,1),(2,2,2),(3,1,3),(7,1,7),(8,2,8),(9,2,9); +select count(distinct b+1) as col from t; +col +2 +drop table if exists t; +create table t (c_int int, c_str varchar(40), primary key(c_int, c_str)); +insert into t values (3, 'bose'); +select * from t where c_int in (3); +c_int c_str +3 bose +select * from t where c_int in (3) or c_str in ('yalow') and c_int in (1, 2); +c_int c_str +3 bose +drop table if exists ta; +drop table if exists tb; +drop table if exists tc; +drop view if exists v; +CREATE TABLE `ta` ( +`id` varchar(36) NOT NULL , +`status` varchar(1) NOT NULL +); +CREATE TABLE `tb` ( +`id` varchar(36) NOT NULL , +`status` varchar(1) NOT NULL +); +CREATE TABLE `tc` ( +`id` varchar(36) NOT NULL , +`status` varchar(1) NOT NULL +); +insert into ta values('1','1'); +insert into tb values('1','1'); +insert into tc values('1','1'); +create definer='root'@'localhost' view v as +select +concat(`ta`.`status`,`tb`.`status`) AS `status`, +`ta`.`id` AS `id` from (`ta` join `tb`) +where (`ta`.`id` = `tb`.`id`); +SELECT tc.status,v.id FROM tc, v WHERE tc.id = v.id AND v.status = '11'; +status id +1 1 +drop table if exists t1, t2; +create table t1(a int primary key, b int); +create table t2(a int primary key, b int); +insert into t1 values(1,1),(2,2); +insert into t2 values(2,2); +delete t1.* from t1 join t2 using (a); +select * from t1; +a b +1 1 +select * from t2; +a b +2 2 +drop table if exists t; +set @@tidb_enable_clustered_index = 'ON'; +CREATE TABLE planner__core__integration.`t` ( `a` int(11) NOT NULL, `b` varchar(10) COLLATE utf8_general_ci NOT NULL, `c` varchar(50) COLLATE utf8_general_ci NOT NULL, `d` char(10) NOT NULL, PRIMARY KEY (`c`), UNIQUE KEY `a_uniq` (`a`), UNIQUE KEY `b_uniq` (`b`), UNIQUE KEY `d_uniq` (`d`), KEY `a_idx` (`a`), KEY `b_idx` (`b`), KEY `d_idx` (`d`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (1, '1', '0', '1'); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (2, ' 2', ' 0', ' 2'); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (3, ' 3 ', ' 3 ', ' 3 '); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (4, 'a', 'a ', 'a'); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (5, ' A ', ' A ', ' A '); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (6, ' E', 'é ', ' E'); +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`a_uniq`); +a b c d +3 3 3 3 +2 2 0 2 +5 A A A +1 1 0 1 +4 a a a +6 E é E +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`b_uniq`); +a b c d +3 3 3 3 +2 2 0 2 +5 A A A +1 1 0 1 +4 a a a +6 E é E +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`d_uniq`); +a b c d +3 3 3 3 +2 2 0 2 +5 A A A +1 1 0 1 +4 a a a +6 E é E +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`a_idx`); +a b c d +3 3 3 3 +2 2 0 2 +5 A A A +1 1 0 1 +4 a a a +6 E é E +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`b_idx`); +a b c d +3 3 3 3 +2 2 0 2 +5 A A A +1 1 0 1 +4 a a a +6 E é E +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`d_idx`); +a b c d +3 3 3 3 +2 2 0 2 +5 A A A +1 1 0 1 +4 a a a +6 E é E +admin check table t; + +set @@tidb_enable_clustered_index = DEFAULT; +drop table if exists t; +CREATE TABLE `t` ( +`fid` bigint(36) NOT NULL, +`oty` varchar(30) DEFAULT NULL, +`oid` int(11) DEFAULT NULL, +`pid` bigint(20) DEFAULT NULL, +`bid` int(11) DEFAULT NULL, +`r5` varchar(240) DEFAULT '', +PRIMARY KEY (`fid`) +)PARTITION BY HASH( `fid` ) PARTITIONS 4; +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (59, 'm', 441, 1, 2143, 'LE1264_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (135, 'm', 1121, 1, 2423, 'LE2008_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (139, 'm', 1125, 1, 2432, 'LE2005_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (143, 'm', 1129, 1, 2438, 'LE2006_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (147, 'm', 1133, 1, 2446, 'LE2014_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (167, 'm', 1178, 1, 2512, 'LE2055_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (171, 'm', 1321, 1, 2542, 'LE1006_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (179, 'm', 1466, 1, 2648, 'LE2171_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (187, 'm', 1567, 1, 2690, 'LE1293_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (57, 'm', 341, 1, 2102, 'LE1001_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (137, 'm', 1123, 1, 2427, 'LE2003_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (145, 'm', 1131, 1, 2442, 'LE2048_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (138, 'm', 1124, 1, 2429, 'LE2004_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (142, 'm', 1128, 1, 2436, 'LE2049_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (174, 'm', 1381, 1, 2602, 'LE2170_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (28, 'm', 81, 1, 2023, 'LE1009_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (60, 'm', 442, 1, 2145, 'LE1263_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (136, 'm', 1122, 1, 2425, 'LE2002_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (140, 'm', 1126, 1, 2434, 'LE2001_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (168, 'm', 1179, 1, 2514, 'LE2052_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (196, 'm', 3380, 1, 2890, 'LE1300_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (208, 'm', 3861, 1, 3150, 'LE1323_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (432, 'm', 4060, 1, 3290, 'LE1327_r5'); +SELECT DISTINCT t.bid, t.r5 FROM t left join t parent on parent.oid = t.pid WHERE t.oty = 'm'; +bid r5 +2023 LE1009_r5 +2102 LE1001_r5 +2143 LE1264_r5 +2145 LE1263_r5 +2423 LE2008_r5 +2425 LE2002_r5 +2427 LE2003_r5 +2429 LE2004_r5 +2432 LE2005_r5 +2434 LE2001_r5 +2436 LE2049_r5 +2438 LE2006_r5 +2442 LE2048_r5 +2446 LE2014_r5 +2512 LE2055_r5 +2514 LE2052_r5 +2542 LE1006_r5 +2602 LE2170_r5 +2648 LE2171_r5 +2690 LE1293_r5 +2890 LE1300_r5 +3150 LE1323_r5 +3290 LE1327_r5 +drop table if exists t; +create table t(a int default null, b int default null, c int default null); +explain format = 'brief' select * from t where a = 1 and a = 2; +id estRows task access object operator info +TableDual 0.00 root rows:0 +drop table t; +explain select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2; +id estRows task access object operator info +HashJoin_8 1.00 root CARTESIAN left outer join +├─Projection_12(Build) 1.00 root 2->Column#2 +│ └─TableDual_13 1.00 root rows:1 +└─Projection_10(Probe) 1.00 root 1->Column#1 + └─TableDual_11 1.00 root rows:1 +select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2; +1 2 +1 2 +drop table if exists t; +create table t(pk int(11) primary key); +insert into t values(1),(2),(3); +select a from (select pk as a from t) t1 where a = 18446744073709551615; +a +drop table if exists t; +create table t (a int not null primary key); +insert into t values (1); +UPDATE t m, t n SET m.a = m.a + 10, n.a = n.a + 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'. +drop table if exists t; +create table t (a varchar(10) not null primary key); +insert into t values ('abc'); +UPDATE t m, t n SET m.a = 'def', n.a = 'xyz'; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'. +drop table if exists t; +create table t (a int, b int, primary key (a, b)); +insert into t values (1, 2); +UPDATE t m, t n SET m.a = m.a + 10, n.b = n.b + 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'. +drop table if exists t; +create table t (a int primary key, b int); +insert into t values (1, 2); +UPDATE t m, t n SET m.a = m.a + 10, n.a = n.a + 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'. +UPDATE t m, t n SET m.b = m.b + 10, n.b = n.b + 10; +SELECT * FROM t; +a b +1 12 +UPDATE t m, t n SET m.a = m.a + 1, n.b = n.b + 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'. +UPDATE t m, t n, t q SET m.a = m.a + 1, n.b = n.b + 10, q.b = q.b - 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'. +UPDATE t m, t n, t q SET m.b = m.b + 1, n.a = n.a + 10, q.b = q.b - 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'n'. +UPDATE t m, t n, t q SET m.b = m.b + 1, n.b = n.b + 10, q.a = q.a - 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'm' and 'q'. +UPDATE t q, t n, t m SET m.b = m.b + 1, n.b = n.b + 10, q.a = q.a - 10; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'q' and 'n'. +update t m, t n set m.a = n.a+10 where m.a=n.a; +select * from t; +a b +11 12 +drop table if exists ttest; +create table ttest (v1 int, v2 int); +insert into ttest values(1, 2), (4,6), (1, 7); +select v1 from ttest order by count(v2); +Error 3029 (HY000): Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query +select v1 from ttest having count(v2); +Error 8123 (HY000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'v1'; this is incompatible with sql_mode=only_full_group_by +select v2, v1 from (select * from ttest) t1 join (select 1, 2) t2 group by v1; +Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'planner__core__integration.t1.v2' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by +select v2, v1 from (select t1.v1, t2.v2 from ttest t1 join ttest t2) t3 join (select 1, 2) t2 group by v1; +Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'planner__core__integration.t3.v2' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by +create table tt (x int, z int as (x+10) stored); +insert into tt(x) values (1); +update tt set x=2, z = default; +update tt set x=2, z = default(z); +select * from tt; +x z +2 12 +update tt set x=2, z = default(x); +Error 3105 (HY000): The value specified for generated column 'z' in table 'tt' is not allowed. +update tt set z = 123; +Error 3105 (HY000): The value specified for generated column 'z' in table 'tt' is not allowed. +update tt as ss set z = 123; +Error 3105 (HY000): The value specified for generated column 'z' in table 'tt' is not allowed. +update tt as ss set x = 3, z = 13; +Error 3105 (HY000): The value specified for generated column 'z' in table 'tt' is not allowed. +update tt as s1, tt as s2 set s1.z = default, s2.z = 456; +Error 3105 (HY000): The value specified for generated column 'z' in table 'tt' is not allowed. +drop table if exists t; +create table t(a int not null, b int not null, key(a), key(b)); +insert into t values(1,1),(2,2),(3,3),(4,4),(5,5),(6,6); +set session tidb_enable_extended_stats = off; +alter table t add stats_extended s1 correlation(a,b); +Error 1105 (HY000): Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF +alter table t drop stats_extended s1; +Error 1105 (HY000): Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF +admin reload stats_extended; +Error 1105 (HY000): Extended statistics feature is not generally available now, and tidb_enable_extended_stats is OFF +set session tidb_enable_extended_stats = on; +alter table t add stats_extended s1 correlation(a,b); +select stats, status from mysql.stats_extended where name = 's1'; +stats status +NULL 0 +set session tidb_enable_extended_stats = off; +analyze table t; +select stats, status from mysql.stats_extended where name = 's1'; +stats status +NULL 0 +set session tidb_enable_extended_stats = on; +analyze table t; +select stats, status from mysql.stats_extended where name = 's1'; +stats status +1.000000 1 +explain format = 'brief' select * from t use index(b) where a > 3 order by b limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─Projection 1.00 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexLookUp 1.00 root + ├─IndexFullScan(Build) 4.00 cop[tikv] table:t, index:b(b) keep order:true + └─Selection(Probe) 1.00 cop[tikv] gt(planner__core__integration.t.a, 3) + └─TableRowIDScan 4.00 cop[tikv] table:t keep order:false +set session tidb_enable_extended_stats = off; +explain format = 'brief' select * from t use index(b) where a > 3 order by b limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─Projection 1.00 root planner__core__integration.t.a, planner__core__integration.t.b + └─IndexLookUp 1.00 root + ├─IndexFullScan(Build) 2.00 cop[tikv] table:t, index:b(b) keep order:true + └─Selection(Probe) 1.00 cop[tikv] gt(planner__core__integration.t.a, 3) + └─TableRowIDScan 2.00 cop[tikv] table:t keep order:false +drop table if exists ttest; +create table ttest (v1 int, v2 int); +insert into ttest values(1, 2), (4,6), (1, 7); +select distinct v1 from ttest order by v2; +Error 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'planner__core__integration.ttest.v2' which is not in SELECT list; this is incompatible with DISTINCT +select distinct v1+1 from ttest order by v1; +Error 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'planner__core__integration.ttest.v1' which is not in SELECT list; this is incompatible with DISTINCT +select distinct v1+1 from ttest order by 1+v1; +Error 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'planner__core__integration.ttest.v1' which is not in SELECT list; this is incompatible with DISTINCT +select distinct v1+1 from ttest order by v1+2; +Error 3065 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, references column 'planner__core__integration.ttest.v1' which is not in SELECT list; this is incompatible with DISTINCT +select distinct count(v1) from ttest group by v2 order by sum(v1); +Error 3066 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, contains aggregate function; this is incompatible with DISTINCT +select distinct sum(v1)+1 from ttest group by v2 order by sum(v1); +Error 3066 (HY000): Expression #1 of ORDER BY clause is not in SELECT list, contains aggregate function; this is incompatible with DISTINCT +select distinct v1+1 from ttest order by v1+1; +v1+1 +2 +5 +select distinct count(v1) from ttest order by count(v1); +count(v1) +3 +select distinct count(v1) from ttest group by v2 order by count(v1); +count(v1) +1 +select distinct sum(v1) from ttest group by v2 order by sum(v1); +sum(v1) +1 +4 +select distinct v1, v2 from ttest order by 1, 2; +v1 v2 +1 2 +1 7 +4 6 +select distinct v1, v2 from ttest order by 2, 1; +v1 v2 +1 2 +4 6 +1 7 +select distinct v1 from ttest order by v1+1; +v1 +1 +4 +select distinct v1, v2 from ttest order by v1+1, v2; +v1 v2 +1 2 +1 7 +4 6 +select distinct v1+1 as z, v2 from ttest order by v1+1, z+v2; +z v2 +2 2 +2 7 +5 6 +select distinct sum(v1) as z from ttest group by v2 order by z+1; +z +1 +4 +select distinct sum(v1)+1 from ttest group by v2 order by sum(v1)+1; +sum(v1)+1 +2 +5 +select distinct v1 as z from ttest order by v1+z; +z +1 +4 +DROP TABLE IF EXISTS temptest; +create table temptest (val int, val1 int); +SELECT val FROM temptest WINDOW w AS (ORDER BY val RANGE 1 PRECEDING); +val +SELECT val FROM temptest WINDOW w AS (ORDER BY val, val1 RANGE 1 PRECEDING); +Error 3587 (HY000): Window 'w' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type +select val1, avg(val1) as a from temptest group by val1 window w as (order by a); +Error 1054 (42S22): Unknown column 'a' in 'window order by' +select val1, avg(val1) as a from temptest group by val1 window w as (partition by a); +Error 1054 (42S22): Unknown column 'a' in 'window partition by' +DROP TABLE IF EXISTS tab, tab2; +CREATE TABLE tab(i INT); +CREATE TABLE tab2(j INT); +insert into tab values(1),(2),(3); +insert into tab2 values(1),(2),(3),(15); +SELECT m.i, +(SELECT COUNT(n.j) +FROM tab2 WHERE j=15) AS o +FROM tab m, tab2 n GROUP BY 1 order by m.i; +i o +1 4 +2 4 +3 4 +SELECT +(SELECT COUNT(n.j) +FROM tab2 WHERE j=15) AS o +FROM tab m, tab2 n order by m.i; +o +12 +drop table if exists t1, t2; +create table t1 (a int, b int); +create table t2 (m int, n int); +insert into t1 values (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); +insert into t2 values (1,11), (2,22), (3,32), (4,44), (4,44); +set @@sql_mode='TRADITIONAL'; +select count(*) c, a, +( select group_concat(count(a)) from t2 where m = a ) +from t1 group by a order by a; +c a ( select group_concat(count(a)) from t2 where m = a ) +2 2 2 +3 3 3 +1 4 1,1 +drop table if exists t; +create table t (a int, b int); +insert into t values (1,1),(2,1),(2,2),(3,1),(3,2),(3,3); +select (select count(a)) from t; +(select count(a)) +6 +select (select (select (select count(a)))) from t; +(select (select (select count(a)))) +6 +select (select (select count(n.a)) from t m order by count(m.b)) from t n; +(select (select count(n.a)) from t m order by count(m.b)) +6 +select (select count(n.a) from t where count(n.a)=3) from t n; +(select count(n.a) from t where count(n.a)=3) +NULL +select (select count(a) from t where count(distinct n.a)=3) from t n; +(select count(a) from t where count(distinct n.a)=3) +6 +select (select count(n.a) from t having count(n.a)=6 limit 1) from t n; +(select count(n.a) from t having count(n.a)=6 limit 1) +6 +select (select count(n.a) from t having count(distinct n.b)=3 limit 1) from t n; +(select count(n.a) from t having count(distinct n.b)=3 limit 1) +6 +select (select sum(distinct n.a) from t having count(distinct n.b)=3 limit 1) from t n; +(select sum(distinct n.a) from t having count(distinct n.b)=3 limit 1) +6 +select (select sum(distinct n.a) from t having count(distinct n.b)=6 limit 1) from t n; +(select sum(distinct n.a) from t having count(distinct n.b)=6 limit 1) +NULL +select (select count(n.a) from t order by count(n.b) limit 1) from t n; +(select count(n.a) from t order by count(n.b) limit 1) +6 +select (select count(distinct n.b) from t order by count(n.b) limit 1) from t n; +(select count(distinct n.b) from t order by count(n.b) limit 1) +3 +select (select cnt from (select count(a) cnt) s) from t; +(select cnt from (select count(a) cnt) s) +6 +select (select count(cnt) from (select count(a) cnt) s) from t; +(select count(cnt) from (select count(a) cnt) s) +1 +select (select sum((select count(a)))) from t; +(select sum((select count(a)))) +6 +select (select sum((select count(a))+sum(a))) from t; +(select sum((select count(a))+sum(a))) +20 +select (select count(a) from t group by count(n.a)) from t n; +(select count(a) from t group by count(n.a)) +6 +select (select count(distinct a) from t group by count(n.a)) from t n; +(select count(distinct a) from t group by count(n.a)) +3 +select sum(a) from t having (select count(a)) = 0; +sum(a) +select sum(a) from t having (select count(a)) > 0; +sum(a) +14 +select count(a) from t group by b order by (select count(a)); +count(a) +1 +2 +3 +select count(a) from t group by b order by (select -count(a)); +count(a) +3 +2 +1 +select (select sum(count(a))) from t; +(select sum(count(a))) +6 +select (select sum(sum(a))) from t; +(select sum(sum(a))) +14 +select count(a), (select count(a)) from t; +count(a) (select count(a)) +6 6 +select sum(distinct b), count(a), (select count(a)), (select cnt from (select sum(distinct b) as cnt) n) from t; +sum(distinct b) count(a) (select count(a)) (select cnt from (select sum(distinct b) as cnt) n) +6 6 6 6 +set @@sql_mode=DEFAULT; +drop table if exists t; +create table t (a int, b int); +insert into t values (1,1); +select (select count(n.a + a) from t) from t n; +(select count(n.a + a) from t) +1 +drop table if exists t; +create table t (a int, b int, c int); +insert into t values (1, 2, 3), (4, 5, 6), (7, 8, 9); +select a, count(b) from t where a = 1; +a count(b) +1 1 +select a, count(b) from t where a = 10; +a count(b) +NULL 0 +select a, c, sum(b) from t where a = 1 group by c; +a c sum(b) +1 3 2 +select a from t where a = 1 order by count(b); +Error 3029 (HY000): Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query +select a from t where a = 1 having count(b) > 0; +a +1 +drop table if exists t; +create table t (a int, b int, primary key(a,b)); +select * from t where (a,b) in ((1,2),(1,2)); +a b +select * from t where (a,b) in (1,2); +Error 1241 (21000): Operand should contain 2 column(s) +select * from t where (a,b) in ((1,2),1); +Error 1241 (21000): Operand should contain 2 column(s) +drop table if exists t; +create table t (a int); +insert into t values(1),(2),(5); +select n in (1,2) from (select a in (1,2) as n from t) g; +n in (1,2) +1 +1 +0 +select n in (1,n) from (select a in (1,2) as n from t) g; +n in (1,n) +1 +1 +1 +drop table if exists t1, t2; +create table t1(i int primary key, j int, index idx_j(j)); +create table t2(i int primary key, j int, index idx_j(j)); +select t1.*, (select t2.* from t1) from t1; +Error 1051 (42S02): Unknown table 't2' +set @@tidb_partition_prune_mode='static'; +drop table if exists t1; +create table t1(a int) partition by hash (a) partitions 5; +insert into t1 values (0); +select * from t1 where a not between 1 and 2; +a +0 +set @@tidb_partition_prune_mode='dynamic'; +drop table if exists t2; +create table t2(a int) partition by hash (a) partitions 5; +insert into t2 values (0); +select * from t2 where a not between 1 and 2; +a +0 +set @@tidb_partition_prune_mode=DEFAULT; +create table tx (a int) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20)); +insert into tx values (1); +set @@tidb_partition_prune_mode='dynamic'; +begin; +delete from tx where a in (1); +select * from tx PARTITION(p0); +a +select * from tx; +a +rollback; +drop table if exists t1; +create table `t1` (`a` enum('aa') DEFAULT NULL, KEY `k` (`a`)); +insert into t1 values('aa'); +insert into t1 values(null); +select a from t1 where a<=>'aa'; +a +aa +select a from t1 where a<=>null; +a +NULL +CREATE TABLE IDT_MULTI15860STROBJSTROBJ ( +COL1 enum('aa') DEFAULT NULL, +COL2 int(41) DEFAULT NULL, +COL3 year(4) DEFAULT NULL, +KEY U_M_COL4 (COL1,COL2), +KEY U_M_COL5 (COL3,COL2)); +insert into IDT_MULTI15860STROBJSTROBJ values("aa", 1013610488, 1982); +SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = "aa"; +COL1 COL2 COL3 COL1 COL2 COL3 +prepare stmt from "SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = ?"; +set @a="aa"; +execute stmt using @a; +COL1 COL2 COL3 COL1 COL2 COL3 +drop table if exists t; +create table t(a int); +delete t from t; +delete t from planner__core__integration.t as t; +delete planner__core__integration.t from planner__core__integration.t as t; +Error 1109 (42S02): Unknown table 't' in MULTI DELETE +delete planner__core__integration.t from t; +drop database if exists db1; +create database db1; +use db1; +create table t(a int); +delete planner__core__integration.t from t; +Error 1109 (42S02): Unknown table 't' in MULTI DELETE +use planner__core__integration; +drop table if exists t; +create table t(a int primary key, b int not null, key(b)); +delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (b < SOME (SELECT /*+ use_index_merge(t)*/ b FROM t WHERE a<2 OR b<2)); +drop table if exists t; +create table t(a int not null, b int not null, key(a), key(b)); +delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (b < SOME (SELECT /*+ use_index_merge(t)*/ b FROM t WHERE a<2 OR b<2)); +drop table if exists t; +create table t(a int primary key, b int not null, c int, key(a), key(b,c)); +delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (a<2 and b<2); +drop table if exists t; +create table t(a int, b int, c int, d int, key(a), key(b)); +insert into t values(10,1,1,10); +explain format = 'brief' select /*+ use_index_merge(t) */ * from t where a=10 or (b=10 and c=10); +id estRows task access object operator info +IndexMerge 0.02 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[10,10], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[10,10], keep order:false, stats:pseudo +└─Selection(Probe) 0.02 cop[tikv] or(eq(planner__core__integration.t.a, 10), and(eq(planner__core__integration.t.b, 10), eq(planner__core__integration.t.c, 10))) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ * from t where a=10 or (b=10 and c=10); +a b c d +10 1 1 10 +explain format = 'brief' select /*+ use_index_merge(t) */ * from t where (a=10 and d=10) or (b=10 and c=10); +id estRows task access object operator info +IndexMerge 0.00 root type: union +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:a(a) range:[10,10], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:b(b) range:[10,10], keep order:false, stats:pseudo +└─Selection(Probe) 0.00 cop[tikv] or(and(eq(planner__core__integration.t.a, 10), eq(planner__core__integration.t.d, 10)), and(eq(planner__core__integration.t.b, 10), eq(planner__core__integration.t.c, 10))) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +select /*+ use_index_merge(t) */ * from t where (a=10 and d=10) or (b=10 and c=10); +a b c d +10 1 1 10 +drop table if exists t1; +CREATE TABLE t1 (a int(11)); +SELECT @v:=(SELECT 1 FROM t1 t2 LEFT JOIN t1 ON t1.a GROUP BY t1.a) FROM t1; +@v:=(SELECT 1 FROM t1 t2 LEFT JOIN t1 ON t1.a GROUP BY t1.a) +drop table if exists t1, t2; +create table t1(a int(11)); +create table t2(a decimal(40,20) unsigned, b decimal(40,20)); +select count(*) as x from t1 group by a having x not in (select a from t2 where x = t2.b); +x +drop table if exists t1_no_idx; +create table t1_no_idx(id int, col_bit bit(16)); +insert into t1_no_idx values(1, 0x3135); +insert into t1_no_idx values(2, 0x0f); +prepare stmt from 'select id from t1_no_idx where col_bit = ?'; +set @a = 0x3135; +execute stmt using @a; +id +1 +set @a = 0x0F; +execute stmt using @a; +id +2 +prepare stmt from 'select id from t1_no_idx where col_bit in (?)'; +set @a = 0x3135; +execute stmt using @a; +id +1 +set @a = 0x0F; +execute stmt using @a; +id +2 +drop table if exists t2_idx; +create table t2_idx(id int, col_bit bit(16), key(col_bit)); +insert into t2_idx values(1, 0x3135); +insert into t2_idx values(2, 0x0f); +prepare stmt from 'select id from t2_idx where col_bit = ?'; +set @a = 0x3135; +execute stmt using @a; +id +1 +set @a = 0x0F; +execute stmt using @a; +id +2 +prepare stmt from 'select id from t2_idx where col_bit in (?)'; +set @a = 0x3135; +execute stmt using @a; +id +1 +set @a = 0x0F; +execute stmt using @a; +id +2 +drop table if exists t_varchar; +create table t_varchar(id int, col_varchar varchar(100), key(col_varchar)); +insert into t_varchar values(1, '15'); +prepare stmt from 'select id from t_varchar where col_varchar = ?'; +set @a = 0x3135; +execute stmt using @a; +id +1 +drop table if exists t1_no_idx; +create table t1_no_idx(id int, col_bit bit(16)); +insert into t1_no_idx values(1, 0x3135); +insert into t1_no_idx values(2, 0x0f); +prepare stmt from 'select id from t1_no_idx where col_bit = ?'; +set @a = 0b11000100110101; +execute stmt using @a; +id +1 +prepare stmt from 'select id from t1_no_idx where col_bit in (?)'; +set @a = 0b11000100110101; +execute stmt using @a; +id +1 +drop table if exists t; +create table t (c1 float, c2 int, c3 int, primary key (c1) /*T![clustered_index] CLUSTERED */, key idx_1 (c2), key idx_2 (c3)); +insert into t values(1.0,1,2),(2.0,2,1),(3.0,1,1),(4.0,2,2); +select /*+ use_index_merge(t) */ c3 from t where c3 = 1 or c2 = 1; +c3 +1 +1 +2 +drop table t; +create table t (a int, b int, c int, primary key (a,b) /*T![clustered_index] CLUSTERED */, key idx_c(c)); +insert into t values (0,1,2); +select /*+ use_index_merge(t) */ c from t where c > 10 or a < 1; +c +2 +drop table if exists t0, t1; +create table t0(a int, b int, c int as (a + b) virtual, unique index (c) invisible); +create table t1(a int, b int, c int as (a + b) virtual); +insert into t0(a, b) values (12, -1), (8, 7); +insert into t1(a, b) values (12, -1), (8, 7); +select /*+ stream_agg() */ count(1) from t0 where c > 10 and b < 2; +count(1) +1 +select /*+ stream_agg() */ count(1) from t1 where c > 10 and b < 2; +count(1) +1 +delete from t0; +insert into t0(a, b) values (5, 1); +select /*+ nth_plan(3) */ count(1) from t0 where c > 10 and b < 2; +count(1) +0 +explain select /*+ stream_agg() */ count(1) from t0 where c > 10 and b < 2; +id estRows task access object operator info +StreamAgg_9 1.00 root funcs:count(1)->Column#5 +└─Selection_18 3333.33 root gt(planner__core__integration.t0.c, 10) + └─Projection_17 10000.00 root planner__core__integration.t0.b, planner__core__integration.t0.c + └─TableReader_16 3323.33 root data:Selection_15 + └─Selection_15 3323.33 cop[tikv] lt(planner__core__integration.t0.b, 2) + └─TableFullScan_14 10000.00 cop[tikv] table:t0 keep order:false, stats:pseudo +drop table if exists NT_HP27193; +CREATE TABLE `NT_HP27193` ( `COL1` int(20) DEFAULT NULL, `COL2` varchar(20) DEFAULT NULL, `COL4` datetime DEFAULT NULL, `COL3` bigint(20) DEFAULT NULL, `COL5` float DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH ( `COL1`%`COL3` ) PARTITIONS 10; +select col1 from NT_HP27193 where col1 is null; +col1 +INSERT INTO NT_HP27193 (COL2, COL4, COL3, COL5) VALUES ('m', '2020-05-04 13:15:27', 8, 2602); +select col1 from NT_HP27193 where col1 is null; +col1 +NULL +drop table if exists NT_HP27193; +drop table if exists t; +create table t(a varbinary(10),UNIQUE KEY(a)); +insert into t values(0x00A4EEF4FA55D6706ED5); +select count(*) from t where a=0x00A4EEF4FA55D6706ED5; +count(*) +1 +select * from t where a=0x00A4EEF4FA55D6706ED5; +a +Upn +drop table if exists BB; +CREATE TABLE `BB` ( +`col_int` int(11) DEFAULT NULL, +`col_varchar_10` varchar(10) DEFAULT NULL, +`pk` int(11) NOT NULL AUTO_INCREMENT, +`col_int_not_null` int(11) NOT NULL, +`col_decimal` decimal(10,0) DEFAULT NULL, +`col_datetime` datetime DEFAULT NULL, +`col_decimal_not_null` decimal(10,0) NOT NULL, +`col_datetime_not_null` datetime NOT NULL, +`col_varchar_10_not_null` varchar(10) NOT NULL, +PRIMARY KEY (`pk`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000001; +explain SELECT OUTR . col2 AS X FROM (SELECT INNR . col1 as col1, SUM( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR2 INNER JOIN (SELECT INNR . col1 as col1, MAX( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR ON OUTR2.col1 = OUTR.col1 GROUP BY OUTR . col1, OUTR2 . col1 HAVING X <> 'b'; +Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column '.OUTR.' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by +drop table if exists member, agent, deposit, view_member_agents; +create table member(login varchar(50) NOT NULL, agent_login varchar(100) DEFAULT NULL, PRIMARY KEY(login)); +create table agent(login varchar(50) NOT NULL, data varchar(100) DEFAULT NULL, share_login varchar(50) NOT NULL, PRIMARY KEY(login)); +create table deposit(id varchar(50) NOT NULL, member_login varchar(50) NOT NULL, transfer_amount int NOT NULL, PRIMARY KEY(id), KEY midx(member_login, transfer_amount)); +create definer='root'@'localhost' view view_member_agents (member, share_login) as select m.login as member, a.share_login AS share_login from member as m join agent as a on m.agent_login = a.login; +select s.member_login as v1, SUM(s.transfer_amount) AS v2 FROM deposit AS s JOIN view_member_agents AS v ON s.member_login = v.member WHERE 1 = 1 AND v.share_login = 'somevalue' GROUP BY s.member_login UNION select 1 as v1, 2 as v2; +v1 v2 +1 2 +drop table if exists t1, t2; +create table t1 (a float default null, b smallint(6) DEFAULT NULL); +insert into t1 values (1, 1); +create table t2 (a float default null, b tinyint(4) DEFAULT NULL, key b (b)); +insert into t2 values (null, 1); +explain select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b); +id estRows task access object operator info +IndexJoin_12 8000.00 root anti semi join, inner:IndexLookUp_11, outer key:planner__core__integration.t1.b, inner key:planner__core__integration.t2.b, equal cond:eq(planner__core__integration.t1.b, planner__core__integration.t2.b), other cond:eq(planner__core__integration.t1.a, planner__core__integration.t2.a) +├─TableReader_22(Build) 10000.00 root data:TableFullScan_21 +│ └─TableFullScan_21 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─IndexLookUp_11(Probe) 12500.00 root + ├─IndexRangeScan_9(Build) 12500.00 cop[tikv] table:t2, index:b(b) range: decided by [eq(planner__core__integration.t2.b, planner__core__integration.t1.b)], keep order:false, stats:pseudo + └─TableRowIDScan_10(Probe) 12500.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b); +a b +drop table if exists t; +create table t(a int); +insert into t values(1); +select count(a) f1, row_number() over (order by count(a)) as f2 from t limit 1; +f1 f2 +1 1 +set names utf8mb4; +drop table if exists all_types; +CREATE TABLE `all_types` (`id` int(11) NOT NULL,`d_tinyint` tinyint(4) DEFAULT NULL,`d_smallint` smallint(6) DEFAULT NULL,`d_int` int(11) DEFAULT NULL,`d_bigint` bigint(20) DEFAULT NULL,`d_float` float DEFAULT NULL,`d_double` double DEFAULT NULL,`d_decimal` decimal(10,2) DEFAULT NULL,`d_bit` bit(10) DEFAULT NULL,`d_binary` binary(10) DEFAULT NULL,`d_date` date DEFAULT NULL,`d_datetime` datetime DEFAULT NULL,`d_timestamp` timestamp NULL DEFAULT NULL,`d_varchar` varchar(20) NULL default NULL,PRIMARY KEY (`id`)); +select @@collation_connection; +@@collation_connection +utf8mb4_bin +insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123'); +select collation(c) from (select d_date c from all_types union select d_int c from all_types) t; +collation(c) +utf8mb4_bin +utf8mb4_bin +select collation(c) from (select d_date c from all_types union select d_int collate binary c from all_types) t; +collation(c) +binary +binary +select collation(c) from (select d_date c from all_types union select d_float c from all_types) t; +collation(c) +utf8mb4_bin +utf8mb4_bin +select collation(c) from (select d_timestamp c from all_types union select d_float c from all_types) t; +collation(c) +utf8mb4_bin +utf8mb4_bin +drop table if exists t; +create table t (a char(65) collate utf8_unicode_ci, b text collate utf8_general_ci not null); +insert into t values ('a', 'A'); +insert into t values ('b', 'B'); +(select a from t) union ( select b from t); +Error 1271 (HY000): Illegal mix of collations for operation 'UNION' +(select 'a' collate utf8mb4_unicode_ci) union (select 'b' collate utf8mb4_general_ci); +Error 1271 (HY000): Illegal mix of collations for operation 'UNION' +(select a from t) union ( select b from t) union all select 'a'; +Error 1271 (HY000): Illegal mix of collations for operation 'UNION' +(select a from t) union ( select b from t) union select 'a'; +Error 1271 (HY000): Illegal mix of collations for operation 'UNION' +(select a from t) union ( select b from t) union select 'a' except select 'd'; +Error 1271 (HY000): Illegal mix of collations for operation 'UNION' +create table tp (id int primary key) partition by range (id) (partition p0 values less than (100)); +create table tn (id int primary key); +insert into tp values(1),(2); +insert into tn values(1),(2); +select * from tp,tn where tp.id=tn.id and tn.id=1 for update; +id id +1 1 +drop table if exists t; +create table t (pk int primary key auto_increment, year int, c varchar(256), index idx_year(year)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +analyze table t; +set @@tidb_opt_enable_correlation_adjustment = false; +explain format=brief select * from t use index(primary) where year=2002 limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─TableReader 1.00 root data:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─Selection 1.00 cop[tikv] eq(planner__core__integration.t.year, 2002) + └─TableFullScan 3.00 cop[tikv] table:t keep order:false +set @@tidb_opt_enable_correlation_adjustment = true; +explain format=brief select * from t use index(primary) where year=2002 limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─TableReader 1.00 root data:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─Selection 1.00 cop[tikv] eq(planner__core__integration.t.year, 2002) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +truncate table t; +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2003, space(256)); +insert into t (year, c) values (2003, space(256)); +insert into t (year, c) values (2004, space(256)); +insert into t (year, c) values (2004, space(256)); +insert into t (year, c) values (2005, space(256)); +insert into t (year, c) values (2005, space(256)); +insert into t (year, c) values (2006, space(256)); +insert into t (year, c) values (2006, space(256)); +insert into t (year, c) values (2007, space(256)); +insert into t (year, c) values (2007, space(256)); +insert into t (year, c) values (2008, space(256)); +insert into t (year, c) values (2008, space(256)); +insert into t (year, c) values (2009, space(256)); +insert into t (year, c) values (2009, space(256)); +insert into t (year, c) values (2010, space(256)); +insert into t (year, c) values (2010, space(256)); +insert into t (year, c) values (2011, space(256)); +insert into t (year, c) values (2011, space(256)); +insert into t (year, c) values (2012, space(256)); +insert into t (year, c) values (2012, space(256)); +insert into t (year, c) values (2013, space(256)); +insert into t (year, c) values (2013, space(256)); +insert into t (year, c) values (2014, space(256)); +insert into t (year, c) values (2014, space(256)); +insert into t (year, c) values (2015, space(256)); +insert into t (year, c) values (2015, space(256)); +insert into t (year, c) values (2016, space(256)); +insert into t (year, c) values (2016, space(256)); +insert into t (year, c) values (2017, space(256)); +insert into t (year, c) values (2017, space(256)); +insert into t (year, c) values (2018, space(256)); +insert into t (year, c) values (2018, space(256)); +insert into t (year, c) values (2019, space(256)); +insert into t (year, c) values (2019, space(256)); +insert into t (year, c) values (2020, space(256)); +insert into t (year, c) values (2020, space(256)); +insert into t (year, c) values (2021, space(256)); +insert into t (year, c) values (2021, space(256)); +insert into t (year, c) values (2022, space(256)); +insert into t (year, c) values (2022, space(256)); +insert into t (year, c) values (2023, space(256)); +insert into t (year, c) values (2023, space(256)); +insert into t (year, c) values (2024, space(256)); +insert into t (year, c) values (2024, space(256)); +insert into t (year, c) values (2025, space(256)); +insert into t (year, c) values (2025, space(256)); +insert into t (year, c) values (2026, space(256)); +insert into t (year, c) values (2026, space(256)); +insert into t (year, c) values (2027, space(256)); +insert into t (year, c) values (2027, space(256)); +insert into t (year, c) values (2028, space(256)); +insert into t (year, c) values (2028, space(256)); +insert into t (year, c) values (2029, space(256)); +insert into t (year, c) values (2029, space(256)); +insert into t (year, c) values (2030, space(256)); +insert into t (year, c) values (2030, space(256)); +insert into t (year, c) values (2031, space(256)); +insert into t (year, c) values (2031, space(256)); +insert into t (year, c) values (2032, space(256)); +insert into t (year, c) values (2032, space(256)); +insert into t (year, c) values (2033, space(256)); +insert into t (year, c) values (2033, space(256)); +insert into t (year, c) values (2034, space(256)); +insert into t (year, c) values (2034, space(256)); +insert into t (year, c) values (2035, space(256)); +insert into t (year, c) values (2035, space(256)); +insert into t (year, c) values (2036, space(256)); +insert into t (year, c) values (2036, space(256)); +insert into t (year, c) values (2037, space(256)); +insert into t (year, c) values (2037, space(256)); +insert into t (year, c) values (2038, space(256)); +insert into t (year, c) values (2038, space(256)); +insert into t (year, c) values (2039, space(256)); +insert into t (year, c) values (2039, space(256)); +insert into t (year, c) values (2040, space(256)); +insert into t (year, c) values (2040, space(256)); +insert into t (year, c) values (2041, space(256)); +insert into t (year, c) values (2041, space(256)); +insert into t (year, c) values (2042, space(256)); +insert into t (year, c) values (2042, space(256)); +insert into t (year, c) values (2043, space(256)); +insert into t (year, c) values (2043, space(256)); +insert into t (year, c) values (2044, space(256)); +insert into t (year, c) values (2044, space(256)); +insert into t (year, c) values (2045, space(256)); +insert into t (year, c) values (2045, space(256)); +insert into t (year, c) values (2046, space(256)); +insert into t (year, c) values (2046, space(256)); +insert into t (year, c) values (2047, space(256)); +insert into t (year, c) values (2047, space(256)); +insert into t (year, c) values (2048, space(256)); +insert into t (year, c) values (2048, space(256)); +insert into t (year, c) values (2049, space(256)); +insert into t (year, c) values (2049, space(256)); +insert into t (year, c) values (2050, space(256)); +insert into t (year, c) values (2050, space(256)); +analyze table t; +explain format=brief select * from t use index(primary) where year=2000 limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─TableReader 1.00 root data:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─Selection 1.00 cop[tikv] eq(planner__core__integration.t.year, 2000) + └─TableFullScan 51.00 cop[tikv] table:t keep order:false +drop table if exists t1, t2, t3; +create table t1(t1a int, t1b int, t1c int); +create table t2(t2a int, t2b int, t2c int); +create table t3(t3a int, t3b int, t3c int); +with inv as +(select t1a , t3a, sum(t2c) +from t1, t2, t3 +where t2a = t1a +and t2b = t3b +and t3c = 1998 +group by t1a, t3a) +select inv1.t1a, inv2.t3a +from inv inv1, inv inv2 +where inv1.t1a = inv2.t1a +and inv1.t3a = 4 +and inv2.t3a = 4+1; +t1a t3a +drop table if exists t; +create table `t` (`a` int(11) default null, `b` int(11) default null, `c` int(11) default null, key `expression_index` ((case when `a` < 0 then 1 else 2 end))); +select * from t where case when a < 0 then 1 else 2 end <= 1 order by 4; +Error 1054 (42S22): Unknown column '4' in 'order clause' +drop table if exists t6; +CREATE TABLE t6(t TIME, ts TIMESTAMP); +INSERT INTO t6 VALUES ('12:30', '2016-07-05 08:30:42'); +drop view if exists v; +CREATE definer='root'@'localhost' VIEW v AS SELECT COUNT(*) OVER w0, COUNT(*) OVER w from t6 WINDOW w0 AS (), w AS (w0 ORDER BY t); +select * from v; +COUNT(*) OVER w0 COUNT(*) OVER w +1 1 +drop table if exists IDT_MC21814; +CREATE TABLE `IDT_MC21814` (`COL1` year(4) DEFAULT NULL,`COL2` year(4) DEFAULT NULL,KEY `U_M_COL` (`COL1`,`COL2`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into IDT_MC21814 values(1901, 2119), (2155, 2000); +SELECT/*+ INL_JOIN(t1, t2), nth_plan(1) */ t2.* FROM IDT_MC21814 t1 LEFT JOIN IDT_MC21814 t2 ON t1.col1 = t2.col1 WHERE t2.col2 BETWEEN 2593 AND 1971 AND t1.col1 IN (2155, 1901, 1967); +COL1 COL2 +SELECT/*+ INL_JOIN(t1, t2), nth_plan(2) */ t2.* FROM IDT_MC21814 t1 LEFT JOIN IDT_MC21814 t2 ON t1.col1 = t2.col1 WHERE t2.col2 BETWEEN 2593 AND 1971 AND t1.col1 IN (2155, 1901, 1967); +COL1 COL2 +Level Code Message +Warning 1105 The parameter of nth_plan() is out of range +drop table if exists t; +create table t (a int); +insert into t values (1); +analyze table t; +set tidb_opt_limit_push_down_threshold=0; +explain format=brief select a from t order by a desc limit 10; +id estRows task access object operator info +TopN 1.00 root planner__core__integration.t.a:desc, offset:0, count:10 +└─TableReader 1.00 root data:TableFullScan + └─TableFullScan 1.00 cop[tikv] table:t keep order:false +set tidb_opt_limit_push_down_threshold=10; +explain format=brief select a from t order by a desc limit 10; +id estRows task access object operator info +TopN 1.00 root planner__core__integration.t.a:desc, offset:0, count:10 +└─TableReader 1.00 root data:TopN + └─TopN 1.00 cop[tikv] planner__core__integration.t.a:desc, offset:0, count:10 + └─TableFullScan 1.00 cop[tikv] table:t keep order:false +explain format=brief select a from t order by a desc limit 11; +id estRows task access object operator info +TopN 1.00 root planner__core__integration.t.a:desc, offset:0, count:11 +└─TableReader 1.00 root data:TableFullScan + └─TableFullScan 1.00 cop[tikv] table:t keep order:false +explain format=brief select /*+ limit_to_cop() */ a from t order by a desc limit 11; +id estRows task access object operator info +TopN 1.00 root planner__core__integration.t.a:desc, offset:0, count:11 +└─TableReader 1.00 root data:TopN + └─TopN 1.00 cop[tikv] planner__core__integration.t.a:desc, offset:0, count:11 + └─TableFullScan 1.00 cop[tikv] table:t keep order:false +drop table if exists t; +create table t(a timestamp, b datetime); +insert into t values('2020-07-29 09:07:01', '2020-07-27 16:57:36'); +select greatest(a, b) from t union select null; +greatest(a, b) +NULL +2020-07-29 09:07:01 +drop table if exists t1; +set tidb_cost_model_version=2; +create table t1( a enum('y','b','Abc','null'),b enum('y','b','Abc','null'),key(a)); +explain format=brief select * from t1 where a like "A%"; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] like(planner__core__integration.t1.a, "A%", 92) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +explain format=brief select * from t1 where b like "A%"; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] like(planner__core__integration.t1.b, "A%", 92) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +drop table if exists t2; +create table t2( a enum('y','b','Abc','null'),b enum('y','b','Abc','null'),key(a, b)); +explain format=brief select * from t2 where a like "A%"; +id estRows task access object operator info +IndexReader 8000.00 root index:Selection +└─Selection 8000.00 cop[tikv] like(planner__core__integration.t2.a, "A%", 92) + └─IndexFullScan 10000.00 cop[tikv] table:t2, index:a(a, b) keep order:false, stats:pseudo +explain format=brief select * from t2 where a like "A%" and b like "A%"; +id estRows task access object operator info +IndexReader 8000.00 root index:Selection +└─Selection 8000.00 cop[tikv] like(planner__core__integration.t2.a, "A%", 92), like(planner__core__integration.t2.b, "A%", 92) + └─IndexFullScan 10000.00 cop[tikv] table:t2, index:a(a, b) keep order:false, stats:pseudo +drop table if exists t3; +create table t3( a int,b enum('y','b','Abc','null'), c enum('y','b','Abc','null'),key(a, b, c)); +explain format=brief select * from t3 where a = 1 and b like "A%"; +id estRows task access object operator info +IndexReader 8.00 root index:Selection +└─Selection 8.00 cop[tikv] like(planner__core__integration.t3.b, "A%", 92) + └─IndexRangeScan 10.00 cop[tikv] table:t3, index:a(a, b, c) range:[1,1], keep order:false, stats:pseudo +drop table if exists UK_MU16407; +CREATE TABLE UK_MU16407 (COL3 timestamp NULL DEFAULT NULL, UNIQUE KEY U3(COL3)); +insert into UK_MU16407 values("1985-08-31 18:03:27"); +SELECT COL3 FROM UK_MU16407 WHERE COL3>_utf8mb4'2039-1-19 3:14:40'; +COL3 +DROP TABLE UK_MU16407; +drop table if exists t28424, dt28242; +set time_zone='+00:00'; +drop table if exists t28424,dt28424; +create table t28424 (t timestamp); +insert into t28424 values ("2038-01-19 03:14:07"), ("1970-01-01 00:00:01"); +select * from t28424 where t != "2038-1-19 3:14:08"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t < "2038-1-19 3:14:08"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t <= "2038-1-19 3:14:08"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t >= "2038-1-19 3:14:08"; +t +select * from t28424 where t > "2038-1-19 3:14:08"; +t +select * from t28424 where t != "1970-1-1 0:0:0"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t < "1970-1-1 0:0:0"; +t +select * from t28424 where t <= "1970-1-1 0:0:0"; +t +select * from t28424 where t >= "1970-1-1 0:0:0"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t > "1970-1-1 0:0:0"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +alter table t28424 add unique index (t); +select * from t28424 where t != "2038-1-19 3:14:08"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t < "2038-1-19 3:14:08"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t <= "2038-1-19 3:14:08"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t >= "2038-1-19 3:14:08"; +t +select * from t28424 where t > "2038-1-19 3:14:08"; +t +select * from t28424 where t != "1970-1-1 0:0:0"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t < "1970-1-1 0:0:0"; +t +select * from t28424 where t <= "1970-1-1 0:0:0"; +t +select * from t28424 where t >= "1970-1-1 0:0:0"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +select * from t28424 where t > "1970-1-1 0:0:0"; +t +1970-01-01 00:00:01 +2038-01-19 03:14:07 +create table dt28424 (dt datetime); +insert into dt28424 values ("2038-01-19 03:14:07"), ("1970-01-01 00:00:01"); +insert into dt28424 values ("1969-12-31 23:59:59"), ("1970-01-01 00:00:00"), ("2038-03-19 03:14:08"); +select * from t28424 right join dt28424 on t28424.t = dt28424.dt; +t dt +NULL 1969-12-31 23:59:59 +NULL 1970-01-01 00:00:00 +NULL 2038-03-19 03:14:08 +1970-01-01 00:00:01 1970-01-01 00:00:01 +2038-01-19 03:14:07 2038-01-19 03:14:07 +DROP TABLE dt28424; +DROP TABLE t28424; +create temporary table tmp1(a int, b int, c int); +insert into tmp1 values (1,1,1),(2,2,2),(3,3,3),(4,4,4); +with cte1 as (with cte2 as (select * from tmp1) select * from cte2) select * from cte1 left join tmp1 on cte1.c=tmp1.c; +a b c a b c +1 1 1 1 1 1 +2 2 2 2 2 2 +3 3 3 3 3 3 +4 4 4 4 4 4 +with cte1 as (with cte2 as (select * from tmp1) select * from cte2) select * from cte1 t1 left join cte1 t2 on t1.c=t2.c; +a b c a b c +1 1 1 1 1 1 +2 2 2 2 2 2 +3 3 3 3 3 3 +4 4 4 4 4 4 +WITH RECURSIVE cte(a) AS (SELECT 1 UNION SELECT a+1 FROM tmp1 WHERE a < 5) SELECT * FROM cte order by a; +a +1 +2 +3 +4 +5 +SELECT @@session.tidb_partition_prune_mode; +@@session.tidb_partition_prune_mode +dynamic +set @@session.tidb_partition_prune_mode = 'static'; +drop table if exists t27797; +create table t27797(a int, b int, c int, d int) partition by range columns(d) (partition p0 values less than (20),partition p1 values less than(40),partition p2 values less than(60)); +insert into t27797 values(1,1,1,1), (2,2,2,2), (22,22,22,22), (44,44,44,44); +set sql_mode=''; +select count(*) from (select a, b from t27797 where d > 1 and d < 60 and b > 0 group by b, c) tt; +count(*) +3 +drop table if exists IDT_HP24172; +CREATE TABLE `IDT_HP24172` ( `COL1` mediumint(16) DEFAULT NULL, `COL2` varchar(20) DEFAULT NULL, `COL4` datetime DEFAULT NULL, `COL3` bigint(20) DEFAULT NULL, `COL5` float DEFAULT NULL, KEY `UM_COL` (`COL1`,`COL3`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH( `COL1`+`COL3` ) PARTITIONS 8; +insert into IDT_HP24172(col1) values(8388607); +select col2 from IDT_HP24172 where col1 = 8388607 and col1 in (select col1 from IDT_HP24172); +col2 +NULL +set @@session.tidb_partition_prune_mode = DEFAULT; +set sql_mode=DEFAULT; +drop table if exists t; +create table t(a TEXT); +insert into t values('abc'); +select * from t where from_base64(''); +a +update t set a = 'def' where from_base64(''); +Error 1292 (22007): Truncated incorrect DOUBLE value: '' +select * from t where from_base64('invalidbase64'); +a +update t set a = 'hig' where from_base64('invalidbase64'); +select * from t where from_base64('test'); +a +update t set a = 'xyz' where from_base64('test'); +Error 1292 (22007): Truncated incorrect DOUBLE value: '-' +select * from t; +a +abc +drop table if exists t; +drop table if exists tbl_29711; +CREATE TABLE `tbl_29711` (`col_250` text COLLATE utf8_unicode_ci NOT NULL,`col_251` enum('Alice','Bob','Charlie','David') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Charlie',PRIMARY KEY (`col_251`,`col_250`(1)) NONCLUSTERED); +explain format=brief select col_250,col_251 from tbl_29711 where col_251 between 'Bob' and 'David' order by col_250,col_251 limit 6; +id estRows task access object operator info +TopN 6.00 root planner__core__integration.tbl_29711.col_250, planner__core__integration.tbl_29711.col_251, offset:0, count:6 +└─IndexLookUp 6.00 root + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:tbl_29711, index:PRIMARY(col_251, col_250) range:["Bob","Bob"], ["Charlie","Charlie"], ["David","David"], keep order:false, stats:pseudo + └─TopN(Probe) 6.00 cop[tikv] planner__core__integration.tbl_29711.col_250, planner__core__integration.tbl_29711.col_251, offset:0, count:6 + └─TableRowIDScan 30.00 cop[tikv] table:tbl_29711 keep order:false, stats:pseudo +drop table if exists t29711; +CREATE TABLE `t29711` (`a` varchar(10) DEFAULT NULL,`b` int(11) DEFAULT NULL,`c` int(11) DEFAULT NULL,KEY `ia` (`a`(2))); +explain format=brief select * from t29711 use index (ia) order by a limit 10; +id estRows task access object operator info +TopN 10.00 root planner__core__integration.t29711.a, offset:0, count:10 +└─IndexLookUp 10.00 root + ├─IndexFullScan(Build) 10000.00 cop[tikv] table:t29711, index:ia(a) keep order:false, stats:pseudo + └─TopN(Probe) 10.00 cop[tikv] planner__core__integration.t29711.a, offset:0, count:10 + └─TableRowIDScan 10000.00 cop[tikv] table:t29711 keep order:false, stats:pseudo +drop table if exists t; +create table t(a varchar(100), b int, c int, index idx1(a(2), b), index idx2(a)); +explain format = 'verbose' select * from t where a = 'abcdefghijk' and b > 4; +id estRows estCost task access object operator info +IndexLookUp_11 33.33 65346.12 root +├─IndexRangeScan_8(Build) 33.33 9127.55 cop[tikv] table:t, index:idx1(a, b) range:("ab" 4,"ab" +inf], keep order:false, stats:pseudo +└─Selection_10(Probe) 33.33 11066.03 cop[tikv] eq(planner__core__integration.t.a, "abcdefghijk") + └─TableRowIDScan_9 33.33 9402.70 cop[tikv] table:t keep order:false, stats:pseudo +drop table if exists t30094; +create table t30094(a varchar(10)); +explain format = 'brief' select * from t30094 where cast(a as float) and cast(a as char); +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] cast(planner__core__integration.t30094.a, float BINARY), cast(planner__core__integration.t30094.a, var_string(5)) + └─TableFullScan 10000.00 cop[tikv] table:t30094 keep order:false, stats:pseudo +explain format = 'brief' select * from t30094 where concat(a,'1') = _binary 0xe59388e59388e59388 collate binary and concat(a,'1') = _binary 0xe598bfe598bfe598bf collate binary; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(concat(planner__core__integration.t30094.a, "1"), "0xe59388e59388e59388"), eq(concat(planner__core__integration.t30094.a, "1"), "0xe598bfe598bfe598bf") + └─TableFullScan 10000.00 cop[tikv] table:t30094 keep order:false, stats:pseudo +SELECT @@session.tidb_partition_prune_mode; +@@session.tidb_partition_prune_mode +dynamic +set @@session.tidb_partition_prune_mode = 'static'; +drop table if exists t; +create table t(id int) partition by hash(id) partitions 4; +insert into t values(1); +SELECT COUNT(1) FROM ( SELECT COUNT(1) FROM t b GROUP BY id) a; +COUNT(1) +1 +set @@session.tidb_partition_prune_mode = DEFAULT; +drop table if exists t; +create table t(a char(10), b char(10), c char(10), index (a, b, c)) collate utf8mb4_bin; +insert into t values ('b', 'a', '1'), ('b', 'A', '2'), ('c', 'a', '3'); +set names utf8mb4 collate utf8mb4_general_ci; +select * from t where (a>'a' and b='a') or (b = 'A' and a < 'd') order by a,c; +a b c +b a 1 +b A 2 +c a 3 +drop table if exists t1, t2; +create table t1(a int, b int); +create table t2(a int, b int); +select avg(0) over w from t1 window w as (order by (select 1)); +avg(0) over w +select avg(0) over w from t1 where b > (select sum(t2.a) over w from t2) window w as (partition by t1.b); +Error 3579 (HY000): Window name 'w' is not defined. +select avg(0) over w1 from t1 where b > (select sum(t2.a) over w2 from t2 window w2 as (partition by t2.b)) window w1 as (partition by t1.b); +avg(0) over w1 +drop table if exists t1; +create table t1(c1 int, c2 int); +select /*+ use_index_merge(t1) */ * from t1 where c1 < 1 or c2 < 1; +c1 c2 +Level Code Message +Warning 1105 IndexMerge is inapplicable or disabled. No available filter or available index. +drop table if exists t1; +create table t1(c1 int, c2 int, key(c1), key(c2)); +select /*+ use_index_merge(t1), no_index_merge() */ * from t1 where c1 < 1 or c2 < 1; +c1 c2 +Level Code Message +Warning 1105 IndexMerge is inapplicable or disabled. Got no_index_merge hint or tidb_enable_index_merge is off. +drop table if exists t1; +create temporary table t1(c1 int, c2 int, key(c1), key(c2)); +select /*+ use_index_merge(t1) */ * from t1 where c1 < 1 or c2 < 1; +c1 c2 +Level Code Message +Warning 1105 IndexMerge is inapplicable or disabled. Cannot use IndexMerge on temporary table. +drop table if exists t1, t2; +CREATE TABLE t1 (a int PRIMARY KEY, b int); +CREATE TABLE t2 (a int PRIMARY KEY, b int); +INSERT INTO t1 VALUES (1,1), (2,1), (3,1), (4,2); +INSERT INTO t2 VALUES (1,2), (2,2); +explain format=brief SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE not(0+(t1.a=30 and t2.b=1)); +id estRows task access object operator info +Selection 8000.00 root not(plus(0, and(eq(planner__core__integration.t1.a, 30), eq(planner__core__integration.t2.b, 1)))) +└─MergeJoin 10000.00 root left outer join, left key:planner__core__integration.t1.a, right key:planner__core__integration.t2.a + ├─TableReader(Build) 8000.00 root data:Selection + │ └─Selection 8000.00 cop[tikv] not(istrue_with_null(plus(0, and(eq(planner__core__integration.t2.a, 30), eq(planner__core__integration.t2.b, 1))))) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE not(0+(t1.a=30 and t2.b=1)); +a b a b +1 1 1 2 +2 1 2 2 +3 1 NULL NULL +4 2 NULL NULL +drop table if exists t1; +create table t1(c1 longtext, c2 decimal(37, 4), unique key(c1(10)), unique key(c2)); +insert into t1 values('眐', -962541614831459.7458); +select * from t1 order by c2 + 10; +c1 c2 +眐 -962541614831459.7458 +drop table if exists t1; +create table t1(a int, b int, c int); +insert into t1 value(10,10,10); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 value(1,1,1); +analyze table t1; +explain format = 'brief' select * from t1 where a=1 or b=1; +id estRows task access object operator info +TableReader 1.99 root data:Selection +└─Selection 1.99 cop[tikv] or(eq(planner__core__integration.t1.a, 1), eq(planner__core__integration.t1.b, 1)) + └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false +explain format = 'brief' select * from t1 where 0=1 or a=1 or b=1; +id estRows task access object operator info +TableReader 1.99 root data:Selection +└─Selection 1.99 cop[tikv] or(0, or(eq(planner__core__integration.t1.a, 1), eq(planner__core__integration.t1.b, 1))) + └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false +explain format = 'brief' select * from t1 where null or a=1 or b=1; +id estRows task access object operator info +TableReader 1.99 root data:Selection +└─Selection 1.99 cop[tikv] or(0, or(eq(planner__core__integration.t1.a, 1), eq(planner__core__integration.t1.b, 1))) + └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false +explain format = 'brief' select * from t1 where a=1 or false or b=1; +id estRows task access object operator info +TableReader 1.99 root data:Selection +└─Selection 1.99 cop[tikv] or(eq(planner__core__integration.t1.a, 1), or(0, eq(planner__core__integration.t1.b, 1))) + └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false +explain format = 'brief' select * from t1 where a=1 or b=1 or "false"; +id estRows task access object operator info +TableReader 1.99 root data:Selection +└─Selection 1.99 cop[tikv] or(eq(planner__core__integration.t1.a, 1), or(eq(planner__core__integration.t1.b, 1), 0)) + └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false +explain format = 'brief' select * from t1 where 1=1 or a=1 or b=1; +id estRows task access object operator info +TableReader 129.00 root data:Selection +└─Selection 129.00 cop[tikv] or(1, or(eq(planner__core__integration.t1.a, 1), eq(planner__core__integration.t1.b, 1))) + └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false +explain format = 'brief' select * from t1 where a=1 or b=1 or 1=1; +id estRows task access object operator info +TableReader 129.00 root data:Selection +└─Selection 129.00 cop[tikv] or(eq(planner__core__integration.t1.a, 1), or(eq(planner__core__integration.t1.b, 1), 1)) + └─TableFullScan 129.00 cop[tikv] table:t1 keep order:false +drop table if exists t1; +create database natural_join_update; +use natural_join_update; +create table t1(a int, b int); +insert into t1 values (1,1),(2,2); +update t1 as a natural join t1 b SET a.a = 2, b.b = 3; +select * from t1; +a b +2 3 +2 3 +drop table t1; +create table t1 (a int primary key, b int); +insert into t1 values (1,1),(2,2); +update t1 as a natural join t1 b SET a.a = 2, b.b = 3; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'a' and 'b'. +drop table t1; +create table t1 (a int, b int) partition by hash (a) partitions 3; +insert into t1 values (1,1),(2,2); +update t1 as a natural join t1 b SET a.a = 2, b.b = 3; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'a' and 'b'. +drop table t1; +create table t1 (A int, b int) partition by hash (b) partitions 3; +insert into t1 values (1,1),(2,2); +update t1 as a natural join t1 B SET a.A = 2, b.b = 3; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'a' and 'B'. +update t1 as a natural join t1 B SET a.A = 2, b.b = 3; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'a' and 'B'. +drop table t1; +create table t1 (A int, b int) partition by RANGE COLUMNS (b) (partition `pNeg` values less than (0),partition `pPos` values less than MAXVALUE); +insert into t1 values (1,1),(2,2); +update t1 as a natural join t1 B SET a.A = 2, b.b = 3; +Error 1706 (HY000): Primary key/partition key update is not allowed since the table is updated both as 'a' and 'B'. +drop table t1; +drop database natural_join_update; +use planner__core__integration; +drop table if exists t1, t2; +create table t1(id int primary key, col1 int); +create table t2(id int primary key, col1 int); +explain format='brief' SELECT /*+ merge_join(t1, t2)*/ * FROM (t1 LEFT JOIN t2 ON t1.col1=t2.id) order by t2.id; +id estRows task access object operator info +Sort 12500.00 root planner__core__integration.t2.id +└─MergeJoin 12500.00 root left outer join, left key:planner__core__integration.t1.col1, right key:planner__core__integration.t2.id + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo + └─Sort(Probe) 10000.00 root planner__core__integration.t1.col1 + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +drop table if exists t1; +drop table if exists t2; +create table t1 (a int, b int); +create table t2 (c int, d int); +insert into t1 values(1, 1), (1,2),(2,1),(2,2); +insert into t2 values(1, 3), (1,4),(2,5),(2,6); +explain select one.a from t1 one order by (select two.d from t2 two where two.c = one.b); +id estRows task access object operator info +Projection_16 10000.00 root planner__core__integration.t1.a +└─Sort_17 10000.00 root planner__core__integration.t2.d + └─Apply_20 10000.00 root CARTESIAN left outer join + ├─TableReader_22(Build) 10000.00 root data:TableFullScan_21 + │ └─TableFullScan_21 10000.00 cop[tikv] table:one keep order:false, stats:pseudo + └─MaxOneRow_23(Probe) 10000.00 root + └─TableReader_26 20000.00 root data:Selection_25 + └─Selection_25 20000.00 cop[tikv] eq(planner__core__integration.t2.c, planner__core__integration.t1.b) + └─TableFullScan_24 20000000.00 cop[tikv] table:two keep order:false, stats:pseudo +explain select rank() over (partition by table_name) from information_schema.tables; +id estRows task access object operator info +Projection_7 10000.00 root Column#27->Column#28 +└─Shuffle_11 10000.00 root execution info: concurrency:5, data sources:[MemTableScan_9] + └─Window_8 10000.00 root rank()->Column#27 over(partition by Column#3) + └─Sort_10 10000.00 root Column#3 + └─MemTableScan_9 10000.00 root table:TABLES +drop table if exists t; +create table deci (a decimal(65,30),b decimal(65,0)); +insert into deci values (1234567890.123456789012345678901234567890,987654321098765432109876543210987654321098765432109876543210); +select a from deci union ALL select b from deci; +a +1234567890.123456789012345678901234567890 +99999999999999999999999999999999999.999999999999999999999999999999 +drop table if exists t; +create table t(a json); +insert into t values('{"id": "ish"}'); +select t2.a from t t1 left join t t2 on t1.a=t2.a where t2.a->'$.id'='ish'; +a +{"id": "ish"} +explain format = 'brief' select * from t t1 left join t t2 on t1.a=t2.a where t2.a->'$.id'='ish'; +id estRows task access object operator info +Selection 8000.00 root eq(json_extract(planner__core__integration.t.a, "$.id"), cast("ish", json BINARY)) +└─HashJoin 10000.00 root left outer join, equal:[eq(planner__core__integration.t.a, planner__core__integration.t.a)] + ├─TableReader(Build) 8000.00 root data:Selection + │ └─Selection 8000.00 cop[tikv] not(isnull(cast(planner__core__integration.t.a, var_string(4294967295)))) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +drop table if exists t, t2; +set @@tidb_partition_prune_mode='static'; +CREATE TABLE t (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6),PARTITION p1 VALUES LESS THAN (11)); +insert into t values (1),(2),(3),(4),(7),(8),(9),(10); +analyze table t; +explain format='brief' select * from t; +id estRows task access object operator info +PartitionUnion 8.00 root +├─TableReader 4.00 root data:TableFullScan +│ └─TableFullScan 4.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 4.00 root data:TableFullScan + └─TableFullScan 4.00 cop[tikv] table:t, partition:p1 keep order:false +CREATE TABLE t2 (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6),PARTITION p1 VALUES LESS THAN (11)); +insert into t2 values (1),(2),(3),(4),(7),(8),(9),(10); +analyze table t2; +set @@tidb_partition_prune_mode='dynamic'; +explain format='brief' select * from t; +id estRows task access object operator info +PartitionUnion 8.00 root +├─TableReader 4.00 root data:TableFullScan +│ └─TableFullScan 4.00 cop[tikv] table:t, partition:p0 keep order:false +└─TableReader 4.00 root data:TableFullScan + └─TableFullScan 4.00 cop[tikv] table:t, partition:p1 keep order:false +analyze table t; +explain format='brief' select * from t; +id estRows task access object operator info +TableReader 8.00 root partition:all data:TableFullScan +└─TableFullScan 8.00 cop[tikv] table:t keep order:false +explain format='brief' select * from t union all select * from t2; +id estRows task access object operator info +Union 16.00 root +├─PartitionUnion 8.00 root +│ ├─TableReader 4.00 root data:TableFullScan +│ │ └─TableFullScan 4.00 cop[tikv] table:t, partition:p0 keep order:false +│ └─TableReader 4.00 root data:TableFullScan +│ └─TableFullScan 4.00 cop[tikv] table:t, partition:p1 keep order:false +└─PartitionUnion 8.00 root + ├─TableReader 4.00 root data:TableFullScan + │ └─TableFullScan 4.00 cop[tikv] table:t2, partition:p0 keep order:false + └─TableReader 4.00 root data:TableFullScan + └─TableFullScan 4.00 cop[tikv] table:t2, partition:p1 keep order:false +set @@tidb_partition_prune_mode=DEFAULT; +drop table if exists t1, t2; +create table t1 (a int primary key, b int); +create table t2 (c int); +explain format='brief' select * from t1 where a in (10, 20, 30, 40, 50) and b > 1; +id estRows task access object operator info +Selection 1.67 root gt(planner__core__integration.t1.b, 1) +└─Batch_Point_Get 5.00 root table:t1 handle:[10 20 30 40 50], keep order:false, desc:false +explain format='brief' select * from t1 join t2 on t1.b = t2.c where t1.a in (10, 20, 30, 40, 50); +id estRows task access object operator info +HashJoin 6.24 root inner join, equal:[eq(planner__core__integration.t1.b, planner__core__integration.t2.c)] +├─Selection(Build) 5.00 root not(isnull(planner__core__integration.t1.b)) +│ └─Batch_Point_Get 5.00 root table:t1 handle:[10 20 30 40 50], keep order:false, desc:false +└─TableReader(Probe) 9990.00 root data:Selection + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__integration.t2.c)) + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +set @@tidb_opt_range_max_size=10; +explain format='brief' select * from t1 where a in (10, 20, 30, 40, 50) and b > 1; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] gt(planner__core__integration.t1.b, 1), in(planner__core__integration.t1.a, 10, 20, 30, 40, 50) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Level Code Message +Warning 1105 Memory capacity of 10 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +explain format='brief' select * from t1 join t2 on t1.b = t2.c where t1.a in (10, 20, 30, 40, 50); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__integration.t1.b, planner__core__integration.t2.c)] +├─TableReader(Build) 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] not(isnull(planner__core__integration.t2.c)) +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +└─TableReader(Probe) 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(planner__core__integration.t1.a, 10, 20, 30, 40, 50), not(isnull(planner__core__integration.t1.b)) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Level Code Message +Warning 1105 Memory capacity of 10 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +drop table if exists t1, t2, t3, t4; +create table t1 (a varchar(10), b varchar(10), c varchar(10), index idx_a_b(a(2), b(2))); +create table t2 (d varchar(10)); +create table t3 (pk int primary key, a int, key(a)); +create table t4 (a int, b int, c int, index idx_a_b(a, b)); +set @@tidb_opt_range_max_size=0; +explain format='brief' select * from t1 where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +id estRows task access object operator info +IndexLookUp 0.90 root +├─IndexRangeScan(Build) 0.90 cop[tikv] table:t1, index:idx_a_b(a, b) range:["aa" "dd","aa" "dd"], ["aa" "ee","aa" "ee"], ["aa" "ff","aa" "ff"], ["bb" "dd","bb" "dd"], ["bb" "ee","bb" "ee"], ["bb" "ff","bb" "ff"], ["cc" "dd","cc" "dd"], ["cc" "ee","cc" "ee"], ["cc" "ff","cc" "ff"], keep order:false, stats:pseudo +└─Selection(Probe) 0.90 cop[tikv] in(planner__core__integration.t1.a, "aaa", "bbb", "ccc"), in(planner__core__integration.t1.b, "ddd", "eee", "fff") + └─TableRowIDScan 0.90 cop[tikv] table:t1 keep order:false, stats:pseudo +set @@tidb_opt_range_max_size=1000; +explain format='brief' select * from t1 where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +id estRows task access object operator info +IndexLookUp 0.09 root +├─IndexRangeScan(Build) 30.00 cop[tikv] table:t1, index:idx_a_b(a, b) range:["aa","aa"], ["bb","bb"], ["cc","cc"], keep order:false, stats:pseudo +└─Selection(Probe) 0.09 cop[tikv] in(planner__core__integration.t1.a, "aaa", "bbb", "ccc"), in(planner__core__integration.t1.b, "ddd", "eee", "fff") + └─TableRowIDScan 30.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Level Code Message +Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +set @@tidb_opt_range_max_size=0; +explain format='brief' select * from t1 join t2 on t1.c = t2.d where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +id estRows task access object operator info +HashJoin 1.12 root inner join, equal:[eq(planner__core__integration.t1.c, planner__core__integration.t2.d)] +├─IndexLookUp(Build) 0.90 root +│ ├─IndexRangeScan(Build) 0.90 cop[tikv] table:t1, index:idx_a_b(a, b) range:["aa" "dd","aa" "dd"], ["aa" "ee","aa" "ee"], ["aa" "ff","aa" "ff"], ["bb" "dd","bb" "dd"], ["bb" "ee","bb" "ee"], ["bb" "ff","bb" "ff"], ["cc" "dd","cc" "dd"], ["cc" "ee","cc" "ee"], ["cc" "ff","cc" "ff"], keep order:false, stats:pseudo +│ └─Selection(Probe) 0.90 cop[tikv] in(planner__core__integration.t1.a, "aaa", "bbb", "ccc"), in(planner__core__integration.t1.b, "ddd", "eee", "fff"), not(isnull(planner__core__integration.t1.c)) +│ └─TableRowIDScan 0.90 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 9990.00 root data:Selection + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__integration.t2.d)) + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +set @@tidb_opt_range_max_size=1000; +explain format='brief' select * from t1 join t2 on t1.c = t2.d where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +id estRows task access object operator info +HashJoin 0.11 root inner join, equal:[eq(planner__core__integration.t1.c, planner__core__integration.t2.d)] +├─IndexLookUp(Build) 0.09 root +│ ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t1, index:idx_a_b(a, b) range:["aa","aa"], ["bb","bb"], ["cc","cc"], keep order:false, stats:pseudo +│ └─Selection(Probe) 0.09 cop[tikv] in(planner__core__integration.t1.a, "aaa", "bbb", "ccc"), in(planner__core__integration.t1.b, "ddd", "eee", "fff"), not(isnull(planner__core__integration.t1.c)) +│ └─TableRowIDScan 30.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 9990.00 root data:Selection + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__integration.t2.d)) + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +Level Code Message +Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +set @@tidb_opt_range_max_size=0; +explain format='brief' select /*+ use_index(t3, a) */ * from t3 where a in (1, 3, 5) and pk in (2, 4, 6); +id estRows task access object operator info +IndexReader 0.90 root index:IndexRangeScan +└─IndexRangeScan 0.90 cop[tikv] table:t3, index:a(a) range:[1 2,1 2], [1 4,1 4], [1 6,1 6], [3 2,3 2], [3 4,3 4], [3 6,3 6], [5 2,5 2], [5 4,5 4], [5 6,5 6], keep order:false, stats:pseudo +set @@tidb_opt_range_max_size=1000; +explain format='brief' select /*+ use_index(t3, a) */ * from t3 where a in (1, 3, 5) and pk in (2, 4, 6); +id estRows task access object operator info +IndexReader 0.01 root index:Selection +└─Selection 0.01 cop[tikv] in(planner__core__integration.t3.pk, 2, 4, 6) + └─IndexRangeScan 30.00 cop[tikv] table:t3, index:a(a) range:[1,1], [3,3], [5,5], keep order:false, stats:pseudo +Level Code Message +Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +set @@tidb_opt_range_max_size=0; +explain format='brief' select /*+ use_index(t4, idx_a_b) */ * from t4 where a in (1, 3, 5) and b = 2; +id estRows task access object operator info +IndexLookUp 0.30 root +├─IndexRangeScan(Build) 0.30 cop[tikv] table:t4, index:idx_a_b(a, b) range:[1 2,1 2], [3 2,3 2], [5 2,5 2], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.30 cop[tikv] table:t4 keep order:false, stats:pseudo +set @@tidb_opt_range_max_size=1000; +explain format='brief' select /*+ use_index(t4, idx_a_b) */ * from t4 where a in (1, 3, 5) and b = 2; +id estRows task access object operator info +IndexLookUp 0.03 root +├─Selection(Build) 0.03 cop[tikv] eq(planner__core__integration.t4.b, 2) +│ └─IndexRangeScan 30.00 cop[tikv] table:t4, index:idx_a_b(a, b) range:[1,1], [3,3], [5,5], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.03 cop[tikv] table:t4 keep order:false, stats:pseudo +Level Code Message +Warning 1105 Memory capacity of 1000 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +set @@tidb_opt_range_max_size=DEFAULT; +set @@tidb_enable_prepared_plan_cache=1; +drop table if exists t; +create table t (a int primary key, b int); +set @@tidb_opt_range_max_size=10; +prepare stmt from 'select * from t where a in (?, ?, ?, ?, ?) and b > 1'; +set @a=10, @b=20, @c=30, @d=40, @e=50; +execute stmt using @a, @b, @c, @d, @e; +a b +execute stmt using @a, @b, @c, @d, @e; +a b +Level Code Message +Warning 1105 Memory capacity of 10 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +Warning 1105 skip prepared plan-cache: in-list is too long +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +drop table if exists t; +create table t(a int primary key); +insert into t values (2), (4), (6); +set @@tidb_opt_range_max_size=1; +select * from t where a; +a +2 +4 +6 +Level Code Message +Warning 1105 Memory capacity of 1 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +set @@tidb_opt_range_max_size=DEFAULT; +drop table if exists t0; +drop view if exists v0; +CREATE TABLE t0(c0 BLOB(298) , c1 BLOB(182) , c2 NUMERIC); +CREATE VIEW v0(c0) AS SELECT t0.c1 FROM t0; +INSERT INTO t0 VALUES (-1, 'a', '2046549365'); +CREATE INDEX i0 ON t0(c2); +SELECT t0.c1, t0.c2 FROM t0 GROUP BY MOD(t0.c0, DEFAULT(t0.c2)); +Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'planner__core__integration.t0.c1' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by +UPDATE t0 SET c2=1413; +drop table if exists t1, t2; +create table t1 (a int, c int); +insert into t1 values (1, 1), (1, 2), (2, 3), (2, 4); +create table t2 (a int, c int); +insert into t2 values (1, 1), (1, 2), (2, 3), (2, 4); +select group_concat(c order by (select group_concat(c order by a) from t2 where a=t1.a)) from t1; +group_concat(c order by (select group_concat(c order by a) from t2 where a=t1.a)) +2,1,4,3 +select group_concat(c order by (select group_concat(c order by c) from t2 where a=t1.a), c desc) from t1; +group_concat(c order by (select group_concat(c order by c) from t2 where a=t1.a), c desc) +2,1,4,3 +drop table if exists t0, t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +INSERT INTO t0 VALUES (NULL); +SELECT t0.c0 FROM t0 LEFT JOIN t1 ON t0.c0>=t1.c0 WHERE (CONCAT_WS(t0.c0, t1.c0) IS NULL); +c0 +NULL +drop table if exists t; +CREATE TABLE t(col1 enum('p5', '9a33x') NOT NULL DEFAULT 'p5',col2 tinyblob DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = latin1 COLLATE = latin1_bin; +(select last_value(col1) over () as r0 from t) union all (select col2 as r0 from t); +r0 +drop table if exists t; +create table t (a int, b int, c int, index ia(a)); +select * from t t1 join t t2 on t1.b = t2.b join t t3 on t2.b=t3.b join t t4 on t3.b=t4.b where t3.a=1 and t2.a=2; +a b c a b c a b c a b c +select plan from information_schema.statements_summary where SCHEMA_NAME = 'test' and STMT_TYPE = 'Select'; +plan +CREATE TABLE `sbtest1` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `k` int(11) NOT NULL DEFAULT '0', `c` char(120) NOT NULL DEFAULT '', `pad` char(60) NOT NULL DEFAULT '', PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ , KEY `k_1` (`k`) ); +set @@tidb_opt_range_max_size = 111; +explain format='brief' select * from planner__core__integration.sbtest1 a where pad in ('1','1','1','1','1') and id in (1,1,1,1,1); +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] in(planner__core__integration.sbtest1.id, 1, 1, 1, 1, 1), in(planner__core__integration.sbtest1.pad, "1", "1", "1", "1", "1") + └─TableFullScan 10000.00 cop[tikv] table:a keep order:false, stats:pseudo +Level Code Message +Warning 1105 Memory capacity of 111 bytes for 'tidb_opt_range_max_size' exceeded when building ranges. Less accurate ranges such as full range are chosen +set @@tidb_opt_range_max_size = DEFAULT; +drop table if exists t1, t2, t3, t4; +create table t1 (c1 int, c2 int, c3 int, primary key(c1, c2)); +create table t2 (c2 int, c1 int, primary key(c2, c1)); +create table t3 (c4 int, key(c4)); +create table t4 (c2 varchar(20) , test_col varchar(50), gen_col varchar(50) generated always as(concat(test_col,'')) virtual not null, unique key(gen_col)); +select count(1) +from (select ( case +when count(1) +over( +partition by a.c2) >= 50 then 1 +else 0 +end ) alias1, +b.c2 as alias_col1 +from t1 a +left join (select c2 +from t4 f) k +on k.c2 = a.c2 +inner join t2 b +on b.c1 = a.c3) alias2 +where exists (select 1 +from (select distinct alias3.c4 as c2 +from t3 alias3) alias4 +where alias4.c2 = alias2.alias_col1); +count(1) +0 +drop table if exists planner__core__integration.first_range; +create table planner__core__integration.first_range(p int not null, o tinyint not null, v int not null); +insert into planner__core__integration.first_range (p, o, v) values (0, 0, 0), (1, 1, 1), (1, 2, 2), (1, 4, 4), (1, 8, 8), (2, 0, 0), (2, 3, 3), (2, 10, 10), (2, 13, 13), (2, 15, 15), (3, 1, 1), (3, 3, 3), (3, 5, 5), (3, 9, 9), (3, 15, 15), (3, 20, 20), (3, 31, 31); +select *, first_value(v) over (partition by p order by o range between 3.1 preceding and 2.9 following) as a from planner__core__integration.first_range; +p o v a +0 0 0 0 +1 1 1 1 +1 2 2 1 +1 4 4 1 +1 8 8 8 +2 0 0 0 +2 10 10 10 +2 13 13 10 +2 15 15 13 +2 3 3 0 +3 1 1 1 +3 15 15 15 +3 20 20 20 +3 3 3 1 +3 31 31 31 +3 5 5 3 +3 9 9 9 +set @@tidb_enable_pipelined_window_function=0; +select *, first_value(v) over (partition by p order by o range between 3.1 preceding and 2.9 following) as a from planner__core__integration.first_range; +p o v a +0 0 0 0 +1 1 1 1 +1 2 2 1 +1 4 4 1 +1 8 8 8 +2 0 0 0 +2 10 10 10 +2 13 13 10 +2 15 15 13 +2 3 3 0 +3 1 1 1 +3 15 15 15 +3 20 20 20 +3 3 3 1 +3 31 31 31 +3 5 5 3 +3 9 9 9 +set @@tidb_enable_pipelined_window_function=DEFAULT; diff --git a/tests/integrationtest/r/planner/core/integration_partition.result b/tests/integrationtest/r/planner/core/integration_partition.result new file mode 100644 index 0000000000..ef2583b649 --- /dev/null +++ b/tests/integrationtest/r/planner/core/integration_partition.result @@ -0,0 +1,1290 @@ +create database list_partition_dml; +use list_partition_dml; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist partition(p0) values (0), (1); +insert into tlist partition(p0, p1) values (2), (3), (8), (9); +insert into tlist partition(p0) values (9); +Error 1748 (HY000): Found a row not matching the given partition set +insert into tlist partition(p3) values (20); +Error 1735 (HY000): Unknown partition 'p3' in table 'tlist' +update tlist partition(p0) set a=a+1; +select a from tlist order by a; +a +1 +2 +3 +4 +8 +9 +update tlist partition(p0, p1) set a=a-1; +select a from tlist order by a; +a +0 +1 +2 +3 +7 +8 +delete from tlist partition(p1); +select a from tlist order by a; +a +0 +1 +2 +3 +delete from tlist partition(p0, p2); +select a from tlist order by a; +a +create table tcollist (a int) partition by list columns(a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist partition(p0) values (0), (1); +insert into tcollist partition(p0, p1) values (2), (3), (8), (9); +insert into tcollist partition(p0) values (9); +Error 1748 (HY000): Found a row not matching the given partition set +insert into tcollist partition(p3) values (20); +Error 1735 (HY000): Unknown partition 'p3' in table 'tcollist' +update tcollist partition(p0) set a=a+1; +select a from tcollist order by a; +a +1 +2 +3 +4 +8 +9 +update tcollist partition(p0, p1) set a=a-1; +select a from tcollist order by a; +a +0 +1 +2 +3 +7 +8 +delete from tcollist partition(p1); +select a from tcollist order by a; +a +0 +1 +2 +3 +delete from tcollist partition(p0, p2); +select a from tcollist order by a; +a +create database list_partition_cre; +use list_partition_cre; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tuk1 (a int, b int, unique key(a)) partition by list (a) (partition p0 values in (0)); +create table tuk2 (a int, b int, unique key(a)) partition by list (b) (partition p0 values in (0)); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +create table tuk2 (a int, b int, unique key(a), unique key(b)) partition by list (a) (partition p0 values in (0)); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +create table tcoluk1 (a int, b int, unique key(a)) partition by list columns(a) (partition p0 values in (0)); +create table tcoluk2 (a int, b int, unique key(a)) partition by list columns(b) (partition p0 values in (0)); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +create table tcoluk2 (a int, b int, unique key(a), unique key(b)) partition by list columns(a) (partition p0 values in (0)); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +create table tpk1 (a int, b int, primary key(a)) partition by list (a) (partition p0 values in (0)); +create table tpk2 (a int, b int, primary key(a, b)) partition by list (a) (partition p0 values in (0)); +create table tcolpk1 (a int, b int, primary key(a)) partition by list columns(a) (partition p0 values in (0)); +create table tcolpk2 (a int, b int, primary key(a, b)) partition by list columns(a) (partition p0 values in (0)); +create table tidx1 (a int, b int, key(a), key(b)) partition by list (a) (partition p0 values in (0)); +create table tidx2 (a int, b int, key(a, b), key(b)) partition by list (a) (partition p0 values in (0)); +create table tcolidx1 (a int, b int, key(a), key(b)) partition by list columns(a) (partition p0 values in (0)); +create table tcolidx2 (a int, b int, key(a, b), key(b)) partition by list columns(a) (partition p0 values in (0)); +create table texp1 (a int, b int) partition by list(a-10000) (partition p0 values in (0)); +create table texp2 (a int, b int) partition by list(a%b) (partition p0 values in (0)); +create table texp3 (a int, b int) partition by list(a*b) (partition p0 values in (0)); +create table texp4 (a int, b int) partition by list(a|b) (partition p0 values in (0)); +Error 1564 (HY000): This partition function is not allowed +create table texp4 (a int, b int) partition by list(a^b) (partition p0 values in (0)); +Error 1564 (HY000): This partition function is not allowed +create table texp4 (a int, b int) partition by list(a&b) (partition p0 values in (0)); +Error 1564 (HY000): This partition function is not allowed +create database list_partition_ddl; +use list_partition_ddl; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, b int) partition by list (a) (partition p0 values in (0)); +alter table tlist add primary key (b); +Error 1503 (HY000): A PRIMARY must include all columns in the table's partitioning function +alter table tlist add primary key (a); +alter table tlist add unique key (b); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +alter table tlist add key (b); +alter table tlist rename index b to bb; +alter table tlist drop index bb; +create table tcollist (a int, b int) partition by list columns (a) (partition p0 values in (0)); +alter table tcollist add primary key (b); +Error 1503 (HY000): A PRIMARY must include all columns in the table's partitioning function +alter table tcollist add primary key (a); +alter table tcollist add unique key (b); +Error 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function +alter table tcollist add key (b); +alter table tcollist rename index b to bb; +alter table tcollist drop index bb; +alter table tlist add column c varchar(8); +alter table tlist rename column c to cc; +alter table tlist drop column cc; +alter table tcollist add column c varchar(8); +alter table tcollist rename column c to cc; +alter table tcollist drop column cc; +alter table tlist rename to tlistxx; +truncate tlistxx; +drop table tlistxx; +alter table tcollist rename to tcollistxx; +truncate tcollistxx; +drop table tcollistxx; +create database list_partition_op; +use list_partition_op; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14), +partition p3 values in (15, 16, 17, 18, 19)); +create table tcollist (a int) partition by list columns(a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14), +partition p3 values in (15, 16, 17, 18, 19)); +insert into tlist values (0), (5), (10), (15); +select * from tlist; +a +0 +10 +15 +5 +alter table tlist truncate partition p0; +select * from tlist; +a +10 +15 +5 +alter table tlist truncate partition p1, p2; +select * from tlist; +a +15 +insert into tcollist values (0), (5), (10), (15); +select * from tcollist; +a +0 +10 +15 +5 +alter table tcollist truncate partition p0; +select * from tcollist; +a +10 +15 +5 +alter table tcollist truncate partition p1, p2; +select * from tcollist; +a +15 +insert into tlist values (0), (5), (10); +select * from tlist; +a +0 +10 +15 +5 +alter table tlist drop partition p0; +select * from tlist; +a +10 +15 +5 +select * from tlist partition (p0); +Error 1735 (HY000): Unknown partition 'p0' in table 'tlist' +alter table tlist drop partition p1, p2; +select * from tlist; +a +15 +select * from tlist partition (p1); +Error 1735 (HY000): Unknown partition 'p1' in table 'tlist' +alter table tlist drop partition p3; +Error 1508 (HY000): Cannot remove all partitions, use DROP TABLE instead +insert into tcollist values (0), (5), (10); +select * from tcollist; +a +0 +10 +15 +5 +alter table tcollist drop partition p0; +select * from tcollist; +a +10 +15 +5 +select * from tcollist partition (p0); +Error 1735 (HY000): Unknown partition 'p0' in table 'tcollist' +alter table tcollist drop partition p1, p2; +select * from tcollist; +a +15 +select * from tcollist partition (p1); +Error 1735 (HY000): Unknown partition 'p1' in table 'tcollist' +alter table tcollist drop partition p3; +Error 1508 (HY000): Cannot remove all partitions, use DROP TABLE instead +alter table tlist add partition (partition p0 values in (0, 1, 2, 3, 4)); +alter table tlist add partition (partition p1 values in (5, 6, 7, 8, 9), partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (5), (10); +select * from tlist; +a +0 +10 +15 +5 +alter table tlist add partition (partition pxxx values in (4)); +Error 1495 (HY000): Multiple definition of same constant in list partitioning +alter table tcollist add partition (partition p0 values in (0, 1, 2, 3, 4)); +alter table tcollist add partition (partition p1 values in (5, 6, 7, 8, 9), partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (5), (10); +select * from tcollist; +a +0 +10 +15 +5 +alter table tcollist add partition (partition pxxx values in (4)); +Error 1495 (HY000): Multiple definition of same constant in list partitioning +create database list_partition_shard_bits; +use list_partition_shard_bits; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (1), (5), (6), (10), (12); +select * from tlist; +a +0 +1 +10 +12 +5 +6 +select * from tlist partition (p0); +a +0 +1 +select * from tlist partition (p1, p2); +a +10 +12 +5 +6 +create table tcollist (a int) partition by list columns (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (1), (5), (6), (10), (12); +select * from tcollist; +a +0 +1 +10 +12 +5 +6 +select * from tcollist partition (p0); +a +0 +1 +select * from tcollist partition (p1, p2); +a +10 +12 +5 +6 +create database list_partition_split_region; +use list_partition_split_region; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, key(a)) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (1), (5), (6), (10), (12); +split table tlist index a between (2) and (15) regions 10; +select * from tlist; +a +0 +1 +10 +12 +5 +6 +select * from tlist partition (p0); +a +0 +1 +select * from tlist partition (p1, p2); +a +10 +12 +5 +6 +create table tcollist (a int, key(a)) partition by list columns (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (1), (5), (6), (10), (12); +split table tcollist index a between (2) and (15) regions 10; +select * from tcollist; +a +0 +1 +10 +12 +5 +6 +select * from tcollist partition (p0); +a +0 +1 +select * from tcollist partition (p1, p2); +a +10 +12 +5 +6 +create database list_partition_auto_incre; +use list_partition_auto_incre; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist1 (a int, b int AUTO_INCREMENT) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +create table tlist (a int, b int AUTO_INCREMENT, key(b)) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist (a) values (0); +insert into tlist (a) values (5); +insert into tlist (a) values (10); +insert into tlist (a) values (1); +create table tcollist1 (a int, b int AUTO_INCREMENT) partition by list columns (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +create table tcollist (a int, b int AUTO_INCREMENT, key(b)) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist (a) values (0); +insert into tcollist (a) values (5); +insert into tcollist (a) values (10); +insert into tcollist (a) values (1); +create database list_partition_auto_rand; +use list_partition_auto_rand; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, b bigint AUTO_RANDOM) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +Error 8216 (HY000): Invalid auto random: auto_random is only supported on the tables with clustered primary key +create table tlist (a bigint auto_random, primary key(a)) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +create table tcollist (a int, b bigint AUTO_RANDOM) partition by list columns (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +Error 8216 (HY000): Invalid auto random: auto_random is only supported on the tables with clustered primary key +create table tcollist (a bigint auto_random, primary key(a)) partition by list columns (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +create database list_partition_invisible_idx; +use list_partition_invisible_idx; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, b int, key(a)) partition by list (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5)); +alter table tlist alter index a invisible; +explain select a from tlist where a>=0 and a<=5; +id estRows task access object operator info +PartitionUnion_8 500.00 root +├─TableReader_11 250.00 root data:Selection_10 +│ └─Selection_10 250.00 cop[tikv] ge(list_partition_invisible_idx.tlist.a, 0), le(list_partition_invisible_idx.tlist.a, 5) +│ └─TableFullScan_9 10000.00 cop[tikv] table:tlist, partition:p0 keep order:false, stats:pseudo +└─TableReader_14 250.00 root data:Selection_13 + └─Selection_13 250.00 cop[tikv] ge(list_partition_invisible_idx.tlist.a, 0), le(list_partition_invisible_idx.tlist.a, 5) + └─TableFullScan_12 10000.00 cop[tikv] table:tlist, partition:p1 keep order:false, stats:pseudo +create table tcollist (a int, b int, key(a)) partition by list columns (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5)); +alter table tcollist alter index a invisible; +explain select a from tcollist where a>=0 and a<=5; +id estRows task access object operator info +PartitionUnion_8 500.00 root +├─TableReader_11 250.00 root data:Selection_10 +│ └─Selection_10 250.00 cop[tikv] ge(list_partition_invisible_idx.tcollist.a, 0), le(list_partition_invisible_idx.tcollist.a, 5) +│ └─TableFullScan_9 10000.00 cop[tikv] table:tcollist, partition:p0 keep order:false, stats:pseudo +└─TableReader_14 250.00 root data:Selection_13 + └─Selection_13 250.00 cop[tikv] ge(list_partition_invisible_idx.tcollist.a, 0), le(list_partition_invisible_idx.tcollist.a, 5) + └─TableFullScan_12 10000.00 cop[tikv] table:tcollist, partition:p1 keep order:false, stats:pseudo +create database list_partition_cte; +use list_partition_cte; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (1), (5), (6), (10); +with tmp as (select a+1 as a from tlist) select * from tmp; +a +1 +11 +2 +6 +7 +create table tcollist (a int) partition by list columns (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (1), (5), (6), (10); +with tmp as (select a+1 as a from tcollist) select * from tmp; +a +1 +11 +2 +6 +7 +create database list_partition_temp_table; +use list_partition_temp_table; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create global temporary table t(a int, b int) partition by list(a) (partition p0 values in (0)) on commit delete rows; +Error 1562 (HY000): Cannot create temporary table with partitions +create global temporary table t(a int, b int) partition by list columns (a) (partition p0 values in (0)) on commit delete rows; +Error 1562 (HY000): Cannot create temporary table with partitions +create database list_partition_alter_pk; +use list_partition_alter_pk; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, b int) partition by list (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +alter table tlist add primary key(a); +alter table tlist drop primary key; +alter table tlist add primary key(b); +Error 1503 (HY000): A PRIMARY must include all columns in the table's partitioning function +create table tcollist (a int, b int) partition by list columns (a) ( +partition p0 values in (0, 1, 2, 3, 4), +partition p1 values in (5, 6, 7, 8, 9), +partition p2 values in (10, 11, 12, 13, 14)); +alter table tcollist add primary key(a); +alter table tcollist drop primary key; +alter table tcollist add primary key(b); +Error 1503 (HY000): A PRIMARY must include all columns in the table's partitioning function +create database issue_27018; +use issue_27018; +set tidb_enable_list_partition = 1; +CREATE TABLE PK_LP9326 ( +COL1 tinyint(45) NOT NULL DEFAULT '30' COMMENT 'NUMERIC PK', +PRIMARY KEY (COL1) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( +PARTITION P0 VALUES IN (56,127,-128,-125,-40,-18,-10,-5,49,51), +PARTITION P1 VALUES IN (-107,-97,-57,-37,4,43,99,-9,-6,45), +PARTITION P2 VALUES IN (108,114,-85,-72,-38,-11,29,97,40,107), +PARTITION P3 VALUES IN (-112,-95,-42,24,28,47,-103,-94,7,64), +PARTITION P4 VALUES IN (-115,-101,-76,-47,1,19,-114,-23,-19,11), +PARTITION P5 VALUES IN (44,95,-92,-89,-26,-21,25,-117,-116,27), +PARTITION P6 VALUES IN (50,61,118,-110,-32,-1,111,125,-90,74), +PARTITION P7 VALUES IN (75,121,-96,-87,-14,-13,37,-68,-58,81), +PARTITION P8 VALUES IN (126,30,48,68) +); +insert into PK_LP9326 values(30),(48),(56); +SELECT COL1 FROM PK_LP9326 WHERE COL1 NOT IN (621579514938,-17333745845828,2777039147338); +COL1 +56 +30 +48 +create database issue_27017; +use issue_27017; +set tidb_enable_list_partition = 1; +CREATE TABLE PK_LP9465 ( +COL1 mediumint(45) NOT NULL DEFAULT '77' COMMENT 'NUMERIC PK', +PRIMARY KEY (COL1) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( +PARTITION P0 VALUES IN (-5237720,2949267,6047247,-8317208,-6854239,-6612749,-6578207,-5649321,2450483,2953765), +PARTITION P1 VALUES IN (5884439,-7816703,-6716210,-6050369,-5691207,6836620,5769359,-8237127,-1294367,-1228621), +PARTITION P2 VALUES IN (-976130,-8351227,-8294140,-4800605,1370685,-7351802,-6447779,77,1367409,5965199), +PARTITION P3 VALUES IN (7347944,7397124,8013414,-5737292,-3938813,-3687304,1307396,444598,1216072,1603451), +PARTITION P4 VALUES IN (2518402,-8388608,-5291256,-3796824,121011,8388607,39191,2323510,3386861,4886727), +PARTITION P5 VALUES IN (-6512367,-5922779,-3272589,-1313463,5751641,-3974640,2605656,3336269,4416436,-7975238), +PARTITION P6 VALUES IN (-6693544,-6023586,-4201506,6416586,-3254125,-205332,1072201,2679754,1963191,2077718), +PARTITION P7 VALUES IN (4205081,5170051,-8087893,-5805143,-1202286,1657202,8330979,5042855,7578575,-5830439), +PARTITION P8 VALUES IN (-5244013,3837781,4246485,670906,5644986,5843443,7794811,7831812,-7704740,-2222984), +PARTITION P9 VALUES IN (764108,3406142,8263677,248997,6129417,7556305,7939455,3526998,8239485,-5195482), +PARTITION P10 VALUES IN (-3625794,69270,377245) +); +insert into PK_LP9465 values(8263677); +SELECT COL1 FROM PK_LP9465 HAVING COL1>=-12354348921530; +COL1 +8263677 +create database issue_27544; +use issue_27544; +set tidb_enable_list_partition = 1; +create table t3 (a datetime) partition by list (mod( year(a) - abs(weekday(a) + dayofweek(a)), 4) + 1) ( +partition p0 values in (2), +partition p1 values in (3), +partition p3 values in (4)); +insert into t3 values ('1921-05-10 15:20:10'); +insert into t3 values ('1921-05-10 15:20:20'); +insert into t3 values ('1921-05-10 15:20:30'); +create database issue_27012; +use issue_27012; +set tidb_enable_list_partition = 1; +CREATE TABLE IDT_LP24306 ( +COL1 tinyint(16) DEFAULT '41' COMMENT 'NUMERIC UNIQUE INDEX', +KEY UK_COL1 (COL1) /*!80000 INVISIBLE */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( +PARTITION P0 VALUES IN (-126,-36,-96,-6,-83,-123,-5,-52,-98,-124), +PARTITION P1 VALUES IN (-2,-22,-88,-100,-60,-39,-69,-38,-11,-30), +PARTITION P2 VALUES IN (-119,-13,-67,-91,-65,-16,0,-128,-73,-118), +PARTITION P3 VALUES IN (-99,-56,-76,-110,-93,-114,-78,NULL) +); +insert into IDT_LP24306 values(-128); +select * from IDT_LP24306 where col1 not between 12021 and 99 and col1 <= -128; +COL1 +-128 +drop table if exists IDT_LP24306; +CREATE TABLE IDT_LP24306 ( +COL1 tinyint(16) DEFAULT '41' COMMENT 'NUMERIC UNIQUE INDEX', +KEY UK_COL1 (COL1) /*!80000 INVISIBLE */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into IDT_LP24306 values(-128); +select * from IDT_LP24306 where col1 not between 12021 and 99 and col1 <= -128; +COL1 +-128 +create database issue_27030; +use issue_27030; +set tidb_enable_list_partition = 1; +CREATE TABLE PK_LCP9290 ( +COL1 varbinary(10) NOT NULL, +PRIMARY KEY (COL1) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( +PARTITION P5 VALUES IN (x'32d8fb9da8b63508a6b8'), +PARTITION P6 VALUES IN (x'ffacadeb424179bc4b5c'), +PARTITION P8 VALUES IN (x'ae9f733168669fa900be') +); +insert into PK_LCP9290 values(0xffacadeb424179bc4b5c),(0xae9f733168669fa900be),(0x32d8fb9da8b63508a6b8); +SELECT COL1 FROM PK_LCP9290 WHERE COL1!=x'9f7ebdc957a36f2531b5' AND COL1 IN (x'ffacadeb424179bc4b5c',x'ae9f733168669fa900be',x'32d8fb9da8b63508a6b8'); +COL1 +25 +s1hf +BAyK\ +SELECT COL1 FROM PK_LCP9290 WHERE COL1 IN (x'ffacadeb424179bc4b5c',x'ae9f733168669fa900be',x'32d8fb9da8b63508a6b8'); +COL1 +25 +s1hf +BAyK\ +create database issue_27070; +use issue_27070; +set @@tidb_enable_list_partition = OFF; +create table if not exists t (id int, create_date date NOT NULL DEFAULT '2000-01-01', PRIMARY KEY (id,create_date) ) PARTITION BY list COLUMNS(create_date) ( PARTITION p20210506 VALUES IN ("20210507"), PARTITION p20210507 VALUES IN ("20210508") ); +Level Code Message +Warning 8200 Unsupported partition type LIST, treat as normal table +create database issue_27031; +use issue_27031; +set tidb_enable_list_partition = 1; +CREATE TABLE NT_LP27390 ( +COL1 mediumint(28) DEFAULT '114' COMMENT 'NUMERIC NO INDEX' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( +PARTITION P9 VALUES IN (3376825,-7753310,-4123498,6483048,6953968,-996842,-7542484,320451,-8322717,-2426029) +); +insert into NT_LP27390 values(-4123498); +SELECT COL1 FROM NT_LP27390 WHERE COL1 IN (46015556,-4123498,54419751); +COL1 +-4123498 +create database issue_27493; +use issue_27493; +set tidb_enable_list_partition = 1; +CREATE TABLE UK_LP17321 ( +COL1 mediumint(16) DEFAULT '82' COMMENT 'NUMERIC UNIQUE INDEX', +COL3 bigint(20) DEFAULT NULL, +UNIQUE KEY UM_COL (COL1,COL3) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST (COL1 DIV COL3) ( +PARTITION P0 VALUES IN (NULL,0) +); +select * from UK_LP17321 where col1 is null; +COL1 COL3 +create database issue_27532; +use issue_27532; +set tidb_enable_list_partition = 1; +create table t2 (c1 int primary key, c2 int, c3 int, c4 int, key k2 (c2), key k3 (c3)) partition by hash(c1) partitions 10; +insert into t2 values (1,1,1,1),(2,2,2,2),(3,3,3,3),(4,4,4,4); +set @@tidb_partition_prune_mode="dynamic"; +set autocommit = 0; +select * from t2; +c1 c2 c3 c4 +1 1 1 1 +2 2 2 2 +3 3 3 3 +4 4 4 4 +select * from t2; +c1 c2 c3 c4 +1 1 1 1 +2 2 2 2 +3 3 3 3 +4 4 4 4 +drop table t2; +drop database issue_27532; +use test; +set @@tidb_partition_prune_mode = 'dynamic'; +select @@tidb_partition_prune_mode; +@@tidb_partition_prune_mode +dynamic +create table t1 (id int, c date) partition by range (to_days(c)) +(partition p0 values less than (to_days('2022-01-11')), +partition p1 values less than (to_days('2022-02-11')), +partition p2 values less than (to_days('2022-03-11'))); +analyze table t1; +explain select * from t1 where c in ('2022-01-23', '2022-01-22'); +id estRows task access object operator info +TableReader_7 20.00 root partition:p1 data:Selection_6 +└─Selection_6 20.00 cop[tikv] in(test.t1.c, 2022-01-23 00:00:00.000000, 2022-01-22 00:00:00.000000) + └─TableFullScan_5 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select * from t1 where c in ('2022-01-23', '2022-01-22'); +id c +explain select * from t1 where c in (NULL, '2022-01-23'); +id estRows task access object operator info +TableReader_7 10.00 root partition:p0,p1 data:Selection_6 +└─Selection_6 10.00 cop[tikv] in(test.t1.c, NULL, 2022-01-23 00:00:00.000000) + └─TableFullScan_5 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select * from t1 where c in (NULL, '2022-01-23'); +id c +drop table t1; +create database RangeColumnsMulti; +use RangeColumnsMulti; +create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)(partition p0 values less than (NULL,NULL,NULL)); +Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 26 near ",'',''))" +create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)(partition p1 values less than (-2147483649,'0000-00-00',"")); +Error 1654 (HY000): Partition column values of incorrect type +create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)(partition p1 values less than (-2147483648,'0000-00-00',""),partition p2 values less than (10,'2022-01-01',"Wow"),partition p3 values less than (11,'2022-01-01',MAXVALUE),partition p4 values less than (MAXVALUE,'2022-01-01',"Wow")); +insert into t values (-2147483648,'0000-00-00',null); +Error 1292 (22007): Incorrect datetime value: '0000-00-00' for column 'b' at row 1 +insert into t values (NULL,NULL,NULL); +set @@sql_mode = ''; +insert into t values (-2147483648,'0000-00-00',null); +insert into t values (-2147483648,'0000-00-00',""); +insert into t values (5,'0000-00-00',null); +insert into t values (5,'0000-00-00',"Hi"); +set @@sql_mode = DEFAULT; +insert into t values (10,'2022-01-01',"Hi"); +insert into t values (10,'2022-01-01',"Wow"); +insert into t values (10,'2022-01-01',"Wowe"); +insert into t values (11,'2022-01-01',"Wow"); +insert into t values (1,null,"Wow"); +insert into t values (NULL,'2022-01-01',"Wow"); +insert into t values (11,null,"Wow"); +analyze table t; +select a,b,c from t partition(p1); +a b c +NULL NULL NULL +NULL 2022-01-01 00:00:00 Wow +-2147483648 0000-00-00 00:00:00 NULL +select a,b,c from t partition(p2); +a b c +-2147483648 0000-00-00 00:00:00 +1 NULL Wow +10 2022-01-01 00:00:00 Hi +5 0000-00-00 00:00:00 NULL +5 0000-00-00 00:00:00 Hi +select a,b,c from t partition(p3); +a b c +10 2022-01-01 00:00:00 Wow +10 2022-01-01 00:00:00 Wowe +11 NULL Wow +11 2022-01-01 00:00:00 Wow +select * from t where a = 10 and b = "2022-01-01" and c = "Wow"; +a b c +10 2022-01-01 00:00:00 Wow +select * from t where a = 10 and b = "2022-01-01" and c <= "Wow"; +a b c +10 2022-01-01 00:00:00 Hi +10 2022-01-01 00:00:00 Wow +select * from t where a = 10 and b = "2022-01-01" and c < "Wow"; +a b c +10 2022-01-01 00:00:00 Hi +select * from t where a = 10 and b = "2022-01-01" and c > "Wow"; +a b c +10 2022-01-01 00:00:00 Wowe +select * from t where a = 10 and b = "2022-01-01" and c >= "Wow"; +a b c +10 2022-01-01 00:00:00 Wow +10 2022-01-01 00:00:00 Wowe +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c = "Wow"; +id estRows task access object operator info + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +TableReader 0.52 root partition:p3 data:Selection +└─Selection 0.52 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), eq(rangecolumnsmulti.t.c, "Wow") +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c <= "Wow"; +id estRows task access object operator info + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +TableReader 0.83 root partition:p2,p3 data:Selection +└─Selection 0.83 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), le(rangecolumnsmulti.t.c, "Wow") +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c < "Wow"; +id estRows task access object operator info + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +TableReader 0.31 root partition:p2 data:Selection +└─Selection 0.31 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.t.c, "Wow") +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c > "Wow"; +id estRows task access object operator info + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +TableReader 0.10 root partition:p3 data:Selection +└─Selection 0.10 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), gt(rangecolumnsmulti.t.c, "Wow") +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c >= "Wow"; +id estRows task access object operator info + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +TableReader 0.62 root partition:p3 data:Selection +└─Selection 0.62 cop[tikv] eq(rangecolumnsmulti.t.a, 10), eq(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), ge(rangecolumnsmulti.t.c, "Wow") +select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"; +a b c +-2147483648 0000-00-00 00:00:00 +10 2022-01-01 00:00:00 Hi +5 0000-00-00 00:00:00 Hi +select * from t where a = 10 and b = "2022-01-01" and c = "Wow"; +a b c +10 2022-01-01 00:00:00 Wow +select * from t where a <= 10 and b <= '2022-01-01' and c <= "Wow"; +a b c +-2147483648 0000-00-00 00:00:00 +10 2022-01-01 00:00:00 Hi +10 2022-01-01 00:00:00 Wow +5 0000-00-00 00:00:00 Hi +explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"; +id estRows task access object operator info + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +TableReader 1.50 root partition:p1,p2,p3 data:Selection +└─Selection 1.50 cop[tikv] le(rangecolumnsmulti.t.a, 10), le(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.t.c, "Wow") +select * from t where a <= 11 and b <= '2022-01-01' and c < "Wow"; +a b c +-2147483648 0000-00-00 00:00:00 +10 2022-01-01 00:00:00 Hi +5 0000-00-00 00:00:00 Hi +explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"; +id estRows task access object operator info +TableReader 1.50 root partition:p1,p2,p3 data:Selection +└─Selection 1.50 cop[tikv] le(rangecolumnsmulti.t.a, 10), le(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.t.c, "Wow") + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +create table tref (a int, b datetime, c varchar(255), key (a,b,c)); +set @@sql_mode = ''; +insert into tref select * from t; +set @@sql_mode = DEFAULT; +explain format = 'brief' select * from tref where a <= 10 and b <= '2022-01-01' and c < "Wow"; +id estRows task access object operator info +IndexReader 367.05 root index:Selection +└─Selection 367.05 cop[tikv] le(rangecolumnsmulti.tref.b, 2022-01-01 00:00:00.000000), lt(rangecolumnsmulti.tref.c, "Wow") + └─IndexRangeScan 3323.33 cop[tikv] table:tref, index:a(a, b, c) range:[-inf,10], keep order:false, stats:pseudo +explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c <= "Wow"; +id estRows task access object operator info +TableReader 4.00 root partition:p1,p2,p3 data:Selection +└─Selection 4.00 cop[tikv] le(rangecolumnsmulti.t.a, 10), le(rangecolumnsmulti.t.b, 2022-01-01 00:00:00.000000), le(rangecolumnsmulti.t.c, "Wow") + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +select * from t where a = 2 and b = "2022-01-02" and c = "Hi" or b = '2022-01-01' and c = "Wow"; +a b c +NULL 2022-01-01 00:00:00 Wow +10 2022-01-01 00:00:00 Wow +11 2022-01-01 00:00:00 Wow +select * from t where a = 2 and b = "2022-01-02" and c = "Hi" or a = 10 and b = '2022-01-01' and c = "Wow"; +a b c +10 2022-01-01 00:00:00 Wow +select * from t where a = 2 and b = "2022-01-02" and c = "Hi"; +a b c +select * from t where a = 2 and b = "2022-01-02" and c < "Hi"; +a b c +select * from t where a < 2; +a b c +-2147483648 0000-00-00 00:00:00 +-2147483648 0000-00-00 00:00:00 NULL +1 NULL Wow +select * from t where a <= 2 and b <= "2022-01-02" and c < "Hi"; +a b c +-2147483648 0000-00-00 00:00:00 +explain format = 'brief' select * from t where a < 2; +id estRows task access object operator info +TableReader 3.00 root partition:p1,p2 data:Selection +└─Selection 3.00 cop[tikv] lt(rangecolumnsmulti.t.a, 2) + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +select * from t where a < 2 and a > -22; +a b c +1 NULL Wow +explain format = 'brief' select * from t where a < 2 and a > -22; +id estRows task access object operator info +TableReader 1.00 root partition:p2 data:Selection +└─Selection 1.00 cop[tikv] gt(rangecolumnsmulti.t.a, -22), lt(rangecolumnsmulti.t.a, 2) + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +select * from t where c = ""; +a b c +-2147483648 0000-00-00 00:00:00 +explain format = 'brief' select * from t where c = ""; +id estRows task access object operator info +TableReader 1.00 root partition:all data:Selection +└─Selection 1.00 cop[tikv] eq(rangecolumnsmulti.t.c, "") + └─TableFullScan 12.00 cop[tikv] table:t keep order:false +create database RColumnsMulti; +use RColumnsMulti; +create table t (a int, b datetime, c varchar(255), key (a,b,c)) partition by range columns (a,b,c) (partition p0 values less than (-2147483648, '0000-01-01', ""), partition p1 values less than (-2147483648, '0001-01-01', ""), partition p2 values less than (-2, '0001-01-01', ""), partition p3 values less than (0, '0001-01-01', ""), partition p4 values less than (0, '2031-01-01', ""), partition p5 values less than (0, '2031-01-01', "Wow"), partition p6 values less than (0, '2031-01-01', MAXVALUE), partition p7 values less than (0, MAXVALUE, MAXVALUE), partition p8 values less than (MAXVALUE, MAXVALUE, MAXVALUE)); +insert into t values (-2147483648,'0000-00-00',null); +Error 1292 (22007): Incorrect datetime value: '0000-00-00' for column 'b' at row 1 +insert into t values (NULL,NULL,NULL); +set @@sql_mode = ''; +insert into t values (-2147483648,'0000-00-00',null); +insert into t values (-2147483648,'0000-00-00',""); +insert into t values (5,'0000-00-00',null); +insert into t values (5,'0000-00-00',"Hi"); +set @@sql_mode = DEFAULT; +insert into t values (10,'2022-01-01',"Hi"); +insert into t values (10,'2022-01-01',"Wow"); +insert into t values (11,'2022-01-01',"Wow"); +insert into t values (0,'2020-01-01',"Wow"); +insert into t values (1,null,"Wow"); +insert into t values (NULL,'2022-01-01',"Wow"); +insert into t values (11,null,"Wow"); +analyze table t; +select a,b from t where b = '2022-01-01'; +a b +NULL 2022-01-01 00:00:00 +10 2022-01-01 00:00:00 +10 2022-01-01 00:00:00 +11 2022-01-01 00:00:00 +select a,b,c from t where a = 1; +a b c +1 NULL Wow +select a,b,c from t where a = 1 AND c = "Wow"; +a b c +1 NULL Wow +explain format = 'brief' select a,b,c from t where a = 1 AND c = "Wow"; +id estRows task access object operator info +IndexReader 0.50 root partition:p8 index:Selection +└─Selection 0.50 cop[tikv] eq(rcolumnsmulti.t.c, "Wow") + └─IndexRangeScan 1.00 cop[tikv] table:t, index:a(a, b, c) range:[1,1], keep order:false +select a,b,c from t where a = 0 AND c = "Wow"; +a b c +0 2020-01-01 00:00:00 Wow +explain format = 'brief' select a,b,c from t where a = 0 AND c = "Wow"; +id estRows task access object operator info +IndexReader 0.50 root partition:p3,p4,p5,p6,p7 index:Selection +└─Selection 0.50 cop[tikv] eq(rcolumnsmulti.t.c, "Wow") + └─IndexRangeScan 1.00 cop[tikv] table:t, index:a(a, b, c) range:[0,0], keep order:false +create database rce; +use rce; +create table tref (a int unsigned, b int, c int); +create table t (a int unsigned, b int, c int) partition by range columns (a,b) (partition p0 values less than (3, MAXVALUE), partition p1 values less than (4, -2147483648), partition p2 values less than (4, 1), partition p3 values less than (4, 4), partition p4 values less than (4, 7), partition p5 values less than (4, 11), partition p6 values less than (4, 14), partition p7 values less than (4, 17), partition p8 values less than (4, MAXVALUE), partition p9 values less than (7, 0), partition p10 values less than (11, MAXVALUE), partition p11 values less than (14, -2147483648), partition p12 values less than (17, 17), partition p13 values less than (MAXVALUE, -2147483648)); +insert into t values (0,0,0),(11,2147483647,2147483647),(14,10,4),(14,NULL,2),(14,NULL,NULL),(17,16,16),(17,17,17),(3,2147483647,9),(4,-2147483648,-2147483648),(4,1,1),(4,10,3),(4,13,1),(4,14,2),(4,2147483647,2147483647),(4,4,4),(4,5,6),(4,NULL,4),(5,0,0),(7,0,0),(NULL,-2147483648,NULL),(NULL,NULL,NULL); +insert into tref select * from t; +analyze table t; +select * from tref; +a b c +NULL NULL NULL +NULL -2147483648 NULL +0 0 0 +11 2147483647 2147483647 +14 NULL NULL +14 NULL 2 +14 10 4 +17 16 16 +17 17 17 +3 2147483647 9 +4 NULL 4 +4 -2147483648 -2147483648 +4 1 1 +4 10 3 +4 13 1 +4 14 2 +4 2147483647 2147483647 +4 4 4 +4 5 6 +5 0 0 +7 0 0 +select * from t; +a b c +NULL NULL NULL +NULL -2147483648 NULL +0 0 0 +11 2147483647 2147483647 +14 NULL NULL +14 NULL 2 +14 10 4 +17 16 16 +17 17 17 +3 2147483647 9 +4 NULL 4 +4 -2147483648 -2147483648 +4 1 1 +4 10 3 +4 13 1 +4 14 2 +4 2147483647 2147483647 +4 4 4 +4 5 6 +5 0 0 +7 0 0 +select * from t partition (p0); +a b c +NULL NULL NULL +NULL -2147483648 NULL +0 0 0 +3 2147483647 9 +select * from t partition (p1); +a b c +4 NULL 4 +select * from t partition (p2); +a b c +4 -2147483648 -2147483648 +select * from t partition (p3); +a b c +4 1 1 +select * from t partition (p4); +a b c +4 4 4 +4 5 6 +select * from t partition (p5); +a b c +4 10 3 +select * from t partition (p6); +a b c +4 13 1 +select * from t partition (p7); +a b c +4 14 2 +select * from t partition (p8); +a b c +4 2147483647 2147483647 +select * from t partition (p9); +a b c +5 0 0 +select * from t partition (p10); +a b c +11 2147483647 2147483647 +7 0 0 +select * from t partition (p11); +a b c +14 NULL NULL +14 NULL 2 +select * from t partition (p12); +a b c +14 10 4 +17 16 16 +select * from t partition (p13); +a b c +17 17 17 +explain format = 'brief' select * from t where c = 3; +id estRows task access object operator info +TableReader 1.00 root partition:all data:Selection +└─Selection 1.00 cop[tikv] eq(rce.t.c, 3) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +explain format = 'brief' select * from t where b > 3 and c = 3; +id estRows task access object operator info +TableReader 0.52 root partition:all data:Selection +└─Selection 0.52 cop[tikv] eq(rce.t.c, 3), gt(rce.t.b, 3) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +explain format = 'brief' select * from t where a = 5 and c = 3; +id estRows task access object operator info +TableReader 0.05 root partition:p9 data:Selection +└─Selection 0.05 cop[tikv] eq(rce.t.a, 5), eq(rce.t.c, 3) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +explain format = 'brief' select * from t where a = 4 and c = 3; +id estRows task access object operator info +TableReader 0.43 root partition:p1,p2,p3,p4,p5,p6,p7,p8 data:Selection +└─Selection 0.43 cop[tikv] eq(rce.t.a, 4), eq(rce.t.c, 3) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +explain format = 'brief' select * from t where a in (4,14) and c = 3; +id estRows task access object operator info +TableReader 0.57 root partition:p1,p2,p3,p4,p5,p6,p7,p8,p11,p12 data:Selection +└─Selection 0.57 cop[tikv] eq(rce.t.c, 3), in(rce.t.a, 4, 14) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +explain format = 'brief' select * from t where a in (4,14) and b in (null,10); +id estRows task access object operator info +TableReader 1.14 root partition:p5,p12 data:Selection +└─Selection 1.14 cop[tikv] in(rce.t.a, 4, 14), in(rce.t.b, NULL, 10) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +select * from tref where a in (4,14) and b in (null,10); +a b c +14 10 4 +4 10 3 +select * from t where a in (4,14) and b in (null,10); +a b c +14 10 4 +4 10 3 +explain format = 'brief' select * from t where a in (4,14) and (b in (11,10) OR b is null); +id estRows task access object operator info +TableReader 3.43 root partition:p1,p5,p6,p11,p12 data:Selection +└─Selection 3.43 cop[tikv] in(rce.t.a, 4, 14), or(in(rce.t.b, 11, 10), isnull(rce.t.b)) + └─TableFullScan 21.00 cop[tikv] table:t keep order:false +select * from tref where a in (4,14) and (b in (11,10) OR b is null); +a b c +14 NULL NULL +14 NULL 2 +14 10 4 +4 NULL 4 +4 10 3 +select * from t where a in (4,14) and (b in (11,10) OR b is null); +a b c +14 NULL NULL +14 NULL 2 +14 10 4 +4 NULL 4 +4 10 3 +create database cwc; +use cwc; +create table t (a char(32) collate utf8mb4_unicode_ci) partition by range columns (a) (partition p0 values less than ('c'), partition p1 values less than ('F'), partition p2 values less than ('h'), partition p3 values less than ('L'), partition p4 values less than ('t'), partition p5 values less than (MAXVALUE)); +insert into t values ('a'),('A'),('c'),('C'),('f'),('F'),('h'),('H'),('l'),('L'),('t'),('T'),('z'),('Z'); +analyze table t; +select * from t partition(p0); +a +A +a +select * from t partition(p1); +a +C +c +select * from t partition(p2); +a +F +f +select * from t partition(p3); +a +H +h +select * from t partition(p4); +a +L +l +select * from t partition(p5); +a +T +Z +t +z +select * from t where a > 'C' and a < 'q'; +a +F +H +L +f +h +l +select * from t where a > 'c' and a < 'Q'; +a +F +H +L +f +h +l +explain format = 'brief' select * from t where a > 'C' and a < 'q'; +id estRows task access object operator info +TableReader 6.00 root partition:p1,p2,p3,p4 data:Selection +└─Selection 6.00 cop[tikv] gt(cwc.t.a, "C"), lt(cwc.t.a, "q") + └─TableFullScan 14.00 cop[tikv] table:t keep order:false +explain format = 'brief' select * from t where a > 'c' and a < 'Q'; +id estRows task access object operator info +TableReader 6.00 root partition:p1,p2,p3,p4 data:Selection +└─Selection 6.00 cop[tikv] gt(cwc.t.a, "c"), lt(cwc.t.a, "Q") + └─TableFullScan 14.00 cop[tikv] table:t keep order:false +drop database if exists rcd; +create database rcd; +use rcd; +set @@tidb_partition_prune_mode = 'dynamic'; +create table i (a int, b int, key (a,b)); +select * from i where a < 1 and a > 2; +a b +explain format = 'brief' select * from i where a < 1 and a > 2; +id estRows task access object operator info +TableDual 0.00 root rows:0 +create table t (a date) partition by range columns (a) (partition p0 values less than ('19990601'), partition p1 values less than ('2000-05-01'), partition p2 values less than ('20080401'), partition p3 values less than ('2010-03-01'), partition p4 values less than ('20160201'), partition p5 values less than ('2020-01-01'), partition p6 values less than (MAXVALUE)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` date DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY RANGE COLUMNS(`a`) +(PARTITION `p0` VALUES LESS THAN ('19990601'), + PARTITION `p1` VALUES LESS THAN ('2000-05-01'), + PARTITION `p2` VALUES LESS THAN ('20080401'), + PARTITION `p3` VALUES LESS THAN ('2010-03-01'), + PARTITION `p4` VALUES LESS THAN ('20160201'), + PARTITION `p5` VALUES LESS THAN ('2020-01-01'), + PARTITION `p6` VALUES LESS THAN (MAXVALUE)) +insert into t values ('19990101'),('1999-06-01'),('2000-05-01'),('20080401'),('2010-03-01'),('2016-02-01'),('2020-01-01'); +analyze table t; +select * from t partition(p0); +a +1999-01-01 +select * from t partition(p1); +a +1999-06-01 +select * from t partition(p2); +a +2000-05-01 +select * from t partition(p3); +a +2008-04-01 +select * from t partition(p4); +a +2010-03-01 +select * from t partition(p5); +a +2016-02-01 +select * from t partition(p6); +a +2020-01-01 +explain select * from t where a < '1943-02-12'; +id estRows task access object operator info +TableReader_7 0.00 root partition:p0 data:Selection_6 +└─Selection_6 0.00 cop[tikv] lt(rcd.t.a, 1943-02-12 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a >= '19690213'; +id estRows task access object operator info +TableReader_7 7.00 root partition:all data:Selection_6 +└─Selection_6 7.00 cop[tikv] ge(rcd.t.a, 1969-02-13 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a > '2003-03-13'; +id estRows task access object operator info +TableReader_7 4.00 root partition:p2,p3,p4,p5,p6 data:Selection_6 +└─Selection_6 4.00 cop[tikv] gt(rcd.t.a, 2003-03-13 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a < '2006-02-03'; +id estRows task access object operator info +TableReader_7 3.00 root partition:p0,p1,p2 data:Selection_6 +└─Selection_6 3.00 cop[tikv] lt(rcd.t.a, 2006-02-03 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a = '20070707'; +id estRows task access object operator info +TableReader_7 0.00 root partition:p2 data:Selection_6 +└─Selection_6 0.00 cop[tikv] eq(rcd.t.a, 2007-07-07 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a > '1949-10-10'; +id estRows task access object operator info +TableReader_7 7.00 root partition:all data:Selection_6 +└─Selection_6 7.00 cop[tikv] gt(rcd.t.a, 1949-10-10 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a > '2016-02-01' AND a < '20000103'; +id estRows task access object operator info +TableReader_7 0.00 root partition:dual data:Selection_6 +└─Selection_6 0.00 cop[tikv] gt(rcd.t.a, 2016-02-01 00:00:00.000000), lt(rcd.t.a, 2000-01-03 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a < '19691112' or a >= '2019-09-18'; +id estRows task access object operator info +TableReader_7 1.00 root partition:p0,p5,p6 data:Selection_6 +└─Selection_6 1.00 cop[tikv] or(lt(rcd.t.a, 1969-11-12 00:00:00.000000), ge(rcd.t.a, 2019-09-18 00:00:00.000000)) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a is null; +id estRows task access object operator info +TableReader_7 0.00 root partition:p0 data:Selection_6 +└─Selection_6 0.00 cop[tikv] isnull(rcd.t.a) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where '2003-02-27' >= a; +id estRows task access object operator info +TableReader_7 3.00 root partition:p0,p1,p2 data:Selection_6 +└─Selection_6 3.00 cop[tikv] ge(2003-02-27 00:00:00.000000, rcd.t.a) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where '20141024' < a; +id estRows task access object operator info +TableReader_7 2.00 root partition:p4,p5,p6 data:Selection_6 +└─Selection_6 2.00 cop[tikv] lt(2014-10-24 00:00:00.000000, rcd.t.a) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where '2003-03-30' > a; +id estRows task access object operator info +TableReader_7 3.00 root partition:p0,p1,p2 data:Selection_6 +└─Selection_6 3.00 cop[tikv] gt(2003-03-30 00:00:00.000000, rcd.t.a) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +explain select * from t where a between '2003-03-30' AND '2014-01-01'; +id estRows task access object operator info +TableReader_7 2.00 root partition:p2,p3,p4 data:Selection_6 +└─Selection_6 2.00 cop[tikv] ge(rcd.t.a, 2003-03-30 00:00:00.000000), le(rcd.t.a, 2014-01-01 00:00:00.000000) + └─TableFullScan_5 7.00 cop[tikv] table:t keep order:false +drop database if exists rcd; +create database rcd; +use rcd; +create table t1 (a char, b char, c char) partition by range columns (a,b,c) ( partition p0 values less than ('a','b','c'), partition p1 values less than ('b','c','d'), partition p2 values less than ('d','e','f')); +insert into t1 values ('a', NULL, 'd'); +analyze table t1; +explain format=brief select * from t1 where a = 'a' AND c = 'd'; +id estRows task access object operator info +TableReader 1.00 root partition:p0,p1 data:Selection +└─Selection 1.00 cop[tikv] eq(rcd.t1.a, "a"), eq(rcd.t1.c, "d") + └─TableFullScan 1.00 cop[tikv] table:t1 keep order:false +select * from t1 where a = 'a' AND c = 'd'; +a b c +a NULL d +drop table t1; +drop table if exists q1, q2; +create table q1(a int, b int, key (a)) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20)); +create table q2(a int, b int, key (a)) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20)); +explain format=brief select * from q1,q2; +id estRows task access object operator info +HashJoin 400000000.00 root CARTESIAN inner join +├─PartitionUnion(Build) 20000.00 root +│ ├─TableReader 10000.00 root data:TableFullScan +│ │ └─TableFullScan 10000.00 cop[tikv] table:q2, partition:p0 keep order:false, stats:pseudo +│ └─TableReader 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:q2, partition:p1 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 20000.00 root + ├─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:q1, partition:p0 keep order:false, stats:pseudo + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:q1, partition:p1 keep order:false, stats:pseudo +analyze table q1; +explain format=brief select * from q1,q2; +id estRows task access object operator info +HashJoin 400000000.00 root CARTESIAN inner join +├─PartitionUnion(Build) 20000.00 root +│ ├─TableReader 10000.00 root data:TableFullScan +│ │ └─TableFullScan 10000.00 cop[tikv] table:q2, partition:p0 keep order:false, stats:pseudo +│ └─TableReader 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:q2, partition:p1 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 20000.00 root + ├─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:q1, partition:p0 keep order:false, stats:pseudo + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:q1, partition:p1 keep order:false, stats:pseudo +analyze table q2; +explain format=brief select * from q1,q2; +id estRows task access object operator info +HashJoin 100000000.00 root CARTESIAN inner join +├─TableReader(Build) 10000.00 root partition:all data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:q2 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root partition:all data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:q1 keep order:false, stats:pseudo +create database issue42323; +use issue42323; +set @@session.tidb_partition_prune_mode = 'dynamic'; +CREATE TABLE t(col1 int(11) NOT NULL DEFAULT '0' ) PARTITION BY RANGE (FLOOR(col1))( +PARTITION p2021 VALUES LESS THAN (202200), +PARTITION p2022 VALUES LESS THAN (202300), +PARTITION p2023 VALUES LESS THAN (202400)); +insert into t values(202303); +analyze table t; +select * from t where col1 = 202303; +col1 +202303 +select * from t where col1 = floor(202303); +col1 +202303 +drop database issue42323; diff --git a/tests/integrationtest/r/planner/core/partition_pruner.result b/tests/integrationtest/r/planner/core/partition_pruner.result new file mode 100644 index 0000000000..b978eb7b6e --- /dev/null +++ b/tests/integrationtest/r/planner/core/partition_pruner.result @@ -0,0 +1,3645 @@ +set tidb_cost_model_version=2; +drop database if exists test_range_col_in; +create database test_range_col_in; +use test_range_col_in; +set @@session.tidb_partition_prune_mode='static'; +CREATE TABLE t1 ( +id bigint(20) NOT NULL AUTO_INCREMENT, +dt date, +PRIMARY KEY (id,dt) NONCLUSTERED) +PARTITION BY RANGE COLUMNS(dt) ( +PARTITION p20201125 VALUES LESS THAN ("20201126"), +PARTITION p20201126 VALUES LESS THAN ("20201127"), +PARTITION p20201127 VALUES LESS THAN ("20201128"), +PARTITION p20201128 VALUES LESS THAN ("20201129"), +PARTITION p20201129 VALUES LESS THAN ("20201130")); +explain format='brief' select /*+ HASH_AGG() */ count(1) from t1 where dt in ('2020-11-27','2020-11-28'); +id estRows task access object operator info +HashAgg 1.00 root funcs:count(Column#5)->Column#4 +└─PartitionUnion 2.00 root + ├─HashAgg 1.00 root funcs:count(Column#7)->Column#5 + │ └─IndexReader 1.00 root index:HashAgg + │ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#7 + │ └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000) + │ └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201127, index:PRIMARY(id, dt) keep order:false, stats:pseudo + └─HashAgg 1.00 root funcs:count(Column#10)->Column#5 + └─IndexReader 1.00 root index:HashAgg + └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#10 + └─Selection 20.00 cop[tikv] in(test_range_col_in.t1.dt, 2020-11-27 00:00:00.000000, 2020-11-28 00:00:00.000000) + └─IndexFullScan 10000.00 cop[tikv] table:t1, partition:p20201128, index:PRIMARY(id, dt) keep order:false, stats:pseudo +insert into t1 values (1, "2020-11-25"); +insert into t1 values (2, "2020-11-26"); +insert into t1 values (3, "2020-11-27"); +insert into t1 values (4, "2020-11-28"); +select id from t1 where dt in ('2020-11-27','2020-11-28') order by id; +id +3 +4 +select id from t1 where dt in (20201127,'2020-11-28') order by id; +id +3 +4 +select id from t1 where dt in (20201127,20201128) order by id; +id +3 +4 +select id from t1 where dt in (20201127,20201128,null) order by id; +id +3 +4 +select id from t1 where dt in ('2020-11-26','2020-11-25','2020-11-28') order by id; +id +1 +2 +4 +select id from t1 where dt in ('2020-11-26','wrong','2020-11-28') order by id; +id +2 +4 +create table t2 (a int) partition by range columns(a) ( +partition p0 values less than (0), +partition p1 values less than (10), +partition p2 values less than (20)); +insert into t2 values (-1), (1), (11), (null); +select a from t2 where a in (-1, 1) order by a; +a +-1 +1 +select a from t2 where a in (1, 11, null) order by a; +a +1 +11 +explain format='brief' select a from t2 where a in (-1, 1); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in.t2.a, -1, 1) +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in.t2.a, -1, 1) + └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +create table t3 (a varchar(10)) partition by range columns(a) ( +partition p0 values less than ("aaa"), +partition p1 values less than ("bbb"), +partition p2 values less than ("ccc")); +explain format='brief' select a from t3 where a in ('aaa', 'aab'); +id estRows task access object operator info +TableReader 20.00 root data:Selection +└─Selection 20.00 cop[tikv] in(test_range_col_in.t3.a, "aaa", "aab") + └─TableFullScan 10000.00 cop[tikv] table:t3, partition:p1 keep order:false, stats:pseudo +explain format='brief' select a from t3 where a in ('aaa', 'bu'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in.t3.a, "aaa", "bu") +│ └─TableFullScan 10000.00 cop[tikv] table:t3, partition:p1 keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in.t3.a, "aaa", "bu") + └─TableFullScan 10000.00 cop[tikv] table:t3, partition:p2 keep order:false, stats:pseudo +drop database if exists test_range_col_in_string; +create database test_range_col_in_string; +use test_range_col_in_string; +set names utf8mb4 collate utf8mb4_bin; +set @@session.tidb_partition_prune_mode='static'; +create table t (a varchar(255) charset utf8mb4 collate utf8mb4_bin) partition by range columns(a)( partition pNull values less than (""),partition pAAAA values less than ("AAAA"),partition pCCC values less than ("CCC"),partition pShrimpsandwich values less than ("Räksmörgås"),partition paaa values less than ("aaa"),partition pSushi values less than ("🍣🍣🍣"),partition pMax values less than (MAXVALUE)); +insert into t values (NULL), ("a"), ("Räkmacka"), ("🍣 is life"), ("🍺 after work?"), ("🍺🍺🍺🍺🍺 for oktoberfest"),("AA"),("aa"),("AAA"),("aaa"); +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a = 'aa'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aa'; +a +aa +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'aa' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci = 'aa'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +a +AA +AAA +aa +aaa +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a = 'aa'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aa'; +a +aa +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'aa' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci = 'aa'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +a +AA +AAA +aa +aaa +set names utf8mb4 collate utf8mb4_general_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a = 'aa'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aa'; +a +aa +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'aa' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci = 'aa'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +a +AA +AAA +aa +aaa +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a = 'aa'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aa'; +a +aa +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'aa' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci = 'aa'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +a +AA +AAA +aa +aaa +set names utf8mb4 collate utf8mb4_unicode_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a = 'aa'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aa'; +a +aa +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'aa' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci = 'aa'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +a +AA +AAA +aa +aaa +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a = 'aa'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aa'; +a +aa +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a = 'aa' collate utf8mb4_general_ci; +a +AA +aa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] eq(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci = 'aa'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +id estRows task access object operator info +PartitionUnion 56000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(cast(test_range_col_in_string.t.a, varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci), "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +a +AA +AAA +aa +aaa +drop table t; +create table t (a varchar(255) charset utf8mb4 collate utf8mb4_general_ci) partition by range columns(a)( partition pNull values less than (""),partition paaa values less than ("aaa"),partition pAAAA values less than ("AAAA"),partition pCCC values less than ("CCC"),partition pShrimpsandwich values less than ("Räksmörgås"),partition pSushi values less than ("🍣🍣🍣"),partition pMax values less than (MAXVALUE)); +insert into t values (NULL), ("a"), ("Räkmacka"), ("🍣 is life"), ("🍺 after work?"), ("🍺🍺🍺🍺🍺 for oktoberfest"),("AA"),("aa"),("AAA"),("aaa"); +set names utf8mb4 collate utf8mb4_bin; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_bin; +a +AA +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +aaa +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA' collate utf8mb4_bin; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AA', 'aaa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +a +AAA +aa +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_bin; +a +AA +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +aaa +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA' collate utf8mb4_bin; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AA', 'aaa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +a +AAA +aa +set names utf8mb4 collate utf8mb4_general_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_bin; +a +AA +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +aaa +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA' collate utf8mb4_bin; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AA', 'aaa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +a +AAA +aa +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_bin; +a +AA +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +aaa +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA' collate utf8mb4_bin; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AA', 'aaa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +a +AAA +aa +set names utf8mb4 collate utf8mb4_unicode_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_bin; +a +AA +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +aaa +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA' collate utf8mb4_bin; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AA', 'aaa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +a +AAA +aa +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] isnull(test_range_col_in_string.t.a) + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pNull keep order:false, stats:pseudo +select * from t where a IS NULL; +a +NULL +explain format = 'brief' select * from t where a = 'AA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA'; +a +AA +aa +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +select * from t where a = 'AA' collate utf8mb4_bin; +a +AA +explain format = 'brief' select * from t where a = 'AAA'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA'; +a +AAA +aaa +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +id estRows task access object operator info +TableReader 8000.00 root data:Selection +└─Selection 8000.00 cop[tikv] eq(test_range_col_in_string.t.a, "AAA") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a = 'AAA' collate utf8mb4_bin; +a +AAA +explain format = 'brief' select * from t where a = 'AB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "AB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'AB'; +a +explain format = 'brief' select * from t where a = 'aB'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "aB") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pCCC keep order:false, stats:pseudo +select * from t where a = 'aB'; +a +explain format = 'brief' select * from t where a = '🍣'; +id estRows task access object operator info +TableReader 10.00 root data:Selection +└─Selection 10.00 cop[tikv] eq(test_range_col_in_string.t.a, "🍣") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +select * from t where a = '🍣'; +a +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +id estRows task access object operator info +PartitionUnion 90.00 root +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pShrimpsandwich keep order:false, stats:pseudo +├─TableReader 30.00 root data:Selection +│ └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:pSushi keep order:false, stats:pseudo +└─TableReader 30.00 root data:Selection + └─Selection 30.00 cop[tikv] in(test_range_col_in_string.t.a, "🍣 is life", "Räkmacka", "🍺🍺🍺🍺 after work?") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pMax keep order:false, stats:pseudo +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +a +Räkmacka +🍣 is life +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +id estRows task access object operator info +PartitionUnion 40.00 root +├─TableReader 20.00 root data:Selection +│ └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 20.00 root data:Selection + └─Selection 20.00 cop[tikv] in(test_range_col_in_string.t.a, "AA", "aaa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AA', 'aaa'); +a +AA +AAA +aa +aaa +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +a +AAA +aa +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +id estRows task access object operator info +PartitionUnion 16000.00 root +├─TableReader 8000.00 root data:Selection +│ └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") +│ └─TableFullScan 10000.00 cop[tikv] table:t, partition:paaa keep order:false, stats:pseudo +└─TableReader 8000.00 root data:Selection + └─Selection 8000.00 cop[tikv] in(test_range_col_in_string.t.a, "AAA", "aa") + └─TableFullScan 10000.00 cop[tikv] table:t, partition:pAAAA keep order:false, stats:pseudo +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +a +AAA +aa +drop database if exists test_partition; +create database test_partition; +use test_partition; +set @@session.tidb_enable_list_partition = ON; +create table t1 (id int, a int, b int ) partition by list columns (b, id, a) (partition p0 values in ((1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0)),partition p1 values in ((1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2)),partition p2 values in ((0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2))); +drop database if exists test_partition_1; +create database test_partition_1; +use test_partition_1; +create table t1 (id int, a int, b int); +insert into t1 (b,id,a) values (1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0); +insert into t1 (b,id,a) values (1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0); +select * from t1 order by id,a,b; +id a b +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 2 0 +1 2 0 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +select * from t1 order by id,a,b; +id a b +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 2 0 +1 2 0 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +insert into t1 (b,id,a) values (1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2); +insert into t1 (b,id,a) values (1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2); +select * from t1 order by id,a,b; +id a b +0 1 1 +0 1 1 +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 1 2 +1 1 2 +1 2 0 +1 2 0 +1 2 2 +1 2 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 1 2 +2 1 2 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +select * from t1 order by id,a,b; +id a b +0 1 1 +0 1 1 +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 1 2 +1 1 2 +1 2 0 +1 2 0 +1 2 2 +1 2 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 1 2 +2 1 2 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +insert into t1 (b,id,a) values (0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2); +insert into t1 (b,id,a) values (0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2); +select * from t1 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +0 1 0 +0 1 0 +0 1 1 +0 1 1 +0 1 2 +0 1 2 +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 1 1 +1 1 1 +1 1 2 +1 1 2 +1 2 0 +1 2 0 +1 2 1 +1 2 1 +1 2 2 +1 2 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +2 1 0 +2 1 0 +2 1 1 +2 1 1 +2 1 2 +2 1 2 +2 2 0 +2 2 0 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +select * from t1 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +0 1 0 +0 1 0 +0 1 1 +0 1 1 +0 1 2 +0 1 2 +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 1 1 +1 1 1 +1 1 2 +1 1 2 +1 2 0 +1 2 0 +1 2 1 +1 2 1 +1 2 2 +1 2 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +2 1 0 +2 1 0 +2 1 1 +2 1 1 +2 1 2 +2 1 2 +2 2 0 +2 2 0 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +select * from t1 where id = 0 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +0 1 0 +0 1 0 +0 1 1 +0 1 1 +0 1 2 +0 1 2 +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +select * from t1 where id = 0 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +0 1 0 +0 1 0 +0 1 1 +0 1 1 +0 1 2 +0 1 2 +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +select * from t1 where a = 0 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +select * from t1 where a = 0 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +select * from t1 where b = 0 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 1 0 +0 1 0 +0 2 0 +0 2 0 +1 0 0 +1 0 0 +1 1 0 +1 1 0 +1 2 0 +1 2 0 +2 0 0 +2 0 0 +2 1 0 +2 1 0 +2 2 0 +2 2 0 +select * from t1 where b = 0 order by id,a,b; +id a b +0 0 0 +0 0 0 +0 1 0 +0 1 0 +0 2 0 +0 2 0 +1 0 0 +1 0 0 +1 1 0 +1 1 0 +1 2 0 +1 2 0 +2 0 0 +2 0 0 +2 1 0 +2 1 0 +2 2 0 +2 2 0 +select * from t1 where id = 1 order by id,a,b; +id a b +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 1 1 +1 1 1 +1 1 2 +1 1 2 +1 2 0 +1 2 0 +1 2 1 +1 2 1 +1 2 2 +1 2 2 +select * from t1 where id = 1 order by id,a,b; +id a b +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +1 1 0 +1 1 0 +1 1 1 +1 1 1 +1 1 2 +1 1 2 +1 2 0 +1 2 0 +1 2 1 +1 2 1 +1 2 2 +1 2 2 +select * from t1 where a = 1 order by id,a,b; +id a b +0 1 0 +0 1 0 +0 1 1 +0 1 1 +0 1 2 +0 1 2 +1 1 0 +1 1 0 +1 1 1 +1 1 1 +1 1 2 +1 1 2 +2 1 0 +2 1 0 +2 1 1 +2 1 1 +2 1 2 +2 1 2 +select * from t1 where a = 1 order by id,a,b; +id a b +0 1 0 +0 1 0 +0 1 1 +0 1 1 +0 1 2 +0 1 2 +1 1 0 +1 1 0 +1 1 1 +1 1 1 +1 1 2 +1 1 2 +2 1 0 +2 1 0 +2 1 1 +2 1 1 +2 1 2 +2 1 2 +select * from t1 where b = 1 order by id,a,b; +id a b +0 0 1 +0 0 1 +0 1 1 +0 1 1 +0 2 1 +0 2 1 +1 0 1 +1 0 1 +1 1 1 +1 1 1 +1 2 1 +1 2 1 +2 0 1 +2 0 1 +2 1 1 +2 1 1 +2 2 1 +2 2 1 +select * from t1 where b = 1 order by id,a,b; +id a b +0 0 1 +0 0 1 +0 1 1 +0 1 1 +0 2 1 +0 2 1 +1 0 1 +1 0 1 +1 1 1 +1 1 1 +1 2 1 +1 2 1 +2 0 1 +2 0 1 +2 1 1 +2 1 1 +2 2 1 +2 2 1 +select * from t1 where id = 2 order by id,a,b; +id a b +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +2 1 0 +2 1 0 +2 1 1 +2 1 1 +2 1 2 +2 1 2 +2 2 0 +2 2 0 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +select * from t1 where id = 2 order by id,a,b; +id a b +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +2 1 0 +2 1 0 +2 1 1 +2 1 1 +2 1 2 +2 1 2 +2 2 0 +2 2 0 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +select * from t1 where a = 2 order by id,a,b; +id a b +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 2 0 +1 2 0 +1 2 1 +1 2 1 +1 2 2 +1 2 2 +2 2 0 +2 2 0 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +select * from t1 where a = 2 order by id,a,b; +id a b +0 2 0 +0 2 0 +0 2 1 +0 2 1 +0 2 2 +0 2 2 +1 2 0 +1 2 0 +1 2 1 +1 2 1 +1 2 2 +1 2 2 +2 2 0 +2 2 0 +2 2 1 +2 2 1 +2 2 2 +2 2 2 +select * from t1 where b = 2 order by id,a,b; +id a b +0 0 2 +0 0 2 +0 1 2 +0 1 2 +0 2 2 +0 2 2 +1 0 2 +1 0 2 +1 1 2 +1 1 2 +1 2 2 +1 2 2 +2 0 2 +2 0 2 +2 1 2 +2 1 2 +2 2 2 +2 2 2 +select * from t1 where b = 2 order by id,a,b; +id a b +0 0 2 +0 0 2 +0 1 2 +0 1 2 +0 2 2 +0 2 2 +1 0 2 +1 0 2 +1 1 2 +1 1 2 +1 2 2 +1 2 2 +2 0 2 +2 0 2 +2 1 2 +2 1 2 +2 2 2 +2 2 2 +select * from t1 where id = 3 order by id,a,b; +id a b +select * from t1 where id = 3 order by id,a,b; +id a b +select * from t1 where a = 3 order by id,a,b; +id a b +select * from t1 where a = 3 order by id,a,b; +id a b +select * from t1 where b = 3 order by id,a,b; +id a b +select * from t1 where b = 3 order by id,a,b; +id a b +select * from t1 where id = 4 order by id,a,b; +id a b +select * from t1 where id = 4 order by id,a,b; +id a b +select * from t1 where a = 4 order by id,a,b; +id a b +select * from t1 where a = 4 order by id,a,b; +id a b +select * from t1 where b = 4 order by id,a,b; +id a b +select * from t1 where b = 4 order by id,a,b; +id a b +select * from t1 where id = 5 order by id,a,b; +id a b +select * from t1 where id = 5 order by id,a,b; +id a b +select * from t1 where a = 5 order by id,a,b; +id a b +select * from t1 where a = 5 order by id,a,b; +id a b +select * from t1 where b = 5 order by id,a,b; +id a b +select * from t1 where b = 5 order by id,a,b; +id a b +select * from t1 where id = 6 order by id,a,b; +id a b +select * from t1 where id = 6 order by id,a,b; +id a b +select * from t1 where a = 6 order by id,a,b; +id a b +select * from t1 where a = 6 order by id,a,b; +id a b +select * from t1 where b = 6 order by id,a,b; +id a b +select * from t1 where b = 6 order by id,a,b; +id a b +select * from t1 where id = 7 order by id,a,b; +id a b +select * from t1 where id = 7 order by id,a,b; +id a b +select * from t1 where a = 7 order by id,a,b; +id a b +select * from t1 where a = 7 order by id,a,b; +id a b +select * from t1 where b = 7 order by id,a,b; +id a b +select * from t1 where b = 7 order by id,a,b; +id a b +select * from t1 where id = 8 order by id,a,b; +id a b +select * from t1 where id = 8 order by id,a,b; +id a b +select * from t1 where a = 8 order by id,a,b; +id a b +select * from t1 where a = 8 order by id,a,b; +id a b +select * from t1 where b = 8 order by id,a,b; +id a b +select * from t1 where b = 8 order by id,a,b; +id a b +select * from t1 where id = 9 order by id,a,b; +id a b +select * from t1 where id = 9 order by id,a,b; +id a b +select * from t1 where a = 9 order by id,a,b; +id a b +select * from t1 where a = 9 order by id,a,b; +id a b +select * from t1 where b = 9 order by id,a,b; +id a b +select * from t1 where b = 9 order by id,a,b; +id a b +select * from t1 where id = 10 order by id,a,b; +id a b +select * from t1 where id = 10 order by id,a,b; +id a b +select * from t1 where a = 10 order by id,a,b; +id a b +select * from t1 where a = 10 order by id,a,b; +id a b +select * from t1 where b = 10 order by id,a,b; +id a b +select * from t1 where b = 10 order by id,a,b; +id a b +select * from t1 where 0 = a or 4 = b order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +select * from t1 where 0 = a or 4 = b order by id,a,b; +id a b +0 0 0 +0 0 0 +0 0 1 +0 0 1 +0 0 2 +0 0 2 +1 0 0 +1 0 0 +1 0 1 +1 0 1 +1 0 2 +1 0 2 +2 0 0 +2 0 0 +2 0 1 +2 0 1 +2 0 2 +2 0 2 +select * from t1 where b in (3,4,3,1) and b = 0 order by id,a,b; +id a b +select * from t1 where b in (3,4,3,1) and b = 0 order by id,a,b; +id a b +select * from t1 where 1 = b and id = 3 and 1 = id and b in (1,0,1,3,4,0,4,4) order by id,a,b; +id a b +select * from t1 where 1 = b and id = 3 and 1 = id and b in (1,0,1,3,4,0,4,4) order by id,a,b; +id a b +select * from t1 where 1 = b and id in (1,1,4,4,1,0,3) order by id,a,b; +id a b +0 0 1 +0 0 1 +0 1 1 +0 1 1 +0 2 1 +0 2 1 +1 0 1 +1 0 1 +1 1 1 +1 1 1 +1 2 1 +1 2 1 +select * from t1 where 1 = b and id in (1,1,4,4,1,0,3) order by id,a,b; +id a b +0 0 1 +0 0 1 +0 1 1 +0 1 1 +0 2 1 +0 2 1 +1 0 1 +1 0 1 +1 1 1 +1 1 1 +1 2 1 +1 2 1 +select * from t1 where 1 = b and b = 4 order by id,a,b; +id a b +select * from t1 where 1 = b and b = 4 order by id,a,b; +id a b +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a int(11) DEFAULT NULL, +b int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY HASH( a ) +PARTITIONS 4; +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +aa COUNT(DISTINCT b) +insert into t1 values (1, 1); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +aa COUNT(DISTINCT b) +1 1 +insert into t1 values (2, 2), (2, 2); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +aa COUNT(DISTINCT b) +1 2 +insert into t1 values (3, 3), (3, 3), (3, 3); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +aa COUNT(DISTINCT b) +1 3 +insert into t1 values (4, 4), (4, 4), (4, 4), (4, 4); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a DESC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +aa COUNT(DISTINCT b) +4 4 +DROP TABLE IF EXISTS test; +CREATE TABLE NT_RP3763 (COL1 TINYINT(8) SIGNED COMMENT "NUMERIC NO INDEX" DEFAULT 41,COL2 VARCHAR(20),COL3 DATETIME,COL4 BIGINT,COL5 FLOAT) PARTITION BY RANGE (COL1 * COL3) (PARTITION P0 VALUES LESS THAN (0),PARTITION P1 VALUES LESS THAN (10),PARTITION P2 VALUES LESS THAN (20),PARTITION P3 VALUES LESS THAN (30),PARTITION P4 VALUES LESS THAN (40),PARTITION P5 VALUES LESS THAN (50),PARTITION PMX VALUES LESS THAN MAXVALUE); +insert into NT_RP3763 (COL1,COL2,COL3,COL4,COL5) values(-82,"夐齏醕皆磹漋甓崘潮嵙燷渏艂朼洛炷鉢儝鱈肇","5748\-06\-26\ 20:48:49",-3133527360541070260,-2.624880003397658e+38); +insert into NT_RP3763 (COL1,COL2,COL3,COL4,COL5) values(48,"簖鹩筈匹眜赖泽騈爷詵赺玡婙Ɇ郝鮙廛賙疼舢","7228\-12\-13\ 02:59:54",-6181009269190017937,2.7731105531290494e+38); +select * from `NT_RP3763` where `COL1` in (10, 48, -82); +COL1 COL2 COL3 COL4 COL5 +-82 夐齏醕皆磹漋甓崘潮嵙燷渏艂朼洛炷鉢儝鱈肇 5748-06-26 20:48:49 -3133527360541070260 -2.62488e38 +48 簖鹩筈匹眜赖泽騈爷詵赺玡婙Ɇ郝鮙廛賙疼舢 7228-12-13 02:59:54 -6181009269190017937 2.77311e38 +select * from `NT_RP3763` where `COL1` in (48); +COL1 COL2 COL3 COL4 COL5 +48 簖鹩筈匹眜赖泽騈爷詵赺玡婙Ɇ郝鮙廛賙疼舢 7228-12-13 02:59:54 -6181009269190017937 2.77311e38 +drop table if exists t2; +create table t2 (a int, b int) partition by range (a) (partition p0 values less than (0), partition p1 values less than (5)); +insert into t2(a) values (-1), (1); +select * from t2 where a > 10 or b is NULL order by a; +a b +-1 NULL +1 NULL +DROP TABLE IF EXISTS test; +CREATE TABLE test(a INT, b INT, PRIMARY KEY(a, b)) PARTITION BY RANGE (a + b) (PARTITION p0 VALUES LESS THAN (20),PARTITION p1 VALUES LESS THAN MAXVALUE); +INSERT INTO test(a, b) VALUES(1, 11),(2, 22),(3, 33),(10, 44),(9, 55); +select * FROM test WHERE a = 1; +a b +1 11 +select * FROM test WHERE b = 1; +a b +select * FROM test WHERE a = 1 AND b = 1; +a b +select * FROM test WHERE a + b = 2; +a b +set @@tidb_partition_prune_mode='static'; +drop table if exists t1; +create table t1(a int) partition by hash (a) partitions 10; +insert into t1 values (1), (2), (12), (3), (11), (13); +select * from t1 where a not between 2 and 2; +a +1 +11 +12 +13 +3 +select * from t1 where not (a < -20 or a > 20); +a +1 +11 +12 +13 +2 +3 +select * from t1 where not (a > 0 and a < 10); +a +11 +12 +13 +select * from t1 where not (a < -20); +a +1 +11 +12 +13 +2 +3 +select * from t1 where not (a > 20); +a +1 +11 +12 +13 +2 +3 +select * from t1 where not (a = 1); +a +11 +12 +13 +2 +3 +select * from t1 where not (a != 1); +a +1 +drop table if exists t2; +create table t2(a int) +partition by range (a) ( +partition p0 values less than (0), +partition p1 values less than (10), +partition p2 values less than (20) +); +explain format = 'brief' select * from t2 where not (a < 5); +id estRows task access object operator info +PartitionUnion 6666.67 root +├─TableReader 3333.33 root data:Selection +│ └─Selection 3333.33 cop[tikv] ge(test_partition_1.t2.a, 5) +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +└─TableReader 3333.33 root data:Selection + └─Selection 3333.33 cop[tikv] ge(test_partition_1.t2.a, 5) + └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo +set @@tidb_partition_prune_mode='dynamic'; +drop table if exists t3; +create table t3(a int) partition by hash (a) partitions 10; +insert into t3 values (1), (2), (12), (3), (11), (13); +select * from t3 where a not between 2 and 2; +a +1 +11 +12 +13 +3 +select * from t3 where not (a < -20 or a > 20); +a +1 +11 +12 +13 +2 +3 +select * from t3 where not (a > 0 and a < 10); +a +11 +12 +13 +select * from t3 where not (a < -20); +a +1 +11 +12 +13 +2 +3 +select * from t3 where not (a > 20); +a +1 +11 +12 +13 +2 +3 +select * from t3 where not (a = 1); +a +11 +12 +13 +2 +3 +select * from t3 where not (a != 1); +a +1 +set @@tidb_partition_prune_mode='static'; +DROP TABLE IF EXISTS t; +CREATE TABLE t (`COL1` int, `COL3` bigint) PARTITION BY HASH ((`COL1` * `COL3`))PARTITIONS 13; +select * FROM t WHERE col3 =2659937067964964513 and col1 = 783367513002; +COL1 COL3 +drop table if exists t; +CREATE TABLE `t` (`COL1` int NOT NULL DEFAULT '25' COMMENT 'NUMERIC PK',`COL3` bigint NOT NULL,PRIMARY KEY (`COL1`,`COL3`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH ((`COL1` * `COL3`))PARTITIONS 13; +insert into t(col1, col3) values(0, 3522101843073676459); +SELECT col1, COL3 FROM t WHERE COL1 IN (0,14158354938390,0) AND COL3 IN (3522101843073676459,-2846203247576845955,838395691793635638); +col1 COL3 +0 3522101843073676459 +set @@tidb_partition_prune_mode='dynamic'; +DROP TABLE IF EXISTS t; +create table t (a int primary key, b int, key (b)) partition by hash(a) (partition P0, partition p1, partition P2); +insert into t values (1, 1),(2, 2),(3, 3); +explain select * from t where a IN (1, 2); +id estRows task access object operator info +Batch_Point_Get_1 2.00 root table:t, partition:p1,P2 handle:[1 2], keep order:false, desc:false +explain select * from t where a IN (1, 2, 1); +id estRows task access object operator info +Batch_Point_Get_1 3.00 root table:t, partition:p1,P2 handle:[1 2 1], keep order:false, desc:false +create database Issue32007; +USE Issue32007; +create table t1 (a int, b tinyint, primary key (a)) partition by range (a) (partition p0 values less than (5),partition p1 values less than (20),partition p2 values less than (30),partition p3 values less than (40),partition p4 values less than MAXVALUE); +insert into t1 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (40, 40), (50, 50), (80, 80), (90, 90), (100, 100); +create table t3 (a int, b mediumint, primary key (a)); +insert into t3 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23); +set @@tidb_partition_prune_mode='static'; +select * from t3 where t3.a <> ALL (select t1.a from t1 partition (p0)) order by t3.a; +a b +10 10 +11 11 +12 12 +13 13 +14 14 +15 15 +16 16 +17 17 +18 18 +19 19 +20 20 +21 21 +22 22 +23 23 +5 5 +6 6 +7 7 +8 8 +9 9 +set @@tidb_partition_prune_mode='dynamic'; +select * from t3 where t3.a <> ALL (select t1.a from t1 partition (p0)) order by t3.a; +a b +10 10 +11 11 +12 12 +13 13 +14 14 +15 15 +16 16 +17 17 +18 18 +19 19 +20 20 +21 21 +22 22 +23 23 +5 5 +6 6 +7 7 +8 8 +9 9 +create database issue33231; +use issue33231; +set @@session.tidb_partition_prune_mode = 'dynamic'; +create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) clustered, key(c_int) ) partition by hash (c_int) partitions 4; +create table t2 like t1; +insert into t1 values(6, 'beautiful curran'); +insert into t1 values(7, 'epic kalam'); +insert into t1 values(7, 'affectionate curie'); +insert into t2 values(6, 'vigorous rhodes'); +insert into t2 values(7, 'sweet aryabhata'); +select /*+ INL_JOIN(t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_str <= t2.c_str and t2.c_int in (6, 7, 6); +c_int c_str c_int c_str +6 beautiful curran 6 vigorous rhodes +7 affectionate curie 7 sweet aryabhata +7 epic kalam 7 sweet aryabhata +create database ListDefaultPrune; +use ListDefaultPrune; +create table t (a int, b int) partition by list columns (a,b) (partition p1 values in ((1,1)), partition p2 values in ((2,2)), partition pDef default); +insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4); +analyze table t; +select * from t where a in (1,2) and b in (1,2); +a b +1 1 +1 2 +2 1 +2 2 +select * from t where a in (1,2) and b in (3,4); +a b +1 4 +2 3 +explain format='brief' select * from t where a in (1,2) and b in (3,4); +id estRows task access object operator info +TableReader 2.57 root partition:pDef data:Selection +└─Selection 2.57 cop[tikv] in(listdefaultprune.t.a, 1, 2), in(listdefaultprune.t.b, 3, 4) + └─TableFullScan 7.00 cop[tikv] table:t keep order:false +select * from t where a in (1,2) and b in (1,2); +a b +1 1 +1 2 +2 1 +2 2 +explain format='brief' select * from t where a in (1,2) and b in (1,2); +id estRows task access object operator info +TableReader 3.43 root partition:p1,p2,pDef data:Selection +└─Selection 3.43 cop[tikv] in(listdefaultprune.t.a, 1, 2), in(listdefaultprune.t.b, 1, 2) + └─TableFullScan 7.00 cop[tikv] table:t keep order:false +select * from t where a in (1) and b in (1); +a b +1 1 +explain format='brief' select * from t where a in (1) and b in (1); +id estRows task access object operator info +TableReader 0.86 root partition:p1,pDef data:Selection +└─Selection 0.86 cop[tikv] eq(listdefaultprune.t.a, 1), eq(listdefaultprune.t.b, 1) + └─TableFullScan 7.00 cop[tikv] table:t keep order:false +select * from t where a = 1 and b = 1; +a b +1 1 +explain format='brief' select * from t where a = 1 and b = 1; +id estRows task access object operator info +TableReader 0.86 root partition:p1,pDef data:Selection +└─Selection 0.86 cop[tikv] eq(listdefaultprune.t.a, 1), eq(listdefaultprune.t.b, 1) + └─TableFullScan 7.00 cop[tikv] table:t keep order:false +drop table t; +create table t (a int, b int) partition by list columns (a,b) (partition p1 values in ((1,1), (1,2)), partition p2 values in ((2,2),(2,1)), partition pDef default); +insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4); +analyze table t; +select * from t where a in (1,2) and b in (1,2); +a b +1 1 +1 2 +2 1 +2 2 +explain format='brief' select * from t where a in (1,2) and b in (1,2); +id estRows task access object operator info +TableReader 3.43 root partition:p1,p2,pDef data:Selection +└─Selection 3.43 cop[tikv] in(listdefaultprune.t.a, 1, 2), in(listdefaultprune.t.b, 1, 2) + └─TableFullScan 7.00 cop[tikv] table:t keep order:false +drop table t; +create table t (a int, b int) partition by list columns (a) (partition p1 values in (1), partition p2 values in (2), partition pDef default); +insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4); +analyze table t; +select * from t where a in (1,2); +a b +1 1 +1 2 +1 4 +2 1 +2 2 +2 3 +explain format='brief' select * from t where a in (1,2); +id estRows task access object operator info +TableReader 6.00 root partition:p1,p2 data:Selection +└─Selection 6.00 cop[tikv] in(listdefaultprune.t.a, 1, 2) + └─TableFullScan 7.00 cop[tikv] table:t keep order:false +select * from t where a = 1; +a b +1 1 +1 2 +1 4 +explain format='brief' select * from t where a = 1; +id estRows task access object operator info +TableReader 3.00 root partition:p1 data:Selection +└─Selection 3.00 cop[tikv] eq(listdefaultprune.t.a, 1) + └─TableFullScan 7.00 cop[tikv] table:t keep order:false +create database issue42273; +use issue42273; +CREATE TABLE t(a tinyint unsigned, b tinyint unsigned) PARTITION BY RANGE COLUMNS (a,b)( +PARTITION p0 VALUES LESS THAN (10,255), +PARTITION p1 VALUES LESS THAN (20,MAXVALUE), +PARTITION p2 VALUES LESS THAN (30,255), +PARTITION p3 VALUES LESS THAN (MAXVALUE, 0)); +insert into t values(20, 30); +analyze table t; +explain format='brief' select * from t where a = 20; +id estRows task access object operator info +TableReader 1.00 root partition:p1 data:Selection +└─Selection 1.00 cop[tikv] eq(issue42273.t.a, 20) + └─TableFullScan 1.00 cop[tikv] table:t keep order:false +explain format='brief' select * from t where a > 10 and a <= 20; +id estRows task access object operator info +TableReader 1.00 root partition:p1 data:Selection +└─Selection 1.00 cop[tikv] gt(issue42273.t.a, 10), le(issue42273.t.a, 20) + └─TableFullScan 1.00 cop[tikv] table:t keep order:false +select * from t where a = 20; +a b +20 30 +select * from t where a > 10 and a <= 20; +a b +20 30 +drop database issue42273; +create database issue43459; +use issue43459; +set @@session.tidb_partition_prune_mode = 'dynamic'; +CREATE TABLE test1 (ID varchar(50) NOT NULL, +PARTITION_NO int(11) NOT NULL DEFAULT '0', +CREATE_TIME datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (ID,PARTITION_NO,CREATE_TIME), +KEY index_partition_no (PARTITION_NO) +) PARTITION BY RANGE COLUMNS(PARTITION_NO,CREATE_TIME) +(PARTITION 2023p1 VALUES LESS THAN (200000,'2023-01-01 00:00:00'), +PARTITION 2023p2 VALUES LESS THAN (300000,'2023-01-01 00:00:00')) ; +insert into test1 values("1", 200000, "2022-12-29 12:00:00"), ("2",200000,"2023-01-01"); +analyze table test1; +explain select * from test1 where partition_no > 199999; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] gt(issue43459.test1.partition_no, 199999) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no = 200000; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] eq(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no >= 200000; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] ge(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no < 200000; +id estRows task access object operator info +IndexReader_10 0.00 root partition:2023p1 index:Selection_9 +└─Selection_9 0.00 cop[tikv] lt(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no <= 200000; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] le(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no > 200000; +id estRows task access object operator info +IndexReader_10 0.00 root partition:2023p2 index:Selection_9 +└─Selection_9 0.00 cop[tikv] gt(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +select * from test1 partition (2023p1); +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 12:00:00 +select * from test1 partition (2023p2); +ID PARTITION_NO CREATE_TIME +2 200000 2023-01-01 00:00:00 +select * from test1; +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 12:00:00 +2 200000 2023-01-01 00:00:00 +select * from test1 where partition_no = 200000; +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 12:00:00 +2 200000 2023-01-01 00:00:00 +select * from test1 where partition_no >= 200000; +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 12:00:00 +2 200000 2023-01-01 00:00:00 +drop table test1; +CREATE TABLE test1 (ID varchar(50) NOT NULL, +PARTITION_NO int(11) NOT NULL DEFAULT '0', +CREATE_TIME date NOT NULL DEFAULT CURRENT_DATE, +PRIMARY KEY (ID,PARTITION_NO,CREATE_TIME), +KEY index_partition_no (PARTITION_NO) +) PARTITION BY RANGE COLUMNS(PARTITION_NO,CREATE_TIME) +(PARTITION 2023p1 VALUES LESS THAN (200000,'2023-01-01 00:00:00'), +PARTITION 2023p2 VALUES LESS THAN (300000,'2023-01-01 00:00:00')) ; +insert into test1 values("1", 200000, "2022-12-29 12:00:00"), ("2",200000,"2023-01-01"); +analyze table test1; +explain select * from test1 where partition_no > 199999; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] gt(issue43459.test1.partition_no, 199999) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no = 200000; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] eq(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no >= 200000; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] ge(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no < 200000; +id estRows task access object operator info +IndexReader_10 0.00 root partition:2023p1 index:Selection_9 +└─Selection_9 0.00 cop[tikv] lt(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no <= 200000; +id estRows task access object operator info +IndexReader_10 2.00 root partition:all index:Selection_9 +└─Selection_9 2.00 cop[tikv] le(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +explain select * from test1 where partition_no > 200000; +id estRows task access object operator info +IndexReader_10 0.00 root partition:2023p2 index:Selection_9 +└─Selection_9 0.00 cop[tikv] gt(issue43459.test1.partition_no, 200000) + └─IndexFullScan_8 2.00 cop[tikv] table:test1, index:PRIMARY(ID, PARTITION_NO, CREATE_TIME) keep order:false +select * from test1 partition (2023p1); +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 +select * from test1 partition (2023p2); +ID PARTITION_NO CREATE_TIME +2 200000 2023-01-01 +select * from test1; +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 +2 200000 2023-01-01 +select * from test1 where partition_no = 200000; +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 +2 200000 2023-01-01 +select * from test1 where partition_no >= 200000; +ID PARTITION_NO CREATE_TIME +1 200000 2022-12-29 +2 200000 2023-01-01 +drop database issue43459; diff --git a/tests/integrationtest/t/black_list.test b/tests/integrationtest/t/black_list.test index 0be2855feb..70fe4bab1c 100644 --- a/tests/integrationtest/t/black_list.test +++ b/tests/integrationtest/t/black_list.test @@ -39,3 +39,7 @@ delete from mysql.expr_pushdown_blacklist where name='lt' and store_type = 'tikv admin reload expr_pushdown_blacklist; explain format = 'brief' select * from t where a < 1; + +delete from mysql.expr_pushdown_blacklist; + +admin reload expr_pushdown_blacklist; diff --git a/tests/integrationtest/t/expression/issues.test b/tests/integrationtest/t/expression/issues.test index 7425607dcf..e17313f066 100644 --- a/tests/integrationtest/t/expression/issues.test +++ b/tests/integrationtest/t/expression/issues.test @@ -528,6 +528,8 @@ insert into mysql.expr_pushdown_blacklist values('json_extract','tikv',''); admin reload expr_pushdown_blacklist; SELECT * FROM testjson WHERE JSON_EXTRACT(j,'$.test'); select * from testjson where j; +delete from mysql.expr_pushdown_blacklist; +admin reload expr_pushdown_blacklist; # TestIssue15743 drop table if exists t0; diff --git a/tests/integrationtest/t/planner/core/indexmerge_path.test b/tests/integrationtest/t/planner/core/indexmerge_path.test new file mode 100644 index 0000000000..89ef9fe9e5 --- /dev/null +++ b/tests/integrationtest/t/planner/core/indexmerge_path.test @@ -0,0 +1,232 @@ +# TestAnalyzeMVIndexWarnings +drop table if exists t; +create table t(a int, b int, c int, j json, +index(a), index(b), +index idx(a, b, (cast(j as signed array)), c), +index idx2(a, b, (cast(j->'$.str' as char(10) array)), c)); +set tidb_analyze_version=2; +--enable_warnings +analyze table t; +analyze table t index idx; +set tidb_analyze_version=1; +analyze table t; +analyze table t index idx; +analyze table t index a; +analyze table t index a, idx, idx2; +--disable_warnings + + +# TestIndexMergeJSONMemberOf +drop table if exists t; +create table t( +a int, j0 json, j1 json, +index j0_0((cast(j0->'$.path0' as signed array))), +index j0_1((cast(j0->'$.path1' as signed array))), +index j0_string((cast(j0->'$.path_string' as char(10) array))), +index j0_date((cast(j0->'$.path_date' as date array))), +index j1((cast(j1 as signed array)))); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where (1 member of (j0->'$.path0')); +explain format = 'brief' select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.XXX')) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10; +explain format = 'brief' select /*+ use_index(t, j0_0) */ * from t where (1 member of (j0->'$.path0')); +explain format = 'brief' select /*+ use_index(t, j0_1) */ * from t where (1 member of (j0->'$.path1')) and a<10; +explain format = 'brief' select * from t use index(j0_0) where (1 member of (j0->'$.path0')); +explain format = 'brief' select * from t use index(j0_1) where (1 member of (j0->'$.path1')) and a<10; +explain format = 'brief' select * from t force index(j0_0) where (1 member of (j0->'$.path0')); +explain format = 'brief' select * from t force index(j0_1) where (1 member of (j0->'$.path1')) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j1) */ * from t where (1 member of (j0->'$.path1')) and (2 member of (j1)) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]'); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]'); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0')); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '[1, 2, 3]') and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '[1, 2, 3]') and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('[1, 2, 3]', (j0->'$.path0')) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1'); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1'); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0')); +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_contains((j0->'$.path0'), '1') and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps((j0->'$.path0'), '1') and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_0) */ * from t where json_overlaps('1', (j0->'$.path0')) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where ("a" member of (j0->'$.path_string')); +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where ("a" member of (j0->'$.path_string')) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '["a", "b", "c"]'); +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_contains((j0->'$.path_string'), '["a", "b", "c"]') and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '["a", "b", "c"]'); +explain format = 'brief' select /*+ use_index_merge(t, j0_string) */ * from t where json_overlaps((j0->'$.path_string'), '["a", "b", "c"]') and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where ("2023-01-01" member of (j0->'$.path_date')); +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where ("2023-01-01" member of (j0->'$.path_date')) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))); +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_contains((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10; +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))); +explain format = 'brief' select /*+ use_index_merge(t, j0_date) */ * from t where json_overlaps((j0->'$.path_date'), json_array(cast('2023-01-01' as date), cast('2023-01-02' as date), cast('2023-01-03' as date))) and a<10; + + +# TestDNFOnMVIndex +drop table if exists t; +create table t(a int, b int, c int, j json, +index idx1((cast(j as signed array))), +index idx2(a, b, (cast(j as signed array)), c)); +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where (1 member of (j)) or (2 member of (j)); +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where ((1 member of (j)) or (2 member of (j))) and (a > 10); +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where (json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]')); +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where ((json_overlaps(j, '[1, 2]')) or (json_overlaps(j, '[3, 4]'))) and (a > 10); +explain format = 'brief' select /*+ use_index_merge(t, idx1) */ * from t where (json_contains(j, '[1, 2]')) or (json_contains(j, '[3, 4]')); +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j))); +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where (a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)) and c=14); +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where ((a=1 and b=2 and (3 member of (j))) or (a=11 and b=12 and (13 member of (j)))) and (c > 10); + + +# TestCompositeMVIndex +drop table if exists t; +create table t(a int, b int , c int, j json, +index idx(a, b, (cast(j as signed array)), c), +index idx2(a, b, (cast(j->'$.str' as char(10) array)), c)); +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4; +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)); +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1 and b=2; +explain format = 'brief' select /*+ use_index_merge(t, idx) */ * from t where a=1; +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str')) and c=4; +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2 and ('3' member of (j->'$.str')); +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1 and b=2; +explain format = 'brief' select /*+ use_index_merge(t, idx2) */ * from t where a=1; +explain format = 'brief' select /*+ use_index(t, idx) */ * from t where a=1 and b=2 and (3 member of (j)) and c=4; +explain format = 'brief' select * from t use index(idx) where a=1 and b=2 and (3 member of (j)); +explain format = 'brief' select /*+ use_index(t, idx) */ * from t where a=1 and b=2; +explain format = 'brief' select * from t use index(idx) where a=1; +explain format = 'brief' select * from t force index(idx) where a=1 and b=2 and (3 member of (j)); +explain format = 'brief' select * from t force index(idx) where a=1; + + +# TestMVIndexSelection +drop table if exists t; +create table t(a int, j json, +index i_int((cast(j->'$.int' as signed array)))); +explain format = 'brief' select (j->'$.int') from t where (1 member of (j->'$.int')); +explain format = 'brief' select * from t where (1 member of (j->'$.int')); +explain format = 'brief' select * from t where (1 member of (j->'$.int')) and a<10; +explain format = 'brief' select (j->'$.int') from t where json_contains((j->'$.int'), '[1, 2, 3]'); +explain format = 'brief' select * from t where json_contains((j->'$.int'), '[1, 2, 3]'); +explain format = 'brief' select * from t where json_contains((j->'$.int'), '[1, 2, 3]') and a<10; +explain format = 'brief' select (j->'$.int') from t where json_overlaps((j->'$.int'), '[1, 2, 3]'); +explain format = 'brief' select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]'); +explain format = 'brief' select * from t where json_overlaps((j->'$.int'), '[1, 2, 3]') and a<10; + + +# TestMVIndexIndexMergePlanCache +drop table if exists t; +create table t(j json, index kj((cast(j as signed array)))); +--enable_warnings +prepare st from 'select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j))'; +--disable_warnings +execute st; +execute st; +select @@last_plan_from_cache; + + +# TestMVIndexPointGet +drop table if exists t; +create table t(j json, unique kj((cast(j as signed array)))); +explain select j from t where j=1; +explain select j from t where j=1 or j=2; +explain select j from t where j in (1, 2); + + +# TestEnforceMVIndex +drop table if exists t; +create table t(a int, j json, index kj((cast(j as signed array)))); +-- error 1815 +explain format = 'brief' select /*+ use_index(t, kj) */ * from t; +-- error 1815 +explain format = 'brief' select /*+ use_index(t, kj) */ a from t; +-- error 1815 +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where a<10; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) and a=10; +-- error 1815 +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) or a=10; +explain format = 'brief' select /*+ use_index_merge(t, kj) */ * from t; +explain format = 'brief' select /*+ use_index_merge(t, kj) */ a from t; +explain format = 'brief' select /*+ use_index_merge(t, kj) */ * from t where a<10; +explain format = 'brief' select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j)) or a=10; + + +# TestMVIndexInvisible +drop table if exists t; +create table t(a int, j json, index kj((cast(j as signed array)))); +explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); +ALTER TABLE t ALTER INDEX kj INVISIBLE; +explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); +explain format='brief' select /*+ use_index_merge(t, kj) */ * from t where (1 member of (j)); +ALTER TABLE t ALTER INDEX kj VISIBLE; +explain format='brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)); + + +# TestMVIndexFullScan +drop table if exists t; +create table t(j json, index kj((cast(j as signed array)))); +insert into t values ('[1]'); +insert into t values ('[1, 2]'); +insert into t values ('[]'); +insert into t values (NULL); +select /*+ use_index_merge(t, kj) */ count(*) from t; +select /*+ use_index_merge(t, kj) */ count(*) from t where (1 member of (j)); +select /*+ use_index_merge(t, kj) */ count(*) from t where json_contains((j), '[1]'); +select /*+ use_index_merge(t, kj) */ count(*) from t where json_overlaps((j), '[1]'); +-- error 1815 +select /*+ use_index(t, kj) */ count(*) from t; + + +# TestMVIndexEmptyArray +drop table if exists t; +create table t(j json, index kj((cast(j as signed array)))); +insert into t values ('[1]'); +insert into t values ('[1, 2]'); +insert into t values ('[]'); +insert into t values (NULL); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[]'); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[1]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[1]'); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[1, 2]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[1, 2]'); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_contains(j, '[1, 10]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_contains(j, '[1, 10]'); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[]'); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[1]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[1]'); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[1, 2]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[1, 2]'); +-- sorted_result +select /*+ use_index_merge(t) */ * from t where json_overlaps(j, '[1, 10]'); +-- sorted_result +select /*+ ignore_index(t, kj) */ * from t where json_overlaps(j, '[1, 10]'); + + +# TestIndexMergeJSONMemberOf2 +drop table if exists t; +create table t( +a int, j0 json, j1 json, +index j0_0((cast(j0->'$.path0' as signed array)))); +insert into t values(1, '{"path0" : [1,2,3]}', null ); ; +select /*+ no_index_merge() */ a from t where (1 member of (j0->'$.path0')); ; +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')); ; + + diff --git a/tests/integrationtest/t/planner/core/integration.test b/tests/integrationtest/t/planner/core/integration.test new file mode 100644 index 0000000000..c53c971e6e --- /dev/null +++ b/tests/integrationtest/t/planner/core/integration.test @@ -0,0 +1,2092 @@ +# TestShowSubquery +set tidb_cost_model_version=2; +drop table if exists t; +create table t(a varchar(10), b int, c int); +show columns from t where true; +show columns from t where field = 'b'; +show columns from t where field in (select 'b'); +show columns from t where field in (select 'b') and true; +show columns from t where field in (select 'b') and false; +insert into t values('c', 0, 0); +show columns from t where field < all (select a from t); +insert into t values('b', 0, 0); +show columns from t where field < all (select a from t); + + +# TestJoinOperatorRightAssociative +drop table if exists t; +create table t(a int, b int); +insert into t values(1,10),(2,20); +--error 1054 +select t1.* from t t0 cross join (t t1 join t t2 on 100=t0.a); + + +# TestPpdWithSetVar +drop table if exists t; +create table t(c1 int, c2 varchar(255)); +insert into t values(1,'a'),(2,'d'),(3,'c'); +select t01.c1,t01.c2,t01.c3 from (select t1.*,@c3:=@c3+1 as c3 from (select t.*,@c3:=0 from t order by t.c1)t1)t01 where t01.c3=1 and t01.c2='d'; +select t01.c1,t01.c2,t01.c3 from (select t1.*,@c3:=@c3+1 as c3 from (select t.*,@c3:=0 from t order by t.c1)t1)t01 where t01.c3=2 and t01.c2='d'; + + +# TestBitColErrorMessage +drop table if exists bit_col_t; +create table bit_col_t (a bit(64)); +drop table bit_col_t; +create table bit_col_t (a bit(1)); +drop table bit_col_t; +--error 3013 +create table bit_col_t (a bit(0)); +--error 1439 +create table bit_col_t (a bit(65)); + + +# TestAggPushDownLeftJoin +set tidb_cost_model_version=2; +drop table if exists customer; +create table customer (C_CUSTKEY bigint(20) NOT NULL, C_NAME varchar(25) NOT NULL, C_ADDRESS varchar(25) NOT NULL, PRIMARY KEY (`C_CUSTKEY`) /*T![clustered_index] CLUSTERED */); +drop table if exists orders; +create table orders (O_ORDERKEY bigint(20) NOT NULL, O_CUSTKEY bigint(20) NOT NULL, O_TOTALPRICE decimal(15,2) NOT NULL, PRIMARY KEY (`O_ORDERKEY`) /*T![clustered_index] CLUSTERED */); +insert into customer values (6, "xiao zhang", "address1"); +set @@tidb_opt_agg_push_down=1; +select c_custkey, count(o_orderkey) as c_count from customer left outer join orders on c_custkey = o_custkey group by c_custkey; +explain format='brief' select c_custkey, count(o_orderkey) as c_count from customer left outer join orders on c_custkey = o_custkey group by c_custkey; +select c_custkey, count(o_orderkey) as c_count from orders right outer join customer on c_custkey = o_custkey group by c_custkey; +explain format='brief' select c_custkey, count(o_orderkey) as c_count from orders right outer join customer on c_custkey = o_custkey group by c_custkey; + + +# TestIssue22298 +drop table if exists t; +create table t(a int, b int); +--error 1054 +select * from t where 0 and c = 10; + + +# TestIssue24571 +create view v as select 1 as b; +drop table if exists t; +create table t (a int); +update v, t set a=2; +--error 1288 +update v, t set b=2; +create database db1; +use db1; +update planner__core__integration.t, (select 1 as a) as t set planner__core__integration.t.a=1; +update (select 1 as a) as t, planner__core__integration.t set planner__core__integration.t.a=1; + + +# TestBuildUpdateListResolver +drop table if exists t; +drop table if exists t1; +create table t(a int); +create table t1(b int); +--error 1288 +update (select 1 as a) as t set a=1; +--error 1288 +update (select 1 as a) as t, t1 set a=1; +drop table if exists t; +drop table if exists t1; +create table t(a int default -1, c int as (a+10) stored); +insert into t(a) values(1); +update planner__core__integration.t, (select 1 as b) as t set planner__core__integration.t.a=default; +select * from t; +drop table if exists t; + + +# TestIssue22828 +drop table if exists t1; +create table t (c int); +--error 1054 +select group_concat((select concat(c,group_concat(c)) FROM t where xxx=xxx)) FROM t; + + +# TestIssue35623 +drop table if exists t1; +drop view if exists v1; +CREATE TABLE t1(c0 INT UNIQUE); +CREATE definer='root'@'localhost' VIEW v1(c0) AS SELECT 1 FROM t1; +SELECT v1.c0 FROM v1 WHERE (true)LIKE(v1.c0); +SELECT v2.c0 FROM (select 1 as c0 from t1) v2 WHERE (v2.c0)like(True); + + +# TestIssue37971 +drop table if exists t3; +CREATE TABLE t3(c0 INT, primary key(c0)); +SELECT v2.c0 FROM (select 1 as c0 from t3) v2 WHERE (v2.c0)like(True); + + +# TestJoinNotNullFlag +drop table if exists t1, t2; +create table t1(x int not null); +create table t2(x int); +insert into t2 values (1); +select IFNULL((select t1.x from t1 where t1.x = t2.x), 'xxx') as col1 from t2; +select ifnull(t1.x, 'xxx') from t2 left join t1 using(x); +select ifnull(t1.x, 'xxx') from t2 natural left join t1; + + +# TestAntiJoinConstProp +drop table if exists t1, t2; +create table t1(a int not null, b int not null); +insert into t1 values (1,1); +create table t2(a int not null, b int not null); +insert into t2 values (2,2); +select * from t1 where t1.a not in (select a from t2 where t2.a = t1.a and t2.a > 1); +select * from t1 where t1.a not in (select a from t2 where t2.b = t1.b and t2.a > 1); +select * from t1 where t1.a not in (select a from t2 where t2.b = t1.b and t2.b > 1); +select q.a in (select count(*) from t1 s where not exists (select 1 from t1 p where q.a > 1 and p.a = s.a)) from t1 q; +select q.a in (select not exists (select 1 from t1 p where q.a > 1 and p.a = s.a) from t1 s) from t1 q; +drop table t1, t2; +create table t1(a int not null, b int); +insert into t1 values (1,null); +create table t2(a int not null, b int); +insert into t2 values (2,2); +select * from t1 where t1.a not in (select a from t2 where t2.b > t1.b); +select * from t1 where t1.a not in (select a from t2 where t1.a = 2); + + +# TestPartitionTableDynamicModeUnderNewCollation +create database test_new_collation; +use test_new_collation; +set @@tidb_partition_prune_mode = 'dynamic'; +CREATE TABLE thash (a int, c varchar(20) charset utf8mb4 collate utf8mb4_general_ci, key(a)) partition by hash(a) partitions 4; +CREATE TABLE trange (a int, c varchar(20) charset utf8mb4 collate utf8mb4_general_ci, key(a)) partition by range(a) ( + partition p0 values less than (10), + partition p1 values less than (20), + partition p2 values less than (30), + partition p3 values less than (40)); +insert into thash values (1, 'a'), (1, 'A'), (11, 'a'), (11, 'A'), (21, 'a'), (21, 'A'), (31, 'a'), (31, 'A'); +insert into trange values (1, 'a'), (1, 'A'), (11, 'a'), (11, 'A'), (21, 'a'), (21, 'A'), (31, 'a'), (31, 'A'); +--sorted_result +select * from thash use index(a) where a in (1, 11, 31) and c='a'; +--sorted_result +select * from thash ignore index(a) where a in (1, 11, 31) and c='a'; +--sorted_result +select * from trange use index(a) where a in (1, 11, 31) and c='a'; +--sorted_result +select * from trange ignore index(a) where a in (1, 11, 31) and c='a'; +create table strrange(a varchar(10) charset utf8mb4 collate utf8mb4_general_ci, b int) partition by range columns(a) ( + partition p0 values less than ('a'), + partition p1 values less than ('k'), + partition p2 values less than ('z')); +insert into strrange values ('a', 1), ('A', 1), ('y', 1), ('Y', 1), ('q', 1); +--sorted_result +select * from strrange where a in ('a', 'y'); +create table strlist(a varchar(10) charset utf8mb4 collate utf8mb4_general_ci, b int) partition by list columns (a) ( + partition p0 values in ('a', 'b'), + partition p1 values in ('c', 'd'), + partition p2 values in ('e', 'f')); +insert into strlist values ('a', 1), ('A', 1), ('d', 1), ('D', 1), ('e', 1); +--sorted_result +select * from strlist where a='a'; +--sorted_result +select * from strlist where a in ('D', 'e'); +use planner__core__integration; + +# TestIssue40910 +drop table if exists t; +create table t(a int, b int, index idx_a(a), index idx_b(b)); +select * from t where a > 1 and a < 10 order by b; +select @@last_plan_from_binding; +create session binding for select * from t where a > 1 and a < 10 order by b using select /*+ use_index(t, idx_a) */ * from t where a > 1 and a < 10 order by b; +select * from t where a > 1 and a < 10 order by b; +select @@last_plan_from_binding; +select /*+ use_index(t, idx_b) */ * from t where a > 1 and a < 10 order by b; +select @@last_plan_from_binding; +--enable_warnings +select /*+ use_index(t, idx_b) */ * from t where a > 1 and a < 10 order by b; +--disable_warnings + + +# TestSplitJoinHint +drop table if exists t; +create table t(a int, b int, index idx_a(a), index idx_b(b)); +set @@tidb_opt_advanced_join_hint=0; +--enable_warnings +select /*+ hash_join(t1) merge_join(t2) */ * from t t1 join t t2 join t t3 where t1.a = t2.a and t2.a=t3.a; +--disable_warnings +set @@tidb_opt_advanced_join_hint=1; +--enable_warnings +select /*+ hash_join(t1) merge_join(t2) */ * from t t1 join t t2 join t t3 where t1.a = t2.a and t2.a=t3.a; +--disable_warnings +set @@tidb_opt_advanced_join_hint=DEFAULT; + + +# TestINLJHintSmallTable +drop table if exists t1, t2; +create table t1(a int not null, b int, key(a)); +insert into t1 values(1,1),(2,2); +create table t2(a int not null, b int, key(a)); +insert into t2 values(1,1),(2,2),(3,3),(4,4),(5,5); +analyze table t1, t2; +explain format = 'brief' select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a = t2.a; + + +# TestIssue46580 +drop table if exists t0,t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 BOOL, c1 BOOL); +INSERT INTO t1 VALUES (false, true); +INSERT INTO t1 VALUES (true, true); +CREATE definer='root'@'localhost' VIEW v0(c0, c1, c2) AS SELECT t1.c0, LOG10(t0.c0), t1.c0 FROM t0, t1; +INSERT INTO t0(c0) VALUES (3); +SELECT /*+ MERGE_JOIN(t1, t0, v0)*/v0.c2, t1.c0 FROM v0, t0 CROSS JOIN t1 ORDER BY -v0.c1; + + +# TestInvisibleIndex +drop table if exists t; +create table t(a int, b int, unique index i_a (a) invisible, unique index i_b(b)); +insert into t values (1,2); +admin check table t; +select a from t order by a; +explain select a from t order by a; +select a from t where a > 0; +explain select a from t where a > 1; +--error 1176 +select * from t use index(i_a); +--error 1176 +select * from t force index(i_a); +--error 1176 +select * from t ignore index(i_a); +--enable_warnings +select /*+ USE_INDEX(t, i_a) */ * from t; +select /*+ IGNORE_INDEX(t, i_a), USE_INDEX(t, i_b) */ a from t order by a; +select /*+ FORCE_INDEX(t, i_a), USE_INDEX(t, i_b) */ a from t order by a; +select /*+ FORCE_INDEX(aaa) */ * from t; +--disable_warnings +admin check table t; +admin check index t i_a; + + +# TestTopNByConstFunc +select max(t.col) from (select 'a' as col union all select '' as col) as t; + + +# TestIssue32672 +drop table if exists t; +create table t(a int); +explain format='verbose' select /*+ stream_agg() */ count(*) from t; +explain format='verbose' select /*+ hash_agg() */ count(*) from t; + + +# TestIssue15546 +drop table if exists t, pt, vt; +create table t(a int, b int); +insert into t values(1, 1); +create table pt(a int primary key, b int) partition by range(a) (PARTITION `p0` VALUES LESS THAN (10), PARTITION `p1` VALUES LESS THAN (20), PARTITION `p2` VALUES LESS THAN (30)); +insert into pt values(1, 1), (11, 11), (21, 21); +create definer='root'@'localhost' view vt(a, b) as select a, b from t; +select * from pt, vt where pt.a = vt.a; + + +# TestApproxCountDistinctInPartitionTable +drop table if exists t; +create table t(a int(11), b int) partition by range (a) (partition p0 values less than (3), partition p1 values less than maxvalue); +insert into t values(1, 1), (2, 1), (3, 1), (4, 2), (4, 2); +set session tidb_opt_agg_push_down=1; +set @@tidb_partition_prune_mode='static'; +explain format = 'brief' select approx_count_distinct(a), b from t group by b order by b desc; +select approx_count_distinct(a), b from t group by b order by b desc; + + +# TestIssue17813 +drop table if exists hash_partition_overflow; +create table hash_partition_overflow (c0 bigint unsigned) partition by hash(c0) partitions 3; +insert into hash_partition_overflow values (9223372036854775808); +select * from hash_partition_overflow where c0 = 9223372036854775808; +select * from hash_partition_overflow where c0 in (1, 9223372036854775808); + + +# TestIssue15813 +drop table if exists t0, t1; +create table t0(c0 int primary key); +create table t1(c0 int primary key); +CREATE INDEX i0 ON t0(c0); +CREATE INDEX i0 ON t1(c0); +select /*+ MERGE_JOIN(t0, t1) */ * from t0, t1 where t0.c0 = t1.c0; + + +# TestIssue31261 +drop table if exists PK_MULTI_COL_5177; + CREATE TABLE PK_MULTI_COL_5177 ( + COL1 binary(10) NOT NULL, + COL2 varbinary(10) NOT NULL, + COL3 smallint(45) NOT NULL, + PRIMARY KEY (COL1(5),COL2,COL3), + UNIQUE KEY UIDXM (COL1(5),COL2), + UNIQUE KEY UIDX (COL2), + KEY IDX3 (COL3), + KEY IDXM (COL3,COL2)); +insert into PK_MULTI_COL_5177(col1, col2, col3) values(0x00000000000000000000, 0x002B200DF5BA03E59F82, 1); +select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 in (0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82, 0x002B200DF5BA03E59F82); +select col1, col2 from PK_MULTI_COL_5177 where col1 = 0x00000000000000000000 and col2 = 0x002B200DF5BA03E59F82; + + +# TestFullGroupByOrderBy +drop table if exists t; +create table t(a int, b int); +select count(a) as b from t group by a order by b; +--error 1055 +select count(a) as cnt from t group by a order by b; + + +# TestIssue15858 +drop table if exists t; +create table t(a int primary key); +select * from t t1, (select a from t order by a+1) t2 where t1.a = t2.a; + + +# TestIssue15846 +drop table if exists t0, t1; +CREATE TABLE t0(t0 INT UNIQUE); +CREATE TABLE t1(c0 FLOAT); +INSERT INTO t1(c0) VALUES (0); +INSERT INTO t0(t0) VALUES (NULL), (NULL); +SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1; +drop table if exists t0, t1; +CREATE TABLE t0(t0 INT); +CREATE TABLE t1(c0 FLOAT); +INSERT INTO t1(c0) VALUES (0); +INSERT INTO t0(t0) VALUES (NULL), (NULL); +SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1; +drop table if exists t0, t1; +CREATE TABLE t0(t0 INT); +CREATE TABLE t1(c0 FLOAT); +create unique index idx on t0(t0); +INSERT INTO t1(c0) VALUES (0); +INSERT INTO t0(t0) VALUES (NULL), (NULL); +SELECT t1.c0 FROM t1 LEFT JOIN t0 ON 1; + + +# TestFloorUnixTimestampPruning +drop table if exists floor_unix_timestamp; +create table floor_unix_timestamp (ts timestamp(3)) +partition by range (floor(unix_timestamp(ts))) ( +partition p0 values less than (unix_timestamp('2020-04-05 00:00:00')), +partition p1 values less than (unix_timestamp('2020-04-12 00:00:00')), +partition p2 values less than (unix_timestamp('2020-04-15 00:00:00'))); +insert into floor_unix_timestamp values ('2020-04-04 00:00:00'); +insert into floor_unix_timestamp values ('2020-04-04 23:59:59.999'); +insert into floor_unix_timestamp values ('2020-04-05 00:00:00'); +insert into floor_unix_timestamp values ('2020-04-05 00:00:00.001'); +insert into floor_unix_timestamp values ('2020-04-12 01:02:03.456'); +insert into floor_unix_timestamp values ('2020-04-14 00:00:42'); +select count(*) from floor_unix_timestamp where '2020-04-05 00:00:00.001' = ts; +select * from floor_unix_timestamp where ts > '2020-04-05 00:00:00' order by ts; +select count(*) from floor_unix_timestamp where ts <= '2020-04-05 23:00:00'; +select * from floor_unix_timestamp partition(p1, p2) where ts > '2020-04-14 00:00:00'; + + +# TestIssue16290And16292 +drop table if exists t; +create table t(a int, b int, primary key(a)); +insert into t values(1, 1); +set session tidb_opt_agg_push_down = 0; +select avg(a) from (select * from t ta union all select * from t tb) t; +select avg(b) from (select * from t ta union all select * from t tb) t; +select count(distinct a) from (select * from t ta union all select * from t tb) t; +select count(distinct b) from (select * from t ta union all select * from t tb) t; +set session tidb_opt_agg_push_down = 1; +select avg(a) from (select * from t ta union all select * from t tb) t; +select avg(b) from (select * from t ta union all select * from t tb) t; +select count(distinct a) from (select * from t ta union all select * from t tb) t; +select count(distinct b) from (select * from t ta union all select * from t tb) t; + + +# TestTableDualWithRequiredProperty +drop table if exists t1, t2; +create table t1 (a int, b int) partition by range(a) (partition p0 values less than(10), partition p1 values less than MAXVALUE); +create table t2 (a int, b int); +select /*+ MERGE_JOIN(t1, t2) */ * from t1 partition (p0), t2 where t1.a > 100 and t1.a = t2.a; + + +# TestIssue16837 +drop table if exists t; +create table t(a int,b int,c int,d int,e int,unique key idx_ab(a,b),unique key(c),unique key(d)); +--enable_warnings +explain format = 'brief' select /*+ use_index_merge(t,c,idx_ab) */ * from t where a = 1 or (e = 1 and c = 1); +--disable_warnings +insert into t values (2, 1, 1, 1, 2); +select /*+ use_index_merge(t,c,idx_ab) */ * from t where a = 1 or (e = 1 and c = 1); + + +# TestIndexMergePartialScansClusteredIndex +drop table if exists t; +create table t (a int, b int, c int, primary key (a, b) clustered, key idx_c(c)); +insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100); +explain select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ a from t where a < 2 or a > 88 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ a from t where a < 2 or a > 88 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or a > 88 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ b from t where a < 2 or a > 88 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or a > 88 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ c from t where a < 2 or a > 88 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or a > 88 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or a > 88 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or a > 88 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or a > 88 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a > 88 or c > 10000 order by a, b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a, b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a, b; + + +# TestIndexMergePartialScansTiDBRowID +drop table if exists t; +create table t (a int, b int, c int, unique key (a, b), key idx_c(c)); +insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100); +explain select /*+ use_index_merge(t) */ a from t where c < 10 or a < 2 order by a; +select /*+ use_index_merge(t) */ a from t where c < 10 or a < 2 order by a; +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or c > 10000 order by a; +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or c > 10000 order by a; +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ b from t where c < 10 or a < 2 order by a; +select /*+ use_index_merge(t) */ b from t where c < 10 or a < 2 order by a; +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or c > 10000 order by a; +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or c > 10000 order by a; +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ c from t where c < 10 or a < 2 order by a; +select /*+ use_index_merge(t) */ c from t where c < 10 or a < 2 order by a; +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or c > 10000 order by a; +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or c > 10000 order by a; +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ a,b from t where c < 10 or a < 2 order by a; +select /*+ use_index_merge(t) */ a,b from t where c < 10 or a < 2 order by a; +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or c > 10000 order by a; +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or c > 10000 order by a; +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ a,b from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ b,c from t where c < 10 or a < 2 order by a; +select /*+ use_index_merge(t) */ b,c from t where c < 10 or a < 2 order by a; +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or c > 10000 order by a; +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or c > 10000 order by a; +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ b,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ c,a from t where c < 10 or a < 2 order by a; +select /*+ use_index_merge(t) */ c,a from t where c < 10 or a < 2 order by a; +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or c > 10000 order by a; +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or c > 10000 order by a; +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ c,a from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ b,a,c from t where c < 10 or a < 2 order by a; +select /*+ use_index_merge(t) */ b,a,c from t where c < 10 or a < 2 order by a; +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or c > 10000 order by a; +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or c > 10000 order by a; +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or _tidb_rowid < 10 or c > 11 order by a; +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or c > 100 or c < 1 order by a; +explain select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; +select /*+ use_index_merge(t) */ b,a,c from t where _tidb_rowid < 2 or (a >= 10 and b >= 10) or (a >= 20 and b < 10) or c > 100 or c < 1 order by a; + + +# TestIndexMergePartialScansPKIsHandle +drop table if exists t; +create table t (a int, b int, c int, primary key (a), unique key (b), key idx_c(c)); +insert into t values (1, 1, 1), (10, 10, 10), (100, 100, 100); +explain select /*+ use_index_merge(t) */ a from t where b < 10 or c < 11 or c > 50 order by b; +select /*+ use_index_merge(t) */ a from t where b < 10 or c < 11 or c > 50 order by b; +explain select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by b; +select /*+ use_index_merge(t) */ a from t where a < 2 or c > 10000 order by b; +explain select /*+ use_index_merge(t) */ a from t where a < 2 or a < 10 or b > 11 order by b; +select /*+ use_index_merge(t) */ a from t where a < 2 or a < 10 or b > 11 order by b; +explain select /*+ use_index_merge(t) */ a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +select /*+ use_index_merge(t) */ a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +explain select /*+ use_index_merge(t) */ a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +select /*+ use_index_merge(t) */ a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +explain select /*+ use_index_merge(t) */ b from t where b < 10 or c < 11 or c > 50 order by b; +select /*+ use_index_merge(t) */ b from t where b < 10 or c < 11 or c > 50 order by b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by b; +select /*+ use_index_merge(t) */ b from t where a < 2 or c > 10000 order by b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or a < 10 or b > 11 order by b; +select /*+ use_index_merge(t) */ b from t where a < 2 or a < 10 or b > 11 order by b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +select /*+ use_index_merge(t) */ b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +explain select /*+ use_index_merge(t) */ b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +select /*+ use_index_merge(t) */ b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +explain select /*+ use_index_merge(t) */ c from t where b < 10 or c < 11 or c > 50 order by b; +select /*+ use_index_merge(t) */ c from t where b < 10 or c < 11 or c > 50 order by b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by b; +select /*+ use_index_merge(t) */ c from t where a < 2 or c > 10000 order by b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or a < 10 or b > 11 order by b; +select /*+ use_index_merge(t) */ c from t where a < 2 or a < 10 or b > 11 order by b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +select /*+ use_index_merge(t) */ c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +explain select /*+ use_index_merge(t) */ c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +select /*+ use_index_merge(t) */ c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +explain select /*+ use_index_merge(t) */ a,b from t where b < 10 or c < 11 or c > 50 order by b; +select /*+ use_index_merge(t) */ a,b from t where b < 10 or c < 11 or c > 50 order by b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or c > 10000 order by b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or a < 10 or b > 11 order by b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or a < 10 or b > 11 order by b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +explain select /*+ use_index_merge(t) */ a,b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +select /*+ use_index_merge(t) */ a,b from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +explain select /*+ use_index_merge(t) */ b,c from t where b < 10 or c < 11 or c > 50 order by b; +select /*+ use_index_merge(t) */ b,c from t where b < 10 or c < 11 or c > 50 order by b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or c > 10000 order by b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or a < 10 or b > 11 order by b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or a < 10 or b > 11 order by b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +explain select /*+ use_index_merge(t) */ b,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +select /*+ use_index_merge(t) */ b,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +explain select /*+ use_index_merge(t) */ c,a from t where b < 10 or c < 11 or c > 50 order by b; +select /*+ use_index_merge(t) */ c,a from t where b < 10 or c < 11 or c > 50 order by b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or c > 10000 order by b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or a < 10 or b > 11 order by b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or a < 10 or b > 11 order by b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +explain select /*+ use_index_merge(t) */ c,a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +select /*+ use_index_merge(t) */ c,a from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +explain select /*+ use_index_merge(t) */ b,a,c from t where b < 10 or c < 11 or c > 50 order by b; +select /*+ use_index_merge(t) */ b,a,c from t where b < 10 or c < 11 or c > 50 order by b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or c > 10000 order by b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a < 10 or b > 11 order by b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a < 10 or b > 11 order by b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or b >= 10 or c > 100 or c < 1 order by b; +explain select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; +select /*+ use_index_merge(t) */ b,a,c from t where a < 2 or a >= 10 or a >= 20 or c > 100 or b < 1 order by b; + + +# TestIssue23919 +drop table if exists t; +create table t (a int, b int, index(a), index(b)) partition by hash (a) partitions 2; +insert into t values (1, 5); +select /*+ use_index_merge( t ) */ * from t where a in (3) or b in (5) order by a; +drop table if exists t; +CREATE TABLE t ( + col_5 text NOT NULL, + col_6 tinyint(3) unsigned DEFAULT NULL, + col_7 float DEFAULT '4779.165058537128', + col_8 smallint(6) NOT NULL DEFAULT '-24790', + col_9 date DEFAULT '2031-01-15', + col_37 int(11) DEFAULT '1350204687', + PRIMARY KEY (col_5(6),col_8) /*T![clustered_index] NONCLUSTERED */, + UNIQUE KEY idx_6 (col_9,col_7,col_8), + KEY idx_8 (col_8,col_6,col_5(6),col_9,col_7), + KEY idx_9 (col_9,col_7,col_8) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY RANGE ( col_8 ) ( + PARTITION p0 VALUES LESS THAN (-17650), + PARTITION p1 VALUES LESS THAN (-13033), + PARTITION p2 VALUES LESS THAN (2521), + PARTITION p3 VALUES LESS THAN (7510) +); +insert into t values ('', NULL, 6304.0146, -24790, '2031-01-15', 1350204687); +select var_samp(col_7) aggCol from (select /*+ use_index_merge( t ) */ * from t where t.col_9 in ( '2002-06-22' ) or t.col_5 in ( 'PkfzI' ) or t.col_8 in ( -24874 ) and t.col_6 > null and t.col_5 > 'r' and t.col_9 in ( '1979-09-04' ) and t.col_7 < 8143.667552769195 or t.col_5 in ( 'iZhfEjRWci' , 'T' , '' ) or t.col_9 <> '1976-09-11' and t.col_7 = 8796.436181615773 and t.col_8 = 7372 order by col_5,col_8 ) ordered_tbl group by col_6; + + +# TestIssue16407 +drop table if exists t; +create table t(a int,b char(100),key(a),key(b(10))); +--enable_warnings; +explain format = 'brief' select /*+ use_index_merge(t) */ * from t where a=10 or b='x'; +--disable_warnings; +insert into t values (1, 'xx'); +select /*+ use_index_merge(t) */ * from t where a=10 or b='x'; + + +# TestSelectLimit +set tidb_cost_model_version=2; +drop table if exists t; +create table t(a int); +insert into t values(1),(1),(2); +set @@session.sql_select_limit=1; +--sorted_result +select * from t order by a; +--sorted_result +select * from t order by a limit 2; +set @@session.sql_select_limit=default; +--sorted_result +select * from t order by a; +set @@session.sql_select_limit=1; +--sorted_result +select * from (select * from t) s order by a; +--sorted_result +select * from (select * from t limit 2) s order by a; +--sorted_result +select (select * from t limit 1) s; +--sorted_result +select * from t where t.a in (select * from t) limit 3; +--sorted_result +select * from (select * from t) s limit 3; +--sorted_result +select * from t union all select * from t limit 2; +--sorted_result +select * from t union all (select * from t limit 2); +prepare s1 from 'select * from t where a = ?'; +set @a = 1; +--sorted_result +execute s1 using @a; +set @@session.sql_select_limit=default; +--sorted_result +execute s1 using @a; +set @@session.sql_select_limit=1; +prepare s2 from 'select * from t where a = ? limit 3'; +--sorted_result +execute s2 using @a; +set @@session.sql_select_limit=1; +create definer='root'@'localhost' view s as select * from t; +--sorted_result +select * from s; +set @@session.sql_select_limit=default; +--sorted_result +select * from s; +set @@session.sql_select_limit=1; +create table b (a int); +insert into b select * from t; +--sorted_result +select * from b limit 3; +update b set a = 2 where a = 1; +--sorted_result +select * from b limit 3; +--sorted_result +select * from b; +delete from b where a = 2; +--sorted_result +select * from b; +set @@session.sql_select_limit=DEFAULT; + + +# TestHintParserWarnings +drop table if exists t; +create table t(a int, b int, key(a), key(b)); +--enable_warnings; +select /*+ use_index_merge() */ * from t where a = 1 or b = 1; +--disable_warnings; + + +# TestIssue16935 +drop table if exists t0; +drop view if exists v0; +CREATE TABLE t0(c0 INT); +INSERT INTO t0(c0) VALUES (1), (1), (1), (1), (1), (1); +CREATE definer='root'@'localhost' VIEW v0(c0) AS SELECT NULL FROM t0; +SELECT * FROM t0 LEFT JOIN v0 ON TRUE WHERE v0.c0 IS NULL; + + +# TestClusterIndexUniqueDoubleRead +create database cluster_idx_unique_double_read; +use cluster_idx_unique_double_read; +set @@tidb_enable_clustered_index = 'ON'; +drop table if exists t; +create table t (a varchar(64), b varchar(64), uk int, v int, primary key(a, b), unique key uuk(uk)); +insert t values ('a', 'a1', 1, 11), ('b', 'b1', 2, 22), ('c', 'c1', 3, 33); +select * from t use index (uuk); +drop database cluster_idx_unique_double_read; +set @@tidb_enable_clustered_index = DEFAULT; +use planner__core__integration + + +# TestIssue18984 +drop table if exists t, t2; +set @@tidb_enable_clustered_index = 'ON'; +create table t(a int, b int, c int, primary key(a, b)); +create table t2(a int, b int, c int, d int, primary key(a,b), index idx(c)); +insert into t values(1,1,1), (2,2,2), (3,3,3); +insert into t2 values(1,2,3,4), (2,4,3,5), (1,3,1,1); +select /*+ INL_MERGE_JOIN(t) */ * from t right outer join t2 on t.a=t2.c; +select /*+ INL_MERGE_JOIN(t2) */ * from t left outer join t2 on t.a=t2.c; +set @@tidb_enable_clustered_index = DEFAULT; + + +# TestDistinctScalarFunctionPushDown +drop table if exists t; +create table t (a int not null, b int not null, c int not null, primary key (a,c)) partition by range (c) (partition p0 values less than (5), partition p1 values less than (10)); +insert into t values(1,1,1),(2,2,2),(3,1,3),(7,1,7),(8,2,8),(9,2,9); +select count(distinct b+1) as col from t; + + +# TestPartialBatchPointGet +drop table if exists t; +create table t (c_int int, c_str varchar(40), primary key(c_int, c_str)); +insert into t values (3, 'bose'); +select * from t where c_int in (3); +select * from t where c_int in (3) or c_str in ('yalow') and c_int in (1, 2); + + +# TestIssue19926 +drop table if exists ta; +drop table if exists tb; +drop table if exists tc; +drop view if exists v; +CREATE TABLE `ta` ( + `id` varchar(36) NOT NULL , + `status` varchar(1) NOT NULL +); +CREATE TABLE `tb` ( + `id` varchar(36) NOT NULL , + `status` varchar(1) NOT NULL +); +CREATE TABLE `tc` ( + `id` varchar(36) NOT NULL , + `status` varchar(1) NOT NULL +); +insert into ta values('1','1'); +insert into tb values('1','1'); +insert into tc values('1','1'); +create definer='root'@'localhost' view v as +select +concat(`ta`.`status`,`tb`.`status`) AS `status`, +`ta`.`id` AS `id` from (`ta` join `tb`) +where (`ta`.`id` = `tb`.`id`); +SELECT tc.status,v.id FROM tc, v WHERE tc.id = v.id AND v.status = '11'; + + +# TestDeleteUsingJoin +drop table if exists t1, t2; +create table t1(a int primary key, b int); +create table t2(a int primary key, b int); +insert into t1 values(1,1),(2,2); +insert into t2 values(2,2); +delete t1.* from t1 join t2 using (a); +select * from t1; +select * from t2; + + +# Test19942 +drop table if exists t; +set @@tidb_enable_clustered_index = 'ON'; +CREATE TABLE planner__core__integration.`t` ( `a` int(11) NOT NULL, `b` varchar(10) COLLATE utf8_general_ci NOT NULL, `c` varchar(50) COLLATE utf8_general_ci NOT NULL, `d` char(10) NOT NULL, PRIMARY KEY (`c`), UNIQUE KEY `a_uniq` (`a`), UNIQUE KEY `b_uniq` (`b`), UNIQUE KEY `d_uniq` (`d`), KEY `a_idx` (`a`), KEY `b_idx` (`b`), KEY `d_idx` (`d`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (1, '1', '0', '1'); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (2, ' 2', ' 0', ' 2'); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (3, ' 3 ', ' 3 ', ' 3 '); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (4, 'a', 'a ', 'a'); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (5, ' A ', ' A ', ' A '); +INSERT INTO planner__core__integration.t (a, b, c, d) VALUES (6, ' E', 'é ', ' E'); +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`a_uniq`); +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`b_uniq`); +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`d_uniq`); +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`a_idx`); +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`b_idx`); +SELECT * FROM `planner__core__integration`.`t` FORCE INDEX(`d_idx`); +admin check table t; +set @@tidb_enable_clustered_index = DEFAULT; + + +# TestPartitionUnionWithPPruningColumn +drop table if exists t; +CREATE TABLE `t` ( + `fid` bigint(36) NOT NULL, + `oty` varchar(30) DEFAULT NULL, + `oid` int(11) DEFAULT NULL, + `pid` bigint(20) DEFAULT NULL, + `bid` int(11) DEFAULT NULL, + `r5` varchar(240) DEFAULT '', + PRIMARY KEY (`fid`) +)PARTITION BY HASH( `fid` ) PARTITIONS 4; +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (59, 'm', 441, 1, 2143, 'LE1264_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (135, 'm', 1121, 1, 2423, 'LE2008_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (139, 'm', 1125, 1, 2432, 'LE2005_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (143, 'm', 1129, 1, 2438, 'LE2006_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (147, 'm', 1133, 1, 2446, 'LE2014_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (167, 'm', 1178, 1, 2512, 'LE2055_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (171, 'm', 1321, 1, 2542, 'LE1006_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (179, 'm', 1466, 1, 2648, 'LE2171_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (187, 'm', 1567, 1, 2690, 'LE1293_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (57, 'm', 341, 1, 2102, 'LE1001_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (137, 'm', 1123, 1, 2427, 'LE2003_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (145, 'm', 1131, 1, 2442, 'LE2048_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (138, 'm', 1124, 1, 2429, 'LE2004_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (142, 'm', 1128, 1, 2436, 'LE2049_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (174, 'm', 1381, 1, 2602, 'LE2170_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (28, 'm', 81, 1, 2023, 'LE1009_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (60, 'm', 442, 1, 2145, 'LE1263_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (136, 'm', 1122, 1, 2425, 'LE2002_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (140, 'm', 1126, 1, 2434, 'LE2001_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (168, 'm', 1179, 1, 2514, 'LE2052_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (196, 'm', 3380, 1, 2890, 'LE1300_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (208, 'm', 3861, 1, 3150, 'LE1323_r5'); +INSERT INTO t (fid, oty, oid, pid, bid, r5) VALUES (432, 'm', 4060, 1, 3290, 'LE1327_r5'); +--sorted_result +SELECT DISTINCT t.bid, t.r5 FROM t left join t parent on parent.oid = t.pid WHERE t.oty = 'm'; + + + +# TestIssue14481 +drop table if exists t; +create table t(a int default null, b int default null, c int default null); +explain format = 'brief' select * from t where a = 1 and a = 2; +drop table t; + + +# TestQueryBlockTableAliasInHint +explain select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2; +--enable_warnings +select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2; +--disable_warnings + + +# TestIssue10448 +drop table if exists t; +create table t(pk int(11) primary key); +insert into t values(1),(2),(3); +select a from (select pk as a from t) t1 where a = 18446744073709551615; + + +# TestMultiUpdateOnPrimaryKey +drop table if exists t; +create table t (a int not null primary key); +insert into t values (1); +-- error 1706 +UPDATE t m, t n SET m.a = m.a + 10, n.a = n.a + 10; +drop table if exists t; +create table t (a varchar(10) not null primary key); +insert into t values ('abc'); +-- error 1706 +UPDATE t m, t n SET m.a = 'def', n.a = 'xyz'; +drop table if exists t; +create table t (a int, b int, primary key (a, b)); +insert into t values (1, 2); +-- error 1706 +UPDATE t m, t n SET m.a = m.a + 10, n.b = n.b + 10; +drop table if exists t; +create table t (a int primary key, b int); +insert into t values (1, 2); +-- error 1706 +UPDATE t m, t n SET m.a = m.a + 10, n.a = n.a + 10; +UPDATE t m, t n SET m.b = m.b + 10, n.b = n.b + 10; +SELECT * FROM t; +-- error 1706 +UPDATE t m, t n SET m.a = m.a + 1, n.b = n.b + 10; +-- error 1706 +UPDATE t m, t n, t q SET m.a = m.a + 1, n.b = n.b + 10, q.b = q.b - 10; +-- error 1706 +UPDATE t m, t n, t q SET m.b = m.b + 1, n.a = n.a + 10, q.b = q.b - 10; +-- error 1706 +UPDATE t m, t n, t q SET m.b = m.b + 1, n.b = n.b + 10, q.a = q.a - 10; +-- error 1706 +UPDATE t q, t n, t m SET m.b = m.b + 1, n.b = n.b + 10, q.a = q.a - 10; +update t m, t n set m.a = n.a+10 where m.a=n.a; +select * from t; + + +# TestOrderByHavingNotInSelect +drop table if exists ttest; +create table ttest (v1 int, v2 int); +insert into ttest values(1, 2), (4,6), (1, 7); +-- error 3029 +select v1 from ttest order by count(v2); +-- error 8123 +select v1 from ttest having count(v2); +-- error 1055 +select v2, v1 from (select * from ttest) t1 join (select 1, 2) t2 group by v1; +-- error 1055 +select v2, v1 from (select t1.v1, t2.v2 from ttest t1 join ttest t2) t3 join (select 1, 2) t2 group by v1; + + +# TestUpdateSetDefault +create table tt (x int, z int as (x+10) stored); +insert into tt(x) values (1); +update tt set x=2, z = default; +update tt set x=2, z = default(z); +select * from tt; +-- error 3105 +update tt set x=2, z = default(x); +-- error 3105 +update tt set z = 123; +-- error 3105 +update tt as ss set z = 123; +-- error 3105 +update tt as ss set x = 3, z = 13; +-- error 3105 +update tt as s1, tt as s2 set s1.z = default, s2.z = 456; + + +# TestExtendedStatsSwitch +drop table if exists t; +create table t(a int not null, b int not null, key(a), key(b)); +insert into t values(1,1),(2,2),(3,3),(4,4),(5,5),(6,6); +set session tidb_enable_extended_stats = off; +-- error 1105 +alter table t add stats_extended s1 correlation(a,b); +-- error 1105 +alter table t drop stats_extended s1; +-- error 1105 +admin reload stats_extended; +set session tidb_enable_extended_stats = on; +alter table t add stats_extended s1 correlation(a,b); +select stats, status from mysql.stats_extended where name = 's1'; +set session tidb_enable_extended_stats = off; +analyze table t; +select stats, status from mysql.stats_extended where name = 's1'; +set session tidb_enable_extended_stats = on; +analyze table t; +select stats, status from mysql.stats_extended where name = 's1'; +explain format = 'brief' select * from t use index(b) where a > 3 order by b limit 1; +set session tidb_enable_extended_stats = off; +explain format = 'brief' select * from t use index(b) where a > 3 order by b limit 1; + + +# TestOrderByNotInSelectDistinct +drop table if exists ttest; +create table ttest (v1 int, v2 int); +insert into ttest values(1, 2), (4,6), (1, 7); +-- error 3065 +select distinct v1 from ttest order by v2; +-- error 3065 +select distinct v1+1 from ttest order by v1; +-- error 3065 +select distinct v1+1 from ttest order by 1+v1; +-- error 3065 +select distinct v1+1 from ttest order by v1+2; +-- error 3066 +select distinct count(v1) from ttest group by v2 order by sum(v1); +-- error 3066 +select distinct sum(v1)+1 from ttest group by v2 order by sum(v1); +select distinct v1+1 from ttest order by v1+1; +select distinct count(v1) from ttest order by count(v1); +select distinct count(v1) from ttest group by v2 order by count(v1); +select distinct sum(v1) from ttest group by v2 order by sum(v1); +select distinct v1, v2 from ttest order by 1, 2; +select distinct v1, v2 from ttest order by 2, 1; +select distinct v1 from ttest order by v1+1; +select distinct v1, v2 from ttest order by v1+1, v2; +select distinct v1+1 as z, v2 from ttest order by v1+1, z+v2; +select distinct sum(v1) as z from ttest group by v2 order by z+1; +select distinct sum(v1)+1 from ttest group by v2 order by sum(v1)+1; +select distinct v1 as z from ttest order by v1+z; + + +# TestInvalidNamedWindowSpec +DROP TABLE IF EXISTS temptest; +create table temptest (val int, val1 int); +SELECT val FROM temptest WINDOW w AS (ORDER BY val RANGE 1 PRECEDING); +-- error 3587 +SELECT val FROM temptest WINDOW w AS (ORDER BY val, val1 RANGE 1 PRECEDING); +-- error 1054 +select val1, avg(val1) as a from temptest group by val1 window w as (order by a); +-- error 1054 +select val1, avg(val1) as a from temptest group by val1 window w as (partition by a); + + +# TestCorrelatedAggregate +DROP TABLE IF EXISTS tab, tab2; +CREATE TABLE tab(i INT); +CREATE TABLE tab2(j INT); +insert into tab values(1),(2),(3); +insert into tab2 values(1),(2),(3),(15); +SELECT m.i, + (SELECT COUNT(n.j) + FROM tab2 WHERE j=15) AS o + FROM tab m, tab2 n GROUP BY 1 order by m.i; +SELECT + (SELECT COUNT(n.j) + FROM tab2 WHERE j=15) AS o + FROM tab m, tab2 n order by m.i; +drop table if exists t1, t2; +create table t1 (a int, b int); +create table t2 (m int, n int); +insert into t1 values (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); +insert into t2 values (1,11), (2,22), (3,32), (4,44), (4,44); +set @@sql_mode='TRADITIONAL'; +select count(*) c, a, + ( select group_concat(count(a)) from t2 where m = a ) + from t1 group by a order by a; +drop table if exists t; +create table t (a int, b int); +insert into t values (1,1),(2,1),(2,2),(3,1),(3,2),(3,3); +select (select count(a)) from t; +select (select (select (select count(a)))) from t; +select (select (select count(n.a)) from t m order by count(m.b)) from t n; +select (select count(n.a) from t where count(n.a)=3) from t n; +select (select count(a) from t where count(distinct n.a)=3) from t n; +select (select count(n.a) from t having count(n.a)=6 limit 1) from t n; +select (select count(n.a) from t having count(distinct n.b)=3 limit 1) from t n; +select (select sum(distinct n.a) from t having count(distinct n.b)=3 limit 1) from t n; +select (select sum(distinct n.a) from t having count(distinct n.b)=6 limit 1) from t n; +select (select count(n.a) from t order by count(n.b) limit 1) from t n; +select (select count(distinct n.b) from t order by count(n.b) limit 1) from t n; +select (select cnt from (select count(a) cnt) s) from t; +select (select count(cnt) from (select count(a) cnt) s) from t; +select (select sum((select count(a)))) from t; +select (select sum((select count(a))+sum(a))) from t; +select (select count(a) from t group by count(n.a)) from t n; +select (select count(distinct a) from t group by count(n.a)) from t n; +select sum(a) from t having (select count(a)) = 0; +select sum(a) from t having (select count(a)) > 0; +select count(a) from t group by b order by (select count(a)); +select count(a) from t group by b order by (select -count(a)); +select (select sum(count(a))) from t; +select (select sum(sum(a))) from t; +select count(a), (select count(a)) from t; +select sum(distinct b), count(a), (select count(a)), (select cnt from (select sum(distinct b) as cnt) n) from t; +set @@sql_mode=DEFAULT; + + +# TestCorrelatedColumnAggFuncPushDown +drop table if exists t; +create table t (a int, b int); +insert into t values (1,1); +select (select count(n.a + a) from t) from t n; + + + +# TestNonaggregateColumnWithSingleValueInOnlyFullGroupByMode +drop table if exists t; +create table t (a int, b int, c int); +insert into t values (1, 2, 3), (4, 5, 6), (7, 8, 9); +select a, count(b) from t where a = 1; +select a, count(b) from t where a = 10; +select a, c, sum(b) from t where a = 1 group by c; +-- error 3029 +select a from t where a = 1 order by count(b); +select a from t where a = 1 having count(b) > 0; + + +# TestIssue22040 +drop table if exists t; +create table t (a int, b int, primary key(a,b)); +select * from t where (a,b) in ((1,2),(1,2)); +-- error 1241 +select * from t where (a,b) in (1,2); +-- error 1241 +select * from t where (a,b) in ((1,2),1); + + +# TestIssue22071 +drop table if exists t; +create table t (a int); +insert into t values(1),(2),(5); +select n in (1,2) from (select a in (1,2) as n from t) g; +select n in (1,n) from (select a in (1,2) as n from t) g; + + +# TestIssue22199 +drop table if exists t1, t2; +create table t1(i int primary key, j int, index idx_j(j)); +create table t2(i int primary key, j int, index idx_j(j)); +-- error 1051 +select t1.*, (select t2.* from t1) from t1; + + +# TestIssue22892 +set @@tidb_partition_prune_mode='static'; +drop table if exists t1; +create table t1(a int) partition by hash (a) partitions 5; +insert into t1 values (0); +select * from t1 where a not between 1 and 2; +set @@tidb_partition_prune_mode='dynamic'; +drop table if exists t2; +create table t2(a int) partition by hash (a) partitions 5; +insert into t2 values (0); +select * from t2 where a not between 1 and 2; +set @@tidb_partition_prune_mode=DEFAULT; + + +# TestIssue26719 +create table tx (a int) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20)); +insert into tx values (1); +set @@tidb_partition_prune_mode='dynamic'; +begin; +delete from tx where a in (1); +select * from tx PARTITION(p0); +select * from tx; +rollback; + + +# TestIssue32428 +drop table if exists t1; +create table `t1` (`a` enum('aa') DEFAULT NULL, KEY `k` (`a`)); +insert into t1 values('aa'); +insert into t1 values(null); +select a from t1 where a<=>'aa'; +select a from t1 where a<=>null; +CREATE TABLE IDT_MULTI15860STROBJSTROBJ ( + COL1 enum('aa') DEFAULT NULL, + COL2 int(41) DEFAULT NULL, + COL3 year(4) DEFAULT NULL, + KEY U_M_COL4 (COL1,COL2), + KEY U_M_COL5 (COL3,COL2)); +insert into IDT_MULTI15860STROBJSTROBJ values("aa", 1013610488, 1982); +SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = "aa"; +prepare stmt from "SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = ?"; +set @a="aa"; +execute stmt using @a; + + +# TestDeleteStmt +drop table if exists t; +create table t(a int); +delete t from t; +delete t from planner__core__integration.t as t; +-- error 1109 +delete planner__core__integration.t from planner__core__integration.t as t; +delete planner__core__integration.t from t; +drop database if exists db1; +create database db1; +use db1; +create table t(a int); +-- error 1109 +delete planner__core__integration.t from t; +use planner__core__integration; + + +# TestIndexMergeConstantTrue +drop table if exists t; +create table t(a int primary key, b int not null, key(b)); +delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (b < SOME (SELECT /*+ use_index_merge(t)*/ b FROM t WHERE a<2 OR b<2)); +drop table if exists t; +create table t(a int not null, b int not null, key(a), key(b)); +delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (b < SOME (SELECT /*+ use_index_merge(t)*/ b FROM t WHERE a<2 OR b<2)); +drop table if exists t; +create table t(a int primary key, b int not null, c int, key(a), key(b,c)); +delete /*+ use_index_merge(t) */ FROM t WHERE a=1 OR (a<2 and b<2); + + +# TestIndexMergeTableFilter +drop table if exists t; +create table t(a int, b int, c int, d int, key(a), key(b)); +insert into t values(10,1,1,10); +explain format = 'brief' select /*+ use_index_merge(t) */ * from t where a=10 or (b=10 and c=10); +select /*+ use_index_merge(t) */ * from t where a=10 or (b=10 and c=10); +explain format = 'brief' select /*+ use_index_merge(t) */ * from t where (a=10 and d=10) or (b=10 and c=10); +select /*+ use_index_merge(t) */ * from t where (a=10 and d=10) or (b=10 and c=10); + + +# TestIssue22850 +drop table if exists t1; +CREATE TABLE t1 (a int(11)); +SELECT @v:=(SELECT 1 FROM t1 t2 LEFT JOIN t1 ON t1.a GROUP BY t1.a) FROM t1; + + +# TestJoinSchemaChange +drop table if exists t1, t2; +create table t1(a int(11)); +create table t2(a decimal(40,20) unsigned, b decimal(40,20)); +select count(*) as x from t1 group by a having x not in (select a from t2 where x = t2.b); + + +# TestGetVarExprWithHexLiteral +drop table if exists t1_no_idx; +create table t1_no_idx(id int, col_bit bit(16)); +insert into t1_no_idx values(1, 0x3135); +insert into t1_no_idx values(2, 0x0f); +prepare stmt from 'select id from t1_no_idx where col_bit = ?'; +set @a = 0x3135; +execute stmt using @a; +set @a = 0x0F; +execute stmt using @a; +prepare stmt from 'select id from t1_no_idx where col_bit in (?)'; +set @a = 0x3135; +execute stmt using @a; +set @a = 0x0F; +execute stmt using @a; +drop table if exists t2_idx; +create table t2_idx(id int, col_bit bit(16), key(col_bit)); +insert into t2_idx values(1, 0x3135); +insert into t2_idx values(2, 0x0f); +prepare stmt from 'select id from t2_idx where col_bit = ?'; +set @a = 0x3135; +execute stmt using @a; +set @a = 0x0F; +execute stmt using @a; +prepare stmt from 'select id from t2_idx where col_bit in (?)'; +set @a = 0x3135; +execute stmt using @a; +set @a = 0x0F; +execute stmt using @a; +drop table if exists t_varchar; +create table t_varchar(id int, col_varchar varchar(100), key(col_varchar)); +insert into t_varchar values(1, '15'); +prepare stmt from 'select id from t_varchar where col_varchar = ?'; +set @a = 0x3135; +execute stmt using @a; + + +# TestGetVarExprWithBitLiteral +drop table if exists t1_no_idx; +create table t1_no_idx(id int, col_bit bit(16)); +insert into t1_no_idx values(1, 0x3135); +insert into t1_no_idx values(2, 0x0f); +prepare stmt from 'select id from t1_no_idx where col_bit = ?'; +set @a = 0b11000100110101; +execute stmt using @a; +prepare stmt from 'select id from t1_no_idx where col_bit in (?)'; +set @a = 0b11000100110101; +execute stmt using @a; + + +# TestIndexMergeClusterIndex +drop table if exists t; +create table t (c1 float, c2 int, c3 int, primary key (c1) /*T![clustered_index] CLUSTERED */, key idx_1 (c2), key idx_2 (c3)); +insert into t values(1.0,1,2),(2.0,2,1),(3.0,1,1),(4.0,2,2); +--sorted_result +select /*+ use_index_merge(t) */ c3 from t where c3 = 1 or c2 = 1; +drop table t; +create table t (a int, b int, c int, primary key (a,b) /*T![clustered_index] CLUSTERED */, key idx_c(c)); +insert into t values (0,1,2); +--sorted_result +select /*+ use_index_merge(t) */ c from t where c > 10 or a < 1; + + +# TestIssue23736 +drop table if exists t0, t1; +create table t0(a int, b int, c int as (a + b) virtual, unique index (c) invisible); +create table t1(a int, b int, c int as (a + b) virtual); +insert into t0(a, b) values (12, -1), (8, 7); +insert into t1(a, b) values (12, -1), (8, 7); +select /*+ stream_agg() */ count(1) from t0 where c > 10 and b < 2; +select /*+ stream_agg() */ count(1) from t1 where c > 10 and b < 2; +delete from t0; +insert into t0(a, b) values (5, 1); +select /*+ nth_plan(3) */ count(1) from t0 where c > 10 and b < 2; +explain select /*+ stream_agg() */ count(1) from t0 where c > 10 and b < 2; + + +# TestPanicWhileQueryTableWithIsNull +drop table if exists NT_HP27193; +CREATE TABLE `NT_HP27193` ( `COL1` int(20) DEFAULT NULL, `COL2` varchar(20) DEFAULT NULL, `COL4` datetime DEFAULT NULL, `COL3` bigint(20) DEFAULT NULL, `COL5` float DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH ( `COL1`%`COL3` ) PARTITIONS 10; +select col1 from NT_HP27193 where col1 is null; +INSERT INTO NT_HP27193 (COL2, COL4, COL3, COL5) VALUES ('m', '2020-05-04 13:15:27', 8, 2602); +select col1 from NT_HP27193 where col1 is null; +drop table if exists NT_HP27193; + + +# TestIssue23846 +drop table if exists t; +create table t(a varbinary(10),UNIQUE KEY(a)); +insert into t values(0x00A4EEF4FA55D6706ED5); +select count(*) from t where a=0x00A4EEF4FA55D6706ED5; +select * from t where a=0x00A4EEF4FA55D6706ED5; + + +# TestIssue23839 +drop table if exists BB; +CREATE TABLE `BB` ( + `col_int` int(11) DEFAULT NULL, + `col_varchar_10` varchar(10) DEFAULT NULL, + `pk` int(11) NOT NULL AUTO_INCREMENT, + `col_int_not_null` int(11) NOT NULL, + `col_decimal` decimal(10,0) DEFAULT NULL, + `col_datetime` datetime DEFAULT NULL, + `col_decimal_not_null` decimal(10,0) NOT NULL, + `col_datetime_not_null` datetime NOT NULL, + `col_varchar_10_not_null` varchar(10) NOT NULL, + PRIMARY KEY (`pk`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000001; +--error 1055 +explain SELECT OUTR . col2 AS X FROM (SELECT INNR . col1 as col1, SUM( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR2 INNER JOIN (SELECT INNR . col1 as col1, MAX( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR ON OUTR2.col1 = OUTR.col1 GROUP BY OUTR . col1, OUTR2 . col1 HAVING X <> 'b'; + + +# TestIssue24281 +drop table if exists member, agent, deposit, view_member_agents; +create table member(login varchar(50) NOT NULL, agent_login varchar(100) DEFAULT NULL, PRIMARY KEY(login)); +create table agent(login varchar(50) NOT NULL, data varchar(100) DEFAULT NULL, share_login varchar(50) NOT NULL, PRIMARY KEY(login)); +create table deposit(id varchar(50) NOT NULL, member_login varchar(50) NOT NULL, transfer_amount int NOT NULL, PRIMARY KEY(id), KEY midx(member_login, transfer_amount)); +create definer='root'@'localhost' view view_member_agents (member, share_login) as select m.login as member, a.share_login AS share_login from member as m join agent as a on m.agent_login = a.login; + select s.member_login as v1, SUM(s.transfer_amount) AS v2 FROM deposit AS s JOIN view_member_agents AS v ON s.member_login = v.member WHERE 1 = 1 AND v.share_login = 'somevalue' GROUP BY s.member_login UNION select 1 as v1, 2 as v2; + + +# TestIssue25799 +drop table if exists t1, t2; +create table t1 (a float default null, b smallint(6) DEFAULT NULL); +insert into t1 values (1, 1); +create table t2 (a float default null, b tinyint(4) DEFAULT NULL, key b (b)); +insert into t2 values (null, 1); +explain select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b); +select /*+ TIDB_INLJ(t2@sel_2) */ t1.a, t1.b from t1 where t1.a not in (select t2.a from t2 where t1.b=t2.b); + + +# TestLimitWindowColPrune +drop table if exists t; +create table t(a int); +insert into t values(1); +select count(a) f1, row_number() over (order by count(a)) as f2 from t limit 1; + + +# TestIssue27167 +set names utf8mb4; +drop table if exists all_types; +CREATE TABLE `all_types` (`id` int(11) NOT NULL,`d_tinyint` tinyint(4) DEFAULT NULL,`d_smallint` smallint(6) DEFAULT NULL,`d_int` int(11) DEFAULT NULL,`d_bigint` bigint(20) DEFAULT NULL,`d_float` float DEFAULT NULL,`d_double` double DEFAULT NULL,`d_decimal` decimal(10,2) DEFAULT NULL,`d_bit` bit(10) DEFAULT NULL,`d_binary` binary(10) DEFAULT NULL,`d_date` date DEFAULT NULL,`d_datetime` datetime DEFAULT NULL,`d_timestamp` timestamp NULL DEFAULT NULL,`d_varchar` varchar(20) NULL default NULL,PRIMARY KEY (`id`)); +select @@collation_connection; +insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123'); +select collation(c) from (select d_date c from all_types union select d_int c from all_types) t; +select collation(c) from (select d_date c from all_types union select d_int collate binary c from all_types) t; +select collation(c) from (select d_date c from all_types union select d_float c from all_types) t; +select collation(c) from (select d_timestamp c from all_types union select d_float c from all_types) t; + + +# TestIssue25300 +drop table if exists t; +create table t (a char(65) collate utf8_unicode_ci, b text collate utf8_general_ci not null); +insert into t values ('a', 'A'); +insert into t values ('b', 'B'); +-- error 1271 +(select a from t) union ( select b from t); +-- error 1271 +(select 'a' collate utf8mb4_unicode_ci) union (select 'b' collate utf8mb4_general_ci); +-- error 1271 +(select a from t) union ( select b from t) union all select 'a'; +-- error 1271 +(select a from t) union ( select b from t) union select 'a'; +-- error 1271 +(select a from t) union ( select b from t) union select 'a' except select 'd'; + + +# TestIssue26250 +create table tp (id int primary key) partition by range (id) (partition p0 values less than (100)); +create table tn (id int primary key); +insert into tp values(1),(2); +insert into tn values(1),(2); +select * from tp,tn where tp.id=tn.id and tn.id=1 for update; + + +# TestCorrelationAdjustment4Limit +drop table if exists t; +create table t (pk int primary key auto_increment, year int, c varchar(256), index idx_year(year)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +analyze table t; +set @@tidb_opt_enable_correlation_adjustment = false; +explain format=brief select * from t use index(primary) where year=2002 limit 1; +set @@tidb_opt_enable_correlation_adjustment = true; +explain format=brief select * from t use index(primary) where year=2002 limit 1; +truncate table t; +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2000, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2001, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2002, space(256)); +insert into t (year, c) values (2003, space(256)); +insert into t (year, c) values (2003, space(256)); +insert into t (year, c) values (2004, space(256)); +insert into t (year, c) values (2004, space(256)); +insert into t (year, c) values (2005, space(256)); +insert into t (year, c) values (2005, space(256)); +insert into t (year, c) values (2006, space(256)); +insert into t (year, c) values (2006, space(256)); +insert into t (year, c) values (2007, space(256)); +insert into t (year, c) values (2007, space(256)); +insert into t (year, c) values (2008, space(256)); +insert into t (year, c) values (2008, space(256)); +insert into t (year, c) values (2009, space(256)); +insert into t (year, c) values (2009, space(256)); +insert into t (year, c) values (2010, space(256)); +insert into t (year, c) values (2010, space(256)); +insert into t (year, c) values (2011, space(256)); +insert into t (year, c) values (2011, space(256)); +insert into t (year, c) values (2012, space(256)); +insert into t (year, c) values (2012, space(256)); +insert into t (year, c) values (2013, space(256)); +insert into t (year, c) values (2013, space(256)); +insert into t (year, c) values (2014, space(256)); +insert into t (year, c) values (2014, space(256)); +insert into t (year, c) values (2015, space(256)); +insert into t (year, c) values (2015, space(256)); +insert into t (year, c) values (2016, space(256)); +insert into t (year, c) values (2016, space(256)); +insert into t (year, c) values (2017, space(256)); +insert into t (year, c) values (2017, space(256)); +insert into t (year, c) values (2018, space(256)); +insert into t (year, c) values (2018, space(256)); +insert into t (year, c) values (2019, space(256)); +insert into t (year, c) values (2019, space(256)); +insert into t (year, c) values (2020, space(256)); +insert into t (year, c) values (2020, space(256)); +insert into t (year, c) values (2021, space(256)); +insert into t (year, c) values (2021, space(256)); +insert into t (year, c) values (2022, space(256)); +insert into t (year, c) values (2022, space(256)); +insert into t (year, c) values (2023, space(256)); +insert into t (year, c) values (2023, space(256)); +insert into t (year, c) values (2024, space(256)); +insert into t (year, c) values (2024, space(256)); +insert into t (year, c) values (2025, space(256)); +insert into t (year, c) values (2025, space(256)); +insert into t (year, c) values (2026, space(256)); +insert into t (year, c) values (2026, space(256)); +insert into t (year, c) values (2027, space(256)); +insert into t (year, c) values (2027, space(256)); +insert into t (year, c) values (2028, space(256)); +insert into t (year, c) values (2028, space(256)); +insert into t (year, c) values (2029, space(256)); +insert into t (year, c) values (2029, space(256)); +insert into t (year, c) values (2030, space(256)); +insert into t (year, c) values (2030, space(256)); +insert into t (year, c) values (2031, space(256)); +insert into t (year, c) values (2031, space(256)); +insert into t (year, c) values (2032, space(256)); +insert into t (year, c) values (2032, space(256)); +insert into t (year, c) values (2033, space(256)); +insert into t (year, c) values (2033, space(256)); +insert into t (year, c) values (2034, space(256)); +insert into t (year, c) values (2034, space(256)); +insert into t (year, c) values (2035, space(256)); +insert into t (year, c) values (2035, space(256)); +insert into t (year, c) values (2036, space(256)); +insert into t (year, c) values (2036, space(256)); +insert into t (year, c) values (2037, space(256)); +insert into t (year, c) values (2037, space(256)); +insert into t (year, c) values (2038, space(256)); +insert into t (year, c) values (2038, space(256)); +insert into t (year, c) values (2039, space(256)); +insert into t (year, c) values (2039, space(256)); +insert into t (year, c) values (2040, space(256)); +insert into t (year, c) values (2040, space(256)); +insert into t (year, c) values (2041, space(256)); +insert into t (year, c) values (2041, space(256)); +insert into t (year, c) values (2042, space(256)); +insert into t (year, c) values (2042, space(256)); +insert into t (year, c) values (2043, space(256)); +insert into t (year, c) values (2043, space(256)); +insert into t (year, c) values (2044, space(256)); +insert into t (year, c) values (2044, space(256)); +insert into t (year, c) values (2045, space(256)); +insert into t (year, c) values (2045, space(256)); +insert into t (year, c) values (2046, space(256)); +insert into t (year, c) values (2046, space(256)); +insert into t (year, c) values (2047, space(256)); +insert into t (year, c) values (2047, space(256)); +insert into t (year, c) values (2048, space(256)); +insert into t (year, c) values (2048, space(256)); +insert into t (year, c) values (2049, space(256)); +insert into t (year, c) values (2049, space(256)); +insert into t (year, c) values (2050, space(256)); +insert into t (year, c) values (2050, space(256)); +analyze table t; +explain format=brief select * from t use index(primary) where year=2000 limit 1; + + +# TestCTESelfJoin +drop table if exists t1, t2, t3; +create table t1(t1a int, t1b int, t1c int); +create table t2(t2a int, t2b int, t2c int); +create table t3(t3a int, t3b int, t3c int); + + with inv as + (select t1a , t3a, sum(t2c) + from t1, t2, t3 + where t2a = t1a + and t2b = t3b + and t3c = 1998 + group by t1a, t3a) + select inv1.t1a, inv2.t3a + from inv inv1, inv inv2 + where inv1.t1a = inv2.t1a + and inv1.t3a = 4 + and inv2.t3a = 4+1; + + +# TestIssue26214 +drop table if exists t; +create table `t` (`a` int(11) default null, `b` int(11) default null, `c` int(11) default null, key `expression_index` ((case when `a` < 0 then 1 else 2 end))); +-- error 1054 +select * from t where case when a < 0 then 1 else 2 end <= 1 order by 4; + + +# TestCreateViewWithWindowFunc +drop table if exists t6; +CREATE TABLE t6(t TIME, ts TIMESTAMP); +INSERT INTO t6 VALUES ('12:30', '2016-07-05 08:30:42'); +drop view if exists v; +CREATE definer='root'@'localhost' VIEW v AS SELECT COUNT(*) OVER w0, COUNT(*) OVER w from t6 WINDOW w0 AS (), w AS (w0 ORDER BY t); +select * from v; + + +# TestIssue29834 +drop table if exists IDT_MC21814; +CREATE TABLE `IDT_MC21814` (`COL1` year(4) DEFAULT NULL,`COL2` year(4) DEFAULT NULL,KEY `U_M_COL` (`COL1`,`COL2`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into IDT_MC21814 values(1901, 2119), (2155, 2000); +SELECT/*+ INL_JOIN(t1, t2), nth_plan(1) */ t2.* FROM IDT_MC21814 t1 LEFT JOIN IDT_MC21814 t2 ON t1.col1 = t2.col1 WHERE t2.col2 BETWEEN 2593 AND 1971 AND t1.col1 IN (2155, 1901, 1967); +--enable_warnings +SELECT/*+ INL_JOIN(t1, t2), nth_plan(2) */ t2.* FROM IDT_MC21814 t1 LEFT JOIN IDT_MC21814 t2 ON t1.col1 = t2.col1 WHERE t2.col2 BETWEEN 2593 AND 1971 AND t1.col1 IN (2155, 1901, 1967); +--disable_warnings + + +# TestLimitPushDown +drop table if exists t; +create table t (a int); +insert into t values (1); +analyze table t; +set tidb_opt_limit_push_down_threshold=0; +explain format=brief select a from t order by a desc limit 10; +set tidb_opt_limit_push_down_threshold=10; +explain format=brief select a from t order by a desc limit 10; +explain format=brief select a from t order by a desc limit 11; +explain format=brief select /*+ limit_to_cop() */ a from t order by a desc limit 11; + + +# TestIssue26559 +drop table if exists t; +create table t(a timestamp, b datetime); +insert into t values('2020-07-29 09:07:01', '2020-07-27 16:57:36'); +--sorted_result +select greatest(a, b) from t union select null; + + + +# TestIssues27130 +drop table if exists t1; +set tidb_cost_model_version=2; +create table t1( a enum('y','b','Abc','null'),b enum('y','b','Abc','null'),key(a)); +explain format=brief select * from t1 where a like "A%"; +explain format=brief select * from t1 where b like "A%"; +drop table if exists t2; +create table t2( a enum('y','b','Abc','null'),b enum('y','b','Abc','null'),key(a, b)); +explain format=brief select * from t2 where a like "A%"; +explain format=brief select * from t2 where a like "A%" and b like "A%"; +drop table if exists t3; +create table t3( a int,b enum('y','b','Abc','null'), c enum('y','b','Abc','null'),key(a, b, c)); +explain format=brief select * from t3 where a = 1 and b like "A%"; + + +# TestIssue27242 +drop table if exists UK_MU16407; +CREATE TABLE UK_MU16407 (COL3 timestamp NULL DEFAULT NULL, UNIQUE KEY U3(COL3)); +insert into UK_MU16407 values("1985-08-31 18:03:27"); +SELECT COL3 FROM UK_MU16407 WHERE COL3>_utf8mb4'2039-1-19 3:14:40'; +DROP TABLE UK_MU16407; + + +# TestIssue28424 +drop table if exists t28424, dt28242; +set time_zone='+00:00'; +drop table if exists t28424,dt28424; +create table t28424 (t timestamp); +insert into t28424 values ("2038-01-19 03:14:07"), ("1970-01-01 00:00:01"); +-- sorted_result +select * from t28424 where t != "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t < "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t <= "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t >= "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t > "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t != "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t < "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t <= "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t >= "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t > "1970-1-1 0:0:0"; +alter table t28424 add unique index (t); +-- sorted_result +select * from t28424 where t != "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t < "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t <= "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t >= "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t > "2038-1-19 3:14:08"; +-- sorted_result +select * from t28424 where t != "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t < "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t <= "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t >= "1970-1-1 0:0:0"; +-- sorted_result +select * from t28424 where t > "1970-1-1 0:0:0"; +create table dt28424 (dt datetime); +insert into dt28424 values ("2038-01-19 03:14:07"), ("1970-01-01 00:00:01"); +insert into dt28424 values ("1969-12-31 23:59:59"), ("1970-01-01 00:00:00"), ("2038-03-19 03:14:08"); +-- sorted_result +select * from t28424 right join dt28424 on t28424.t = dt28424.dt; +DROP TABLE dt28424; +DROP TABLE t28424; + + +# TestTemporaryTableForCte +create temporary table tmp1(a int, b int, c int); +insert into tmp1 values (1,1,1),(2,2,2),(3,3,3),(4,4,4); +with cte1 as (with cte2 as (select * from tmp1) select * from cte2) select * from cte1 left join tmp1 on cte1.c=tmp1.c; +with cte1 as (with cte2 as (select * from tmp1) select * from cte2) select * from cte1 t1 left join cte1 t2 on t1.c=t2.c; +WITH RECURSIVE cte(a) AS (SELECT 1 UNION SELECT a+1 FROM tmp1 WHERE a < 5) SELECT * FROM cte order by a; + + +# TestIssue27797 +SELECT @@session.tidb_partition_prune_mode; +set @@session.tidb_partition_prune_mode = 'static'; +drop table if exists t27797; +create table t27797(a int, b int, c int, d int) partition by range columns(d) (partition p0 values less than (20),partition p1 values less than(40),partition p2 values less than(60)); +insert into t27797 values(1,1,1,1), (2,2,2,2), (22,22,22,22), (44,44,44,44); +set sql_mode=''; +select count(*) from (select a, b from t27797 where d > 1 and d < 60 and b > 0 group by b, c) tt; +drop table if exists IDT_HP24172; +CREATE TABLE `IDT_HP24172` ( `COL1` mediumint(16) DEFAULT NULL, `COL2` varchar(20) DEFAULT NULL, `COL4` datetime DEFAULT NULL, `COL3` bigint(20) DEFAULT NULL, `COL5` float DEFAULT NULL, KEY `UM_COL` (`COL1`,`COL3`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH( `COL1`+`COL3` ) PARTITIONS 8; +insert into IDT_HP24172(col1) values(8388607); +select col2 from IDT_HP24172 where col1 = 8388607 and col1 in (select col1 from IDT_HP24172); +set @@session.tidb_partition_prune_mode = DEFAULT; +set sql_mode=DEFAULT; + + +# TestIssue28154 +drop table if exists t; +create table t(a TEXT); +insert into t values('abc'); +select * from t where from_base64(''); +-- error 1292 +update t set a = 'def' where from_base64(''); +select * from t where from_base64('invalidbase64'); +update t set a = 'hig' where from_base64('invalidbase64'); +select * from t where from_base64('test'); +-- error 1292 +update t set a = 'xyz' where from_base64('test'); +select * from t; +drop table if exists t; + + +# TestIssues29711 +drop table if exists tbl_29711; +CREATE TABLE `tbl_29711` (`col_250` text COLLATE utf8_unicode_ci NOT NULL,`col_251` enum('Alice','Bob','Charlie','David') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Charlie',PRIMARY KEY (`col_251`,`col_250`(1)) NONCLUSTERED); +explain format=brief select col_250,col_251 from tbl_29711 where col_251 between 'Bob' and 'David' order by col_250,col_251 limit 6; +drop table if exists t29711; +CREATE TABLE `t29711` (`a` varchar(10) DEFAULT NULL,`b` int(11) DEFAULT NULL,`c` int(11) DEFAULT NULL,KEY `ia` (`a`(2))); +explain format=brief select * from t29711 use index (ia) order by a limit 10; + + +# TestIssue27313 +drop table if exists t; +create table t(a varchar(100), b int, c int, index idx1(a(2), b), index idx2(a)); +--enable_warnings +explain format = 'verbose' select * from t where a = 'abcdefghijk' and b > 4; +--disable_warnings + + +# TestIssue30094 +drop table if exists t30094; +create table t30094(a varchar(10)); +explain format = 'brief' select * from t30094 where cast(a as float) and cast(a as char); +explain format = 'brief' select * from t30094 where concat(a,'1') = _binary 0xe59388e59388e59388 collate binary and concat(a,'1') = _binary 0xe598bfe598bfe598bf collate binary; + + +# TestIssue29705 +SELECT @@session.tidb_partition_prune_mode; +set @@session.tidb_partition_prune_mode = 'static'; +drop table if exists t; +create table t(id int) partition by hash(id) partitions 4; +insert into t values(1); +SELECT COUNT(1) FROM ( SELECT COUNT(1) FROM t b GROUP BY id) a; +set @@session.tidb_partition_prune_mode = DEFAULT; + + +# TestIssue30271 +drop table if exists t; +create table t(a char(10), b char(10), c char(10), index (a, b, c)) collate utf8mb4_bin; +insert into t values ('b', 'a', '1'), ('b', 'A', '2'), ('c', 'a', '3'); +set names utf8mb4 collate utf8mb4_general_ci; +select * from t where (a>'a' and b='a') or (b = 'A' and a < 'd') order by a,c; + + +# TestIssue30804 +drop table if exists t1, t2; +create table t1(a int, b int); +create table t2(a int, b int); +select avg(0) over w from t1 window w as (order by (select 1)); +-- error 3579 +select avg(0) over w from t1 where b > (select sum(t2.a) over w from t2) window w as (partition by t1.b); +select avg(0) over w1 from t1 where b > (select sum(t2.a) over w2 from t2 window w2 as (partition by t2.b)) window w1 as (partition by t1.b); + + +# TestIndexMergeWarning +drop table if exists t1; +create table t1(c1 int, c2 int); +--enable_warnings +select /*+ use_index_merge(t1) */ * from t1 where c1 < 1 or c2 < 1; +drop table if exists t1; +create table t1(c1 int, c2 int, key(c1), key(c2)); +select /*+ use_index_merge(t1), no_index_merge() */ * from t1 where c1 < 1 or c2 < 1; +drop table if exists t1; +create temporary table t1(c1 int, c2 int, key(c1), key(c2)); +select /*+ use_index_merge(t1) */ * from t1 where c1 < 1 or c2 < 1; +--disable_warnings + + +# TestIssue20510 +drop table if exists t1, t2; +CREATE TABLE t1 (a int PRIMARY KEY, b int); +CREATE TABLE t2 (a int PRIMARY KEY, b int); +INSERT INTO t1 VALUES (1,1), (2,1), (3,1), (4,2); +INSERT INTO t2 VALUES (1,2), (2,2); +explain format=brief SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE not(0+(t1.a=30 and t2.b=1)); +SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE not(0+(t1.a=30 and t2.b=1)); + + +# TestIssue31035 +drop table if exists t1; +create table t1(c1 longtext, c2 decimal(37, 4), unique key(c1(10)), unique key(c2)); +insert into t1 values('眐', -962541614831459.7458); +select * from t1 order by c2 + 10; + + +# TestDNFCondSelectivityWithConst +drop table if exists t1; +create table t1(a int, b int, c int); +insert into t1 value(10,10,10); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 value(1,1,1); +analyze table t1; +explain format = 'brief' select * from t1 where a=1 or b=1; +explain format = 'brief' select * from t1 where 0=1 or a=1 or b=1; +explain format = 'brief' select * from t1 where null or a=1 or b=1; +explain format = 'brief' select * from t1 where a=1 or false or b=1; +explain format = 'brief' select * from t1 where a=1 or b=1 or "false"; +explain format = 'brief' select * from t1 where 1=1 or a=1 or b=1; +explain format = 'brief' select * from t1 where a=1 or b=1 or 1=1; +drop table if exists t1; + + +# TestNaturalJoinUpdateSameTable +create database natural_join_update; +use natural_join_update; +create table t1(a int, b int); +insert into t1 values (1,1),(2,2); +update t1 as a natural join t1 b SET a.a = 2, b.b = 3; +--sorted_result +select * from t1; +drop table t1; +create table t1 (a int primary key, b int); +insert into t1 values (1,1),(2,2); +--error 1706 +update t1 as a natural join t1 b SET a.a = 2, b.b = 3; +drop table t1; +create table t1 (a int, b int) partition by hash (a) partitions 3; +insert into t1 values (1,1),(2,2); +--error 1706 +update t1 as a natural join t1 b SET a.a = 2, b.b = 3; +drop table t1; +create table t1 (A int, b int) partition by hash (b) partitions 3; +insert into t1 values (1,1),(2,2); +--error 1706 +update t1 as a natural join t1 B SET a.A = 2, b.b = 3; +--error 1706 +update t1 as a natural join t1 B SET a.A = 2, b.b = 3; +drop table t1; +create table t1 (A int, b int) partition by RANGE COLUMNS (b) (partition `pNeg` values less than (0),partition `pPos` values less than MAXVALUE); +insert into t1 values (1,1),(2,2); +--error 1706 +update t1 as a natural join t1 B SET a.A = 2, b.b = 3; +drop table t1; +drop database natural_join_update; +use planner__core__integration; + + +# TestIssue33042 +drop table if exists t1, t2; +create table t1(id int primary key, col1 int); +create table t2(id int primary key, col1 int); +explain format='brief' SELECT /*+ merge_join(t1, t2)*/ * FROM (t1 LEFT JOIN t2 ON t1.col1=t2.id) order by t2.id; + + +# TestIssue29663 +drop table if exists t1; +drop table if exists t2; +create table t1 (a int, b int); +create table t2 (c int, d int); +insert into t1 values(1, 1), (1,2),(2,1),(2,2); +insert into t2 values(1, 3), (1,4),(2,5),(2,6); +explain select one.a from t1 one order by (select two.d from t2 two where two.c = one.b); + + +# TestIssue31609 +explain select rank() over (partition by table_name) from information_schema.tables; + + +# TestDecimalOverflow +drop table if exists t; +create table deci (a decimal(65,30),b decimal(65,0)); +insert into deci values (1234567890.123456789012345678901234567890,987654321098765432109876543210987654321098765432109876543210); +select a from deci union ALL select b from deci; + + +# TestIssue25813 +drop table if exists t; +create table t(a json); +insert into t values('{"id": "ish"}'); +select t2.a from t t1 left join t t2 on t1.a=t2.a where t2.a->'$.id'='ish'; +explain format = 'brief' select * from t t1 left join t t2 on t1.a=t2.a where t2.a->'$.id'='ish'; + + +# TestPartitionTableFallBackStatic +drop table if exists t, t2; +set @@tidb_partition_prune_mode='static'; +CREATE TABLE t (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6),PARTITION p1 VALUES LESS THAN (11)); +insert into t values (1),(2),(3),(4),(7),(8),(9),(10); +analyze table t; +explain format='brief' select * from t; +CREATE TABLE t2 (a int) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6),PARTITION p1 VALUES LESS THAN (11)); +insert into t2 values (1),(2),(3),(4),(7),(8),(9),(10); +analyze table t2; +set @@tidb_partition_prune_mode='dynamic'; +explain format='brief' select * from t; +analyze table t; +explain format='brief' select * from t; +explain format='brief' select * from t union all select * from t2; +set @@tidb_partition_prune_mode=DEFAULT; + + +# TestTableRangeFallback +drop table if exists t1, t2; +create table t1 (a int primary key, b int); +create table t2 (c int); +explain format='brief' select * from t1 where a in (10, 20, 30, 40, 50) and b > 1; +explain format='brief' select * from t1 join t2 on t1.b = t2.c where t1.a in (10, 20, 30, 40, 50); +set @@tidb_opt_range_max_size=10; +--enable_warnings +explain format='brief' select * from t1 where a in (10, 20, 30, 40, 50) and b > 1; +explain format='brief' select * from t1 join t2 on t1.b = t2.c where t1.a in (10, 20, 30, 40, 50); +--disable_warnings + + +# TestIndexRangeFallback +drop table if exists t1, t2, t3, t4; +create table t1 (a varchar(10), b varchar(10), c varchar(10), index idx_a_b(a(2), b(2))); +create table t2 (d varchar(10)); +create table t3 (pk int primary key, a int, key(a)); +create table t4 (a int, b int, c int, index idx_a_b(a, b)); +set @@tidb_opt_range_max_size=0; +--enable_warnings +explain format='brief' select * from t1 where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +set @@tidb_opt_range_max_size=1000; +explain format='brief' select * from t1 where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +set @@tidb_opt_range_max_size=0; +explain format='brief' select * from t1 join t2 on t1.c = t2.d where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +set @@tidb_opt_range_max_size=1000; +explain format='brief' select * from t1 join t2 on t1.c = t2.d where a in ('aaa', 'bbb', 'ccc') and b in ('ddd', 'eee', 'fff'); +set @@tidb_opt_range_max_size=0; +explain format='brief' select /*+ use_index(t3, a) */ * from t3 where a in (1, 3, 5) and pk in (2, 4, 6); +set @@tidb_opt_range_max_size=1000; +explain format='brief' select /*+ use_index(t3, a) */ * from t3 where a in (1, 3, 5) and pk in (2, 4, 6); +set @@tidb_opt_range_max_size=0; +explain format='brief' select /*+ use_index(t4, idx_a_b) */ * from t4 where a in (1, 3, 5) and b = 2; +set @@tidb_opt_range_max_size=1000; +explain format='brief' select /*+ use_index(t4, idx_a_b) */ * from t4 where a in (1, 3, 5) and b = 2; +--disable_warnings +set @@tidb_opt_range_max_size=DEFAULT; + + +# TestPlanCacheForTableRangeFallback +set @@tidb_enable_prepared_plan_cache=1; +drop table if exists t; +create table t (a int primary key, b int); +set @@tidb_opt_range_max_size=10; +prepare stmt from 'select * from t where a in (?, ?, ?, ?, ?) and b > 1'; +set @a=10, @b=20, @c=30, @d=40, @e=50; +execute stmt using @a, @b, @c, @d, @e; +--enable_warnings +execute stmt using @a, @b, @c, @d, @e; +--disable_warnings +select @@last_plan_from_cache; + + +# TestIssue37760 +drop table if exists t; +create table t(a int primary key); +insert into t values (2), (4), (6); +set @@tidb_opt_range_max_size=1; +--enable_warnings +select * from t where a; +--disable_warnings +set @@tidb_opt_range_max_size=DEFAULT; + + +# TestIssue38295 +drop table if exists t0; +drop view if exists v0; +CREATE TABLE t0(c0 BLOB(298) , c1 BLOB(182) , c2 NUMERIC); +CREATE VIEW v0(c0) AS SELECT t0.c1 FROM t0; +INSERT INTO t0 VALUES (-1, 'a', '2046549365'); +CREATE INDEX i0 ON t0(c2); +-- error 1055 +SELECT t0.c1, t0.c2 FROM t0 GROUP BY MOD(t0.c0, DEFAULT(t0.c2)); +UPDATE t0 SET c2=1413; + + +# TestOuterJoinEliminationForIssue18216 +drop table if exists t1, t2; +create table t1 (a int, c int); +insert into t1 values (1, 1), (1, 2), (2, 3), (2, 4); +create table t2 (a int, c int); +insert into t2 values (1, 1), (1, 2), (2, 3), (2, 4); +select group_concat(c order by (select group_concat(c order by a) from t2 where a=t1.a)) from t1; ; +select group_concat(c order by (select group_concat(c order by c) from t2 where a=t1.a), c desc) from t1; + + +# TestIssue36888 +drop table if exists t0, t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +INSERT INTO t0 VALUES (NULL); +SELECT t0.c0 FROM t0 LEFT JOIN t1 ON t0.c0>=t1.c0 WHERE (CONCAT_WS(t0.c0, t1.c0) IS NULL); + + +# TestIssue40285 +drop table if exists t; +CREATE TABLE t(col1 enum('p5', '9a33x') NOT NULL DEFAULT 'p5',col2 tinyblob DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = latin1 COLLATE = latin1_bin; +(select last_value(col1) over () as r0 from t) union all (select col2 as r0 from t); + + +# TestIssue41458 +drop table if exists t; +create table t (a int, b int, c int, index ia(a)); +select * from t t1 join t t2 on t1.b = t2.b join t t3 on t2.b=t3.b join t t4 on t3.b=t4.b where t3.a=1 and t2.a=2; +select plan from information_schema.statements_summary where SCHEMA_NAME = 'test' and STMT_TYPE = 'Select'; + + +# TestIssue43116 +CREATE TABLE `sbtest1` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `k` int(11) NOT NULL DEFAULT '0', `c` char(120) NOT NULL DEFAULT '', `pad` char(60) NOT NULL DEFAULT '', PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ , KEY `k_1` (`k`) ); +set @@tidb_opt_range_max_size = 111; +-- enable_warnings +explain format='brief' select * from planner__core__integration.sbtest1 a where pad in ('1','1','1','1','1') and id in (1,1,1,1,1); +-- disable_warnings +set @@tidb_opt_range_max_size = DEFAULT; + + +# TestIssue45033 +drop table if exists t1, t2, t3, t4; +create table t1 (c1 int, c2 int, c3 int, primary key(c1, c2)); +create table t2 (c2 int, c1 int, primary key(c2, c1)); +create table t3 (c4 int, key(c4)); +create table t4 (c2 varchar(20) , test_col varchar(50), gen_col varchar(50) generated always as(concat(test_col,'')) virtual not null, unique key(gen_col)); +select count(1) + from (select ( case + when count(1) + over( + partition by a.c2) >= 50 then 1 + else 0 + end ) alias1, + b.c2 as alias_col1 + from t1 a + left join (select c2 + from t4 f) k + on k.c2 = a.c2 + inner join t2 b + on b.c1 = a.c3) alias2 + where exists (select 1 + from (select distinct alias3.c4 as c2 + from t3 alias3) alias4 + where alias4.c2 = alias2.alias_col1); + + +# TestIssue46298 +drop table if exists planner__core__integration.first_range; +create table planner__core__integration.first_range(p int not null, o tinyint not null, v int not null); +insert into planner__core__integration.first_range (p, o, v) values (0, 0, 0), (1, 1, 1), (1, 2, 2), (1, 4, 4), (1, 8, 8), (2, 0, 0), (2, 3, 3), (2, 10, 10), (2, 13, 13), (2, 15, 15), (3, 1, 1), (3, 3, 3), (3, 5, 5), (3, 9, 9), (3, 15, 15), (3, 20, 20), (3, 31, 31); +--sorted_result +select *, first_value(v) over (partition by p order by o range between 3.1 preceding and 2.9 following) as a from planner__core__integration.first_range; +set @@tidb_enable_pipelined_window_function=0; +--sorted_result +select *, first_value(v) over (partition by p order by o range between 3.1 preceding and 2.9 following) as a from planner__core__integration.first_range; +set @@tidb_enable_pipelined_window_function=DEFAULT; + + diff --git a/tests/integrationtest/t/planner/core/integration_partition.test b/tests/integrationtest/t/planner/core/integration_partition.test new file mode 100644 index 0000000000..b59b2d07a2 --- /dev/null +++ b/tests/integrationtest/t/planner/core/integration_partition.test @@ -0,0 +1,848 @@ +# TestListPartitionDML +create database list_partition_dml; +use list_partition_dml; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist partition(p0) values (0), (1); +insert into tlist partition(p0, p1) values (2), (3), (8), (9); +-- error 1748 +insert into tlist partition(p0) values (9); +-- error 1735 +insert into tlist partition(p3) values (20); +update tlist partition(p0) set a=a+1; +select a from tlist order by a; +update tlist partition(p0, p1) set a=a-1; +select a from tlist order by a; +delete from tlist partition(p1); +select a from tlist order by a; +delete from tlist partition(p0, p2); +select a from tlist order by a; +create table tcollist (a int) partition by list columns(a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist partition(p0) values (0), (1); +insert into tcollist partition(p0, p1) values (2), (3), (8), (9); +-- error 1748 +insert into tcollist partition(p0) values (9); +-- error 1735 +insert into tcollist partition(p3) values (20); +update tcollist partition(p0) set a=a+1; +select a from tcollist order by a; +update tcollist partition(p0, p1) set a=a-1; +select a from tcollist order by a; +delete from tcollist partition(p1); +select a from tcollist order by a; +delete from tcollist partition(p0, p2); +select a from tcollist order by a; + + +# TestListPartitionCreation +create database list_partition_cre; +use list_partition_cre; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tuk1 (a int, b int, unique key(a)) partition by list (a) (partition p0 values in (0)); +-- error 1503 +create table tuk2 (a int, b int, unique key(a)) partition by list (b) (partition p0 values in (0)); +-- error 1503 +create table tuk2 (a int, b int, unique key(a), unique key(b)) partition by list (a) (partition p0 values in (0)); +create table tcoluk1 (a int, b int, unique key(a)) partition by list columns(a) (partition p0 values in (0)); +-- error 1503 +create table tcoluk2 (a int, b int, unique key(a)) partition by list columns(b) (partition p0 values in (0)); +-- error 1503 +create table tcoluk2 (a int, b int, unique key(a), unique key(b)) partition by list columns(a) (partition p0 values in (0)); +create table tpk1 (a int, b int, primary key(a)) partition by list (a) (partition p0 values in (0)); +create table tpk2 (a int, b int, primary key(a, b)) partition by list (a) (partition p0 values in (0)); +create table tcolpk1 (a int, b int, primary key(a)) partition by list columns(a) (partition p0 values in (0)); +create table tcolpk2 (a int, b int, primary key(a, b)) partition by list columns(a) (partition p0 values in (0)); +create table tidx1 (a int, b int, key(a), key(b)) partition by list (a) (partition p0 values in (0)); +create table tidx2 (a int, b int, key(a, b), key(b)) partition by list (a) (partition p0 values in (0)); +create table tcolidx1 (a int, b int, key(a), key(b)) partition by list columns(a) (partition p0 values in (0)); +create table tcolidx2 (a int, b int, key(a, b), key(b)) partition by list columns(a) (partition p0 values in (0)); +create table texp1 (a int, b int) partition by list(a-10000) (partition p0 values in (0)); +create table texp2 (a int, b int) partition by list(a%b) (partition p0 values in (0)); +create table texp3 (a int, b int) partition by list(a*b) (partition p0 values in (0)); +-- error 1564 +create table texp4 (a int, b int) partition by list(a|b) (partition p0 values in (0)); +-- error 1564 +create table texp4 (a int, b int) partition by list(a^b) (partition p0 values in (0)); +-- error 1564 +create table texp4 (a int, b int) partition by list(a&b) (partition p0 values in (0)); + + +# TestListPartitionDDL +create database list_partition_ddl; +use list_partition_ddl; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, b int) partition by list (a) (partition p0 values in (0)); +-- error 1503 +alter table tlist add primary key (b); +alter table tlist add primary key (a); +-- error 1503 +alter table tlist add unique key (b); +alter table tlist add key (b); +alter table tlist rename index b to bb; +alter table tlist drop index bb; +create table tcollist (a int, b int) partition by list columns (a) (partition p0 values in (0)); +-- error 1503 +alter table tcollist add primary key (b); +alter table tcollist add primary key (a); +-- error 1503 +alter table tcollist add unique key (b); +alter table tcollist add key (b); +alter table tcollist rename index b to bb; +alter table tcollist drop index bb; +alter table tlist add column c varchar(8); +alter table tlist rename column c to cc; +alter table tlist drop column cc; +alter table tcollist add column c varchar(8); +alter table tcollist rename column c to cc; +alter table tcollist drop column cc; +alter table tlist rename to tlistxx; +truncate tlistxx; +drop table tlistxx; +alter table tcollist rename to tcollistxx; +truncate tcollistxx; +drop table tcollistxx; + + +# TestListPartitionOperations +create database list_partition_op; +use list_partition_op; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14), + partition p3 values in (15, 16, 17, 18, 19)); +create table tcollist (a int) partition by list columns(a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14), + partition p3 values in (15, 16, 17, 18, 19)); +insert into tlist values (0), (5), (10), (15); +--sorted_result +select * from tlist; +alter table tlist truncate partition p0; +--sorted_result +select * from tlist; +alter table tlist truncate partition p1, p2; +--sorted_result +select * from tlist; +insert into tcollist values (0), (5), (10), (15); +--sorted_result +select * from tcollist; +alter table tcollist truncate partition p0; +--sorted_result +select * from tcollist; +alter table tcollist truncate partition p1, p2; +--sorted_result +select * from tcollist; +insert into tlist values (0), (5), (10); +--sorted_result +select * from tlist; +alter table tlist drop partition p0; +--sorted_result +select * from tlist; +--sorted_result +--error 1735 +select * from tlist partition (p0); +alter table tlist drop partition p1, p2; +--sorted_result +select * from tlist; +--sorted_result +--error 1735 +select * from tlist partition (p1); +--error 1508 +alter table tlist drop partition p3; +insert into tcollist values (0), (5), (10); +--sorted_result +select * from tcollist; +alter table tcollist drop partition p0; +--sorted_result +select * from tcollist; +--sorted_result +--error 1735 +select * from tcollist partition (p0); +alter table tcollist drop partition p1, p2; +--sorted_result +select * from tcollist; +--sorted_result +--error 1735 +select * from tcollist partition (p1); +--error 1508 +alter table tcollist drop partition p3; +alter table tlist add partition (partition p0 values in (0, 1, 2, 3, 4)); +alter table tlist add partition (partition p1 values in (5, 6, 7, 8, 9), partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (5), (10); +--sorted_result +select * from tlist; +--error 1495 +alter table tlist add partition (partition pxxx values in (4)); +alter table tcollist add partition (partition p0 values in (0, 1, 2, 3, 4)); +alter table tcollist add partition (partition p1 values in (5, 6, 7, 8, 9), partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (5), (10); +--sorted_result +select * from tcollist; +--error 1495 +alter table tcollist add partition (partition pxxx values in (4)); + + +# TestListPartitionShardBits +create database list_partition_shard_bits; +use list_partition_shard_bits; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (1), (5), (6), (10), (12); +--sorted_result +select * from tlist; +--sorted_result +select * from tlist partition (p0); +--sorted_result +select * from tlist partition (p1, p2); +create table tcollist (a int) partition by list columns (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (1), (5), (6), (10), (12); +--sorted_result +select * from tcollist; +--sorted_result +select * from tcollist partition (p0); +--sorted_result +select * from tcollist partition (p1, p2); + + +# TestListPartitionSplitRegion +create database list_partition_split_region; +use list_partition_split_region; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, key(a)) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (1), (5), (6), (10), (12); +split table tlist index a between (2) and (15) regions 10; +--sorted_result +select * from tlist; +--sorted_result +select * from tlist partition (p0); +--sorted_result +select * from tlist partition (p1, p2); +create table tcollist (a int, key(a)) partition by list columns (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (1), (5), (6), (10), (12); +split table tcollist index a between (2) and (15) regions 10; +--sorted_result +select * from tcollist; +--sorted_result +select * from tcollist partition (p0); +--sorted_result +select * from tcollist partition (p1, p2); + +# TestListPartitionAutoIncre +create database list_partition_auto_incre; +use list_partition_auto_incre; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist1 (a int, b int AUTO_INCREMENT) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +create table tlist (a int, b int AUTO_INCREMENT, key(b)) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist (a) values (0); +insert into tlist (a) values (5); +insert into tlist (a) values (10); +insert into tlist (a) values (1); +create table tcollist1 (a int, b int AUTO_INCREMENT) partition by list columns (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +create table tcollist (a int, b int AUTO_INCREMENT, key(b)) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist (a) values (0); +insert into tcollist (a) values (5); +insert into tcollist (a) values (10); +insert into tcollist (a) values (1); + + +# TestListPartitionAutoRandom +create database list_partition_auto_rand; +use list_partition_auto_rand; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +--error 8216 +create table tlist (a int, b bigint AUTO_RANDOM) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +create table tlist (a bigint auto_random, primary key(a)) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +--error 8216 +create table tcollist (a int, b bigint AUTO_RANDOM) partition by list columns (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +create table tcollist (a bigint auto_random, primary key(a)) partition by list columns (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); + + +# TestListPartitionInvisibleIdx +create database list_partition_invisible_idx; +use list_partition_invisible_idx; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, b int, key(a)) partition by list (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5)); +alter table tlist alter index a invisible; +explain select a from tlist where a>=0 and a<=5; +create table tcollist (a int, b int, key(a)) partition by list columns (a) (partition p0 values in (0, 1, 2), partition p1 values in (3, 4, 5)); +alter table tcollist alter index a invisible; +explain select a from tcollist where a>=0 and a<=5; + + +# TestListPartitionCTE +create database list_partition_cte; +use list_partition_cte; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tlist values (0), (1), (5), (6), (10); +--sorted_result +with tmp as (select a+1 as a from tlist) select * from tmp; +create table tcollist (a int) partition by list columns (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +insert into tcollist values (0), (1), (5), (6), (10); +--sorted_result +with tmp as (select a+1 as a from tcollist) select * from tmp; + + +# TestListPartitionTempTable +create database list_partition_temp_table; +use list_partition_temp_table; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +--error 1526 +create global temporary table t(a int, b int) partition by list(a) (partition p0 values in (0)) on commit delete rows; +--error 1526 +create global temporary table t(a int, b int) partition by list columns (a) (partition p0 values in (0)) on commit delete rows; + + +# TestListPartitionAlterPK +create database list_partition_alter_pk; +use list_partition_alter_pk; +drop table if exists tlist; +set tidb_enable_list_partition = 1; +create table tlist (a int, b int) partition by list (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +alter table tlist add primary key(a); +alter table tlist drop primary key; +-- error 1503 +alter table tlist add primary key(b); +create table tcollist (a int, b int) partition by list columns (a) ( + partition p0 values in (0, 1, 2, 3, 4), + partition p1 values in (5, 6, 7, 8, 9), + partition p2 values in (10, 11, 12, 13, 14)); +alter table tcollist add primary key(a); +alter table tcollist drop primary key; +-- error 1503 +alter table tcollist add primary key(b); + + +# TestIssue27018 +create database issue_27018; +use issue_27018; +set tidb_enable_list_partition = 1; +CREATE TABLE PK_LP9326 ( + COL1 tinyint(45) NOT NULL DEFAULT '30' COMMENT 'NUMERIC PK', + PRIMARY KEY (COL1) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( + PARTITION P0 VALUES IN (56,127,-128,-125,-40,-18,-10,-5,49,51), + PARTITION P1 VALUES IN (-107,-97,-57,-37,4,43,99,-9,-6,45), + PARTITION P2 VALUES IN (108,114,-85,-72,-38,-11,29,97,40,107), + PARTITION P3 VALUES IN (-112,-95,-42,24,28,47,-103,-94,7,64), + PARTITION P4 VALUES IN (-115,-101,-76,-47,1,19,-114,-23,-19,11), + PARTITION P5 VALUES IN (44,95,-92,-89,-26,-21,25,-117,-116,27), + PARTITION P6 VALUES IN (50,61,118,-110,-32,-1,111,125,-90,74), + PARTITION P7 VALUES IN (75,121,-96,-87,-14,-13,37,-68,-58,81), + PARTITION P8 VALUES IN (126,30,48,68) +); +insert into PK_LP9326 values(30),(48),(56); +SELECT COL1 FROM PK_LP9326 WHERE COL1 NOT IN (621579514938,-17333745845828,2777039147338); + + +# TestIssue27017 +create database issue_27017; +use issue_27017; +set tidb_enable_list_partition = 1; +CREATE TABLE PK_LP9465 ( + COL1 mediumint(45) NOT NULL DEFAULT '77' COMMENT 'NUMERIC PK', + PRIMARY KEY (COL1) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( + PARTITION P0 VALUES IN (-5237720,2949267,6047247,-8317208,-6854239,-6612749,-6578207,-5649321,2450483,2953765), + PARTITION P1 VALUES IN (5884439,-7816703,-6716210,-6050369,-5691207,6836620,5769359,-8237127,-1294367,-1228621), + PARTITION P2 VALUES IN (-976130,-8351227,-8294140,-4800605,1370685,-7351802,-6447779,77,1367409,5965199), + PARTITION P3 VALUES IN (7347944,7397124,8013414,-5737292,-3938813,-3687304,1307396,444598,1216072,1603451), + PARTITION P4 VALUES IN (2518402,-8388608,-5291256,-3796824,121011,8388607,39191,2323510,3386861,4886727), + PARTITION P5 VALUES IN (-6512367,-5922779,-3272589,-1313463,5751641,-3974640,2605656,3336269,4416436,-7975238), + PARTITION P6 VALUES IN (-6693544,-6023586,-4201506,6416586,-3254125,-205332,1072201,2679754,1963191,2077718), + PARTITION P7 VALUES IN (4205081,5170051,-8087893,-5805143,-1202286,1657202,8330979,5042855,7578575,-5830439), + PARTITION P8 VALUES IN (-5244013,3837781,4246485,670906,5644986,5843443,7794811,7831812,-7704740,-2222984), + PARTITION P9 VALUES IN (764108,3406142,8263677,248997,6129417,7556305,7939455,3526998,8239485,-5195482), + PARTITION P10 VALUES IN (-3625794,69270,377245) +); +insert into PK_LP9465 values(8263677); +SELECT COL1 FROM PK_LP9465 HAVING COL1>=-12354348921530; + + +# TestIssue27544 +create database issue_27544; +use issue_27544; +set tidb_enable_list_partition = 1; +create table t3 (a datetime) partition by list (mod( year(a) - abs(weekday(a) + dayofweek(a)), 4) + 1) ( + partition p0 values in (2), + partition p1 values in (3), + partition p3 values in (4)); +insert into t3 values ('1921-05-10 15:20:10'); +insert into t3 values ('1921-05-10 15:20:20'); +insert into t3 values ('1921-05-10 15:20:30'); + + +# TestIssue27012 +create database issue_27012; +use issue_27012; +set tidb_enable_list_partition = 1; +CREATE TABLE IDT_LP24306 ( + COL1 tinyint(16) DEFAULT '41' COMMENT 'NUMERIC UNIQUE INDEX', + KEY UK_COL1 (COL1) /*!80000 INVISIBLE */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( + PARTITION P0 VALUES IN (-126,-36,-96,-6,-83,-123,-5,-52,-98,-124), + PARTITION P1 VALUES IN (-2,-22,-88,-100,-60,-39,-69,-38,-11,-30), + PARTITION P2 VALUES IN (-119,-13,-67,-91,-65,-16,0,-128,-73,-118), + PARTITION P3 VALUES IN (-99,-56,-76,-110,-93,-114,-78,NULL) +); +insert into IDT_LP24306 values(-128); +--sorted_result +select * from IDT_LP24306 where col1 not between 12021 and 99 and col1 <= -128; +drop table if exists IDT_LP24306; +CREATE TABLE IDT_LP24306 ( + COL1 tinyint(16) DEFAULT '41' COMMENT 'NUMERIC UNIQUE INDEX', + KEY UK_COL1 (COL1) /*!80000 INVISIBLE */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into IDT_LP24306 values(-128); +--sorted_result +select * from IDT_LP24306 where col1 not between 12021 and 99 and col1 <= -128; + + +# TestIssue27030 +create database issue_27030; +use issue_27030; +set tidb_enable_list_partition = 1; +CREATE TABLE PK_LCP9290 ( + COL1 varbinary(10) NOT NULL, + PRIMARY KEY (COL1) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( + PARTITION P5 VALUES IN (x'32d8fb9da8b63508a6b8'), + PARTITION P6 VALUES IN (x'ffacadeb424179bc4b5c'), + PARTITION P8 VALUES IN (x'ae9f733168669fa900be') +); +insert into PK_LCP9290 values(0xffacadeb424179bc4b5c),(0xae9f733168669fa900be),(0x32d8fb9da8b63508a6b8); +--sorted_result +SELECT COL1 FROM PK_LCP9290 WHERE COL1!=x'9f7ebdc957a36f2531b5' AND COL1 IN (x'ffacadeb424179bc4b5c',x'ae9f733168669fa900be',x'32d8fb9da8b63508a6b8'); +--sorted_result +SELECT COL1 FROM PK_LCP9290 WHERE COL1 IN (x'ffacadeb424179bc4b5c',x'ae9f733168669fa900be',x'32d8fb9da8b63508a6b8'); + + +# TestIssue27070 +create database issue_27070; +use issue_27070; +set @@tidb_enable_list_partition = OFF; +--enable_warnings +create table if not exists t (id int, create_date date NOT NULL DEFAULT '2000-01-01', PRIMARY KEY (id,create_date) ) PARTITION BY list COLUMNS(create_date) ( PARTITION p20210506 VALUES IN ("20210507"), PARTITION p20210507 VALUES IN ("20210508") ); +--disable_warnings + + +# TestIssue27031 +create database issue_27031; +use issue_27031; +set tidb_enable_list_partition = 1; +CREATE TABLE NT_LP27390 ( + COL1 mediumint(28) DEFAULT '114' COMMENT 'NUMERIC NO INDEX' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST COLUMNS(col1) ( + PARTITION P9 VALUES IN (3376825,-7753310,-4123498,6483048,6953968,-996842,-7542484,320451,-8322717,-2426029) +); +insert into NT_LP27390 values(-4123498); +--sorted_result +SELECT COL1 FROM NT_LP27390 WHERE COL1 IN (46015556,-4123498,54419751); + + +# TestIssue27493 +create database issue_27493; +use issue_27493; +set tidb_enable_list_partition = 1; +CREATE TABLE UK_LP17321 ( + COL1 mediumint(16) DEFAULT '82' COMMENT 'NUMERIC UNIQUE INDEX', + COL3 bigint(20) DEFAULT NULL, + UNIQUE KEY UM_COL (COL1,COL3) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY LIST (COL1 DIV COL3) ( + PARTITION P0 VALUES IN (NULL,0) +); +--sorted_result +select * from UK_LP17321 where col1 is null; + + +# TestIssue27532 +create database issue_27532; +use issue_27532; +set tidb_enable_list_partition = 1; +create table t2 (c1 int primary key, c2 int, c3 int, c4 int, key k2 (c2), key k3 (c3)) partition by hash(c1) partitions 10; +insert into t2 values (1,1,1,1),(2,2,2,2),(3,3,3,3),(4,4,4,4); +set @@tidb_partition_prune_mode="dynamic"; +set autocommit = 0; +--sorted_result +select * from t2; +--sorted_result +select * from t2; +drop table t2; +drop database issue_27532; + + +# TestIssue37508 +use test; +set @@tidb_partition_prune_mode = 'dynamic'; +select @@tidb_partition_prune_mode; +create table t1 (id int, c date) partition by range (to_days(c)) +(partition p0 values less than (to_days('2022-01-11')), +partition p1 values less than (to_days('2022-02-11')), +partition p2 values less than (to_days('2022-03-11'))); +analyze table t1; +explain select * from t1 where c in ('2022-01-23', '2022-01-22'); +--sorted_result +select * from t1 where c in ('2022-01-23', '2022-01-22'); +explain select * from t1 where c in (NULL, '2022-01-23'); +--sorted_result +select * from t1 where c in (NULL, '2022-01-23'); +drop table t1; + + +# TestRangeColumnsMultiColumn +create database RangeColumnsMulti; +use RangeColumnsMulti; +-- error 1064 +create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)(partition p0 values less than (NULL,NULL,NULL)); +-- error 1654 +create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)(partition p1 values less than (-2147483649,'0000-00-00',"")); +create table t (a int, b datetime, c varchar(255)) partition by range columns (a,b,c)(partition p1 values less than (-2147483648,'0000-00-00',""),partition p2 values less than (10,'2022-01-01',"Wow"),partition p3 values less than (11,'2022-01-01',MAXVALUE),partition p4 values less than (MAXVALUE,'2022-01-01',"Wow")); +-- error 1292 +insert into t values (-2147483648,'0000-00-00',null); +insert into t values (NULL,NULL,NULL); +set @@sql_mode = ''; +insert into t values (-2147483648,'0000-00-00',null); +insert into t values (-2147483648,'0000-00-00',""); +-- enable_warnings +insert into t values (5,'0000-00-00',null); +insert into t values (5,'0000-00-00',"Hi"); +-- disable_warnings +set @@sql_mode = DEFAULT; +insert into t values (10,'2022-01-01',"Hi"); +insert into t values (10,'2022-01-01',"Wow"); +insert into t values (10,'2022-01-01',"Wowe"); +insert into t values (11,'2022-01-01',"Wow"); +insert into t values (1,null,"Wow"); +insert into t values (NULL,'2022-01-01',"Wow"); +insert into t values (11,null,"Wow"); +analyze table t; +--sorted_result +select a,b,c from t partition(p1); +--sorted_result +select a,b,c from t partition(p2); +--sorted_result +select a,b,c from t partition(p3); +--sorted_result +select * from t where a = 10 and b = "2022-01-01" and c = "Wow"; +--sorted_result +select * from t where a = 10 and b = "2022-01-01" and c <= "Wow"; +--sorted_result +select * from t where a = 10 and b = "2022-01-01" and c < "Wow"; +--sorted_result +select * from t where a = 10 and b = "2022-01-01" and c > "Wow"; +--sorted_result +select * from t where a = 10 and b = "2022-01-01" and c >= "Wow"; +--sorted_result +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c = "Wow"; +--sorted_result +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c <= "Wow"; +--sorted_result +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c < "Wow"; +--sorted_result +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c > "Wow"; +--sorted_result +explain format = 'brief' select * from t where a = 10 and b = "2022-01-01" and c >= "Wow"; +--sorted_result +select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"; +--sorted_result +select * from t where a = 10 and b = "2022-01-01" and c = "Wow"; +--sorted_result +select * from t where a <= 10 and b <= '2022-01-01' and c <= "Wow"; +--sorted_result +explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"; +--sorted_result +select * from t where a <= 11 and b <= '2022-01-01' and c < "Wow"; +explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c < "Wow"; +create table tref (a int, b datetime, c varchar(255), key (a,b,c)); +set @@sql_mode = ''; +insert into tref select * from t; +set @@sql_mode = DEFAULT; +explain format = 'brief' select * from tref where a <= 10 and b <= '2022-01-01' and c < "Wow"; +explain format = 'brief' select * from t where a <= 10 and b <= '2022-01-01' and c <= "Wow"; +--sorted_result +select * from t where a = 2 and b = "2022-01-02" and c = "Hi" or b = '2022-01-01' and c = "Wow"; +--sorted_result +select * from t where a = 2 and b = "2022-01-02" and c = "Hi" or a = 10 and b = '2022-01-01' and c = "Wow"; +--sorted_result +select * from t where a = 2 and b = "2022-01-02" and c = "Hi"; +--sorted_result +select * from t where a = 2 and b = "2022-01-02" and c < "Hi"; +--sorted_result +select * from t where a < 2; +--sorted_result +select * from t where a <= 2 and b <= "2022-01-02" and c < "Hi"; +explain format = 'brief' select * from t where a < 2; +--sorted_result +select * from t where a < 2 and a > -22; +explain format = 'brief' select * from t where a < 2 and a > -22; +--sorted_result +select * from t where c = ""; +explain format = 'brief' select * from t where c = ""; + + +# TestRangeMultiColumnsPruning +create database RColumnsMulti; +use RColumnsMulti; +create table t (a int, b datetime, c varchar(255), key (a,b,c)) partition by range columns (a,b,c) (partition p0 values less than (-2147483648, '0000-01-01', ""), partition p1 values less than (-2147483648, '0001-01-01', ""), partition p2 values less than (-2, '0001-01-01', ""), partition p3 values less than (0, '0001-01-01', ""), partition p4 values less than (0, '2031-01-01', ""), partition p5 values less than (0, '2031-01-01', "Wow"), partition p6 values less than (0, '2031-01-01', MAXVALUE), partition p7 values less than (0, MAXVALUE, MAXVALUE), partition p8 values less than (MAXVALUE, MAXVALUE, MAXVALUE)); +--error 1292 +insert into t values (-2147483648,'0000-00-00',null); +insert into t values (NULL,NULL,NULL); +set @@sql_mode = ''; +insert into t values (-2147483648,'0000-00-00',null); +insert into t values (-2147483648,'0000-00-00',""); +--enable_warnings +insert into t values (5,'0000-00-00',null); +insert into t values (5,'0000-00-00',"Hi"); +--disable_warnings +set @@sql_mode = DEFAULT; +insert into t values (10,'2022-01-01',"Hi"); +insert into t values (10,'2022-01-01',"Wow"); +insert into t values (11,'2022-01-01',"Wow"); +insert into t values (0,'2020-01-01',"Wow"); +insert into t values (1,null,"Wow"); +insert into t values (NULL,'2022-01-01',"Wow"); +insert into t values (11,null,"Wow"); +analyze table t; +--sorted_result +select a,b from t where b = '2022-01-01'; +--sorted_result +select a,b,c from t where a = 1; +--sorted_result +select a,b,c from t where a = 1 AND c = "Wow"; +explain format = 'brief' select a,b,c from t where a = 1 AND c = "Wow"; +--sorted_result +select a,b,c from t where a = 0 AND c = "Wow"; +explain format = 'brief' select a,b,c from t where a = 0 AND c = "Wow"; + + +# TestRangeColumnsExpr +create database rce; +use rce; +create table tref (a int unsigned, b int, c int); +create table t (a int unsigned, b int, c int) partition by range columns (a,b) (partition p0 values less than (3, MAXVALUE), partition p1 values less than (4, -2147483648), partition p2 values less than (4, 1), partition p3 values less than (4, 4), partition p4 values less than (4, 7), partition p5 values less than (4, 11), partition p6 values less than (4, 14), partition p7 values less than (4, 17), partition p8 values less than (4, MAXVALUE), partition p9 values less than (7, 0), partition p10 values less than (11, MAXVALUE), partition p11 values less than (14, -2147483648), partition p12 values less than (17, 17), partition p13 values less than (MAXVALUE, -2147483648)); +insert into t values (0,0,0),(11,2147483647,2147483647),(14,10,4),(14,NULL,2),(14,NULL,NULL),(17,16,16),(17,17,17),(3,2147483647,9),(4,-2147483648,-2147483648),(4,1,1),(4,10,3),(4,13,1),(4,14,2),(4,2147483647,2147483647),(4,4,4),(4,5,6),(4,NULL,4),(5,0,0),(7,0,0),(NULL,-2147483648,NULL),(NULL,NULL,NULL); +insert into tref select * from t; +analyze table t; +--sorted_result +select * from tref; +--sorted_result +select * from t; +--sorted_result +select * from t partition (p0); +--sorted_result +select * from t partition (p1); +--sorted_result +select * from t partition (p2); +--sorted_result +select * from t partition (p3); +--sorted_result +select * from t partition (p4); +--sorted_result +select * from t partition (p5); +--sorted_result +select * from t partition (p6); +--sorted_result +select * from t partition (p7); +--sorted_result +select * from t partition (p8); +--sorted_result +select * from t partition (p9); +--sorted_result +select * from t partition (p10); +--sorted_result +select * from t partition (p11); +--sorted_result +select * from t partition (p12); +--sorted_result +select * from t partition (p13); +explain format = 'brief' select * from t where c = 3; +explain format = 'brief' select * from t where b > 3 and c = 3; +explain format = 'brief' select * from t where a = 5 and c = 3; +explain format = 'brief' select * from t where a = 4 and c = 3; +explain format = 'brief' select * from t where a in (4,14) and c = 3; +explain format = 'brief' select * from t where a in (4,14) and b in (null,10); +--sorted_result +select * from tref where a in (4,14) and b in (null,10); +--sorted_result +select * from t where a in (4,14) and b in (null,10); +explain format = 'brief' select * from t where a in (4,14) and (b in (11,10) OR b is null); +--sorted_result +select * from tref where a in (4,14) and (b in (11,10) OR b is null); +--sorted_result +select * from t where a in (4,14) and (b in (11,10) OR b is null); + + +# TestPartitionRangePrunerCharWithCollation +create database cwc; +use cwc; +create table t (a char(32) collate utf8mb4_unicode_ci) partition by range columns (a) (partition p0 values less than ('c'), partition p1 values less than ('F'), partition p2 values less than ('h'), partition p3 values less than ('L'), partition p4 values less than ('t'), partition p5 values less than (MAXVALUE)); +insert into t values ('a'),('A'),('c'),('C'),('f'),('F'),('h'),('H'),('l'),('L'),('t'),('T'),('z'),('Z'); +analyze table t; +--sorted_result +select * from t partition(p0); +--sorted_result +select * from t partition(p1); +--sorted_result +select * from t partition(p2); +--sorted_result +select * from t partition(p3); +--sorted_result +select * from t partition(p4); +--sorted_result +select * from t partition(p5); +--sorted_result +select * from t where a > 'C' and a < 'q'; +--sorted_result +select * from t where a > 'c' and a < 'Q'; +explain format = 'brief' select * from t where a > 'C' and a < 'q'; +explain format = 'brief' select * from t where a > 'c' and a < 'Q'; + +# TestPartitionRangePrunerDate +drop database if exists rcd; +create database rcd; +use rcd; +set @@tidb_partition_prune_mode = 'dynamic'; +create table i (a int, b int, key (a,b)); +select * from i where a < 1 and a > 2; +explain format = 'brief' select * from i where a < 1 and a > 2; +create table t (a date) partition by range columns (a) (partition p0 values less than ('19990601'), partition p1 values less than ('2000-05-01'), partition p2 values less than ('20080401'), partition p3 values less than ('2010-03-01'), partition p4 values less than ('20160201'), partition p5 values less than ('2020-01-01'), partition p6 values less than (MAXVALUE)); +show create table t; +insert into t values ('19990101'),('1999-06-01'),('2000-05-01'),('20080401'),('2010-03-01'),('2016-02-01'),('2020-01-01'); +analyze table t; +--sorted_result +select * from t partition(p0); +--sorted_result +select * from t partition(p1); +--sorted_result +select * from t partition(p2); +--sorted_result +select * from t partition(p3); +--sorted_result +select * from t partition(p4); +--sorted_result +select * from t partition(p5); +--sorted_result +select * from t partition(p6); +explain select * from t where a < '1943-02-12'; +explain select * from t where a >= '19690213'; +explain select * from t where a > '2003-03-13'; +explain select * from t where a < '2006-02-03'; +explain select * from t where a = '20070707'; +explain select * from t where a > '1949-10-10'; +explain select * from t where a > '2016-02-01' AND a < '20000103'; +explain select * from t where a < '19691112' or a >= '2019-09-18'; +explain select * from t where a is null; +explain select * from t where '2003-02-27' >= a; +explain select * from t where '20141024' < a; +explain select * from t where '2003-03-30' > a; +explain select * from t where a between '2003-03-30' AND '2014-01-01'; + + +# TestPartitionRangeColumnPruning +drop database if exists rcd; +create database rcd; +use rcd; +create table t1 (a char, b char, c char) partition by range columns (a,b,c) ( partition p0 values less than ('a','b','c'), partition p1 values less than ('b','c','d'), partition p2 values less than ('d','e','f')); +insert into t1 values ('a', NULL, 'd'); +analyze table t1; +explain format=brief select * from t1 where a = 'a' AND c = 'd'; +--sorted_result +select * from t1 where a = 'a' AND c = 'd'; +drop table t1; + +# TestPartitionProcessorWithUninitializedTable +drop table if exists q1, q2; +create table q1(a int, b int, key (a)) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20)); +create table q2(a int, b int, key (a)) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20)); +explain format=brief select * from q1,q2; +analyze table q1; +explain format=brief select * from q1,q2; +analyze table q2; +explain format=brief select * from q1,q2; + +# TestIssue42323 +create database issue42323; +use issue42323; +set @@session.tidb_partition_prune_mode = 'dynamic'; +CREATE TABLE t(col1 int(11) NOT NULL DEFAULT '0' ) PARTITION BY RANGE (FLOOR(col1))( + PARTITION p2021 VALUES LESS THAN (202200), + PARTITION p2022 VALUES LESS THAN (202300), + PARTITION p2023 VALUES LESS THAN (202400)); +insert into t values(202303); +analyze table t; +select * from t where col1 = 202303; +select * from t where col1 = floor(202303); +drop database issue42323; + + diff --git a/tests/integrationtest/t/planner/core/partition_pruner.test b/tests/integrationtest/t/planner/core/partition_pruner.test new file mode 100644 index 0000000000..324d2a1752 --- /dev/null +++ b/tests/integrationtest/t/planner/core/partition_pruner.test @@ -0,0 +1,1014 @@ +# TestRangeColumnPartitionPruningForIn +set tidb_cost_model_version=2; +drop database if exists test_range_col_in; +create database test_range_col_in; +use test_range_col_in; +set @@session.tidb_partition_prune_mode='static'; +CREATE TABLE t1 ( + id bigint(20) NOT NULL AUTO_INCREMENT, + dt date, + PRIMARY KEY (id,dt) NONCLUSTERED) + PARTITION BY RANGE COLUMNS(dt) ( + PARTITION p20201125 VALUES LESS THAN ("20201126"), + PARTITION p20201126 VALUES LESS THAN ("20201127"), + PARTITION p20201127 VALUES LESS THAN ("20201128"), + PARTITION p20201128 VALUES LESS THAN ("20201129"), + PARTITION p20201129 VALUES LESS THAN ("20201130")); +explain format='brief' select /*+ HASH_AGG() */ count(1) from t1 where dt in ('2020-11-27','2020-11-28'); +insert into t1 values (1, "2020-11-25"); +insert into t1 values (2, "2020-11-26"); +insert into t1 values (3, "2020-11-27"); +insert into t1 values (4, "2020-11-28"); +select id from t1 where dt in ('2020-11-27','2020-11-28') order by id; +select id from t1 where dt in (20201127,'2020-11-28') order by id; +select id from t1 where dt in (20201127,20201128) order by id; +select id from t1 where dt in (20201127,20201128,null) order by id; +select id from t1 where dt in ('2020-11-26','2020-11-25','2020-11-28') order by id; +select id from t1 where dt in ('2020-11-26','wrong','2020-11-28') order by id; +create table t2 (a int) partition by range columns(a) ( + partition p0 values less than (0), + partition p1 values less than (10), + partition p2 values less than (20)); +insert into t2 values (-1), (1), (11), (null); +select a from t2 where a in (-1, 1) order by a; +select a from t2 where a in (1, 11, null) order by a; +explain format='brief' select a from t2 where a in (-1, 1); +create table t3 (a varchar(10)) partition by range columns(a) ( + partition p0 values less than ("aaa"), + partition p1 values less than ("bbb"), + partition p2 values less than ("ccc")); +explain format='brief' select a from t3 where a in ('aaa', 'aab'); +explain format='brief' select a from t3 where a in ('aaa', 'bu'); + + +# TestRangeColumnPartitionPruningForInString +drop database if exists test_range_col_in_string; +create database test_range_col_in_string; +use test_range_col_in_string; +set names utf8mb4 collate utf8mb4_bin; +set @@session.tidb_partition_prune_mode='static'; +create table t (a varchar(255) charset utf8mb4 collate utf8mb4_bin) partition by range columns(a)( partition pNull values less than (""),partition pAAAA values less than ("AAAA"),partition pCCC values less than ("CCC"),partition pShrimpsandwich values less than ("Räksmörgås"),partition paaa values less than ("aaa"),partition pSushi values less than ("🍣🍣🍣"),partition pMax values less than (MAXVALUE)); +insert into t values (NULL), ("a"), ("Räkmacka"), ("🍣 is life"), ("🍺 after work?"), ("🍺🍺🍺🍺🍺 for oktoberfest"),("AA"),("aa"),("AAA"),("aaa"); +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a = 'aa'; +--sorted_result +select * from t where a = 'aa'; +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'aa' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +--sorted_result +select * from t where a collate utf8mb4_general_ci = 'aa'; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +--sorted_result +select * from t where a in ('AAA', 'aa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +--sorted_result +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a = 'aa'; +--sorted_result +select * from t where a = 'aa'; +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'aa' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +--sorted_result +select * from t where a collate utf8mb4_general_ci = 'aa'; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +--sorted_result +select * from t where a in ('AAA', 'aa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +--sorted_result +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +set names utf8mb4 collate utf8mb4_general_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a = 'aa'; +--sorted_result +select * from t where a = 'aa'; +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'aa' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +--sorted_result +select * from t where a collate utf8mb4_general_ci = 'aa'; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +--sorted_result +select * from t where a in ('AAA', 'aa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +--sorted_result +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a = 'aa'; +--sorted_result +select * from t where a = 'aa'; +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'aa' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +--sorted_result +select * from t where a collate utf8mb4_general_ci = 'aa'; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +--sorted_result +select * from t where a in ('AAA', 'aa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +--sorted_result +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +set names utf8mb4 collate utf8mb4_unicode_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a = 'aa'; +--sorted_result +select * from t where a = 'aa'; +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'aa' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +--sorted_result +select * from t where a collate utf8mb4_general_ci = 'aa'; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +--sorted_result +select * from t where a in ('AAA', 'aa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +--sorted_result +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a = 'aa'; +--sorted_result +select * from t where a = 'aa'; +explain format = 'brief' select * from t where a = 'aa' collate utf8mb4_general_ci; +--sorted_result +select * from t where a = 'aa' collate utf8mb4_general_ci; +explain format = 'brief' select * from t where a collate utf8mb4_general_ci = 'aa'; +--sorted_result +select * from t where a collate utf8mb4_general_ci = 'aa'; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AAA', 'aa'); +--sorted_result +select * from t where a in ('AAA', 'aa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_general_ci, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_general_ci); +explain format = 'brief' select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +--sorted_result +select * from t where a collate utf8mb4_general_ci in ('AAA', 'aa'); +drop table t; +create table t (a varchar(255) charset utf8mb4 collate utf8mb4_general_ci) partition by range columns(a)( partition pNull values less than (""),partition paaa values less than ("aaa"),partition pAAAA values less than ("AAAA"),partition pCCC values less than ("CCC"),partition pShrimpsandwich values less than ("Räksmörgås"),partition pSushi values less than ("🍣🍣🍣"),partition pMax values less than (MAXVALUE)); +insert into t values (NULL), ("a"), ("Räkmacka"), ("🍣 is life"), ("🍺 after work?"), ("🍺🍺🍺🍺🍺 for oktoberfest"),("AA"),("aa"),("AAA"),("aaa"); +set names utf8mb4 collate utf8mb4_bin; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AAA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +--sorted_result +select * from t where a in ('AA', 'aaa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AAA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +--sorted_result +select * from t where a in ('AA', 'aaa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +set names utf8mb4 collate utf8mb4_general_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AAA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +--sorted_result +select * from t where a in ('AA', 'aaa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AAA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +--sorted_result +select * from t where a in ('AA', 'aaa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +set names utf8mb4 collate utf8mb4_unicode_ci; +set @@tidb_partition_prune_mode = 'dynamic'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AAA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +--sorted_result +select * from t where a in ('AA', 'aaa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +set @@tidb_partition_prune_mode = 'static'; +explain format = 'brief' select * from t where a IS NULL; +--sorted_result +select * from t where a IS NULL; +explain format = 'brief' select * from t where a = 'AA'; +--sorted_result +select * from t where a = 'AA'; +explain format = 'brief' select * from t where a = 'AA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AAA'; +--sorted_result +select * from t where a = 'AAA'; +explain format = 'brief' select * from t where a = 'AAA' collate utf8mb4_bin; +--sorted_result +select * from t where a = 'AAA' collate utf8mb4_bin; +explain format = 'brief' select * from t where a = 'AB'; +--sorted_result +select * from t where a = 'AB'; +explain format = 'brief' select * from t where a = 'aB'; +--sorted_result +select * from t where a = 'aB'; +explain format = 'brief' select * from t where a = '🍣'; +--sorted_result +select * from t where a = '🍣'; +explain format = 'brief' select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +--sorted_result +select * from t where a in ('🍣 is life', "Räkmacka", "🍺🍺🍺🍺 after work?"); +explain format = 'brief' select * from t where a in ('AA', 'aaa'); +--sorted_result +select * from t where a in ('AA', 'aaa'); +explain format = 'brief' select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +--sorted_result +select * from t where a in ('AAA' collate utf8mb4_bin, 'aa'); +explain format = 'brief' select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); +--sorted_result +select * from t where a in ('AAA', 'aa' collate utf8mb4_bin); + + +# TestListColumnsPartitionPrunerRandom +drop database if exists test_partition; +create database test_partition; +use test_partition; +set @@session.tidb_enable_list_partition = ON; +create table t1 (id int, a int, b int ) partition by list columns (b, id, a) (partition p0 values in ((1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0)),partition p1 values in ((1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2)),partition p2 values in ((0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2))); +# TestListColumnsPartitionPrunerRandom +drop database if exists test_partition_1; +create database test_partition_1; +use test_partition_1; +create table t1 (id int, a int, b int); +insert into t1 (b,id,a) values (1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0); +insert into t1 (b,id,a) values (1,0,2),(2,0,2),(0,1,0),(1,1,0),(2,1,0),(0,1,1),(0,1,2),(0,2,0),(1,2,0); +--sorted_result +select * from t1 order by id,a,b; +--sorted_result +select * from t1 order by id,a,b; +insert into t1 (b,id,a) values (1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2); +insert into t1 (b,id,a) values (1,0,1),(0,0,2),(2,1,1),(2,1,2),(2,2,1),(1,2,2),(2,2,2); +--sorted_result +select * from t1 order by id,a,b; +--sorted_result +select * from t1 order by id,a,b; +insert into t1 (b,id,a) values (0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2); +insert into t1 (b,id,a) values (0,0,0),(1,0,0),(2,0,0),(0,0,1),(2,0,1),(1,1,1),(1,1,2),(2,2,0),(0,2,1),(1,2,1),(0,2,2); +--sorted_result +select * from t1 order by id,a,b; +--sorted_result +select * from t1 order by id,a,b; +--sorted_result +select * from t1 where id = 0 order by id,a,b; +--sorted_result +select * from t1 where id = 0 order by id,a,b; +--sorted_result +select * from t1 where a = 0 order by id,a,b; +--sorted_result +select * from t1 where a = 0 order by id,a,b; +--sorted_result +select * from t1 where b = 0 order by id,a,b; +--sorted_result +select * from t1 where b = 0 order by id,a,b; +--sorted_result +select * from t1 where id = 1 order by id,a,b; +--sorted_result +select * from t1 where id = 1 order by id,a,b; +--sorted_result +select * from t1 where a = 1 order by id,a,b; +--sorted_result +select * from t1 where a = 1 order by id,a,b; +--sorted_result +select * from t1 where b = 1 order by id,a,b; +--sorted_result +select * from t1 where b = 1 order by id,a,b; +--sorted_result +select * from t1 where id = 2 order by id,a,b; +--sorted_result +select * from t1 where id = 2 order by id,a,b; +--sorted_result +select * from t1 where a = 2 order by id,a,b; +--sorted_result +select * from t1 where a = 2 order by id,a,b; +--sorted_result +select * from t1 where b = 2 order by id,a,b; +--sorted_result +select * from t1 where b = 2 order by id,a,b; +--sorted_result +select * from t1 where id = 3 order by id,a,b; +--sorted_result +select * from t1 where id = 3 order by id,a,b; +--sorted_result +select * from t1 where a = 3 order by id,a,b; +--sorted_result +select * from t1 where a = 3 order by id,a,b; +--sorted_result +select * from t1 where b = 3 order by id,a,b; +--sorted_result +select * from t1 where b = 3 order by id,a,b; +--sorted_result +select * from t1 where id = 4 order by id,a,b; +--sorted_result +select * from t1 where id = 4 order by id,a,b; +--sorted_result +select * from t1 where a = 4 order by id,a,b; +--sorted_result +select * from t1 where a = 4 order by id,a,b; +--sorted_result +select * from t1 where b = 4 order by id,a,b; +--sorted_result +select * from t1 where b = 4 order by id,a,b; +--sorted_result +select * from t1 where id = 5 order by id,a,b; +--sorted_result +select * from t1 where id = 5 order by id,a,b; +--sorted_result +select * from t1 where a = 5 order by id,a,b; +--sorted_result +select * from t1 where a = 5 order by id,a,b; +--sorted_result +select * from t1 where b = 5 order by id,a,b; +--sorted_result +select * from t1 where b = 5 order by id,a,b; +--sorted_result +select * from t1 where id = 6 order by id,a,b; +--sorted_result +select * from t1 where id = 6 order by id,a,b; +--sorted_result +select * from t1 where a = 6 order by id,a,b; +--sorted_result +select * from t1 where a = 6 order by id,a,b; +--sorted_result +select * from t1 where b = 6 order by id,a,b; +--sorted_result +select * from t1 where b = 6 order by id,a,b; +--sorted_result +select * from t1 where id = 7 order by id,a,b; +--sorted_result +select * from t1 where id = 7 order by id,a,b; +--sorted_result +select * from t1 where a = 7 order by id,a,b; +--sorted_result +select * from t1 where a = 7 order by id,a,b; +--sorted_result +select * from t1 where b = 7 order by id,a,b; +--sorted_result +select * from t1 where b = 7 order by id,a,b; +--sorted_result +select * from t1 where id = 8 order by id,a,b; +--sorted_result +select * from t1 where id = 8 order by id,a,b; +--sorted_result +select * from t1 where a = 8 order by id,a,b; +--sorted_result +select * from t1 where a = 8 order by id,a,b; +--sorted_result +select * from t1 where b = 8 order by id,a,b; +--sorted_result +select * from t1 where b = 8 order by id,a,b; +--sorted_result +select * from t1 where id = 9 order by id,a,b; +--sorted_result +select * from t1 where id = 9 order by id,a,b; +--sorted_result +select * from t1 where a = 9 order by id,a,b; +--sorted_result +select * from t1 where a = 9 order by id,a,b; +--sorted_result +select * from t1 where b = 9 order by id,a,b; +--sorted_result +select * from t1 where b = 9 order by id,a,b; +--sorted_result +select * from t1 where id = 10 order by id,a,b; +--sorted_result +select * from t1 where id = 10 order by id,a,b; +--sorted_result +select * from t1 where a = 10 order by id,a,b; +--sorted_result +select * from t1 where a = 10 order by id,a,b; +--sorted_result +select * from t1 where b = 10 order by id,a,b; +--sorted_result +select * from t1 where b = 10 order by id,a,b; +--sorted_result +select * from t1 where 0 = a or 4 = b order by id,a,b; +--sorted_result +select * from t1 where 0 = a or 4 = b order by id,a,b; +--sorted_result +select * from t1 where b in (3,4,3,1) and b = 0 order by id,a,b; +--sorted_result +select * from t1 where b in (3,4,3,1) and b = 0 order by id,a,b; +--sorted_result +select * from t1 where 1 = b and id = 3 and 1 = id and b in (1,0,1,3,4,0,4,4) order by id,a,b; +--sorted_result +select * from t1 where 1 = b and id = 3 and 1 = id and b in (1,0,1,3,4,0,4,4) order by id,a,b; +--sorted_result +select * from t1 where 1 = b and id in (1,1,4,4,1,0,3) order by id,a,b; +--sorted_result +select * from t1 where 1 = b and id in (1,1,4,4,1,0,3) order by id,a,b; +--sorted_result +select * from t1 where 1 = b and b = 4 order by id,a,b; +--sorted_result +select * from t1 where 1 = b and b = 4 order by id,a,b; + + + + +# TestIssue22635 +DROP TABLE IF EXISTS t1; + +CREATE TABLE t1 ( + a int(11) DEFAULT NULL, + b int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY HASH( a ) +PARTITIONS 4; +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +insert into t1 values (1, 1); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +insert into t1 values (2, 2), (2, 2); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +insert into t1 values (3, 3), (3, 3), (3, 3); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a ASC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; +insert into t1 values (4, 4), (4, 4), (4, 4), (4, 4); +SELECT (SELECT tt.a FROM t1 tt ORDER BY a DESC LIMIT 1) aa, COUNT(DISTINCT b) FROM t1 GROUP BY aa; + + +# TestIssue22898 +DROP TABLE IF EXISTS test; +CREATE TABLE NT_RP3763 (COL1 TINYINT(8) SIGNED COMMENT "NUMERIC NO INDEX" DEFAULT 41,COL2 VARCHAR(20),COL3 DATETIME,COL4 BIGINT,COL5 FLOAT) PARTITION BY RANGE (COL1 * COL3) (PARTITION P0 VALUES LESS THAN (0),PARTITION P1 VALUES LESS THAN (10),PARTITION P2 VALUES LESS THAN (20),PARTITION P3 VALUES LESS THAN (30),PARTITION P4 VALUES LESS THAN (40),PARTITION P5 VALUES LESS THAN (50),PARTITION PMX VALUES LESS THAN MAXVALUE); +insert into NT_RP3763 (COL1,COL2,COL3,COL4,COL5) values(-82,"夐齏醕皆磹漋甓崘潮嵙燷渏艂朼洛炷鉢儝鱈肇","5748\-06\-26\ 20:48:49",-3133527360541070260,-2.624880003397658e+38); +insert into NT_RP3763 (COL1,COL2,COL3,COL4,COL5) values(48,"簖鹩筈匹眜赖泽騈爷詵赺玡婙Ɇ郝鮙廛賙疼舢","7228\-12\-13\ 02:59:54",-6181009269190017937,2.7731105531290494e+38); +--sorted_result +select * from `NT_RP3763` where `COL1` in (10, 48, -82); +--sorted_result +select * from `NT_RP3763` where `COL1` in (48); + + +# TestIssue23622 +drop table if exists t2; +create table t2 (a int, b int) partition by range (a) (partition p0 values less than (0), partition p1 values less than (5)); +insert into t2(a) values (-1), (1); +--sorted_result +select * from t2 where a > 10 or b is NULL order by a; + + +# Test22396 +DROP TABLE IF EXISTS test; +CREATE TABLE test(a INT, b INT, PRIMARY KEY(a, b)) PARTITION BY RANGE (a + b) (PARTITION p0 VALUES LESS THAN (20),PARTITION p1 VALUES LESS THAN MAXVALUE); +INSERT INTO test(a, b) VALUES(1, 11),(2, 22),(3, 33),(10, 44),(9, 55); +--sorted_result +select * FROM test WHERE a = 1; +--sorted_result +select * FROM test WHERE b = 1; +--sorted_result +select * FROM test WHERE a = 1 AND b = 1; +--sorted_result +select * FROM test WHERE a + b = 2; + + +# TestIssue23608 +set @@tidb_partition_prune_mode='static'; +drop table if exists t1; +create table t1(a int) partition by hash (a) partitions 10; +insert into t1 values (1), (2), (12), (3), (11), (13); +--sorted_result +select * from t1 where a not between 2 and 2; +--sorted_result +select * from t1 where not (a < -20 or a > 20); +--sorted_result +select * from t1 where not (a > 0 and a < 10); +--sorted_result +select * from t1 where not (a < -20); +--sorted_result +select * from t1 where not (a > 20); +--sorted_result +select * from t1 where not (a = 1); +--sorted_result +select * from t1 where not (a != 1); +drop table if exists t2; + +create table t2(a int) +partition by range (a) ( + partition p0 values less than (0), + partition p1 values less than (10), + partition p2 values less than (20) +); +explain format = 'brief' select * from t2 where not (a < 5); +set @@tidb_partition_prune_mode='dynamic'; +drop table if exists t3; +create table t3(a int) partition by hash (a) partitions 10; +insert into t3 values (1), (2), (12), (3), (11), (13); +--sorted_result +select * from t3 where a not between 2 and 2; +--sorted_result +select * from t3 where not (a < -20 or a > 20); +--sorted_result +select * from t3 where not (a > 0 and a < 10); +--sorted_result +select * from t3 where not (a < -20); +--sorted_result +select * from t3 where not (a > 20); +--sorted_result +select * from t3 where not (a = 1); +--sorted_result +select * from t3 where not (a != 1); + + +# TestHashPartitionPruning +set @@tidb_partition_prune_mode='static'; +DROP TABLE IF EXISTS t; +CREATE TABLE t (`COL1` int, `COL3` bigint) PARTITION BY HASH ((`COL1` * `COL3`))PARTITIONS 13; +--sorted_result +select * FROM t WHERE col3 =2659937067964964513 and col1 = 783367513002; +drop table if exists t; +CREATE TABLE `t` (`COL1` int NOT NULL DEFAULT '25' COMMENT 'NUMERIC PK',`COL3` bigint NOT NULL,PRIMARY KEY (`COL1`,`COL3`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH ((`COL1` * `COL3`))PARTITIONS 13; +insert into t(col1, col3) values(0, 3522101843073676459); +SELECT col1, COL3 FROM t WHERE COL1 IN (0,14158354938390,0) AND COL3 IN (3522101843073676459,-2846203247576845955,838395691793635638); + + +# TestIssue32815 +set @@tidb_partition_prune_mode='dynamic'; +DROP TABLE IF EXISTS t; +create table t (a int primary key, b int, key (b)) partition by hash(a) (partition P0, partition p1, partition P2); +insert into t values (1, 1),(2, 2),(3, 3); +explain select * from t where a IN (1, 2); +explain select * from t where a IN (1, 2, 1); + + +# TestIssue32007 +create database Issue32007; +USE Issue32007; +create table t1 (a int, b tinyint, primary key (a)) partition by range (a) (partition p0 values less than (5),partition p1 values less than (20),partition p2 values less than (30),partition p3 values less than (40),partition p4 values less than MAXVALUE); +insert into t1 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (30, 30), (31, 31), (32, 32), (33, 33), (34, 34), (35, 35), (36, 36), (40, 40), (50, 50), (80, 80), (90, 90), (100, 100); +create table t3 (a int, b mediumint, primary key (a)); +insert into t3 values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23); +set @@tidb_partition_prune_mode='static'; +--sorted_result +select * from t3 where t3.a <> ALL (select t1.a from t1 partition (p0)) order by t3.a; +set @@tidb_partition_prune_mode='dynamic'; +--sorted_result +select * from t3 where t3.a <> ALL (select t1.a from t1 partition (p0)) order by t3.a; + + +# TestIssue33231 +create database issue33231; +use issue33231; +set @@session.tidb_partition_prune_mode = 'dynamic'; +create table t1 (c_int int, c_str varchar(40), primary key (c_int, c_str) clustered, key(c_int) ) partition by hash (c_int) partitions 4; +create table t2 like t1; +insert into t1 values(6, 'beautiful curran'); +insert into t1 values(7, 'epic kalam'); +insert into t1 values(7, 'affectionate curie'); +insert into t2 values(6, 'vigorous rhodes'); +insert into t2 values(7, 'sweet aryabhata'); +--sorted_result +select /*+ INL_JOIN(t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_str <= t2.c_str and t2.c_int in (6, 7, 6); + + +# TestListDefaultPruning +create database ListDefaultPrune; +use ListDefaultPrune; +create table t (a int, b int) partition by list columns (a,b) (partition p1 values in ((1,1)), partition p2 values in ((2,2)), partition pDef default); +insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4); +analyze table t; +--sorted_result +select * from t where a in (1,2) and b in (1,2); +--sorted_result +select * from t where a in (1,2) and b in (3,4); +explain format='brief' select * from t where a in (1,2) and b in (3,4); +--sorted_result +select * from t where a in (1,2) and b in (1,2); +explain format='brief' select * from t where a in (1,2) and b in (1,2); +--sorted_result +select * from t where a in (1) and b in (1); +explain format='brief' select * from t where a in (1) and b in (1); +--sorted_result +select * from t where a = 1 and b = 1; +explain format='brief' select * from t where a = 1 and b = 1; +drop table t; +create table t (a int, b int) partition by list columns (a,b) (partition p1 values in ((1,1), (1,2)), partition p2 values in ((2,2),(2,1)), partition pDef default); +insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4); +analyze table t; +--sorted_result +select * from t where a in (1,2) and b in (1,2); +explain format='brief' select * from t where a in (1,2) and b in (1,2); +drop table t; +create table t (a int, b int) partition by list columns (a) (partition p1 values in (1), partition p2 values in (2), partition pDef default); +insert into t values (1,1),(2,2),(1,2),(2,1),(3,3),(2,3),(1,4); +analyze table t; +--sorted_result +select * from t where a in (1,2); +explain format='brief' select * from t where a in (1,2); +--sorted_result +select * from t where a = 1; +explain format='brief' select * from t where a = 1; + + +# TestIssue42273 +create database issue42273; +use issue42273; +CREATE TABLE t(a tinyint unsigned, b tinyint unsigned) PARTITION BY RANGE COLUMNS (a,b)( + PARTITION p0 VALUES LESS THAN (10,255), + PARTITION p1 VALUES LESS THAN (20,MAXVALUE), + PARTITION p2 VALUES LESS THAN (30,255), + PARTITION p3 VALUES LESS THAN (MAXVALUE, 0)); +insert into t values(20, 30); +analyze table t; +explain format='brief' select * from t where a = 20; +explain format='brief' select * from t where a > 10 and a <= 20; +--sorted_result +select * from t where a = 20; +--sorted_result +select * from t where a > 10 and a <= 20; +drop database issue42273; + + +# TestIssue43459 +create database issue43459; +use issue43459; +set @@session.tidb_partition_prune_mode = 'dynamic'; +CREATE TABLE test1 (ID varchar(50) NOT NULL, + PARTITION_NO int(11) NOT NULL DEFAULT '0', + CREATE_TIME datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (ID,PARTITION_NO,CREATE_TIME), + KEY index_partition_no (PARTITION_NO) + ) PARTITION BY RANGE COLUMNS(PARTITION_NO,CREATE_TIME) + (PARTITION 2023p1 VALUES LESS THAN (200000,'2023-01-01 00:00:00'), + PARTITION 2023p2 VALUES LESS THAN (300000,'2023-01-01 00:00:00')) ; +insert into test1 values("1", 200000, "2022-12-29 12:00:00"), ("2",200000,"2023-01-01"); +analyze table test1; +explain select * from test1 where partition_no > 199999; +explain select * from test1 where partition_no = 200000; +explain select * from test1 where partition_no >= 200000; +explain select * from test1 where partition_no < 200000; +explain select * from test1 where partition_no <= 200000; +explain select * from test1 where partition_no > 200000; +--sorted_result +select * from test1 partition (2023p1); +--sorted_result +select * from test1 partition (2023p2); +--sorted_result +select * from test1; +--sorted_result +select * from test1 where partition_no = 200000; +--sorted_result +select * from test1 where partition_no >= 200000; +drop table test1; +CREATE TABLE test1 (ID varchar(50) NOT NULL, + PARTITION_NO int(11) NOT NULL DEFAULT '0', + CREATE_TIME date NOT NULL DEFAULT CURRENT_DATE, + PRIMARY KEY (ID,PARTITION_NO,CREATE_TIME), + KEY index_partition_no (PARTITION_NO) + ) PARTITION BY RANGE COLUMNS(PARTITION_NO,CREATE_TIME) + (PARTITION 2023p1 VALUES LESS THAN (200000,'2023-01-01 00:00:00'), + PARTITION 2023p2 VALUES LESS THAN (300000,'2023-01-01 00:00:00')) ; +insert into test1 values("1", 200000, "2022-12-29 12:00:00"), ("2",200000,"2023-01-01"); +analyze table test1; +explain select * from test1 where partition_no > 199999; +explain select * from test1 where partition_no = 200000; +explain select * from test1 where partition_no >= 200000; +explain select * from test1 where partition_no < 200000; +explain select * from test1 where partition_no <= 200000; +explain select * from test1 where partition_no > 200000; +--sorted_result +select * from test1 partition (2023p1); +--sorted_result +select * from test1 partition (2023p2); +--sorted_result +select * from test1; +--sorted_result +select * from test1 where partition_no = 200000; +--sorted_result +select * from test1 where partition_no >= 200000; +drop database issue43459; + +