From 96ec91f4d9741cf8e6cbb3b66bab83dc309a7859 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 13:04:25 +0800 Subject: [PATCH 01/12] update TestReloadExtStatsLockRelease --- pkg/statistics/handle/storage/BUILD.bazel | 2 +- pkg/statistics/handle/storage/read_test.go | 11 ----------- tests/integrationtest/r/statistics/handle.result | 7 +++++++ tests/integrationtest/t/statistics/handle.test | 9 +++++++++ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pkg/statistics/handle/storage/BUILD.bazel b/pkg/statistics/handle/storage/BUILD.bazel index 41cfbd5bfcd6f..dcae7525d1172 100644 --- a/pkg/statistics/handle/storage/BUILD.bazel +++ b/pkg/statistics/handle/storage/BUILD.bazel @@ -53,7 +53,7 @@ go_test( "read_test.go", ], flaky = True, - shard_count = 21, + shard_count = 20, deps = [ ":storage", "//pkg/domain", diff --git a/pkg/statistics/handle/storage/read_test.go b/pkg/statistics/handle/storage/read_test.go index f67fad1de7772..4160ca9e74025 100644 --- a/pkg/statistics/handle/storage/read_test.go +++ b/pkg/statistics/handle/storage/read_test.go @@ -105,14 +105,3 @@ func TestLoadStats(t *testing.T) { require.Greater(t, float64(cms.TotalCount()+topN.TotalCount())+hg.TotalRowCount(), float64(0)) require.True(t, idx.IsFullLoad()) } - -func TestReloadExtStatsLockRelease(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set session tidb_enable_extended_stats = on") - tk.MustExec("use test") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("insert into t values(1,1),(2,2),(3,3)") - tk.MustExec("alter table t add stats_extended s1 correlation(a,b)") - tk.MustExec("analyze table t") // no error -} diff --git a/tests/integrationtest/r/statistics/handle.result b/tests/integrationtest/r/statistics/handle.result index f04a1f7bbd1b0..31834f28f9437 100644 --- a/tests/integrationtest/r/statistics/handle.result +++ b/tests/integrationtest/r/statistics/handle.result @@ -72,3 +72,10 @@ 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; +drop table if exists t; +create table t(a int, b int); +insert into t values(1,1),(2,2),(3,3); +alter table t add stats_extended s1 correlation(a,b); +analyze table t; +set session tidb_enable_extended_stats = default; diff --git a/tests/integrationtest/t/statistics/handle.test b/tests/integrationtest/t/statistics/handle.test index d003c06355b2c..715ffd69a26ab 100644 --- a/tests/integrationtest/t/statistics/handle.test +++ b/tests/integrationtest/t/statistics/handle.test @@ -73,3 +73,12 @@ alter table t drop stats_extended s1; -- error 1105 admin reload stats_extended; +# TestReloadExtStatsLockRelease +set session tidb_enable_extended_stats = on; +drop table if exists t; +create table t(a int, b int); +insert into t values(1,1),(2,2),(3,3); +alter table t add stats_extended s1 correlation(a,b); +## no error +analyze table t; +set session tidb_enable_extended_stats = default; From 6b0dbda4cee95923a6cfe9fae1fef56a946c34b7 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 13:41:02 +0800 Subject: [PATCH 02/12] update TestIndexMergeRuntimeStats --- pkg/session/test/variable/BUILD.bazel | 2 +- pkg/session/test/variable/variable_test.go | 25 ------------------- .../integrationtest/r/session/variable.result | 15 +++++++++++ tests/integrationtest/t/session/variable.test | 10 ++++++++ 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/session/test/variable/BUILD.bazel b/pkg/session/test/variable/BUILD.bazel index 380a6dff7e4b8..3f0a3dabf64f4 100644 --- a/pkg/session/test/variable/BUILD.bazel +++ b/pkg/session/test/variable/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "variable_test.go", ], flaky = True, - shard_count = 10, + shard_count = 9, deps = [ "//pkg/config", "//pkg/kv", diff --git a/pkg/session/test/variable/variable_test.go b/pkg/session/test/variable/variable_test.go index f4a57c23abcca..776489678396c 100644 --- a/pkg/session/test/variable/variable_test.go +++ b/pkg/session/test/variable/variable_test.go @@ -362,28 +362,3 @@ func TestIsolationRead(t *testing.T) { require.True(t, hasTiFlash) require.False(t, hasTiKV) } - -func TestIndexMergeRuntimeStats(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@tidb_enable_index_merge = 1") - tk.MustExec("create table t1(id int primary key, a int, b int, c int, d int)") - tk.MustExec("create index t1a on t1(a)") - tk.MustExec("create index t1b on t1(b)") - tk.MustExec("insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5)") - rows := tk.MustQuery("explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4;").Rows() - require.Len(t, rows, 4) - explain := fmt.Sprintf("%v", rows[0]) - pattern := ".*time:.*loops:.*index_task:{fetch_handle:.*, merge:.*}.*table_task:{num.*concurrency.*fetch_row.*wait_time.*}.*" - require.Regexp(t, pattern, explain) - tableRangeExplain := fmt.Sprintf("%v", rows[1]) - indexExplain := fmt.Sprintf("%v", rows[2]) - tableExplain := fmt.Sprintf("%v", rows[3]) - require.Regexp(t, ".*time:.*loops:.*cop_task:.*", tableRangeExplain) - require.Regexp(t, ".*time:.*loops:.*cop_task:.*", indexExplain) - require.Regexp(t, ".*time:.*loops:.*cop_task:.*", tableExplain) - tk.MustExec("set @@tidb_enable_collect_execution_info=0;") - tk.MustQuery("select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a").Check(testkit.Rows("1 1 1 1 1", "5 5 5 5 5")) -} diff --git a/tests/integrationtest/r/session/variable.result b/tests/integrationtest/r/session/variable.result index c76c3776da9c4..8997e73b96c94 100644 --- a/tests/integrationtest/r/session/variable.result +++ b/tests/integrationtest/r/session/variable.result @@ -240,3 +240,18 @@ set @@group_concat_max_len='hello'; Error 1232 (42000): Incorrect argument type to variable 'group_concat_max_len' set global group_concat_max_len = default; set @@session.group_concat_max_len = default; +drop table if EXISTS t1; +create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; +id estRows actRows task access object execution info operator info memory disk +IndexMerge_8 3334.67 2 root NULL time:, loops:, RU:, index_task:{fetch_handle:, merge:}, table_task:{num:, concurrency:, fetch_row:, wait_time:} type: union KB N/A +├─TableRangeScan_5(Build) 3333.33 1 cop[tikv] table:t1 time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:}, tikv_task:{time:, loops:} range:[-inf,2), keep order:false, stats:pseudo Bytes N/A +├─IndexRangeScan_6(Build) 3333.33 1 cop[tikv] table:t1, index:t1a(a) time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:}, tikv_task:{time:, loops:} range:(4,+inf], keep order:false, stats:pseudo N/A N/A +└─TableRowIDScan_7(Probe) 3334.67 2 cop[tikv] table:t1 time:, loops:, cop_task: {num:, max:, min:, avg:, p95:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, max_extra_concurrency:}, tikv_task:{proc max:, min:, avg:, p80:, p95:, iters:, tasks:} keep order:false, stats:pseudo N/A N/A +set @@tidb_enable_collect_execution_info=0; +select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; +id a b c d +1 1 1 1 1 +5 5 5 5 5 +set @@tidb_enable_collect_execution_info=default; diff --git a/tests/integrationtest/t/session/variable.test b/tests/integrationtest/t/session/variable.test index 200a0b3269e02..e3f26fc254166 100644 --- a/tests/integrationtest/t/session/variable.test +++ b/tests/integrationtest/t/session/variable.test @@ -179,3 +179,13 @@ set @@group_concat_max_len='hello'; set global group_concat_max_len = default; set @@session.group_concat_max_len = default; +# TestIndexMergeRuntimeStats +drop table if EXISTS t1; +create table t1(id int primary key, a int, b int, c int, d int, index t1a(a), index t1b(b)); +insert into t1 values(1,1,1,1,1),(2,2,2,2,2),(3,3,3,3,3),(4,4,4,4,4),(5,5,5,5,5); +--replace_regex /:[ ]?[.0-9]+[µms]*/:/ /, scan_detail: {.*}// / max_proc_keys:.*?, p95_proc_keys:.*?,// / tot_proc:.*?, tot_wait:.*?,// /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ +explain analyze select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4; +set @@tidb_enable_collect_execution_info=0; +select /*+ use_index_merge(t1, primary, t1a) */ * from t1 where id < 2 or a > 4 order by a; +set @@tidb_enable_collect_execution_info=default; + From 9eac1e145c77f254694474d69682d5b255a29efa Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 14:01:10 +0800 Subject: [PATCH 03/12] update session/txn, 2 test cases --- pkg/session/test/txn/BUILD.bazel | 2 +- pkg/session/test/txn/txn_test.go | 51 ---------------------- tests/integrationtest/r/session/txn.result | 32 ++++++++++++++ tests/integrationtest/t/session/txn.test | 45 +++++++++++++++++++ 4 files changed, 78 insertions(+), 52 deletions(-) create mode 100644 tests/integrationtest/r/session/txn.result create mode 100644 tests/integrationtest/t/session/txn.test diff --git a/pkg/session/test/txn/BUILD.bazel b/pkg/session/test/txn/BUILD.bazel index d3626ad0ca883..34f3c89ef7c6f 100644 --- a/pkg/session/test/txn/BUILD.bazel +++ b/pkg/session/test/txn/BUILD.bazel @@ -9,7 +9,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 11, + shard_count = 9, deps = [ "//pkg/config", "//pkg/kv", diff --git a/pkg/session/test/txn/txn_test.go b/pkg/session/test/txn/txn_test.go index 3f5893157ea34..c1a1845feef45 100644 --- a/pkg/session/test/txn/txn_test.go +++ b/pkg/session/test/txn/txn_test.go @@ -316,32 +316,6 @@ func TestAutoCommitRespectsReadOnly(t *testing.T) { tk1.MustExec("SET GLOBAL tidb_super_read_only = 0") } -func TestRetryForCurrentTxn(t *testing.T) { - store := testkit.CreateMockStore(t) - - setTxnTk := testkit.NewTestKit(t, store) - setTxnTk.MustExec("set global tidb_txn_mode=''") - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("create table history (a int)") - tk.MustExec("insert history values (1)") - - // Firstly, enable retry. - tk.MustExec("set tidb_disable_txn_auto_retry = 0") - tk.MustExec("begin") - tk.MustExec("update history set a = 2") - // Disable retry now. - tk.MustExec("set tidb_disable_txn_auto_retry = 1") - - tk1 := testkit.NewTestKit(t, store) - tk1.MustExec("use test") - tk1.MustExec("update history set a = 3") - - tk.MustExec("commit") - tk.MustQuery("select * from history").Check(testkit.Rows("2")) -} - func TestBatchCommit(t *testing.T) { store := testkit.CreateMockStore(t) setTxnTk := testkit.NewTestKit(t, store) @@ -604,28 +578,3 @@ func TestInTrans(t *testing.T) { tk.MustExec("rollback") require.False(t, txn.Valid()) } - -func TestCommitRetryCount(t *testing.T) { - store := testkit.CreateMockStore(t) - - setTxnTk := testkit.NewTestKit(t, store) - setTxnTk.MustExec("set global tidb_txn_mode=''") - tk1 := testkit.NewTestKit(t, store) - tk1.MustExec("use test") - tk2 := testkit.NewTestKit(t, store) - tk2.MustExec("use test") - - tk1.MustExec("create table no_retry (id int)") - tk1.MustExec("insert into no_retry values (1)") - tk1.MustExec("set @@tidb_retry_limit = 0") - - tk1.MustExec("begin") - tk1.MustExec("update no_retry set id = 2") - - tk2.MustExec("begin") - tk2.MustExec("update no_retry set id = 3") - tk2.MustExec("commit") - - // No auto retry because retry limit is set to 0. - require.Error(t, tk1.ExecToErr("commit")) -} diff --git a/tests/integrationtest/r/session/txn.result b/tests/integrationtest/r/session/txn.result new file mode 100644 index 0000000000000..956ef4b4a3f0a --- /dev/null +++ b/tests/integrationtest/r/session/txn.result @@ -0,0 +1,32 @@ +set session tidb_txn_mode=""; +drop table if exists no_retry; +create table no_retry (id int); +insert into no_retry values (1); +set @@tidb_retry_limit = 0; +begin; +update no_retry set id = 2; +set session tidb_txn_mode=""; +begin; +update no_retry set id = 3; +commit; +## No auto retry because retry limit is set to 0. +commit; +Error 9007 (HY000): Write conflict,
reason=Optimistic [try again later] +set session tidb_txn_mode=pessimistic; +set @@tidb_retry_limit = default; +drop table if exists history; +set session tidb_txn_mode=''; +create table history (a int); +insert history values (1); +## Firstly, enable retry. +set tidb_disable_txn_auto_retry = 0; +begin; +update history set a = 2; +## Disable retry. +set tidb_disable_txn_auto_retry = 1; +update history set a = 3; +commit; +select * from history; +a +2 +set tidb_disable_txn_auto_retry = default; diff --git a/tests/integrationtest/t/session/txn.test b/tests/integrationtest/t/session/txn.test new file mode 100644 index 0000000000000..449ef9ccbd089 --- /dev/null +++ b/tests/integrationtest/t/session/txn.test @@ -0,0 +1,45 @@ +# TestCommitRetryCount +set session tidb_txn_mode=""; +drop table if exists no_retry; +create table no_retry (id int); +insert into no_retry values (1); +set @@tidb_retry_limit = 0; +begin; +update no_retry set id = 2; + +connect (conn1, localhost, root,, session__txn); +set session tidb_txn_mode=""; +begin; +update no_retry set id = 3; +commit; +disconnect conn1; + +-- echo ## No auto retry because retry limit is set to 0. +-- replace_regex /Write conflict,.*reason=Optimistic \[try again later\]/Write conflict,
reason=Optimistic [try again later]/ +-- error 9007 +commit; +set session tidb_txn_mode=pessimistic; +set @@tidb_retry_limit = default; + + +# TestRetryForCurrentTxn +drop table if exists history; +set session tidb_txn_mode=''; +create table history (a int); +insert history values (1); + +-- echo ## Firstly, enable retry. +set tidb_disable_txn_auto_retry = 0; +begin; +update history set a = 2; +-- echo ## Disable retry. +set tidb_disable_txn_auto_retry = 1; + +connect (conn1, localhost, root,, session__txn); +update history set a = 3; +connection default; + +commit; +select * from history; +disconnect conn1; +set tidb_disable_txn_auto_retry = default; From 3b351aeed2ba40b6ec4f26afd7ceb3078395482c Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 14:12:03 +0800 Subject: [PATCH 04/12] update session/privileges, 3 test cases --- pkg/session/test/privileges/BUILD.bazel | 1 - .../test/privileges/privileges_test.go | 120 ----------------- .../r/session/privileges.result | 103 +++++++++++++++ .../integrationtest/t/session/privileges.test | 121 ++++++++++++++++++ 4 files changed, 224 insertions(+), 121 deletions(-) create mode 100644 tests/integrationtest/r/session/privileges.result create mode 100644 tests/integrationtest/t/session/privileges.test diff --git a/pkg/session/test/privileges/BUILD.bazel b/pkg/session/test/privileges/BUILD.bazel index 461850b395826..5000b15ae579b 100644 --- a/pkg/session/test/privileges/BUILD.bazel +++ b/pkg/session/test/privileges/BUILD.bazel @@ -8,7 +8,6 @@ go_test( "privileges_test.go", ], flaky = True, - shard_count = 5, deps = [ "//pkg/config", "//pkg/parser/auth", diff --git a/pkg/session/test/privileges/privileges_test.go b/pkg/session/test/privileges/privileges_test.go index 2d2160298b21a..77d62dd8cba2f 100644 --- a/pkg/session/test/privileges/privileges_test.go +++ b/pkg/session/test/privileges/privileges_test.go @@ -43,126 +43,6 @@ func TestSkipWithGrant(t *testing.T) { tk.MustExec("show grants for root") privileges.SkipWithGrant = save2 } -func TestGrantViewRelated(t *testing.T) { - store := testkit.CreateMockStore(t) - - tkRoot := testkit.NewTestKit(t, store) - tkUser := testkit.NewTestKit(t, store) - tkRoot.MustExec("use test") - tkUser.MustExec("use test") - - tkRoot.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost", CurrentUser: true, AuthUsername: "root", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) - - tkRoot.MustExec("create table if not exists t (a int)") - tkRoot.MustExec("create view v_version29 as select * from t") - tkRoot.MustExec("create user 'u_version29'@'%'") - tkRoot.MustExec("grant select on t to u_version29@'%'") - - tkUser.Session().Auth(&auth.UserIdentity{Username: "u_version29", Hostname: "localhost", CurrentUser: true, AuthUsername: "u_version29", AuthHostname: "%"}, nil, []byte("012345678901234567890"), nil) - - tkUser.MustQuery("select current_user();").Check(testkit.Rows("u_version29@%")) - require.Error(t, tkUser.ExecToErr("select * from test.v_version29;")) - tkUser.MustQuery("select current_user();").Check(testkit.Rows("u_version29@%")) - require.Error(t, tkUser.ExecToErr("create view v_version29_c as select * from t;")) - - tkRoot.MustExec(`grant show view, select on v_version29 to 'u_version29'@'%'`) - tkRoot.MustQuery("select table_priv from mysql.tables_priv where host='%' and db='test' and user='u_version29' and table_name='v_version29'").Check(testkit.Rows("Select,Show View")) - - tkUser.MustQuery("select current_user();").Check(testkit.Rows("u_version29@%")) - tkUser.MustQuery("show create view v_version29;") - require.Error(t, tkUser.ExecToErr("create view v_version29_c as select * from v_version29;")) - - tkRoot.MustExec("create view v_version29_c as select * from v_version29;") - tkRoot.MustExec(`grant create view on v_version29_c to 'u_version29'@'%'`) // Can't grant privilege on a non-exist table/view. - tkRoot.MustQuery("select table_priv from mysql.tables_priv where host='%' and db='test' and user='u_version29' and table_name='v_version29_c'").Check(testkit.Rows("Create View")) - tkRoot.MustExec("drop view v_version29_c") - - tkRoot.MustExec(`grant select on v_version29 to 'u_version29'@'%'`) - tkUser.MustQuery("select current_user();").Check(testkit.Rows("u_version29@%")) - tkUser.MustExec("create view v_version29_c as select * from v_version29;") -} - -func TestUpdatePrivilege(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 (id int);") - tk.MustExec("create table t2 (id int);") - tk.MustExec("insert into t1 values (1);") - tk.MustExec("insert into t2 values (2);") - tk.MustExec("create user xxx;") - tk.MustExec("grant all on test.t1 to xxx;") - tk.MustExec("grant select on test.t2 to xxx;") - - tk1 := testkit.NewTestKit(t, store) - tk1.MustExec("use test") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: "localhost"}, []byte(""), []byte(""), nil)) - - tk1.MustMatchErrMsg("update t2 set id = 666 where id = 1;", "privilege check.*") - - // Cover a bug that t1 and t2 both require update privilege. - // In fact, the privlege check for t1 should be update, and for t2 should be select. - tk1.MustExec("update t1,t2 set t1.id = t2.id;") - - // Fix issue 8911 - tk.MustExec("create database weperk") - tk.MustExec("use weperk") - tk.MustExec("create table tb_wehub_server (id int, active_count int, used_count int)") - tk.MustExec("create user 'weperk'") - tk.MustExec("grant all privileges on weperk.* to 'weperk'@'%'") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "weperk", Hostname: "%"}, []byte(""), []byte(""), nil)) - tk1.MustExec("use weperk") - tk1.MustExec("update tb_wehub_server a set a.active_count=a.active_count+1,a.used_count=a.used_count+1 where id=1") - - tk.MustExec("create database service") - tk.MustExec("create database report") - tk.MustExec(`CREATE TABLE service.t1 ( - id int(11) DEFAULT NULL, - a bigint(20) NOT NULL, - b text DEFAULT NULL, - PRIMARY KEY (a) -)`) - tk.MustExec(`CREATE TABLE report.t2 ( - a bigint(20) DEFAULT NULL, - c bigint(20) NOT NULL -)`) - tk.MustExec("grant all privileges on service.* to weperk") - tk.MustExec("grant all privileges on report.* to weperk") - tk1.Session().GetSessionVars().CurrentDB = "" - tk1.MustExec(`update service.t1 s, -report.t2 t -set s.a = t.a -WHERE -s.a = t.a -and t.c >= 1 and t.c <= 10000 -and s.b !='xx';`) - - // Fix issue 10028 - tk.MustExec("create database ap") - tk.MustExec("create database tp") - tk.MustExec("grant all privileges on ap.* to xxx") - tk.MustExec("grant select on tp.* to xxx") - tk.MustExec("create table tp.record( id int,name varchar(128),age int)") - tk.MustExec("insert into tp.record (id,name,age) values (1,'john',18),(2,'lary',19),(3,'lily',18)") - tk.MustExec("create table ap.record( id int,name varchar(128),age int)") - tk.MustExec("insert into ap.record(id) values(1)") - require.NoError(t, tk1.Session().Auth(&auth.UserIdentity{Username: "xxx", Hostname: "localhost"}, []byte(""), []byte(""), nil)) - tk1.MustExec("update ap.record t inner join tp.record tt on t.id=tt.id set t.name=tt.name") -} - -func TestDBUserNameLength(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table if not exists t (a int)") - // Test username length can be longer than 16. - tk.MustExec(`CREATE USER 'abcddfjakldfjaldddds'@'%' identified by ''`) - tk.MustExec(`grant all privileges on test.* to 'abcddfjakldfjaldddds'@'%'`) - tk.MustExec(`grant all privileges on test.t to 'abcddfjakldfjaldddds'@'%'`) -} func TestSessionAuth(t *testing.T) { store := testkit.CreateMockStore(t) diff --git a/tests/integrationtest/r/session/privileges.result b/tests/integrationtest/r/session/privileges.result new file mode 100644 index 0000000000000..1379b5a416b38 --- /dev/null +++ b/tests/integrationtest/r/session/privileges.result @@ -0,0 +1,103 @@ +drop user if exists 'abcddfjakldfjaldddds'@'%'; +create table if not exists t (a int); +## Test username length can be longer than 16. +CREATE USER 'abcddfjakldfjaldddds'@'%' identified by ''; +grant all privileges on test.* to 'abcddfjakldfjaldddds'@'%'; +grant all privileges on test.t to 'abcddfjakldfjaldddds'@'%'; +drop view if exists v_version29; +drop user if exists 'u_version29'@'%'; +create table if not exists t (a int); +create view v_version29 as select * from t; +create user 'u_version29'@'%'; +grant select on t to u_version29@'%'; +select current_user(); +current_user() +u_version29@% +select * from test.v_version29; +Error 1142 (42000): SELECT command denied to user 'u_version29'@'%' for table 'v_version29' +select current_user(); +current_user() +u_version29@% +create view v_version29_c as select * from t; +Error 1142 (42000): CREATE VIEW command denied to user 'u_version29'@'%' for table 'v_version29_c' +grant show view, select on v_version29 to 'u_version29'@'%'; +select table_priv from mysql.tables_priv where host='%' and db='session__privileges' and user='u_version29' and table_name='v_version29'; +table_priv +Select,Show View +select current_user(); +current_user() +u_version29@% +show create view v_version29; +View Create View character_set_client collation_connection +v_version29 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v_version29` (`a`) AS SELECT `session__privileges`.`t`.`a` AS `a` FROM `session__privileges`.`t` utf8mb4 utf8mb4_general_ci +create view v_version29_c as select * from v_version29; +Error 1142 (42000): CREATE VIEW command denied to user 'u_version29'@'%' for table 'v_version29_c' +create view v_version29_c as select * from v_version29; +grant create view on v_version29_c to 'u_version29'@'%'; +select table_priv from mysql.tables_priv where host='%' and db='session__privileges' and user='u_version29' and table_name='v_version29_c'; +table_priv +Create View +drop view v_version29_c; +grant select on v_version29 to 'u_version29'@'%'; +select current_user(); +current_user() +u_version29@% +create view v_version29_c as select * from v_version29; +drop table if exists t1, t2; +drop user if exists xxx; +create table t1 (id int); +create table t2 (id int); +insert into t1 values (1); +insert into t2 values (2); +create user xxx; +grant all on session__privileges.t1 to xxx; +grant select on session__privileges.t2 to xxx; +update t2 set id = 666 where id = 1; +Error 8121 (HY000): privilege check for 'Update' fail +## Cover a bug that t1 and t2 both require update privilege. +## In fact, the privlege check for t1 should be update, and for t2 should be select. +update t1,t2 set t1.id = t2.id; +## Fix issue 8911 +drop database if exists weperk; +drop user if exists weperk; +create database weperk; +use weperk; +create table tb_wehub_server (id int, active_count int, used_count int); +create user 'weperk'; +grant all privileges on weperk.* to 'weperk'@'%'; +update tb_wehub_server a set a.active_count=a.active_count+1,a.used_count=a.used_count+1 where id=1; +drop database if exists service; +drop database if exists report; +create database service; +create database report; +CREATE TABLE service.t1 ( +id int(11) DEFAULT NULL, +a bigint(20) NOT NULL, +b text DEFAULT NULL, +PRIMARY KEY (a) +); +CREATE TABLE report.t2 ( +a bigint(20) DEFAULT NULL, +c bigint(20) NOT NULL +); +grant all privileges on service.* to weperk; +grant all privileges on report.* to weperk; +update service.t1 s, +report.t2 t +set s.a = t.a +WHERE +s.a = t.a +and t.c >= 1 and t.c <= 10000 +and s.b !='xx'; +## Fix issue 10028 +drop database if exists ap; +drop database if exists tp; +create database ap; +create database tp; +grant all privileges on ap.* to xxx; +grant select on tp.* to xxx; +create table tp.record( id int,name varchar(128),age int); +insert into tp.record (id,name,age) values (1,'john',18),(2,'lary',19),(3,'lily',18); +create table ap.record( id int,name varchar(128),age int); +insert into ap.record(id) values(1); +update ap.record t inner join tp.record tt on t.id=tt.id set t.name=tt.name; diff --git a/tests/integrationtest/t/session/privileges.test b/tests/integrationtest/t/session/privileges.test new file mode 100644 index 0000000000000..82801c47045a2 --- /dev/null +++ b/tests/integrationtest/t/session/privileges.test @@ -0,0 +1,121 @@ +# TestDBUserNameLength +drop user if exists 'abcddfjakldfjaldddds'@'%'; +create table if not exists t (a int); +-- echo ## Test username length can be longer than 16. +CREATE USER 'abcddfjakldfjaldddds'@'%' identified by ''; +grant all privileges on test.* to 'abcddfjakldfjaldddds'@'%'; +grant all privileges on test.t to 'abcddfjakldfjaldddds'@'%'; + +# TestGrantViewRelated +drop view if exists v_version29; +drop user if exists 'u_version29'@'%'; +create table if not exists t (a int); +create view v_version29 as select * from t; +create user 'u_version29'@'%'; +grant select on t to u_version29@'%'; + +connect (conn1, localhost, u_version29,, session__privileges); +select current_user(); +-- error 1142 +select * from test.v_version29; +select current_user(); +-- error 1142 +create view v_version29_c as select * from t; + +connection default; +grant show view, select on v_version29 to 'u_version29'@'%'; +select table_priv from mysql.tables_priv where host='%' and db='session__privileges' and user='u_version29' and table_name='v_version29'; + +connection conn1; +select current_user(); +show create view v_version29; +-- error 1142 +create view v_version29_c as select * from v_version29; + +connection default; +create view v_version29_c as select * from v_version29; +grant create view on v_version29_c to 'u_version29'@'%'; +select table_priv from mysql.tables_priv where host='%' and db='session__privileges' and user='u_version29' and table_name='v_version29_c'; +drop view v_version29_c; +grant select on v_version29 to 'u_version29'@'%'; + +connection conn1; +select current_user(); +create view v_version29_c as select * from v_version29; + +disconnect conn1; + +# TestUpdatePrivilege +drop table if exists t1, t2; +drop user if exists xxx; +create table t1 (id int); +create table t2 (id int); +insert into t1 values (1); +insert into t2 values (2); +create user xxx; +grant all on session__privileges.t1 to xxx; +grant select on session__privileges.t2 to xxx; + +connect (conn1, localhost, xxx,,session__privileges); +-- error 8121 +update t2 set id = 666 where id = 1; +-- echo ## Cover a bug that t1 and t2 both require update privilege. +-- echo ## In fact, the privlege check for t1 should be update, and for t2 should be select. +update t1,t2 set t1.id = t2.id; +disconnect conn1; + +-- echo ## Fix issue 8911 +drop database if exists weperk; +drop user if exists weperk; +create database weperk; +use weperk; +create table tb_wehub_server (id int, active_count int, used_count int); +create user 'weperk'; +grant all privileges on weperk.* to 'weperk'@'%'; + +connect (conn1, localhost, weperk,,weperk); +update tb_wehub_server a set a.active_count=a.active_count+1,a.used_count=a.used_count+1 where id=1; +disconnect conn1; + +drop database if exists service; +drop database if exists report; +create database service; +create database report; +CREATE TABLE service.t1 ( + id int(11) DEFAULT NULL, + a bigint(20) NOT NULL, + b text DEFAULT NULL, + PRIMARY KEY (a) +); +CREATE TABLE report.t2 ( + a bigint(20) DEFAULT NULL, + c bigint(20) NOT NULL +); +grant all privileges on service.* to weperk; +grant all privileges on report.* to weperk; + +connect (conn1, localhost, weperk,,); +update service.t1 s, + report.t2 t + set s.a = t.a +WHERE + s.a = t.a +and t.c >= 1 and t.c <= 10000 +and s.b !='xx'; +disconnect conn1; + +--echo ## Fix issue 10028 +drop database if exists ap; +drop database if exists tp; +create database ap; +create database tp; +grant all privileges on ap.* to xxx; +grant select on tp.* to xxx; +create table tp.record( id int,name varchar(128),age int); +insert into tp.record (id,name,age) values (1,'john',18),(2,'lary',19),(3,'lily',18); +create table ap.record( id int,name varchar(128),age int); +insert into ap.record(id) values(1); + +connect (conn1, localhost, xxx,,); +update ap.record t inner join tp.record tt on t.id=tt.id set t.name=tt.name; +disconnect conn1; From 84d17a9cbee20f867f6f96786018dbb4c8135eee Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 16:12:48 +0800 Subject: [PATCH 05/12] update planner/core/casetest/physicalplantest/physical_plan.test, 22 test cases --- .../casetest/physicalplantest/BUILD.bazel | 3 +- .../physicalplantest/physical_plan_test.go | 1133 +--- .../testdata/plan_suite_in.json | 463 -- .../testdata/plan_suite_out.json | 5553 ++--------------- .../physicalplantest/physical_plan.result | 3731 +++++++++++ .../physicalplantest/physical_plan.test | 971 +++ 6 files changed, 5434 insertions(+), 6420 deletions(-) create mode 100644 tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result create mode 100644 tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test diff --git a/pkg/planner/core/casetest/physicalplantest/BUILD.bazel b/pkg/planner/core/casetest/physicalplantest/BUILD.bazel index 63eb84c1bafb4..5281d694291c3 100644 --- a/pkg/planner/core/casetest/physicalplantest/BUILD.bazel +++ b/pkg/planner/core/casetest/physicalplantest/BUILD.bazel @@ -10,7 +10,7 @@ go_test( data = glob(["testdata/**"]), flaky = True, race = "on", - shard_count = 50, + shard_count = 30, deps = [ "//pkg/config", "//pkg/domain", @@ -23,7 +23,6 @@ go_test( "//pkg/planner/core", "//pkg/planner/core/internal", "//pkg/sessionctx/stmtctx", - "//pkg/sessionctx/variable", "//pkg/testkit", "//pkg/testkit/external", "//pkg/testkit/testdata", diff --git a/pkg/planner/core/casetest/physicalplantest/physical_plan_test.go b/pkg/planner/core/casetest/physicalplantest/physical_plan_test.go index 667aec2ca725f..ba29c00fee313 100644 --- a/pkg/planner/core/casetest/physicalplantest/physical_plan_test.go +++ b/pkg/planner/core/casetest/physicalplantest/physical_plan_test.go @@ -32,7 +32,6 @@ import ( "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/planner/core/internal" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" - "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/testkit" "github.com/pingcap/tidb/pkg/testkit/external" "github.com/pingcap/tidb/pkg/testkit/testdata" @@ -52,56 +51,6 @@ func assertSameHints(t *testing.T, expected, actual []*ast.TableOptimizerHint) { require.ElementsMatch(t, expectedStr, actualStr) } -func doTestPushdownDistinct(t *testing.T, vars, input []string, output []struct { - SQL string - Plan []string - Result []string -}) { - 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, index(c))") - tk.MustExec("insert into t values (1, 1, 1), (1, 1, 3), (1, 2, 3), (2, 1, 3), (1, 2, NULL);") - - tk.MustExec("drop table if exists pt") - tk.MustExec(`CREATE TABLE pt (a int, b int) PARTITION BY RANGE (a) ( - PARTITION p0 VALUES LESS THAN (2), - PARTITION p1 VALUES LESS THAN (100) - );`) - - tk.MustExec("drop table if exists tc;") - tk.MustExec("CREATE TABLE `tc`(`timestamp` timestamp NULL DEFAULT NULL, KEY `idx_timestamp` (`timestamp`)) PARTITION BY RANGE ( UNIX_TIMESTAMP(`timestamp`) ) (PARTITION `p2020072312` VALUES LESS THAN (1595480400),PARTITION `p2020072313` VALUES LESS THAN (1595484000));") - - tk.MustExec("drop table if exists ta") - tk.MustExec("create table ta(a int);") - tk.MustExec("insert into ta values(1), (1);") - tk.MustExec("drop table if exists tb") - tk.MustExec("create table tb(a int);") - tk.MustExec("insert into tb values(1), (1);") - - tk.MustExec("set session sql_mode=''") - tk.MustExec(fmt.Sprintf("set session %s=1", variable.TiDBHashAggPartialConcurrency)) - tk.MustExec(fmt.Sprintf("set session %s=1", variable.TiDBHashAggFinalConcurrency)) - - tk.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`) - - for _, v := range vars { - tk.MustExec(v) - } - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...)) - } -} - func TestRefine(t *testing.T) { store := testkit.CreateMockStore(t) @@ -196,144 +145,6 @@ func TestRuleColumnPruningLogicalApply(t *testing.T) { } } -func TestINMJHint(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - 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 not null)") - tk.MustExec("create table t2(a int primary key, b int not null)") - tk.MustExec("insert into t1 values(1,1),(2,2)") - tk.MustExec("insert into t2 values(1,1),(2,1)") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...)) - } -} - -func TestEliminateMaxOneRow(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - 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("drop table if exists t3;") - tk.MustExec("create table t1(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, UNIQUE KEY idx_a (a))") - tk.MustExec("create table t2(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL)") - tk.MustExec("create table t3(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, c int(11) DEFAULT NULL, UNIQUE KEY idx_abc (a, b, c))") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestIndexJoinUnionScan(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("create table t (a int primary key, b int, index idx(a))") - tk.MustExec("create table tt (a int primary key) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200))") - tk.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`) - - var input [][]string - var output []struct { - SQL []string - Plan []string - } - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, ts := range input { - tk.MustExec("begin") - for j, tt := range ts { - if j != len(ts)-1 { - tk.MustExec(tt) - } - testdata.OnRecord(func() { - output[i].SQL = ts - if j == len(ts)-1 { - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Rows()) - } - }) - if j == len(ts)-1 { - tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...)) - } - } - tk.MustExec("rollback") - } -} - -func TestMergeJoinUnionScan(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key (c_int))") - tk.MustExec("create table t2 (c_int int, c_str varchar(40), primary key (c_int))") - tk.MustExec("insert into t1 (`c_int`, `c_str`) values (11, 'keen williamson'), (10, 'gracious hermann')") - tk.MustExec("insert into t2 (`c_int`, `c_str`) values (10, 'gracious hermann')") - - var input [][]string - var output []struct { - SQL []string - Plan []string - } - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, ts := range input { - tk.MustExec("begin") - for j, tt := range ts { - if j != len(ts)-1 { - tk.MustExec(tt) - } - testdata.OnRecord(func() { - output[i].SQL = ts - if j == len(ts)-1 { - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Rows()) - } - }) - if j == len(ts)-1 { - tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...)) - } - } - tk.MustExec("rollback") - } -} - func TestSemiJoinToInner(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1052,364 +863,131 @@ func TestAggToCopHint(t *testing.T) { } } -func TestLimitToCopHint(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 tn") - tk.MustExec("create table tn(a int, b int, c int, d int, key (a, b, c, d))") - tk.MustExec(`set tidb_opt_limit_push_down_threshold=0`) - +func TestGroupConcatOrderby(t *testing.T) { + failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune", `return(true)`) + defer failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune") var ( input []string output []struct { - SQL string - Plan []string - Warning []string + SQL string + Plan []string + Result []string } ) - planSuiteData := GetPlanSuiteData() planSuiteData.LoadTestCases(t, &input, &output) + 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(id int, name int)") + tk.MustExec("insert into test values(1, 10);") + tk.MustExec("insert into test values(1, 20);") + tk.MustExec("insert into test values(1, 30);") + tk.MustExec("insert into test values(2, 20);") + tk.MustExec("insert into test values(3, 200);") + tk.MustExec("insert into test values(3, 500);") + + tk.MustExec("drop table if exists ptest;") + tk.MustExec("CREATE TABLE ptest (id int,name int) PARTITION BY RANGE ( id ) " + + "(PARTITION `p0` VALUES LESS THAN (2), PARTITION `p1` VALUES LESS THAN (11))") + tk.MustExec("insert into ptest select * from test;") + tk.MustExec(fmt.Sprintf("set session tidb_opt_distinct_agg_push_down = %v", 1)) + tk.MustExec(fmt.Sprintf("set session tidb_opt_agg_push_down = %v", 1)) for i, ts := range input { testdata.OnRecord(func() { output[i].SQL = ts output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) + output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) }) tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - - comment := fmt.Sprintf("case:%v sql:%s", i, ts) - warnings := tk.Session().GetSessionVars().StmtCtx.GetWarnings() - testdata.OnRecord(func() { - if len(warnings) > 0 { - output[i].Warning = make([]string, len(warnings)) - for j, warning := range warnings { - output[i].Warning[j] = warning.Err.Error() - } - } - }) - if len(output[i].Warning) == 0 { - require.Len(t, warnings, 0) - } else { - require.Len(t, warnings, len(output[i].Warning), comment) - for j, warning := range warnings { - require.Equal(t, stmtctx.WarnLevelWarning, warning.Level, comment) - require.Equal(t, output[i].Warning[j], warning.Err.Error(), comment) - } - } + tk.MustQuery(ts).Check(testkit.Rows(output[i].Result...)) } } -func TestCTEMergeHint(t *testing.T) { +func TestIndexHint(t *testing.T) { store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) tk.MustExec("use test") - tk.MustExec("drop table if exists tc") - tk.MustExec("drop table if exists te") - tk.MustExec("drop table if exists t1") - tk.MustExec("drop table if exists t2") - tk.MustExec("drop table if exists t3") - tk.MustExec("drop table if exists t4") - tk.MustExec("drop view if exists v") - tk.MustExec("create table tc(a int)") - tk.MustExec("create table te(c int)") - tk.MustExec("create table t1(a int)") - tk.MustExec("create table t2(b int)") - tk.MustExec("create table t3(c int)") - tk.MustExec("create table t4(d int)") - tk.MustExec("insert into tc values (1), (5), (10), (15), (20), (30), (50);") - tk.MustExec("insert into te values (1), (5), (10), (25), (40), (60), (100);") - tk.MustExec("insert into t1 values (1), (5), (10), (25), (40), (60), (100);") - tk.MustExec("insert into t2 values (1), (5), (10), (25), (40), (60), (100);") - tk.MustExec("insert into t3 values (1), (5), (10), (25), (40), (60), (100);") - tk.MustExec("insert into t4 values (1), (5), (10), (25), (40), (60), (100);") - tk.MustExec("analyze table tc;") - tk.MustExec("analyze table te;") - tk.MustExec("analyze table t1;") - tk.MustExec("analyze table t2;") - tk.MustExec("analyze table t3;") - tk.MustExec("analyze table t4;") - tk.MustExec("create definer='root'@'localhost' view v as select * from tc") - var ( - input []string - output []struct { - SQL string - Plan []string - Warning []string - } - ) + var input []string + var output []struct { + SQL string + Best string + HasWarn bool + Hints string + } planSuiteData := GetPlanSuiteData() planSuiteData.LoadTestCases(t, &input, &output) + ctx := context.Background() + p := parser.New() + is := infoschema.MockInfoSchema([]*model.TableInfo{core.MockSignedTable(), core.MockUnsignedTable()}) - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) + for i, test := range input { + comment := fmt.Sprintf("case:%v sql:%s", i, test) + tk.Session().GetSessionVars().StmtCtx.SetWarnings(nil) - comment := fmt.Sprintf("case:%v sql:%s", i, ts) - warnings := tk.Session().GetSessionVars().StmtCtx.GetWarnings() + stmt, err := p.ParseOneStmt(test, "", "") + require.NoError(t, err, comment) + + p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) + require.NoError(t, err) testdata.OnRecord(func() { - if len(warnings) > 0 { - output[i].Warning = make([]string, len(warnings)) - for j, warning := range warnings { - output[i].Warning[j] = warning.Err.Error() - } - } + output[i].SQL = test + output[i].Best = core.ToString(p) + output[i].HasWarn = len(tk.Session().GetSessionVars().StmtCtx.GetWarnings()) > 0 + output[i].Hints = hint.RestoreOptimizerHints(core.GenHintsFromPhysicalPlan(p)) }) - if len(output[i].Warning) == 0 { - require.Len(t, warnings, 0) + require.Equal(t, output[i].Best, core.ToString(p), comment) + warnings := tk.Session().GetSessionVars().StmtCtx.GetWarnings() + if output[i].HasWarn { + require.Len(t, warnings, 1, comment) } else { - require.Len(t, warnings, len(output[i].Warning), comment) - for j, warning := range warnings { - require.Equal(t, stmtctx.WarnLevelWarning, warning.Level, comment) - require.Equal(t, output[i].Warning[j], warning.Err.Error(), comment) - } + require.Len(t, warnings, 0, comment) } + hints := core.GenHintsFromPhysicalPlan(p) + + // test the new genHints code + flat := core.FlattenPhysicalPlan(p, false) + newHints := core.GenHintsFromFlatPlan(flat) + assertSameHints(t, hints, newHints) + + require.Equal(t, output[i].Hints, hint.RestoreOptimizerHints(hints), comment) } } -func TestForceInlineCTE(t *testing.T) { +func TestIndexMergeHint(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(11));") - tk.MustExec("insert into t values (1), (5), (10), (15), (20), (30), (50);") - var ( - input []string - output []struct { - SQL string - Plan []string - Warning []string - } - ) + var input []string + var output []struct { + SQL string + Best string + HasWarn bool + Hints string + } planSuiteData := GetPlanSuiteData() planSuiteData.LoadTestCases(t, &input, &output) + ctx := context.Background() + p := parser.New() + is := infoschema.MockInfoSchema([]*model.TableInfo{core.MockSignedTable(), core.MockUnsignedTable()}) - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - }) - if strings.HasPrefix(ts, "set") { - tk.MustExec(ts) - continue - } - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief' " + ts).Rows()) - }) - tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - - comment := fmt.Sprintf("case:%v sql:%s", i, ts) - warnings := tk.Session().GetSessionVars().StmtCtx.GetWarnings() - testdata.OnRecord(func() { - if len(warnings) > 0 { - output[i].Warning = make([]string, len(warnings)) - for j, warning := range warnings { - output[i].Warning[j] = warning.Err.Error() - } - } - }) - if len(output[i].Warning) == 0 { - require.Len(t, warnings, 0) - } else { - require.Len(t, warnings, len(output[i].Warning), comment) - for j, warning := range warnings { - require.Equal(t, stmtctx.WarnLevelWarning, warning.Level, comment) - require.Equal(t, output[i].Warning[j], warning.Err.Error(), comment) - } - } - } -} - -func TestSingleConsumerCTE(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));") - tk.MustExec("create table t1 (c1 int primary key, c2 int, index c2 (c2));") - tk.MustExec("create table t2 (c1 int unique, c2 int);") - tk.MustExec("insert into t values (1), (5), (10), (15), (20), (30), (50);") - - var ( - input []string - output []struct { - SQL string - Plan []string - Warning []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - }) - if strings.HasPrefix(ts, "set") { - tk.MustExec(ts) - continue - } - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief' " + ts).Rows()) - }) - tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - } -} - -func TestPushdownDistinctEnableAggPushDownDisable(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - vars := []string{ - fmt.Sprintf("set @@session.%s = 1", variable.TiDBOptDistinctAggPushDown), - "set session tidb_opt_agg_push_down = 0", - "set tidb_cost_model_version=2", - } - doTestPushdownDistinct(t, vars, input, output) -} - -func TestGroupConcatOrderby(t *testing.T) { - failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune", `return(true)`) - defer failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune") - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - 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(id int, name int)") - tk.MustExec("insert into test values(1, 10);") - tk.MustExec("insert into test values(1, 20);") - tk.MustExec("insert into test values(1, 30);") - tk.MustExec("insert into test values(2, 20);") - tk.MustExec("insert into test values(3, 200);") - tk.MustExec("insert into test values(3, 500);") - - tk.MustExec("drop table if exists ptest;") - tk.MustExec("CREATE TABLE ptest (id int,name int) PARTITION BY RANGE ( id ) " + - "(PARTITION `p0` VALUES LESS THAN (2), PARTITION `p1` VALUES LESS THAN (11))") - tk.MustExec("insert into ptest select * from test;") - tk.MustExec(fmt.Sprintf("set session tidb_opt_distinct_agg_push_down = %v", 1)) - tk.MustExec(fmt.Sprintf("set session tidb_opt_agg_push_down = %v", 1)) - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestIndexHint(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - var input []string - var output []struct { - SQL string - Best string - HasWarn bool - Hints string - } - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - ctx := context.Background() - p := parser.New() - is := infoschema.MockInfoSchema([]*model.TableInfo{core.MockSignedTable(), core.MockUnsignedTable()}) - - for i, test := range input { - comment := fmt.Sprintf("case:%v sql:%s", i, test) - tk.Session().GetSessionVars().StmtCtx.SetWarnings(nil) - - stmt, err := p.ParseOneStmt(test, "", "") - require.NoError(t, err, comment) - - p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) - require.NoError(t, err) - testdata.OnRecord(func() { - output[i].SQL = test - output[i].Best = core.ToString(p) - output[i].HasWarn = len(tk.Session().GetSessionVars().StmtCtx.GetWarnings()) > 0 - output[i].Hints = hint.RestoreOptimizerHints(core.GenHintsFromPhysicalPlan(p)) - }) - require.Equal(t, output[i].Best, core.ToString(p), comment) - warnings := tk.Session().GetSessionVars().StmtCtx.GetWarnings() - if output[i].HasWarn { - require.Len(t, warnings, 1, comment) - } else { - require.Len(t, warnings, 0, comment) - } - hints := core.GenHintsFromPhysicalPlan(p) - - // test the new genHints code - flat := core.FlattenPhysicalPlan(p, false) - newHints := core.GenHintsFromFlatPlan(flat) - assertSameHints(t, hints, newHints) - - require.Equal(t, output[i].Hints, hint.RestoreOptimizerHints(hints), comment) - } -} - -func TestIndexMergeHint(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=2") - - var input []string - var output []struct { - SQL string - Best string - HasWarn bool - Hints string - } - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - ctx := context.Background() - p := parser.New() - is := infoschema.MockInfoSchema([]*model.TableInfo{core.MockSignedTable(), core.MockUnsignedTable()}) - - for i, test := range input { - comment := fmt.Sprintf("case:%v sql:%s", i, test) - tk.Session().GetSessionVars().StmtCtx.SetWarnings(nil) - stmt, err := p.ParseOneStmt(test, "", "") - require.NoError(t, err, comment) - sctx := tk.Session() - err = executor.ResetContextOfStmt(sctx, stmt) - require.NoError(t, err) - p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) - require.NoError(t, err) + for i, test := range input { + comment := fmt.Sprintf("case:%v sql:%s", i, test) + tk.Session().GetSessionVars().StmtCtx.SetWarnings(nil) + stmt, err := p.ParseOneStmt(test, "", "") + require.NoError(t, err, comment) + sctx := tk.Session() + err = executor.ResetContextOfStmt(sctx, stmt) + require.NoError(t, err) + p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) + require.NoError(t, err) testdata.OnRecord(func() { output[i].SQL = test output[i].Best = core.ToString(p) @@ -1511,382 +1089,89 @@ func TestInlineProjection(t *testing.T) { output[i].Plan = core.ToString(p) output[i].Hints = hint.RestoreOptimizerHints(core.GenHintsFromPhysicalPlan(p)) }) - require.Equal(t, output[i].Plan, core.ToString(p), comment) - hints := core.GenHintsFromPhysicalPlan(p) - - // test the new genHints code - flat := core.FlattenPhysicalPlan(p, false) - newHints := core.GenHintsFromFlatPlan(flat) - assertSameHints(t, hints, newHints) - - require.Equal(t, output[i].Hints, hint.RestoreOptimizerHints(hints), comment) - } -} - -func TestIndexJoinHint(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 test.t1, test.t2, test.t;`) - tk.MustExec(`create table test.t1(a bigint, b bigint, index idx_a(a), index idx_b(b));`) - tk.MustExec(`create table test.t2(a bigint, b bigint, index idx_a(a), index idx_b(b));`) - tk.MustExec("CREATE TABLE `t` ( `a` bigint(20) NOT NULL, `b` tinyint(1) DEFAULT NULL, `c` datetime DEFAULT NULL, `d` int(10) unsigned DEFAULT NULL, `e` varchar(20) DEFAULT NULL, `f` double DEFAULT NULL, `g` decimal(30,5) DEFAULT NULL, `h` float DEFAULT NULL, `i` date DEFAULT NULL, `j` timestamp NULL DEFAULT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`), KEY `c` (`c`,`d`,`e`), KEY `f` (`f`), KEY `g` (`g`,`h`), KEY `g_2` (`g`), UNIQUE KEY `g_3` (`g`), KEY `i` (`i`) );") - - var input []string - var output []struct { - SQL string - Plan string - } - - is := domain.GetDomain(tk.Session()).InfoSchema() - p := parser.New() - ctx := context.Background() - - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - comment := fmt.Sprintf("case:%v sql: %s", i, tt) - stmt, err := p.ParseOneStmt(tt, "", "") - require.NoError(t, err, comment) - p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) - require.NoError(t, err, comment) - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = core.ToString(p) - }) - require.Equal(t, output[i].Plan, core.ToString(p), comment) - } -} - -func TestNominalSort(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - var input []string - var output []struct { - SQL string - Plan []string - Result []string - } - tk.MustExec("create table t (a int, b int, index idx_a(a), index idx_b(b))") - tk.MustExec("insert into t values(1, 1)") - tk.MustExec("insert into t values(1, 2)") - tk.MustExec("insert into t values(2, 4)") - tk.MustExec("insert into t values(3, 5)") - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Check(testkit.Rows(output[i].Result...)) - } -} - -func TestHintFromDiffDatabase(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists test.t1`) - tk.MustExec(`create table test.t1(a bigint, index idx_a(a));`) - tk.MustExec(`create table test.t2(a bigint, index idx_a(a));`) - tk.MustExec("drop database if exists test2") - tk.MustExec("create database test2") - tk.MustExec("use test2") - - var input []string - var output []struct { - SQL string - Plan string - } - is := domain.GetDomain(tk.Session()).InfoSchema() - p := parser.New() - ctx := context.Background() - - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - for i, tt := range input { - comment := fmt.Sprintf("case:%v sql: %s", i, tt) - stmt, err := p.ParseOneStmt(tt, "", "") - require.NoError(t, err, comment) - p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) - require.NoError(t, err, comment) - testdata.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = core.ToString(p) - }) - require.Equal(t, output[i].Plan, core.ToString(p), comment) - } -} - -func TestNthPlanHintWithExplain(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`drop table if exists test.tt`) - tk.MustExec(`create table test.tt (a int,b int, index(a), index(b));`) - tk.MustExec("insert into tt values (1, 1), (2, 2), (3, 4)") - tk.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`) - - var input []string - var output []struct { - SQL string - Plan []string - } - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - } - - // This assertion makes sure a query with or without nth_plan() hint output exactly the same plan(including plan ID). - // The query below is the same as queries in the testdata except for nth_plan() hint. - // Currently, its output is the same as the second test case in the testdata, which is `output[1]`. If this doesn't - // hold in the future, you may need to modify this. - tk.MustQuery("explain format = 'brief' select * from test.tt where a=1 and b=1").Check(testkit.Rows(output[1].Plan...)) -} - -func TestEnumIndex(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - 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(e enum('c','b','a',''), index idx(e))") - tk.MustExec("insert ignore into t values(0),(1),(2),(3),(4);") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - }) - tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...)) - } -} - -func TestIssue27233(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("CREATE TABLE `PK_S_MULTI_31` (\n `COL1` tinyint(45) NOT NULL,\n `COL2` tinyint(45) NOT NULL,\n PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("insert into PK_S_MULTI_31 values(122,100),(124,-22),(124,34),(127,103);") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - }) - tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...)) - } -} - -func TestSelectionPartialPushDown(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - 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 as (a+1) virtual)") - tk.MustExec("create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a))") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows()) - }) - tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) + require.Equal(t, output[i].Plan, core.ToString(p), comment) + hints := core.GenHintsFromPhysicalPlan(p) + + // test the new genHints code + flat := core.FlattenPhysicalPlan(p, false) + newHints := core.GenHintsFromFlatPlan(flat) + assertSameHints(t, hints, newHints) + + require.Equal(t, output[i].Hints, hint.RestoreOptimizerHints(hints), comment) } } -func TestIssue28316(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) +func TestIndexJoinHint(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("set tidb_cost_model_version=2") + tk.MustExec(`drop table if exists test.t1, test.t2, test.t;`) + tk.MustExec(`create table test.t1(a bigint, b bigint, index idx_a(a), index idx_b(b));`) + tk.MustExec(`create table test.t2(a bigint, b bigint, index idx_a(a), index idx_b(b));`) + tk.MustExec("CREATE TABLE `t` ( `a` bigint(20) NOT NULL, `b` tinyint(1) DEFAULT NULL, `c` datetime DEFAULT NULL, `d` int(10) unsigned DEFAULT NULL, `e` varchar(20) DEFAULT NULL, `f` double DEFAULT NULL, `g` decimal(30,5) DEFAULT NULL, `h` float DEFAULT NULL, `i` date DEFAULT NULL, `j` timestamp NULL DEFAULT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`), KEY `c` (`c`,`d`,`e`), KEY `f` (`f`), KEY `g` (`g`,`h`), KEY `g_2` (`g`), UNIQUE KEY `g_3` (`g`), KEY `i` (`i`) );") - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows()) - }) - tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) + var input []string + var output []struct { + SQL string + Plan string } -} -func TestSkewDistinctAgg(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - } - ) + is := domain.GetDomain(tk.Session()).InfoSchema() + p := parser.New() + ctx := context.Background() + planSuiteData := GetPlanSuiteData() planSuiteData.LoadTestCases(t, &input, &output) - 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(11), `b` int(11), `c` int(11), `d` date)") - tk.MustExec("insert into t (a,b,c,d) value(1,4,5,'2019-06-01')") - tk.MustExec("insert into t (a,b,c,d) value(2,null,1,'2019-07-01')") - tk.MustExec("insert into t (a,b,c,d) value(3,4,5,'2019-08-01')") - tk.MustExec("insert into t (a,b,c,d) value(3,6,2,'2019-09-01')") - tk.MustExec("insert into t (a,b,c,d) value(10,4,null,'2020-06-01')") - tk.MustExec("insert into t (a,b,c,d) value(20,null,1,'2020-07-01')") - tk.MustExec("insert into t (a,b,c,d) value(30,4,5,'2020-08-01')") - tk.MustExec("insert into t (a,b,c,d) value(30,6,5,'2020-09-01')") - tk.MustQuery("select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) " + - "from t group by date_format(d,'%Y') order by df;").Check( - testkit.Rows("2019 9 3 3", "2020 90 3 2")) - tk.MustExec("set @@tidb_opt_skew_distinct_agg=1") - tk.MustQuery("select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) " + - "from t group by date_format(d,'%Y') order by df;").Check( - testkit.Rows("2019 9 3 3", "2020 90 3 2")) - tk.MustQuery("select count(distinct b), sum(c) from t group by a order by 1,2;").Check( - testkit.Rows("0 1", "0 1", "1 ", "1 5", "2 7", "2 10")) - tk.MustQuery("select count(distinct b) from t group by date_format(d,'%Y') order by 1;").Check( - testkit.Rows("2", "2")) - tk.MustQuery("select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y') order by 1,2,3;").Check( - testkit.Rows("4 2 6", "4 2 6")) - tk.MustQuery("select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y'),c order by 1,2,3;").Check( - testkit.Rows("1 0 ", "1 0 ", "1 1 4", "1 1 6", "2 1 4", "2 2 6")) - tk.MustQuery("select avg(distinct b), count(a), sum(b) from t group by date_format(d,'%Y'),c order by 1,2,3;").Check( - testkit.Rows(" 1 ", " 1 ", "4.0000 1 4", "4.0000 2 8", "5.0000 2 10", "6.0000 1 6")) - - for i, ts := range input { + for i, tt := range input { + comment := fmt.Sprintf("case:%v sql: %s", i, tt) + stmt, err := p.ParseOneStmt(tt, "", "") + require.NoError(t, err, comment) + p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) + require.NoError(t, err, comment) testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief' " + ts).Rows()) + output[i].SQL = tt + output[i].Plan = core.ToString(p) }) - tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) + require.Equal(t, output[i].Plan, core.ToString(p), comment) } } -func TestHJBuildAndProbeHint(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - Warning []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) +func TestHintFromDiffDatabase(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 t1, t2, t3") - tk.MustExec("create table t1(a int primary key, b int not null)") - tk.MustExec("create table t2(a int primary key, b int not null)") - tk.MustExec("create table t3(a int primary key, b int not null)") - tk.MustExec("insert into t1 values(1,1),(2,2)") - tk.MustExec("insert into t2 values(1,1),(2,1)") - tk.MustExec("insert into t3 values(1,1),(2,1)") + tk.MustExec(`drop table if exists test.t1`) + tk.MustExec(`create table test.t1(a bigint, index idx_a(a));`) + tk.MustExec(`create table test.t2(a bigint, index idx_a(a));`) + tk.MustExec("drop database if exists test2") + tk.MustExec("create database test2") + tk.MustExec("use test2") - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - output[i].Warning = testdata.ConvertRowsToStrings(tk.MustQuery("show warnings").Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...)) - tk.MustQuery("show warnings").Check(testkit.Rows(output[i].Warning...)) + var input []string + var output []struct { + SQL string + Plan string } -} + is := domain.GetDomain(tk.Session()).InfoSchema() + p := parser.New() + ctx := context.Background() -func TestHJBuildAndProbeHint4StaticPartitionTable(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - Warning []string - } - ) planSuiteData := GetPlanSuiteData() planSuiteData.LoadTestCases(t, &input, &output) - 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 t1, t2, t3") - tk.MustExec(`create table t1(a int, b int) partition by hash(a) partitions 4`) - tk.MustExec(`create table t2(a int, b int) partition by hash(a) partitions 5`) - tk.MustExec(`create table t3(a int, b int) partition by hash(b) partitions 3`) - tk.MustExec("insert into t1 values(1,1),(2,2)") - tk.MustExec("insert into t2 values(1,1),(2,1)") - tk.MustExec("insert into t3 values(1,1),(2,1)") - tk.MustExec(`set @@tidb_partition_prune_mode="static"`) - - for i, ts := range input { + for i, tt := range input { + comment := fmt.Sprintf("case:%v sql: %s", i, tt) + stmt, err := p.ParseOneStmt(tt, "", "") + require.NoError(t, err, comment) + p, _, err := planner.Optimize(ctx, tk.Session(), stmt, is) + require.NoError(t, err, comment) testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - output[i].Warning = testdata.ConvertRowsToStrings(tk.MustQuery("show warnings").Rows()) + output[i].SQL = tt + output[i].Plan = core.ToString(p) }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...)) + require.Equal(t, output[i].Plan, core.ToString(p), comment) } } @@ -2023,77 +1308,6 @@ func TestMPPSinglePartitionType(t *testing.T) { } } -func TestNoDecorrelateHint(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Result []string - Warning []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - 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 t1, t2") - tk.MustExec("create table t1(a int, b int)") - tk.MustExec("create table t2(a int primary key, b int)") - tk.MustExec("create table t3(a int, b int)") - tk.MustExec("insert into t1 values(1,1),(2,2)") - tk.MustExec("insert into t2 values(1,1),(2,1)") - tk.MustExec("insert into t3 values(1,1),(2,1)") - - tk.MustExec("create table ta(id int, code int, name varchar(20), index idx_ta_id(id),index idx_ta_name(name), index idx_ta_code(code))") - tk.MustExec("create table tb(id int, code int, name varchar(20), index idx_tb_id(id),index idx_tb_name(name))") - tk.MustExec("create table tc(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name))") - tk.MustExec("create table td(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name))") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows()) - output[i].Warning = testdata.ConvertRowsToStrings(tk.MustQuery("show warnings").Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...)) - tk.MustQuery("show warnings").Check(testkit.Rows(output[i].Warning...)) - } -} - -func TestCountStarForTikv(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Warning []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=1") - tk.MustExec("create table t (a int(11) not null, b varchar(10) not null, c date not null, d char(1) not null, e bigint not null, f datetime not null, g bool not null, h bool )") - tk.MustExec("create table t_pick_row_id (a char(20) not null)") - - // tikv - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - } -} - func TestCountStarForTiFlash(t *testing.T) { var ( input []string @@ -2209,66 +1423,3 @@ func TestHashAggPushdownToTiFlashCompute(t *testing.T) { tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) } } - -func TestIndexMergeOrderPushDown(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Warning []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=1") - tk.MustExec("create table t (a int, b int, c int, index idx(a, c), index idx2(b, c))") - tk.MustExec("create table tcommon (a int, b int, c int, primary key(a, c), index idx2(b, c))") - tk.MustExec("create table thash(a int, b int, c int, index idx_ac(a, c), index idx_bc(b, c)) PARTITION BY HASH (`a`) PARTITIONS 4") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows()) - output[i].Warning = testdata.ConvertRowsToStrings(tk.MustQuery("show warnings").Rows()) - }) - tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery("show warnings").Check(testkit.Rows(output[i].Warning...)) - } -} - -func TestIndexMergeSinkLimit(t *testing.T) { - var ( - input []string - output []struct { - SQL string - Plan []string - Warning []string - } - ) - planSuiteData := GetPlanSuiteData() - planSuiteData.LoadTestCases(t, &input, &output) - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=1") - tk.MustExec(" CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ") - tk.MustExec("insert into t2 values(1,2,1),(2,1,1),(3,3,1)") - tk.MustExec("create table t(a int, j json, index kj((cast(j as signed array))))") - tk.MustExec("insert into t values(1, '[1,2,3]')") - - for i, ts := range input { - testdata.OnRecord(func() { - output[i].SQL = ts - output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery(ts).Rows()) - output[i].Warning = testdata.ConvertRowsToStrings(tk.MustQuery("show warnings").Rows()) - }) - tk.MustQuery(ts).Check(testkit.Rows(output[i].Plan...)) - tk.MustQuery("show warnings").Check(testkit.Rows(output[i].Warning...)) - } -} diff --git a/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json b/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json index c9602ec23e885..76e17bcd71c12 100644 --- a/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json +++ b/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json @@ -447,41 +447,6 @@ "select /*+ HASH_JOIN(@sel_2 t1@sel_2, t2@sel_2), MERGE_JOIN(@sel_1 t1@sel_1, t2@sel_1) */ * from (select t1.a, t1.b from t t1, t t2 where t1.a = t2.a) t1, t t2 where t1.b = t2.b" ] }, - { - "name": "TestIndexJoinUnionScan", - "cases": [ - [ - "insert into t values(1, 1)", - // Test Index Join + UnionScan + TableScan. - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a" - ], - [ - "insert into t values(1, 1)", - // Test Index Join + UnionScan + DoubleRead. - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.b" - ], - [ - "insert into t values(1, 1)", - // Test Index Join + UnionScan + IndexScan. - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ t1.a , t2.b from t t1, t t2 where t1.a = t2.b" - ], - [ - "insert into tt values(1)", - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from tt t1, tt t2 where t1.a = t2.a" - ] - ] - }, - { - "name": "TestMergeJoinUnionScan", - "cases": [ - [ - "insert into t2 values (11, 'amazing merkle')", - "insert into t2 values (12, 'amazing merkle')", - // Test Merge Join + UnionScan + TableScan. - "explain format = 'brief' select /*+ MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_int = t2.c_int order by t1.c_int, t2.c_str;" - ] - ] - }, { "name": "TestSemiJoinToInner", "cases": [ @@ -517,86 +482,6 @@ "select /*+ LIMIT_TO_COP() */ a from tn where a > 10 limit 1" ] }, - { - "name": "TestCTEMergeHint", - "cases": [ - "with cte as (select /*+ MERGE() */ * from tc where tc.a < 60) select * from cte where cte.a <18", - "with cte as (select * from tc where tc.a < 60) select * from cte c1, cte c2 where c1.a <18", - "with cte as (select /*+ MERGE() */ * from v) select * from cte", - "WITH cte1 AS (SELECT /*+ MERGE() */ a FROM tc), cte2 AS (SELECT /*+ MERGE()*/ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c;", - "WITH cte1 AS (SELECT a FROM tc), cte2 AS (SELECT /*+ MERGE() */ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c;", - "with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1;", - "WITH cte1 AS (SELECT * FROM t1) SELECT /*+ MERGE() */ * FROM cte1 join t2 on cte1.a = t2.b;", - "with cte1 as (with cte3 as (select /*+ MERGE() */ * from t1),cte4 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3,cte4) ,cte2 as (select /*+ MERGE() */ * from t3) select * from cte1,cte2;", - "with cte1 as (select * from tc), cte2 as (with cte3 as (select /*+ MERGE() */ * from te) ,cte4 as (select * from tc) select * from cte3,cte4) select * from cte2;", - "with cte1 as (with cte2 as (select /*+ MERGE() */ * from te) ,cte3 as (select /*+ MERGE() */ * from tc) select /*+ MERGE() */ * from cte2,cte3) select * from cte1;", - "with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2;", - "with cte1 as (select /*+ MERGE() */ * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2;", - "with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select /*+ MERGE() */ * from t4) select * from cte3,cte4) select * from cte1,cte2;", - "with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select /*+ MERGE() */ * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2;", - "with cte2 as (with cte4 as (select * from tc) select * from te, cte4) select * from cte2;", - "with cte2 as (with cte4 as (select /*+ merge() */ * from tc) select * from te, cte4) select * from cte2;", - "with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select /*+ MERGE() */ * from t1) ttt) select * from cte1;", - "with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select /*+ MERGE() */ * from t3) ttw;", - "with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select * from t3) ttw;" - ] - }, - { - "name": "TestForceInlineCTE", - "cases": [ - "set tidb_opt_force_inline_cte=1; -- enable force inline CTE", - "with cte as (select * from t) select * from cte; -- inline", - "with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline", - "with cte as (select * from t) select * from cte cte1, cte cte2; -- inline CTEs is used by multi consumers", - "with cte1 as (select * from t), cte2 as (select a from cte1 group by a) select * from cte1, cte2; -- multi inline CTEs", - "with recursive cte1(c1) as (select 1 union select c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined", - "with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'", - "with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'", - "with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'", - "set tidb_opt_force_inline_cte=0; -- disable force inline CTE", - "with cte as (select * from t) select * from cte; -- inlined by single consumer", - "with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline, merge hint override session variable", - "with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined", - "with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'", - "with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'", - "with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'" - ] - }, - { - "name": "TestSingleConsumerCTE", - "cases": [ - "with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 1) select * from cte1; -- non-recursive limit, inline cte1", - "with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 100 offset 100) select * from cte1; -- non-recursive limit, inline cte1", - "with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 0 offset 0) select * from cte1; -- non-recursive limit, inline cte1", - "with cte1 as (select 1), cte2 as (select 2) select * from cte1 union (with cte2 as (select 3) select * from cte2 union all select * from cte2) -- inline cte1, not inline cte2", - "with base1 as (WITH RECURSIVE cte(a) AS (with tmp as (select 1 as a) SELECT a from tmp UNION SELECT a+1 FROM cte) SELECT * FROM cte) select * from base1; -- issue #43318", - "with cte as (select 1) select * from cte; -- inline cte", - "with cte1 as (select 1), cte2 as (select 2) select * from cte1 union select * from cte2; -- inline cte1, cte2", - "with cte as (select 1) select * from cte union select * from cte; -- cannot be inlined", - "with cte as (with cte as (select 1) select * from cte) select * from cte; -- inline nested cte", - "with cte as (with cte as (select 1) select * from cte) select * from cte a, cte b; -- inline inner cte, cannot be inlined outer cte", - "with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte1, cte2; -- inline cte2, cte3, cannot be inlined cte1", - "with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte2; -- inline cte1, cte2, cte3", - "with cte1 as (select 1), cte2 as (select * from cte1) select * from cte2 a, cte2 b; -- inline cte1, cannot be inlined cte2", - "with recursive cte(a) as (select 1 union select a from cte) select * from cte; -- recursive cte cannot be inlined", - "with x as (select * from (select a from t for update) s) select * from x where a = 1;", - "set tidb_opt_force_inline_cte=1; -- enable force inline CTE", - "with cte as (select 1) select * from cte union select * from cte; -- force inline cte while multi-consumer", - "set tidb_opt_force_inline_cte=0; -- disable force inline CTE", - "with cte as (select 1) select /*+ MERGE() */ * from cte union select * from cte; -- firstly inline cte, secondly cannot be inlined", - "with a as (select 8 as id from dual),maxa as (select max(id) as max_id from a),b as (with recursive temp as (select 1 as lvl from dual union all select lvl+1 from temp, maxa where lvl < max_id)select * from temp) select * from b; -- issue #47711, maxa cannot be inlined because it contains agg and in the recursive part of cte temp", - "with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select 1 as res from t1 union all select res+1 from tmp,b where res+1 < bb) select * from tmp) select * from c; -- inline a, cannot be inline b because b indirectly contains agg and in the recursive part of cte tmp", - "with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c" - ] - }, - { - "name": "TestPushdownDistinctEnableAggPushDownDisable", - "cases": [ - "select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt;", - "select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t;", - "select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ;" - ] - }, { "name": "TestGroupConcatOrderby", "cases": [ @@ -606,21 +491,6 @@ "select /*+ agg_to_cop */ group_concat(distinct name order by name desc) from ptest;" ] }, - { - "name": "TestNominalSort", - "cases": [ - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3", - "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a" - ] - }, { "name": "TestInlineProjection", "cases":[ @@ -642,89 +512,6 @@ "select /*+ inl_hash_join(test.t1) */ * from test.t2 join test.t1 on test.t2.a = test.t1.a" ] }, - { - "name": "TestNthPlanHintWithExplain", - "cases": [ - "select /*+nth_plan(1)*/ * from test.tt where a=1 and b=1", - "select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1;", - "select /*+nth_plan(3)*/ * from test.tt where a=1 and b=1;", - "select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1;", - "select * from test.tt where a=1 and b=1" - ] - }, - { - "name": "TestINMJHint", - "cases": [ - "select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b" - ] - }, - { - "name": "TestEliminateMaxOneRow", - "cases": [ - "select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a);", - "select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null);", - "select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a);" - ] - }, - { - "name": "TestEnumIndex", - "cases": [ - "select e from t where e = 'b'", - "select e from t where e != 'b'", - "select e from t where e > 'b'", - "select e from t where e >= 'b'", - "select e from t where e < 'b'", - "select e from t where e <= 'b'", - "select e from t where e = 2", - "select e from t where e != 2", - "select e from t where e > 2", - "select e from t where e >= 2", - "select e from t where e < 2", - "select e from t where e <= 2", - - // Out of range - "select e from t where e > ''", - "select e from t where e > 'd'", - "select e from t where e > -1", - "select e from t where e > 5", - - // zero-value - "select e from t where e = ''", - "select e from t where e != ''" - ] - }, - { - "name": "TestIssue27233", - "cases": [ - "SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2;" - ] - }, - { - "name": "TestSelectionPartialPushDown", - "cases": [ - // Make sure row_count(tikv_selection) == row_count(table_reader) and row_count(table_reader) > row_count(tidb_selection) - "select * from t1 where a > 1 and b > 1", - // Make sure row_count(tikv_selection) == row_count(index_lookup) and row_count(index_lookup) > row_count(tidb_selection) - "select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1" - ] - }, - { - "name": "TestIssue28316", - "cases": [ - "select * from t where t.a < 3 and t.a < 3" - ] - }, - { - "name": "TestSkewDistinctAgg", - "cases": [ - "select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y')", - "select d, a, count(*), count(b), count(distinct c) from t group by d, a", - "select d, sum(a), count(b), avg(distinct c) from t group by d" - ] - }, { "name": "TestMPPSinglePartitionType", "cases": [ @@ -775,153 +562,6 @@ "select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 where t1.a > t.a)" ] }, - { - "name": "TestHJBuildAndProbeHint", - "cases": [ - // Test for different join type - // inner join - "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - "select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - // outer join - "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - - // straight_join - "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - - // cross join - "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - - // semi join - "select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - "select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - "select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - "select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - - // anti semi join - "select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - "select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - "select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - "select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - - // left outer semi join - "select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1", - "select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1", - "select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1", - "select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1", - - // anti left outer semi join - "select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1", - "select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1", - "select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1", - "select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1", - - // Hint scope - // The same table name appear in the hint - "select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - // The undefined table name appear in the hint - "select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - // The alias appear in the hint - "select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b", - "select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b", - - // The hints are conflict - "select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - // Combine with other hints - "select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - - "select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - - "select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - "select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - "select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - "select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - - "SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - "SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - - "SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);" - ] - }, - { - "name": "TestHJBuildAndProbeHint4StaticPartitionTable", - "cases": [ - "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b" - ] - }, { "name": "TestHJBuildAndProbeHint4DynamicPartitionTable", "cases": [ @@ -940,74 +580,6 @@ "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b" ] }, - { - "name": "TestNoDecorrelateHint", - "cases": [ - "select /*+ no_decorrelate() */ * from t1", - "select * from t1, (select /*+ no_decorrelate() */ * from t2) n", - "select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n", - "select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3", - - "select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b)", - "select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b)", - - "select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b)", - "select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b)", - - "select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1", - "select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1", - - "select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1", - "select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1", - - "select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1", - "select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1", - - "select t1.a, t1.b not in (select t3.b from t3) from t1", - "select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1", - - "select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1", - "select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1", - - "select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1", - "select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1", - - "select (select count(t3.a) from t3 where t3.b = t1.b) from t1;", - "select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1;", - - "SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - "SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - - "SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - "SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - "SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - "SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - - "SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900", - "SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900", - - "SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100", - "SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100", - "SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100" - - ] - }, - { - "name": "TestCountStarForTikv", - "cases": [ - "select count(*) from t", - "select count(1), count(3.1415), count(0), count(null) from t -- shouldn't be rewritten", - "select count(*) from t where a=1", - "select count(*) from t_pick_row_id", - "select t.b, t.c from (select count(*) as c from t) a, t where a.c=t.a -- shouldn't be rewritten", - "select * from t outTable where outTable.a > (select count(*) from t inn where inn.a = outTable.b) -- shouldn't be rewritten", - "select count(*) from t t1, t t2 where t1.a=t2.e -- shouldn't be rewritten", - "select count(distinct 1) from t -- shouldn't be rewritten", - "select count(1), count(a), count(b) from t -- shouldn't be rewritten", - "select a, count(*) from t group by a -- shouldn't be rewritten", - "select sum(a) from t -- sum shouldn't be rewritten" - ] - }, { "name": "TestCountStarForTiFlash", "cases": [ @@ -1031,40 +603,5 @@ "select /*+ agg_to_cop() hash_agg() */ count(1) from tbl_15 ;", "select /*+ agg_to_cop() stream_agg() */ avg( tbl_16.col_100 ) as r0 from tbl_16 where tbl_16.col_100 in ( 10672141 ) or tbl_16.col_104 in ( 'yfEG1t!*b' ,'C1*bqx_qyO' ,'vQ^yUpKHr&j#~' ) group by tbl_16.col_100 order by r0 limit 20 ;" ] - }, - { - "name": "TestIndexMergeOrderPushDown", - "cases": [ - "select * from t where a = 1 or b = 1 order by c limit 2", - "select * from t where a = 1 or b in (1, 2, 3) order by c limit 2", - "select * from t where a in (1, 2, 3) or b = 1 order by c limit 2", - "select * from t where a in (1, 2, 3) or b in (1, 2, 3) order by c limit 2", - "select * from t where (a = 1 and c = 2) or (b = 1) order by c limit 2", - "select * from t where (a = 1 and c = 2) or b in (1, 2, 3) order by c limit 2", - "select * from t where (a = 1 and c = 2) or (b in (1, 2, 3) and c = 3) order by c limit 2", - "select * from t where (a = 1 or b = 2) and c = 3 order by c limit 2", - "select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by c limit 2", - "select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by b limit 2", - "select * from tcommon where a = 1 or b = 1 order by c limit 2", - "select * from tcommon where (a = 1 and c = 2) or (b = 1) order by c limit 2", - "select * from thash use index(idx_ac, idx_bc) where a = 1 or b = 1 order by c limit 2" - ] - }, - { - "name": "TestIndexMergeSinkLimit", - "cases": [ - "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; -- test sink limit to table side of union index merge case, because of table side selection", - "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; -- test sink limit to table side of intersection index merge case, because of table side selection", - "select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2", - "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; -- test sink limit to index side of union index merge case, because of table side is pure table scan", - "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; -- test sink limit to table side of intersection index merge case, because of intersection case special", - "select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2", - "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; -- index merge union case, sink limit into index side and embed another one inside index merge reader", - "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; -- index merge intersection case, embedding limit into index merge reader", - "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down", - "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; -- index merge union case, sink limit to table side, because selection exists on table side", - "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; -- index merge intersection case, sink limit to table side because selection exists on table side", - "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down" - ] } ] diff --git a/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json b/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json index 12aa76b84c9d9..85743605cc0b7 100644 --- a/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json +++ b/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json @@ -2539,104 +2539,6 @@ } ] }, - { - "Name": "TestIndexJoinUnionScan", - "Cases": [ - { - "SQL": [ - "insert into t values(1, 1)", - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a" - ], - "Plan": [ - "IndexJoin 12500.00 root inner join, inner:UnionScan, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a)", - "├─UnionScan(Build) 10000.00 root ", - "│ └─TableReader 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─UnionScan(Probe) 10000.00 root ", - " └─TableReader 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [test.t.a], keep order:false, stats:pseudo" - ] - }, - { - "SQL": [ - "insert into t values(1, 1)", - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.b" - ], - "Plan": [ - "Projection 12487.50 root test.t.a, test.t.b, test.t.a, test.t.b", - "└─HashJoin 12487.50 root inner join, equal:[eq(test.t.b, test.t.a)]", - " ├─UnionScan(Build) 9990.00 root not(isnull(test.t.b))", - " │ └─TableReader 9990.00 root data:Selection", - " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " └─UnionScan(Probe) 10000.00 root ", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ] - }, - { - "SQL": [ - "insert into t values(1, 1)", - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ t1.a , t2.b from t t1, t t2 where t1.a = t2.b" - ], - "Plan": [ - "Projection 12487.50 root test.t.a, test.t.b", - "└─HashJoin 12487.50 root inner join, equal:[eq(test.t.b, test.t.a)]", - " ├─UnionScan(Build) 10000.00 root ", - " │ └─TableReader 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─UnionScan(Probe) 9990.00 root not(isnull(test.t.b))", - " └─TableReader 9990.00 root data:Selection", - " └─Selection 9990.00 cop[tikv] not(isnull(test.t.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ] - }, - { - "SQL": [ - "insert into tt values(1)", - "explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from tt t1, tt t2 where t1.a = t2.a" - ], - "Plan": [ - "HashJoin 25000.00 root inner join, equal:[eq(test.tt.a, test.tt.a)]", - "├─PartitionUnion(Build) 20000.00 root ", - "│ ├─UnionScan 10000.00 root ", - "│ │ └─TableReader 10000.00 root data:TableFullScan", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo", - "│ └─UnionScan 10000.00 root ", - "│ └─TableReader 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo", - "└─PartitionUnion(Probe) 20000.00 root ", - " ├─UnionScan 10000.00 root ", - " │ └─TableReader 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo", - " └─UnionScan 10000.00 root ", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestMergeJoinUnionScan", - "Cases": [ - { - "SQL": [ - "insert into t2 values (11, 'amazing merkle')", - "insert into t2 values (12, 'amazing merkle')", - "explain format = 'brief' select /*+ MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_int = t2.c_int order by t1.c_int, t2.c_str;" - ], - "Plan": [ - "Sort 12500.00 root test.t1.c_int, test.t2.c_str", - "└─MergeJoin 12500.00 root inner join, left key:test.t1.c_int, right key:test.t2.c_int", - " ├─UnionScan(Build) 10000.00 root ", - " │ └─TableReader 10000.00 root data:TableFullScan", - " │ └─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" - ] - } - ] - }, { "Name": "TestSemiJoinToInner", "Cases": [ @@ -2697,4722 +2599,778 @@ ] }, { - "Name": "TestLimitToCopHint", + "Name": "TestGroupConcatOrderby", "Cases": [ { - "SQL": "select /*+ LIMIT_TO_COP() */ * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1", + "SQL": "select /*+ agg_to_cop */ group_concat(name ORDER BY name desc SEPARATOR '++'), group_concat(id ORDER BY name desc, id asc SEPARATOR '--') from test;", "Plan": [ - "TopN 0.83 root test.tn.d, offset:0, count:1", - "└─IndexReader 0.83 root index:TopN", - " └─TopN 0.83 cop[tikv] test.tn.d, offset:0, count:1", - " └─Selection 0.83 cop[tikv] gt(test.tn.c, 50)", - " └─IndexRangeScan 2.50 cop[tikv] table:tn, index:a(a, b, c, d) range:(1 10,1 20), keep order:false, stats:pseudo" + "HashAgg 1.00 root funcs:group_concat(Column#6 order by Column#7 desc separator \"++\")->Column#4, funcs:group_concat(Column#8 order by Column#9 desc, Column#10 separator \"--\")->Column#5", + "└─Projection 10000.00 root cast(test.test.name, var_string(20))->Column#6, test.test.name->Column#7, cast(test.test.id, var_string(20))->Column#8, test.test.name->Column#9, test.test.id->Column#10", + " └─TableReader 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" ], - "Warning": null + "Result": [ + "500++200++30++20++20++10 3--3--1--1--2--1" + ] }, { - "SQL": "select * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1", + "SQL": "select /*+ agg_to_cop */ group_concat(name ORDER BY name desc SEPARATOR '++'), group_concat(id ORDER BY name desc, id asc SEPARATOR '--') from ptest;", "Plan": [ - "TopN 0.83 root test.tn.d, offset:0, count:1", - "└─IndexReader 0.83 root index:TopN", - " └─TopN 0.83 cop[tikv] test.tn.d, offset:0, count:1", - " └─Selection 0.83 cop[tikv] gt(test.tn.c, 50)", - " └─IndexRangeScan 2.50 cop[tikv] table:tn, index:a(a, b, c, d) range:(1 10,1 20), keep order:false, stats:pseudo" + "HashAgg 1.00 root funcs:group_concat(Column#6 order by Column#7 desc separator \"++\")->Column#4, funcs:group_concat(Column#8 order by Column#9 desc, Column#10 separator \"--\")->Column#5", + "└─Projection 10000.00 root cast(test.ptest.name, var_string(20))->Column#6, test.ptest.name->Column#7, cast(test.ptest.id, var_string(20))->Column#8, test.ptest.name->Column#9, test.ptest.id->Column#10", + " └─TableReader 10000.00 root partition:all data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:ptest keep order:false, stats:pseudo" ], - "Warning": null + "Result": [ + "500++200++30++20++20++10 3--3--1--1--2--1" + ] }, { - "SQL": "select /*+ LIMIT_TO_COP() */ a from tn where a div 2 order by a limit 1", + "SQL": "select /*+ agg_to_cop */ group_concat(distinct name order by name desc) from test;", "Plan": [ - "Limit 1.00 root offset:0, count:1", - "└─Selection 1.00 root intdiv(test.tn.a, 2)", - " └─IndexReader 1.00 root index:IndexFullScan", - " └─IndexFullScan 1.00 cop[tikv] table:tn, index:a(a, b, c, d) keep order:true, stats:pseudo" + "HashAgg 1.00 root funcs:group_concat(distinct Column#5 order by Column#6 desc separator \",\")->Column#4", + "└─Projection 10000.00 root cast(test.test.name, var_string(20))->Column#5, test.test.name->Column#6", + " └─TableReader 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" ], - "Warning": [ - "Scalar function 'intdiv'(signature: IntDivideInt, return type: bigint(20)) is not supported to push down to storage layer now.", - "[planner:1815]Optimizer Hint LIMIT_TO_COP is inapplicable" + "Result": [ + "500,200,30,20,10" ] }, { - "SQL": "select /*+ LIMIT_TO_COP() */ a from tn where a > 10 limit 1", + "SQL": "select /*+ agg_to_cop */ group_concat(distinct name order by name desc) from ptest;", "Plan": [ - "Limit 1.00 root offset:0, count:1", - "└─IndexReader 1.00 root index:Limit", - " └─Limit 1.00 cop[tikv] offset:0, count:1", - " └─IndexRangeScan 1.00 cop[tikv] table:tn, index:a(a, b, c, d) range:(10,+inf], keep order:false, stats:pseudo" + "HashAgg 1.00 root funcs:group_concat(distinct Column#5 order by Column#6 desc separator \",\")->Column#4", + "└─Projection 10000.00 root cast(test.ptest.name, var_string(20))->Column#5, test.ptest.name->Column#6", + " └─TableReader 10000.00 root partition:all data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:ptest keep order:false, stats:pseudo" ], - "Warning": null + "Result": [ + "500,200,30,20,10" + ] } ] }, { - "Name": "TestCTEMergeHint", + "Name": "TestInlineProjection", "Cases": [ { - "SQL": "with cte as (select /*+ MERGE() */ * from tc where tc.a < 60) select * from cte where cte.a <18", - "Plan": [ - "TableReader 4.00 root data:Selection", - "└─Selection 4.00 cop[tikv] lt(test.tc.a, 18), lt(test.tc.a, 60)", - " └─TableFullScan 7.00 cop[tikv] table:tc keep order:false" - ], - "Warning": null + "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1, t2 where t1.a = t2.a;", + "Plan": "LeftHashJoin{TableReader(Table(t1)->Sel([not(isnull(test.t1.a))]))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t1.a,test.t2.a)", + "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" }, { - "SQL": "with cte as (select * from tc where tc.a < 60) select * from cte c1, cte c2 where c1.a <18", - "Plan": [ - "Projection 39.20 root test.tc.a, test.tc.a", - "└─HashJoin 39.20 root CARTESIAN inner join", - " ├─Selection(Build) 5.60 root lt(test.tc.a, 18)", - " │ └─CTEFullScan 7.00 root CTE:cte AS c1 data:CTE_0", - " └─CTEFullScan(Probe) 7.00 root CTE:cte AS c2 data:CTE_0", - "CTE_0 7.00 root Non-Recursive CTE", - "└─TableReader(Seed Part) 7.00 root data:Selection", - " └─Selection 7.00 cop[tikv] lt(test.tc.a, 60), or(lt(test.tc.a, 18), 1)", - " └─TableFullScan 7.00 cop[tikv] table:tc keep order:false" - ], - "Warning": null + "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", + "Plan": "LeftHashJoin{TableReader(Table(t1)->Sel([not(isnull(test.t1.a))]))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t1.a,test.t2.a)", + "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" }, { - "SQL": "with cte as (select /*+ MERGE() */ * from v) select * from cte", - "Plan": [ - "TableReader 7.00 root data:TableFullScan", - "└─TableFullScan 7.00 cop[tikv] table:tc keep order:false" - ], - "Warning": null + "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 left outer join t2 on t1.a = t2.a;", + "Plan": "LeftHashJoin{TableReader(Table(t1))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t1.a,test.t2.a)", + "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" }, { - "SQL": "WITH cte1 AS (SELECT /*+ MERGE() */ a FROM tc), cte2 AS (SELECT /*+ MERGE()*/ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c;", - "Plan": [ - "HashJoin 7.00 root inner join, equal:[eq(test.tc.a, test.te.c)]", - "├─TableReader(Build) 7.00 root data:Selection", - "│ └─Selection 7.00 cop[tikv] not(isnull(test.te.c))", - "│ └─TableFullScan 7.00 cop[tikv] table:te keep order:false", - "└─TableReader(Probe) 7.00 root data:Selection", - " └─Selection 7.00 cop[tikv] not(isnull(test.tc.a))", - " └─TableFullScan 7.00 cop[tikv] table:tc keep order:false" - ], - "Warning": null + "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 right outer join t2 on t1.a = t2.a;", + "Plan": "RightHashJoin{TableReader(Table(t1)->Sel([not(isnull(test.t1.a))]))->TableReader(Table(t2))}(test.t1.a,test.t2.a)", + "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" }, { - "SQL": "WITH cte1 AS (SELECT a FROM tc), cte2 AS (SELECT /*+ MERGE() */ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c;", - "Plan": [ - "HashJoin 7.00 root inner join, equal:[eq(test.tc.a, test.te.c)]", - "├─TableReader(Build) 7.00 root data:Selection", - "│ └─Selection 7.00 cop[tikv] not(isnull(test.te.c))", - "│ └─TableFullScan 7.00 cop[tikv] table:te keep order:false", - "└─TableReader(Probe) 7.00 root data:Selection", - " └─Selection 7.00 cop[tikv] not(isnull(test.tc.a))", - " └─TableFullScan 7.00 cop[tikv] table:tc keep order:false" - ], - "Warning": null + "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a in (select t2.a from t2) from t1) x;", + "Plan": "LeftHashJoin{IndexReader(Index(t1.idx_a)[[NULL,+inf]])->IndexReader(Index(t2.idx_a)[[NULL,+inf]])}->Projection", + "Hints": "hash_join(@`sel_2` `test`.`t1`), use_index(@`sel_2` `test`.`t1` `idx_a`), no_order_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_3` `test`.`t2` `idx_a`), no_order_index(@`sel_3` `test`.`t2` `idx_a`)" }, { - "SQL": "with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1;", - "Plan": [ - "CTEFullScan 2.00 root CTE:cte1 data:CTE_0", - "CTE_0 2.00 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#2", - "│ └─TableDual 1.00 root rows:1", - "└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5", - " └─Selection 0.80 root lt(Column#3, 100)", - " └─CTETable 1.00 root Scan on CTE_0" - ], - "Warning": [ - "[planner:1815]Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte." - ] + "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a not in (select t2.a from t2) from t1) x;", + "Plan": "LeftHashJoin{IndexReader(Index(t1.idx_a)[[NULL,+inf]])->IndexReader(Index(t2.idx_a)[[NULL,+inf]])}->Projection", + "Hints": "hash_join(@`sel_2` `test`.`t1`), use_index(@`sel_2` `test`.`t1` `idx_a`), no_order_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_3` `test`.`t2` `idx_a`), no_order_index(@`sel_3` `test`.`t2` `idx_a`)" }, { - "SQL": "WITH cte1 AS (SELECT * FROM t1) SELECT /*+ MERGE() */ * FROM cte1 join t2 on cte1.a = t2.b;", - "Plan": [ - "HashJoin 7.00 root inner join, equal:[eq(test.t1.a, test.t2.b)]", - "├─TableReader(Build) 7.00 root data:Selection", - "│ └─Selection 7.00 cop[tikv] not(isnull(test.t2.b))", - "│ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false", - "└─TableReader(Probe) 7.00 root data:Selection", - " └─Selection 7.00 cop[tikv] not(isnull(test.t1.a))", - " └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false" - ], - "Warning": [ - "[planner:1815]Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE." - ] + "SQL": "select /*+ INL_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", + "Plan": "IndexJoin{IndexLookUp(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]), Table(t1))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t2.a,test.t1.a)", + "Hints": "inl_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), no_order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` )" }, { - "SQL": "with cte1 as (with cte3 as (select /*+ MERGE() */ * from t1),cte4 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3,cte4) ,cte2 as (select /*+ MERGE() */ * from t3) select * from cte1,cte2;", - "Plan": [ - "HashJoin 343.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false", - "└─HashJoin(Probe) 49.00 root CARTESIAN inner join", - " ├─TableReader(Build) 7.00 root data:TableFullScan", - " │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false", - " └─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false" - ], - "Warning": null + "SQL": "select /*+ INL_HASH_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", + "Plan": "IndexHashJoin{IndexLookUp(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]), Table(t1))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t2.a,test.t1.a)", + "Hints": "inl_hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), no_order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` )" }, { - "SQL": "with cte1 as (select * from tc), cte2 as (with cte3 as (select /*+ MERGE() */ * from te) ,cte4 as (select * from tc) select * from cte3,cte4) select * from cte2;", - "Plan": [ - "HashJoin 49.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false", - "└─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:te keep order:false" - ], - "Warning": null + "SQL": "select /*+ INL_MERGE_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", + "Plan": "IndexMergeJoin{IndexLookUp(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]), Table(t1))->Projection->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t2.a,test.t1.a)", + "Hints": "inl_merge_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` )" }, { - "SQL": "with cte1 as (with cte2 as (select /*+ MERGE() */ * from te) ,cte3 as (select /*+ MERGE() */ * from tc) select /*+ MERGE() */ * from cte2,cte3) select * from cte1;", - "Plan": [ - "HashJoin 49.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false", - "└─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:te keep order:false" - ], - "Warning": null - }, + "SQL": "select /*+ MERGE_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", + "Plan": "MergeInnerJoin{IndexLookUp(Index(t1.idx_a)[[-inf,+inf]], Table(t1))->Projection->IndexLookUp(Index(t2.idx_a)[[-inf,+inf]], Table(t2))->Projection}(test.t1.a,test.t2.a)", + "Hints": "merge_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` `idx_a`), order_index(@`sel_1` `test`.`t2` `idx_a`)" + } + ] + }, + { + "Name": "TestHintFromDiffDatabase", + "Cases": [ + { + "SQL": "select /*+ inl_hash_join(test.t1) */ * from test.t2 join test.t1 on test.t2.a = test.t1.a", + "Plan": "IndexHashJoin{IndexReader(Index(t2.idx_a)[[-inf,+inf]])->IndexReader(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]))}(test.t2.a,test.t1.a)" + } + ] + }, + { + "Name": "TestMPPSinglePartitionType", + "Cases": [ { - "SQL": "with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2;", + "SQL": "select * from employee where deptid>1", "Plan": [ - "HashJoin 2401.00 root CARTESIAN inner join", - "├─HashJoin(Build) 49.00 root CARTESIAN inner join", - "│ ├─TableReader(Build) 7.00 root data:TableFullScan", - "│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false", - "│ └─TableReader(Probe) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false", - "└─HashJoin(Probe) 49.00 root CARTESIAN inner join", - " ├─TableReader(Build) 7.00 root data:TableFullScan", - " │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false", - " └─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false" - ], - "Warning": null + "TableReader 3333.33 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 3333.33 mpp[tiflash] ExchangeType: PassThrough", + " └─Selection 3333.33 mpp[tiflash] gt(test.employee.deptid, 1)", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "with cte1 as (select /*+ MERGE() */ * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2;", + "SQL": "select deptid+5, empid*10 from employee where deptid>1", "Plan": [ - "HashJoin 2401.00 root CARTESIAN inner join", - "├─HashJoin(Build) 49.00 root CARTESIAN inner join", - "│ ├─TableReader(Build) 7.00 root data:TableFullScan", - "│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false", - "│ └─TableReader(Probe) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false", - "└─HashJoin(Probe) 49.00 root CARTESIAN inner join", - " ├─TableReader(Build) 7.00 root data:TableFullScan", - " │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false", - " └─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false" - ], - "Warning": null + "TableReader 3333.33 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 3333.33 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 3333.33 mpp[tiflash] plus(test.employee.deptid, 5)->Column#5, mul(test.employee.empid, 10)->Column#6", + " └─Selection 3333.33 mpp[tiflash] gt(test.employee.deptid, 1)", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select /*+ MERGE() */ * from t4) select * from cte3,cte4) select * from cte1,cte2;", + "SQL": "select count(*) from employee group by deptid+1", "Plan": [ - "HashJoin 2401.00 root CARTESIAN inner join", - "├─HashJoin(Build) 49.00 root CARTESIAN inner join", - "│ ├─TableReader(Build) 7.00 root data:TableFullScan", - "│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false", - "│ └─TableReader(Probe) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false", - "└─HashJoin(Probe) 49.00 root CARTESIAN inner join", - " ├─TableReader(Build) 7.00 root data:TableFullScan", - " │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false", - " └─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false" - ], - "Warning": null + "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 8000.00 mpp[tiflash] Column#5", + " └─HashAgg 8000.00 mpp[tiflash] group by:Column#12, funcs:sum(Column#13)->Column#5", + " └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#12, collate: binary]", + " └─HashAgg 8000.00 mpp[tiflash] group by:Column#14, funcs:count(1)->Column#13", + " └─Projection 10000.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#14", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" + ] }, { - "SQL": "with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select /*+ MERGE() */ * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2;", + "SQL": "select count(distinct deptid) a from employee", "Plan": [ - "HashJoin 2401.00 root CARTESIAN inner join", - "├─HashJoin(Build) 49.00 root CARTESIAN inner join", - "│ ├─TableReader(Build) 7.00 root data:TableFullScan", - "│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false", - "│ └─TableReader(Probe) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false", - "└─HashJoin(Probe) 49.00 root CARTESIAN inner join", - " ├─TableReader(Build) 7.00 root data:TableFullScan", - " │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false", - " └─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false" - ], - "Warning": null + "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 1.00 mpp[tiflash] Column#5", + " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#7)->Column#5", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#7", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" + ] }, { - "SQL": "with cte2 as (with cte4 as (select * from tc) select * from te, cte4) select * from cte2;", + "SQL": "select * from employee join employee e1 using(deptid)", "Plan": [ - "HashJoin 49.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false", - "└─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:te keep order:false" - ], - "Warning": null + "TableReader 12487.50 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 12487.50 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 12487.50 mpp[tiflash] test.employee.deptid, test.employee.empid, test.employee.salary, test.employee.empid, test.employee.salary", + " └─HashJoin 12487.50 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, test.employee.deptid)]", + " ├─ExchangeReceiver(Build) 9990.00 mpp[tiflash] ", + " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee pushed down filter:empty, keep order:false, stats:pseudo", + " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "with cte2 as (with cte4 as (select /*+ merge() */ * from tc) select * from te, cte4) select * from cte2;", + "SQL": "select count(distinct a) from (select count(distinct deptid) a from employee) x", "Plan": [ - "HashJoin 49.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false", - "└─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:te keep order:false" - ], - "Warning": null + "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 1.00 mpp[tiflash] Column#6", + " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct Column#5)->Column#6", + " └─Projection 1.00 mpp[tiflash] Column#5", + " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#8)->Column#5", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#8", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" + ] }, { - "SQL": "with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select /*+ MERGE() */ * from t1) ttt) select * from cte1;", + "SQL": "select count(a) from (select count(distinct deptid) a, count(distinct empid) b from employee) x group by b+1", "Plan": [ - "HashJoin 49.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false", - "└─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false" - ], - "Warning": [ - "[planner:1815]Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE.", - "[planner:1815]Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE." + "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 1.00 mpp[tiflash] Column#7", + " └─HashAgg 1.00 mpp[tiflash] group by:Column#12, funcs:sum(Column#13)->Column#7", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#12, collate: binary]", + " └─HashAgg 1.00 mpp[tiflash] group by:Column#15, funcs:count(Column#14)->Column#13", + " └─Projection 1.00 mpp[tiflash] Column#5->Column#14, plus(Column#6, 1)->Column#15", + " └─Projection 1.00 mpp[tiflash] Column#5, Column#6", + " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#5, funcs:count(distinct test.employee.empid)->Column#6", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, test.employee.empid, ", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" ] }, { - "SQL": "with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select /*+ MERGE() */ * from t3) ttw;", + "SQL": "select count(a) from (select count(distinct deptid) a, count(distinct empid) b from employee) x group by b", "Plan": [ - "HashJoin 343.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false", - "└─HashJoin(Probe) 49.00 root CARTESIAN inner join", - " ├─TableReader(Build) 7.00 root data:TableFullScan", - " │ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false", - " └─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false" - ], - "Warning": [ - "[planner:1815]Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE." + "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 1.00 mpp[tiflash] Column#7", + " └─HashAgg 1.00 mpp[tiflash] group by:Column#6, funcs:count(Column#5)->Column#7", + " └─Projection 1.00 mpp[tiflash] Column#5, Column#6", + " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#5, funcs:count(distinct test.employee.empid)->Column#6", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, test.employee.empid, ", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" ] }, { - "SQL": "with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select * from t3) ttw;", + "SQL": "select * from employee join (select count(distinct deptid) a, count(distinct empid) b from employee) e1", "Plan": [ - "HashJoin 343.00 root CARTESIAN inner join", - "├─TableReader(Build) 7.00 root data:TableFullScan", - "│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false", - "└─HashJoin(Probe) 49.00 root CARTESIAN inner join", - " ├─TableReader(Build) 7.00 root data:TableFullScan", - " │ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false", - " └─TableReader(Probe) 7.00 root data:TableFullScan", - " └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false" - ], - "Warning": null - } - ] - }, - { - "Name": "TestForceInlineCTE", - "Cases": [ - { - "SQL": "set tidb_opt_force_inline_cte=1; -- enable force inline CTE", - "Plan": null, - "Warning": null - }, - { - "SQL": "with cte as (select * from t) select * from cte; -- inline", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with cte as (select * from t) select * from cte cte1, cte cte2; -- inline CTEs is used by multi consumers", - "Plan": [ - "HashJoin 100000000.00 root CARTESIAN inner join", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with cte1 as (select * from t), cte2 as (select a from cte1 group by a) select * from cte1, cte2; -- multi inline CTEs", - "Plan": [ - "HashJoin 80000000.00 root CARTESIAN inner join", - "├─HashAgg(Build) 8000.00 root group by:test.t.a, funcs:firstrow(test.t.a)->test.t.a", - "│ └─TableReader 8000.00 root data:HashAgg", - "│ └─HashAgg 8000.00 cop[tikv] group by:test.t.a, ", - "│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with recursive cte1(c1) as (select 1 union select c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined", - "Plan": [ - "CTEFullScan 2.00 root CTE:cte1 data:CTE_0", - "CTE_0 2.00 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#2", - "│ └─TableDual 1.00 root rows:1", - "└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5", - " └─Selection 0.80 root lt(Column#3, 100)", - " └─CTETable 1.00 root Scan on CTE_0" - ], - "Warning": [ - "[planner:1815]Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte." - ] - }, - { - "SQL": "with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'", - "Plan": [ - "CTEFullScan 8001.00 root CTE:cte2 data:CTE_0", - "CTE_0 8001.00 root Recursive CTE", - "├─TableReader(Seed Part) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", - "└─Projection(Recursive Part) 8000.00 root cast(plus(test.t.a, 1), int(11))->test.t.a", - " └─Selection 8000.00 root lt(test.t.a, 100)", - " └─CTETable 10000.00 root Scan on CTE_0" - ], - "Warning": [ - "[planner:1815]Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte." - ] - }, - { - "SQL": "with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'", - "Plan": [ - "CTEFullScan 2.00 root CTE:cte2 data:CTE_2", - "CTE_2 2.00 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#9", - "│ └─TableDual 1.00 root rows:1", - "└─Projection(Recursive Part) 0.80 root cast(plus(Column#10, 1), bigint(1) BINARY)->Column#12", - " └─Selection 0.80 root lt(Column#10, 100)", - " └─CTETable 1.00 root Scan on CTE_2" - ], - "Warning": [ - "[planner:1815]Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte.", - "[planner:1815]Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte." - ] - }, - { - "SQL": "set tidb_opt_force_inline_cte=0; -- disable force inline CTE", - "Plan": null, - "Warning": null - }, - { - "SQL": "with cte as (select * from t) select * from cte; -- inlined by single consumer", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline, merge hint override session variable", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined", - "Plan": [ - "CTEFullScan 2.00 root CTE:cte1 data:CTE_0", - "CTE_0 2.00 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#2", - "│ └─TableDual 1.00 root rows:1", - "└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5", - " └─Selection 0.80 root lt(Column#3, 100)", - " └─CTETable 1.00 root Scan on CTE_0" - ], - "Warning": [ - "[planner:1815]Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte." - ] - }, - { - "SQL": "with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'", - "Plan": [ - "CTEFullScan 8001.00 root CTE:cte2 data:CTE_0", - "CTE_0 8001.00 root Recursive CTE", - "├─TableReader(Seed Part) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", - "└─Projection(Recursive Part) 8000.00 root cast(plus(test.t.a, 1), int(11))->test.t.a", - " └─Selection 8000.00 root lt(test.t.a, 100)", - " └─CTETable 10000.00 root Scan on CTE_0" - ], - "Warning": null - }, - { - "SQL": "with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'", - "Plan": [ - "CTEFullScan 2.00 root CTE:cte2 data:CTE_2", - "CTE_2 2.00 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#9", - "│ └─TableDual 1.00 root rows:1", - "└─Projection(Recursive Part) 0.80 root cast(plus(Column#10, 1), bigint(1) BINARY)->Column#12", - " └─Selection 0.80 root lt(Column#10, 100)", - " └─CTETable 1.00 root Scan on CTE_2" - ], - "Warning": null - } - ] - }, - { - "Name": "TestSingleConsumerCTE", - "Cases": [ - { - "SQL": "with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 1) select * from cte1; -- non-recursive limit, inline cte1", - "Plan": [ - "Limit 1.00 root offset:0, count:1", - "└─HashAgg 1.00 root group by:Column#18, funcs:firstrow(Column#18)->Column#18", - " └─Union 20000.00 root ", - " ├─TableReader 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─IndexReader 10000.00 root index:IndexFullScan", - " └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 100 offset 100) select * from cte1; -- non-recursive limit, inline cte1", - "Plan": [ - "Limit 100.00 root offset:100, count:100", - "└─HashAgg 200.00 root group by:Column#18, funcs:firstrow(Column#18)->Column#18", - " └─Union 20000.00 root ", - " ├─TableReader 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─IndexReader 10000.00 root index:IndexFullScan", - " └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 0 offset 0) select * from cte1; -- non-recursive limit, inline cte1", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Warning": null - }, - { - "SQL": "with cte1 as (select 1), cte2 as (select 2) select * from cte1 union (with cte2 as (select 3) select * from cte2 union all select * from cte2) -- inline cte1, not inline cte2", - "Plan": [ - "HashAgg 3.00 root group by:Column#9, funcs:firstrow(Column#9)->Column#9", - "└─Union 3.00 root ", - " ├─Projection 1.00 root 1->Column#9", - " │ └─TableDual 1.00 root rows:1", - " └─Union 2.00 root ", - " ├─CTEFullScan 1.00 root CTE:cte2 data:CTE_2", - " └─CTEFullScan 1.00 root CTE:cte2 data:CTE_2", - "CTE_2 1.00 root Non-Recursive CTE", - "└─Projection(Seed Part) 1.00 root 3->Column#5", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with base1 as (WITH RECURSIVE cte(a) AS (with tmp as (select 1 as a) SELECT a from tmp UNION SELECT a+1 FROM cte) SELECT * FROM cte) select * from base1; -- issue #43318", - "Plan": [ - "CTEFullScan 2.00 root CTE:cte data:CTE_3", - "CTE_3 2.00 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#15", - "│ └─TableDual 1.00 root rows:1", - "└─Projection(Recursive Part) 1.00 root cast(plus(Column#16, 1), bigint(1) BINARY)->Column#18", - " └─CTETable 1.00 root Scan on CTE_3" - ], - "Warning": null - }, - { - "SQL": "with cte as (select 1) select * from cte; -- inline cte", - "Plan": [ - "Projection 1.00 root 1->Column#3", - "└─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with cte1 as (select 1), cte2 as (select 2) select * from cte1 union select * from cte2; -- inline cte1, cte2", - "Plan": [ - "HashAgg 2.00 root group by:Column#7, funcs:firstrow(Column#7)->Column#7", - "└─Union 2.00 root ", - " ├─Projection 1.00 root 1->Column#7", - " │ └─TableDual 1.00 root rows:1", - " └─Projection 1.00 root 2->Column#7", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with cte as (select 1) select * from cte union select * from cte; -- cannot be inlined", - "Plan": [ - "HashAgg 2.00 root group by:Column#4, funcs:firstrow(Column#4)->Column#4", - "└─Union 2.00 root ", - " ├─CTEFullScan 1.00 root CTE:cte data:CTE_0", - " └─CTEFullScan 1.00 root CTE:cte data:CTE_0", - "CTE_0 1.00 root Non-Recursive CTE", - "└─Projection(Seed Part) 1.00 root 1->Column#1", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with cte as (with cte as (select 1) select * from cte) select * from cte; -- inline nested cte", - "Plan": [ - "Projection 1.00 root 1->Column#7", - "└─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with cte as (with cte as (select 1) select * from cte) select * from cte a, cte b; -- inline inner cte, cannot be inlined outer cte", - "Plan": [ - "HashJoin 1.00 root CARTESIAN inner join", - "├─CTEFullScan(Build) 1.00 root CTE:cte AS b data:CTE_0", - "└─CTEFullScan(Probe) 1.00 root CTE:cte AS a data:CTE_0", - "CTE_0 1.00 root Non-Recursive CTE", - "└─Projection(Seed Part) 1.00 root 1->Column#3", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte1, cte2; -- inline cte2, cte3, cannot be inlined cte1", - "Plan": [ - "HashJoin 1.00 root CARTESIAN inner join", - "├─CTEFullScan(Build) 1.00 root CTE:cte1 data:CTE_0", - "└─CTEFullScan(Probe) 1.00 root CTE:cte1 data:CTE_0", - "CTE_0 1.00 root Non-Recursive CTE", - "└─Projection(Seed Part) 1.00 root 1->Column#1", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte2; -- inline cte1, cte2, cte3", - "Plan": [ - "Projection 1.00 root 1->Column#12", - "└─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with cte1 as (select 1), cte2 as (select * from cte1) select * from cte2 a, cte2 b; -- inline cte1, cannot be inlined cte2", - "Plan": [ - "HashJoin 1.00 root CARTESIAN inner join", - "├─CTEFullScan(Build) 1.00 root CTE:cte2 AS b data:CTE_1", - "└─CTEFullScan(Probe) 1.00 root CTE:cte2 AS a data:CTE_1", - "CTE_1 1.00 root Non-Recursive CTE", - "└─Projection(Seed Part) 1.00 root 1->Column#3", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with recursive cte(a) as (select 1 union select a from cte) select * from cte; -- recursive cte cannot be inlined", - "Plan": [ - "CTEFullScan 2.00 root CTE:cte data:CTE_0", - "CTE_0 2.00 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#2", - "│ └─TableDual 1.00 root rows:1", - "└─CTETable(Recursive Part) 1.00 root Scan on CTE_0" - ], - "Warning": null - }, - { - "SQL": "with x as (select * from (select a from t for update) s) select * from x where a = 1;", - "Plan": [ - "Projection 10.00 root test.t.a", - "└─SelectLock 10.00 root for update 0", - " └─TableReader 10.00 root data:Selection", - " └─Selection 10.00 cop[tikv] eq(test.t.a, 1)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "set tidb_opt_force_inline_cte=1; -- enable force inline CTE", - "Plan": null, - "Warning": null - }, - { - "SQL": "with cte as (select 1) select * from cte union select * from cte; -- force inline cte while multi-consumer", - "Plan": [ - "HashAgg 2.00 root group by:Column#6, funcs:firstrow(Column#6)->Column#6", - "└─Union 2.00 root ", - " ├─Projection 1.00 root 1->Column#6", - " │ └─TableDual 1.00 root rows:1", - " └─Projection 1.00 root 1->Column#6", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "set tidb_opt_force_inline_cte=0; -- disable force inline CTE", - "Plan": null, - "Warning": null - }, - { - "SQL": "with cte as (select 1) select /*+ MERGE() */ * from cte union select * from cte; -- firstly inline cte, secondly cannot be inlined", - "Plan": [ - "HashAgg 2.00 root group by:Column#4, funcs:firstrow(Column#4)->Column#4", - "└─Union 2.00 root ", - " ├─CTEFullScan 1.00 root CTE:cte data:CTE_0", - " └─CTEFullScan 1.00 root CTE:cte data:CTE_0", - "CTE_0 1.00 root Non-Recursive CTE", - "└─Projection(Seed Part) 1.00 root 1->Column#1", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with a as (select 8 as id from dual),maxa as (select max(id) as max_id from a),b as (with recursive temp as (select 1 as lvl from dual union all select lvl+1 from temp, maxa where lvl < max_id)select * from temp) select * from b; -- issue #47711, maxa cannot be inlined because it contains agg and in the recursive part of cte temp", - "Plan": [ - "CTEFullScan 1.64 root CTE:temp data:CTE_4", - "CTE_4 1.64 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 1->Column#14", - "│ └─TableDual 1.00 root rows:1", - "└─Projection(Recursive Part) 0.64 root cast(plus(Column#15, 1), bigint(1) BINARY)->Column#18", - " └─HashJoin 0.64 root CARTESIAN inner join, other cond:lt(Column#15, Column#16)", - " ├─Selection(Build) 0.80 root not(isnull(Column#16))", - " │ └─CTEFullScan 1.00 root CTE:maxa data:CTE_1", - " └─Selection(Probe) 0.80 root not(isnull(Column#15))", - " └─CTETable 1.00 root Scan on CTE_4", - "CTE_1 1.00 root Non-Recursive CTE", - "└─StreamAgg(Seed Part) 1.00 root funcs:max(Column#3)->Column#4", - " └─Projection 1.00 root 8->Column#3", - " └─TableDual 1.00 root rows:1" - ], - "Warning": null - }, - { - "SQL": "with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select 1 as res from t1 union all select res+1 from tmp,b where res+1 < bb) select * from tmp) select * from c; -- inline a, cannot be inline b because b indirectly contains agg and in the recursive part of cte tmp", - "Plan": [ - "CTEFullScan 20000.00 root CTE:tmp data:CTE_4", - "CTE_4 20000.00 root Recursive CTE", - "├─Projection(Seed Part) 10000.00 root 1->Column#26", - "│ └─TableReader 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─Projection(Recursive Part) 10000.00 root cast(plus(Column#27, 1), bigint(1) BINARY)->Column#30", - " └─HashJoin 10000.00 root CARTESIAN inner join, other cond:lt(plus(Column#27, 1), Column#28)", - " ├─CTEFullScan(Build) 1.00 root CTE:b data:CTE_1", - " └─CTETable(Probe) 10000.00 root Scan on CTE_4", - "CTE_1 1.00 root Non-Recursive CTE", - "└─Projection(Seed Part) 1.00 root 2->Column#8", - " └─HashAgg 1.00 root funcs:count(Column#37)->Column#35", - " └─TableReader 1.00 root data:HashAgg", - " └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#37", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c", - "Plan": [ - "CTEFullScan 1.80 root CTE:tmp data:CTE_4", - "CTE_4 1.80 root Recursive CTE", - "├─Projection(Seed Part) 1.00 root 2->Column#37", - "│ └─HashAgg 1.00 root funcs:count(Column#46)->Column#44", - "│ └─TableReader 1.00 root data:HashAgg", - "│ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#46", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─Projection(Recursive Part) 0.80 root cast(plus(Column#38, 1), bigint(1) BINARY)->Column#40", - " └─Selection 0.80 root lt(plus(Column#38, 1), 10)", - " └─CTETable 1.00 root Scan on CTE_4" - ], - "Warning": null - } - ] - }, - { - "Name": "TestPushdownDistinctEnableAggPushDownDisable", - "Cases": [ - { - "SQL": "select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt;", - "Plan": [ - "HashAgg 1.00 root funcs:sum(distinct Column#9)->Column#4", - "└─Projection 16000.00 root cast(test.pt.b, decimal(10,0) BINARY)->Column#9", - " └─PartitionUnion 16000.00 root ", - " ├─HashAgg 8000.00 root group by:test.pt.b, funcs:firstrow(test.pt.b)->test.pt.b, funcs:firstrow(test.pt.b)->test.pt.b", - " │ └─TableReader 8000.00 root data:HashAgg", - " │ └─HashAgg 8000.00 cop[tikv] group by:test.pt.b, ", - " │ └─TableFullScan 10000.00 cop[tikv] table:pt, partition:p0 keep order:false, stats:pseudo", - " └─HashAgg 8000.00 root group by:test.pt.b, funcs:firstrow(test.pt.b)->test.pt.b, funcs:firstrow(test.pt.b)->test.pt.b", - " └─TableReader 8000.00 root data:HashAgg", - " └─HashAgg 8000.00 cop[tikv] group by:test.pt.b, ", - " └─TableFullScan 10000.00 cop[tikv] table:pt, partition:p1 keep order:false, stats:pseudo" - ], - "Result": [ - "" - ] - }, - { - "SQL": "select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t;", - "Plan": [ - "HashAgg 1.00 root funcs:count(distinct Column#5)->Column#6", - "└─Union 20000.00 root ", - " ├─TableReader 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo" - ], - "Result": [ - "1" - ] - }, - { - "SQL": "select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ;", - "Plan": [ - "HashAgg 16000.00 root group by:Column#5, funcs:firstrow(Column#6)->Column#3", - "└─PartitionUnion 16000.00 root ", - " ├─HashAgg 8000.00 root group by:Column#7, funcs:firstrow(Column#7)->Column#6, funcs:firstrow(Column#7)->Column#5", - " │ └─IndexReader 8000.00 root index:HashAgg", - " │ └─HashAgg 8000.00 cop[tikv] group by:date_format(test.tc.timestamp, \"%Y-%m-%d %H\"), ", - " │ └─IndexFullScan 10000.00 cop[tikv] table:tc, partition:p2020072312, index:idx_timestamp(timestamp) keep order:false, stats:pseudo", - " └─HashAgg 8000.00 root group by:Column#10, funcs:firstrow(Column#10)->Column#6, funcs:firstrow(Column#10)->Column#5", - " └─IndexReader 8000.00 root index:HashAgg", - " └─HashAgg 8000.00 cop[tikv] group by:date_format(test.tc.timestamp, \"%Y-%m-%d %H\"), ", - " └─IndexFullScan 10000.00 cop[tikv] table:tc, partition:p2020072313, index:idx_timestamp(timestamp) keep order:false, stats:pseudo" - ], - "Result": null - } - ] - }, - { - "Name": "TestGroupConcatOrderby", - "Cases": [ - { - "SQL": "select /*+ agg_to_cop */ group_concat(name ORDER BY name desc SEPARATOR '++'), group_concat(id ORDER BY name desc, id asc SEPARATOR '--') from test;", - "Plan": [ - "HashAgg 1.00 root funcs:group_concat(Column#6 order by Column#7 desc separator \"++\")->Column#4, funcs:group_concat(Column#8 order by Column#9 desc, Column#10 separator \"--\")->Column#5", - "└─Projection 10000.00 root cast(test.test.name, var_string(20))->Column#6, test.test.name->Column#7, cast(test.test.id, var_string(20))->Column#8, test.test.name->Column#9, test.test.id->Column#10", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" - ], - "Result": [ - "500++200++30++20++20++10 3--3--1--1--2--1" - ] - }, - { - "SQL": "select /*+ agg_to_cop */ group_concat(name ORDER BY name desc SEPARATOR '++'), group_concat(id ORDER BY name desc, id asc SEPARATOR '--') from ptest;", - "Plan": [ - "HashAgg 1.00 root funcs:group_concat(Column#6 order by Column#7 desc separator \"++\")->Column#4, funcs:group_concat(Column#8 order by Column#9 desc, Column#10 separator \"--\")->Column#5", - "└─Projection 10000.00 root cast(test.ptest.name, var_string(20))->Column#6, test.ptest.name->Column#7, cast(test.ptest.id, var_string(20))->Column#8, test.ptest.name->Column#9, test.ptest.id->Column#10", - " └─TableReader 10000.00 root partition:all data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:ptest keep order:false, stats:pseudo" - ], - "Result": [ - "500++200++30++20++20++10 3--3--1--1--2--1" - ] - }, - { - "SQL": "select /*+ agg_to_cop */ group_concat(distinct name order by name desc) from test;", - "Plan": [ - "HashAgg 1.00 root funcs:group_concat(distinct Column#5 order by Column#6 desc separator \",\")->Column#4", - "└─Projection 10000.00 root cast(test.test.name, var_string(20))->Column#5, test.test.name->Column#6", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" - ], - "Result": [ - "500,200,30,20,10" - ] - }, - { - "SQL": "select /*+ agg_to_cop */ group_concat(distinct name order by name desc) from ptest;", - "Plan": [ - "HashAgg 1.00 root funcs:group_concat(distinct Column#5 order by Column#6 desc separator \",\")->Column#4", - "└─Projection 10000.00 root cast(test.ptest.name, var_string(20))->Column#5, test.ptest.name->Column#6", - " └─TableReader 10000.00 root partition:all data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:ptest keep order:false, stats:pseudo" - ], - "Result": [ - "500,200,30,20,10" - ] - } - ] - }, - { - "Name": "TestNominalSort", - "Cases": [ - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a", - "Plan": [ - "MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - "├─IndexReader(Build) 9990.00 root index:IndexFullScan", - "│ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo", - "└─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo" - ], - "Result": [ - "1", - "1", - "2" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, plus(test.t.a, 1)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo" - ], - "Result": [ - "1", - "1", - "2" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, minus(test.t.a, 1)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo" - ], - "Result": [ - "1", - "1", - "2" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, unaryminus(test.t.a)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo" - ], - "Result": [ - "2", - "1", - "1" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, plus(unaryminus(test.t.a), 3)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo" - ], - "Result": [ - "2", - "1", - "1" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, plus(1, test.t.a)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo" - ], - "Result": [ - "1", - "1", - "2" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, minus(1, test.t.a)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo" - ], - "Result": [ - "2", - "1", - "1" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, plus(minus(1, test.t.a), 3)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo" - ], - "Result": [ - "2", - "1", - "1" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Projection 12487.50 root test.t.a, plus(plus(1, test.t.a), 3)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo" - ], - "Result": [ - "1", - "1", - "2" - ] - }, - { - "SQL": "select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a", - "Plan": [ - "Projection 12487.50 root test.t.a", - "└─Sort 12487.50 root Column#7", - " └─Projection 12487.50 root test.t.a, mul(3, test.t.a)->Column#7", - " └─MergeJoin 12487.50 root inner join, left key:test.t.a, right key:test.t.b", - " ├─IndexReader(Build) 9990.00 root index:IndexFullScan", - " │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo", - " └─IndexReader(Probe) 9990.00 root index:IndexFullScan", - " └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo" - ], - "Result": [ - "1", - "1", - "2" - ] - } - ] - }, - { - "Name": "TestInlineProjection", - "Cases": [ - { - "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1, t2 where t1.a = t2.a;", - "Plan": "LeftHashJoin{TableReader(Table(t1)->Sel([not(isnull(test.t1.a))]))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t1.a,test.t2.a)", - "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" - }, - { - "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", - "Plan": "LeftHashJoin{TableReader(Table(t1)->Sel([not(isnull(test.t1.a))]))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t1.a,test.t2.a)", - "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" - }, - { - "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 left outer join t2 on t1.a = t2.a;", - "Plan": "LeftHashJoin{TableReader(Table(t1))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t1.a,test.t2.a)", - "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" - }, - { - "SQL": "select /*+ HASH_JOIN(t1) */ t1.b, t2.b from t1 right outer join t2 on t1.a = t2.a;", - "Plan": "RightHashJoin{TableReader(Table(t1)->Sel([not(isnull(test.t1.a))]))->TableReader(Table(t2))}(test.t1.a,test.t2.a)", - "Hints": "hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` ), use_index(@`sel_1` `test`.`t2` )" - }, - { - "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a in (select t2.a from t2) from t1) x;", - "Plan": "LeftHashJoin{IndexReader(Index(t1.idx_a)[[NULL,+inf]])->IndexReader(Index(t2.idx_a)[[NULL,+inf]])}->Projection", - "Hints": "hash_join(@`sel_2` `test`.`t1`), use_index(@`sel_2` `test`.`t1` `idx_a`), no_order_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_3` `test`.`t2` `idx_a`), no_order_index(@`sel_3` `test`.`t2` `idx_a`)" - }, - { - "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a not in (select t2.a from t2) from t1) x;", - "Plan": "LeftHashJoin{IndexReader(Index(t1.idx_a)[[NULL,+inf]])->IndexReader(Index(t2.idx_a)[[NULL,+inf]])}->Projection", - "Hints": "hash_join(@`sel_2` `test`.`t1`), use_index(@`sel_2` `test`.`t1` `idx_a`), no_order_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_3` `test`.`t2` `idx_a`), no_order_index(@`sel_3` `test`.`t2` `idx_a`)" - }, - { - "SQL": "select /*+ INL_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", - "Plan": "IndexJoin{IndexLookUp(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]), Table(t1))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t2.a,test.t1.a)", - "Hints": "inl_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), no_order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` )" - }, - { - "SQL": "select /*+ INL_HASH_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", - "Plan": "IndexHashJoin{IndexLookUp(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]), Table(t1))->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t2.a,test.t1.a)", - "Hints": "inl_hash_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), no_order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` )" - }, - { - "SQL": "select /*+ INL_MERGE_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", - "Plan": "IndexMergeJoin{IndexLookUp(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]), Table(t1))->Projection->TableReader(Table(t2)->Sel([not(isnull(test.t2.a))]))}(test.t2.a,test.t1.a)", - "Hints": "inl_merge_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` )" - }, - { - "SQL": "select /*+ MERGE_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", - "Plan": "MergeInnerJoin{IndexLookUp(Index(t1.idx_a)[[-inf,+inf]], Table(t1))->Projection->IndexLookUp(Index(t2.idx_a)[[-inf,+inf]], Table(t2))->Projection}(test.t1.a,test.t2.a)", - "Hints": "merge_join(@`sel_1` `test`.`t1`), use_index(@`sel_1` `test`.`t1` `idx_a`), order_index(@`sel_1` `test`.`t1` `idx_a`), use_index(@`sel_1` `test`.`t2` `idx_a`), order_index(@`sel_1` `test`.`t2` `idx_a`)" - } - ] - }, - { - "Name": "TestHintFromDiffDatabase", - "Cases": [ - { - "SQL": "select /*+ inl_hash_join(test.t1) */ * from test.t2 join test.t1 on test.t2.a = test.t1.a", - "Plan": "IndexHashJoin{IndexReader(Index(t2.idx_a)[[-inf,+inf]])->IndexReader(Index(t1.idx_a)[[NULL,NULL]]->Sel([not(isnull(test.t1.a))]))}(test.t2.a,test.t1.a)" - } - ] - }, - { - "Name": "TestNthPlanHintWithExplain", - "Cases": [ - { - "SQL": "select /*+nth_plan(1)*/ * from test.tt where a=1 and b=1", - "Plan": [ - "TableReader 0.01 root data:Selection", - "└─Selection 0.01 cop[tikv] eq(test.tt.a, 1), eq(test.tt.b, 1)", - " └─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1;", - "Plan": [ - "IndexLookUp 0.01 root ", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1)", - " └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+nth_plan(3)*/ * from test.tt where a=1 and b=1;", - "Plan": [ - "IndexLookUp 0.01 root ", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:b(b) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.a, 1)", - " └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1;", - "Plan": [ - "IndexLookUp 0.01 root ", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1)", - " └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from test.tt where a=1 and b=1", - "Plan": [ - "IndexLookUp 0.01 root ", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo", - "└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1)", - " └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestINMJHint", - "Cases": [ - { - "SQL": "select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "IndexMergeJoin 12500.00 root left outer join, inner:TableReader, outer key:test.t1.a, inner key:test.t2.a, other cond:eq(test.t1.b, test.t2.b)", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [test.t1.a], keep order:true, stats:pseudo" - ], - "Result": [ - "1 1", - "2 " - ] - }, - { - "SQL": "select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "IndexHashJoin 12500.00 root left outer join, inner:TableReader, outer key:test.t1.a, inner key:test.t2.a, equal cond:eq(test.t1.a, test.t2.a), eq(test.t1.b, test.t2.b)", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [test.t1.a], keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 " - ] - }, - { - "SQL": "select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "IndexJoin 12500.00 root left outer join, inner:TableReader, outer key:test.t1.a, inner key:test.t2.a, equal cond:eq(test.t1.a, test.t2.a), eq(test.t1.b, test.t2.b)", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [test.t1.a], keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 " - ] - }, - { - "SQL": "select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root left outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 " - ] - } - ] - }, - { - "Name": "TestEliminateMaxOneRow", - "Cases": [ - { - "SQL": "select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a);", - "Plan": [ - "HashJoin 9990.00 root inner join, equal:[eq(test.t2.a, test.t1.a)], other cond:lt(test.t2.a, test.t1.a)", - "├─IndexReader(Build) 7992.00 root index:Selection", - "│ └─Selection 7992.00 cop[tikv] lt(test.t1.a, test.t1.a)", - "│ └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo", - "└─TableReader(Probe) 7992.00 root data:Selection", - " └─Selection 7992.00 cop[tikv] lt(test.t2.a, test.t2.a), not(isnull(test.t2.a))", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": null - }, - { - "SQL": "select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null);", - "Plan": [ - "Projection 9990.00 root test.t2.a", - "└─Apply 9990.00 root CARTESIAN inner join, other cond:lt(test.t2.a, test.t1.a)", - " ├─TableReader(Build) 9990.00 root data:Selection", - " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " └─Selection(Probe) 7992.00 root not(isnull(test.t1.a))", - " └─MaxOneRow 9990.00 root ", - " └─IndexLookUp 9.99 root ", - " ├─IndexRangeScan(Build) 9990.00 cop[tikv] table:t1, index:idx_a(a) range:[NULL,NULL], keep order:false, stats:pseudo", - " └─Selection(Probe) 9.99 cop[tikv] eq(test.t1.b, test.t2.b)", - " └─TableRowIDScan 9990.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": null - }, - { - "SQL": "select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a);", - "Plan": [ - "Projection 9990.00 root test.t2.a", - "└─Apply 9990.00 root CARTESIAN inner join, other cond:lt(test.t2.a, test.t3.a)", - " ├─TableReader(Build) 9990.00 root data:Selection", - " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.a))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " └─Selection(Probe) 7992.00 root not(isnull(test.t3.a))", - " └─MaxOneRow 9990.00 root ", - " └─IndexReader 19980.00 root index:IndexRangeScan", - " └─IndexRangeScan 19980.00 cop[tikv] table:t3, index:idx_abc(a, b, c) range: decided by [eq(test.t3.a, test.t2.a)], keep order:false, stats:pseudo" - ], - "Result": null - } - ] - }, - { - "Name": "TestEnumIndex", - "Cases": [ - { - "SQL": "select e from t where e = 'b'", - "Plan": [ - "IndexReader 10.00 root index:IndexRangeScan", - "└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:[\"b\",\"b\"], keep order:false, stats:pseudo" - ], - "Result": [ - "b" - ] - }, - { - "SQL": "select e from t where e != 'b'", - "Plan": [ - "IndexReader 40.00 root index:IndexRangeScan", - "└─IndexRangeScan 40.00 cop[tikv] table:t, index:idx(e) range:[\"\",\"\"], [\"c\",\"c\"], [\"a\",\"a\"], [\"\",\"\"], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "", - "a", - "c" - ] - }, - { - "SQL": "select e from t where e > 'b'", - "Plan": [ - "IndexReader 10.00 root index:IndexRangeScan", - "└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:[\"c\",\"c\"], keep order:false, stats:pseudo" - ], - "Result": [ - "c" - ] - }, - { - "SQL": "select e from t where e >= 'b'", - "Plan": [ - "IndexReader 20.00 root index:IndexRangeScan", - "└─IndexRangeScan 20.00 cop[tikv] table:t, index:idx(e) range:[\"c\",\"c\"], [\"b\",\"b\"], keep order:false, stats:pseudo" - ], - "Result": [ - "b", - "c" - ] - }, - { - "SQL": "select e from t where e < 'b'", - "Plan": [ - "IndexReader 30.00 root index:IndexRangeScan", - "└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:[\"\",\"\"], [\"a\",\"a\"], [\"\",\"\"], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "", - "a" - ] - }, - { - "SQL": "select e from t where e <= 'b'", - "Plan": [ - "IndexReader 40.00 root index:IndexRangeScan", - "└─IndexRangeScan 40.00 cop[tikv] table:t, index:idx(e) range:[\"\",\"\"], [\"b\",\"b\"], [\"a\",\"a\"], [\"\",\"\"], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "", - "a", - "b" - ] - }, - { - "SQL": "select e from t where e = 2", - "Plan": [ - "IndexReader 10.00 root index:IndexRangeScan", - "└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:[\"b\",\"b\"], keep order:false, stats:pseudo" - ], - "Result": [ - "b" - ] - }, - { - "SQL": "select e from t where e != 2", - "Plan": [ - "IndexReader 6656.67 root index:IndexRangeScan", - "└─IndexRangeScan 6656.67 cop[tikv] table:t, index:idx(e) range:[-inf,\"b\"), (\"b\",+inf], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "", - "a", - "c" - ] - }, - { - "SQL": "select e from t where e > 2", - "Plan": [ - "IndexReader 3333.33 root index:IndexRangeScan", - "└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:(\"b\",+inf], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "a" - ] - }, - { - "SQL": "select e from t where e >= 2", - "Plan": [ - "IndexReader 3333.33 root index:IndexRangeScan", - "└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:[\"b\",+inf], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "a", - "b" - ] - }, - { - "SQL": "select e from t where e < 2", - "Plan": [ - "IndexReader 3323.33 root index:IndexRangeScan", - "└─IndexRangeScan 3323.33 cop[tikv] table:t, index:idx(e) range:[-inf,\"b\"), keep order:false, stats:pseudo" - ], - "Result": [ - "", - "c" - ] - }, - { - "SQL": "select e from t where e <= 2", - "Plan": [ - "IndexReader 3323.33 root index:IndexRangeScan", - "└─IndexRangeScan 3323.33 cop[tikv] table:t, index:idx(e) range:[-inf,\"b\"], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "b", - "c" - ] - }, - { - "SQL": "select e from t where e > ''", - "Plan": [ - "IndexReader 30.00 root index:IndexRangeScan", - "└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:[\"c\",\"c\"], [\"b\",\"b\"], [\"a\",\"a\"], keep order:false, stats:pseudo" - ], - "Result": [ - "a", - "b", - "c" - ] - }, - { - "SQL": "select e from t where e > 'd'", - "Plan": [ - "TableDual 0.00 root rows:0" - ], - "Result": null - }, - { - "SQL": "select e from t where e > -1", - "Plan": [ - "IndexReader 3333.33 root index:IndexRangeScan", - "└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:[\"\",+inf], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "", - "a", - "b", - "c" - ] - }, - { - "SQL": "select e from t where e > 5", - "Plan": [ - "IndexReader 3333.33 root index:IndexRangeScan", - "└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:(\"\",+inf], keep order:false, stats:pseudo" - ], - "Result": null - }, - { - "SQL": "select e from t where e = ''", - "Plan": [ - "IndexReader 20.00 root index:IndexRangeScan", - "└─IndexRangeScan 20.00 cop[tikv] table:t, index:idx(e) range:[\"\",\"\"], [\"\",\"\"], keep order:false, stats:pseudo" - ], - "Result": [ - "", - "" - ] - }, - { - "SQL": "select e from t where e != ''", - "Plan": [ - "IndexReader 30.00 root index:IndexRangeScan", - "└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:[\"c\",\"c\"], [\"b\",\"b\"], [\"a\",\"a\"], keep order:false, stats:pseudo" - ], - "Result": [ - "a", - "b", - "c" - ] - } - ] - }, - { - "Name": "TestIssue27233", - "Cases": [ - { - "SQL": "SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2;", - "Plan": [ - "Sort 0.80 root test.pk_s_multi_31.col2", - "└─Projection 0.80 root test.pk_s_multi_31.col2", - " └─Selection 0.80 root gt(Column#7, 2)", - " └─HashAgg 1.00 root group by:test.pk_s_multi_31.col1, test.pk_s_multi_31.col2, funcs:firstrow(test.pk_s_multi_31.col2)->test.pk_s_multi_31.col2, funcs:count(distinct test.pk_s_multi_31.col1, test.pk_s_multi_31.col2)->Column#7", - " └─HashJoin 100000000.00 root CARTESIAN left outer join, other cond:gt(test.pk_s_multi_31.col1, test.pk_s_multi_31.col1)", - " ├─IndexReader(Build) 10000.00 root index:IndexFullScan", - " │ └─IndexFullScan 10000.00 cop[tikv] table:T2, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo", - " └─IndexReader(Probe) 10000.00 root index:IndexFullScan", - " └─IndexFullScan 10000.00 cop[tikv] table:T1, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo" - ], - "Result": [ - "100" - ] - } - ] - }, - { - "Name": "TestSelectionPartialPushDown", - "Cases": [ - { - "SQL": "select * from t1 where a > 1 and b > 1", - "Plan": [ - "Selection 1111.11 root gt(test.t1.b, 1)", - "└─TableReader 3333.33 root data:Selection", - " └─Selection 3333.33 cop[tikv] gt(test.t1.a, 1)", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1", - "Plan": [ - "Selection 370.37 root gt(test.t2.b, 1)", - "└─IndexLookUp 1111.11 root ", - " ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t2, index:idx_a(a) range:(1,+inf], keep order:false, stats:pseudo", - " └─Selection(Probe) 1111.11 cop[tikv] gt(test.t2.c, 1)", - " └─TableRowIDScan 3333.33 cop[tikv] table:t2 keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestIssue28316", - "Cases": [ - { - "SQL": "select * from t where t.a < 3 and t.a < 3", - "Plan": [ - "TableReader 3323.33 root data:Selection", - "└─Selection 3323.33 cop[tikv] lt(test.t.a, 3)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestSkewDistinctAgg", - "Cases": [ - { - "SQL": "select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y')", - "Plan": [ - "Projection 8000.00 root date_format(test.t.d, %Y)->Column#9, Column#6, cast(Column#13, bigint(21) BINARY)->Column#7, Column#8", - "└─HashAgg 8000.00 root group by:Column#23, funcs:sum(Column#19)->Column#6, funcs:sum(Column#20)->Column#13, funcs:count(Column#21)->Column#8, funcs:firstrow(Column#22)->test.t.d", - " └─Projection 8000.00 root Column#11->Column#19, cast(Column#12, decimal(20,0) BINARY)->Column#20, test.t.c->Column#21, test.t.d->Column#22, date_format(test.t.d, %Y)->Column#23", - " └─HashAgg 8000.00 root group by:Column#14, test.t.c, funcs:sum(Column#15)->Column#11, funcs:count(Column#16)->Column#12, funcs:firstrow(test.t.c)->test.t.c, funcs:firstrow(Column#18)->test.t.d", - " └─TableReader 8000.00 root data:HashAgg", - " └─HashAgg 8000.00 cop[tikv] group by:date_format(test.t.d, \"%Y\"), test.t.c, funcs:sum(test.t.a)->Column#15, funcs:count(test.t.b)->Column#16, funcs:firstrow(test.t.d)->Column#18", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select d, a, count(*), count(b), count(distinct c) from t group by d, a", - "Plan": [ - "Projection 8000.00 root test.t.d, test.t.a, cast(Column#10, bigint(21) BINARY)->Column#6, cast(Column#12, bigint(21) BINARY)->Column#7, Column#8", - "└─HashAgg 8000.00 root group by:Column#23, Column#24, funcs:sum(Column#18)->Column#10, funcs:sum(Column#19)->Column#12, funcs:count(Column#20)->Column#8, funcs:firstrow(Column#21)->test.t.a, funcs:firstrow(Column#22)->test.t.d", - " └─Projection 8000.00 root cast(Column#9, decimal(20,0) BINARY)->Column#18, cast(Column#11, decimal(20,0) BINARY)->Column#19, test.t.c->Column#20, test.t.a->Column#21, test.t.d->Column#22, test.t.d->Column#23, test.t.a->Column#24", - " └─HashAgg 8000.00 root group by:test.t.a, test.t.c, test.t.d, funcs:count(Column#13)->Column#9, funcs:count(Column#14)->Column#11, funcs:firstrow(test.t.c)->test.t.c, funcs:firstrow(test.t.a)->test.t.a, funcs:firstrow(test.t.d)->test.t.d", - " └─TableReader 8000.00 root data:HashAgg", - " └─HashAgg 8000.00 cop[tikv] group by:test.t.a, test.t.c, test.t.d, funcs:count(1)->Column#13, funcs:count(test.t.b)->Column#14", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select d, sum(a), count(b), avg(distinct c) from t group by d", - "Plan": [ - "Projection 8000.00 root test.t.d, Column#6, cast(Column#11, bigint(21) BINARY)->Column#7, Column#8", - "└─HashAgg 8000.00 root group by:Column#20, funcs:sum(Column#16)->Column#6, funcs:sum(Column#17)->Column#11, funcs:avg(Column#18)->Column#8, funcs:firstrow(Column#19)->test.t.d", - " └─Projection 8000.00 root Column#9->Column#16, cast(Column#10, decimal(20,0) BINARY)->Column#17, cast(test.t.c, decimal(10,0) BINARY)->Column#18, test.t.d->Column#19, test.t.d->Column#20", - " └─HashAgg 8000.00 root group by:test.t.c, test.t.d, funcs:sum(Column#12)->Column#9, funcs:count(Column#13)->Column#10, funcs:firstrow(test.t.c)->test.t.c, funcs:firstrow(test.t.d)->test.t.d", - " └─TableReader 8000.00 root data:HashAgg", - " └─HashAgg 8000.00 cop[tikv] group by:test.t.c, test.t.d, funcs:sum(test.t.a)->Column#12, funcs:count(test.t.b)->Column#13", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestMPPSinglePartitionType", - "Cases": [ - { - "SQL": "select * from employee where deptid>1", - "Plan": [ - "TableReader 3333.33 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 3333.33 mpp[tiflash] ExchangeType: PassThrough", - " └─Selection 3333.33 mpp[tiflash] gt(test.employee.deptid, 1)", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select deptid+5, empid*10 from employee where deptid>1", - "Plan": [ - "TableReader 3333.33 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 3333.33 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 3333.33 mpp[tiflash] plus(test.employee.deptid, 5)->Column#5, mul(test.employee.empid, 10)->Column#6", - " └─Selection 3333.33 mpp[tiflash] gt(test.employee.deptid, 1)", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select count(*) from employee group by deptid+1", - "Plan": [ - "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 8000.00 mpp[tiflash] Column#5", - " └─HashAgg 8000.00 mpp[tiflash] group by:Column#12, funcs:sum(Column#13)->Column#5", - " └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#12, collate: binary]", - " └─HashAgg 8000.00 mpp[tiflash] group by:Column#14, funcs:count(1)->Column#13", - " └─Projection 10000.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#14", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select count(distinct deptid) a from employee", - "Plan": [ - "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 1.00 mpp[tiflash] Column#5", - " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#7)->Column#5", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#7", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from employee join employee e1 using(deptid)", - "Plan": [ - "TableReader 12487.50 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 12487.50 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 12487.50 mpp[tiflash] test.employee.deptid, test.employee.empid, test.employee.salary, test.employee.empid, test.employee.salary", - " └─HashJoin 12487.50 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, test.employee.deptid)]", - " ├─ExchangeReceiver(Build) 9990.00 mpp[tiflash] ", - " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee pushed down filter:empty, keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select count(distinct a) from (select count(distinct deptid) a from employee) x", - "Plan": [ - "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 1.00 mpp[tiflash] Column#6", - " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct Column#5)->Column#6", - " └─Projection 1.00 mpp[tiflash] Column#5", - " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#8)->Column#5", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#8", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select count(a) from (select count(distinct deptid) a, count(distinct empid) b from employee) x group by b+1", - "Plan": [ - "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 1.00 mpp[tiflash] Column#7", - " └─HashAgg 1.00 mpp[tiflash] group by:Column#12, funcs:sum(Column#13)->Column#7", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#12, collate: binary]", - " └─HashAgg 1.00 mpp[tiflash] group by:Column#15, funcs:count(Column#14)->Column#13", - " └─Projection 1.00 mpp[tiflash] Column#5->Column#14, plus(Column#6, 1)->Column#15", - " └─Projection 1.00 mpp[tiflash] Column#5, Column#6", - " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#5, funcs:count(distinct test.employee.empid)->Column#6", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, test.employee.empid, ", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select count(a) from (select count(distinct deptid) a, count(distinct empid) b from employee) x group by b", - "Plan": [ - "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 1.00 mpp[tiflash] Column#7", - " └─HashAgg 1.00 mpp[tiflash] group by:Column#6, funcs:count(Column#5)->Column#7", - " └─Projection 1.00 mpp[tiflash] Column#5, Column#6", - " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#5, funcs:count(distinct test.employee.empid)->Column#6", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, test.employee.empid, ", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from employee join (select count(distinct deptid) a, count(distinct empid) b from employee) e1", - "Plan": [ - "TableReader 10000.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 10000.00 mpp[tiflash] CARTESIAN inner join", - " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Projection 1.00 mpp[tiflash] Column#9, Column#10", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#9, funcs:count(distinct test.employee.empid)->Column#10", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, test.employee.empid, ", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from employee e1 join (select count(distinct deptid) a from employee) e2 on e1.deptid = e2.a", - "Plan": [ - "TableReader 1.25 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 1.25 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 1.25 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#9)]", - " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Projection 1.00 mpp[tiflash] Column#9", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#10)->Column#9", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#10", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from (select count(distinct deptid) a from employee) e1 join employee e2 on e1.a = e2.deptid", - "Plan": [ - "TableReader 1.25 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 1.25 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 1.25 mpp[tiflash] Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", - " └─HashJoin 1.25 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#5)]", - " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Projection 1.00 mpp[tiflash] Column#5", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#10)->Column#5", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#10", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from (select count(distinct deptid) a from employee) e1 join (select count(distinct deptid) b from employee) e2 on e1.a=e2.b", - "Plan": [ - "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 1.00 mpp[tiflash] inner join, equal:[eq(Column#5, Column#10)]", - " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Projection 1.00 mpp[tiflash] Column#5", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#11)->Column#5", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#11", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─Projection(Probe) 1.00 mpp[tiflash] Column#10", - " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#12)->Column#10", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#12", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from employee e1 join employee e2 on e1.deptid = e2.deptid", - "Plan": [ - "TableReader 12487.50 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 12487.50 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 12487.50 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, test.employee.deptid)]", - " ├─ExchangeReceiver(Build) 9990.00 mpp[tiflash] ", - " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join employee e2 on e1.d = e2.deptid", - "Plan": [ - "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 8000.00 mpp[tiflash] Column#6, Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", - " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#6)]", - " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", - " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", - " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#5, funcs:firstrow(Column#15)->test.employee.deptid", - " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#27, funcs:count(Column#25)->Column#14, funcs:firstrow(Column#26)->Column#15", - " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#25, test.employee.deptid->Column#26, plus(test.employee.deptid, 1)->Column#27", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from employee e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.deptid = e2.d", - "Plan": [ - "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#10)]", - " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", - " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#10, Column#9", - " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " │ └─Projection 8000.00 mpp[tiflash] Column#9, test.employee.deptid", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#9, funcs:firstrow(Column#15)->test.employee.deptid", - " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#27, funcs:count(Column#25)->Column#14, funcs:firstrow(Column#26)->Column#15", - " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#25, test.employee.deptid->Column#26, plus(test.employee.deptid, 1)->Column#27", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.d = e2.d", - "Plan": [ - "TableReader 6400.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 6400.00 mpp[tiflash] inner join, equal:[eq(Column#6, Column#12)]", - " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", - " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", - " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#17, funcs:sum(Column#18)->Column#5, funcs:firstrow(Column#19)->test.employee.deptid", - " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#17, collate: binary]", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#43, funcs:count(Column#41)->Column#18, funcs:firstrow(Column#42)->Column#19", - " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#41, test.employee.deptid->Column#42, plus(test.employee.deptid, 1)->Column#43", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─Projection(Probe) 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#12, Column#11", - " └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " └─Projection 8000.00 mpp[tiflash] Column#11, test.employee.deptid", - " └─HashAgg 8000.00 mpp[tiflash] group by:Column#20, funcs:sum(Column#21)->Column#11, funcs:firstrow(Column#22)->test.employee.deptid", - " └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#20, collate: binary]", - " └─HashAgg 8000.00 mpp[tiflash] group by:Column#46, funcs:count(Column#44)->Column#21, funcs:firstrow(Column#45)->Column#22", - " └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#44, test.employee.deptid->Column#45, plus(test.employee.deptid, 1)->Column#46", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "set tidb_broadcast_join_threshold_count=1", - "Plan": null - }, - { - "SQL": "set tidb_broadcast_join_threshold_size=1", - "Plan": null - }, - { - "SQL": "select * from (select count(distinct deptid) a from employee) e1 join employee e2 on e1.a = e2.deptid", - "Plan": [ - "Projection 1.25 root Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", - "└─HashJoin 1.25 root inner join, equal:[eq(test.employee.deptid, Column#5)]", - " ├─TableReader(Build) 1.00 root MppVersion: 2, data:ExchangeSender", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - " │ └─Projection 1.00 mpp[tiflash] Column#5", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#12)->Column#5", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#12", - " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", - " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─TableReader(Probe) 9990.00 root MppVersion: 2, data:ExchangeSender", - " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from (select count(distinct deptid) a from employee) e1 join (select count(distinct deptid) b from employee) e2 on e1.a=e2.b", - "Plan": [ - "HashJoin 1.00 root inner join, equal:[eq(Column#5, Column#10)]", - "├─TableReader(Build) 1.00 root MppVersion: 2, data:ExchangeSender", - "│ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - "│ └─Projection 1.00 mpp[tiflash] Column#10", - "│ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#16)->Column#10", - "│ └─ExchangeReceiver 1.00 mpp[tiflash] ", - "│ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - "│ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#16", - "│ └─ExchangeReceiver 1.00 mpp[tiflash] ", - "│ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - "│ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - "│ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - "└─TableReader(Probe) 1.00 root MppVersion: 2, data:ExchangeSender", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 1.00 mpp[tiflash] Column#5", - " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#15)->Column#5", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", - " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#15", - " └─ExchangeReceiver 1.00 mpp[tiflash] ", - " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from employee e1 join employee e2 on e1.deptid = e2.deptid", - "Plan": [ - "TableReader 12487.50 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 12487.50 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 12487.50 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, test.employee.deptid)]", - " ├─ExchangeReceiver(Build) 9990.00 mpp[tiflash] ", - " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo", - " └─ExchangeReceiver(Probe) 9990.00 mpp[tiflash] ", - " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", - " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join employee e2 on e1.d = e2.deptid", - "Plan": [ - "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 8000.00 mpp[tiflash] Column#6, Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", - " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#6)]", - " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", - " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#6, collate: binary]", - " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", - " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#5, funcs:firstrow(Column#15)->test.employee.deptid", - " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#29, funcs:count(Column#27)->Column#14, funcs:firstrow(Column#28)->Column#15", - " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#27, test.employee.deptid->Column#28, plus(test.employee.deptid, 1)->Column#29", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─ExchangeReceiver(Probe) 9990.00 mpp[tiflash] ", - " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#26, collate: binary]", - " └─Projection 9990.00 mpp[tiflash] test.employee.empid, test.employee.deptid, test.employee.salary, cast(test.employee.deptid, bigint(20))->Column#26", - " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from employee e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.deptid = e2.d", - "Plan": [ - "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 8000.00 mpp[tiflash] test.employee.empid, test.employee.deptid, test.employee.salary, Column#10, Column#9", - " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#10)]", - " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", - " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#10, collate: binary]", - " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#10, Column#9", - " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " │ └─Projection 8000.00 mpp[tiflash] Column#9, test.employee.deptid", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#9, funcs:firstrow(Column#15)->test.employee.deptid", - " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#29, funcs:count(Column#27)->Column#14, funcs:firstrow(Column#28)->Column#15", - " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#27, test.employee.deptid->Column#28, plus(test.employee.deptid, 1)->Column#29", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─ExchangeReceiver(Probe) 9990.00 mpp[tiflash] ", - " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#26, collate: binary]", - " └─Projection 9990.00 mpp[tiflash] test.employee.empid, test.employee.deptid, test.employee.salary, cast(test.employee.deptid, bigint(20))->Column#26", - " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", - " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" - ] - }, - { - "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.d = e2.d", - "Plan": [ - "TableReader 6400.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashJoin 6400.00 mpp[tiflash] inner join, equal:[eq(Column#6, Column#12)]", - " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", - " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#6, collate: binary]", - " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", - " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#17, funcs:sum(Column#18)->Column#5, funcs:firstrow(Column#19)->test.employee.deptid", - " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#17, collate: binary]", - " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#43, funcs:count(Column#41)->Column#18, funcs:firstrow(Column#42)->Column#19", - " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#41, test.employee.deptid->Column#42, plus(test.employee.deptid, 1)->Column#43", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", - " └─ExchangeReceiver(Probe) 6400.00 mpp[tiflash] ", - " └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#12, collate: binary]", - " └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#12, Column#11", - " └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", - " └─Projection 8000.00 mpp[tiflash] Column#11, test.employee.deptid", - " └─HashAgg 8000.00 mpp[tiflash] group by:Column#20, funcs:sum(Column#21)->Column#11, funcs:firstrow(Column#22)->test.employee.deptid", - " └─ExchangeReceiver 8000.00 mpp[tiflash] ", - " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#20, collate: binary]", - " └─HashAgg 8000.00 mpp[tiflash] group by:Column#46, funcs:count(Column#44)->Column#21, funcs:firstrow(Column#45)->Column#22", - " └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#44, test.employee.deptid->Column#45, plus(test.employee.deptid, 1)->Column#46", - " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestSemiJoinRewriteHints", - "Cases": [ - { - "SQL": "select /*+ SEMI_JOIN_REWRITE() */ * from t", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": "[planner:1815]The SEMI_JOIN_REWRITE hint is not used correctly, maybe it's not in a subquery or the subquery is not EXISTS clause." - }, - { - "SQL": "select * from t where a > (select /*+ SEMI_JOIN_REWRITE() */ min(b) from t t1 where t1.c = t.c)", - "Plan": [ - "HashJoin 7992.00 root inner join, equal:[eq(test.t.c, test.t.c)], other cond:gt(test.t.a, Column#9)", - "├─Selection(Build) 6393.60 root not(isnull(Column#9))", - "│ └─HashAgg 7992.00 root group by:test.t.c, funcs:min(Column#10)->Column#9, funcs:firstrow(test.t.c)->test.t.c", - "│ └─TableReader 7992.00 root data:HashAgg", - "│ └─HashAgg 7992.00 cop[tikv] group by:test.t.c, funcs:min(test.t.b)->Column#10", - "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.c))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9980.01 root data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t.a)), not(isnull(test.t.c))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": "[planner:1815]The SEMI_JOIN_REWRITE hint is not used correctly, maybe it's not in a subquery or the subquery is not EXISTS clause." - }, - { - "SQL": "select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 where t1.a=t.a)", - "Plan": [ - "HashJoin 9990.00 root inner join, equal:[eq(test.t.a, test.t.a)]", - "├─HashAgg(Build) 7992.00 root group by:test.t.a, funcs:firstrow(test.t.a)->test.t.a", - "│ └─TableReader 7992.00 root data:HashAgg", - "│ └─HashAgg 7992.00 cop[tikv] group by:test.t.a, ", - "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.a))", - "│ └─TableFullScan 10000.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.t.a))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": "" - }, - { - "SQL": "select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ t.b from t t1 where t1.a=t.a)", - "Plan": [ - "HashJoin 9990.00 root inner join, equal:[eq(test.t.a, test.t.a)]", - "├─HashAgg(Build) 7992.00 root group by:test.t.a, funcs:firstrow(test.t.a)->test.t.a", - "│ └─TableReader 7992.00 root data:HashAgg", - "│ └─HashAgg 7992.00 cop[tikv] group by:test.t.a, ", - "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.a))", - "│ └─TableFullScan 10000.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.t.a))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": "" - }, - { - "SQL": "select exists(select /*+ SEMI_JOIN_REWRITE() */ * from t t1 where t1.a=t.a) from t", - "Plan": [ - "HashJoin 10000.00 root left outer semi join, equal:[eq(test.t.a, test.t.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": "[planner:1815]SEMI_JOIN_REWRITE() is inapplicable for LeftOuterSemiJoin." - }, - { - "SQL": "select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 where t1.a > t.a)", - "Plan": [ - "HashJoin 7992.00 root CARTESIAN semi join, other cond:gt(test.t.a, test.t.a)", - "├─TableReader(Build) 9990.00 root data:Selection", - "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.a))", - "│ └─TableFullScan 10000.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.t.a))", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": "[planner:1815]SEMI_JOIN_REWRITE() is inapplicable for SemiJoin with left conditions or other conditions." - } - ] - }, - { - "Name": "TestHJBuildAndProbeHint", - "Cases": [ - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root left outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 " - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root left outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 " - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root left outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 " - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root left outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 " - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root right outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - " 2" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root right outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - " 2" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root right outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - " 2" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root right outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - " 2" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root anti semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root anti semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root anti semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b)", - "Plan": [ - "HashJoin 8000.00 root anti semi join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root anti left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "0" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root anti left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "0" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root anti left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "0" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1", - "Plan": [ - "HashAgg 1.00 root funcs:sum(Column#9)->Column#8", - "└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9", - " └─MergeJoin 10000.00 root anti left outer semi join, left key:test.t1.a, right key:test.t2.a", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "0" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint", - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 There are no matching table names for (t2) in optimizer hint /*+ HASH_JOIN_PROBE(t2, t2) */. Maybe you can use the table alias name" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 There are no matching table names for (t1) in optimizer hint /*+ HASH_JOIN_BUILD(t1, t1) */. Maybe you can use the table alias name" - ] - }, - { - "SQL": "select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 There are no matching table names for (tt) in optimizer hint /*+ HASH_JOIN_PROBE(tt) */. Maybe you can use the table alias name" - ] - }, - { - "SQL": "select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 There are no matching table names for (tt) in optimizer hint /*+ HASH_JOIN_BUILD(tt) */. Maybe you can use the table alias name" - ] - }, - { - "SQL": "select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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:tt keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "Projection 15625.00 root test.t1.a, test.t2.a", - "└─HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - " └─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t2.a, test.t1.a) eq(test.t2.b, test.t1.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "Projection 15625.00 root test.t1.a, test.t2.a", - "└─HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - " └─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t2.a, test.t1.a) eq(test.t2.b, test.t1.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a", - "Plan": [ - "HashJoin 15625.00 root inner join, equal:[eq(test.t2.a, test.t3.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1" - ], - "Warning": [ - "Warning 1815 Join hints are conflict, you can only specify one type of join" - ] - }, - { - "SQL": "SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "HashJoin 10000.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─StreamAgg(Build) 8000.00 root group by:test.t2.a, funcs:firstrow(test.t2.a)->test.t2.a", - "│ └─TableReader 8000.00 root data:StreamAgg", - "│ └─StreamAgg 8000.00 cop[tikv] group by:test.t2.a, ", - "│ └─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:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "HashJoin 10000.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─StreamAgg(Probe) 8000.00 root group by:test.t2.a, funcs:firstrow(test.t2.a)->test.t2.a", - " └─TableReader 8000.00 root data:StreamAgg", - " └─StreamAgg 8000.00 cop[tikv] group by:test.t2.a, ", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "HashJoin 10000.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─StreamAgg(Probe) 8000.00 root group by:test.t2.a, funcs:firstrow(test.t2.a)->test.t2.a", - " └─TableReader 8000.00 root data:StreamAgg", - " └─StreamAgg 8000.00 cop[tikv] group by:test.t2.a, ", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a);", - "Plan": [ - "HashJoin 10000.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─StreamAgg(Build) 8000.00 root group by:test.t2.a, funcs:firstrow(test.t2.a)->test.t2.a", - "│ └─TableReader 8000.00 root data:StreamAgg", - "│ └─StreamAgg 8000.00 cop[tikv] group by:test.t2.a, ", - "│ └─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:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "MergeJoin 12500.00 root inner join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "MergeJoin 12500.00 root inner join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "HashJoin 12500.00 root inner join, equal:[eq(test.t1.a, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": null - }, - { - "SQL": "SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - }, - { - "SQL": "SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2);", - "Plan": [ - "MergeJoin 8000.00 root semi join, left key:test.t1.a, right key:test.t2.a", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint" - ] - } - ] - }, - { - "Name": "TestHJBuildAndProbeHint4StaticPartitionTable", - "Cases": [ - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 49900.05 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─PartitionUnion(Build) 49900.05 root ", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo", - "│ └─TableReader 9980.01 root data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo", - "└─PartitionUnion(Probe) 39920.04 root ", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo", - " └─TableReader 9980.01 root data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 49900.05 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─PartitionUnion(Build) 39920.04 root ", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo", - "│ └─TableReader 9980.01 root data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo", - "└─PartitionUnion(Probe) 49900.05 root ", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo", - " └─TableReader 9980.01 root data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 49900.05 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─PartitionUnion(Build) 39920.04 root ", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo", - "│ └─TableReader 9980.01 root data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo", - "└─PartitionUnion(Probe) 49900.05 root ", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo", - " └─TableReader 9980.01 root data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 49900.05 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─PartitionUnion(Build) 49900.05 root ", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo", - "│ ├─TableReader 9980.01 root data:Selection", - "│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo", - "│ └─TableReader 9980.01 root data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo", - "└─PartitionUnion(Probe) 39920.04 root ", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo", - " ├─TableReader 9980.01 root data:Selection", - " │ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo", - " └─TableReader 9980.01 root data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - } - ] - }, - { - "Name": "TestHJBuildAndProbeHint4DynamicPartitionTable", - "Cases": [ - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 9980.01 root partition:all data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9980.01 root partition:all data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 9980.01 root partition:all data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9980.01 root partition:all data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 9980.01 root partition:all data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9980.01 root partition:all data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - "├─TableReader(Build) 9980.01 root partition:all data:Selection", - "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9980.01 root partition:all data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1" - ], - "Warning": null - } - ] - }, - { - "Name": "TestHJBuildAndProbeHint4TiFlash", - "Cases": [ - { - "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", - " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", - " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo", - " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", - " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", - " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo", - " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", - " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", - " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo", - " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", - "Plan": [ - "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", - "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", - " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", - " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", - " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", - " │ └─TableFullScan 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo", - " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo" - ], - "Warning": null - } - ] - }, - { - "Name": "TestNoDecorrelateHint", - "Cases": [ - { - "SQL": "select /*+ no_decorrelate() */ * from t1", - "Plan": [ - "TableReader 10000.00 root data:TableFullScan", - "└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 2" - ], - "Warning": [ - "Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery." + "TableReader 10000.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 10000.00 mpp[tiflash] CARTESIAN inner join", + " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Projection 1.00 mpp[tiflash] Column#9, Column#10", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#9, funcs:count(distinct test.employee.empid)->Column#10", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, test.employee.empid, ", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" ] }, { - "SQL": "select * from t1, (select /*+ no_decorrelate() */ * from t2) n", + "SQL": "select * from employee e1 join (select count(distinct deptid) a from employee) e2 on e1.deptid = e2.a", "Plan": [ - "HashJoin 100000000.00 root CARTESIAN inner join", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1 1 1", - "1 1 2 1", - "2 2 1 1", - "2 2 2 1" - ], - "Warning": [ - "Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery." + "TableReader 1.25 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 1.25 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 1.25 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#9)]", + " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Projection 1.00 mpp[tiflash] Column#9", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#10)->Column#9", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#10", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" ] }, { - "SQL": "select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n", + "SQL": "select * from (select count(distinct deptid) a from employee) e1 join employee e2 on e1.a = e2.deptid", "Plan": [ - "Projection 10000.00 root plus(test.t1.a, 1)->Column#4, minus(test.t1.b, 1)->Column#5", - "└─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "2 0", - "3 1" - ], - "Warning": [ - "Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery." + "TableReader 1.25 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 1.25 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 1.25 mpp[tiflash] Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", + " └─HashJoin 1.25 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#5)]", + " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Projection 1.00 mpp[tiflash] Column#5", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#10)->Column#5", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#10", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" ] }, { - "SQL": "select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3", + "SQL": "select * from (select count(distinct deptid) a from employee) e1 join (select count(distinct deptid) b from employee) e2 on e1.a=e2.b", "Plan": [ - "HashJoin 10000.00 root left outer semi join, equal:[eq(test.t3.a, test.t1.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo" - ], - "Result": [ - "1", - "1" - ], - "Warning": [ - "Warning 1815 NO_DECORRELATE() and SEMI_JOIN_REWRITE() are in conflict. Both will be ineffective." + "TableReader 1.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 1.00 mpp[tiflash] inner join, equal:[eq(Column#5, Column#10)]", + " ├─ExchangeReceiver(Build) 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Projection 1.00 mpp[tiflash] Column#5", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#11)->Column#5", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#11", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─Projection(Probe) 1.00 mpp[tiflash] Column#10", + " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#12)->Column#10", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#12", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" ] }, { - "SQL": "select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b)", - "Plan": [ - "HashJoin 7984.01 root semi join, equal:[eq(test.t1.b, test.t2.a) eq(test.t1.a, test.t2.b)]", - "├─TableReader(Build) 9990.00 root data:Selection", - "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.b))", - "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - "└─TableReader(Probe) 9980.01 root data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1" - ], - "Warning": null - }, - { - "SQL": "select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b)", - "Plan": [ - "Projection 9990.00 root test.t1.a", - "└─Apply 9990.00 root semi join, equal:[eq(test.t1.a, test.t2.b)]", - " ├─TableReader(Build) 9990.00 root data:Selection", - " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t1.a))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─TableReader(Probe) 99800.10 root data:Selection", - " └─Selection 99800.10 cop[tikv] not(isnull(test.t2.b))", - " └─TableRangeScan 9990.00 cop[tikv] table:t2 range: decided by [eq(test.t2.a, test.t1.b)], keep order:false, stats:pseudo" - ], - "Result": [ - "1" - ], - "Warning": null - }, - { - "SQL": "select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b)", - "Plan": [ - "Projection 8000.00 root test.t1.a", - "└─Selection 8000.00 root Column#6", - " └─HashJoin 10000.00 root left outer semi join, equal:[eq(test.t1.b, test.t2.a)], other cond:eq(test.t1.a, test.t2.b)", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─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" - ], - "Result": [ - "1" - ], - "Warning": null - }, - { - "SQL": "select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b)", - "Plan": [ - "Projection 8000.00 root test.t1.a", - "└─Selection 8000.00 root Column#6", - " └─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.a, test.t2.b)", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(test.t2.a, test.t1.b)], keep order:false, stats:pseudo" - ], - "Result": [ - "1" - ], - "Warning": null - }, - { - "SQL": "select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1", - "Plan": [ - "Projection 10000.00 root test.t1.a, and(or(or(gt(Column#9, 1), ne(test.t1.a, Column#8)), if(ne(Column#10, 0), , 0)), and(ne(Column#11, 0), if(isnull(test.t1.a), , 1)))->Column#12", - "└─Apply 10000.00 root CARTESIAN inner join", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─StreamAgg(Probe) 10000.00 root funcs:max(Column#14)->Column#8, funcs:count(distinct Column#15)->Column#9, funcs:sum(Column#16)->Column#10, funcs:count(1)->Column#11", - " └─Projection 10000.00 root test.t2.b->Column#14, test.t2.b->Column#15, cast(isnull(test.t2.b), decimal(20,0) BINARY)->Column#16", - " └─TableReader 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(test.t2.a, test.t1.b)], keep order:false, stats:pseudo" - ], - "Result": [ - "1 0", - "2 1" - ], - "Warning": null - }, - { - "SQL": "select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1", + "SQL": "select * from employee e1 join employee e2 on e1.deptid = e2.deptid", "Plan": [ - "Projection 10000.00 root test.t1.a, and(or(or(gt(Column#9, 1), ne(test.t1.a, Column#8)), if(ne(Column#10, 0), , 0)), and(ne(Column#11, 0), if(isnull(test.t1.a), , 1)))->Column#12", - "└─Apply 10000.00 root CARTESIAN inner join", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─StreamAgg(Probe) 10000.00 root funcs:max(Column#14)->Column#8, funcs:count(distinct Column#15)->Column#9, funcs:sum(Column#16)->Column#10, funcs:count(1)->Column#11", - " └─Projection 10000.00 root test.t2.b->Column#14, test.t2.b->Column#15, cast(isnull(test.t2.b), decimal(20,0) BINARY)->Column#16", - " └─TableReader 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(test.t2.a, test.t1.b)], keep order:false, stats:pseudo" - ], - "Result": [ - "1 0", - "2 1" - ], - "Warning": null + "TableReader 12487.50 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 12487.50 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 12487.50 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, test.employee.deptid)]", + " ├─ExchangeReceiver(Build) 9990.00 mpp[tiflash] ", + " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo", + " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1", + "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join employee e2 on e1.d = e2.deptid", "Plan": [ - "Projection 10000.00 root test.t1.a, or(and(gt(test.t1.a, Column#8), if(ne(Column#9, 0), , 1)), or(eq(Column#10, 0), if(isnull(test.t1.a), , 0)))->Column#11", - "└─Apply 10000.00 root CARTESIAN inner join", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─StreamAgg(Probe) 10000.00 root funcs:max(Column#19)->Column#8, funcs:sum(Column#20)->Column#9, funcs:count(1)->Column#10", - " └─Projection 10000.00 root test.t2.b->Column#19, cast(isnull(test.t2.b), decimal(20,0) BINARY)->Column#20", - " └─TableReader 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(test.t2.a, test.t1.b)], keep order:false, stats:pseudo" - ], - "Result": [ - "1 0", - "2 1" - ], - "Warning": null + "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 8000.00 mpp[tiflash] Column#6, Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", + " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#6)]", + " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", + " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", + " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#5, funcs:firstrow(Column#15)->test.employee.deptid", + " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#27, funcs:count(Column#25)->Column#14, funcs:firstrow(Column#26)->Column#15", + " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#25, test.employee.deptid->Column#26, plus(test.employee.deptid, 1)->Column#27", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1", + "SQL": "select * from employee e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.deptid = e2.d", "Plan": [ - "Projection 10000.00 root test.t1.a, or(and(gt(test.t1.a, Column#8), if(ne(Column#9, 0), , 1)), or(eq(Column#10, 0), if(isnull(test.t1.a), , 0)))->Column#11", - "└─Apply 10000.00 root CARTESIAN inner join", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─StreamAgg(Probe) 10000.00 root funcs:max(Column#19)->Column#8, funcs:sum(Column#20)->Column#9, funcs:count(1)->Column#10", - " └─Projection 10000.00 root test.t2.b->Column#19, cast(isnull(test.t2.b), decimal(20,0) BINARY)->Column#20", - " └─TableReader 10000.00 root data:TableRangeScan", - " └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(test.t2.a, test.t1.b)], keep order:false, stats:pseudo" - ], - "Result": [ - "1 0", - "2 1" - ], - "Warning": null + "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#10)]", + " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", + " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#10, Column#9", + " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " │ └─Projection 8000.00 mpp[tiflash] Column#9, test.employee.deptid", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#9, funcs:firstrow(Column#15)->test.employee.deptid", + " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#27, funcs:count(Column#25)->Column#14, funcs:firstrow(Column#26)->Column#15", + " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#25, test.employee.deptid->Column#26, plus(test.employee.deptid, 1)->Column#27", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1", + "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.d = e2.d", "Plan": [ - "HashJoin 12500.00 root left outer join, equal:[eq(test.t1.b, test.t2.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─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" - ], - "Result": [ - "1 1", - "2 1" - ], - "Warning": null + "TableReader 6400.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 6400.00 mpp[tiflash] inner join, equal:[eq(Column#6, Column#12)]", + " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", + " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", + " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#17, funcs:sum(Column#18)->Column#5, funcs:firstrow(Column#19)->test.employee.deptid", + " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#17, collate: binary]", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#43, funcs:count(Column#41)->Column#18, funcs:firstrow(Column#42)->Column#19", + " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#41, test.employee.deptid->Column#42, plus(test.employee.deptid, 1)->Column#43", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─Projection(Probe) 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#12, Column#11", + " └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " └─Projection 8000.00 mpp[tiflash] Column#11, test.employee.deptid", + " └─HashAgg 8000.00 mpp[tiflash] group by:Column#20, funcs:sum(Column#21)->Column#11, funcs:firstrow(Column#22)->test.employee.deptid", + " └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#20, collate: binary]", + " └─HashAgg 8000.00 mpp[tiflash] group by:Column#46, funcs:count(Column#44)->Column#21, funcs:firstrow(Column#45)->Column#22", + " └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#44, test.employee.deptid->Column#45, plus(test.employee.deptid, 1)->Column#46", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" + ] }, { - "SQL": "select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1", - "Plan": [ - "Projection 10000.00 root test.t1.a, test.t2.b", - "└─Apply 10000.00 root CARTESIAN left outer join", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─MaxOneRow(Probe) 10000.00 root ", - " └─TableReader 2000.00 root data:TableRangeScan", - " └─TableRangeScan 2000.00 cop[tikv] table:t2 range: decided by [eq(test.t2.a, test.t1.b)], keep order:false, stats:pseudo" - ], - "Result": [ - "1 1", - "2 1" - ], - "Warning": null + "SQL": "set tidb_broadcast_join_threshold_count=1", + "Plan": null }, { - "SQL": "select t1.a, t1.b not in (select t3.b from t3) from t1", - "Plan": [ - "HashJoin 10000.00 root Null-aware anti left outer semi join, equal:[eq(test.t1.b, test.t3.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1 0", - "2 1" - ], - "Warning": null + "SQL": "set tidb_broadcast_join_threshold_size=1", + "Plan": null }, { - "SQL": "select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1", + "SQL": "select * from (select count(distinct deptid) a from employee) e1 join employee e2 on e1.a = e2.deptid", "Plan": [ - "HashJoin 10000.00 root Null-aware anti left outer semi join, equal:[eq(test.t1.b, test.t3.b)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1 0", - "2 1" - ], - "Warning": [ - "Warning 1815 NO_DECORRELATE() is inapplicable because there are no correlated columns." + "Projection 1.25 root Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", + "└─HashJoin 1.25 root inner join, equal:[eq(test.employee.deptid, Column#5)]", + " ├─TableReader(Build) 1.00 root MppVersion: 2, data:ExchangeSender", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + " │ └─Projection 1.00 mpp[tiflash] Column#5", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#12)->Column#5", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " │ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#12", + " │ └─ExchangeReceiver 1.00 mpp[tiflash] ", + " │ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " │ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─TableReader(Probe) 9990.00 root MppVersion: 2, data:ExchangeSender", + " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" ] }, { - "SQL": "select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1", + "SQL": "select * from (select count(distinct deptid) a from employee) e1 join (select count(distinct deptid) b from employee) e2 on e1.a=e2.b", "Plan": [ - "HashJoin 10000.00 root left outer semi join, equal:[eq(test.t1.b, test.t3.a)]", - "├─TableReader(Build) 10000.00 root data:TableFullScan", - "│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1", - "1" - ], - "Warning": null + "HashJoin 1.00 root inner join, equal:[eq(Column#5, Column#10)]", + "├─TableReader(Build) 1.00 root MppVersion: 2, data:ExchangeSender", + "│ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + "│ └─Projection 1.00 mpp[tiflash] Column#10", + "│ └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#16)->Column#10", + "│ └─ExchangeReceiver 1.00 mpp[tiflash] ", + "│ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + "│ └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#16", + "│ └─ExchangeReceiver 1.00 mpp[tiflash] ", + "│ └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + "│ └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + "│ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + "└─TableReader(Probe) 1.00 root MppVersion: 2, data:ExchangeSender", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 1.00 mpp[tiflash] Column#5", + " └─HashAgg 1.00 mpp[tiflash] funcs:sum(Column#15)->Column#5", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST", + " └─HashAgg 1.00 mpp[tiflash] funcs:count(distinct test.employee.deptid)->Column#15", + " └─ExchangeReceiver 1.00 mpp[tiflash] ", + " └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " └─HashAgg 1.00 mpp[tiflash] group by:test.employee.deptid, ", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" + ] }, { - "SQL": "select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1", + "SQL": "select * from employee e1 join employee e2 on e1.deptid = e2.deptid", "Plan": [ - "Projection 10000.00 root Column#10", - "└─Apply 10000.00 root CARTESIAN left outer semi join", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─Limit(Probe) 20000.00 root offset:0, count:2", - " └─TableReader 20000.00 root data:Limit", - " └─Limit 20000.00 cop[tikv] offset:0, count:2", - " └─Selection 20000.00 cop[tikv] eq(test.t3.a, test.t1.b)", - " └─TableFullScan 20000000.00 cop[tikv] table:t3 keep order:false, stats:pseudo" - ], - "Result": [ - "1", - "1" - ], - "Warning": null + "TableReader 12487.50 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 12487.50 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 12487.50 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, test.employee.deptid)]", + " ├─ExchangeReceiver(Build) 9990.00 mpp[tiflash] ", + " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo", + " └─ExchangeReceiver(Probe) 9990.00 mpp[tiflash] ", + " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]", + " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1", + "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join employee e2 on e1.d = e2.deptid", "Plan": [ - "Projection 1.00 root test.t1.a, Column#6->Column#11", - "└─HashJoin 1.00 root CARTESIAN left outer join", - " ├─Point_Get(Build) 1.00 root table:t2 handle:10", - " └─HashAgg(Probe) 1.00 root funcs:sum(Column#13)->Column#6, funcs:firstrow(Column#14)->test.t1.a", - " └─TableReader 1.00 root data:HashAgg", - " └─HashAgg 1.00 cop[tikv] funcs:sum(test.t1.a)->Column#13, funcs:firstrow(test.t1.a)->Column#14", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "1 3" - ], - "Warning": null + "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 8000.00 mpp[tiflash] Column#6, Column#5, test.employee.empid, test.employee.deptid, test.employee.salary", + " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#6)]", + " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", + " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#6, collate: binary]", + " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", + " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#5, funcs:firstrow(Column#15)->test.employee.deptid", + " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#29, funcs:count(Column#27)->Column#14, funcs:firstrow(Column#28)->Column#15", + " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#27, test.employee.deptid->Column#28, plus(test.employee.deptid, 1)->Column#29", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─ExchangeReceiver(Probe) 9990.00 mpp[tiflash] ", + " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#26, collate: binary]", + " └─Projection 9990.00 mpp[tiflash] test.employee.empid, test.employee.deptid, test.employee.salary, cast(test.employee.deptid, bigint(20))->Column#26", + " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e2 pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1", + "SQL": "select * from employee e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.deptid = e2.d", "Plan": [ - "Projection 1.00 root test.t1.a, Column#9->Column#11", - "└─Apply 1.00 root CARTESIAN left outer join", - " ├─HashAgg(Build) 1.00 root funcs:sum(Column#14)->Column#6, funcs:firstrow(Column#15)->test.t1.a", - " │ └─Projection 10000.00 root cast(test.t1.a, decimal(10,0) BINARY)->Column#14, test.t1.a->Column#15", - " │ └─TableReader 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─MaxOneRow(Probe) 1.00 root ", - " └─Projection 1.00 root Column#6->Column#9", - " └─Point_Get 1.00 root table:t2 handle:10" - ], - "Result": [ - "1 " - ], - "Warning": null + "TableReader 8000.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 8000.00 mpp[tiflash] test.employee.empid, test.employee.deptid, test.employee.salary, Column#10, Column#9", + " └─HashJoin 8000.00 mpp[tiflash] inner join, equal:[eq(test.employee.deptid, Column#10)]", + " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", + " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#10, collate: binary]", + " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#10, Column#9", + " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " │ └─Projection 8000.00 mpp[tiflash] Column#9, test.employee.deptid", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#13, funcs:sum(Column#14)->Column#9, funcs:firstrow(Column#15)->test.employee.deptid", + " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#13, collate: binary]", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#29, funcs:count(Column#27)->Column#14, funcs:firstrow(Column#28)->Column#15", + " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#27, test.employee.deptid->Column#28, plus(test.employee.deptid, 1)->Column#29", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─ExchangeReceiver(Probe) 9990.00 mpp[tiflash] ", + " └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#26, collate: binary]", + " └─Projection 9990.00 mpp[tiflash] test.employee.empid, test.employee.deptid, test.employee.salary, cast(test.employee.deptid, bigint(20))->Column#26", + " └─Selection 9990.00 mpp[tiflash] not(isnull(test.employee.deptid))", + " └─TableFullScan 10000.00 mpp[tiflash] table:e1 pushed down filter:empty, keep order:false, stats:pseudo" + ] }, { - "SQL": "select (select count(t3.a) from t3 where t3.b = t1.b) from t1;", + "SQL": "select * from (select deptid+1 d, count(empid) a from employee group by d) e1 join (select deptid+1 d, count(empid) a from employee group by d) e2 on e1.d = e2.d", "Plan": [ - "Projection 10000.00 root ifnull(Column#10, 0)->Column#10", - "└─HashJoin 10000.00 root left outer join, equal:[eq(test.t1.b, test.t3.b)]", - " ├─HashAgg(Build) 7992.00 root group by:test.t3.b, funcs:count(Column#11)->Column#10, funcs:firstrow(test.t3.b)->test.t3.b", - " │ └─TableReader 7992.00 root data:HashAgg", - " │ └─HashAgg 7992.00 cop[tikv] group by:test.t3.b, funcs:count(test.t3.a)->Column#11", - " │ └─Selection 9990.00 cop[tikv] not(isnull(test.t3.b))", - " │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Result": [ - "0", - "2" - ], - "Warning": null - }, + "TableReader 6400.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: PassThrough", + " └─HashJoin 6400.00 mpp[tiflash] inner join, equal:[eq(Column#6, Column#12)]", + " ├─ExchangeReceiver(Build) 6400.00 mpp[tiflash] ", + " │ └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#6, collate: binary]", + " │ └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#6, Column#5", + " │ └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " │ └─Projection 8000.00 mpp[tiflash] Column#5, test.employee.deptid", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#17, funcs:sum(Column#18)->Column#5, funcs:firstrow(Column#19)->test.employee.deptid", + " │ └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#17, collate: binary]", + " │ └─HashAgg 8000.00 mpp[tiflash] group by:Column#43, funcs:count(Column#41)->Column#18, funcs:firstrow(Column#42)->Column#19", + " │ └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#41, test.employee.deptid->Column#42, plus(test.employee.deptid, 1)->Column#43", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo", + " └─ExchangeReceiver(Probe) 6400.00 mpp[tiflash] ", + " └─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#12, collate: binary]", + " └─Projection 6400.00 mpp[tiflash] plus(test.employee.deptid, 1)->Column#12, Column#11", + " └─Selection 6400.00 mpp[tiflash] not(isnull(plus(test.employee.deptid, 1)))", + " └─Projection 8000.00 mpp[tiflash] Column#11, test.employee.deptid", + " └─HashAgg 8000.00 mpp[tiflash] group by:Column#20, funcs:sum(Column#21)->Column#11, funcs:firstrow(Column#22)->test.employee.deptid", + " └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#20, collate: binary]", + " └─HashAgg 8000.00 mpp[tiflash] group by:Column#46, funcs:count(Column#44)->Column#21, funcs:firstrow(Column#45)->Column#22", + " └─Projection 10000.00 mpp[tiflash] test.employee.empid->Column#44, test.employee.deptid->Column#45, plus(test.employee.deptid, 1)->Column#46", + " └─TableFullScan 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" + ] + } + ] + }, + { + "Name": "TestSemiJoinRewriteHints", + "Cases": [ { - "SQL": "select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1;", + "SQL": "select /*+ SEMI_JOIN_REWRITE() */ * from t", "Plan": [ - "Projection 10000.00 root Column#10", - "└─Apply 10000.00 root CARTESIAN left outer join", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─MaxOneRow(Probe) 10000.00 root ", - " └─StreamAgg 10000.00 root funcs:count(Column#12)->Column#10", - " └─TableReader 10000.00 root data:StreamAgg", - " └─StreamAgg 10000.00 cop[tikv] funcs:count(test.t3.a)->Column#12", - " └─Selection 100000.00 cop[tikv] eq(test.t3.b, test.t1.b)", - " └─TableFullScan 100000000.00 cop[tikv] table:t3 keep order:false, stats:pseudo" - ], - "Result": [ - "0", - "2" + "TableReader 10000.00 root data:TableFullScan", + "└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], - "Warning": null + "Warning": "[planner:1815]The SEMI_JOIN_REWRITE hint is not used correctly, maybe it's not in a subquery or the subquery is not EXISTS clause." }, { - "SQL": "SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", + "SQL": "select * from t where a > (select /*+ SEMI_JOIN_REWRITE() */ min(b) from t t1 where t1.c = t.c)", "Plan": [ - "HashJoin 250.00 root left outer join, equal:[eq(test.ta.id, test.tb.id)]", - "├─TableReader(Build) 250.00 root data:Selection", - "│ └─Selection 250.00 cop[tikv] like(test.ta.name, \"chad999%\", 92)", - "│ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - "└─HashAgg(Probe) 7992.00 root group by:test.tb.id, funcs:sum(Column#19)->Column#13, funcs:firstrow(test.tb.id)->test.tb.id", - " └─TableReader 7992.00 root data:HashAgg", - " └─HashAgg 7992.00 cop[tikv] group by:test.tb.id, funcs:sum(test.tb.code)->Column#19", - " └─Selection 9990.00 cop[tikv] not(isnull(test.tb.id))", - " └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo" + "HashJoin 7992.00 root inner join, equal:[eq(test.t.c, test.t.c)], other cond:gt(test.t.a, Column#9)", + "├─Selection(Build) 6393.60 root not(isnull(Column#9))", + "│ └─HashAgg 7992.00 root group by:test.t.c, funcs:min(Column#10)->Column#9, funcs:firstrow(test.t.c)->test.t.c", + "│ └─TableReader 7992.00 root data:HashAgg", + "│ └─HashAgg 7992.00 cop[tikv] group by:test.t.c, funcs:min(test.t.b)->Column#10", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.c))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9980.01 root data:Selection", + " └─Selection 9980.01 cop[tikv] not(isnull(test.t.a)), not(isnull(test.t.c))", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], - "Result": null, - "Warning": null + "Warning": "[planner:1815]The SEMI_JOIN_REWRITE hint is not used correctly, maybe it's not in a subquery or the subquery is not EXISTS clause." }, { - "SQL": "SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", + "SQL": "select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 where t1.a=t.a)", "Plan": [ - "Projection 250.00 root test.ta.name, Column#13", - "└─Apply 250.00 root CARTESIAN left outer join", - " ├─TableReader(Build) 250.00 root data:Selection", - " │ └─Selection 250.00 cop[tikv] like(test.ta.name, \"chad999%\", 92)", - " │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - " └─MaxOneRow(Probe) 250.00 root ", - " └─StreamAgg 250.00 root funcs:sum(Column#21)->Column#13", - " └─Projection 2500.00 root cast(test.tb.code, decimal(10,0) BINARY)->Column#21", - " └─IndexLookUp 2500.00 root ", - " ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(test.ta.id, test.tb.id)], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo" + "HashJoin 9990.00 root inner join, equal:[eq(test.t.a, test.t.a)]", + "├─HashAgg(Build) 7992.00 root group by:test.t.a, funcs:firstrow(test.t.a)->test.t.a", + "│ └─TableReader 7992.00 root data:HashAgg", + "│ └─HashAgg 7992.00 cop[tikv] group by:test.t.a, ", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.a))", + "│ └─TableFullScan 10000.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.t.a))", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], - "Result": null, - "Warning": null + "Warning": "" }, { - "SQL": "SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", + "SQL": "select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ t.b from t t1 where t1.a=t.a)", "Plan": [ - "HashJoin 250.00 root left outer join, equal:[eq(test.ta.id, test.tb.id)]", - "├─TableReader(Build) 250.00 root data:Selection", - "│ └─Selection 250.00 cop[tikv] like(test.ta.name, \"chad999%\", 92)", - "│ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - "└─HashAgg(Probe) 6387.21 root group by:Column#39, funcs:sum(Column#37)->Column#18, funcs:firstrow(Column#38)->test.tb.id", - " └─Projection 7984.01 root cast(test.tb.code, decimal(10,0) BINARY)->Column#37, test.tb.id->Column#38, test.tb.id->Column#39", - " └─HashJoin 7984.01 root semi join, equal:[eq(test.tb.name, test.tc.name)]", - " ├─TableReader(Build) 7992.00 root data:Selection", - " │ └─Selection 7992.00 cop[tikv] like(cast(test.tc.code, var_string(20)), \"999%\", 92), not(isnull(test.tc.name))", - " │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo", - " └─TableReader(Probe) 9980.01 root data:Selection", - " └─Selection 9980.01 cop[tikv] not(isnull(test.tb.id)), not(isnull(test.tb.name))", - " └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo" + "HashJoin 9990.00 root inner join, equal:[eq(test.t.a, test.t.a)]", + "├─HashAgg(Build) 7992.00 root group by:test.t.a, funcs:firstrow(test.t.a)->test.t.a", + "│ └─TableReader 7992.00 root data:HashAgg", + "│ └─HashAgg 7992.00 cop[tikv] group by:test.t.a, ", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.a))", + "│ └─TableFullScan 10000.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.t.a))", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], - "Result": null, - "Warning": null - }, - { - "SQL": "SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - "Plan": [ - "Projection 250.00 root test.ta.name, Column#18", - "└─Apply 250.00 root CARTESIAN left outer join", - " ├─TableReader(Build) 250.00 root data:Selection", - " │ └─Selection 250.00 cop[tikv] like(test.ta.name, \"chad999%\", 92)", - " │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - " └─MaxOneRow(Probe) 250.00 root ", - " └─StreamAgg 250.00 root funcs:sum(Column#33)->Column#18", - " └─Projection 1998.00 root cast(test.tb.code, decimal(10,0) BINARY)->Column#33", - " └─IndexHashJoin 1998.00 root semi join, inner:IndexLookUp, outer key:test.tb.name, inner key:test.tc.name, equal cond:eq(test.tb.name, test.tc.name)", - " ├─IndexLookUp(Build) 2497.50 root ", - " │ ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(test.ta.id, test.tb.id)], keep order:false, stats:pseudo", - " │ └─Selection(Probe) 2497.50 cop[tikv] not(isnull(test.tb.name))", - " │ └─TableRowIDScan 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo", - " └─IndexLookUp(Probe) 3121.87 root ", - " ├─Selection(Build) 3902.34 cop[tikv] not(isnull(test.tc.name))", - " │ └─IndexRangeScan 3906.25 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(test.tc.name, test.tb.name)], keep order:false, stats:pseudo", - " └─Selection(Probe) 3121.87 cop[tikv] like(cast(test.tc.code, var_string(20)), \"999%\", 92)", - " └─TableRowIDScan 3902.34 cop[tikv] table:tc keep order:false, stats:pseudo" - ], - "Result": null, - "Warning": null - }, - { - "SQL": "SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - "Plan": [ - "HashJoin 250.00 root left outer join, equal:[eq(test.ta.id, test.tb.id)]", - "├─TableReader(Build) 250.00 root data:Selection", - "│ └─Selection 250.00 cop[tikv] like(test.ta.name, \"chad999%\", 92)", - "│ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - "└─HashAgg(Probe) 7992.00 root group by:Column#28, funcs:sum(Column#26)->Column#18, funcs:firstrow(Column#27)->test.tb.id", - " └─Projection 9990.00 root cast(test.tb.code, decimal(10,0) BINARY)->Column#26, test.tb.id->Column#27, test.tb.id->Column#28", - " └─Apply 9990.00 root CARTESIAN semi join", - " ├─TableReader(Build) 9990.00 root data:Selection", - " │ └─Selection 9990.00 cop[tikv] not(isnull(test.tb.id))", - " │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo", - " └─IndexLookUp(Probe) 79920.00 root ", - " ├─IndexRangeScan(Build) 99900.00 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(test.tb.name, test.tc.name)], keep order:false, stats:pseudo", - " └─Selection(Probe) 79920.00 cop[tikv] like(cast(test.tc.code, var_string(20)), \"999%\", 92)", - " └─TableRowIDScan 99900.00 cop[tikv] table:tc keep order:false, stats:pseudo" - ], - "Result": null, - "Warning": null - }, - { - "SQL": "SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'", - "Plan": [ - "Projection 250.00 root test.ta.name, Column#18", - "└─Apply 250.00 root CARTESIAN left outer join", - " ├─TableReader(Build) 250.00 root data:Selection", - " │ └─Selection 250.00 cop[tikv] like(test.ta.name, \"chad999%\", 92)", - " │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - " └─MaxOneRow(Probe) 250.00 root ", - " └─StreamAgg 250.00 root funcs:sum(Column#22)->Column#18", - " └─Projection 2500.00 root cast(test.tb.code, decimal(10,0) BINARY)->Column#22", - " └─Apply 2500.00 root CARTESIAN semi join", - " ├─IndexLookUp(Build) 2500.00 root ", - " │ ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(test.ta.id, test.tb.id)], keep order:false, stats:pseudo", - " │ └─TableRowIDScan(Probe) 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo", - " └─IndexLookUp(Probe) 20000.00 root ", - " ├─IndexRangeScan(Build) 25000.00 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(test.tb.name, test.tc.name)], keep order:false, stats:pseudo", - " └─Selection(Probe) 20000.00 cop[tikv] like(cast(test.tc.code, var_string(20)), \"999%\", 92)", - " └─TableRowIDScan 25000.00 cop[tikv] table:tc keep order:false, stats:pseudo" - ], - "Result": null, - "Warning": null + "Warning": "" }, { - "SQL": "SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900", + "SQL": "select exists(select /*+ SEMI_JOIN_REWRITE() */ * from t t1 where t1.a=t.a) from t", "Plan": [ - "Projection 9.99 root test.ta.id, split->Column#10", - "└─HashJoin 9.99 root inner join, equal:[eq(test.ta.id, test.tb.id)]", - " ├─IndexLookUp(Build) 9.99 root ", - " │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:ta, index:idx_ta_name(name) range:[\"chad999\",\"chad999\"], keep order:false, stats:pseudo", - " │ └─Selection(Probe) 9.99 cop[tikv] not(isnull(test.ta.id))", - " │ └─TableRowIDScan 10.00 cop[tikv] table:ta keep order:false, stats:pseudo", - " └─Selection(Probe) 6393.60 root gt(Column#9, 900)", - " └─HashAgg 7992.00 root group by:test.tb.id, funcs:max(Column#19)->Column#9, funcs:firstrow(test.tb.id)->test.tb.id", - " └─TableReader 7992.00 root data:HashAgg", - " └─HashAgg 7992.00 cop[tikv] group by:test.tb.id, funcs:max(test.tb.code)->Column#19", - " └─Selection 9990.00 cop[tikv] not(isnull(test.tb.id))", - " └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo" + "HashJoin 10000.00 root left outer semi join, equal:[eq(test.t.a, test.t.a)]", + "├─TableReader(Build) 10000.00 root data:TableFullScan", + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + "└─TableReader(Probe) 10000.00 root data:TableFullScan", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], - "Result": null, - "Warning": null - }, - { - "SQL": "SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900", - "Plan": [ - "Projection 10.00 root test.ta.id, split->Column#10", - "└─Apply 10.00 root CARTESIAN inner join", - " ├─IndexLookUp(Build) 10.00 root ", - " │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:ta, index:idx_ta_name(name) range:[\"chad999\",\"chad999\"], keep order:false, stats:pseudo", - " │ └─TableRowIDScan(Probe) 10.00 cop[tikv] table:ta keep order:false, stats:pseudo", - " └─Selection(Probe) 8.00 root gt(Column#9, 900)", - " └─MaxOneRow 10.00 root ", - " └─StreamAgg 10.00 root funcs:max(test.tb.code)->Column#9", - " └─TopN 10.00 root test.tb.code:desc, offset:0, count:1", - " └─IndexLookUp 10.00 root ", - " ├─IndexRangeScan(Build) 100.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(test.ta.id, test.tb.id)], keep order:false, stats:pseudo", - " └─TopN(Probe) 10.00 cop[tikv] test.tb.code:desc, offset:0, count:1", - " └─Selection 99.90 cop[tikv] not(isnull(test.tb.code))", - " └─TableRowIDScan 100.00 cop[tikv] table:tb keep order:false, stats:pseudo" - ], - "Result": null, - "Warning": null - }, - { - "SQL": "SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100", - "Plan": [ - "HashJoin 159.84 root inner join, equal:[eq(test.ta.id, test.td.id)]", - "├─Selection(Build) 159.84 root gt(Column#19, 100)", - "│ └─HashAgg 199.80 root group by:test.td.id, funcs:max(Column#32)->Column#19, funcs:firstrow(test.td.id)->test.td.id", - "│ └─TableReader 199.80 root data:HashAgg", - "│ └─HashAgg 199.80 cop[tikv] group by:test.td.id, funcs:max(test.td.id)->Column#32", - "│ └─Selection 249.75 cop[tikv] like(test.td.name, \"chad999%\", 92), not(isnull(test.td.id))", - "│ └─TableFullScan 10000.00 cop[tikv] table:td keep order:false, stats:pseudo", - "└─HashJoin(Probe) 200.00 root inner join, equal:[eq(test.ta.name, test.tc.name)]", - " ├─Selection(Build) 160.00 root gt(Column#14, 100)", - " │ └─HashAgg 200.00 root group by:test.tc.name, funcs:max(Column#24)->Column#14, funcs:firstrow(test.tc.name)->test.tc.name", - " │ └─TableReader 200.00 root data:HashAgg", - " │ └─HashAgg 200.00 cop[tikv] group by:test.tc.name, funcs:max(test.tc.id)->Column#24", - " │ └─Selection 250.00 cop[tikv] like(test.tc.name, \"chad99%\", 92), not(isnull(test.tc.name))", - " │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo", - " └─HashJoin(Probe) 7976.02 root semi join, equal:[eq(test.ta.code, test.tb.code)]", - " ├─TableReader(Build) 249.75 root data:Selection", - " │ └─Selection 249.75 cop[tikv] like(test.tb.name, \"chad9%\", 92), not(isnull(test.tb.code))", - " │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo", - " └─TableReader(Probe) 9970.03 root data:Selection", - " └─Selection 9970.03 cop[tikv] not(isnull(test.ta.code)), not(isnull(test.ta.id)), not(isnull(test.ta.name))", - " └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo" - ], - "Result": null, - "Warning": null - }, - { - "SQL": "SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100", - "Plan": [ - "Projection 249.75 root test.ta.name", - "└─Apply 249.75 root CARTESIAN inner join", - " ├─Apply(Build) 249.75 root CARTESIAN inner join", - " │ ├─IndexHashJoin(Build) 249.75 root inner join, inner:IndexLookUp, outer key:test.tb.code, inner key:test.ta.code, equal cond:eq(test.tb.code, test.ta.code)", - " │ │ ├─HashAgg(Build) 199.80 root group by:test.tb.code, funcs:firstrow(test.tb.code)->test.tb.code", - " │ │ │ └─TableReader 249.75 root data:Selection", - " │ │ │ └─Selection 249.75 cop[tikv] like(test.tb.name, \"chad9%\", 92), not(isnull(test.tb.code))", - " │ │ │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo", - " │ │ └─IndexLookUp(Probe) 249.75 root ", - " │ │ ├─Selection(Build) 249.75 cop[tikv] not(isnull(test.ta.code))", - " │ │ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_code(code) range: decided by [eq(test.ta.code, test.tb.code)], keep order:false, stats:pseudo", - " │ │ └─TableRowIDScan(Probe) 249.75 cop[tikv] table:ta keep order:false, stats:pseudo", - " │ └─Selection(Probe) 199.80 root gt(Column#14, 100)", - " │ └─MaxOneRow 249.75 root ", - " │ └─StreamAgg 249.75 root funcs:max(test.tc.id)->Column#14", - " │ └─TopN 62.38 root test.tc.id:desc, offset:0, count:1", - " │ └─IndexLookUp 62.38 root ", - " │ ├─Selection(Build) 62.44 cop[tikv] eq(test.ta.name, test.tc.name)", - " │ │ └─IndexRangeScan 62437.50 cop[tikv] table:tc, index:idx_tc_name(name) range:[\"chad99\",\"chad9:\"), keep order:false, stats:pseudo", - " │ └─TopN(Probe) 62.38 cop[tikv] test.tc.id:desc, offset:0, count:1", - " │ └─Selection 62.38 cop[tikv] not(isnull(test.tc.id))", - " │ └─TableRowIDScan 62.44 cop[tikv] table:tc keep order:false, stats:pseudo", - " └─Selection(Probe) 199.80 root gt(Column#19, 100)", - " └─MaxOneRow 249.75 root ", - " └─StreamAgg 249.75 root funcs:max(test.td.id)->Column#19", - " └─Limit 62.38 root offset:0, count:1", - " └─Projection 62.38 root test.td.id, test.td.name", - " └─IndexLookUp 62.38 root ", - " ├─Selection(Build) 2495.00 cop[tikv] eq(test.ta.id, test.td.id)", - " │ └─IndexFullScan 2495002.50 cop[tikv] table:td, index:idx_tc_id(id) keep order:true, desc, stats:pseudo", - " └─Selection(Probe) 62.38 cop[tikv] like(test.td.name, \"chad999%\", 92)", - " └─TableRowIDScan 2495.00 cop[tikv] table:td keep order:false, stats:pseudo" - ], - "Result": null, - "Warning": null + "Warning": "[planner:1815]SEMI_JOIN_REWRITE() is inapplicable for LeftOuterSemiJoin." }, { - "SQL": "SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100", - "Plan": [ - "Projection 10000.00 root test.ta.name", - "└─Apply 10000.00 root CARTESIAN inner join", - " ├─Apply(Build) 10000.00 root CARTESIAN inner join", - " │ ├─Apply(Build) 10000.00 root CARTESIAN semi join", - " │ │ ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ │ │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo", - " │ │ └─TableReader(Probe) 2500.00 root data:Selection", - " │ │ └─Selection 2500.00 cop[tikv] eq(test.ta.code, test.tb.code), like(test.tb.name, \"chad9%\", 92)", - " │ │ └─TableFullScan 100000000.00 cop[tikv] table:tb keep order:false, stats:pseudo", - " │ └─Selection(Probe) 8000.00 root gt(Column#14, 100)", - " │ └─MaxOneRow 10000.00 root ", - " │ └─StreamAgg 10000.00 root funcs:max(test.tc.id)->Column#14", - " │ └─TopN 2497.50 root test.tc.id:desc, offset:0, count:1", - " │ └─IndexLookUp 2497.50 root ", - " │ ├─Selection(Build) 2500.00 cop[tikv] eq(test.ta.name, test.tc.name)", - " │ │ └─IndexRangeScan 2500000.00 cop[tikv] table:tc, index:idx_tc_name(name) range:[\"chad99\",\"chad9:\"), keep order:false, stats:pseudo", - " │ └─TopN(Probe) 2497.50 cop[tikv] test.tc.id:desc, offset:0, count:1", - " │ └─Selection 2497.50 cop[tikv] not(isnull(test.tc.id))", - " │ └─TableRowIDScan 2500.00 cop[tikv] table:tc keep order:false, stats:pseudo", - " └─Selection(Probe) 8000.00 root gt(Column#19, 100)", - " └─MaxOneRow 10000.00 root ", - " └─StreamAgg 10000.00 root funcs:max(test.td.id)->Column#19", - " └─Limit 2497.50 root offset:0, count:1", - " └─Projection 2497.50 root test.td.id, test.td.name", - " └─IndexLookUp 2497.50 root ", - " ├─Selection(Build) 99900.00 cop[tikv] eq(test.ta.id, test.td.id)", - " │ └─IndexFullScan 99900000.00 cop[tikv] table:td, index:idx_tc_id(id) keep order:true, desc, stats:pseudo", - " └─Selection(Probe) 2497.50 cop[tikv] like(test.td.name, \"chad999%\", 92)", - " └─TableRowIDScan 99900.00 cop[tikv] table:td keep order:false, stats:pseudo" - ], - "Result": null, - "Warning": null + "SQL": "select * from t where exists (select /*+ SEMI_JOIN_REWRITE() */ 1 from t t1 where t1.a > t.a)", + "Plan": [ + "HashJoin 7992.00 root CARTESIAN semi join, other cond:gt(test.t.a, test.t.a)", + "├─TableReader(Build) 9990.00 root data:Selection", + "│ └─Selection 9990.00 cop[tikv] not(isnull(test.t.a))", + "│ └─TableFullScan 10000.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.t.a))", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + ], + "Warning": "[planner:1815]SEMI_JOIN_REWRITE() is inapplicable for SemiJoin with left conditions or other conditions." } ] }, { - "Name": "TestCountStarForTikv", + "Name": "TestHJBuildAndProbeHint4DynamicPartitionTable", "Cases": [ { - "SQL": "select count(*) from t", + "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "StreamAgg 1.00 root funcs:count(Column#12)->Column#10", - "└─TableReader 1.00 root data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#12", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + "├─TableReader(Build) 9980.01 root partition:all data:Selection", + "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9980.01 root partition:all data:Selection", + " └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", + " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], - "Warning": null - }, - { - "SQL": "select count(1), count(3.1415), count(0), count(null) from t -- shouldn't be rewritten", - "Plan": [ - "StreamAgg 1.00 root funcs:count(Column#18)->Column#10, funcs:count(Column#19)->Column#11, funcs:count(Column#20)->Column#12, funcs:count(Column#21)->Column#13", - "└─TableReader 1.00 root data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#18, funcs:count(3.1415)->Column#19, funcs:count(0)->Column#20, funcs:count(NULL)->Column#21", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "Result": [ + "1 1" ], "Warning": null }, { - "SQL": "select count(*) from t where a=1", + "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "StreamAgg 1.00 root funcs:count(Column#12)->Column#10", - "└─TableReader 1.00 root data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#12", - " └─Selection 10.00 cop[tikv] eq(test.t.a, 1)", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + "├─TableReader(Build) 9980.01 root partition:all data:Selection", + "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9980.01 root partition:all data:Selection", + " └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" ], - "Warning": null - }, - { - "SQL": "select count(*) from t_pick_row_id", - "Plan": [ - "StreamAgg 1.00 root funcs:count(Column#5)->Column#3", - "└─TableReader 1.00 root data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#5", - " └─TableFullScan 10000.00 cop[tikv] table:t_pick_row_id keep order:false, stats:pseudo" + "Result": [ + "1 1" ], "Warning": null }, { - "SQL": "select t.b, t.c from (select count(*) as c from t) a, t where a.c=t.a -- shouldn't be rewritten", + "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "HashJoin 1.25 root inner join, equal:[eq(test.t.a, Column#10)]", - "├─StreamAgg(Build) 1.00 root funcs:count(Column#21)->Column#10", - "│ └─TableReader 1.00 root data:StreamAgg", - "│ └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#21", - "│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + "├─TableReader(Build) 9980.01 root partition:all data:Selection", + "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9980.01 root partition:all data:Selection", + " └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", + " └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo" ], - "Warning": null - }, - { - "SQL": "select * from t outTable where outTable.a > (select count(*) from t inn where inn.a = outTable.b) -- shouldn't be rewritten", - "Plan": [ - "Projection 10000.00 root test.t.a, test.t.b, test.t.c, test.t.d, test.t.e, test.t.f, test.t.g, test.t.h", - "└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(test.t.a, Column#19)", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:outTable keep order:false, stats:pseudo", - " └─StreamAgg(Probe) 10000.00 root funcs:count(Column#21)->Column#19", - " └─TableReader 10000.00 root data:StreamAgg", - " └─StreamAgg 10000.00 cop[tikv] funcs:count(1)->Column#21", - " └─Selection 80000000.00 cop[tikv] eq(cast(test.t.a, double BINARY), cast(test.t.b, double BINARY))", - " └─TableFullScan 100000000.00 cop[tikv] table:inn keep order:false, stats:pseudo" + "Result": [ + "1 1" ], "Warning": null }, { - "SQL": "select count(*) from t t1, t t2 where t1.a=t2.e -- shouldn't be rewritten", + "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "HashAgg 1.00 root funcs:count(1)->Column#19", - "└─HashJoin 12500.00 root inner join, equal:[eq(test.t.a, test.t.e)]", - " ├─TableReader(Build) 10000.00 root data:TableFullScan", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " └─TableReader(Probe) 10000.00 root data:TableFullScan", + "HashJoin 12475.01 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + "├─TableReader(Build) 9980.01 root partition:all data:Selection", + "│ └─Selection 9980.01 cop[tikv] not(isnull(test.t2.a)), not(isnull(test.t2.b))", + "│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + "└─TableReader(Probe) 9980.01 root partition:all data:Selection", + " └─Selection 9980.01 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b))", " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], + "Result": [ + "1 1" + ], "Warning": null - }, + } + ] + }, + { + "Name": "TestHJBuildAndProbeHint4TiFlash", + "Cases": [ { - "SQL": "select count(distinct 1) from t -- shouldn't be rewritten", + "SQL": "select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "StreamAgg 1.00 root funcs:count(distinct 1)->Column#10", - "└─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", + " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", + " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo", + " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo" ], "Warning": null }, { - "SQL": "select count(1), count(a), count(b) from t -- shouldn't be rewritten", + "SQL": "select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "StreamAgg 1.00 root funcs:count(Column#16)->Column#10, funcs:count(Column#17)->Column#11, funcs:count(Column#18)->Column#12", - "└─TableReader 1.00 root data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#16, funcs:count(test.t.a)->Column#17, funcs:count(test.t.b)->Column#18", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", + " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", + " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo", + " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo" ], "Warning": null }, { - "SQL": "select a, count(*) from t group by a -- shouldn't be rewritten", + "SQL": "select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "Projection 8000.00 root test.t.a, Column#10", - "└─HashAgg 8000.00 root group by:test.t.a, funcs:count(1)->Column#10, funcs:firstrow(test.t.a)->test.t.a", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", + " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", + " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo", + " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo" ], "Warning": null }, { - "SQL": "select sum(a) from t -- sum shouldn't be rewritten", + "SQL": "select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b", "Plan": [ - "StreamAgg 1.00 root funcs:sum(Column#12)->Column#10", - "└─TableReader 1.00 root data:StreamAgg", - " └─StreamAgg 1.00 cop[tikv] funcs:sum(test.t.a)->Column#12", - " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" + "TableReader 12500.00 root MppVersion: 2, data:ExchangeSender", + "└─ExchangeSender 12500.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection 12500.00 mpp[tiflash] test.t1.a, test.t2.a", + " └─HashJoin 12500.00 mpp[tiflash] inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]", + " ├─ExchangeReceiver(Build) 10000.00 mpp[tiflash] ", + " │ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: Broadcast, Compression: FAST", + " │ └─TableFullScan 10000.00 mpp[tiflash] table:t2 keep order:false, stats:pseudo", + " └─TableFullScan(Probe) 10000.00 mpp[tiflash] table:t1 keep order:false, stats:pseudo" ], "Warning": null } @@ -7663,338 +3621,5 @@ "Warning": null } ] - }, - { - "Name": "TestIndexMergeOrderPushDown", - "Cases": [ - { - "SQL": "select * from t where a = 1 or b = 1 order by c limit 2", - "Plan": [ - "Projection 2.00 root test.t.a, test.t.b, test.t.c", - "└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - " ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:true, stats:pseudo", - " ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where a = 1 or b in (1, 2, 3) order by c limit 2", - "Plan": [ - "TopN 2.00 root test.t.c, offset:0, count:2", - "└─IndexMerge 2.00 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo", - " └─TopN(Probe) 2.00 cop[tikv] test.t.c, offset:0, count:2", - " └─TableRowIDScan 39.97 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where a in (1, 2, 3) or b = 1 order by c limit 2", - "Plan": [ - "TopN 2.00 root test.t.c, offset:0, count:2", - "└─IndexMerge 2.00 root type: union", - " ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:false, stats:pseudo", - " └─TopN(Probe) 2.00 cop[tikv] test.t.c, offset:0, count:2", - " └─TableRowIDScan 39.97 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where a in (1, 2, 3) or b in (1, 2, 3) order by c limit 2", - "Plan": [ - "TopN 2.00 root test.t.c, offset:0, count:2", - "└─IndexMerge 2.00 root type: union", - " ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo", - " └─TopN(Probe) 2.00 cop[tikv] test.t.c, offset:0, count:2", - " └─TableRowIDScan 59.91 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where (a = 1 and c = 2) or (b = 1) order by c limit 2", - "Plan": [ - "Projection 2.00 root test.t.a, test.t.b, test.t.c", - "└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - " ├─Limit(Build) 0.02 cop[tikv] offset:0, count:2", - " │ └─IndexRangeScan 0.02 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:true, stats:pseudo", - " ├─Limit(Build) 1.98 cop[tikv] offset:0, count:2", - " │ └─IndexRangeScan 1.98 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where (a = 1 and c = 2) or b in (1, 2, 3) order by c limit 2", - "Plan": [ - "TopN 2.00 root test.t.c, offset:0, count:2", - "└─IndexMerge 2.00 root type: union", - " ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo", - " └─TopN(Probe) 2.00 cop[tikv] test.t.c, offset:0, count:2", - " └─TableRowIDScan 30.10 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where (a = 1 and c = 2) or (b in (1, 2, 3) and c = 3) order by c limit 2", - "Plan": [ - "TopN 0.40 root test.t.c, offset:0, count:2", - "└─IndexMerge 0.40 root type: union", - " ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 0.30 cop[tikv] table:t, index:idx2(b, c) range:[1 3,1 3], [2 3,2 3], [3 3,3 3], keep order:false, stats:pseudo", - " └─TopN(Probe) 0.40 cop[tikv] test.t.c, offset:0, count:2", - " └─TableRowIDScan 0.40 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where (a = 1 or b = 2) and c = 3 order by c limit 2", - "Plan": [ - "TopN 0.02 root test.t.c, offset:0, count:2", - "└─IndexMerge 0.02 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo", - " └─TopN(Probe) 0.02 cop[tikv] test.t.c, offset:0, count:2", - " └─Selection 0.02 cop[tikv] eq(test.t.c, 3)", - " └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by c limit 2", - "Plan": [ - "TopN 0.06 root test.t.c, offset:0, count:2", - "└─IndexMerge 0.06 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo", - " └─TopN(Probe) 0.06 cop[tikv] test.t.c, offset:0, count:2", - " └─Selection 0.06 cop[tikv] in(test.t.c, 1, 2, 3)", - " └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by b limit 2", - "Plan": [ - "TopN 0.06 root test.t.b, offset:0, count:2", - "└─IndexMerge 0.06 root type: union", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo", - " └─TopN(Probe) 0.06 cop[tikv] test.t.b, offset:0, count:2", - " └─Selection 0.06 cop[tikv] in(test.t.c, 1, 2, 3)", - " └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from tcommon where a = 1 or b = 1 order by c limit 2", - "Plan": [ - "IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - "├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - "│ └─TableRangeScan 1.00 cop[tikv] table:tcommon range:[1,1], keep order:true, stats:pseudo", - "├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - "│ └─IndexRangeScan 1.00 cop[tikv] table:tcommon, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo", - "└─TableRowIDScan(Probe) 2.00 cop[tikv] table:tcommon keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from tcommon where (a = 1 and c = 2) or (b = 1) order by c limit 2", - "Plan": [ - "IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - "├─Limit(Build) 0.18 cop[tikv] offset:0, count:2", - "│ └─TableRangeScan 0.18 cop[tikv] table:tcommon range:[1 2,1 2], keep order:true, stats:pseudo", - "├─Limit(Build) 1.82 cop[tikv] offset:0, count:2", - "│ └─IndexRangeScan 1.82 cop[tikv] table:tcommon, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo", - "└─TableRowIDScan(Probe) 2.00 cop[tikv] table:tcommon keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select * from thash use index(idx_ac, idx_bc) where a = 1 or b = 1 order by c limit 2", - "Plan": [ - "TopN 2.00 root test.thash.c, offset:0, count:2", - "└─PartitionUnion 8.00 root ", - " ├─Projection 2.00 root test.thash.a, test.thash.b, test.thash.c", - " │ └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - " │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p0, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p0, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo", - " │ └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p0 keep order:false, stats:pseudo", - " ├─Projection 2.00 root test.thash.a, test.thash.b, test.thash.c", - " │ └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - " │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p1, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p1, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo", - " │ └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p1 keep order:false, stats:pseudo", - " ├─Projection 2.00 root test.thash.a, test.thash.b, test.thash.c", - " │ └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - " │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p2, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p2, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo", - " │ └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p2 keep order:false, stats:pseudo", - " └─Projection 2.00 root test.thash.a, test.thash.b, test.thash.c", - " └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - " ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p3, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo", - " ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - " │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p3, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo", - " └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p3 keep order:false, stats:pseudo" - ], - "Warning": [ - "Warning 1105 disable dynamic pruning due to thash has no global stats" - ] - } - ] - }, - { - "Name": "TestIndexMergeSinkLimit", - "Cases": [ - { - "SQL": "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; -- test sink limit to table side of union index merge case, because of table side selection", - "Plan": [ - "Limit 2.00 root offset:0, count:2", - "└─IndexMerge 0.00 root type: union", - " ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo", - " └─Limit(Probe) 0.00 cop[tikv] offset:0, count:2", - " └─Selection 0.00 cop[tikv] or(eq(test.t2.a, 1), and(eq(test.t2.b, 1), eq(test.t2.c, 1)))", - " └─TableRowIDScan 3.99 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; -- test sink limit to table side of intersection index merge case, because of table side selection", - "Plan": [ - "Limit 0.00 root offset:0, count:2", - "└─IndexMerge 0.01 root type: intersection", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo", - " └─Limit(Probe) 0.01 cop[tikv] offset:0, count:2", - " └─Selection 0.01 cop[tikv] eq(test.t2.c, 1)", - " └─TableRowIDScan 0.01 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2", - "Plan": null, - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; -- test sink limit to index side of union index merge case, because of table side is pure table scan", - "Plan": [ - "IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2)", - "├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - "│ └─IndexRangeScan 1.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo", - "├─Limit(Build) 1.00 cop[tikv] offset:0, count:2", - "│ └─IndexRangeScan 1.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 2.00 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; -- test sink limit to table side of intersection index merge case, because of intersection case special", - "Plan": [ - "IndexMerge 0.01 root type: intersection, limit embedded(offset:0, count:2)", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.01 cop[tikv] table:t2 keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2", - "Plan": null, - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; -- index merge union case, sink limit into index side and embed another one inside index merge reader", - "Plan": [ - "IndexMerge 0.00 root type: union, limit embedded(offset:0, count:1)", - "├─Limit(Build) 0.00 cop[tikv] offset:0, count:1", - "│ └─IndexRangeScan 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; -- index merge intersection case, embedding limit into index merge reader", - "Plan": [ - "IndexMerge 0.00 root type: intersection, limit embedded(offset:0, count:1)", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - "├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo", - "└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down", - "Plan": [ - "Limit 1.00 root offset:0, count:1", - "└─Selection 1.00 root json_overlaps(test.t.j, cast(\"[1, 2, 3]\", json BINARY))", - " └─IndexMerge 0.00 root type: union", - " ├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": [ - "Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now." - ] - }, - { - "SQL": "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; -- index merge union case, sink limit to table side, because selection exists on table side", - "Plan": [ - "Limit 1.00 root offset:0, count:1", - "└─IndexMerge 0.00 root type: union", - " ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - " └─Limit(Probe) 0.00 cop[tikv] offset:0, count:1", - " └─Selection 0.00 cop[tikv] eq(test.t.a, 1)", - " └─TableRowIDScan 1.25 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; -- index merge intersection case, sink limit to table side because selection exists on table side", - "Plan": [ - "Limit 1.00 root offset:0, count:1", - "└─IndexMerge 0.00 root type: intersection", - " ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─Limit(Probe) 0.00 cop[tikv] offset:0, count:1", - " └─Selection 0.00 cop[tikv] eq(test.t.a, 1)", - " └─TableRowIDScan 1.25 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": null - }, - { - "SQL": "explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down", - "Plan": [ - "Limit 1.00 root offset:0, count:1", - "└─Selection 1.00 root json_overlaps(test.t.j, cast(\"[1, 2, 3]\", json BINARY))", - " └─IndexMerge 1.00 root type: union", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo", - " ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo", - " └─Selection(Probe) 1.00 cop[tikv] eq(test.t.a, 1)", - " └─TableRowIDScan 1.00 cop[tikv] table:t keep order:false, stats:pseudo" - ], - "Warning": [ - "Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now." - ] - } - ] } ] diff --git a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result new file mode 100644 index 0000000000000..c95d563ce7047 --- /dev/null +++ b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result @@ -0,0 +1,3731 @@ +drop table if exists t1, t2; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +explain format = 'brief' select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +IndexMergeJoin 12500.00 root left outer join, inner:TableReader, outer key:planner__core__casetest__physicalplantest__physical_plan.t1.a, inner key:planner__core__casetest__physicalplantest__physical_plan.t2.a, other cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [planner__core__casetest__physicalplantest__physical_plan.t1.a], keep order:true, stats:pseudo +select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +explain format = 'brief' select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +IndexHashJoin 12500.00 root left outer join, inner:TableReader, outer key:planner__core__casetest__physicalplantest__physical_plan.t1.a, inner key:planner__core__casetest__physicalplantest__physical_plan.t2.a, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a), eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [planner__core__casetest__physicalplantest__physical_plan.t1.a], keep order:false, stats:pseudo +select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +explain format = 'brief' select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +IndexJoin 12500.00 root left outer join, inner:TableReader, outer key:planner__core__casetest__physicalplantest__physical_plan.t1.a, inner key:planner__core__casetest__physicalplantest__physical_plan.t2.a, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a), eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [planner__core__casetest__physicalplantest__physical_plan.t1.a], keep order:false, stats:pseudo +select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +explain format = 'brief' select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +drop table if exists t1, t2, t3; +create table t1(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, UNIQUE KEY idx_a (a)); +create table t2(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL); +create table t3(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, c int(11) DEFAULT NULL, UNIQUE KEY idx_abc (a, b, c)); +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +id estRows task access object operator info +HashJoin 9990.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a)], other cond:lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) +├─IndexReader(Build) 7992.00 root index:Selection +│ └─Selection 7992.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) +│ └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo +└─TableReader(Probe) 7992.00 root data:Selection + └─Selection 7992.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t2.a), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)) + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +a +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +id estRows task access object operator info +Projection 9990.00 root planner__core__casetest__physicalplantest__physical_plan.t2.a +└─Apply 9990.00 root CARTESIAN inner join, other cond:lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─Selection(Probe) 7992.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)) + └─MaxOneRow 9990.00 root + └─IndexLookUp 9.99 root + ├─IndexRangeScan(Build) 9990.00 cop[tikv] table:t1, index:idx_a(a) range:[NULL,NULL], keep order:false, stats:pseudo + └─Selection(Probe) 9.99 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) + └─TableRowIDScan 9990.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +a +explain format = 'brief' select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); +id estRows task access object operator info +Projection 9990.00 root planner__core__casetest__physicalplantest__physical_plan.t2.a +└─Apply 9990.00 root CARTESIAN inner join, other cond:lt(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a) + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─Selection(Probe) 7992.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t3.a)) + └─MaxOneRow 9990.00 root + └─IndexReader 19980.00 root index:IndexRangeScan + └─IndexRangeScan 19980.00 cop[tikv] table:t3, index:idx_abc(a, b, c) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t3.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)], keep order:false, stats:pseudo +select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); +a +set tidb_cost_model_version=2; +drop table if exists t, tt; +create table t (a int primary key, b int, index idx(a)); +create table tt (a int primary key) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200)); +set @@tidb_partition_prune_mode='static'; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a; +id estRows task access object operator info +IndexJoin 12500.00 root inner join, inner:UnionScan, outer key:planner__core__casetest__physicalplantest__physical_plan.t.a, inner key:planner__core__casetest__physicalplantest__physical_plan.t.a, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.a) +├─UnionScan(Build) 10000.00 root +│ └─TableReader 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─UnionScan(Probe) 10000.00 root + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [planner__core__casetest__physicalplantest__physical_plan.t.a], keep order:false, stats:pseudo +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.b; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b +└─HashJoin 12487.50 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.a)] + ├─UnionScan(Build) 9990.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + │ └─TableReader 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─UnionScan(Probe) 10000.00 root + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ t1.a , t2.b from t t1, t t2 where t1.a = t2.b; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b +└─HashJoin 12487.50 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.a)] + ├─UnionScan(Build) 10000.00 root + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─UnionScan(Probe) 9990.00 root not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + └─TableReader 9990.00 root data:Selection + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t.b)) + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +rollback; +begin; +insert into tt values(1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from tt t1, tt t2 where t1.a = t2.a; +id estRows task access object operator info +HashJoin 25000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tt.a, planner__core__casetest__physicalplantest__physical_plan.tt.a)] +├─PartitionUnion(Build) 20000.00 root +│ ├─UnionScan 10000.00 root +│ │ └─TableReader 10000.00 root data:TableFullScan +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo +│ └─UnionScan 10000.00 root +│ └─TableReader 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 20000.00 root + ├─UnionScan 10000.00 root + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo + └─UnionScan 10000.00 root + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo +rollback; +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), primary key (c_int)); +create table t2 (c_int int, c_str varchar(40), primary key (c_int)); +insert into t1 (`c_int`, `c_str`) values (11, 'keen williamson'), (10, 'gracious hermann'); +insert into t2 (`c_int`, `c_str`) values (10, 'gracious hermann'); +begin; +insert into t2 values (11, 'amazing merkle'); +insert into t2 values (12, 'amazing merkle'); +explain format = 'brief' select /*+ MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_int = t2.c_int order by t1.c_int, t2.c_str; +id estRows task access object operator info +Sort 12500.00 root planner__core__casetest__physicalplantest__physical_plan.t1.c_int, planner__core__casetest__physicalplantest__physical_plan.t2.c_str +└─MergeJoin 12500.00 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.c_int, right key:planner__core__casetest__physicalplantest__physical_plan.t2.c_int + ├─UnionScan(Build) 10000.00 root + │ └─TableReader 10000.00 root data:TableFullScan + │ └─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 +rollback; +set tidb_cost_model_version=2; +drop table if exists tn; +create table tn(a int, b int, c int, d int, key (a, b, c, d)); +set tidb_opt_limit_push_down_threshold=0; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +id estRows task access object operator info +TopN 0.83 root planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 +└─IndexReader 0.83 root index:TopN + └─TopN 0.83 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 + └─Selection 0.83 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.tn.c, 50) + └─IndexRangeScan 2.50 cop[tikv] table:tn, index:a(a, b, c, d) range:(1 10,1 20), keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +id estRows task access object operator info +TopN 0.83 root planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 +└─IndexReader 0.83 root index:TopN + └─TopN 0.83 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tn.d, offset:0, count:1 + └─Selection 0.83 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.tn.c, 50) + └─IndexRangeScan 2.50 cop[tikv] table:tn, index:a(a, b, c, d) range:(1 10,1 20), keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a div 2 order by a limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─Selection 1.00 root intdiv(planner__core__casetest__physicalplantest__physical_plan.tn.a, 2) + └─IndexReader 1.00 root index:IndexFullScan + └─IndexFullScan 1.00 cop[tikv] table:tn, index:a(a, b, c, d) keep order:true, stats:pseudo +show warnings; +Level Code Message +Warning 1105 Scalar function 'intdiv'(signature: IntDivideInt, return type: bigint(20)) is not supported to push down to storage layer now. +Warning 1815 Optimizer Hint LIMIT_TO_COP is inapplicable +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a > 10 limit 1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─IndexReader 1.00 root index:Limit + └─Limit 1.00 cop[tikv] offset:0, count:1 + └─IndexRangeScan 1.00 cop[tikv] table:tn, index:a(a, b, c, d) range:(10,+inf], keep order:false, stats:pseudo +show warnings; +Level Code Message +set tidb_cost_model_version=DEFAULT; +set tidb_opt_limit_push_down_threshold=DEFAULT; +drop table if exists tc, te, t1, t2, t3, t4; +drop view if exists v; +create table tc(a int); +create table te(c int); +create table t1(a int); +create table t2(b int); +create table t3(c int); +create table t4(d int); +insert into tc values (1), (5), (10), (15), (20), (30), (50); +insert into te values (1), (5), (10), (25), (40), (60), (100); +insert into t1 values (1), (5), (10), (25), (40), (60), (100); +insert into t2 values (1), (5), (10), (25), (40), (60), (100); +insert into t3 values (1), (5), (10), (25), (40), (60), (100); +insert into t4 values (1), (5), (10), (25), (40), (60), (100); +analyze table tc; +analyze table te; +analyze table t1; +analyze table t2; +analyze table t3; +analyze table t4; +create definer='root'@'localhost' view v as select * from tc; +explain format = 'brief' with cte as (select /*+ MERGE() */ * from tc where tc.a < 60) select * from cte where cte.a <18; +id estRows task access object operator info +TableReader 4.00 root data:Selection +└─Selection 4.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 18), lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 60) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte as (select * from tc where tc.a < 60) select * from cte c1, cte c2 where c1.a <18; +id estRows task access object operator info +Projection 39.20 root planner__core__casetest__physicalplantest__physical_plan.tc.a, planner__core__casetest__physicalplantest__physical_plan.tc.a +└─HashJoin 39.20 root CARTESIAN inner join + ├─Selection(Build) 5.60 root lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 18) + │ └─CTEFullScan 7.00 root CTE:cte AS c1 data:CTE_0 + └─CTEFullScan(Probe) 7.00 root CTE:cte AS c2 data:CTE_0 +CTE_0 7.00 root Non-Recursive CTE +└─TableReader(Seed Part) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 60), or(lt(planner__core__casetest__physicalplantest__physical_plan.tc.a, 18), 1) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte as (select /*+ MERGE() */ * from v) select * from cte; +id estRows task access object operator info +TableReader 7.00 root data:TableFullScan +└─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' WITH cte1 AS (SELECT /*+ MERGE() */ a FROM tc), cte2 AS (SELECT /*+ MERGE()*/ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +id estRows task access object operator info +HashJoin 7.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tc.a, planner__core__casetest__physicalplantest__physical_plan.te.c)] +├─TableReader(Build) 7.00 root data:Selection +│ └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.te.c)) +│ └─TableFullScan 7.00 cop[tikv] table:te keep order:false +└─TableReader(Probe) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.a)) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' WITH cte1 AS (SELECT a FROM tc), cte2 AS (SELECT /*+ MERGE() */ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +id estRows task access object operator info +HashJoin 7.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tc.a, planner__core__casetest__physicalplantest__physical_plan.te.c)] +├─TableReader(Build) 7.00 root data:Selection +│ └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.te.c)) +│ └─TableFullScan 7.00 cop[tikv] table:te keep order:false +└─TableReader(Probe) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.a)) + └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +show warnings; +Level Code Message +explain format = 'brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte1 data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 + └─Selection 0.80 root lt(Column#3, 100) + └─CTETable 1.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format = 'brief' WITH cte1 AS (SELECT * FROM t1) SELECT /*+ MERGE() */ * FROM cte1 join t2 on cte1.a = t2.b; +id estRows task access object operator info +HashJoin 7.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 7.00 root data:Selection +│ └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +└─TableReader(Probe) 7.00 root data:Selection + └─Selection 7.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)) + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +explain format = 'brief' with cte1 as (with cte3 as (select /*+ MERGE() */ * from t1),cte4 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3,cte4) ,cte2 as (select /*+ MERGE() */ * from t3) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 343.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from tc), cte2 as (with cte3 as (select /*+ MERGE() */ * from te) ,cte4 as (select * from tc) select * from cte3,cte4) select * from cte2; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (with cte2 as (select /*+ MERGE() */ * from te) ,cte3 as (select /*+ MERGE() */ * from tc) select /*+ MERGE() */ * from cte2,cte3) select * from cte1; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select /*+ MERGE() */ * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select /*+ MERGE() */ * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select /*+ MERGE() */ * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +id estRows task access object operator info +HashJoin 2401.00 root CARTESIAN inner join +├─HashJoin(Build) 49.00 root CARTESIAN inner join +│ ├─TableReader(Build) 7.00 root data:TableFullScan +│ │ └─TableFullScan 7.00 cop[tikv] table:t4 keep order:false +│ └─TableReader(Probe) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte2 as (with cte4 as (select * from tc) select * from te, cte4) select * from cte2; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte2 as (with cte4 as (select /*+ merge() */ * from tc) select * from te, cte4) select * from cte2; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:tc keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:te keep order:false +show warnings; +Level Code Message +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select /*+ MERGE() */ * from t1) ttt) select * from cte1; +id estRows task access object operator info +HashJoin 49.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false +└─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +show warnings; +Level Code Message +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select /*+ MERGE() */ * from t3) ttw; +id estRows task access object operator info +HashJoin 343.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +show warnings; +Level Code Message +Warning 1815 Hint merge() is inapplicable. Please check whether the hint is used in the right place, you should use this hint inside the CTE. +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select * from t3) ttw; +id estRows task access object operator info +HashJoin 343.00 root CARTESIAN inner join +├─TableReader(Build) 7.00 root data:TableFullScan +│ └─TableFullScan 7.00 cop[tikv] table:t3 keep order:false +└─HashJoin(Probe) 49.00 root CARTESIAN inner join + ├─TableReader(Build) 7.00 root data:TableFullScan + │ └─TableFullScan 7.00 cop[tikv] table:t1 keep order:false + └─TableReader(Probe) 7.00 root data:TableFullScan + └─TableFullScan 7.00 cop[tikv] table:t2 keep order:false +show warnings; +Level Code Message +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11)); +insert into t values (1), (5), (10), (15), (20), (30), (50); +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inline; +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 +show warnings; +Level Code Message +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline; +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 +show warnings; +Level Code Message +explain format='brief' with cte as (select * from t) select * from cte cte1, cte cte2; -- inline CTEs is used by multi consumers; +id estRows task access object operator info +HashJoin 100000000.00 root CARTESIAN inner join +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with cte1 as (select * from t), cte2 as (select a from cte1 group by a) select * from cte1, cte2; -- multi inline CTEs; +id estRows task access object operator info +HashJoin 80000000.00 root CARTESIAN inner join +├─HashAgg(Build) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.a)->planner__core__casetest__physicalplantest__physical_plan.t.a +│ └─TableReader 8000.00 root data:HashAgg +│ └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t.a, +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format='brief' with recursive cte1(c1) as (select 1 union select c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte1 data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 + └─Selection 0.80 root lt(Column#3, 100) + └─CTETable 1.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +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 +show warnings; +Level Code Message +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +id estRows task access object operator info +CTEFullScan 8001.00 root CTE:cte2 data:CTE_0 +CTE_0 8001.00 root Recursive CTE +├─TableReader(Seed Part) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─Projection(Recursive Part) 8000.00 root cast(plus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1), int(11))->planner__core__casetest__physicalplantest__physical_plan.t.a + └─Selection 8000.00 root lt(planner__core__casetest__physicalplantest__physical_plan.t.a, 100) + └─CTETable 10000.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte2 data:CTE_2 +CTE_2 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#9 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#10, 1), bigint(1) BINARY)->Column#12 + └─Selection 0.80 root lt(Column#10, 100) + └─CTETable 1.00 root Scan on CTE_2 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte. +Warning 1815 Recursive CTE cte2 can not be inlined by merge() or tidb_opt_force_inline_cte. +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inlined by single consumer; +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 +show warnings; +Level Code Message +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline, merge hint override session variable; +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 +show warnings; +Level Code Message +explain format='brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte1 data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 + └─Selection 0.80 root lt(Column#3, 100) + └─CTETable 1.00 root Scan on CTE_0 +show warnings; +Level Code Message +Warning 1815 Recursive CTE cte1 can not be inlined by merge() or tidb_opt_force_inline_cte. +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +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 +show warnings; +Level Code Message +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +id estRows task access object operator info +CTEFullScan 8001.00 root CTE:cte2 data:CTE_0 +CTE_0 8001.00 root Recursive CTE +├─TableReader(Seed Part) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─Projection(Recursive Part) 8000.00 root cast(plus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1), int(11))->planner__core__casetest__physicalplantest__physical_plan.t.a + └─Selection 8000.00 root lt(planner__core__casetest__physicalplantest__physical_plan.t.a, 100) + └─CTETable 10000.00 root Scan on CTE_0 +show warnings; +Level Code Message +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte2 data:CTE_2 +CTE_2 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#9 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.80 root cast(plus(Column#10, 1), bigint(1) BINARY)->Column#12 + └─Selection 0.80 root lt(Column#10, 100) + └─CTETable 1.00 root Scan on CTE_2 +show warnings; +Level Code Message +set tidb_cost_model_version=DEFAULT; +set tidb_opt_force_inline_cte=DEFAULT; +drop table if exists t, t1, t2; +CREATE TABLE `t` (`a` int(11)); +create table t1 (c1 int primary key, c2 int, index c2 (c2)); +create table t2 (c1 int unique, c2 int); +insert into t values (1), (5), (10), (15), (20), (30), (50); +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 1) select * from cte1; -- non-recursive limit, inline cte1; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─HashAgg 1.00 root group by:Column#18, funcs:firstrow(Column#18)->Column#18 + └─Union 20000.00 root + ├─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 100 offset 100) select * from cte1; -- non-recursive limit, inline cte1; +id estRows task access object operator info +Limit 100.00 root offset:100, count:100 +└─HashAgg 200.00 root group by:Column#18, funcs:firstrow(Column#18)->Column#18 + └─Union 20000.00 root + ├─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─IndexReader 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 0 offset 0) select * from cte1; -- non-recursive limit, inline cte1; +id estRows task access object operator info +TableDual 0.00 root rows:0 +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union (with cte2 as (select 3) select * from cte2 union all select * from cte2) -- inline cte1, not inline cte2; +id estRows task access object operator info +HashAgg 3.00 root group by:Column#9, funcs:firstrow(Column#9)->Column#9 +└─Union 3.00 root + ├─Projection 1.00 root 1->Column#9 + │ └─TableDual 1.00 root rows:1 + └─Union 2.00 root + ├─CTEFullScan 1.00 root CTE:cte2 data:CTE_2 + └─CTEFullScan 1.00 root CTE:cte2 data:CTE_2 +CTE_2 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 3->Column#5 + └─TableDual 1.00 root rows:1 +explain format='brief' with base1 as (WITH RECURSIVE cte(a) AS (with tmp as (select 1 as a) SELECT a from tmp UNION SELECT a+1 FROM cte) SELECT * FROM cte) select * from base1; -- issue #43318; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte data:CTE_3 +CTE_3 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#15 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 1.00 root cast(plus(Column#16, 1), bigint(1) BINARY)->Column#18 + └─CTETable 1.00 root Scan on CTE_3 +explain format='brief' with cte as (select 1) select * from cte; -- inline cte; +id estRows task access object operator info +Projection 1.00 root 1->Column#3 +└─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union select * from cte2; -- inline cte1, cte2; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#7, funcs:firstrow(Column#7)->Column#7 +└─Union 2.00 root + ├─Projection 1.00 root 1->Column#7 + │ └─TableDual 1.00 root rows:1 + └─Projection 1.00 root 2->Column#7 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- cannot be inlined; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#4, funcs:firstrow(Column#4)->Column#4 +└─Union 2.00 root + ├─CTEFullScan 1.00 root CTE:cte data:CTE_0 + └─CTEFullScan 1.00 root CTE:cte data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#1 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte; -- inline nested cte; +id estRows task access object operator info +Projection 1.00 root 1->Column#7 +└─TableDual 1.00 root rows:1 +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte a, cte b; -- inline inner cte, cannot be inlined outer cte; +id estRows task access object operator info +HashJoin 1.00 root CARTESIAN inner join +├─CTEFullScan(Build) 1.00 root CTE:cte AS b data:CTE_0 +└─CTEFullScan(Probe) 1.00 root CTE:cte AS a data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#3 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte1, cte2; -- inline cte2, cte3, cannot be inlined cte1; +id estRows task access object operator info +HashJoin 1.00 root CARTESIAN inner join +├─CTEFullScan(Build) 1.00 root CTE:cte1 data:CTE_0 +└─CTEFullScan(Probe) 1.00 root CTE:cte1 data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#1 + └─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte2; -- inline cte1, cte2, cte3; +id estRows task access object operator info +Projection 1.00 root 1->Column#12 +└─TableDual 1.00 root rows:1 +explain format='brief' with cte1 as (select 1), cte2 as (select * from cte1) select * from cte2 a, cte2 b; -- inline cte1, cannot be inlined cte2; +id estRows task access object operator info +HashJoin 1.00 root CARTESIAN inner join +├─CTEFullScan(Build) 1.00 root CTE:cte2 AS b data:CTE_1 +└─CTEFullScan(Probe) 1.00 root CTE:cte2 AS a data:CTE_1 +CTE_1 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#3 + └─TableDual 1.00 root rows:1 +explain format='brief' with recursive cte(a) as (select 1 union select a from cte) select * from cte; -- recursive cte cannot be inlined; +id estRows task access object operator info +CTEFullScan 2.00 root CTE:cte data:CTE_0 +CTE_0 2.00 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#2 +│ └─TableDual 1.00 root rows:1 +└─CTETable(Recursive Part) 1.00 root Scan on CTE_0 +explain format='brief' with x as (select * from (select a from t for update) s) select * from x where a = 1; +id estRows task access object operator info +Projection 10.00 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─SelectLock 10.00 root for update 0 + └─TableReader 10.00 root data:Selection + └─Selection 10.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- force inline cte while multi-consumer; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#6, funcs:firstrow(Column#6)->Column#6 +└─Union 2.00 root + ├─Projection 1.00 root 1->Column#6 + │ └─TableDual 1.00 root rows:1 + └─Projection 1.00 root 1->Column#6 + └─TableDual 1.00 root rows:1 +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select 1) select /*+ MERGE() */ * from cte union select * from cte; -- firstly inline cte, secondly cannot be inlined; +id estRows task access object operator info +HashAgg 2.00 root group by:Column#4, funcs:firstrow(Column#4)->Column#4 +└─Union 2.00 root + ├─CTEFullScan 1.00 root CTE:cte data:CTE_0 + └─CTEFullScan 1.00 root CTE:cte data:CTE_0 +CTE_0 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 1->Column#1 + └─TableDual 1.00 root rows:1 +explain format='brief' with a as (select 8 as id from dual),maxa as (select max(id) as max_id from a),b as (with recursive temp as (select 1 as lvl from dual union all select lvl+1 from temp, maxa where lvl < max_id)select * from temp) select * from b; -- issue #47711, maxa cannot be inlined because it contains agg and in the recursive part of cte temp; +id estRows task access object operator info +CTEFullScan 1.64 root CTE:temp data:CTE_4 +CTE_4 1.64 root Recursive CTE +├─Projection(Seed Part) 1.00 root 1->Column#14 +│ └─TableDual 1.00 root rows:1 +└─Projection(Recursive Part) 0.64 root cast(plus(Column#15, 1), bigint(1) BINARY)->Column#18 + └─HashJoin 0.64 root CARTESIAN inner join, other cond:lt(Column#15, Column#16) + ├─Selection(Build) 0.80 root not(isnull(Column#16)) + │ └─CTEFullScan 1.00 root CTE:maxa data:CTE_1 + └─Selection(Probe) 0.80 root not(isnull(Column#15)) + └─CTETable 1.00 root Scan on CTE_4 +CTE_1 1.00 root Non-Recursive CTE +└─StreamAgg(Seed Part) 1.00 root funcs:max(Column#3)->Column#4 + └─Projection 1.00 root 8->Column#3 + └─TableDual 1.00 root rows:1 +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select 1 as res from t1 union all select res+1 from tmp,b where res+1 < bb) select * from tmp) select * from c; -- inline a, cannot be inline b because b indirectly contains agg and in the recursive part of cte tmp; +id estRows task access object operator info +CTEFullScan 20000.00 root CTE:tmp data:CTE_4 +CTE_4 20000.00 root Recursive CTE +├─Projection(Seed Part) 10000.00 root 1->Column#26 +│ └─TableReader 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─Projection(Recursive Part) 10000.00 root cast(plus(Column#27, 1), bigint(1) BINARY)->Column#30 + └─HashJoin 10000.00 root CARTESIAN inner join, other cond:lt(plus(Column#27, 1), Column#28) + ├─CTEFullScan(Build) 1.00 root CTE:b data:CTE_1 + └─CTETable(Probe) 10000.00 root Scan on CTE_4 +CTE_1 1.00 root Non-Recursive CTE +└─Projection(Seed Part) 1.00 root 2->Column#8 + └─HashAgg 1.00 root funcs:count(Column#37)->Column#35 + └─TableReader 1.00 root data:HashAgg + └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#37 + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c; +id estRows task access object operator info +CTEFullScan 1.80 root CTE:tmp data:CTE_4 +CTE_4 1.80 root Recursive CTE +├─Projection(Seed Part) 1.00 root 2->Column#37 +│ └─HashAgg 1.00 root funcs:count(Column#46)->Column#44 +│ └─TableReader 1.00 root data:HashAgg +│ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#46 +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─Projection(Recursive Part) 0.80 root cast(plus(Column#38, 1), bigint(1) BINARY)->Column#40 + └─Selection 0.80 root lt(plus(Column#38, 1), 10) + └─CTETable 1.00 root Scan on CTE_4 +drop table if exists t; +create table t(a int, b int, c int, index(c)); +insert into t values (1, 1, 1), (1, 1, 3), (1, 2, 3), (2, 1, 3), (1, 2, NULL); +drop table if exists pt; +CREATE TABLE pt (a int, b int) PARTITION BY RANGE (a) ( +PARTITION p0 VALUES LESS THAN (2), +PARTITION p1 VALUES LESS THAN (100) +); +drop table if exists tc; +CREATE TABLE `tc`(`timestamp` timestamp NULL DEFAULT NULL, KEY `idx_timestamp` (`timestamp`)) PARTITION BY RANGE ( UNIX_TIMESTAMP(`timestamp`) ) (PARTITION `p2020072312` VALUES LESS THAN (1595480400),PARTITION `p2020072313` VALUES LESS THAN (1595484000)); +drop table if exists ta; +create table ta(a int); +insert into ta values(1), (1); +drop table if exists tb; +create table tb(a int); +insert into tb values(1), (1); +set session sql_mode=''; +set session tidb_hashagg_partial_concurrency=1; +set session tidb_hashagg_final_concurrency=1; +set @@tidb_partition_prune_mode='static'; +set @@session.tidb_opt_distinct_agg_push_down = 1; +set session tidb_opt_agg_push_down = 0; +set tidb_cost_model_version=2; +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(distinct Column#9)->Column#4 +└─Projection 16000.00 root cast(planner__core__casetest__physicalplantest__physical_plan.pt.b, decimal(10,0) BINARY)->Column#9 + └─PartitionUnion 16000.00 root + ├─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b + │ └─TableReader 8000.00 root data:HashAgg + │ └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, + │ └─TableFullScan 10000.00 cop[tikv] table:pt, partition:p0 keep order:false, stats:pseudo + └─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pt.b)->planner__core__casetest__physicalplantest__physical_plan.pt.b + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.pt.b, + └─TableFullScan 10000.00 cop[tikv] table:pt, partition:p1 keep order:false, stats:pseudo +select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +sum(distinct b) +NULL +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +id estRows task access object operator info +HashAgg 1.00 root funcs:count(distinct Column#5)->Column#6 +└─Union 20000.00 root + ├─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo +select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +count(distinct a) +1 +explain format = 'brief' select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; +id estRows task access object operator info +HashAgg 16000.00 root group by:Column#5, funcs:firstrow(Column#6)->Column#3 +└─PartitionUnion 16000.00 root + ├─HashAgg 8000.00 root group by:Column#7, funcs:firstrow(Column#7)->Column#6, funcs:firstrow(Column#7)->Column#5 + │ └─IndexReader 8000.00 root index:HashAgg + │ └─HashAgg 8000.00 cop[tikv] group by:date_format(planner__core__casetest__physicalplantest__physical_plan.tc.timestamp, "%Y-%m-%d %H"), + │ └─IndexFullScan 10000.00 cop[tikv] table:tc, partition:p2020072312, index:idx_timestamp(timestamp) keep order:false, stats:pseudo + └─HashAgg 8000.00 root group by:Column#10, funcs:firstrow(Column#10)->Column#6, funcs:firstrow(Column#10)->Column#5 + └─IndexReader 8000.00 root index:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:date_format(planner__core__casetest__physicalplantest__physical_plan.tc.timestamp, "%Y-%m-%d %H"), + └─IndexFullScan 10000.00 cop[tikv] table:tc, partition:p2020072313, index:idx_timestamp(timestamp) keep order:false, stats:pseudo +select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; +tt +set session sql_mode=DEFAULT; +set session tidb_hashagg_partial_concurrency=DEFAULT; +set session tidb_hashagg_final_concurrency=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +set @@session.tidb_opt_distinct_agg_push_down = DEFAULT; +set session tidb_opt_agg_push_down = DEFAULT; +drop table if exists t; +create table t (a int, b int, index idx_a(a), index idx_b(b)); +insert into t values(1, 1); +insert into t values(1, 2); +insert into t values(2, 4); +insert into t values(3, 5); +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +id estRows task access object operator info +MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b +├─IndexReader(Build) 9990.00 root index:IndexFullScan +│ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo +└─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, minus(planner__core__casetest__physicalplantest__physical_plan.t.a, 1)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, unaryminus(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(unaryminus(planner__core__casetest__physicalplantest__physical_plan.t.a), 3)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(1, planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, minus(1, planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(minus(1, planner__core__casetest__physicalplantest__physical_plan.t.a), 3)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, desc, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, desc, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +a +2 +1 +1 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, plus(plus(1, planner__core__casetest__physicalplantest__physical_plan.t.a), 3)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +a +1 +1 +2 +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; +id estRows task access object operator info +Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a +└─Sort 12487.50 root Column#7 + └─Projection 12487.50 root planner__core__casetest__physicalplantest__physical_plan.t.a, mul(3, planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#7 + └─MergeJoin 12487.50 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t.a, right key:planner__core__casetest__physicalplantest__physical_plan.t.b + ├─IndexReader(Build) 9990.00 root index:IndexFullScan + │ └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx_b(b) keep order:true, stats:pseudo + └─IndexReader(Probe) 9990.00 root index:IndexFullScan + └─IndexFullScan 9990.00 cop[tikv] table:t1, index:idx_a(a) keep order:true, stats:pseudo +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; +a +1 +1 +2 +drop table if exists test.tt; +create table test.tt (a int,b int, index(a), index(b)); +insert into test.tt values (1, 1), (2, 2), (3, 4); +set @@tidb_partition_prune_mode='static'; +explain format = 'brief' select /*+nth_plan(1)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +TableReader 0.01 root data:Selection +└─Selection 0.01 cop[tikv] eq(test.tt.a, 1), eq(test.tt.b, 1) + └─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select /*+nth_plan(3)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:b(b) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.a, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +explain format = 'brief' select * from test.tt where a=1 and b=1; +id estRows task access object operator info +IndexLookUp 0.01 root +├─IndexRangeScan(Build) 10.00 cop[tikv] table:tt, index:a(a) range:[1,1], keep order:false, stats:pseudo +└─Selection(Probe) 0.01 cop[tikv] eq(test.tt.b, 1) + └─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo +set @@tidb_partition_prune_mode=DEFAULT; +drop table if exists t; +create table t(e enum('c','b','a',''), index idx(e)); +insert ignore into t values(0),(1),(2),(3),(4); +explain format='brief' select e from t where e = 'b'; +id estRows task access object operator info +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:["b","b"], keep order:false, stats:pseudo +select e from t where e = 'b'; +e +b +explain format='brief' select e from t where e != 'b'; +id estRows task access object operator info +IndexReader 40.00 root index:IndexRangeScan +└─IndexRangeScan 40.00 cop[tikv] table:t, index:idx(e) range:["",""], ["c","c"], ["a","a"], ["",""], keep order:false, stats:pseudo +select e from t where e != 'b'; +e + +c +a + +explain format='brief' select e from t where e > 'b'; +id estRows task access object operator info +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:["c","c"], keep order:false, stats:pseudo +select e from t where e > 'b'; +e +c +explain format='brief' select e from t where e >= 'b'; +id estRows task access object operator info +IndexReader 20.00 root index:IndexRangeScan +└─IndexRangeScan 20.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], keep order:false, stats:pseudo +select e from t where e >= 'b'; +e +c +b +explain format='brief' select e from t where e < 'b'; +id estRows task access object operator info +IndexReader 30.00 root index:IndexRangeScan +└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["",""], ["a","a"], ["",""], keep order:false, stats:pseudo +select e from t where e < 'b'; +e + +a + +explain format='brief' select e from t where e <= 'b'; +id estRows task access object operator info +IndexReader 40.00 root index:IndexRangeScan +└─IndexRangeScan 40.00 cop[tikv] table:t, index:idx(e) range:["",""], ["b","b"], ["a","a"], ["",""], keep order:false, stats:pseudo +select e from t where e <= 'b'; +e + +b +a + +explain format='brief' select e from t where e = 2; +id estRows task access object operator info +IndexReader 10.00 root index:IndexRangeScan +└─IndexRangeScan 10.00 cop[tikv] table:t, index:idx(e) range:["b","b"], keep order:false, stats:pseudo +select e from t where e = 2; +e +b +explain format='brief' select e from t where e != 2; +id estRows task access object operator info +IndexReader 6656.67 root index:IndexRangeScan +└─IndexRangeScan 6656.67 cop[tikv] table:t, index:idx(e) range:[-inf,"b"), ("b",+inf], keep order:false, stats:pseudo +select e from t where e != 2; +e + +c +a + +explain format='brief' select e from t where e > 2; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:("b",+inf], keep order:false, stats:pseudo +select e from t where e > 2; +e +a + +explain format='brief' select e from t where e >= 2; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:["b",+inf], keep order:false, stats:pseudo +select e from t where e >= 2; +e +b +a + +explain format='brief' select e from t where e < 2; +id estRows task access object operator info +IndexReader 3323.33 root index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t, index:idx(e) range:[-inf,"b"), keep order:false, stats:pseudo +select e from t where e < 2; +e + +c +explain format='brief' select e from t where e <= 2; +id estRows task access object operator info +IndexReader 3323.33 root index:IndexRangeScan +└─IndexRangeScan 3323.33 cop[tikv] table:t, index:idx(e) range:[-inf,"b"], keep order:false, stats:pseudo +select e from t where e <= 2; +e + +c +b +explain format='brief' select e from t where e > ''; +id estRows task access object operator info +IndexReader 30.00 root index:IndexRangeScan +└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], ["a","a"], keep order:false, stats:pseudo +select e from t where e > ''; +e +c +b +a +explain format='brief' select e from t where e > 'd'; +id estRows task access object operator info +TableDual 0.00 root rows:0 +select e from t where e > 'd'; +e +explain format='brief' select e from t where e > -1; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:["",+inf], keep order:false, stats:pseudo +select e from t where e > -1; +e + +c +b +a + +explain format='brief' select e from t where e > 5; +id estRows task access object operator info +IndexReader 3333.33 root index:IndexRangeScan +└─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:("",+inf], keep order:false, stats:pseudo +select e from t where e > 5; +e +explain format='brief' select e from t where e = ''; +id estRows task access object operator info +IndexReader 20.00 root index:IndexRangeScan +└─IndexRangeScan 20.00 cop[tikv] table:t, index:idx(e) range:["",""], ["",""], keep order:false, stats:pseudo +select e from t where e = ''; +e + + +explain format='brief' select e from t where e != ''; +id estRows task access object operator info +IndexReader 30.00 root index:IndexRangeScan +└─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], ["a","a"], keep order:false, stats:pseudo +select e from t where e != ''; +e +c +b +a +drop table if exists PK_S_MULTI_31; +CREATE TABLE `PK_S_MULTI_31` ( +`COL1` tinyint(45) NOT NULL, +`COL2` tinyint(45) NOT NULL, +PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into PK_S_MULTI_31 values(122,100),(124,-22),(124,34),(127,103); +explain format='brief' SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; +id estRows task access object operator info +Sort 0.80 root planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2 +└─Projection 0.80 root planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2 + └─Selection 0.80 root gt(Column#7, 2) + └─HashAgg 1.00 root group by:planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1, planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2)->planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2, funcs:count(distinct planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1, planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col2)->Column#7 + └─HashJoin 100000000.00 root CARTESIAN left outer join, other cond:gt(planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1, planner__core__casetest__physicalplantest__physical_plan.pk_s_multi_31.col1) + ├─IndexReader(Build) 10000.00 root index:IndexFullScan + │ └─IndexFullScan 10000.00 cop[tikv] table:T2, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo + └─IndexReader(Probe) 10000.00 root index:IndexFullScan + └─IndexFullScan 10000.00 cop[tikv] table:T1, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo +SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; +col2 +100 +drop table if exists t1, t2; +create table t1(a int, b int as (a+1) virtual); +create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a)); +explain format='brief' select * from t1 where a > 1 and b > 1; +id estRows task access object operator info +Selection 1111.11 root gt(planner__core__casetest__physicalplantest__physical_plan.t1.b, 1) +└─TableReader 3333.33 root data:Selection + └─Selection 3333.33 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.t1.a, 1) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +explain format='brief' select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1; +id estRows task access object operator info +Selection 370.37 root gt(planner__core__casetest__physicalplantest__physical_plan.t2.b, 1) +└─IndexLookUp 1111.11 root + ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t2, index:idx_a(a) range:(1,+inf], keep order:false, stats:pseudo + └─Selection(Probe) 1111.11 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.t2.c, 1) + └─TableRowIDScan 3333.33 cop[tikv] table:t2 keep order:false, stats:pseudo +drop table if exists t; +create table t(a int); +explain format='brief' select * from t where t.a < 3 and t.a < 3; +id estRows task access object operator info +TableReader 3323.33 root data:Selection +└─Selection 3323.33 cop[tikv] lt(planner__core__casetest__physicalplantest__physical_plan.t.a, 3) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11), `b` int(11), `c` int(11), `d` date); +insert into t (a,b,c,d) value(1,4,5,'2019-06-01'); +insert into t (a,b,c,d) value(2,null,1,'2019-07-01'); +insert into t (a,b,c,d) value(3,4,5,'2019-08-01'); +insert into t (a,b,c,d) value(3,6,2,'2019-09-01'); +insert into t (a,b,c,d) value(10,4,null,'2020-06-01'); +insert into t (a,b,c,d) value(20,null,1,'2020-07-01'); +insert into t (a,b,c,d) value(30,4,5,'2020-08-01'); +insert into t (a,b,c,d) value(30,6,5,'2020-09-01'); +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +df sum(a) count(b) count(distinct c) +2019 9 3 3 +2020 90 3 2 +set @@tidb_opt_skew_distinct_agg=1; +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +df sum(a) count(b) count(distinct c) +2019 9 3 3 +2020 90 3 2 +select count(distinct b), sum(c) from t group by a order by 1,2; +count(distinct b) sum(c) +0 1 +0 1 +1 NULL +1 5 +2 7 +2 10 +select count(distinct b) from t group by date_format(d,'%Y') order by 1; +count(distinct b) +2 +2 +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y') order by 1,2,3; +count(a) count(distinct b) max(b) +4 2 6 +4 2 6 +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +count(a) count(distinct b) max(b) +1 0 NULL +1 0 NULL +1 1 4 +1 1 6 +2 1 4 +2 2 6 +select avg(distinct b), count(a), sum(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +avg(distinct b) count(a) sum(b) +NULL 1 NULL +NULL 1 NULL +4.0000 1 4 +4.0000 2 8 +5.0000 2 10 +6.0000 1 6 +explain format='brief' select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y'); +id estRows task access object operator info +Projection 8000.00 root date_format(planner__core__casetest__physicalplantest__physical_plan.t.d, %Y)->Column#9, Column#6, cast(Column#13, bigint(21) BINARY)->Column#7, Column#8 +└─HashAgg 8000.00 root group by:Column#23, funcs:sum(Column#19)->Column#6, funcs:sum(Column#20)->Column#13, funcs:count(Column#21)->Column#8, funcs:firstrow(Column#22)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─Projection 8000.00 root Column#11->Column#19, cast(Column#12, decimal(20,0) BINARY)->Column#20, planner__core__casetest__physicalplantest__physical_plan.t.c->Column#21, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#22, date_format(planner__core__casetest__physicalplantest__physical_plan.t.d, %Y)->Column#23 + └─HashAgg 8000.00 root group by:Column#14, planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:sum(Column#15)->Column#11, funcs:count(Column#16)->Column#12, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.c)->planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:firstrow(Column#18)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:date_format(planner__core__casetest__physicalplantest__physical_plan.t.d, "%Y"), planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#15, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#16, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.d)->Column#18 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format='brief' select d, a, count(*), count(b), count(distinct c) from t group by d, a; +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t.d, planner__core__casetest__physicalplantest__physical_plan.t.a, cast(Column#10, bigint(21) BINARY)->Column#6, cast(Column#12, bigint(21) BINARY)->Column#7, Column#8 +└─HashAgg 8000.00 root group by:Column#23, Column#24, funcs:sum(Column#18)->Column#10, funcs:sum(Column#19)->Column#12, funcs:count(Column#20)->Column#8, funcs:firstrow(Column#21)->planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:firstrow(Column#22)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─Projection 8000.00 root cast(Column#9, decimal(20,0) BINARY)->Column#18, cast(Column#11, decimal(20,0) BINARY)->Column#19, planner__core__casetest__physicalplantest__physical_plan.t.c->Column#20, planner__core__casetest__physicalplantest__physical_plan.t.a->Column#21, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#22, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#23, planner__core__casetest__physicalplantest__physical_plan.t.a->Column#24 + └─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:count(Column#13)->Column#9, funcs:count(Column#14)->Column#11, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.c)->planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.a)->planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.d)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:count(1)->Column#13, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#14 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format='brief' select d, sum(a), count(b), avg(distinct c) from t group by d; +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t.d, Column#6, cast(Column#11, bigint(21) BINARY)->Column#7, Column#8 +└─HashAgg 8000.00 root group by:Column#20, funcs:sum(Column#16)->Column#6, funcs:sum(Column#17)->Column#11, funcs:avg(Column#18)->Column#8, funcs:firstrow(Column#19)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─Projection 8000.00 root Column#9->Column#16, cast(Column#10, decimal(20,0) BINARY)->Column#17, cast(planner__core__casetest__physicalplantest__physical_plan.t.c, decimal(10,0) BINARY)->Column#18, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#19, planner__core__casetest__physicalplantest__physical_plan.t.d->Column#20 + └─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:sum(Column#12)->Column#9, funcs:count(Column#13)->Column#10, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.c)->planner__core__casetest__physicalplantest__physical_plan.t.c, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.d)->planner__core__casetest__physicalplantest__physical_plan.t.d + └─TableReader 8000.00 root data:HashAgg + └─HashAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#12, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#13 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_cost_model_version=DEFAULT; +set @@tidb_opt_skew_distinct_agg=DEFAULT; +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +create table t3(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +2 NULL +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root right outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +NULL 2 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +a b +1 1 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +id estRows task access object operator info +HashJoin 8000.00 root anti semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +a b +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +sum(t1.a in (select a from t2)) +2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +id estRows task access object operator info +HashAgg 1.00 root funcs:sum(Column#9)->Column#8 +└─Projection 10000.00 root cast(Column#7, decimal(3,0) BINARY)->Column#9 + └─MergeJoin 10000.00 root anti left outer semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +sum(t1.a not in (select a from t2)) +0 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for anti left outer semi join, please check the hint +explain format = 'brief' select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (t2) in optimizer hint /*+ HASH_JOIN_PROBE(t2, t2) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (t1) in optimizer hint /*+ HASH_JOIN_BUILD(t1, t1) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (tt) in optimizer hint /*+ HASH_JOIN_PROBE(tt) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 There are no matching table names for (tt) in optimizer hint /*+ HASH_JOIN_BUILD(tt) */. Maybe you can use the table alias name +explain format = 'brief' select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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:tt keep order:false, stats:pseudo +select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +Projection 15625.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a +└─HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo + └─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) eq(planner__core__casetest__physicalplantest__physical_plan.t2.b, planner__core__casetest__physicalplantest__physical_plan.t1.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 +select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +Projection 15625.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a +└─HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo + └─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.a) eq(planner__core__casetest__physicalplantest__physical_plan.t2.b, planner__core__casetest__physicalplantest__physical_plan.t1.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 +select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +id estRows task access object operator info +HashJoin 15625.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─HashJoin(Probe) 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +a a +1 1 +show warnings; +Level Code Message +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints conflict after join reorder phase, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +show warnings; +Level Code Message +Warning 1815 Join hints are conflict, you can only specify one type of join +explain format = 'brief' SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─StreamAgg(Build) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a +│ └─TableReader 8000.00 root data:StreamAgg +│ └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, +│ └─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:false, stats:pseudo +SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─StreamAgg(Probe) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a + └─TableReader 8000.00 root data:StreamAgg + └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─StreamAgg(Probe) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a + └─TableReader 8000.00 root data:StreamAgg + └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:true, stats:pseudo +SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +id estRows task access object operator info +HashJoin 10000.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─StreamAgg(Build) 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t2.a)->planner__core__casetest__physicalplantest__physical_plan.t2.a +│ └─TableReader 8000.00 root data:StreamAgg +│ └─StreamAgg 8000.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t2.a, +│ └─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:false, stats:pseudo +SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 12500.00 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 12500.00 root inner join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +id estRows task access object operator info +MergeJoin 8000.00 root semi join, left key:planner__core__casetest__physicalplantest__physical_plan.t1.a, right key:planner__core__casetest__physicalplantest__physical_plan.t2.a +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 We can't use the HASH_JOIN_BUILD or HASH_JOIN_PROBE hint for semi join, please check the hint +set tidb_cost_model_version=DEFAULT; +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int, b int) partition by hash(a) partitions 4; +create table t2(a int, b int) partition by hash(a) partitions 5; +create table t3(a int, b int) partition by hash(b) partitions 3; +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +set @@tidb_partition_prune_mode="static"; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 49900.05 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 39920.04 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 39920.04 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 49900.05 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 39920.04 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 49900.05 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +id estRows task access object operator info +HashJoin 49900.05 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─PartitionUnion(Build) 49900.05 root +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p0 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p1 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p2 keep order:false, stats:pseudo +│ ├─TableReader 9980.01 root data:Selection +│ │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ │ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p3 keep order:false, stats:pseudo +│ └─TableReader 9980.01 root data:Selection +│ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t2, partition:p4 keep order:false, stats:pseudo +└─PartitionUnion(Probe) 39920.04 root + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p0 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo + ├─TableReader 9980.01 root data:Selection + │ └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p2 keep order:false, stats:pseudo + └─TableReader 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p3 keep order:false, stats:pseudo +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +a a +1 1 +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3, ta, tb, tc, td; +create table t1(a int, b int); +create table t2(a int primary key, b int); +create table t3(a int, b int); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +create table ta(id int, code int, name varchar(20), index idx_ta_id(id),index idx_ta_name(name), index idx_ta_code(code)); +create table tb(id int, code int, name varchar(20), index idx_tb_id(id),index idx_tb_name(name)); +create table tc(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +create table td(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +explain format = 'brief' select /*+ no_decorrelate() */ * from t1; +id estRows task access object operator info +TableReader 10000.00 root data:TableFullScan +└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select /*+ no_decorrelate() */ * from t1; +a b +1 1 +2 2 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery. +explain format = 'brief' select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +id estRows task access object operator info +HashJoin 100000000.00 root CARTESIAN inner join +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +a b a b +1 1 1 1 +1 1 2 1 +2 2 1 1 +2 2 2 1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery. +explain format = 'brief' select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +id estRows task access object operator info +Projection 10000.00 root plus(planner__core__casetest__physicalplantest__physical_plan.t1.a, 1)->Column#4, minus(planner__core__casetest__physicalplantest__physical_plan.t1.b, 1)->Column#5 +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +a+1 b-1 +2 0 +3 1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because it's not in an IN subquery, an EXISTS subquery, an ANY/ALL/SOME subquery or a scalar subquery. +explain format = 'brief' select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +id estRows task access object operator info +HashJoin 10000.00 root left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t3.a, planner__core__casetest__physicalplantest__physical_plan.t1.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +exists (select /*+ semi_join_rewrite(), no_decorrelate() * from t1 where t1.a=t3.a) +1 +1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() and SEMI_JOIN_REWRITE() are in conflict. Both will be ineffective. +explain format = 'brief' select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +HashJoin 7984.01 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.a) eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b)] +├─TableReader(Build) 9990.00 root data:Selection +│ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) +│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +└─TableReader(Probe) 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.b)) + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +Projection 9990.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a +└─Apply 9990.00 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b)] + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a)) + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 99800.10 root data:Selection + └─Selection 99800.10 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b)) + └─TableRangeScan 9990.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a +└─Selection 8000.00 root Column#6 + └─HashJoin 10000.00 root left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.a)], other cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b) + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 +select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a +└─Selection 8000.00 root Column#6 + └─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b) + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +a +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, and(or(or(gt(Column#9, 1), ne(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8)), if(ne(Column#10, 0), , 0)), and(ne(Column#11, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 1)))->Column#12 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#14)->Column#8, funcs:count(distinct Column#15)->Column#9, funcs:sum(Column#16)->Column#10, funcs:count(1)->Column#11 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#14, planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#15, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#16 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +a t1.a != any (select t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, and(or(or(gt(Column#9, 1), ne(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8)), if(ne(Column#10, 0), , 0)), and(ne(Column#11, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 1)))->Column#12 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#14)->Column#8, funcs:count(distinct Column#15)->Column#9, funcs:sum(Column#16)->Column#10, funcs:count(1)->Column#11 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#14, planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#15, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#16 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +a t1.a != any (select /*+ no_decorrelate() t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, or(and(gt(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8), if(ne(Column#9, 0), , 1)), or(eq(Column#10, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 0)))->Column#11 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#19)->Column#8, funcs:sum(Column#20)->Column#9, funcs:count(1)->Column#10 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#19, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#20 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +a t1.a > all (select t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, or(and(gt(planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#8), if(ne(Column#9, 0), , 1)), or(eq(Column#10, 0), if(isnull(planner__core__casetest__physicalplantest__physical_plan.t1.a), , 0)))->Column#11 +└─Apply 10000.00 root CARTESIAN inner join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:max(Column#19)->Column#8, funcs:sum(Column#20)->Column#9, funcs:count(1)->Column#10 + └─Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t2.b->Column#19, cast(isnull(planner__core__casetest__physicalplantest__physical_plan.t2.b), decimal(20,0) BINARY)->Column#20 + └─TableReader 10000.00 root data:TableRangeScan + └─TableRangeScan 10000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +a t1.a > all (select /*+ no_decorrelate() t2.b from t2 where t2.a = t1.b) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +HashJoin 12500.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t2.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─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 +select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +a (select t2.b from t2 where t2.a = t1.b) +1 1 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, planner__core__casetest__physicalplantest__physical_plan.t2.b +└─Apply 10000.00 root CARTESIAN left outer join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─MaxOneRow(Probe) 10000.00 root + └─TableReader 2000.00 root data:TableRangeScan + └─TableRangeScan 2000.00 cop[tikv] table:t2 range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, planner__core__casetest__physicalplantest__physical_plan.t1.b)], keep order:false, stats:pseudo +select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +a (select /*+ no_decorrelate() t2.b from t2 where t2.a = t1.b) +1 1 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.b not in (select t3.b from t3) from t1; +id estRows task access object operator info +HashJoin 10000.00 root Null-aware anti left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a, t1.b not in (select t3.b from t3) from t1; +a t1.b not in (select t3.b from t3) +1 0 +2 1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +id estRows task access object operator info +HashJoin 10000.00 root Null-aware anti left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.b)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +a t1.b not in (select /*+ no_decorrelate() t3.b from t3) +1 0 +2 1 +show warnings; +Level Code Message +Warning 1815 NO_DECORRELATE() is inapplicable because there are no correlated columns. +explain format = 'brief' select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +id estRows task access object operator info +HashJoin 10000.00 root left outer semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.a)] +├─TableReader(Build) 10000.00 root data:TableFullScan +│ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +exists (select t3.b from t3 where t3.a = t1.b limit 2) +1 +1 +show warnings; +Level Code Message +explain format = 'brief' select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +id estRows task access object operator info +Projection 10000.00 root Column#10 +└─Apply 10000.00 root CARTESIAN left outer semi join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─Limit(Probe) 20000.00 root offset:0, count:2 + └─TableReader 20000.00 root data:Limit + └─Limit 20000.00 cop[tikv] offset:0, count:2 + └─Selection 20000.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t3.a, planner__core__casetest__physicalplantest__physical_plan.t1.b) + └─TableFullScan 20000000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +exists (select /*+ no_decorrelate() t3.b from t3 where t3.a = t1.b limit 2) +1 +1 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +id estRows task access object operator info +Projection 1.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#6->Column#11 +└─HashJoin 1.00 root CARTESIAN left outer join + ├─Point_Get(Build) 1.00 root table:t2 handle:10 + └─HashAgg(Probe) 1.00 root funcs:sum(Column#13)->Column#6, funcs:firstrow(Column#14)->planner__core__casetest__physicalplantest__physical_plan.t1.a + └─TableReader 1.00 root data:HashAgg + └─HashAgg 1.00 cop[tikv] funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t1.a)->Column#13, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t1.a)->Column#14 + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +a (select sum(t1.a) from t2 where t2.a = 10) +1 3 +show warnings; +Level Code Message +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +id estRows task access object operator info +Projection 1.00 root planner__core__casetest__physicalplantest__physical_plan.t1.a, Column#9->Column#11 +└─Apply 1.00 root CARTESIAN left outer join + ├─HashAgg(Build) 1.00 root funcs:sum(Column#14)->Column#6, funcs:firstrow(Column#15)->planner__core__casetest__physicalplantest__physical_plan.t1.a + │ └─Projection 10000.00 root cast(planner__core__casetest__physicalplantest__physical_plan.t1.a, decimal(10,0) BINARY)->Column#14, planner__core__casetest__physicalplantest__physical_plan.t1.a->Column#15 + │ └─TableReader 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─MaxOneRow(Probe) 1.00 root + └─Projection 1.00 root Column#6->Column#9 + └─Point_Get 1.00 root table:t2 handle:10 +select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +a (select /*+ no_decorrelate() sum(t1.a) from t2 where t2.a = 10) +1 NULL +show warnings; +Level Code Message +explain format = 'brief' select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root ifnull(Column#10, 0)->Column#10 +└─HashJoin 10000.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t1.b, planner__core__casetest__physicalplantest__physical_plan.t3.b)] + ├─HashAgg(Build) 7992.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t3.b, funcs:count(Column#11)->Column#10, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t3.b)->planner__core__casetest__physicalplantest__physical_plan.t3.b + │ └─TableReader 7992.00 root data:HashAgg + │ └─HashAgg 7992.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.t3.b, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t3.a)->Column#11 + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.t3.b)) + │ └─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo + └─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +(select count(t3.a) from t3 where t3.b = t1.b) +0 +2 +show warnings; +Level Code Message +explain format = 'brief' select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +id estRows task access object operator info +Projection 10000.00 root Column#10 +└─Apply 10000.00 root CARTESIAN left outer join + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─MaxOneRow(Probe) 10000.00 root + └─StreamAgg 10000.00 root funcs:count(Column#12)->Column#10 + └─TableReader 10000.00 root data:StreamAgg + └─StreamAgg 10000.00 cop[tikv] funcs:count(planner__core__casetest__physicalplantest__physical_plan.t3.a)->Column#12 + └─Selection 100000.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t3.b, planner__core__casetest__physicalplantest__physical_plan.t1.b) + └─TableFullScan 100000000.00 cop[tikv] table:t3 keep order:false, stats:pseudo +select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +(select /*+ no_decorrelate() count(t3.a) from t3 where t3.b = t1.b) +0 +2 +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +HashJoin 250.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)] +├─TableReader(Build) 250.00 root data:Selection +│ └─Selection 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) +│ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo +└─HashAgg(Probe) 7992.00 root group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:sum(Column#19)->Column#13, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tb.id)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─TableReader 7992.00 root data:HashAgg + └─HashAgg 7992.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:sum(planner__core__casetest__physicalplantest__physical_plan.tb.code)->Column#19 + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)) + └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +Projection 250.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name, Column#13 +└─Apply 250.00 root CARTESIAN left outer join + ├─TableReader(Build) 250.00 root data:Selection + │ └─Selection 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) + │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─MaxOneRow(Probe) 250.00 root + └─StreamAgg 250.00 root funcs:sum(Column#21)->Column#13 + └─Projection 2500.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#21 + └─IndexLookUp 2500.00 root + ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +HashJoin 250.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)] +├─TableReader(Build) 250.00 root data:Selection +│ └─Selection 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) +│ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo +└─HashAgg(Probe) 6387.21 root group by:Column#39, funcs:sum(Column#37)->Column#18, funcs:firstrow(Column#38)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─Projection 7984.01 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#37, planner__core__casetest__physicalplantest__physical_plan.tb.id->Column#38, planner__core__casetest__physicalplantest__physical_plan.tb.id->Column#39 + └─HashJoin 7984.01 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)] + ├─TableReader(Build) 7992.00 root data:Selection + │ └─Selection 7992.00 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.name)) + │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo + └─TableReader(Probe) 9980.01 root data:Selection + └─Selection 9980.01 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.name)) + └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +Projection 250.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name, Column#18 +└─Apply 250.00 root CARTESIAN left outer join + ├─TableReader(Build) 250.00 root data:Selection + │ └─Selection 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) + │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─MaxOneRow(Probe) 250.00 root + └─StreamAgg 250.00 root funcs:sum(Column#33)->Column#18 + └─Projection 1998.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#33 + └─IndexHashJoin 1998.00 root semi join, inner:IndexLookUp, outer key:planner__core__casetest__physicalplantest__physical_plan.tb.name, inner key:planner__core__casetest__physicalplantest__physical_plan.tc.name, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name) + ├─IndexLookUp(Build) 2497.50 root + │ ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + │ └─Selection(Probe) 2497.50 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.name)) + │ └─TableRowIDScan 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─IndexLookUp(Probe) 3121.87 root + ├─Selection(Build) 3902.34 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.name)) + │ └─IndexRangeScan 3906.25 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.tc.name, planner__core__casetest__physicalplantest__physical_plan.tb.name)], keep order:false, stats:pseudo + └─Selection(Probe) 3121.87 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92) + └─TableRowIDScan 3902.34 cop[tikv] table:tc keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +HashJoin 250.00 root left outer join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)] +├─TableReader(Build) 250.00 root data:Selection +│ └─Selection 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) +│ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo +└─HashAgg(Probe) 7992.00 root group by:Column#28, funcs:sum(Column#26)->Column#18, funcs:firstrow(Column#27)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─Projection 9990.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#26, planner__core__casetest__physicalplantest__physical_plan.tb.id->Column#27, planner__core__casetest__physicalplantest__physical_plan.tb.id->Column#28 + └─Apply 9990.00 root CARTESIAN semi join + ├─TableReader(Build) 9990.00 root data:Selection + │ └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)) + │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─IndexLookUp(Probe) 79920.00 root + ├─IndexRangeScan(Build) 99900.00 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)], keep order:false, stats:pseudo + └─Selection(Probe) 79920.00 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92) + └─TableRowIDScan 99900.00 cop[tikv] table:tc keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +id estRows task access object operator info +Projection 250.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name, Column#18 +└─Apply 250.00 root CARTESIAN left outer join + ├─TableReader(Build) 250.00 root data:Selection + │ └─Selection 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.ta.name, "chad999%", 92) + │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─MaxOneRow(Probe) 250.00 root + └─StreamAgg 250.00 root funcs:sum(Column#22)->Column#18 + └─Projection 2500.00 root cast(planner__core__casetest__physicalplantest__physical_plan.tb.code, decimal(10,0) BINARY)->Column#22 + └─Apply 2500.00 root CARTESIAN semi join + ├─IndexLookUp(Build) 2500.00 root + │ ├─IndexRangeScan(Build) 2500.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 2500.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─IndexLookUp(Probe) 20000.00 root + ├─IndexRangeScan(Build) 25000.00 cop[tikv] table:tc, index:idx_tc_name(name) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.tb.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)], keep order:false, stats:pseudo + └─Selection(Probe) 20000.00 cop[tikv] like(cast(planner__core__casetest__physicalplantest__physical_plan.tc.code, var_string(20)), "999%", 92) + └─TableRowIDScan 25000.00 cop[tikv] table:tc keep order:false, stats:pseudo +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +NAME tb_sum_code +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +id estRows task access object operator info +Projection 9.99 root planner__core__casetest__physicalplantest__physical_plan.ta.id, split->Column#10 +└─HashJoin 9.99 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)] + ├─IndexLookUp(Build) 9.99 root + │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad999"], keep order:false, stats:pseudo + │ └─Selection(Probe) 9.99 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.id)) + │ └─TableRowIDScan 10.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─Selection(Probe) 6393.60 root gt(Column#9, 900) + └─HashAgg 7992.00 root group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:max(Column#19)->Column#9, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tb.id)->planner__core__casetest__physicalplantest__physical_plan.tb.id + └─TableReader 7992.00 root data:HashAgg + └─HashAgg 7992.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.tb.id, funcs:max(planner__core__casetest__physicalplantest__physical_plan.tb.code)->Column#19 + └─Selection 9990.00 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.id)) + └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +id flag +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +id estRows task access object operator info +Projection 10.00 root planner__core__casetest__physicalplantest__physical_plan.ta.id, split->Column#10 +└─Apply 10.00 root CARTESIAN inner join + ├─IndexLookUp(Build) 10.00 root + │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:ta, index:idx_ta_name(name) range:["chad999","chad999"], keep order:false, stats:pseudo + │ └─TableRowIDScan(Probe) 10.00 cop[tikv] table:ta keep order:false, stats:pseudo + └─Selection(Probe) 8.00 root gt(Column#9, 900) + └─MaxOneRow 10.00 root + └─StreamAgg 10.00 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.tb.code)->Column#9 + └─TopN 10.00 root planner__core__casetest__physicalplantest__physical_plan.tb.code:desc, offset:0, count:1 + └─IndexLookUp 10.00 root + ├─IndexRangeScan(Build) 100.00 cop[tikv] table:tb, index:idx_tb_id(id) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.tb.id)], keep order:false, stats:pseudo + └─TopN(Probe) 10.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tb.code:desc, offset:0, count:1 + └─Selection 99.90 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.code)) + └─TableRowIDScan 100.00 cop[tikv] table:tb keep order:false, stats:pseudo +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +id flag +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +id estRows task access object operator info +HashJoin 159.84 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.td.id)] +├─Selection(Build) 159.84 root gt(Column#19, 100) +│ └─HashAgg 199.80 root group by:planner__core__casetest__physicalplantest__physical_plan.td.id, funcs:max(Column#32)->Column#19, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.td.id)->planner__core__casetest__physicalplantest__physical_plan.td.id +│ └─TableReader 199.80 root data:HashAgg +│ └─HashAgg 199.80 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.td.id, funcs:max(planner__core__casetest__physicalplantest__physical_plan.td.id)->Column#32 +│ └─Selection 249.75 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.td.name, "chad999%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.td.id)) +│ └─TableFullScan 10000.00 cop[tikv] table:td keep order:false, stats:pseudo +└─HashJoin(Probe) 200.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.name, planner__core__casetest__physicalplantest__physical_plan.tc.name)] + ├─Selection(Build) 160.00 root gt(Column#14, 100) + │ └─HashAgg 200.00 root group by:planner__core__casetest__physicalplantest__physical_plan.tc.name, funcs:max(Column#24)->Column#14, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tc.name)->planner__core__casetest__physicalplantest__physical_plan.tc.name + │ └─TableReader 200.00 root data:HashAgg + │ └─HashAgg 200.00 cop[tikv] group by:planner__core__casetest__physicalplantest__physical_plan.tc.name, funcs:max(planner__core__casetest__physicalplantest__physical_plan.tc.id)->Column#24 + │ └─Selection 250.00 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.tc.name, "chad99%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.name)) + │ └─TableFullScan 10000.00 cop[tikv] table:tc keep order:false, stats:pseudo + └─HashJoin(Probe) 7976.02 root semi join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.ta.code, planner__core__casetest__physicalplantest__physical_plan.tb.code)] + ├─TableReader(Build) 249.75 root data:Selection + │ └─Selection 249.75 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.tb.name, "chad9%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.code)) + │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo + └─TableReader(Probe) 9970.03 root data:Selection + └─Selection 9970.03 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.code)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.id)), not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.name)) + └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo +SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +NAME +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +id estRows task access object operator info +Projection 249.75 root planner__core__casetest__physicalplantest__physical_plan.ta.name +└─Apply 249.75 root CARTESIAN inner join + ├─Apply(Build) 249.75 root CARTESIAN inner join + │ ├─IndexHashJoin(Build) 249.75 root inner join, inner:IndexLookUp, outer key:planner__core__casetest__physicalplantest__physical_plan.tb.code, inner key:planner__core__casetest__physicalplantest__physical_plan.ta.code, equal cond:eq(planner__core__casetest__physicalplantest__physical_plan.tb.code, planner__core__casetest__physicalplantest__physical_plan.ta.code) + │ │ ├─HashAgg(Build) 199.80 root group by:planner__core__casetest__physicalplantest__physical_plan.tb.code, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.tb.code)->planner__core__casetest__physicalplantest__physical_plan.tb.code + │ │ │ └─TableReader 249.75 root data:Selection + │ │ │ └─Selection 249.75 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.tb.name, "chad9%", 92), not(isnull(planner__core__casetest__physicalplantest__physical_plan.tb.code)) + │ │ │ └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo + │ │ └─IndexLookUp(Probe) 249.75 root + │ │ ├─Selection(Build) 249.75 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.ta.code)) + │ │ │ └─IndexRangeScan 250.00 cop[tikv] table:ta, index:idx_ta_code(code) range: decided by [eq(planner__core__casetest__physicalplantest__physical_plan.ta.code, planner__core__casetest__physicalplantest__physical_plan.tb.code)], keep order:false, stats:pseudo + │ │ └─TableRowIDScan(Probe) 249.75 cop[tikv] table:ta keep order:false, stats:pseudo + │ └─Selection(Probe) 199.80 root gt(Column#14, 100) + │ └─MaxOneRow 249.75 root + │ └─StreamAgg 249.75 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.tc.id)->Column#14 + │ └─TopN 62.38 root planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─IndexLookUp 62.38 root + │ ├─Selection(Build) 62.44 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.name, planner__core__casetest__physicalplantest__physical_plan.tc.name) + │ │ └─IndexRangeScan 62437.50 cop[tikv] table:tc, index:idx_tc_name(name) range:["chad99","chad9:"), keep order:false, stats:pseudo + │ └─TopN(Probe) 62.38 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─Selection 62.38 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.id)) + │ └─TableRowIDScan 62.44 cop[tikv] table:tc keep order:false, stats:pseudo + └─Selection(Probe) 199.80 root gt(Column#19, 100) + └─MaxOneRow 249.75 root + └─StreamAgg 249.75 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.td.id)->Column#19 + └─Limit 62.38 root offset:0, count:1 + └─Projection 62.38 root planner__core__casetest__physicalplantest__physical_plan.td.id, planner__core__casetest__physicalplantest__physical_plan.td.name + └─IndexLookUp 62.38 root + ├─Selection(Build) 2495.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.td.id) + │ └─IndexFullScan 2495002.50 cop[tikv] table:td, index:idx_tc_id(id) keep order:true, desc, stats:pseudo + └─Selection(Probe) 62.38 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.td.name, "chad999%", 92) + └─TableRowIDScan 2495.00 cop[tikv] table:td keep order:false, stats:pseudo +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +NAME +show warnings; +Level Code Message +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.ta.name +└─Apply 10000.00 root CARTESIAN inner join + ├─Apply(Build) 10000.00 root CARTESIAN inner join + │ ├─Apply(Build) 10000.00 root CARTESIAN semi join + │ │ ├─TableReader(Build) 10000.00 root data:TableFullScan + │ │ │ └─TableFullScan 10000.00 cop[tikv] table:ta keep order:false, stats:pseudo + │ │ └─TableReader(Probe) 2500.00 root data:Selection + │ │ └─Selection 2500.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.code, planner__core__casetest__physicalplantest__physical_plan.tb.code), like(planner__core__casetest__physicalplantest__physical_plan.tb.name, "chad9%", 92) + │ │ └─TableFullScan 100000000.00 cop[tikv] table:tb keep order:false, stats:pseudo + │ └─Selection(Probe) 8000.00 root gt(Column#14, 100) + │ └─MaxOneRow 10000.00 root + │ └─StreamAgg 10000.00 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.tc.id)->Column#14 + │ └─TopN 2497.50 root planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─IndexLookUp 2497.50 root + │ ├─Selection(Build) 2500.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.name, planner__core__casetest__physicalplantest__physical_plan.tc.name) + │ │ └─IndexRangeScan 2500000.00 cop[tikv] table:tc, index:idx_tc_name(name) range:["chad99","chad9:"), keep order:false, stats:pseudo + │ └─TopN(Probe) 2497.50 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.tc.id:desc, offset:0, count:1 + │ └─Selection 2497.50 cop[tikv] not(isnull(planner__core__casetest__physicalplantest__physical_plan.tc.id)) + │ └─TableRowIDScan 2500.00 cop[tikv] table:tc keep order:false, stats:pseudo + └─Selection(Probe) 8000.00 root gt(Column#19, 100) + └─MaxOneRow 10000.00 root + └─StreamAgg 10000.00 root funcs:max(planner__core__casetest__physicalplantest__physical_plan.td.id)->Column#19 + └─Limit 2497.50 root offset:0, count:1 + └─Projection 2497.50 root planner__core__casetest__physicalplantest__physical_plan.td.id, planner__core__casetest__physicalplantest__physical_plan.td.name + └─IndexLookUp 2497.50 root + ├─Selection(Build) 99900.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.ta.id, planner__core__casetest__physicalplantest__physical_plan.td.id) + │ └─IndexFullScan 99900000.00 cop[tikv] table:td, index:idx_tc_id(id) keep order:true, desc, stats:pseudo + └─Selection(Probe) 2497.50 cop[tikv] like(planner__core__casetest__physicalplantest__physical_plan.td.name, "chad999%", 92) + └─TableRowIDScan 99900.00 cop[tikv] table:td keep order:false, stats:pseudo +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +NAME +show warnings; +Level Code Message +set tidb_cost_model_version=DEFAULT; +drop table if exists t, t_pick_row_id; +set tidb_cost_model_version=1; +create table t (a int(11) not null, b varchar(10) not null, c date not null, d char(1) not null, e bigint not null, f datetime not null, g bool not null, h bool ); +create table t_pick_row_id (a char(20) not null); +explain format = 'brief' select count(*) from t; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#12)->Column#10 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#12 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(1), count(3.1415), count(0), count(null) from t -- shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#18)->Column#10, funcs:count(Column#19)->Column#11, funcs:count(Column#20)->Column#12, funcs:count(Column#21)->Column#13 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#18, funcs:count(3.1415)->Column#19, funcs:count(0)->Column#20, funcs:count(NULL)->Column#21 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(*) from t where a=1; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#12)->Column#10 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#12 + └─Selection 10.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(*) from t_pick_row_id; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#5)->Column#3 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#5 + └─TableFullScan 10000.00 cop[tikv] table:t_pick_row_id keep order:false, stats:pseudo +explain format = 'brief' select t.b, t.c from (select count(*) as c from t) a, t where a.c=t.a -- shouldn't be rewritten; +id estRows task access object operator info +HashJoin 1.25 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.a, Column#10)] +├─StreamAgg(Build) 1.00 root funcs:count(Column#21)->Column#10 +│ └─TableReader 1.00 root data:StreamAgg +│ └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#21 +│ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +└─TableReader(Probe) 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select * from t outTable where outTable.a > (select count(*) from t inn where inn.a = outTable.b) -- shouldn't be rewritten; +id estRows task access object operator info +Projection 10000.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.c, planner__core__casetest__physicalplantest__physical_plan.t.d, planner__core__casetest__physicalplantest__physical_plan.t.e, planner__core__casetest__physicalplantest__physical_plan.t.f, planner__core__casetest__physicalplantest__physical_plan.t.g, planner__core__casetest__physicalplantest__physical_plan.t.h +└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(planner__core__casetest__physicalplantest__physical_plan.t.a, Column#19) + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─TableFullScan 10000.00 cop[tikv] table:outTable keep order:false, stats:pseudo + └─StreamAgg(Probe) 10000.00 root funcs:count(Column#21)->Column#19 + └─TableReader 10000.00 root data:StreamAgg + └─StreamAgg 10000.00 cop[tikv] funcs:count(1)->Column#21 + └─Selection 80000000.00 cop[tikv] eq(cast(planner__core__casetest__physicalplantest__physical_plan.t.a, double BINARY), cast(planner__core__casetest__physicalplantest__physical_plan.t.b, double BINARY)) + └─TableFullScan 100000000.00 cop[tikv] table:inn keep order:false, stats:pseudo +explain format = 'brief' select count(*) from t t1, t t2 where t1.a=t2.e -- shouldn't be rewritten; +id estRows task access object operator info +HashAgg 1.00 root funcs:count(1)->Column#19 +└─HashJoin 12500.00 root inner join, equal:[eq(planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.e)] + ├─TableReader(Build) 10000.00 root data:TableFullScan + │ └─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 +explain format = 'brief' select count(distinct 1) from t -- shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(distinct 1)->Column#10 +└─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select count(1), count(a), count(b) from t -- shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:count(Column#16)->Column#10, funcs:count(Column#17)->Column#11, funcs:count(Column#18)->Column#12 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#16, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#17, funcs:count(planner__core__casetest__physicalplantest__physical_plan.t.b)->Column#18 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select a, count(*) from t group by a -- shouldn't be rewritten; +id estRows task access object operator info +Projection 8000.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, Column#10 +└─HashAgg 8000.00 root group by:planner__core__casetest__physicalplantest__physical_plan.t.a, funcs:count(1)->Column#10, funcs:firstrow(planner__core__casetest__physicalplantest__physical_plan.t.a)->planner__core__casetest__physicalplantest__physical_plan.t.a + └─TableReader 10000.00 root data:TableFullScan + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +explain format = 'brief' select sum(a) from t -- sum shouldn't be rewritten; +id estRows task access object operator info +StreamAgg 1.00 root funcs:sum(Column#12)->Column#10 +└─TableReader 1.00 root data:StreamAgg + └─StreamAgg 1.00 cop[tikv] funcs:sum(planner__core__casetest__physicalplantest__physical_plan.t.a)->Column#12 + └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +set tidb_cost_model_version=DEFAULT; +drop table if exists t, tcommon, thash; +set tidb_cost_model_version=1; +create table t (a int, b int, c int, index idx(a, c), index idx2(b, c)); +create table tcommon (a int, b int, c int, primary key(a, c), index idx2(b, c)); +create table thash(a int, b int, c int, index idx_ac(a, c), index idx_bc(b, c)) PARTITION BY HASH (`a`) PARTITIONS 4; +explain format = 'brief' select * from t where a = 1 or b = 1 order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:true, stats:pseudo + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where a = 1 or b in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 39.97 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where a in (1, 2, 3) or b = 1 order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 39.97 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where a in (1, 2, 3) or b in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 59.91 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b = 1) order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.a, planner__core__casetest__physicalplantest__physical_plan.t.b, planner__core__casetest__physicalplantest__physical_plan.t.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 0.02 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 0.02 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:true, stats:pseudo + ├─Limit(Build) 1.98 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.98 cop[tikv] table:t, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 and c = 2) or b in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 2.00 root type: union + ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 30.00 cop[tikv] table:t, index:idx2(b, c) range:[1,1], [2,2], [3,3], keep order:false, stats:pseudo + └─TopN(Probe) 2.00 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 30.10 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b in (1, 2, 3) and c = 3) order by c limit 2; +id estRows task access object operator info +TopN 0.40 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 0.40 root type: union + ├─IndexRangeScan(Build) 0.10 cop[tikv] table:t, index:idx(a, c) range:[1 2,1 2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 0.30 cop[tikv] table:t, index:idx2(b, c) range:[1 3,1 3], [2 3,2 3], [3 3,3 3], keep order:false, stats:pseudo + └─TopN(Probe) 0.40 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─TableRowIDScan 0.40 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 or b = 2) and c = 3 order by c limit 2; +id estRows task access object operator info +TopN 0.02 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 0.02 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo + └─TopN(Probe) 0.02 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─Selection 0.02 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.c, 3) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by c limit 2; +id estRows task access object operator info +TopN 0.06 root planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 +└─IndexMerge 0.06 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo + └─TopN(Probe) 0.06 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.c, offset:0, count:2 + └─Selection 0.06 cop[tikv] in(planner__core__casetest__physicalplantest__physical_plan.t.c, 1, 2, 3) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by b limit 2; +id estRows task access object operator info +TopN 0.06 root planner__core__casetest__physicalplantest__physical_plan.t.b, offset:0, count:2 +└─IndexMerge 0.06 root type: union + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx(a, c) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx2(b, c) range:[2,2], keep order:false, stats:pseudo + └─TopN(Probe) 0.06 cop[tikv] planner__core__casetest__physicalplantest__physical_plan.t.b, offset:0, count:2 + └─Selection 0.06 cop[tikv] in(planner__core__casetest__physicalplantest__physical_plan.t.c, 1, 2, 3) + └─TableRowIDScan 19.99 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from tcommon where a = 1 or b = 1 order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.tcommon.a, planner__core__casetest__physicalplantest__physical_plan.tcommon.b, planner__core__casetest__physicalplantest__physical_plan.tcommon.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:tcommon, index:PRIMARY(a, c) range:[1,1], keep order:true, stats:pseudo + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:tcommon, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:tcommon keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from tcommon where (a = 1 and c = 2) or (b = 1) order by c limit 2; +id estRows task access object operator info +Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.tcommon.a, planner__core__casetest__physicalplantest__physical_plan.tcommon.b, planner__core__casetest__physicalplantest__physical_plan.tcommon.c +└─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 0.18 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 0.18 cop[tikv] table:tcommon, index:PRIMARY(a, c) range:[1 2,1 2], keep order:true, stats:pseudo + ├─Limit(Build) 1.82 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.82 cop[tikv] table:tcommon, index:idx2(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:tcommon keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select * from thash use index(idx_ac, idx_bc) where a = 1 or b = 1 order by c limit 2; +id estRows task access object operator info +TopN 2.00 root planner__core__casetest__physicalplantest__physical_plan.thash.c, offset:0, count:2 +└─PartitionUnion 8.00 root + ├─Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.thash.a, planner__core__casetest__physicalplantest__physical_plan.thash.b, planner__core__casetest__physicalplantest__physical_plan.thash.c + │ └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p0, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p0, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo + │ └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p0 keep order:false, stats:pseudo + ├─Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.thash.a, planner__core__casetest__physicalplantest__physical_plan.thash.b, planner__core__casetest__physicalplantest__physical_plan.thash.c + │ └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p1, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p1, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo + │ └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p1 keep order:false, stats:pseudo + ├─Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.thash.a, planner__core__casetest__physicalplantest__physical_plan.thash.b, planner__core__casetest__physicalplantest__physical_plan.thash.c + │ └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p2, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + │ ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p2, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo + │ └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p2 keep order:false, stats:pseudo + └─Projection 2.00 root planner__core__casetest__physicalplantest__physical_plan.thash.a, planner__core__casetest__physicalplantest__physical_plan.thash.b, planner__core__casetest__physicalplantest__physical_plan.thash.c + └─IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p3, index:idx_ac(a, c) range:[1,1], keep order:true, stats:pseudo + ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 + │ └─IndexRangeScan 1.00 cop[tikv] table:thash, partition:p3, index:idx_bc(b, c) range:[1,1], keep order:true, stats:pseudo + └─TableRowIDScan(Probe) 2.00 cop[tikv] table:thash, partition:p3 keep order:false, stats:pseudo +show warnings; +Level Code Message +Warning 1105 disable dynamic pruning due to thash has no global stats +set tidb_cost_model_version=DEFAULT; +drop table if exists t, t2; +set tidb_cost_model_version=1; +CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ; +insert into t2 values(1,2,1),(2,1,1),(3,3,1); +create table t(a int, j json, index kj((cast(j as signed array)))); +insert into t values(1, '[1,2,3]'); +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; -- test sink limit to table side of union index merge case, because of table side selection; +id estRows task access object operator info +Limit 2.00 root offset:0, count:2 +└─IndexMerge 0.00 root type: union + ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 2.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo + └─Limit(Probe) 0.00 cop[tikv] offset:0, count:2 + └─Selection 0.00 cop[tikv] or(eq(planner__core__casetest__physicalplantest__physical_plan.t2.a, 1), and(eq(planner__core__casetest__physicalplantest__physical_plan.t2.b, 1), eq(planner__core__casetest__physicalplantest__physical_plan.t2.c, 1))) + └─TableRowIDScan 3.99 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; -- test sink limit to table side of intersection index merge case, because of table side selection; +id estRows task access object operator info +Limit 0.00 root offset:0, count:2 +└─IndexMerge 0.01 root type: intersection + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo + └─Limit(Probe) 0.01 cop[tikv] offset:0, count:2 + └─Selection 0.01 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t2.c, 1) + └─TableRowIDScan 0.01 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; +a b c +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; -- test sink limit to index side of union index merge case, because of table side is pure table scan; +id estRows task access object operator info +IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) +├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 +│ └─IndexRangeScan 1.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo +├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 +│ └─IndexRangeScan 1.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 2.00 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; -- test sink limit to table side of intersection index merge case, because of intersection case special; +id estRows task access object operator info +IndexMerge 0.01 root type: intersection, limit embedded(offset:0, count:2) +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:b(b) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.01 cop[tikv] table:t2 keep order:false, stats:pseudo +show warnings; +Level Code Message +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; +a b c +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; -- index merge union case, sink limit into index side and embed another one inside index merge reader; +id estRows task access object operator info +IndexMerge 0.00 root type: union, limit embedded(offset:0, count:1) +├─Limit(Build) 0.00 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; -- index merge intersection case, embedding limit into index merge reader; +id estRows task access object operator info +IndexMerge 0.00 root type: intersection, limit embedded(offset:0, count:1) +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo +├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo +└─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─Selection 1.00 root json_overlaps(planner__core__casetest__physicalplantest__physical_plan.t.j, cast("[1, 2, 3]", json BINARY)) + └─IndexMerge 0.00 root type: union + ├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now. +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; -- index merge union case, sink limit to table side, because selection exists on table side; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─IndexMerge 0.00 root type: union + ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + └─Limit(Probe) 0.00 cop[tikv] offset:0, count:1 + └─Selection 0.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableRowIDScan 1.25 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; -- index merge intersection case, sink limit to table side because selection exists on table side; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─IndexMerge 0.00 root type: intersection + ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 1.25 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + └─Limit(Probe) 0.00 cop[tikv] offset:0, count:1 + └─Selection 0.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableRowIDScan 1.25 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +id estRows task access object operator info +Limit 1.00 root offset:0, count:1 +└─Selection 1.00 root json_overlaps(planner__core__casetest__physicalplantest__physical_plan.t.j, cast("[1, 2, 3]", json BINARY)) + └─IndexMerge 1.00 root type: union + ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[2,2], keep order:false, stats:pseudo + ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[3,3], keep order:false, stats:pseudo + └─Selection(Probe) 1.00 cop[tikv] eq(planner__core__casetest__physicalplantest__physical_plan.t.a, 1) + └─TableRowIDScan 1.00 cop[tikv] table:t keep order:false, stats:pseudo +show warnings; +Level Code Message +Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now. +set tidb_cost_model_version=DEFAULT; diff --git a/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test b/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test new file mode 100644 index 0000000000000..2e21fa27e0656 --- /dev/null +++ b/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test @@ -0,0 +1,971 @@ +# TestINMJHint +drop table if exists t1, t2; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +explain format = 'brief' select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; + +# TestEliminateMaxOneRow +drop table if exists t1, t2, t3; +create table t1(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, UNIQUE KEY idx_a (a)); +create table t2(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL); +create table t3(a int(11) DEFAULT NULL, b int(11) DEFAULT NULL, c int(11) DEFAULT NULL, UNIQUE KEY idx_abc (a, b, c)); +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +select a from t2 where t2.a < (select t1.a from t1 where t1.a = t2.a); +explain format = 'brief' select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +select a from t2 where t2.a < (select t1.a from t1 where t1.b = t2.b and t1.a is null); +explain format = 'brief' select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); +select a from t2 where t2.a < (select t3.a from t3 where t3.a = t2.a); + +# TestIndexJoinUnionScan +set tidb_cost_model_version=2; +drop table if exists t, tt; +create table t (a int primary key, b int, index idx(a)); +create table tt (a int primary key) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200)); +set @@tidb_partition_prune_mode='static'; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a; +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.b; +rollback; +begin; +insert into t values(1, 1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ t1.a , t2.b from t t1, t t2 where t1.a = t2.b; +rollback; +begin; +insert into tt values(1); +explain format = 'brief' select /*+ TIDB_INLJ(t2) */ * from tt t1, tt t2 where t1.a = t2.a; +rollback; +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; + +# TestMergeJoinUnionScan +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), primary key (c_int)); +create table t2 (c_int int, c_str varchar(40), primary key (c_int)); +insert into t1 (`c_int`, `c_str`) values (11, 'keen williamson'), (10, 'gracious hermann'); +insert into t2 (`c_int`, `c_str`) values (10, 'gracious hermann'); +begin; +insert into t2 values (11, 'amazing merkle'); +insert into t2 values (12, 'amazing merkle'); +explain format = 'brief' select /*+ MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int and t1.c_int = t2.c_int order by t1.c_int, t2.c_str; +rollback; + +# TestLimitToCopHint +set tidb_cost_model_version=2; +drop table if exists tn; +create table tn(a int, b int, c int, d int, key (a, b, c, d)); +set tidb_opt_limit_push_down_threshold=0; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +show warnings; +explain format = 'brief' select * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1; +show warnings; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a div 2 order by a limit 1; +show warnings; +explain format = 'brief' select /*+ LIMIT_TO_COP() */ a from tn where a > 10 limit 1; +show warnings; +set tidb_cost_model_version=DEFAULT; +set tidb_opt_limit_push_down_threshold=DEFAULT; + +# TestCTEMergeHint +drop table if exists tc, te, t1, t2, t3, t4; +drop view if exists v; +create table tc(a int); +create table te(c int); +create table t1(a int); +create table t2(b int); +create table t3(c int); +create table t4(d int); +insert into tc values (1), (5), (10), (15), (20), (30), (50); +insert into te values (1), (5), (10), (25), (40), (60), (100); +insert into t1 values (1), (5), (10), (25), (40), (60), (100); +insert into t2 values (1), (5), (10), (25), (40), (60), (100); +insert into t3 values (1), (5), (10), (25), (40), (60), (100); +insert into t4 values (1), (5), (10), (25), (40), (60), (100); +analyze table tc; +analyze table te; +analyze table t1; +analyze table t2; +analyze table t3; +analyze table t4; +create definer='root'@'localhost' view v as select * from tc; +explain format = 'brief' with cte as (select /*+ MERGE() */ * from tc where tc.a < 60) select * from cte where cte.a <18; +show warnings; +explain format = 'brief' with cte as (select * from tc where tc.a < 60) select * from cte c1, cte c2 where c1.a <18; +show warnings; +explain format = 'brief' with cte as (select /*+ MERGE() */ * from v) select * from cte; +show warnings; +explain format = 'brief' WITH cte1 AS (SELECT /*+ MERGE() */ a FROM tc), cte2 AS (SELECT /*+ MERGE()*/ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +show warnings; +explain format = 'brief' WITH cte1 AS (SELECT a FROM tc), cte2 AS (SELECT /*+ MERGE() */ c FROM te) SELECT * FROM cte1 JOIN cte2 WHERE cte1.a = cte2.c; +show warnings; +explain format = 'brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; +show warnings; +explain format = 'brief' WITH cte1 AS (SELECT * FROM t1) SELECT /*+ MERGE() */ * FROM cte1 join t2 on cte1.a = t2.b; +show warnings; +explain format = 'brief' with cte1 as (with cte3 as (select /*+ MERGE() */ * from t1),cte4 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3,cte4) ,cte2 as (select /*+ MERGE() */ * from t3) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select * from tc), cte2 as (with cte3 as (select /*+ MERGE() */ * from te) ,cte4 as (select * from tc) select * from cte3,cte4) select * from cte2; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (select /*+ MERGE() */ * from te) ,cte3 as (select /*+ MERGE() */ * from tc) select /*+ MERGE() */ * from cte2,cte3) select * from cte1; +show warnings; +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select /*+ MERGE() */ * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select * from t3) select * from cte5,cte6) ,cte4 as (select /*+ MERGE() */ * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte1 as (select * from t1), cte2 as (with cte3 as (with cte5 as (select * from t2),cte6 as (select /*+ MERGE() */ * from t3) select * from cte5,cte6) ,cte4 as (select * from t4) select * from cte3,cte4) select * from cte1,cte2; +show warnings; +explain format = 'brief' with cte2 as (with cte4 as (select * from tc) select * from te, cte4) select * from cte2; +show warnings; +explain format = 'brief' with cte2 as (with cte4 as (select /*+ merge() */ * from tc) select * from te, cte4) select * from cte2; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select /*+ MERGE() */ * from t1) ttt) select * from cte1; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select /*+ MERGE() */ * from t3) ttw; +show warnings; +explain format = 'brief' with cte1 as (with cte2 as (with cte3 as (select /*+ MERGE() */ * from t2) select /*+ MERGE() */ * from cte3) select * from cte2,(select * from t1) ttt) select * from cte1,(select * from t3) ttw; +show warnings; + +# TestForceInlineCTE +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11)); +insert into t values (1), (5), (10), (15), (20), (30), (50); +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inline; +show warnings; +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline; +show warnings; +explain format='brief' with cte as (select * from t) select * from cte cte1, cte cte2; -- inline CTEs is used by multi consumers; +show warnings; +explain format='brief' with cte1 as (select * from t), cte2 as (select a from cte1 group by a) select * from cte1, cte2; -- multi inline CTEs; +show warnings; +explain format='brief' with recursive cte1(c1) as (select 1 union select c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +show warnings; +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +show warnings; +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +show warnings; +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +show warnings; +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select * from t) select * from cte; -- inlined by single consumer; +show warnings; +explain format='brief' with cte as (select /*+ MERGE() */ * from t) select * from cte; -- inline, merge hint override session variable; +show warnings; +explain format='brief' with recursive cte1(c1) as (select 1 union select /*+ MERGE() */ c1 + 1 c1 from cte1 where c1 < 100) select * from cte1; -- Recursive CTE can not be inlined; +show warnings; +explain format='brief' with cte1 as (with cte2 as (select * from t) select * from cte2) select * from cte1; -- non-recursive 'cte2' definition inside another non-recursive 'cte1'; +show warnings; +explain format='brief' with recursive cte2(c1) as (with cte1 as (select * from t) select a c1 from cte1 union select c1+1 c1 from cte2 where c1 < 100) select * from cte2; -- non-recursive 'cte1' inside recursive 'cte2'; +show warnings; +explain format='brief' with cte1 as (with recursive cte2(c1) as (select 1 union select c1 + 1 c1 from cte2 where c1 < 100) select * from cte2) select * from cte1; -- recursive 'cte2' inside non-recursive 'cte1'; +show warnings; + +set tidb_cost_model_version=DEFAULT; +set tidb_opt_force_inline_cte=DEFAULT; + +# TestSingleConsumerCTE +drop table if exists t, t1, t2; +CREATE TABLE `t` (`a` int(11)); +create table t1 (c1 int primary key, c2 int, index c2 (c2)); +create table t2 (c1 int unique, c2 int); +insert into t values (1), (5), (10), (15), (20), (30), (50); +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 1) select * from cte1; -- non-recursive limit, inline cte1; +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 100 offset 100) select * from cte1; -- non-recursive limit, inline cte1; +explain format='brief' with recursive cte1(c1) as (select c1 from t1 union select c1 from t2 limit 0 offset 0) select * from cte1; -- non-recursive limit, inline cte1; +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union (with cte2 as (select 3) select * from cte2 union all select * from cte2) -- inline cte1, not inline cte2; +explain format='brief' with base1 as (WITH RECURSIVE cte(a) AS (with tmp as (select 1 as a) SELECT a from tmp UNION SELECT a+1 FROM cte) SELECT * FROM cte) select * from base1; -- issue #43318; +explain format='brief' with cte as (select 1) select * from cte; -- inline cte; +explain format='brief' with cte1 as (select 1), cte2 as (select 2) select * from cte1 union select * from cte2; -- inline cte1, cte2; +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- cannot be inlined; +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte; -- inline nested cte; +explain format='brief' with cte as (with cte as (select 1) select * from cte) select * from cte a, cte b; -- inline inner cte, cannot be inlined outer cte; +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte1, cte2; -- inline cte2, cte3, cannot be inlined cte1; +explain format='brief' with cte1 as (select 1), cte2 as (with cte3 as (select * from cte1) select * from cte3) select * from cte2; -- inline cte1, cte2, cte3; +explain format='brief' with cte1 as (select 1), cte2 as (select * from cte1) select * from cte2 a, cte2 b; -- inline cte1, cannot be inlined cte2; +explain format='brief' with recursive cte(a) as (select 1 union select a from cte) select * from cte; -- recursive cte cannot be inlined; +explain format='brief' with x as (select * from (select a from t for update) s) select * from x where a = 1; +set tidb_opt_force_inline_cte=1; -- enable force inline CTE; +explain format='brief' with cte as (select 1) select * from cte union select * from cte; -- force inline cte while multi-consumer; +set tidb_opt_force_inline_cte=0; -- disable force inline CTE; +explain format='brief' with cte as (select 1) select /*+ MERGE() */ * from cte union select * from cte; -- firstly inline cte, secondly cannot be inlined; +explain format='brief' with a as (select 8 as id from dual),maxa as (select max(id) as max_id from a),b as (with recursive temp as (select 1 as lvl from dual union all select lvl+1 from temp, maxa where lvl < max_id)select * from temp) select * from b; -- issue #47711, maxa cannot be inlined because it contains agg and in the recursive part of cte temp; +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select 1 as res from t1 union all select res+1 from tmp,b where res+1 < bb) select * from tmp) select * from c; -- inline a, cannot be inline b because b indirectly contains agg and in the recursive part of cte tmp; +explain format='brief' with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c; + +# TestPushdownDistinctEnableAggPushDownDisable +drop table if exists t; +create table t(a int, b int, c int, index(c)); +insert into t values (1, 1, 1), (1, 1, 3), (1, 2, 3), (2, 1, 3), (1, 2, NULL); +drop table if exists pt; +CREATE TABLE pt (a int, b int) PARTITION BY RANGE (a) ( + PARTITION p0 VALUES LESS THAN (2), + PARTITION p1 VALUES LESS THAN (100) + ); +drop table if exists tc; +CREATE TABLE `tc`(`timestamp` timestamp NULL DEFAULT NULL, KEY `idx_timestamp` (`timestamp`)) PARTITION BY RANGE ( UNIX_TIMESTAMP(`timestamp`) ) (PARTITION `p2020072312` VALUES LESS THAN (1595480400),PARTITION `p2020072313` VALUES LESS THAN (1595484000)); +drop table if exists ta; +create table ta(a int); +insert into ta values(1), (1); +drop table if exists tb; +create table tb(a int); +insert into tb values(1), (1); +set session sql_mode=''; +set session tidb_hashagg_partial_concurrency=1; +set session tidb_hashagg_final_concurrency=1; +set @@tidb_partition_prune_mode='static'; +set @@session.tidb_opt_distinct_agg_push_down = 1; +set session tidb_opt_agg_push_down = 0; +set tidb_cost_model_version=2; +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +select /*+ HASH_AGG(), AGG_TO_COP() */ sum(distinct b) from pt; +explain format = 'brief' select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +select /*+ HASH_AGG(), AGG_TO_COP() */ count(distinct a) from (select * from ta union all select * from tb) t; +explain format = 'brief' select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; +select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tc ; + +set session sql_mode=DEFAULT; +set session tidb_hashagg_partial_concurrency=DEFAULT; +set session tidb_hashagg_final_concurrency=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; +set @@session.tidb_opt_distinct_agg_push_down = DEFAULT; +set session tidb_opt_agg_push_down = DEFAULT; + +# TestNominalSort +drop table if exists t; +create table t (a int, b int, index idx_a(a), index idx_b(b)); +insert into t values(1, 1); +insert into t values(1, 2); +insert into t values(2, 4); +insert into t values(3, 5); +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a+1; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by t1.a-1; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by -t1.a+3; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1-t1.a+3; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 1+t1.a+3; +explain format = 'brief' select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; +select /*+ TIDB_SMJ(t1, t2) */ t1.a from t t1, t t2 where t1.a = t2.b order by 3*t1.a; + +# TestNthPlanHintWithExplain +drop table if exists test.tt; +create table test.tt (a int,b int, index(a), index(b)); +insert into test.tt values (1, 1), (2, 2), (3, 4); +set @@tidb_partition_prune_mode='static'; +explain format = 'brief' select /*+nth_plan(1)*/ * from test.tt where a=1 and b=1; +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; +explain format = 'brief' select /*+nth_plan(3)*/ * from test.tt where a=1 and b=1; +explain format = 'brief' select /*+nth_plan(2)*/ * from test.tt where a=1 and b=1; + +## Currently, its output is the same as the second test case in the testdata, which is `/*+nth_plan(2)*/`. If this doesn't +## hold in the future, you may need to modify this. +explain format = 'brief' select * from test.tt where a=1 and b=1; + +set @@tidb_partition_prune_mode=DEFAULT; + +# TestEnumIndex +drop table if exists t; +create table t(e enum('c','b','a',''), index idx(e)); +insert ignore into t values(0),(1),(2),(3),(4); +explain format='brief' select e from t where e = 'b'; +--sorted_result +select e from t where e = 'b'; +explain format='brief' select e from t where e != 'b'; +--sorted_result +select e from t where e != 'b'; +explain format='brief' select e from t where e > 'b'; +--sorted_result +select e from t where e > 'b'; +explain format='brief' select e from t where e >= 'b'; +--sorted_result +select e from t where e >= 'b'; +explain format='brief' select e from t where e < 'b'; +--sorted_result +select e from t where e < 'b'; +explain format='brief' select e from t where e <= 'b'; +--sorted_result +select e from t where e <= 'b'; +explain format='brief' select e from t where e = 2; +--sorted_result +select e from t where e = 2; +explain format='brief' select e from t where e != 2; +--sorted_result +select e from t where e != 2; +explain format='brief' select e from t where e > 2; +--sorted_result +select e from t where e > 2; +explain format='brief' select e from t where e >= 2; +--sorted_result +select e from t where e >= 2; +explain format='brief' select e from t where e < 2; +--sorted_result +select e from t where e < 2; +explain format='brief' select e from t where e <= 2; +--sorted_result +select e from t where e <= 2; +explain format='brief' select e from t where e > ''; +--sorted_result +select e from t where e > ''; +explain format='brief' select e from t where e > 'd'; +--sorted_result +select e from t where e > 'd'; +explain format='brief' select e from t where e > -1; +--sorted_result +select e from t where e > -1; +explain format='brief' select e from t where e > 5; +--sorted_result +select e from t where e > 5; +explain format='brief' select e from t where e = ''; +--sorted_result +select e from t where e = ''; +explain format='brief' select e from t where e != ''; +--sorted_result +select e from t where e != ''; + +# TestIssue27233 +drop table if exists PK_S_MULTI_31; +CREATE TABLE `PK_S_MULTI_31` ( + `COL1` tinyint(45) NOT NULL, + `COL2` tinyint(45) NOT NULL, + PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into PK_S_MULTI_31 values(122,100),(124,-22),(124,34),(127,103); +explain format='brief' SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; +--sorted_result +SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2; + +# TestSelectionPartialPushDown +drop table if exists t1, t2; +create table t1(a int, b int as (a+1) virtual); +create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a)); +-- echo ## Make sure row_count(tikv_selection) == row_count(table_reader) and row_count(table_reader) > row_count(tidb_selection) +explain format='brief' select * from t1 where a > 1 and b > 1; +-- echo Make sure row_count(tikv_selection) == row_count(index_lookup) and row_count(index_lookup) > row_count(tidb_selection) +explain format='brief' select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1; + +# TestIssue28316 +drop table if exists t; +create table t(a int); +explain format='brief' select * from t where t.a < 3 and t.a < 3; + +# TestSkewDistinctAgg +set tidb_cost_model_version=2; +drop table if exists t; +CREATE TABLE `t` (`a` int(11), `b` int(11), `c` int(11), `d` date); +insert into t (a,b,c,d) value(1,4,5,'2019-06-01'); +insert into t (a,b,c,d) value(2,null,1,'2019-07-01'); +insert into t (a,b,c,d) value(3,4,5,'2019-08-01'); +insert into t (a,b,c,d) value(3,6,2,'2019-09-01'); +insert into t (a,b,c,d) value(10,4,null,'2020-06-01'); +insert into t (a,b,c,d) value(20,null,1,'2020-07-01'); +insert into t (a,b,c,d) value(30,4,5,'2020-08-01'); +insert into t (a,b,c,d) value(30,6,5,'2020-09-01'); +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +set @@tidb_opt_skew_distinct_agg=1; +select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y') order by df; +select count(distinct b), sum(c) from t group by a order by 1,2; +select count(distinct b) from t group by date_format(d,'%Y') order by 1; +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y') order by 1,2,3; +select count(a), count(distinct b), max(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +select avg(distinct b), count(a), sum(b) from t group by date_format(d,'%Y'),c order by 1,2,3; +explain format='brief' select date_format(d,'%Y') as df, sum(a), count(b), count(distinct c) from t group by date_format(d,'%Y'); +explain format='brief' select d, a, count(*), count(b), count(distinct c) from t group by d, a; +explain format='brief' select d, sum(a), count(b), avg(distinct c) from t group by d; + +set tidb_cost_model_version=DEFAULT; +set @@tidb_opt_skew_distinct_agg=DEFAULT; + +# TestHJBuildAndProbeHint +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int primary key, b int not null); +create table t2(a int primary key, b int not null); +create table t3(a int primary key, b int not null); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2), hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2), hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 right join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 straight_join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 cross join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t1) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t1) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_build(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +select /*+ hash_join_probe(t2@sel_2) */ * from t1 where t1.a not in (select t2.a from t2 where t1.b = t2.b); +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_build(t1) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_probe(t1) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_build(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_build(t1) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_probe(t1) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_build(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +select /*+ hash_join_probe(t2@sel_2) */ sum(t1.a not in (select a from t2)) from t1; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(tt) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +select /*+ hash_join_probe(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +select /*+ hash_join_build(tt) */ tt.a, t2.a from t1 as tt join t2 on tt.a=t2.a and tt.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) leading(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) leading(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_build(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +select /*+ hash_join_probe(t1) straight_join() */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b join t3 on t2.a = t3.a; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) hash_join(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) hash_join(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) hash_join(t2, t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) INL_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) INL_HASH_JOIN(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t2) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_build(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +select /*+ hash_join_probe(t1) merge_join(t1, t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +show warnings; +explain format = 'brief' SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_probe(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t1) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +SELECT /*+ hash_join_build(t2@sel_2) */ * FROM t1 WHERE EXISTS (SELECT /*+ SEMI_JOIN_REWRITE() */ 1 FROM t2 WHERE t2.a = t1.a); +show warnings; +explain format = 'brief' SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(TRUE) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_build(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_probe(t1) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_build(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; +explain format = 'brief' SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +SELECT /*+ USE_TOJA(false) hash_join_probe(t2@sel_2) */ t1.a, t1.b FROM t1 WHERE t1.a in (SELECT t2.a FROM t2); +show warnings; + +set tidb_cost_model_version=DEFAULT; + +# TestHJBuildAndProbeHint4StaticPartitionTable +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3; +create table t1(a int, b int) partition by hash(a) partitions 4; +create table t2(a int, b int) partition by hash(a) partitions 5; +create table t3(a int, b int) partition by hash(b) partitions 3; +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +set @@tidb_partition_prune_mode="static"; +explain format = 'brief' select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_build(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_probe(t2) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_build(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +explain format = 'brief' select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; +--sorted_result +select /*+ hash_join_probe(t1) */ t1.a, t2.a from t1 join t2 on t1.a=t2.a and t1.b=t2.b; + +set tidb_cost_model_version=DEFAULT; +set @@tidb_partition_prune_mode=DEFAULT; + +# TestNoDecorrelateHint +set tidb_cost_model_version=2; +drop table if exists t1, t2, t3, ta, tb, tc, td; +create table t1(a int, b int); +create table t2(a int primary key, b int); +create table t3(a int, b int); +insert into t1 values(1,1),(2,2); +insert into t2 values(1,1),(2,1); +insert into t3 values(1,1),(2,1); +create table ta(id int, code int, name varchar(20), index idx_ta_id(id),index idx_ta_name(name), index idx_ta_code(code)); +create table tb(id int, code int, name varchar(20), index idx_tb_id(id),index idx_tb_name(name)); +create table tc(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +create table td(id int, code int, name varchar(20), index idx_tc_id(id),index idx_tc_name(name)); +explain format = 'brief' select /*+ no_decorrelate() */ * from t1; +--sorted_result +select /*+ no_decorrelate() */ * from t1; +show warnings; +explain format = 'brief' select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +--sorted_result +select * from t1, (select /*+ no_decorrelate() */ * from t2) n; +show warnings; +explain format = 'brief' select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +--sorted_result +select a+1, b-1 from (select /*+ no_decorrelate() */ * from t1) n; +show warnings; +explain format = 'brief' select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +--sorted_result +select exists (select /*+ semi_join_rewrite(), no_decorrelate() */ * from t1 where t1.a=t3.a) from t3; +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a in (select t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a in (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a = any (select t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +--sorted_result +select t1.a from t1 where t1.a = any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b); +show warnings; +explain format = 'brief' select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a != any (select t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a != any (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a > all (select t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, t1.a > all (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, (select t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +--sorted_result +select t1.a, (select /*+ no_decorrelate() */ t2.b from t2 where t2.a = t1.b) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.b not in (select t3.b from t3) from t1; +--sorted_result +select t1.a, t1.b not in (select t3.b from t3) from t1; +show warnings; +explain format = 'brief' select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +--sorted_result +select t1.a, t1.b not in (select /*+ no_decorrelate() */ t3.b from t3) from t1; +show warnings; +explain format = 'brief' select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +--sorted_result +select exists (select t3.b from t3 where t3.a = t1.b limit 2) from t1; +show warnings; +explain format = 'brief' select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +--sorted_result +select exists (select /*+ no_decorrelate() */ t3.b from t3 where t3.a = t1.b limit 2) from t1; +show warnings; +explain format = 'brief' select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +--sorted_result +select t1.a, (select sum(t1.a) from t2 where t2.a = 10) from t1; +show warnings; +explain format = 'brief' select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +--sorted_result +select t1.a, (select /*+ no_decorrelate() */ sum(t1.a) from t2 where t2.a = 10) from t1; +show warnings; +explain format = 'brief' select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +--sorted_result +select (select count(t3.a) from t3 where t3.b = t1.b) from t1; +show warnings; +explain format = 'brief' select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +--sorted_result +select (select /*+ no_decorrelate() */ count(t3.a) from t3 where t3.b = t1.b) from t1; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +--sorted_result +SELECT ta.NAME,(SELECT /*+ no_decorrelate() */ sum(tb.CODE) FROM tb WHERE ta.id = tb.id and exists (select /*+ no_decorrelate() */ 1 from tc where tb.name=tc.name and tc.`code` like '999%')) tb_sum_code FROM ta WHERE ta.NAME LIKE 'chad999%'; +show warnings; +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +--sorted_result +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select max(tb.code) from tb where ta.id=tb.id ) > 900; +show warnings; +explain format = 'brief' SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +--sorted_result +SELECT ta.id, 'split' as flag FROM ta WHERE ta.NAME ='chad999' and (select /*+ no_decorrelate() */ max(tb.code) from tb where ta.id=tb.id ) > 900; +show warnings; +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +--sorted_result +SELECT ta.NAME FROM ta WHERE EXISTS (select 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +show warnings; +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +--sorted_result +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ semi_join_rewrite() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +show warnings; +explain format = 'brief' SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +--sorted_result +SELECT ta.NAME FROM ta WHERE EXISTS (select /*+ no_decorrelate() */ 1 from tb where ta.code = tb.code and tb.NAME LIKE 'chad9%') AND (select /*+ no_decorrelate() */ max(id) from tc where ta.name=tc.name and tc.name like 'chad99%') > 100 and (select /*+ no_decorrelate() */ max(id) from td where ta.id=td.id and td.name like 'chad999%') > 100; +show warnings; +set tidb_cost_model_version=DEFAULT; + +# TestCountStarForTikv +drop table if exists t, t_pick_row_id; +set tidb_cost_model_version=1; +create table t (a int(11) not null, b varchar(10) not null, c date not null, d char(1) not null, e bigint not null, f datetime not null, g bool not null, h bool ); +create table t_pick_row_id (a char(20) not null); +explain format = 'brief' select count(*) from t; +explain format = 'brief' select count(1), count(3.1415), count(0), count(null) from t -- shouldn't be rewritten; +explain format = 'brief' select count(*) from t where a=1; +explain format = 'brief' select count(*) from t_pick_row_id; +explain format = 'brief' select t.b, t.c from (select count(*) as c from t) a, t where a.c=t.a -- shouldn't be rewritten; +explain format = 'brief' select * from t outTable where outTable.a > (select count(*) from t inn where inn.a = outTable.b) -- shouldn't be rewritten; +explain format = 'brief' select count(*) from t t1, t t2 where t1.a=t2.e -- shouldn't be rewritten; +explain format = 'brief' select count(distinct 1) from t -- shouldn't be rewritten; +explain format = 'brief' select count(1), count(a), count(b) from t -- shouldn't be rewritten; +explain format = 'brief' select a, count(*) from t group by a -- shouldn't be rewritten; +explain format = 'brief' select sum(a) from t -- sum shouldn't be rewritten; +set tidb_cost_model_version=DEFAULT; + +# TestIndexMergeOrderPushDown +drop table if exists t, tcommon, thash; +set tidb_cost_model_version=1; +create table t (a int, b int, c int, index idx(a, c), index idx2(b, c)); +create table tcommon (a int, b int, c int, primary key(a, c), index idx2(b, c)); +create table thash(a int, b int, c int, index idx_ac(a, c), index idx_bc(b, c)) PARTITION BY HASH (`a`) PARTITIONS 4; +explain format = 'brief' select * from t where a = 1 or b = 1 order by c limit 2; +show warnings; +explain format = 'brief' select * from t where a = 1 or b in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where a in (1, 2, 3) or b = 1 order by c limit 2; +show warnings; +explain format = 'brief' select * from t where a in (1, 2, 3) or b in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b = 1) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 and c = 2) or b in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 and c = 2) or (b in (1, 2, 3) and c = 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 or b = 2) and c = 3 order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by c limit 2; +show warnings; +explain format = 'brief' select * from t where (a = 1 or b = 2) and c in (1, 2, 3) order by b limit 2; +show warnings; +explain format = 'brief' select * from tcommon where a = 1 or b = 1 order by c limit 2; +show warnings; +explain format = 'brief' select * from tcommon where (a = 1 and c = 2) or (b = 1) order by c limit 2; +show warnings; +explain format = 'brief' select * from thash use index(idx_ac, idx_bc) where a = 1 or b = 1 order by c limit 2; +show warnings; +set tidb_cost_model_version=DEFAULT; + +# TestIndexMergeSinkLimit +drop table if exists t, t2; +set tidb_cost_model_version=1; +CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ; +insert into t2 values(1,2,1),(2,1,1),(3,3,1); +create table t(a int, j json, index kj((cast(j as signed array)))); +insert into t values(1, '[1,2,3]'); +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; -- test sink limit to table side of union index merge case, because of table side selection; +show warnings; +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; -- test sink limit to table side of intersection index merge case, because of table side selection; +show warnings; +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; +show warnings; +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; -- test sink limit to index side of union index merge case, because of table side is pure table scan; +show warnings; +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; -- test sink limit to table side of intersection index merge case, because of intersection case special; +show warnings; +select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; +show warnings; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; -- index merge union case, sink limit into index side and embed another one inside index merge reader; +show warnings; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; -- index merge intersection case, embedding limit into index merge reader; +show warnings; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +show warnings; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; -- index merge union case, sink limit to table side, because selection exists on table side; +show warnings; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; -- index merge intersection case, sink limit to table side because selection exists on table side; +show warnings; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +show warnings; +set tidb_cost_model_version=DEFAULT; + From b89710b9b6be47d474f805f770cf61688c8744f9 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 16:24:29 +0800 Subject: [PATCH 06/12] update executor/simple, 1 test case --- pkg/executor/test/simpletest/BUILD.bazel | 2 +- pkg/executor/test/simpletest/simple_test.go | 31 ------------------- .../integrationtest/r/executor/simple.result | 31 +++++++++++++++++++ tests/integrationtest/t/executor/simple.test | 28 +++++++++++++++++ 4 files changed, 60 insertions(+), 32 deletions(-) diff --git a/pkg/executor/test/simpletest/BUILD.bazel b/pkg/executor/test/simpletest/BUILD.bazel index 13e5b3f41c37b..63aecc3b4a8ee 100644 --- a/pkg/executor/test/simpletest/BUILD.bazel +++ b/pkg/executor/test/simpletest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 12, + shard_count = 11, deps = [ "//pkg/config", "//pkg/parser/auth", diff --git a/pkg/executor/test/simpletest/simple_test.go b/pkg/executor/test/simpletest/simple_test.go index 7843bed019ef2..65fdab3dcb983 100644 --- a/pkg/executor/test/simpletest/simple_test.go +++ b/pkg/executor/test/simpletest/simple_test.go @@ -37,37 +37,6 @@ import ( "go.opencensus.io/stats/view" ) -func TestStmtAutoNewTxn(t *testing.T) { - store := testkit.CreateMockStore(t) - // Some statements are like DDL, they commit the previous txn automically. - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // Fix issue https://github.com/pingcap/tidb/issues/10705 - tk.MustExec("begin") - tk.MustExec("create user 'xxx'@'%';") - tk.MustExec("grant all privileges on *.* to 'xxx'@'%';") - - tk.MustExec("create table auto_new (id int)") - tk.MustExec("begin") - tk.MustExec("insert into auto_new values (1)") - tk.MustExec("revoke all privileges on *.* from 'xxx'@'%'") - tk.MustExec("rollback") // insert statement has already committed - tk.MustQuery("select * from auto_new").Check(testkit.Rows("1")) - - // Test the behavior when autocommit is false. - tk.MustExec("set autocommit = 0") - tk.MustExec("insert into auto_new values (2)") - tk.MustExec("create user 'yyy'@'%'") - tk.MustExec("rollback") - tk.MustQuery("select * from auto_new").Check(testkit.Rows("1", "2")) - - tk.MustExec("drop user 'yyy'@'%'") - tk.MustExec("insert into auto_new values (3)") - tk.MustExec("rollback") - tk.MustQuery("select * from auto_new").Check(testkit.Rows("1", "2")) -} - func TestExtendedStatsPrivileges(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/r/executor/simple.result b/tests/integrationtest/r/executor/simple.result index 598eb0980a4a1..283aad1280361 100644 --- a/tests/integrationtest/r/executor/simple.result +++ b/tests/integrationtest/r/executor/simple.result @@ -416,3 +416,34 @@ select user_attributes from mysql.user where user = 'usr1'; user_attributes {"metadata": {"comment": "comment1"}, "resource_group": "rg1"} set global tidb_enable_resource_control = default; +## Some statements are like DDL, they commit the previous txn automically. +## Fix issue https://github.com/pingcap/tidb/issues/10705 +begin; +create user 'xxx'@'%'; +grant all privileges on *.* to 'xxx'@'%'; +create table auto_new (id int); +begin; +insert into auto_new values (1); +revoke all privileges on *.* from 'xxx'@'%'; +## insert statement has already committed +rollback; +## Test the behavior when autocommit is false. +select * from auto_new; +id +1 +set autocommit = 0; +insert into auto_new values (2); +create user 'yyy'@'%'; +rollback; +select * from auto_new; +id +1 +2 +drop user 'yyy'@'%'; +insert into auto_new values (3); +rollback; +select * from auto_new; +id +1 +2 +set autocommit = default; diff --git a/tests/integrationtest/t/executor/simple.test b/tests/integrationtest/t/executor/simple.test index b1f99510e2b9b..5075371e0d362 100644 --- a/tests/integrationtest/t/executor/simple.test +++ b/tests/integrationtest/t/executor/simple.test @@ -453,3 +453,31 @@ select user_attributes from mysql.user where user = 'usr1'; set global tidb_enable_resource_control = default; disconnect conn1; + +# TestStmtAutoNewTxn +-- echo ## Some statements are like DDL, they commit the previous txn automically. +-- echo ## Fix issue https://github.com/pingcap/tidb/issues/10705 +begin; +create user 'xxx'@'%'; +grant all privileges on *.* to 'xxx'@'%'; +create table auto_new (id int); +begin; +insert into auto_new values (1); +revoke all privileges on *.* from 'xxx'@'%'; +-- echo ## insert statement has already committed +rollback; + +-- echo ## Test the behavior when autocommit is false. +select * from auto_new; +set autocommit = 0; +insert into auto_new values (2); +create user 'yyy'@'%'; +rollback; +select * from auto_new; + +drop user 'yyy'@'%'; +insert into auto_new values (3); +rollback; +select * from auto_new; + +set autocommit = default; From 1310833b57b54d1f65c8daa5f925254a7145f08b Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 16:39:58 +0800 Subject: [PATCH 07/12] update expression/multi_valued_index.test, 2 test cases --- .../test/multivaluedindex/BUILD.bazel | 2 +- .../multi_valued_index_test.go | 205 ------- .../r/expression/multi_valued_index.result | 508 +++++++++++++++++ .../t/expression/multi_valued_index.test | 513 ++++++++++++++++++ 4 files changed, 1022 insertions(+), 206 deletions(-) create mode 100644 tests/integrationtest/r/expression/multi_valued_index.result create mode 100644 tests/integrationtest/t/expression/multi_valued_index.test diff --git a/pkg/expression/test/multivaluedindex/BUILD.bazel b/pkg/expression/test/multivaluedindex/BUILD.bazel index 1c6ed8490d878..98443c141a278 100644 --- a/pkg/expression/test/multivaluedindex/BUILD.bazel +++ b/pkg/expression/test/multivaluedindex/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "multi_valued_index_test.go", ], flaky = True, - shard_count = 6, + shard_count = 4, deps = [ "//pkg/config", "//pkg/errno", diff --git a/pkg/expression/test/multivaluedindex/multi_valued_index_test.go b/pkg/expression/test/multivaluedindex/multi_valued_index_test.go index b08a469d2b662..58101dcc25ddb 100644 --- a/pkg/expression/test/multivaluedindex/multi_valued_index_test.go +++ b/pkg/expression/test/multivaluedindex/multi_valued_index_test.go @@ -16,7 +16,6 @@ package multivaluedindex import ( "context" - "fmt" "testing" "github.com/pingcap/tidb/pkg/errno" @@ -31,210 +30,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestMultiValuedIndexDDL(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - - tk.MustExec("create table t(a json);") - tk.MustGetErrCode("select cast(a as signed array) from t", errno.ErrNotSupportedYet) - tk.MustGetErrCode("select json_extract(cast(a as signed array), '$[0]') from t", errno.ErrNotSupportedYet) - tk.MustGetErrCode("select * from t where cast(a as signed array)", errno.ErrNotSupportedYet) - tk.MustGetErrCode("select cast('[1,2,3]' as unsigned array);", errno.ErrNotSupportedYet) - - tk.MustExec("drop table t") - tk.MustGetErrCode("CREATE TABLE t(x INT, KEY k ((1 AND CAST(JSON_ARRAY(x) AS UNSIGNED ARRAY))));", errno.ErrNotSupportedYet) - tk.MustGetErrCode("CREATE TABLE t1 (f1 json, key mvi((cast(cast(f1 as unsigned array) as unsigned array))));", errno.ErrNotSupportedYet) - tk.MustGetErrCode("CREATE TABLE t1 (f1 json, primary key mvi((cast(cast(f1 as unsigned array) as unsigned array))));", errno.ErrNotSupportedYet) - tk.MustGetErrCode("CREATE TABLE t1 (f1 json, key mvi((cast(f1->>'$[*]' as unsigned array))));", errno.ErrInvalidTypeForJSON) - tk.MustGetErrCode("CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as year array))));", errno.ErrNotSupportedYet) - tk.MustGetErrCode("CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as json array))));", errno.ErrNotSupportedYet) - tk.MustGetErrCode("CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as char(10) charset gbk array))));", errno.ErrNotSupportedYet) - tk.MustGetErrCode("create table t(j json, gc json as ((concat(cast(j->'$[*]' as unsigned array),\"x\"))));", errno.ErrNotSupportedYet) - tk.MustGetErrCode("create table t(j json, gc json as (cast(j->'$[*]' as unsigned array)));", errno.ErrNotSupportedYet) - tk.MustGetErrCode(`create table t1(j json, key i1((cast(j->"$" as char array))));`, errno.ErrNotSupportedYet) - tk.MustGetErrCode(`create table t1(j json, key i1((cast(j->"$" as binary array))));`, errno.ErrNotSupportedYet) - tk.MustGetErrCode(`create table t1(j json, key i1((cast(j->"$" as float array))));`, errno.ErrNotSupportedYet) - tk.MustGetErrCode(`create table t1(j json, key i1((cast(j->"$" as decimal(4,2) array))));`, errno.ErrNotSupportedYet) - tk.MustGetErrCode("create view v as select cast('[1,2,3]' as unsigned array);", errno.ErrNotSupportedYet) - tk.MustExec("create table t(a json, index idx((cast(a as signed array))));") - tk.MustExec("drop table t;") - tk.MustExec("create table t(a json, index idx(((cast(a as signed array)))))") - tk.MustExec("drop table t;") - tk.MustExec(`create table t(j json, key i1((cast(j->"$" as double array))));`) - - tk.MustExec("drop table t") - tk.MustGetErrCode("create table t(a json, b int, index idx(b, (cast(a as signed array)), (cast(a as signed array))));", errno.ErrNotSupportedYet) - tk.MustExec("create table t(a json, b int);") - tk.MustGetErrCode("create index idx on t (b, (cast(a as signed array)), (cast(a as signed array)))", errno.ErrNotSupportedYet) - tk.MustGetErrCode("alter table t add index idx(b, (cast(a as signed array)), (cast(a as signed array)))", errno.ErrNotSupportedYet) - tk.MustExec("create index idx1 on t (b, (cast(a as signed array)))") - tk.MustExec("alter table t add index idx2(b, (cast(a as signed array)))") - - tk.MustExec("drop table t") - tk.MustExec("create table t(a json, b int, index idx3(b, (cast(a as signed array))));") - tk.MustExec("drop table t") - tk.MustExec("set names gbk") - tk.MustExec("create table t(a json, b int, index idx3(b, (cast(a as char(10) array))));") - - tk.MustExec("CREATE TABLE users (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, doc JSON);") - tk.MustExecToErr("CREATE TABLE t (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, doc JSON, FOREIGN KEY fk_user_id ((cast(doc->'$[*]' as signed array))) REFERENCES users(id));") -} - -func TestMultiValuedIndexDML(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("USE test;") - - mode := []string{`''`, `default`} - - for _, m := range mode { - tk.MustExec(fmt.Sprintf("set @@sql_mode=%s", m)) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as unsigned array))));`) - tk.MustExec(`insert into t values ('[1,2,3]');`) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrDataOutOfRangeFunctionalIndex) - tk.MustGetErrCode(`insert into t values ('["1"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["a"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as signed array))));`) - tk.MustExec(`insert into t values ('[1,2,3]');`) - tk.MustExec(`insert into t values ('[-1]');`) - tk.MustGetErrCode(`insert into t values ('["1"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["a"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as char(1) array))));`) - tk.MustGetErrCode(`insert into t values ('[1,2,3]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values ('["1"]');`) - tk.MustExec(`insert into t values ('["a"]');`) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrFunctionalIndexDataIsTooLong) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as char(2) array))));`) - tk.MustGetErrCode(`insert into t values ('[1,2,3]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values ('["1"]');`) - tk.MustExec(`insert into t values ('["a"]');`) - tk.MustExec(`insert into t values ('["汉字"]');`) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as binary(1) array))));`) - tk.MustGetErrCode(`insert into t values ('[1,2,3]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values ('["1"]');`) - tk.MustExec(`insert into t values ('["a"]');`) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrFunctionalIndexDataIsTooLong) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as binary(2) array))));`) - tk.MustGetErrCode(`insert into t values ('[1,2,3]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values ('["1"]');`) - tk.MustExec(`insert into t values ('["a"]');`) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrFunctionalIndexDataIsTooLong) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as date array))));`) - tk.MustGetErrCode(`insert into t values ('[1,2,3]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["1"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["a"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values (json_array(cast("2022-02-02" as date)));`) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as time array))));`) - tk.MustGetErrCode(`insert into t values ('[1,2,3]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["1"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["a"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values (json_array(cast("11:00:00" as time)));`) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as datetime array))));`) - tk.MustGetErrCode(`insert into t values ('[1,2,3]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[-1]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["1"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["a"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.2]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('[1.0]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a json, index idx((cast(a as double array))));`) - tk.MustExec(`insert into t values ('[1,2,3]');`) - tk.MustExec(`insert into t values ('[-1]');`) - tk.MustGetErrCode(`insert into t values ('["1"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["a"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values ('["汉字"]');`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustExec(`insert into t values ('[1.2]');`) - tk.MustExec(`insert into t values ('[1.0]');`) - tk.MustGetErrCode(`insert into t values (json_array(cast("11:00:00" as time)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02" as date)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime)));`, errno.ErrInvalidJSONValueForFuncIndex) - tk.MustGetErrCode(`insert into t values (json_array(cast('{"a":1}' as json)));`, errno.ErrInvalidJSONValueForFuncIndex) - } -} - func TestWriteMultiValuedIndex(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) diff --git a/tests/integrationtest/r/expression/multi_valued_index.result b/tests/integrationtest/r/expression/multi_valued_index.result new file mode 100644 index 0000000000000..63409df1abe80 --- /dev/null +++ b/tests/integrationtest/r/expression/multi_valued_index.result @@ -0,0 +1,508 @@ +drop table if exists t; +create table t(a json); +select cast(a as signed array) from t; +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +select json_extract(cast(a as signed array), '$[0]') from t; +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +select * from t where cast(a as signed array); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +select cast('[1,2,3]' as unsigned array); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +drop table t; +CREATE TABLE t(x INT, KEY k ((1 AND CAST(JSON_ARRAY(x) AS UNSIGNED ARRAY)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +CREATE TABLE t1 (f1 json, key mvi((cast(cast(f1 as unsigned array) as unsigned array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +CREATE TABLE t1 (f1 json, primary key mvi((cast(cast(f1 as unsigned array) as unsigned array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +CREATE TABLE t1 (f1 json, key mvi((cast(f1->>'$[*]' as unsigned array)))); +Error 3146 (HY000): Invalid data type for JSON data in argument 1 to function cast_as_array; a JSON string or JSON type is required. +CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as year array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'CAST-ing data to array of year(-1) BINARY' +CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as json array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'CAST-ing data to array of json BINARY' +CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as char(10) charset gbk array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'specifying charset for multi-valued index' +create table t(j json, gc json as ((concat(cast(j->'$[*]' as unsigned array),"x")))); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +create table t(j json, gc json as (cast(j->'$[*]' as unsigned array))); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +create table t1(j json, key i1((cast(j->"$" as char array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'CAST-ing data to array of char/binary BLOBs' +create table t1(j json, key i1((cast(j->"$" as binary array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'CAST-ing data to array of char/binary BLOBs' +create table t1(j json, key i1((cast(j->"$" as float array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'CAST-ing data to array of float BINARY' +create table t1(j json, key i1((cast(j->"$" as decimal(4,2) array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'CAST-ing data to array of decimal(4,2) BINARY' +create view v as select cast('[1,2,3]' as unsigned array); +Error 1235 (42000): This version of TiDB doesn't yet support 'Use of CAST( .. AS .. ARRAY) outside of functional index in CREATE(non-SELECT)/ALTER TABLE or in general expressions' +create table t(a json, index idx((cast(a as signed array)))); +drop table t; +create table t(a json, index idx(((cast(a as signed array))))); +drop table t; +create table t(j json, key i1((cast(j->"$" as double array)))); +drop table t; +create table t(a json, b int, index idx(b, (cast(a as signed array)), (cast(a as signed array)))); +Error 1235 (42000): This version of TiDB doesn't yet support 'more than one multi-valued key part per index' +create table t(a json, b int); +create index idx on t (b, (cast(a as signed array)), (cast(a as signed array))); +Error 1235 (42000): This version of TiDB doesn't yet support 'more than one multi-valued key part per index' +alter table t add index idx(b, (cast(a as signed array)), (cast(a as signed array))); +Error 1235 (42000): This version of TiDB doesn't yet support 'more than one multi-valued key part per index' +create index idx1 on t (b, (cast(a as signed array))); +alter table t add index idx2(b, (cast(a as signed array))); +drop table t; +create table t(a json, b int, index idx3(b, (cast(a as signed array)))); +drop table t; +set names gbk; +create table t(a json, b int, index idx3(b, (cast(a as char(10) array)))); +CREATE TABLE users (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, doc JSON); +CREATE TABLE t (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, doc JSON, FOREIGN KEY fk_user_id ((cast(doc->'$[*]' as signed array))) REFERENCES users(id)); +Error 1072 (42000): Key column '_V$_fk_user_id_0' doesn't exist in table +set names default; +set @@sql_mode=''; +drop table if exists t; +create table t(a json, index idx((cast(a as unsigned array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +Error 3752 (HY000): Value is out of range for expression index 'idx' at row 1 +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as signed array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as char(1) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +Error 3907 (HY000): Data too long for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as char(2) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as binary(1) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +Error 3907 (HY000): Data too long for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as binary(2) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +Error 3907 (HY000): Data too long for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as date array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as time array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as datetime array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as double array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +insert into t values ('[1.0]'); +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +set @@sql_mode=default; +drop table if exists t; +create table t(a json, index idx((cast(a as unsigned array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +Error 3752 (HY000): Value is out of range for expression index 'idx' at row 1 +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as signed array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as char(1) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +Error 3907 (HY000): Data too long for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as char(2) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as binary(1) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +Error 3907 (HY000): Data too long for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as binary(2) array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +Error 3907 (HY000): Data too long for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as date array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as time array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as datetime array)))); +insert into t values ('[1,2,3]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[-1]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.0]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +drop table if exists t; +create table t(a json, index idx((cast(a as double array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +insert into t values ('["1"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["a"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('["汉字"]'); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values ('[1.2]'); +insert into t values ('[1.0]'); +insert into t values (json_array(cast("11:00:00" as time))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02" as date))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +insert into t values (json_array(cast('{"a":1}' as json))); +Error 3903 (HY000): Invalid JSON value for CAST for expression index 'idx' +set sql_mode=default; diff --git a/tests/integrationtest/t/expression/multi_valued_index.test b/tests/integrationtest/t/expression/multi_valued_index.test new file mode 100644 index 0000000000000..a52bf2009ed0d --- /dev/null +++ b/tests/integrationtest/t/expression/multi_valued_index.test @@ -0,0 +1,513 @@ +# TestMultiValuedIndexDDL +drop table if exists t; +create table t(a json); +-- error 1235 +select cast(a as signed array) from t; +-- error 1235 +select json_extract(cast(a as signed array), '$[0]') from t; +-- error 1235 +select * from t where cast(a as signed array); +-- error 1235 +select cast('[1,2,3]' as unsigned array); +drop table t; +-- error 1235 +CREATE TABLE t(x INT, KEY k ((1 AND CAST(JSON_ARRAY(x) AS UNSIGNED ARRAY)))); +-- error 1235 +CREATE TABLE t1 (f1 json, key mvi((cast(cast(f1 as unsigned array) as unsigned array)))); +-- error 1235 +CREATE TABLE t1 (f1 json, primary key mvi((cast(cast(f1 as unsigned array) as unsigned array)))); +-- error 3146 +CREATE TABLE t1 (f1 json, key mvi((cast(f1->>'$[*]' as unsigned array)))); +-- error 1235 +CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as year array)))); +-- error 1235 +CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as json array)))); +-- error 1235 +CREATE TABLE t1 (f1 json, key mvi((cast(f1->'$[*]' as char(10) charset gbk array)))); +-- error 1235 +create table t(j json, gc json as ((concat(cast(j->'$[*]' as unsigned array),"x")))); +-- error 1235 +create table t(j json, gc json as (cast(j->'$[*]' as unsigned array))); +-- error 1235 +create table t1(j json, key i1((cast(j->"$" as char array)))); +-- error 1235 +create table t1(j json, key i1((cast(j->"$" as binary array)))); +-- error 1235 +create table t1(j json, key i1((cast(j->"$" as float array)))); +-- error 1235 +create table t1(j json, key i1((cast(j->"$" as decimal(4,2) array)))); +-- error 1235 +create view v as select cast('[1,2,3]' as unsigned array); +create table t(a json, index idx((cast(a as signed array)))); +drop table t; +create table t(a json, index idx(((cast(a as signed array))))); +drop table t; +create table t(j json, key i1((cast(j->"$" as double array)))); +drop table t; +-- error 1235 +create table t(a json, b int, index idx(b, (cast(a as signed array)), (cast(a as signed array)))); +create table t(a json, b int); +-- error 1235 +create index idx on t (b, (cast(a as signed array)), (cast(a as signed array))); +-- error 1235 +alter table t add index idx(b, (cast(a as signed array)), (cast(a as signed array))); +create index idx1 on t (b, (cast(a as signed array))); +alter table t add index idx2(b, (cast(a as signed array))); +drop table t; +create table t(a json, b int, index idx3(b, (cast(a as signed array)))); +drop table t; +set names gbk; +create table t(a json, b int, index idx3(b, (cast(a as char(10) array)))); +CREATE TABLE users (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, doc JSON); +-- error 1072 +CREATE TABLE t (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, doc JSON, FOREIGN KEY fk_user_id ((cast(doc->'$[*]' as signed array))) REFERENCES users(id)); + +set names default; + +# TestMultiValuedIndexDML +set @@sql_mode=''; +drop table if exists t; +create table t(a json, index idx((cast(a as unsigned array)))); +insert into t values ('[1,2,3]'); +-- error 3752 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as signed array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as char(1) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +-- error 3907 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as char(2) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as binary(1) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +-- error 3907 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as binary(2) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +-- error 3907 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as date array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as time array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as datetime array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as double array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +insert into t values ('[1.2]'); +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +set @@sql_mode=default; +drop table if exists t; +create table t(a json, index idx((cast(a as unsigned array)))); +insert into t values ('[1,2,3]'); +-- error 3752 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as signed array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as char(1) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +-- error 3907 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as char(2) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as binary(1) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +-- error 3907 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as binary(2) array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +insert into t values ('["1"]'); +insert into t values ('["a"]'); +-- error 3907 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as date array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as time array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as datetime array)))); +-- error 3903 +insert into t values ('[1,2,3]'); +-- error 3903 +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +-- error 3903 +insert into t values ('[1.2]'); +-- error 3903 +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); +drop table if exists t; +create table t(a json, index idx((cast(a as double array)))); +insert into t values ('[1,2,3]'); +insert into t values ('[-1]'); +-- error 3903 +insert into t values ('["1"]'); +-- error 3903 +insert into t values ('["a"]'); +-- error 3903 +insert into t values ('["汉字"]'); +insert into t values ('[1.2]'); +insert into t values ('[1.0]'); +-- error 3903 +insert into t values (json_array(cast("11:00:00" as time))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02" as date))); +-- error 3903 +insert into t values (json_array(cast("2022-02-02 11:00:00" as datetime))); +-- error 3903 +insert into t values (json_array(cast('{"a":1}' as json))); + +set sql_mode=default; From c0eaa1e09681740697fa86e58aa22284f51a335d Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 16:56:29 +0800 Subject: [PATCH 08/12] update expression_rewriter, 3 test cases --- pkg/planner/core/BUILD.bazel | 1 - pkg/planner/core/expression_rewriter_test.go | 423 ------------------ .../r/planner/core/expression_rewriter.result | 93 ++++ .../t/planner/core/expression_rewriter.test | 45 ++ 4 files changed, 138 insertions(+), 424 deletions(-) delete mode 100644 pkg/planner/core/expression_rewriter_test.go diff --git a/pkg/planner/core/BUILD.bazel b/pkg/planner/core/BUILD.bazel index 4fdc27e94063b..d1723b8a7b38e 100644 --- a/pkg/planner/core/BUILD.bazel +++ b/pkg/planner/core/BUILD.bazel @@ -189,7 +189,6 @@ go_test( "enforce_mpp_test.go", "errors_test.go", "exhaust_physical_plans_test.go", - "expression_rewriter_test.go", "expression_test.go", "find_best_task_test.go", "fragment_test.go", diff --git a/pkg/planner/core/expression_rewriter_test.go b/pkg/planner/core/expression_rewriter_test.go deleted file mode 100644 index 503a6538c3b77..0000000000000 --- a/pkg/planner/core/expression_rewriter_test.go +++ /dev/null @@ -1,423 +0,0 @@ -// Copyright 2018 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 ( - "testing" - - "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/parser/terror" - plannercore "github.com/pingcap/tidb/pkg/planner/core" - "github.com/pingcap/tidb/pkg/testkit" - "github.com/stretchr/testify/require" -) - -func TestIfNullEliminateColName(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)") - rs, err := tk.Exec("select ifnull(a,b) from t") - require.NoError(t, err) - fields := rs.Fields() - require.Greater(t, len(fields), 0) - require.Equal(t, "ifnull(a,b)", rs.Fields()[0].Column.Name.L) - require.NoError(t, rs.Close()) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(e int not null, b int)") - tk.MustExec("insert into t values(1, 1)") - tk.MustExec("create table t1(e int not null, b int)") - tk.MustExec("insert into t1 values(1, 1)") - rows := tk.MustQuery("select b from t where ifnull(e, b)") - rows.Check(testkit.Rows("1")) - rows = tk.MustQuery("select b from t1 where ifnull(e, b)") - rows.Check(testkit.Rows("1")) -} - -func TestBinaryOpFunction(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), (NULL, 2, 3 ), (1, NULL, 3),(1, 2, NULL),(NULL, 2, 3+1), (1, NULL, 3+1), (1, 2+1, NULL),(NULL, 2, 3-1), (1, NULL, 3-1), (1, 2-1, NULL)") - tk.MustQuery("SELECT * FROM t WHERE (a,b,c) <= (1,2,3) order by b").Check(testkit.Rows("1 1 ", "1 2 3")) - tk.MustQuery("SELECT * FROM t WHERE (a,b,c) > (1,2,3) order by b").Check(testkit.Rows("1 3 ")) -} - -func TestDefaultFunction(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 varchar(10) default 'def', - b varchar(10), - c int default '10', - d double default '3.14', - e datetime default '20180101', - f datetime default current_timestamp, - g date default current_date);`) - tk.MustExec("insert into t1(a, b, c, d) values ('1', '1', 1, 1)") - tk.MustExec("set @@timestamp = 1321009871") - defer tk.MustExec("set @@timestamp = DEFAULT") - tk.MustExec("set @@time_zone = '+00:00'") - defer tk.MustExec("set @@time_zone = DEFAULT") - tk.MustQuery(`select - default(a) as defa, - default(b) as defb, - default(c) as defc, - default(d) as defd, - default(e) as defe, - default(f) as deff, - default(g) as defg - from t1`).Check(testkit.RowsWithSep("|", "def||10|3.14|2018-01-01 00:00:00|2011-11-11 11:11:11|2011-11-11")) - require.EqualError(t, tk.ExecToErr("select default(x) from t1"), "[planner:1054]Unknown column 'x' in 'field list'") - - tk.MustQuery("select default(a0) from (select a as a0 from t1) as t0").Check(testkit.Rows("def")) - require.EqualError(t, tk.ExecToErr("select default(a0) from (select a+1 as a0 from t1) as t0"), "[table:1364]Field 'a0' doesn't have a default value") - - tk.MustExec("create table t2(a varchar(10), b varchar(10))") - tk.MustExec("insert into t2 values ('1', '1')") - require.EqualError(t, tk.ExecToErr("select default(a) from t1, t2"), "[expression:1052]Column 'a' in field list is ambiguous") - - tk.MustQuery("select default(t1.a) from t1, t2").Check(testkit.Rows("def")) - - tk.MustExec(`create table t3( - a datetime default current_timestamp, - b timestamp default current_timestamp, - c timestamp(6) default current_timestamp(6), - d varchar(20) default 'current_timestamp')`) - tk.MustExec("insert into t3 values ()") - tk.MustQuery(`select - default(a) as defa, - default(b) as defb, - default(c) as defc, - default(d) as defd - from t3`).Check(testkit.RowsWithSep("|", "2011-11-11 11:11:11|2011-11-11 11:11:11|2011-11-11 11:11:11.000000|current_timestamp")) - - tk.MustExec(`create table t4(a int default 1, b varchar(5))`) - tk.MustExec(`insert into t4 values (0, 'B'), (1, 'B'), (2, 'B')`) - tk.MustExec(`create table t5(d int default 0, e varchar(5))`) - tk.MustExec(`insert into t5 values (5, 'B')`) - - tk.MustQuery(`select a from t4 where a > (select default(d) from t5 where t4.b = t5.e)`).Check(testkit.Rows("1", "2")) - tk.MustQuery(`select a from t4 where a > (select default(a) from t5 where t4.b = t5.e)`).Check(testkit.Rows("2")) - - tk.MustExec("prepare stmt from 'select default(a) from t1';") - tk.MustQuery("execute stmt").Check(testkit.Rows("def")) - tk.MustExec("alter table t1 modify a varchar(10) default 'DEF'") - tk.MustQuery("execute stmt").Check(testkit.Rows("DEF")) - - tk.MustExec("update t1 set c = c + default(c)") - tk.MustQuery("select c from t1").Check(testkit.Rows("11")) - - tk.MustExec("create table t6(a int default -1, b int)") - tk.MustExec(`insert into t6 values (0, 0), (1, 1), (2, 2)`) - tk.MustExec("create table t7(a int default 1, b int)") - tk.MustExec(`insert into t7 values (0, 0), (1, 1), (2, 2)`) - - tk.MustQuery(`select a from t6 where a > (select default(a) from t7 where t6.a = t7.a)`).Check(testkit.Rows("2")) - tk.MustQuery(`select a, default(a) from t6 where a > (select default(a) from t7 where t6.a = t7.a)`).Check(testkit.Rows("2 -1")) - - tk.MustExec("create table t8(a int default 1, b int default -1)") - tk.MustExec(`insert into t8 values (0, 0), (1, 1)`) - - tk.MustQuery(`select a, a from t8 order by default(a)`).Check(testkit.Rows("0 0", "1 1")) - tk.MustQuery(`select a from t8 order by default(b)`).Check(testkit.Rows("0", "1")) - tk.MustQuery(`select a from t8 order by default(b) * a`).Check(testkit.Rows("1", "0")) -} - -func TestCompareSubquery(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("drop table if exists s") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("create table s(a int, b int)") - tk.MustExec("insert into t values(1, null), (2, null)") - - // Test empty checker. - tk.MustQuery("select a != any (select a from s) from t").Check(testkit.Rows( - "0", - "0", - )) - tk.MustQuery("select b != any (select a from s) from t").Check(testkit.Rows( - "0", - "0", - )) - tk.MustQuery("select a = all (select a from s) from t").Check(testkit.Rows( - "1", - "1", - )) - tk.MustQuery("select b = all (select a from s) from t").Check(testkit.Rows( - "1", - "1", - )) - tk.MustQuery("select * from t where a != any (select a from s)").Check(testkit.Rows()) - tk.MustQuery("select * from t where b != any (select a from s)").Check(testkit.Rows()) - tk.MustQuery("select * from t where a = all (select a from s)").Check(testkit.Rows( - "1 ", - "2 ", - )) - tk.MustQuery("select * from t where b = all (select a from s)").Check(testkit.Rows( - "1 ", - "2 ", - )) - // Test outer null checker. - tk.MustQuery("select b != any (select a from t t2) from t t1").Check(testkit.Rows( - "", - "", - )) - tk.MustQuery("select b = all (select a from t t2) from t t1").Check(testkit.Rows( - "", - "", - )) - tk.MustQuery("select * from t t1 where b != any (select a from t t2)").Check(testkit.Rows()) - tk.MustQuery("select * from t t1 where b = all (select a from t t2)").Check(testkit.Rows()) - - tk.MustExec("delete from t where a = 2") - tk.MustQuery("select b != any (select a from t t2) from t t1").Check(testkit.Rows( - "", - )) - tk.MustQuery("select b = all (select a from t t2) from t t1").Check(testkit.Rows( - "", - )) - tk.MustQuery("select * from t t1 where b != any (select a from t t2)").Check(testkit.Rows()) - tk.MustQuery("select * from t t1 where b = all (select a from t t2)").Check(testkit.Rows()) - - // Test inner null checker. - tk.MustExec("insert into t values(null, 1)") - tk.MustQuery("select b != any (select a from t t2) from t t1").Check(testkit.Rows( - "", - "", - )) - tk.MustQuery("select b = all (select a from t t2) from t t1").Check(testkit.Rows( - "", - "", - )) - tk.MustQuery("select * from t t1 where b != any (select a from t t2)").Check(testkit.Rows()) - tk.MustQuery("select * from t t1 where b = all (select a from t t2)").Check(testkit.Rows()) - - tk.MustExec("delete from t where b = 1") - tk.MustExec("insert into t values(null, 2)") - tk.MustQuery("select b != any (select a from t t2) from t t1").Check(testkit.Rows( - "", - "1", - )) - tk.MustQuery("select b = all (select a from t t2) from t t1").Check(testkit.Rows( - "", - "0", - )) - tk.MustQuery("select * from t t1 where b != any (select a from t t2)").Check(testkit.Rows( - " 2", - )) - tk.MustQuery("select * from t t1 where b = all (select a from t t2)").Check(testkit.Rows()) - - // for issue 20059 - tk.MustExec("DROP TABLE IF EXISTS `t`") - tk.MustExec("CREATE TABLE `t` ( `a` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("INSERT INTO `t` VALUES (1);") - tk.MustExec("DROP TABLE IF EXISTS `table_40_utf8_4`;") - tk.MustExec("CREATE TABLE `table_40_utf8_4` (`col_tinyint_key_unsigned` tinyint(4) DEFAULT NULL, `col_bit64_key_signed` bit(64) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;") - tk.MustExec("INSERT INTO `table_40_utf8_4` VALUES (31, -18);") - tk.MustQuery("select count(1) from table_40_utf8_4 where ( select count(1) from t where table_40_utf8_4.col_bit64_key_signed!=table_40_utf8_4.col_tinyint_key_unsigned)").Check(testkit.Rows("1")) -} - -func TestCheckFullGroupBy(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 t1.a, (select max(t2.b) from t t2) from t t1").Check(testkit.Rows()) - err := tk.ExecToErr("select t1.a, (select t2.a, max(t2.b) from t t2) from t t1") - require.True(t, terror.ErrorEqual(err, plannercore.ErrMixOfGroupFuncAndFields)) -} - -func TestPatternLikeToExpression(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustQuery("select 0 like 'a string';").Check(testkit.Rows("0")) - tk.MustQuery("select 0.0 like 'a string';").Check(testkit.Rows("0")) - tk.MustQuery("select 0 like '0.00';").Check(testkit.Rows("0")) - tk.MustQuery("select cast(\"2011-5-3\" as datetime) like \"2011-05-03\";").Check(testkit.Rows("0")) - tk.MustQuery("select 1 like '1';").Check(testkit.Rows("1")) - tk.MustQuery("select 0 like '0';").Check(testkit.Rows("1")) - tk.MustQuery("select 0.00 like '0.00';").Check(testkit.Rows("1")) -} - -func TestExpressionRewriterIssue(t *testing.T) { - // Issue20007 - 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 (c_int int, c_str varchar(40), c_datetime datetime, primary key(c_int));") - tk.MustExec("create table t2 (c_int int, c_str varchar(40), c_datetime datetime, primary key (c_datetime)) partition by range (to_days(c_datetime)) ( partition p0 values less than (to_days('2020-02-01')), partition p1 values less than (to_days('2020-04-01')), partition p2 values less than (to_days('2020-06-01')), partition p3 values less than maxvalue);") - tk.MustExec("insert into t1 (c_int, c_str, c_datetime) values (1, 'xenodochial bassi', '2020-04-29 03:22:51'), (2, 'epic wiles', '2020-01-02 23:29:51'), (3, 'silly burnell', '2020-02-25 07:43:07');") - tk.MustExec("insert into t2 (c_int, c_str, c_datetime) values (1, 'trusting matsumoto', '2020-01-07 00:57:18'), (2, 'pedantic boyd', '2020-06-08 23:12:16'), (null, 'strange hypatia', '2020-05-23 17:45:27');") - // Test 10 times. - for i := 0; i < 10; i++ { - tk.MustQuery("select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); ").Check( - testkit.Rows("2 epic wiles 2020-01-02 23:29:51", "3 silly burnell 2020-02-25 07:43:07")) - } - - // Issue9869 - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1(a int, b bigint unsigned);") - tk.MustExec("insert into t1 (a, b) values (1,4572794622775114594), (2,18196094287899841997),(3,11120436154190595086);") - tk.MustQuery("select (case t1.a when 0 then 0 else t1.b end), cast(t1.b as signed) from t1;").Check( - testkit.Rows("4572794622775114594 4572794622775114594", "18196094287899841997 -250649785809709619", "11120436154190595086 -7326307919518956530")) - - // Issue17652 - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(x bigint unsigned);") - tk.MustExec("insert into t values( 9999999703771440633);") - tk.MustQuery("select ifnull(max(x), 0) from t").Check(testkit.Rows("9999999703771440633")) - // Issue22818 - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a time);") - tk.MustExec("insert into t values(\"23:22:22\");") - tk.MustQuery("select * from t where a between \"23:22:22\" and \"23:22:22\"").Check(testkit.Rows("23:22:22")) - // Issue24705 - tk.MustExec("drop table if exists t1,t2;") - tk.MustExec("create table t1 (c_int int, c_str varchar(40) character set utf8 collate utf8_general_ci);") - tk.MustExec("create table t2 (c_int int, c_str varchar(40) character set utf8 collate utf8_unicode_ci);") - err := tk.ExecToErr("select * from t1 where c_str < any (select c_str from t2 where c_int between 6 and 9);") - require.EqualError(t, err, "[expression:1267]Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '<'") -} - -func TestCompareMultiFieldsInSubquery(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);") - tk.MustExec("CREATE TABLE t2(c1 int, c2 int);") - tk.MustExec("CREATE TABLE t3(c1 int, c2 int);") - tk.MustExec("CREATE TABLE t4(c1 int, c2 int);") - tk.MustExec("INSERT INTO t1 VALUES (0, 0), (NULL, NULL);") - tk.MustExec("INSERT INTO t2 VALUES (0, 0), (NULL, NULL);") - tk.MustExec("INSERT INTO t3 VALUES (1, 2);") - // issue #13551 and #21674 - tk.MustQuery("SELECT * FROM t2 WHERE (SELECT c1, c2 FROM t2 LIMIT 1) = ANY (SELECT c1, c2 FROM t1);").Check(testkit.Rows("0 0", " ")) - tk.MustQuery("SELECT * FROM t2 WHERE (SELECT c1 FROM t2 LIMIT 1) = ANY (SELECT c1 FROM t1);").Check(testkit.Rows("0 0", " ")) - tk.MustQuery("SELECT * FROM t2 WHERE (SELECT c1, c2 FROM t2 order by c1 LIMIT 1) = ANY (SELECT c1, c2 FROM t1);").Check(testkit.Rows()) - - tk.MustQuery("SELECT * FROM t3 WHERE (SELECT c1 FROM t3 LIMIT 1) != ALL(SELECT c1 FROM t4);").Check(testkit.Rows("1 2")) - tk.MustQuery("SELECT * FROM t3 WHERE (SELECT c1, c2 FROM t3 LIMIT 1) != ALL(SELECT c1, c2 FROM t4);").Check(testkit.Rows("1 2")) - tk.MustExec("INSERT INTO t4 VALUES (1, 3);") - tk.MustQuery("SELECT * FROM t3 WHERE (SELECT c1 FROM t3 LIMIT 1) != ALL(SELECT c1 FROM t4);").Check(testkit.Rows()) - tk.MustQuery("SELECT * FROM t3 WHERE (SELECT c1, c2 FROM t3 LIMIT 1) != ALL(SELECT c1, c2 FROM t4);").Check(testkit.Rows("1 2")) - tk.MustExec("INSERT INTO t4 VALUES (1, 2);") - tk.MustQuery("SELECT * FROM t3 WHERE (SELECT c1 FROM t3 LIMIT 1) != ALL(SELECT c1 FROM t4);").Check(testkit.Rows()) - tk.MustQuery("SELECT * FROM t3 WHERE (SELECT c1, c2 FROM t3 LIMIT 1) != ALL(SELECT c1, c2 FROM t4);").Check(testkit.Rows()) -} - -func TestBetweenExprCollation(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 char(10) charset latin1 collate latin1_bin, c char(10) collate utf8mb4_general_ci);") - tk.MustExec("insert into t1 values ('a', 'B');") - tk.MustExec("insert into t1 values ('c', 'D');") - tk.MustQuery("select * from t1 where a between 'B' and c;").Check(testkit.Rows("c D")) - tk.MustQuery("explain select * from t1 where 'a' between 'g' and 'f';").Check(testkit.Rows("TableDual_6 0.00 root rows:0")) - tk.MustGetErrMsg("select * from t1 where a between 'B' collate utf8mb4_general_ci and c collate utf8mb4_unicode_ci;", "[expression:1270]Illegal mix of collations (latin1_bin,IMPLICIT), (utf8mb4_general_ci,EXPLICIT), (utf8mb4_unicode_ci,EXPLICIT) for operation 'BETWEEN'") -} - -func TestInsertOnDuplicateLazyMoreThan1Row(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE if exists t1, t2, source;") - tk.MustExec("CREATE TABLE t1(a INTEGER PRIMARY KEY);") - tk.MustExec("CREATE TABLE t2(a INTEGER);") - tk.MustExec("CREATE TABLE source (b INTEGER);") - tk.MustExec("INSERT INTO t1 VALUES (1);") - tk.MustExec("INSERT INTO t2 VALUES (1);") - tk.MustExec("INSERT INTO source VALUES (1),(1);") - // the on duplicate is not triggered by t1's primary key. - tk.MustGetErrCode("INSERT INTO t1 (a) VALUES (1) ON DUPLICATE KEY UPDATE a= (SELECT b FROM source);", mysql.ErrSubqueryNo1Row) - // the on duplicate is not triggered. - tk.MustExec("INSERT INTO t2 (a) VALUES (1) ON DUPLICATE KEY UPDATE a= (SELECT b FROM source);") - tk.MustExec("DROP TABLE if exists t1, t2, source;") -} - -func TestConvertIfNullToCast(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(cnotnull tinyint not null, cnull tinyint null);") - tk.MustExec("INSERT INTO t1 VALUES(1, 1);") - tk.MustQuery("select CAST(IFNULL(cnull, '1') AS DATE), CAST(IFNULL(cnotnull, '1') AS DATE) from t1;").Check(testkit.Rows(" ")) - tk.MustQuery("explain format=\"brief\" select IFNULL(cnotnull, '1') from t1;").Check(testkit.Rows( - "Projection 10000.00 root cast(test.t1.cnotnull, varchar(4) BINARY CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#4]\n" + - "[└─TableReader 10000.00 root data:TableFullScan]\n" + - "[ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - )) -} - -func TestColResolutionPriBetweenOuterAndNatureJoin(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("DROP VIEW if exists t0;") - tk.MustExec("CREATE TABLE t0(c0 TEXT(328) );") - tk.MustExec("CREATE definer='root'@'localhost' VIEW v0(c0) AS SELECT 'c' FROM t0;") - tk.MustExec("INSERT INTO t0 VALUES (-12);") - tk.MustQuery("SELECT v0.c0 AS c0 FROM v0 NATURAL RIGHT JOIN t0 WHERE (1 !=((v0.c0)REGEXP(-7)));").Check(testkit.Rows()) - tk.MustQuery("SELECT COUNT(v0.c0) AS c0 FROM v0 WHERE EXISTS(SELECT v0.c0 AS c0 FROM v0 NATURAL RIGHT JOIN t0 WHERE (1 !=((v0.c0)REGEXP(-7))));").Check(testkit.Rows("0")) -} - -func TestColResolutionSubqueryWithUnionAll(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("DROP TABLE if exists t;") - tk.MustExec("create table t1(a int);") - tk.MustExec("create table t2(a int);") - tk.MustExec("create table t(a int);") - tk.MustQuery("select * from t where exists ( select a from ( select a from t1 union all select a from t2) u where t.a=u.a);").Check(testkit.Rows()) -} - -func TestDefaultCollationForUTF8MB4(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test;") - tk.MustExec(`set @a = 'xx'`) - // utf8mb4_bin - tk.MustQuery("select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'").Check(testkit.Rows("utf8mb4_bin utf8mb4 46 Yes Yes 1")) - tk.MustQuery("select collation(_utf8mb4'12345')").Check(testkit.Rows("utf8mb4_bin")) - tk.MustQuery("select collation(_utf8mb4'xxx' collate utf8mb4_general_ci);").Check(testkit.Rows("utf8mb4_general_ci")) - tk.MustQuery("select collation(_utf8mb4'@a')").Check(testkit.Rows("utf8mb4_bin")) - tk.MustQuery("select collation(_utf8mb4'@a' collate utf8mb4_general_ci);").Check(testkit.Rows("utf8mb4_general_ci")) - // utf8mb4_0900_ai_ci - tk.MustExec("set @@session.default_collation_for_utf8mb4='utf8mb4_0900_ai_ci'") - tk.MustQuery("select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'").Check(testkit.Rows("utf8mb4_bin utf8mb4 46 Yes Yes 1")) - tk.MustQuery("select collation(_utf8mb4'12345')").Check(testkit.Rows("utf8mb4_0900_ai_ci")) - tk.MustQuery("select collation(_utf8mb4'12345' collate utf8mb4_general_ci);").Check(testkit.Rows("utf8mb4_general_ci")) - tk.MustQuery("select collation(_utf8mb4'@a')").Check(testkit.Rows("utf8mb4_0900_ai_ci")) - tk.MustQuery("select collation(_utf8mb4'@a' collate utf8mb4_general_ci);").Check(testkit.Rows("utf8mb4_general_ci")) -} diff --git a/tests/integrationtest/r/planner/core/expression_rewriter.result b/tests/integrationtest/r/planner/core/expression_rewriter.result index da510642fea64..21a80fa6eaf7e 100644 --- a/tests/integrationtest/r/planner/core/expression_rewriter.result +++ b/tests/integrationtest/r/planner/core/expression_rewriter.result @@ -340,3 +340,96 @@ create table t2(a int); create table t(a int); select * from t where exists ( select a from ( select a from t1 union all select a from t2) u where t.a=u.a); a +drop table if exists t, t1; +create table t(a int not null, b int not null); +select ifnull(a,b) from t; +ifnull(a,b) +drop table if exists t; +create table t(e int not null, b int); +insert into t values(1, 1); +create table t1(e int not null, b int); +insert into t1 values(1, 1); +select b from t where ifnull(e, b); +b +1 +select b from t1 where ifnull(e, b); +b +1 +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), c_datetime datetime, primary key(c_int)); +create table t2 (c_int int, c_str varchar(40), c_datetime datetime, primary key (c_datetime)) partition by range (to_days(c_datetime)) ( partition p0 values less than (to_days('2020-02-01')), partition p1 values less than (to_days('2020-04-01')), partition p2 values less than (to_days('2020-06-01')), partition p3 values less than maxvalue); +insert into t1 (c_int, c_str, c_datetime) values (1, 'xenodochial bassi', '2020-04-29 03:22:51'), (2, 'epic wiles', '2020-01-02 23:29:51'), (3, 'silly burnell', '2020-02-25 07:43:07'); +insert into t2 (c_int, c_str, c_datetime) values (1, 'trusting matsumoto', '2020-01-07 00:57:18'), (2, 'pedantic boyd', '2020-06-08 23:12:16'), (null, 'strange hypatia', '2020-05-23 17:45:27'); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +c_int c_str c_datetime +2 epic wiles 2020-01-02 23:29:51 +3 silly burnell 2020-02-25 07:43:07 +set @a = 'xx'; +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN +utf8mb4_bin utf8mb4 46 Yes Yes 1 +select collation(_utf8mb4'12345'); +collation(_utf8mb4'12345') +utf8mb4_bin +select collation(_utf8mb4'xxx' collate utf8mb4_general_ci); +collation(_utf8mb4'xxx' collate utf8mb4_general_ci) +utf8mb4_general_ci +select collation(_utf8mb4'@a'); +collation(_utf8mb4'@a') +utf8mb4_bin +select collation(_utf8mb4'@a' collate utf8mb4_general_ci); +collation(_utf8mb4'@a' collate utf8mb4_general_ci) +utf8mb4_general_ci +set @@session.default_collation_for_utf8mb4='utf8mb4_0900_ai_ci'; +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN +utf8mb4_bin utf8mb4 46 Yes Yes 1 +select collation(_utf8mb4'12345'); +collation(_utf8mb4'12345') +utf8mb4_0900_ai_ci +select collation(_utf8mb4'12345' collate utf8mb4_general_ci); +collation(_utf8mb4'12345' collate utf8mb4_general_ci) +utf8mb4_general_ci +select collation(_utf8mb4'@a'); +collation(_utf8mb4'@a') +utf8mb4_0900_ai_ci +select collation(_utf8mb4'@a' collate utf8mb4_general_ci); +collation(_utf8mb4'@a' collate utf8mb4_general_ci) +utf8mb4_general_ci +set @@session.default_collation_for_utf8mb4=default; diff --git a/tests/integrationtest/t/planner/core/expression_rewriter.test b/tests/integrationtest/t/planner/core/expression_rewriter.test index ad77cc66999dc..4e400096c7f6d 100644 --- a/tests/integrationtest/t/planner/core/expression_rewriter.test +++ b/tests/integrationtest/t/planner/core/expression_rewriter.test @@ -227,3 +227,48 @@ create table t2(a int); create table t(a int); select * from t where exists ( select a from ( select a from t1 union all select a from t2) u where t.a=u.a); +# TestIfNullEliminateColName +drop table if exists t, t1; +create table t(a int not null, b int not null); +select ifnull(a,b) from t; +drop table if exists t; +create table t(e int not null, b int); +insert into t values(1, 1); +create table t1(e int not null, b int); +insert into t1 values(1, 1); +select b from t where ifnull(e, b); +select b from t1 where ifnull(e, b); + +# TestIssue20007 +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), c_datetime datetime, primary key(c_int)); +create table t2 (c_int int, c_str varchar(40), c_datetime datetime, primary key (c_datetime)) partition by range (to_days(c_datetime)) ( partition p0 values less than (to_days('2020-02-01')), partition p1 values less than (to_days('2020-04-01')), partition p2 values less than (to_days('2020-06-01')), partition p3 values less than maxvalue); +insert into t1 (c_int, c_str, c_datetime) values (1, 'xenodochial bassi', '2020-04-29 03:22:51'), (2, 'epic wiles', '2020-01-02 23:29:51'), (3, 'silly burnell', '2020-02-25 07:43:07'); +insert into t2 (c_int, c_str, c_datetime) values (1, 'trusting matsumoto', '2020-01-07 00:57:18'), (2, 'pedantic boyd', '2020-06-08 23:12:16'), (null, 'strange hypatia', '2020-05-23 17:45:27'); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); +select * from t1 where c_int != any (select c_int from t2 where t1.c_str <= t2.c_str); + +# TestDefaultCollationForUTF8MB4 +set @a = 'xx'; +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +select collation(_utf8mb4'12345'); +select collation(_utf8mb4'xxx' collate utf8mb4_general_ci); +select collation(_utf8mb4'@a'); +select collation(_utf8mb4'@a' collate utf8mb4_general_ci); +set @@session.default_collation_for_utf8mb4='utf8mb4_0900_ai_ci'; +select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; +select collation(_utf8mb4'12345'); +select collation(_utf8mb4'12345' collate utf8mb4_general_ci); +select collation(_utf8mb4'@a'); +select collation(_utf8mb4'@a' collate utf8mb4_general_ci); + +set @@session.default_collation_for_utf8mb4=default; + From d25d08f85749616df8f7edfcc998441e795d17d7 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 17:41:37 +0800 Subject: [PATCH 09/12] update cbo_test, 2 test cases --- pkg/planner/core/cbo_test.go | 80 ------------------- .../integrationtest/r/planner/core/cbo.result | 59 ++++++++++++++ tests/integrationtest/t/planner/core/cbo.test | 49 ++++++++++++ 3 files changed, 108 insertions(+), 80 deletions(-) diff --git a/pkg/planner/core/cbo_test.go b/pkg/planner/core/cbo_test.go index 3ede953e2d1d7..f925c9f621fc9 100644 --- a/pkg/planner/core/cbo_test.go +++ b/pkg/planner/core/cbo_test.go @@ -17,7 +17,6 @@ package core_test import ( "context" "fmt" - "strings" "testing" "github.com/pingcap/tidb/pkg/planner" @@ -27,57 +26,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestExplainCostTrace(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)") - - tk.MustExec("set tidb_cost_model_version=2") - tk.MustQuery("explain format='cost_trace' select * from t").Check(testkit.Rows( - `TableReader_5 10000.00 177906.67 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00 root data:TableFullScan_4`, - `└─TableFullScan_4 10000.00 2035000.00 scan(10000*logrowsize(32)*tikv_scan_factor(40.7)) cop[tikv] table:t keep order:false, stats:pseudo`)) - tk.MustQuery("explain analyze format='cost_trace' select * from t").CheckAt([]int{0, 1, 2, 3, 4}, [][]interface{}{ - {"TableReader_5", "10000.00", "177906.67", "((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00", "1"}, - {"└─TableFullScan_4", "10000.00", "2035000.00", "scan(10000*logrowsize(32)*tikv_scan_factor(40.7))", "1"}, - }) - - tk.MustExec("set tidb_cost_model_version=1") - tk.MustQuery("explain format='cost_trace' select * from t").Check(testkit.Rows( - // cost trace on model ver1 is not supported - `TableReader_5 10000.00 34418.00 N/A root data:TableFullScan_4`, - `└─TableFullScan_4 10000.00 435000.00 N/A cop[tikv] table:t keep order:false, stats:pseudo`, - )) - tk.MustQuery("explain analyze format='cost_trace' select * from t").CheckAt([]int{0, 1, 2, 3, 4}, [][]interface{}{ - {"TableReader_5", "10000.00", "34418.00", "N/A", "1"}, - {"└─TableFullScan_4", "10000.00", "435000.00", "N/A", "1"}, - }) -} - -func TestExplainAnalyze(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set sql_mode='STRICT_TRANS_TABLES'") // disable only full group by - tk.MustExec("create table t1(a int, b int, c int, key idx(a, b))") - tk.MustExec("create table t2(a int, b int)") - tk.MustExec("insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)") - tk.MustExec("insert into t2 values (2, 22), (3, 33), (5, 55), (233, 2), (333, 3), (3434, 5)") - tk.MustExec("analyze table t1, t2") - rs := tk.MustQuery("explain analyze select t1.a, t1.b, sum(t1.c) from t1 join t2 on t1.a = t2.b where t1.a > 1") - require.Len(t, rs.Rows(), 10) - for _, row := range rs.Rows() { - require.Len(t, row, 9) - execInfo := row[5].(string) - require.Contains(t, execInfo, "time") - require.Contains(t, execInfo, "loops") - if strings.Contains(row[0].(string), "Reader") || strings.Contains(row[0].(string), "IndexLookUp") { - require.Contains(t, execInfo, "cop_task") - } - } -} - func constructInsertSQL(i, n int) string { sql := "insert into t (a,b,c,e)values " for j := 0; j < n; j++ { @@ -205,31 +153,3 @@ func BenchmarkOptimize(b *testing.B) { }) } } - -func TestIssue9805(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 ( - id bigint primary key, - a bigint not null, - b varchar(100) not null, - c varchar(10) not null, - d bigint as (a % 30) not null, - key (d, b, c) - ) - `) - tk.MustExec(` - create table t2 ( - id varchar(50) primary key, - a varchar(100) unique, - b datetime, - c varchar(45), - d int not null unique auto_increment - ) - `) - // Test when both tables are empty, EXPLAIN ANALYZE for IndexLookUp would not panic. - tk.MustQuery("explain analyze select /*+ TIDB_INLJ(t2) */ t1.id, t2.a from t1 join t2 on t1.a = t2.d where t1.b = 't2' and t1.d = 4") -} diff --git a/tests/integrationtest/r/planner/core/cbo.result b/tests/integrationtest/r/planner/core/cbo.result index 645686c28e8de..f9d2ff5a8a726 100644 --- a/tests/integrationtest/r/planner/core/cbo.result +++ b/tests/integrationtest/r/planner/core/cbo.result @@ -21,3 +21,62 @@ analyze table t25219; select * from t25219 WHERE (col3 IS NULL OR col1 IS NOT NULL AND col3 <= 6659) AND col3 = 1; a col3 col1 1 1 1 +drop table if exists t1, t2; +create table t1 ( +id bigint primary key, +a bigint not null, +b varchar(100) not null, +c varchar(10) not null, +d bigint as (a % 30) not null, +key (d, b, c) +); +create table t2 ( +id varchar(50) primary key, +a varchar(100) unique, +b datetime, +c varchar(45), +d int not null unique auto_increment +); +explain analyze select /*+ TIDB_INLJ(t2) */ t1.id, t2.a from t1 join t2 on t1.a = t2.d where t1.b = 't2' and t1.d = 4; +drop table if exists t; +create table t (a int); +insert into t values (1); +set tidb_cost_model_version=2; +explain format='cost_trace' select * from t; +id estRows estCost costFormula task access object operator info +TableReader_5 10000.00 177906.67 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00 root data:TableFullScan_4 +└─TableFullScan_4 10000.00 2035000.00 scan(10000*logrowsize(32)*tikv_scan_factor(40.7)) cop[tikv] table:t keep order:false, stats:pseudo +explain analyze format='cost_trace' select * from t; +id estRows estCost costFormula actRows task access object execution info operator info memory disk +TableReader_5 10000.00 177906.67 ((scan(10000*logrowsize(32)*tikv_scan_factor(40.7))) + (net(10000*rowsize(16)*tidb_kv_net_factor(3.96))))/15.00 1 root +└─TableFullScan_4 10000.00 2035000.00 scan(10000*logrowsize(32)*tikv_scan_factor(40.7)) 1 cop[tikv] table:t +set tidb_cost_model_version=1; +explain format='cost_trace' select * from t; +id estRows estCost costFormula task access object operator info +TableReader_5 10000.00 34418.00 N/A root data:TableFullScan_4 +└─TableFullScan_4 10000.00 435000.00 N/A cop[tikv] table:t keep order:false, stats:pseudo +explain analyze format='cost_trace' select * from t; +id estRows estCost costFormula actRows task access object execution info operator info memory disk +TableReader_5 10000.00 34418.00 N/A 1 root +└─TableFullScan_4 10000.00 435000.00 N/A 1 cop[tikv] table:t +set tidb_cost_model_version=default; +drop table if exists t1, t2; +set sql_mode='STRICT_TRANS_TABLES'; +create table t1(a int, b int, c int, key idx(a, b)); +create table t2(a int, b int); +insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5); +insert into t2 values (2, 22), (3, 33), (5, 55), (233, 2), (333, 3), (3434, 5); +analyze table t1, t2; +explain analyze select t1.a, t1.b, sum(t1.c) from t1 join t2 on t1.a = t2.b where t1.a > 1; +id estRows actRows task access object execution info operator info memory disk +Projection_9 1.00 1 root NULL time:, loops:, RU:, Concurrency:OFF planner__core__cbo.t1.a, planner__core__cbo.t1.b, Column#8 KB N/A +└─StreamAgg_11 1.00 1 root NULL time:, loops: funcs:sum(Column#16)->Column#8, funcs:firstrow(Column#17)->planner__core__cbo.t1.a, funcs:firstrow(Column#18)->planner__core__cbo.t1.b KB N/A + └─Projection_53 4.00 3 root NULL time:, loops:, Concurrency:OFF cast(planner__core__cbo.t1.c, decimal(10,0) BINARY)->Column#16, planner__core__cbo.t1.a->Column#17, planner__core__cbo.t1.b->Column#18 KB N/A + └─HashJoin_51 4.00 3 root NULL time:, loops:, build_hash_table:{total:, fetch:, build:}, probe:{concurrency:, total:, max:, probe:, fetch:} inner join, equal:[eq(planner__core__cbo.t1.a, planner__core__cbo.t2.b)] KB Bytes + ├─TableReader_30(Build) 6.00 6 root NULL time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:Selection_29 Bytes N/A + │ └─Selection_29 6.00 6 cop[tikv] NULL tikv_task:{time:, loops:} gt(planner__core__cbo.t2.b, 1), not(isnull(planner__core__cbo.t2.b)) N/A N/A + │ └─TableFullScan_28 6.00 6 cop[tikv] table:t2 tikv_task:{time:, loops:} keep order:false N/A N/A + └─TableReader_33(Probe) 4.00 4 root NULL time:, loops:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:Selection_32 Bytes N/A + └─Selection_32 4.00 4 cop[tikv] NULL tikv_task:{time:, loops:} gt(planner__core__cbo.t1.a, 1), not(isnull(planner__core__cbo.t1.a)) N/A N/A + └─TableFullScan_31 5.00 5 cop[tikv] table:t1 tikv_task:{time:, loops:} keep order:false N/A N/A +set sql_mode=default; diff --git a/tests/integrationtest/t/planner/core/cbo.test b/tests/integrationtest/t/planner/core/cbo.test index 0cafe16802c4e..09bb8aa09203e 100644 --- a/tests/integrationtest/t/planner/core/cbo.test +++ b/tests/integrationtest/t/planner/core/cbo.test @@ -13,3 +13,52 @@ insert into t25219 values(1, 1, 1); analyze table t25219; select * from t25219 WHERE (col3 IS NULL OR col1 IS NOT NULL AND col3 <= 6659) AND col3 = 1; +# TestIssue9805 +drop table if exists t1, t2; +create table t1 ( + id bigint primary key, + a bigint not null, + b varchar(100) not null, + c varchar(10) not null, + d bigint as (a % 30) not null, + key (d, b, c) +); +create table t2 ( + id varchar(50) primary key, + a varchar(100) unique, + b datetime, + c varchar(45), + d int not null unique auto_increment +); +## Test when both tables are empty, EXPLAIN ANALYZE for IndexLookUp would not panic. +--disable_result_log +explain analyze select /*+ TIDB_INLJ(t2) */ t1.id, t2.a from t1 join t2 on t1.a = t2.d where t1.b = 't2' and t1.d = 4; +--enable_result_log + +# TestExplainCostTrace +drop table if exists t; +create table t (a int); +insert into t values (1); +set tidb_cost_model_version=2; +explain format='cost_trace' select * from t; +--replace_column 8 9 10 11 +explain analyze format='cost_trace' select * from t; +set tidb_cost_model_version=1; +## cost trace on model ver1 is not supported +explain format='cost_trace' select * from t; +--replace_column 8 9 10 11 +explain analyze format='cost_trace' select * from t; +set tidb_cost_model_version=default; + +# TestExplainAnalyze +drop table if exists t1, t2; +## disable only full group by +set sql_mode='STRICT_TRANS_TABLES'; +create table t1(a int, b int, c int, key idx(a, b)); +create table t2(a int, b int); +insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5); +insert into t2 values (2, 22), (3, 33), (5, 55), (233, 2), (333, 3), (3434, 5); +analyze table t1, t2; +--replace_regex /:[ ]?[.0-9]+[nµms]*/:/ /, scan_detail: {.*}// / tot_proc:.*?, tot_wait:.*?,// /[0-9]+ Bytes/ Bytes/ /[.0-9]+ KB/ KB/ +explain analyze select t1.a, t1.b, sum(t1.c) from t1 join t2 on t1.a = t2.b where t1.a > 1; +set sql_mode=default; From cd1bda17ade60b6f409586c5986723c3440a459e Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 17:53:25 +0800 Subject: [PATCH 10/12] update --- .../physicalplantest/physical_plan.result | 82 ++++++++++++------- .../physicalplantest/physical_plan.test | 49 ++++++++--- 2 files changed, 88 insertions(+), 43 deletions(-) diff --git a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result index c95d563ce7047..5db9c5101fc29 100644 --- a/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result +++ b/tests/integrationtest/r/planner/core/casetest/physicalplantest/physical_plan.result @@ -1032,9 +1032,9 @@ IndexReader 40.00 root index:IndexRangeScan select e from t where e != 'b'; e -c -a +a +c explain format='brief' select e from t where e > 'b'; id estRows task access object operator info IndexReader 10.00 root index:IndexRangeScan @@ -1048,8 +1048,8 @@ IndexReader 20.00 root index:IndexRangeScan └─IndexRangeScan 20.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], keep order:false, stats:pseudo select e from t where e >= 'b'; e -c b +c explain format='brief' select e from t where e < 'b'; id estRows task access object operator info IndexReader 30.00 root index:IndexRangeScan @@ -1057,8 +1057,8 @@ IndexReader 30.00 root index:IndexRangeScan select e from t where e < 'b'; e -a +a explain format='brief' select e from t where e <= 'b'; id estRows task access object operator info IndexReader 40.00 root index:IndexRangeScan @@ -1066,9 +1066,9 @@ IndexReader 40.00 root index:IndexRangeScan select e from t where e <= 'b'; e -b -a +a +b explain format='brief' select e from t where e = 2; id estRows task access object operator info IndexReader 10.00 root index:IndexRangeScan @@ -1083,26 +1083,26 @@ IndexReader 6656.67 root index:IndexRangeScan select e from t where e != 2; e -c -a +a +c explain format='brief' select e from t where e > 2; id estRows task access object operator info IndexReader 3333.33 root index:IndexRangeScan └─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:("b",+inf], keep order:false, stats:pseudo select e from t where e > 2; e -a +a explain format='brief' select e from t where e >= 2; id estRows task access object operator info IndexReader 3333.33 root index:IndexRangeScan └─IndexRangeScan 3333.33 cop[tikv] table:t, index:idx(e) range:["b",+inf], keep order:false, stats:pseudo select e from t where e >= 2; e -b -a +a +b explain format='brief' select e from t where e < 2; id estRows task access object operator info IndexReader 3323.33 root index:IndexRangeScan @@ -1118,17 +1118,17 @@ IndexReader 3323.33 root index:IndexRangeScan select e from t where e <= 2; e -c b +c explain format='brief' select e from t where e > ''; id estRows task access object operator info IndexReader 30.00 root index:IndexRangeScan └─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], ["a","a"], keep order:false, stats:pseudo select e from t where e > ''; e -c -b a +b +c explain format='brief' select e from t where e > 'd'; id estRows task access object operator info TableDual 0.00 root rows:0 @@ -1141,10 +1141,10 @@ IndexReader 3333.33 root index:IndexRangeScan select e from t where e > -1; e -c -b -a +a +b +c explain format='brief' select e from t where e > 5; id estRows task access object operator info IndexReader 3333.33 root index:IndexRangeScan @@ -1165,9 +1165,9 @@ IndexReader 30.00 root index:IndexRangeScan └─IndexRangeScan 30.00 cop[tikv] table:t, index:idx(e) range:["c","c"], ["b","b"], ["a","a"], keep order:false, stats:pseudo select e from t where e != ''; e -c -b a +b +c drop table if exists PK_S_MULTI_31; CREATE TABLE `PK_S_MULTI_31` ( `COL1` tinyint(45) NOT NULL, @@ -1192,12 +1192,14 @@ col2 drop table if exists t1, t2; create table t1(a int, b int as (a+1) virtual); create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a)); +## Make sure row_count(tikv_selection) == row_count(table_reader) and row_count(table_reader) > row_count(tidb_selection) explain format='brief' select * from t1 where a > 1 and b > 1; id estRows task access object operator info Selection 1111.11 root gt(planner__core__casetest__physicalplantest__physical_plan.t1.b, 1) └─TableReader 3333.33 root data:Selection └─Selection 3333.33 cop[tikv] gt(planner__core__casetest__physicalplantest__physical_plan.t1.a, 1) └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +## Make sure row_count(tikv_selection) == row_count(index_lookup) and row_count(index_lookup) > row_count(tidb_selection) explain format='brief' select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1; id estRows task access object operator info Selection 370.37 root gt(planner__core__casetest__physicalplantest__physical_plan.t2.b, 1) @@ -3610,13 +3612,23 @@ show warnings; Level Code Message Warning 1105 disable dynamic pruning due to thash has no global stats set tidb_cost_model_version=DEFAULT; -drop table if exists t, t2; +drop table if exists t, t2, t3; set tidb_cost_model_version=1; CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ; insert into t2 values(1,2,1),(2,1,1),(3,3,1); create table t(a int, j json, index kj((cast(j as signed array)))); insert into t values(1, '[1,2,3]'); -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; -- test sink limit to table side of union index merge case, because of table side selection; +CREATE TABLE `t3` ( +`id` int(11) NOT NULL, +`aid` bigint(20) DEFAULT NULL, +`c1` varchar(255) DEFAULT NULL, +`c2` varchar(255) DEFAULT NULL, +`d` int(11) DEFAULT NULL, +PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, +KEY `aid_c1` (`aid`,`c1`), +KEY `aid_c2` (`aid`,`c2`) +); +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; id estRows task access object operator info Limit 2.00 root offset:0, count:2 └─IndexMerge 0.00 root type: union @@ -3627,7 +3639,7 @@ Limit 2.00 root offset:0, count:2 └─TableRowIDScan 3.99 cop[tikv] table:t2 keep order:false, stats:pseudo show warnings; Level Code Message -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; -- test sink limit to table side of intersection index merge case, because of table side selection; +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; id estRows task access object operator info Limit 0.00 root offset:0, count:2 └─IndexMerge 0.01 root type: intersection @@ -3642,7 +3654,7 @@ select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limi a b c show warnings; Level Code Message -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; -- test sink limit to index side of union index merge case, because of table side is pure table scan; +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; id estRows task access object operator info IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) ├─Limit(Build) 1.00 cop[tikv] offset:0, count:2 @@ -3652,7 +3664,7 @@ IndexMerge 2.00 root type: union, limit embedded(offset:0, count:2) └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t2 keep order:false, stats:pseudo show warnings; Level Code Message -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; -- test sink limit to table side of intersection index merge case, because of intersection case special; +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; id estRows task access object operator info IndexMerge 0.01 root type: intersection, limit embedded(offset:0, count:2) ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t2, index:a(a) range:[1,1], keep order:false, stats:pseudo @@ -3664,7 +3676,7 @@ select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; a b c show warnings; Level Code Message -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; -- index merge union case, sink limit into index side and embed another one inside index merge reader; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; id estRows task access object operator info IndexMerge 0.00 root type: union, limit embedded(offset:0, count:1) ├─Limit(Build) 0.00 cop[tikv] offset:0, count:1 @@ -3672,7 +3684,7 @@ IndexMerge 0.00 root type: union, limit embedded(offset:0, count:1) └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo show warnings; Level Code Message -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; -- index merge intersection case, embedding limit into index merge reader; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; id estRows task access object operator info IndexMerge 0.00 root type: intersection, limit embedded(offset:0, count:1) ├─IndexRangeScan(Build) 0.00 cop[tikv] table:t, index:kj(cast(`j` as signed array)) range:[1,1], keep order:false, stats:pseudo @@ -3681,7 +3693,7 @@ IndexMerge 0.00 root type: intersection, limit embedded(offset:0, count:1) └─TableRowIDScan(Probe) 0.00 cop[tikv] table:t keep order:false, stats:pseudo show warnings; Level Code Message -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─Selection 1.00 root json_overlaps(planner__core__casetest__physicalplantest__physical_plan.t.j, cast("[1, 2, 3]", json BINARY)) @@ -3693,7 +3705,7 @@ Limit 1.00 root offset:0, count:1 show warnings; Level Code Message Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now. -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; -- index merge union case, sink limit to table side, because selection exists on table side; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─IndexMerge 0.00 root type: union @@ -3703,7 +3715,7 @@ Limit 1.00 root offset:0, count:1 └─TableRowIDScan 1.25 cop[tikv] table:t keep order:false, stats:pseudo show warnings; Level Code Message -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; -- index merge intersection case, sink limit to table side because selection exists on table side; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─IndexMerge 0.00 root type: intersection @@ -3715,7 +3727,7 @@ Limit 1.00 root offset:0, count:1 └─TableRowIDScan 1.25 cop[tikv] table:t keep order:false, stats:pseudo show warnings; Level Code Message -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; id estRows task access object operator info Limit 1.00 root offset:0, count:1 └─Selection 1.00 root json_overlaps(planner__core__casetest__physicalplantest__physical_plan.t.j, cast("[1, 2, 3]", json BINARY)) @@ -3729,3 +3741,13 @@ show warnings; Level Code Message Warning 1105 Scalar function 'json_overlaps'(signature: Unspecified, return type: bigint(20)) is not supported to push down to storage layer now. set tidb_cost_model_version=DEFAULT; +explain select /*+ USE_INDEX_MERGE(t3, aid_c1, aid_c2) */ * from t3 where (aid = 1 and c1='aaa') or (aid = 1 and c2='bbb') limit 1; +id estRows task access object operator info +IndexMerge_20 1.00 root type: union, limit embedded(offset:0, count:1) +├─Limit_18(Build) 0.01 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_11 0.01 cop[tikv] table:t3, index:aid_c1(aid, c1) range:[1 "aaa",1 "aaa"], keep order:false, stats:pseudo +├─Limit_19(Build) 0.01 cop[tikv] offset:0, count:1 +│ └─IndexRangeScan_12 0.01 cop[tikv] table:t3, index:aid_c2(aid, c2) range:[1 "bbb",1 "bbb"], keep order:false, stats:pseudo +└─TableRowIDScan_13(Probe) 1.00 cop[tikv] table:t3 keep order:false, stats:pseudo +show warnings; +Level Code Message diff --git a/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test b/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test index 2e21fa27e0656..3e28f72db0e17 100644 --- a/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test +++ b/tests/integrationtest/t/planner/core/casetest/physicalplantest/physical_plan.test @@ -370,7 +370,7 @@ create table t1(a int, b int as (a+1) virtual); create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a)); -- echo ## Make sure row_count(tikv_selection) == row_count(table_reader) and row_count(table_reader) > row_count(tidb_selection) explain format='brief' select * from t1 where a > 1 and b > 1; --- echo Make sure row_count(tikv_selection) == row_count(index_lookup) and row_count(index_lookup) > row_count(tidb_selection) +-- echo ## Make sure row_count(tikv_selection) == row_count(index_lookup) and row_count(index_lookup) > row_count(tidb_selection) explain format='brief' select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1; # TestIssue28316 @@ -937,35 +937,58 @@ show warnings; set tidb_cost_model_version=DEFAULT; # TestIndexMergeSinkLimit -drop table if exists t, t2; +drop table if exists t, t2, t3; set tidb_cost_model_version=1; CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `a` (`a`), KEY `b` (`b`)) ; insert into t2 values(1,2,1),(2,1,1),(3,3,1); create table t(a int, j json, index kj((cast(j as signed array)))); insert into t values(1, '[1,2,3]'); -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; -- test sink limit to table side of union index merge case, because of table side selection; -show warnings; -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; -- test sink limit to table side of intersection index merge case, because of table side selection; +CREATE TABLE `t3` ( + `id` int(11) NOT NULL, + `aid` bigint(20) DEFAULT NULL, + `c1` varchar(255) DEFAULT NULL, + `c2` varchar(255) DEFAULT NULL, + `d` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, + KEY `aid_c1` (`aid`,`c1`), + KEY `aid_c2` (`aid`,`c2`) +); +## test sink limit to table side of union index merge case, because of table side selection +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 and c=1 limit 2; +show warnings; +## test sink limit to table side of intersection index merge case, because of table side selection +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; show warnings; select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 and c=1 limit 2; show warnings; -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; -- test sink limit to index side of union index merge case, because of table side is pure table scan; +## test sink limit to index side of union index merge case, because of table side is pure table scan +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 or b=1 limit 2; show warnings; -explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; -- test sink limit to table side of intersection index merge case, because of intersection case special; +## test sink limit to table side of intersection index merge case, because of intersection case special +explain format = 'brief' select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; show warnings; select /*+ use_index_merge(t2, a, b) */ * from t2 where a=1 and b=1 limit 2; show warnings; -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; -- index merge union case, sink limit into index side and embed another one inside index merge reader; +## index merge union case, sink limit into index side and embed another one inside index merge reader +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j)) limit 1; show warnings; -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; -- index merge intersection case, embedding limit into index merge reader; +## index merge intersection case, embedding limit into index merge reader +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') limit 1; show warnings; -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +## index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') limit 1; show warnings; -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; -- index merge union case, sink limit to table side, because selection exists on table side; +## index merge union case, sink limit to table side, because selection exists on table side +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where (1 member of (j) and a=1 ) limit 1; show warnings; -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; -- index merge intersection case, sink limit to table side because selection exists on table side; +## index merge intersection case, sink limit to table side because selection exists on table side +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_contains(j, '[1, 2, 3]') and a=1 limit 1; show warnings; -explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; -- index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down; +## index merge union case, sink limit above selection above index merge reader, because json_overlaps can't be pushed down +explain format = 'brief' select /*+ use_index(t, kj) */ * from t where json_overlaps(j, '[1, 2, 3]') and a=1 limit 1; show warnings; set tidb_cost_model_version=DEFAULT; +## index merge union and intersection case from issue 48588 +explain select /*+ USE_INDEX_MERGE(t3, aid_c1, aid_c2) */ * from t3 where (aid = 1 and c1='aaa') or (aid = 1 and c2='bbb') limit 1; +show warnings; From c5df82de8b5dd4b197b1609d2fe4a9967bdc6143 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 18:36:52 +0800 Subject: [PATCH 11/12] update test --- tests/integrationtest/t/planner/core/integration.test | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integrationtest/t/planner/core/integration.test b/tests/integrationtest/t/planner/core/integration.test index d8e9d2fcf8f7a..75d985b760db7 100644 --- a/tests/integrationtest/t/planner/core/integration.test +++ b/tests/integrationtest/t/planner/core/integration.test @@ -2244,14 +2244,13 @@ select * from information_schema.statements_summary; # TestIssue38295 # https://github.com/pingcap/tidb/issues/38295. -# WARN: this test cannot be migrated to tests/integrationtest, because the error message of -# `SELECT t0.c1, t0.c2 FROM t0 GROUP BY MOD(t0.c0, DEFAULT(t0.c2));` is unstable. 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); +--replace_regex /#2/#1/ /c2/c1/ -- error 1055 SELECT t0.c1, t0.c2 FROM t0 GROUP BY MOD(t0.c0, DEFAULT(t0.c2)); UPDATE t0 SET c2=1413; From 480bd16158e69dff4c06c2155fb6dc75e6512d6f Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Thu, 16 Nov 2023 18:41:58 +0800 Subject: [PATCH 12/12] update --- .../physicalplantest/testdata/plan_suite_in.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json b/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json index 76e17bcd71c12..a4d6a105b6001 100644 --- a/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json +++ b/pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_in.json @@ -473,15 +473,6 @@ "select /*+ AGG_TO_COP(), HASH_AGG(), HASH_JOIN(t1), USE_INDEX(t1), USE_INDEX(t2) */ sum(t1.a) from ta t1, ta t2 where t1.a = t2.b group by t1.a" ] }, - { - "name": "TestLimitToCopHint", - "cases": [ - "select /*+ LIMIT_TO_COP() */ * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1", - "select * from tn where a = 1 and b > 10 and b < 20 and c > 50 order by d limit 1", - "select /*+ LIMIT_TO_COP() */ a from tn where a div 2 order by a limit 1", - "select /*+ LIMIT_TO_COP() */ a from tn where a > 10 limit 1" - ] - }, { "name": "TestGroupConcatOrderby", "cases": [