|
| 1 | +drop table if exists t; |
| 2 | +CREATE TABLE `t` (`col_tinyint_key_signed` tinyint(4) DEFAULT NULL,`col_year_key_signed` year(4) DEFAULT NULL,KEY `col_tinyint_key_signed` (`col_tinyint_key_signed`),KEY `col_year_key_signed` (`col_year_key_signed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; |
| 3 | +insert into t values(-100,NULL); |
| 4 | +select /*+ inl_merge_join(t1, t2) */ count(*) from t t1 right join t t2 on t1. `col_year_key_signed` = t2. `col_tinyint_key_signed`; |
| 5 | +count(*) |
| 6 | +1 |
| 7 | +drop table if exists t1, t2; |
| 8 | +create table t1(a int, b int, c int, d int, primary key(a,b,c)); |
| 9 | +create table t2(a int, b int, c int, d int, primary key(a,b,c)); |
| 10 | +insert into t1 values(1,1,1,1),(2,2,2,2),(3,3,3,3); |
| 11 | +insert into t2 values(1,1,1,1),(2,2,2,2); |
| 12 | +explain format = 'brief' select /*+ inl_merge_join(t1,t2) */ * from t1 left join t2 on t1.a = t2.a and t1.c = t2.c and t1.b = t2.b order by t1.a desc; |
| 13 | +id estRows task access object operator info |
| 14 | +Sort 12500.00 root executor__index_lookup_merge_join.t1.a:desc |
| 15 | +└─HashJoin 12500.00 root left outer join, left side:TableReader, equal:[eq(executor__index_lookup_merge_join.t1.a, executor__index_lookup_merge_join.t2.a) eq(executor__index_lookup_merge_join.t1.c, executor__index_lookup_merge_join.t2.c) eq(executor__index_lookup_merge_join.t1.b, executor__index_lookup_merge_join.t2.b)] |
| 16 | + ├─TableReader(Build) 10000.00 root data:TableFullScan |
| 17 | + │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo |
| 18 | + └─TableReader(Probe) 10000.00 root data:TableFullScan |
| 19 | + └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo |
| 20 | +select /*+ inl_merge_join(t1,t2) */ * from t1 left join t2 on t1.a = t2.a and t1.c = t2.c and t1.b = t2.b order by t1.a desc; |
| 21 | +a b c d a b c d |
| 22 | +3 3 3 3 NULL NULL NULL NULL |
| 23 | +2 2 2 2 2 2 2 2 |
| 24 | +1 1 1 1 1 1 1 1 |
| 25 | +drop table if exists t1, t2; |
| 26 | +create table t1 (c_int int, primary key(c_int)); |
| 27 | +create table t2 (c_int int, unique key (c_int)) partition by hash (c_int) partitions 4; |
| 28 | +insert into t1 values (1), (2), (3), (4), (5); |
| 29 | +insert into t2 select * from t1; |
| 30 | +begin; |
| 31 | +delete from t1 where c_int = 1; |
| 32 | +select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int; |
| 33 | +c_int c_int |
| 34 | +2 2 |
| 35 | +3 3 |
| 36 | +4 4 |
| 37 | +5 5 |
| 38 | +select /*+ INL_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int; |
| 39 | +c_int c_int |
| 40 | +2 2 |
| 41 | +3 3 |
| 42 | +4 4 |
| 43 | +5 5 |
| 44 | +select /*+ INL_HASH_JOIN(t1,t2) */ * from t1, t2 where t1.c_int = t2.c_int; |
| 45 | +c_int c_int |
| 46 | +2 2 |
| 47 | +3 3 |
| 48 | +4 4 |
| 49 | +5 5 |
| 50 | +commit; |
| 51 | +drop table if exists t1, t2; |
| 52 | +create table t1 (id bigint(20) unsigned, primary key(id)); |
| 53 | +create table t2 (id bigint(20) unsigned); |
| 54 | +insert into t1 values (8738875760185212610); |
| 55 | +insert into t1 values (9814441339970117597); |
| 56 | +insert into t2 values (8738875760185212610); |
| 57 | +insert into t2 values (9814441339970117597); |
| 58 | +select /*+ INL_MERGE_JOIN(t1, t2) */ * from t2 left join t1 on t1.id = t2.id order by t1.id; |
| 59 | +id id |
| 60 | +8738875760185212610 8738875760185212610 |
| 61 | +9814441339970117597 9814441339970117597 |
| 62 | +set @@tidb_opt_advanced_join_hint=0; |
| 63 | +set @@tidb_partition_prune_mode= 'static'; |
| 64 | +drop table if exists t1, t2; |
| 65 | +create table t1 (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue ); |
| 66 | +create table t2 (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue ); |
| 67 | +insert into t1 values (1, 'Alice'); |
| 68 | +insert into t2 values (1, 'Bob'); |
| 69 | +analyze table t1, t2 all columns; |
| 70 | +select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 71 | +c_int c_str c_int c_str |
| 72 | +1 Alice 1 Bob |
| 73 | +explain format = 'brief' select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 74 | +id estRows task access object operator info |
| 75 | +Projection 1.25 root executor__index_lookup_merge_join.t1.c_int, executor__index_lookup_merge_join.t1.c_str, executor__index_lookup_merge_join.t2.c_int, executor__index_lookup_merge_join.t2.c_str |
| 76 | +└─HashJoin 1.25 root inner join, equal:[eq(executor__index_lookup_merge_join.t2.c_int, executor__index_lookup_merge_join.t1.c_int)], other cond:lt(executor__index_lookup_merge_join.t1.c_str, executor__index_lookup_merge_join.t2.c_str) |
| 77 | + ├─TableReader(Build) 1.00 root data:Selection |
| 78 | + │ └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t2.c_str)) |
| 79 | + │ └─TableFullScan 1.00 cop[tikv] table:t2, partition:p0 keep order:false |
| 80 | + └─PartitionUnion(Probe) 9991.00 root |
| 81 | + ├─TableReader 1.00 root data:Selection |
| 82 | + │ └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 83 | + │ └─TableFullScan 1.00 cop[tikv] table:t1, partition:p0 keep order:false |
| 84 | + └─TableReader 9990.00 root data:Selection |
| 85 | + └─Selection 9990.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 86 | + └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo |
| 87 | +show warnings; |
| 88 | +Level Code Message |
| 89 | +Warning 1815 The INDEX MERGE JOIN hint is deprecated for usage, try other hints. |
| 90 | +select /*+ INL_HASH_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 91 | +c_int c_str c_int c_str |
| 92 | +1 Alice 1 Bob |
| 93 | +explain format = 'brief' select /*+ INL_HASH_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 94 | +id estRows task access object operator info |
| 95 | +IndexHashJoin 1.25 root inner join, inner:TableReader, outer key:executor__index_lookup_merge_join.t1.c_int, inner key:executor__index_lookup_merge_join.t2.c_int, equal cond:eq(executor__index_lookup_merge_join.t1.c_int, executor__index_lookup_merge_join.t2.c_int), other cond:lt(executor__index_lookup_merge_join.t1.c_str, executor__index_lookup_merge_join.t2.c_str) |
| 96 | +├─PartitionUnion(Build) 9991.00 root |
| 97 | +│ ├─TableReader 1.00 root data:Selection |
| 98 | +│ │ └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 99 | +│ │ └─TableFullScan 1.00 cop[tikv] table:t1, partition:p0 keep order:false |
| 100 | +│ └─TableReader 9990.00 root data:Selection |
| 101 | +│ └─Selection 9990.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 102 | +│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo |
| 103 | +└─TableReader(Probe) 1.25 root data:Selection |
| 104 | + └─Selection 1.25 cop[tikv] not(isnull(executor__index_lookup_merge_join.t2.c_str)) |
| 105 | + └─TableRangeScan 1.25 cop[tikv] table:t2, partition:p0 range: decided by [executor__index_lookup_merge_join.t1.c_int], keep order:false |
| 106 | +select /*+ INL_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 107 | +c_int c_str c_int c_str |
| 108 | +1 Alice 1 Bob |
| 109 | +explain format = 'brief' select /*+ INL_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 110 | +id estRows task access object operator info |
| 111 | +IndexJoin 1.25 root inner join, inner:TableReader, outer key:executor__index_lookup_merge_join.t1.c_int, inner key:executor__index_lookup_merge_join.t2.c_int, equal cond:eq(executor__index_lookup_merge_join.t1.c_int, executor__index_lookup_merge_join.t2.c_int), other cond:lt(executor__index_lookup_merge_join.t1.c_str, executor__index_lookup_merge_join.t2.c_str) |
| 112 | +├─PartitionUnion(Build) 9991.00 root |
| 113 | +│ ├─TableReader 1.00 root data:Selection |
| 114 | +│ │ └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 115 | +│ │ └─TableFullScan 1.00 cop[tikv] table:t1, partition:p0 keep order:false |
| 116 | +│ └─TableReader 9990.00 root data:Selection |
| 117 | +│ └─Selection 9990.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 118 | +│ └─TableFullScan 10000.00 cop[tikv] table:t1, partition:p1 keep order:false, stats:pseudo |
| 119 | +└─TableReader(Probe) 1.25 root data:Selection |
| 120 | + └─Selection 1.25 cop[tikv] not(isnull(executor__index_lookup_merge_join.t2.c_str)) |
| 121 | + └─TableRangeScan 1.25 cop[tikv] table:t2, partition:p0 range: decided by [executor__index_lookup_merge_join.t1.c_int], keep order:false |
| 122 | +set @@tidb_partition_prune_mode= 'dynamic'; |
| 123 | +drop table if exists t1, t2; |
| 124 | +create table t1 (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue ); |
| 125 | +create table t2 (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue ); |
| 126 | +insert into t1 values (1, 'Alice'); |
| 127 | +insert into t2 values (1, 'Bob'); |
| 128 | +analyze table t1, t2 all columns; |
| 129 | +select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 130 | +c_int c_str c_int c_str |
| 131 | +1 Alice 1 Bob |
| 132 | +explain format = 'brief' select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 133 | +id estRows task access object operator info |
| 134 | +MergeJoin 1.00 root inner join, left key:executor__index_lookup_merge_join.t1.c_int, right key:executor__index_lookup_merge_join.t2.c_int, other cond:lt(executor__index_lookup_merge_join.t1.c_str, executor__index_lookup_merge_join.t2.c_str) |
| 135 | +├─TableReader(Build) 1.00 root partition:p0 data:Selection |
| 136 | +│ └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t2.c_str)) |
| 137 | +│ └─TableFullScan 1.00 cop[tikv] table:t2 keep order:true |
| 138 | +└─TableReader(Probe) 1.00 root partition:all data:Selection |
| 139 | + └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 140 | + └─TableFullScan 1.00 cop[tikv] table:t1 keep order:true |
| 141 | +show warnings; |
| 142 | +Level Code Message |
| 143 | +Warning 1815 The INDEX MERGE JOIN hint is deprecated for usage, try other hints. |
| 144 | +select /*+ INL_HASH_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 145 | +c_int c_str c_int c_str |
| 146 | +1 Alice 1 Bob |
| 147 | +explain format = 'brief' select /*+ INL_HASH_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 148 | +id estRows task access object operator info |
| 149 | +IndexHashJoin 1.00 root inner join, inner:TableReader, outer key:executor__index_lookup_merge_join.t2.c_int, inner key:executor__index_lookup_merge_join.t1.c_int, equal cond:eq(executor__index_lookup_merge_join.t2.c_int, executor__index_lookup_merge_join.t1.c_int), other cond:lt(executor__index_lookup_merge_join.t1.c_str, executor__index_lookup_merge_join.t2.c_str) |
| 150 | +├─TableReader(Build) 1.00 root partition:p0 data:Selection |
| 151 | +│ └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t2.c_str)) |
| 152 | +│ └─TableFullScan 1.00 cop[tikv] table:t2 keep order:false |
| 153 | +└─TableReader(Probe) 1.00 root partition:all data:Selection |
| 154 | + └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 155 | + └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [executor__index_lookup_merge_join.t2.c_int], keep order:false |
| 156 | +select /*+ INL_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 157 | +c_int c_str c_int c_str |
| 158 | +1 Alice 1 Bob |
| 159 | +explain format = 'brief' select /*+ INL_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str; |
| 160 | +id estRows task access object operator info |
| 161 | +IndexJoin 1.00 root inner join, inner:TableReader, outer key:executor__index_lookup_merge_join.t2.c_int, inner key:executor__index_lookup_merge_join.t1.c_int, equal cond:eq(executor__index_lookup_merge_join.t2.c_int, executor__index_lookup_merge_join.t1.c_int), other cond:lt(executor__index_lookup_merge_join.t1.c_str, executor__index_lookup_merge_join.t2.c_str) |
| 162 | +├─TableReader(Build) 1.00 root partition:p0 data:Selection |
| 163 | +│ └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t2.c_str)) |
| 164 | +│ └─TableFullScan 1.00 cop[tikv] table:t2 keep order:false |
| 165 | +└─TableReader(Probe) 1.00 root partition:all data:Selection |
| 166 | + └─Selection 1.00 cop[tikv] not(isnull(executor__index_lookup_merge_join.t1.c_str)) |
| 167 | + └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [executor__index_lookup_merge_join.t2.c_int], keep order:false |
| 168 | +set @@tidb_opt_advanced_join_hint=DEFAULT; |
| 169 | +set @@tidb_partition_prune_mode= DEFAULT; |
| 170 | +drop table if exists t, s; |
| 171 | +create table s(a int, index(a)); |
| 172 | +create table t(a int); |
| 173 | +insert into t values(1); |
| 174 | +select /*+ hash_join(t,s)*/ * from t left join s on t.a=s.a and t.a>1; |
| 175 | +a a |
| 176 | +1 NULL |
| 177 | +select /*+ inl_merge_join(t,s)*/ * from t left join s on t.a=s.a and t.a>1; |
| 178 | +a a |
| 179 | +1 NULL |
| 180 | +drop table if exists t1, t2; |
| 181 | +CREATE TABLE `t1` (`id` bigint(20) NOT NULL AUTO_INCREMENT, `t2id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), KEY `t2id` (`t2id`)); |
| 182 | +INSERT INTO `t1` VALUES (1,NULL); |
| 183 | +CREATE TABLE `t2` (`id` bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)); |
| 184 | +SELECT /*+ INL_MERGE_JOIN(t1,t2) */ 1 from t1 left outer join t2 on t1.t2id=t2.id; |
| 185 | +1 |
| 186 | +1 |
| 187 | +SELECT /*+ HASH_JOIN(t1,t2) */ 1 from t1 left outer join t2 on t1.t2id=t2.id; |
| 188 | +1 |
| 189 | +1 |
| 190 | +drop table if exists x; |
| 191 | +CREATE TABLE `x` ( `a` enum('y','b','1','x','0','null') DEFAULT NULL, KEY `a` (`a`)); |
| 192 | +insert into x values("x"),("x"),("b"),("y"); |
| 193 | +SELECT /*+ merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a; |
| 194 | +a a |
| 195 | +b b |
| 196 | +x x |
| 197 | +x x |
| 198 | +x x |
| 199 | +x x |
| 200 | +y y |
| 201 | +SELECT /*+ inl_merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a; |
| 202 | +a a |
| 203 | +b b |
| 204 | +x x |
| 205 | +x x |
| 206 | +x x |
| 207 | +x x |
| 208 | +y y |
| 209 | +drop table if exists x; |
| 210 | +CREATE TABLE `x` ( `a` set('y','b','1','x','0','null') DEFAULT NULL, KEY `a` (`a`)); |
| 211 | +insert into x values("x"),("x"),("b"),("y"); |
| 212 | +SELECT /*+ merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a; |
| 213 | +a a |
| 214 | +b b |
| 215 | +x x |
| 216 | +x x |
| 217 | +x x |
| 218 | +x x |
| 219 | +y y |
| 220 | +SELECT /*+ inl_merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a; |
| 221 | +a a |
| 222 | +b b |
| 223 | +x x |
| 224 | +x x |
| 225 | +x x |
| 226 | +x x |
| 227 | +y y |
0 commit comments