| 1 |
DROP VIEW IF EXISTS v1,v2; |
| 2 |
DROP TABLE IF EXISTS t1,t2,t3; |
| 3 |
DROP PROCEDURE IF EXISTS p1; |
| 4 |
DROP FUNCTION IF EXISTS f1; |
| 5 |
DROP TRIGGER IF EXISTS trg1; |
| 6 |
DROP TRIGGER IF EXISTS trg2; |
| 7 |
set sql_warnings = 0; |
| 8 |
SET @@session.default_storage_engine = 'MyISAM'; |
| 9 |
SET optimizer_switch='derived_merge=off'; |
| 10 |
create table t1 (a int, |
| 11 |
b int generated always as (-a) virtual, |
| 12 |
c int generated always as (-a) stored, |
| 13 |
index (c)); |
| 14 |
insert into t1 (a) values (2), (1), (1), (3), (NULL); |
| 15 |
create table t2 like t1; |
| 16 |
insert into t2 (a) values (1); |
| 17 |
create table t3 (a int primary key, |
| 18 |
b int generated always as (-a) virtual, |
| 19 |
c int generated always as (-a) stored unique); |
| 20 |
insert into t3 (a) values (2),(1),(3); |
| 21 |
analyze table t1,t2,t3; |
| 22 |
Table Op Msg_type Msg_text |
| 23 |
test.t1 analyze status OK |
| 24 |
test.t2 analyze status OK |
| 25 |
test.t3 analyze status OK |
| 26 |
# select_type=SIMPLE, type=system |
| 27 |
select * from t2; |
| 28 |
a b c |
| 29 |
1 -1 -1 |
| 30 |
explain select * from t2; |
| 31 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 32 |
1 SIMPLE t2 NULL system NULL NULL NULL NULL 1 100.00 NULL |
| 33 |
Warnings: |
| 34 |
Note 1003 /* select#1 */ select '1' AS `a`,'-1' AS `b`,'-1' AS `c` from dual |
| 35 |
select * from t2 where c=-1; |
| 36 |
a b c |
| 37 |
1 -1 -1 |
| 38 |
explain select * from t2 where c=-1; |
| 39 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 40 |
1 SIMPLE t2 NULL system c NULL NULL NULL 1 100.00 NULL |
| 41 |
Warnings: |
| 42 |
Note 1003 /* select#1 */ select '1' AS `a`,'-1' AS `b`,'-1' AS `c` from dual where true |
| 43 |
# select_type=SIMPLE, type=ALL |
| 44 |
select * from t1 where b=-1; |
| 45 |
a b c |
| 46 |
1 -1 -1 |
| 47 |
1 -1 -1 |
| 48 |
explain select * from t1 where b=-1; |
| 49 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 50 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 20.00 Using where |
| 51 |
Warnings: |
| 52 |
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`b` = <cache>(-(1))) |
| 53 |
# select_type=SIMPLE, type=const |
| 54 |
select * from t3 where a=1; |
| 55 |
a b c |
| 56 |
1 -1 -1 |
| 57 |
explain select * from t3 where a=1; |
| 58 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 59 |
1 SIMPLE t3 NULL const PRIMARY PRIMARY 4 const 1 100.00 NULL |
| 60 |
Warnings: |
| 61 |
Note 1003 /* select#1 */ select '1' AS `a`,'-1' AS `b`,'-1' AS `c` from `test`.`t3` where true |
| 62 |
# select_type=SIMPLE, type=range |
| 63 |
select * from t3 where c>=-1; |
| 64 |
a b c |
| 65 |
1 -1 -1 |
| 66 |
explain select * from t3 where c>=-1; |
| 67 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 68 |
1 SIMPLE t3 NULL range c c 5 NULL 2 100.00 Using index condition |
| 69 |
Warnings: |
| 70 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`c` >= <cache>(-(1))) |
| 71 |
# select_type=SIMPLE, type=ref |
| 72 |
select * from t1,t3 where t1.c=t3.c and t3.c=-1; |
| 73 |
a b c a b c |
| 74 |
1 -1 -1 1 -1 -1 |
| 75 |
1 -1 -1 1 -1 -1 |
| 76 |
explain select * from t1,t3 where t1.c=t3.c and t3.c=-1; |
| 77 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 78 |
1 SIMPLE t3 NULL const c c 5 const 1 100.00 NULL |
| 79 |
1 SIMPLE t1 NULL ref c c 5 const 2 100.00 NULL |
| 80 |
Warnings: |
| 81 |
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,'1' AS `a`,'-1' AS `b`,'-1' AS `c` from `test`.`t1` join `test`.`t3` where (`test`.`t1`.`c` = -(1)) |
| 82 |
# select_type=PRIMARY, type=index,ALL |
| 83 |
select * from t1 where b in (select c from t3); |
| 84 |
a b c |
| 85 |
1 -1 -1 |
| 86 |
1 -1 -1 |
| 87 |
2 -2 -2 |
| 88 |
3 -3 -3 |
| 89 |
explain select * from t1 where b in (select c from t3); |
| 90 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 91 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 Using where |
| 92 |
1 SIMPLE t3 NULL eq_ref c c 5 test.t1.b 1 100.00 Using index |
| 93 |
Warnings: |
| 94 |
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t3` join `test`.`t1` where (`test`.`t3`.`c` = `test`.`t1`.`b`) |
| 95 |
# select_type=PRIMARY, type=range,ref |
| 96 |
select * from t1 where c in (select c from t3 where c between -2 and -1); |
| 97 |
a b c |
| 98 |
1 -1 -1 |
| 99 |
1 -1 -1 |
| 100 |
2 -2 -2 |
| 101 |
explain select * from t1 where c in (select c from t3 where c between -2 and -1); |
| 102 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 103 |
1 SIMPLE t3 NULL range c c 5 NULL 1 100.00 Using where; Using index |
| 104 |
1 SIMPLE t1 NULL ref c c 5 test.t3.c 1 100.00 NULL |
| 105 |
Warnings: |
| 106 |
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t3` join `test`.`t1` where ((`test`.`t1`.`c` = `test`.`t3`.`c`) and (`test`.`t3`.`c` between <cache>(-(2)) and <cache>(-(1)))) |
| 107 |
# select_type=UNION, type=system |
| 108 |
# select_type=UNION RESULT, type=<union1,2> |
| 109 |
select * from t1 union select * from t2; |
| 110 |
a b c |
| 111 |
1 -1 -1 |
| 112 |
2 -2 -2 |
| 113 |
3 -3 -3 |
| 114 |
NULL NULL NULL |
| 115 |
explain select * from t1 union select * from t2; |
| 116 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 117 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 5 100.00 NULL |
| 118 |
2 UNION t2 NULL system NULL NULL NULL NULL 1 100.00 NULL |
| 119 |
3 UNION RESULT <union1,2> NULL ALL NULL NULL NULL NULL NULL NULL Using temporary |
| 120 |
Warnings: |
| 121 |
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` union /* select#2 */ select '1' AS `a`,'-1' AS `b`,'-1' AS `c` from dual |
| 122 |
# select_type=DERIVED, type=system |
| 123 |
select * from (select a,b,c from t1) as t11; |
| 124 |
a b c |
| 125 |
1 -1 -1 |
| 126 |
1 -1 -1 |
| 127 |
2 -2 -2 |
| 128 |
3 -3 -3 |
| 129 |
NULL NULL NULL |
| 130 |
explain select * from (select a,b,c from t1) as t11; |
| 131 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 132 |
1 PRIMARY <derived2> NULL ALL NULL NULL NULL NULL 5 100.00 NULL |
| 133 |
2 DERIVED t1 NULL ALL NULL NULL NULL NULL 5 100.00 NULL |
| 134 |
Warnings: |
| 135 |
Note 1003 /* select#1 */ select `t11`.`a` AS `a`,`t11`.`b` AS `b`,`t11`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1`) `t11` |
| 136 |
### |
| 137 |
### Using aggregate functions with/without DISTINCT |
| 138 |
### |
| 139 |
# SELECT COUNT(*) FROM tbl_name |
| 140 |
select count(*) from t1; |
| 141 |
count(*) |
| 142 |
5 |
| 143 |
explain select count(*) from t1; |
| 144 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 145 |
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away |
| 146 |
Warnings: |
| 147 |
Note 1003 /* select#1 */ select count(0) AS `count(*)` from `test`.`t1` |
| 148 |
# SELECT COUNT(DISTINCT <non-gcol>) FROM tbl_name |
| 149 |
select count(distinct a) from t1; |
| 150 |
count(distinct a) |
| 151 |
3 |
| 152 |
explain select count(distinct a) from t1; |
| 153 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 154 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 NULL |
| 155 |
Warnings: |
| 156 |
Note 1003 /* select#1 */ select count(distinct `test`.`t1`.`a`) AS `count(distinct a)` from `test`.`t1` |
| 157 |
# SELECT COUNT(DISTINCT <non-stored gcol>) FROM tbl_name |
| 158 |
select count(distinct b) from t1; |
| 159 |
count(distinct b) |
| 160 |
3 |
| 161 |
explain select count(distinct b) from t1; |
| 162 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 163 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 NULL |
| 164 |
Warnings: |
| 165 |
Note 1003 /* select#1 */ select count(distinct `test`.`t1`.`b`) AS `count(distinct b)` from `test`.`t1` |
| 166 |
# SELECT COUNT(DISTINCT <stored gcol>) FROM tbl_name |
| 167 |
select count(distinct c) from t1; |
| 168 |
count(distinct c) |
| 169 |
3 |
| 170 |
explain select count(distinct c) from t1; |
| 171 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 172 |
1 SIMPLE t1 NULL range c c 5 NULL 6 100.00 Using index for group-by (scanning) |
| 173 |
Warnings: |
| 174 |
Note 1003 /* select#1 */ select count(distinct `test`.`t1`.`c`) AS `count(distinct c)` from `test`.`t1` |
| 175 |
### |
| 176 |
### filesort & range-based utils |
| 177 |
### |
| 178 |
# SELECT * FROM tbl_name WHERE <gcol expr> |
| 179 |
select * from t3 where c >= -2; |
| 180 |
a b c |
| 181 |
1 -1 -1 |
| 182 |
2 -2 -2 |
| 183 |
explain select * from t3 where c >= -2; |
| 184 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 185 |
1 SIMPLE t3 NULL range c c 5 NULL 2 100.00 Using index condition |
| 186 |
Warnings: |
| 187 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`c` >= <cache>(-(2))) |
| 188 |
# SELECT * FROM tbl_name WHERE <non-gcol expr> |
| 189 |
select * from t3 where a between 1 and 2; |
| 190 |
a b c |
| 191 |
1 -1 -1 |
| 192 |
2 -2 -2 |
| 193 |
explain select * from t3 where a between 1 and 2; |
| 194 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 195 |
1 SIMPLE t3 NULL range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition |
| 196 |
Warnings: |
| 197 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`a` between 1 and 2) |
| 198 |
# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> |
| 199 |
select * from t3 where b between -2 and -1; |
| 200 |
a b c |
| 201 |
1 -1 -1 |
| 202 |
2 -2 -2 |
| 203 |
explain select * from t3 where b between -2 and -1; |
| 204 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 205 |
1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 206 |
Warnings: |
| 207 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`b` between <cache>(-(2)) and <cache>(-(1))) |
| 208 |
# SELECT * FROM tbl_name WHERE <indexed gcol expr> |
| 209 |
select * from t3 where c between -2 and -1; |
| 210 |
a b c |
| 211 |
1 -1 -1 |
| 212 |
2 -2 -2 |
| 213 |
explain select * from t3 where c between -2 and -1; |
| 214 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 215 |
1 SIMPLE t3 NULL range c c 5 NULL 1 100.00 Using index condition |
| 216 |
Warnings: |
| 217 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`c` between <cache>(-(2)) and <cache>(-(1))) |
| 218 |
# bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC |
| 219 |
CREATE TABLE t4 ( |
| 220 |
`pk` int(11) NOT NULL , |
| 221 |
`col_int_nokey` int(11) GENERATED ALWAYS AS (pk + col_int_key) STORED, |
| 222 |
`col_int_key` int(11) DEFAULT NULL, |
| 223 |
`col_date_nokey` date DEFAULT NULL, |
| 224 |
`col_datetime_key` datetime DEFAULT NULL, |
| 225 |
PRIMARY KEY (`pk`), |
| 226 |
KEY `col_int_key` (`col_int_key`), |
| 227 |
KEY `col_datetime_key` (`col_datetime_key`) |
| 228 |
); |
| 229 |
Warnings: |
| 230 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 231 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 232 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 233 |
INSERT INTO t4 VALUES |
| 234 |
(1,default,4,'2008-12-05','1900-01-01 00:00:00'); |
| 235 |
SELECT |
| 236 |
SQL_BIG_RESULT |
| 237 |
GRANDPARENT1 . `col_int_nokey` AS g1 |
| 238 |
FROM t4 AS GRANDPARENT1 LEFT JOIN t4 AS GRANDPARENT2 ON ( GRANDPARENT2 . |
| 239 |
`col_datetime_key` <= GRANDPARENT1 . `col_date_nokey` ) |
| 240 |
GROUP BY GRANDPARENT1 . `pk`; |
| 241 |
g1 |
| 242 |
5 |
| 243 |
DROP TABLE t4; |
| 244 |
# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <indexed gcol> |
| 245 |
select * from t3 where a between 1 and 2 order by c; |
| 246 |
a b c |
| 247 |
2 -2 -2 |
| 248 |
1 -1 -1 |
| 249 |
explain select * from t3 where a between 1 and 2 order by c; |
| 250 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 251 |
1 SIMPLE t3 NULL range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition; Using filesort |
| 252 |
Warnings: |
| 253 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`a` between 1 and 2) order by `test`.`t3`.`c` |
| 254 |
# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-gcol> |
| 255 |
select * from t3 where b between -2 and -1 order by a; |
| 256 |
a b c |
| 257 |
1 -1 -1 |
| 258 |
2 -2 -2 |
| 259 |
explain select * from t3 where b between -2 and -1 order by a; |
| 260 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 261 |
1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using filesort |
| 262 |
Warnings: |
| 263 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`b` between <cache>(-(2)) and <cache>(-(1))) order by `test`.`t3`.`a` |
| 264 |
# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-gcol> |
| 265 |
select * from t3 where c between -2 and -1 order by a; |
| 266 |
a b c |
| 267 |
1 -1 -1 |
| 268 |
2 -2 -2 |
| 269 |
explain select * from t3 where c between -2 and -1 order by a; |
| 270 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 271 |
1 SIMPLE t3 NULL range c c 5 NULL 1 100.00 Using index condition; Using filesort |
| 272 |
Warnings: |
| 273 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`c` between <cache>(-(2)) and <cache>(-(1))) order by `test`.`t3`.`a` |
| 274 |
# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-indexed gcol> |
| 275 |
select * from t3 where b between -2 and -1 order by b; |
| 276 |
a b c |
| 277 |
2 -2 -2 |
| 278 |
1 -1 -1 |
| 279 |
explain select * from t3 where b between -2 and -1 order by b; |
| 280 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 281 |
1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using filesort |
| 282 |
Warnings: |
| 283 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`b` between <cache>(-(2)) and <cache>(-(1))) order by `test`.`t3`.`b` |
| 284 |
# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-indexed gcol> |
| 285 |
select * from t3 where c between -2 and -1 order by b; |
| 286 |
a b c |
| 287 |
2 -2 -2 |
| 288 |
1 -1 -1 |
| 289 |
explain select * from t3 where c between -2 and -1 order by b; |
| 290 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 291 |
1 SIMPLE t3 NULL range c c 5 NULL 1 100.00 Using index condition; Using filesort |
| 292 |
Warnings: |
| 293 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`c` between <cache>(-(2)) and <cache>(-(1))) order by `test`.`t3`.`b` |
| 294 |
# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <indexed gcol> |
| 295 |
select * from t3 where b between -2 and -1 order by c; |
| 296 |
a b c |
| 297 |
2 -2 -2 |
| 298 |
1 -1 -1 |
| 299 |
explain select * from t3 where b between -2 and -1 order by c; |
| 300 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 301 |
1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using filesort |
| 302 |
Warnings: |
| 303 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`b` between <cache>(-(2)) and <cache>(-(1))) order by `test`.`t3`.`c` |
| 304 |
# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <indexed gcol> |
| 305 |
select * from t3 where c between -2 and -1 order by c; |
| 306 |
a b c |
| 307 |
2 -2 -2 |
| 308 |
1 -1 -1 |
| 309 |
explain select * from t3 where c between -2 and -1 order by c; |
| 310 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 311 |
1 SIMPLE t3 NULL range c c 5 NULL 1 100.00 Using index condition |
| 312 |
Warnings: |
| 313 |
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where (`test`.`t3`.`c` between <cache>(-(2)) and <cache>(-(1))) order by `test`.`t3`.`c` |
| 314 |
# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol> |
| 315 |
select sum(b) from t1 group by b; |
| 316 |
sum(b) |
| 317 |
-2 |
| 318 |
-2 |
| 319 |
-3 |
| 320 |
NULL |
| 321 |
explain select sum(b) from t1 group by b; |
| 322 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 323 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 Using temporary |
| 324 |
Warnings: |
| 325 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`b`) AS `sum(b)` from `test`.`t1` group by `test`.`t1`.`b` |
| 326 |
# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <indexed gcol> |
| 327 |
select sum(c) from t1 group by c; |
| 328 |
sum(c) |
| 329 |
NULL |
| 330 |
-3 |
| 331 |
-2 |
| 332 |
-2 |
| 333 |
explain select sum(c) from t1 group by c; |
| 334 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 335 |
1 SIMPLE t1 NULL index c c 5 NULL 5 100.00 Using index |
| 336 |
Warnings: |
| 337 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`c`) AS `sum(c)` from `test`.`t1` group by `test`.`t1`.`c` |
| 338 |
# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <indexed gcol> |
| 339 |
select sum(b) from t1 group by c; |
| 340 |
sum(b) |
| 341 |
NULL |
| 342 |
-3 |
| 343 |
-2 |
| 344 |
-2 |
| 345 |
explain select sum(b) from t1 group by c; |
| 346 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 347 |
1 SIMPLE t1 NULL index c c 5 NULL 5 100.00 NULL |
| 348 |
Warnings: |
| 349 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`b`) AS `sum(b)` from `test`.`t1` group by `test`.`t1`.`c` |
| 350 |
# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol> |
| 351 |
select sum(c) from t1 group by b; |
| 352 |
sum(c) |
| 353 |
-2 |
| 354 |
-2 |
| 355 |
-3 |
| 356 |
NULL |
| 357 |
explain select sum(c) from t1 group by b; |
| 358 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 359 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 Using temporary |
| 360 |
Warnings: |
| 361 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`c`) AS `sum(c)` from `test`.`t1` group by `test`.`t1`.`b` |
| 362 |
drop table t1; |
| 363 |
# |
| 364 |
# Bug#20241655: WL411:FAILING ASSERTION ASSERTION |
| 365 |
# |
| 366 |
CREATE TABLE BB ( |
| 367 |
col_time_key time NOT NULL, |
| 368 |
col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL, |
| 369 |
col_datetime_key datetime NOT NULL); |
| 370 |
INSERT INTO BB VALUES('23:28:02', default, '2005-03-15 22:48:25'); |
| 371 |
CREATE TABLE CC ( |
| 372 |
col_time_key time NOT NULL, |
| 373 |
col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL, |
| 374 |
col_datetime_key datetime NOT NULL |
| 375 |
); |
| 376 |
INSERT INTO CC VALUES('16:22:51', default, '1900-01-01 00:00:00'); |
| 377 |
SELECT 1 AS g1 FROM BB AS gp1 LEFT JOIN BB AS gp2 USING ( col_time_nokey); |
| 378 |
g1 |
| 379 |
1 |
| 380 |
DROP TABLE BB, CC; |
| 381 |
# |
| 382 |
# Bug#20328786: WL411:VALGRIND WARNINGS OF CONDITIONAL |
| 383 |
# JUMP WHILE SELECTING FROM VIEW |
| 384 |
# |
| 385 |
CREATE TABLE A ( |
| 386 |
pk INTEGER AUTO_INCREMENT, |
| 387 |
col_int_nokey INTEGER, |
| 388 |
col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED, |
| 389 |
PRIMARY KEY (pk) |
| 390 |
); |
| 391 |
CREATE TABLE C ( |
| 392 |
pk INTEGER AUTO_INCREMENT, |
| 393 |
col_int_nokey INTEGER, |
| 394 |
col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED, |
| 395 |
col_varchar_nokey VARCHAR(1), |
| 396 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 397 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED, |
| 398 |
PRIMARY KEY (pk), |
| 399 |
KEY (col_int_key), |
| 400 |
KEY (col_varchar_key, col_int_key) |
| 401 |
); |
| 402 |
INSERT INTO C ( |
| 403 |
col_int_nokey, |
| 404 |
col_varchar_nokey |
| 405 |
) VALUES (4, 'v'),(62, 'v'),(7, 'c'),(1, NULL),(0, 'x'),(7, 'i'),(7, 'e'),(1, 'p'),(7, 's'),(1, 'j'),(5, 'z'),(2, 'c'),(0, 'a'),(1, 'q'),(8, 'y'),(1, NULL),(1, 'r'),(9, 'v'),(1, NULL),(5, 'r'); |
| 406 |
CREATE OR REPLACE ALGORITHM=MERGE VIEW V1 AS SELECT alias1. |
| 407 |
col_varchar_key AS field1 , alias1.pk AS field2, alias2. |
| 408 |
col_int_nokey AS field3 FROM C AS alias1 LEFT JOIN A AS alias2 ON |
| 409 |
alias1.pk = alias2.col_int_key WHERE alias1.pk > 8 AND alias1 |
| 410 |
.pk < ( 9 + 2 ) AND alias1.col_int_key <> 1 OR alias1.col_int_key |
| 411 |
> 0 AND alias1.col_int_key <= ( 3 + 2 ) ORDER BY field1, field2, field3 |
| 412 |
LIMIT 100 OFFSET 6; |
| 413 |
Warnings: |
| 414 |
Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm) |
| 415 |
SELECT * FROM V1; |
| 416 |
field1 field2 field3 |
| 417 |
qq 14 NULL |
| 418 |
rr 17 NULL |
| 419 |
ss 9 NULL |
| 420 |
xx 5 NULL |
| 421 |
DROP VIEW V1; |
| 422 |
DROP TABLE A,C; |
| 423 |
# |
| 424 |
# Bug#20406510: WL411:VALGRIND WARNINGS WITH |
| 425 |
# COUNT DISTINCT QUERY ON VIRTUAL GC VARCHAR COLUMN |
| 426 |
# |
| 427 |
CREATE TABLE A ( |
| 428 |
pk INTEGER AUTO_INCREMENT, |
| 429 |
col_time_key TIME NOT NULL, |
| 430 |
col_datetime_key DATETIME NOT NULL, |
| 431 |
PRIMARY KEY (pk), |
| 432 |
KEY (col_time_key), |
| 433 |
KEY (col_datetime_key) |
| 434 |
); |
| 435 |
CREATE TABLE C ( |
| 436 |
pk INTEGER AUTO_INCREMENT, |
| 437 |
col_int_key INTEGER NOT NULL, |
| 438 |
col_varchar_key VARCHAR(1) NOT NULL, |
| 439 |
col_varchar_nokey VARCHAR(2) GENERATED ALWAYS AS |
| 440 |
(CONCAT(col_varchar_key, col_varchar_key)), |
| 441 |
PRIMARY KEY (pk), |
| 442 |
KEY (col_int_key), |
| 443 |
KEY (col_varchar_key, col_int_key) |
| 444 |
); |
| 445 |
INSERT INTO C (col_int_key,col_varchar_key) VALUES (0, 'j'),(8, 'v'),(1, 'c'),(8, 'm'),(9, 'd'); |
| 446 |
SELECT MIN( alias2 . col_int_key ) AS field1, |
| 447 |
COUNT( DISTINCT alias2 . col_varchar_nokey ) AS field2 |
| 448 |
FROM ( A AS alias1 , C AS alias2 ) |
| 449 |
ORDER BY alias1.col_time_key, alias1.col_datetime_key, alias1.pk ASC; |
| 450 |
field1 field2 |
| 451 |
NULL 0 |
| 452 |
DROP TABLE A,C; |
| 453 |
# |
| 454 |
# Bug#20566325: WL8149: INNODB: FAILING ASSERTION: |
| 455 |
# COL_NR < TABLE->N_DEF |
| 456 |
# |
| 457 |
CREATE TABLE A ( |
| 458 |
pk INTEGER AUTO_INCREMENT, |
| 459 |
col_varchar_nokey VARCHAR(1) NOT NULL, |
| 460 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 461 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 462 |
PRIMARY KEY (pk) |
| 463 |
); |
| 464 |
INSERT /*! IGNORE */ INTO A (col_varchar_nokey) VALUES ('k'); |
| 465 |
CREATE TABLE CC ( |
| 466 |
pk INTEGER AUTO_INCREMENT, |
| 467 |
col_datetime_nokey DATETIME /*! NULL */, |
| 468 |
col_time_nokey TIME /*! NULL */, |
| 469 |
col_time_key TIME GENERATED ALWAYS AS |
| 470 |
(ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 471 |
col_varchar_nokey VARCHAR(1) /*! NULL */, |
| 472 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 473 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 474 |
PRIMARY KEY (pk)); |
| 475 |
INSERT INTO CC (col_time_nokey,col_datetime_nokey,col_varchar_nokey) VALUES |
| 476 |
('13:06:13.033877','1900-01-01 00:00:00', 'p'), |
| 477 |
(NULL, '2007-05-25 11:58:54.015689', 'g'); |
| 478 |
SELECT |
| 479 |
table1.col_time_key AS field1, |
| 480 |
'z' AS field2 |
| 481 |
FROM |
| 482 |
(CC AS table1 LEFT OUTER JOIN (A AS table2 STRAIGHT_JOIN CC AS table3 ON |
| 483 |
(table3.col_varchar_key = table2.col_varchar_nokey)) ON |
| 484 |
(table3.col_varchar_key = table2.col_varchar_nokey)) |
| 485 |
WHERE |
| 486 |
table2.pk != 6 |
| 487 |
AND table1.col_varchar_key IN ('l', 's' , 'b' ) |
| 488 |
AND table3.col_varchar_key != table1.col_varchar_key |
| 489 |
ORDER BY table1.col_varchar_key , field1 , field2; |
| 490 |
field1 field2 |
| 491 |
DROP TABLE A,CC; |
| 492 |
CREATE TABLE cc ( |
| 493 |
pk int(11) NOT NULL AUTO_INCREMENT, |
| 494 |
col_int_nokey int(11) NOT NULL, |
| 495 |
col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) STORED, |
| 496 |
col_date_nokey date NOT NULL, |
| 497 |
col_date_key date GENERATED ALWAYS AS (col_date_nokey) STORED, |
| 498 |
col_datetime_nokey datetime NOT NULL, |
| 499 |
col_time_nokey time NOT NULL, |
| 500 |
col_datetime_key datetime GENERATED ALWAYS AS (col_datetime_nokey)STORED, |
| 501 |
col_time_key time GENERATED ALWAYS AS (col_time_nokey) STORED, |
| 502 |
col_varchar_nokey varchar(1) NOT NULL, |
| 503 |
col_varchar_key varchar(1) GENERATED ALWAYS AS (col_varchar_nokey)STORED, |
| 504 |
PRIMARY KEY (pk), |
| 505 |
KEY gc_idx1 (col_int_key), |
| 506 |
KEY gc_idx2 (col_varchar_key), |
| 507 |
KEY gc_idx3 (col_date_key), |
| 508 |
KEY gc_idx4 (col_time_key), |
| 509 |
KEY gc_idx5 (col_datetime_key), |
| 510 |
KEY gc_idx6 (col_varchar_key,col_int_key), |
| 511 |
KEY gc_idx7 (col_date_key,col_datetime_key,col_time_key), |
| 512 |
KEY gc_idx8(col_int_key,col_varchar_key,col_date_key,col_time_key, |
| 513 |
col_datetime_key) |
| 514 |
); |
| 515 |
Warnings: |
| 516 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 517 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 518 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 519 |
INSERT INTO cc ( |
| 520 |
col_int_nokey, |
| 521 |
col_date_nokey, |
| 522 |
col_time_nokey, |
| 523 |
col_datetime_nokey, |
| 524 |
col_varchar_nokey |
| 525 |
) VALUES (1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'), |
| 526 |
(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'), |
| 527 |
(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'), |
| 528 |
(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'), |
| 529 |
(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'), |
| 530 |
(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't'); |
| 531 |
SET @save_old_sql_mode= @@sql_mode; |
| 532 |
SET sql_mode=""; |
| 533 |
SELECT DISTINCT alias1.col_varchar_key AS field1 |
| 534 |
FROM ( cc AS alias1 STRAIGHT_JOIN |
| 535 |
(( cc AS alias2 STRAIGHT_JOIN cc AS alias3 ON |
| 536 |
(alias3.col_varchar_key > alias2.col_varchar_key ) ) ) ON |
| 537 |
(( alias3 .pk >= alias2.col_int_nokey ) AND |
| 538 |
(alias3 .pk >= alias2.col_int_nokey ) )) |
| 539 |
WHERE alias1.col_varchar_key <= 'v' |
| 540 |
GROUP BY field1 HAVING field1 = 91 |
| 541 |
ORDER BY field1, alias1.col_date_key, field1 ASC, field1 DESC, |
| 542 |
alias1.col_time_key ASC, field1; |
| 543 |
field1 |
| 544 |
DROP TABLE cc; |
| 545 |
SET sql_mode=@save_old_sql_mode; |
| 546 |
# |
| 547 |
# Bug#20797941: WL8149:ASSERTION !TABLE || |
| 548 |
# (!TABLE->READ_SET || BITMAP_IS_SET(TABLE->READ_SET |
| 549 |
# |
| 550 |
CREATE TABLE t(a int, b int as(a+1)); |
| 551 |
INSERT INTO t(a) values(1),(2); |
| 552 |
SELECT * FROM t ORDER BY b; |
| 553 |
a b |
| 554 |
1 2 |
| 555 |
2 3 |
| 556 |
DROP TABLE t; |
| 557 |
DROP TABLE t2, t3; |
| 558 |
# |
| 559 |
# Bug#21317507:GC: STORED COLUMN REJECTED, BUT VIRTUAL IS ACCEPTED |
| 560 |
# |
| 561 |
CREATE TABLE t1(a INT); |
| 562 |
INSERT INTO t1 VALUES(2147483647); |
| 563 |
ALTER TABLE t1 ADD INDEX idx(a), WITH VALIDATION; |
| 564 |
ERROR HY000: Incorrect usage of ALTER and WITH VALIDATION |
| 565 |
Should fail and column shouldn't be added |
| 566 |
ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL; |
| 567 |
ERROR 22003: Out of range value for column 'b' at row 1 |
| 568 |
ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL, WITH VALIDATION; |
| 569 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 570 |
ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION; |
| 571 |
ERROR 22003: Out of range value for column 'd' at row 1 |
| 572 |
ALTER TABLE t1 ADD COLUMN c INT AS(a) VIRTUAL; |
| 573 |
ALTER TABLE t1 CHANGE c c SMALLINT AS(a) VIRTUAL, WITH VALIDATION; |
| 574 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 575 |
ALTER TABLE t1 CHANGE c c SMALLINT AS(a) VIRTUAL, WITHOUT VALIDATION; |
| 576 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 577 |
ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL, WITH VALIDATION; |
| 578 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 579 |
ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL, WITHOUT VALIDATION; |
| 580 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 581 |
SELECT * FROM t1; |
| 582 |
a c |
| 583 |
2147483647 2147483647 |
| 584 |
DROP TABLE t1; |
| 585 |
CREATE TABLE t1(a INT); |
| 586 |
INSERT INTO t1 VALUES(2147483647); |
| 587 |
ALTER TABLE t1 ADD COLUMN h INT AS (a) VIRTUAL, WITHOUT VALIDATION; |
| 588 |
ALTER TABLE t1 CHANGE h i INT AS (a) VIRTUAL, WITH VALIDATION, |
| 589 |
ALGORITHM=INPLACE; |
| 590 |
Got one of the listed errors |
| 591 |
ALTER TABLE t1 CHANGE h i INT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 592 |
ALGORITHM=INPLACE; |
| 593 |
ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL, WITH VALIDATION, |
| 594 |
ALGORITHM=INPLACE, LOCK=NONE; |
| 595 |
Got one of the listed errors |
| 596 |
ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL, WITH VALIDATION, |
| 597 |
ALGORITHM=INPLACE, LOCK=SHARED; |
| 598 |
Got one of the listed errors |
| 599 |
ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL, WITH VALIDATION, |
| 600 |
ALGORITHM=INPLACE, LOCK=EXCLUSIVE; |
| 601 |
Got one of the listed errors |
| 602 |
Shouldn't fail on Innodb |
| 603 |
ALTER TABLE t1 ADD COLUMN e SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 604 |
ALGORITHM=INPLACE, LOCK=NONE; |
| 605 |
ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. |
| 606 |
Shouldn't fail on Innodb |
| 607 |
ALTER TABLE t1 ADD COLUMN f SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 608 |
ALGORITHM=INPLACE, LOCK=SHARED; |
| 609 |
ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. |
| 610 |
Shouldn't fail on Innodb |
| 611 |
ALTER TABLE t1 ADD COLUMN g SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 612 |
ALGORITHM=INPLACE, LOCK=EXCLUSIVE; |
| 613 |
ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY. |
| 614 |
DROP TABLE t1; |
| 615 |
# |
| 616 |
# Bug#21980430 GCOLS: CRASHING |
| 617 |
# |
| 618 |
CREATE TABLE t ( |
| 619 |
a INT, |
| 620 |
b BLOB, |
| 621 |
c BLOB GENERATED ALWAYS AS (a+b) VIRTUAL, |
| 622 |
UNIQUE KEY i0008 (a) |
| 623 |
); |
| 624 |
INSERT INTO t(a,b) VALUES(1,'cccc'); |
| 625 |
EXPLAIN SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c |
| 626 |
WHERE b.b>c.a; |
| 627 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 628 |
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables |
| 629 |
Warnings: |
| 630 |
Note 1003 /* select#1 */ select /*+ BKA(@`select#1`) */ 1 AS `c` from dual where (('cccc' > '1') and ('1' > '1')) |
| 631 |
SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c |
| 632 |
WHERE b.b>c.a; |
| 633 |
c |
| 634 |
DROP TABLE t; |
| 635 |
set @optimizer_switch_save = @@optimizer_switch; |
| 636 |
set optimizer_switch='mrr_cost_based=off'; |
| 637 |
set @read_rnd_buffer_size_save= @@read_rnd_buffer_size; |
| 638 |
set read_rnd_buffer_size=32; |
| 639 |
CREATE TABLE t0 ( |
| 640 |
i1 INTEGER NOT NULL |
| 641 |
); |
| 642 |
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); |
| 643 |
CREATE TABLE t1 ( |
| 644 |
pk INTEGER NOT NULL, |
| 645 |
i1 INTEGER NOT NULL, |
| 646 |
i2 INTEGER NOT NULL, |
| 647 |
v1 INTEGER GENERATED ALWAYS AS (i2 + 1) VIRTUAL, |
| 648 |
v2 INTEGER GENERATED ALWAYS AS (i1 / (i1 - i2 + 57)) VIRTUAL, |
| 649 |
PRIMARY KEY (pk), |
| 650 |
INDEX idx(i1) |
| 651 |
); |
| 652 |
INSERT INTO t1 (pk, i1, i2) |
| 653 |
SELECT a0.i1 + a1.i1*10 + a2.i1*100, |
| 654 |
a0.i1 + a1.i1*10, |
| 655 |
a0.i1 + a1.i1*10 |
| 656 |
FROM t0 AS a0, t0 AS a1, t0 AS a2; |
| 657 |
EXPLAIN SELECT * FROM t1 |
| 658 |
WHERE i1 > 41 AND i1 <= 43; |
| 659 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 660 |
1 SIMPLE t1 NULL range idx idx 4 NULL 19 100.00 Using index condition; Using MRR |
| 661 |
Warnings: |
| 662 |
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i1` AS `i1`,`test`.`t1`.`i2` AS `i2`,`test`.`t1`.`v1` AS `v1`,`test`.`t1`.`v2` AS `v2` from `test`.`t1` where ((`test`.`t1`.`i1` > 41) and (`test`.`t1`.`i1` <= 43)) |
| 663 |
SELECT * FROM t1 |
| 664 |
WHERE i1 > 41 AND i1 <= 43; |
| 665 |
pk i1 i2 v1 v2 |
| 666 |
142 42 42 43 1 |
| 667 |
143 43 43 44 1 |
| 668 |
242 42 42 43 1 |
| 669 |
243 43 43 44 1 |
| 670 |
342 42 42 43 1 |
| 671 |
343 43 43 44 1 |
| 672 |
42 42 42 43 1 |
| 673 |
43 43 43 44 1 |
| 674 |
442 42 42 43 1 |
| 675 |
443 43 43 44 1 |
| 676 |
542 42 42 43 1 |
| 677 |
543 43 43 44 1 |
| 678 |
642 42 42 43 1 |
| 679 |
643 43 43 44 1 |
| 680 |
742 42 42 43 1 |
| 681 |
743 43 43 44 1 |
| 682 |
842 42 42 43 1 |
| 683 |
843 43 43 44 1 |
| 684 |
942 42 42 43 1 |
| 685 |
943 43 43 44 1 |
| 686 |
EXPLAIN SELECT * FROM t1 |
| 687 |
WHERE v1 > 41 AND v1 <= 43; |
| 688 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 689 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1000 11.11 Using where |
| 690 |
Warnings: |
| 691 |
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i1` AS `i1`,`test`.`t1`.`i2` AS `i2`,`test`.`t1`.`v1` AS `v1`,`test`.`t1`.`v2` AS `v2` from `test`.`t1` where ((`test`.`t1`.`v1` > 41) and (`test`.`t1`.`v1` <= 43)) |
| 692 |
SELECT * FROM t1 |
| 693 |
WHERE v1 > 41 AND v1 <= 43; |
| 694 |
pk i1 i2 v1 v2 |
| 695 |
141 41 41 42 1 |
| 696 |
142 42 42 43 1 |
| 697 |
241 41 41 42 1 |
| 698 |
242 42 42 43 1 |
| 699 |
341 41 41 42 1 |
| 700 |
342 42 42 43 1 |
| 701 |
41 41 41 42 1 |
| 702 |
42 42 42 43 1 |
| 703 |
441 41 41 42 1 |
| 704 |
442 42 42 43 1 |
| 705 |
541 41 41 42 1 |
| 706 |
542 42 42 43 1 |
| 707 |
641 41 41 42 1 |
| 708 |
642 42 42 43 1 |
| 709 |
741 41 41 42 1 |
| 710 |
742 42 42 43 1 |
| 711 |
841 41 41 42 1 |
| 712 |
842 42 42 43 1 |
| 713 |
941 41 41 42 1 |
| 714 |
942 42 42 43 1 |
| 715 |
DROP TABLE t0, t1; |
| 716 |
set optimizer_switch= @optimizer_switch_save; |
| 717 |
set @@read_rnd_buffer_size= @read_rnd_buffer_size_save; |
| 718 |
# |
| 719 |
# Bug#21872184 CONDITIONAL JUMP AT JOIN_CACHE::WRITE_RECORD_DATA IN |
| 720 |
# SQL_JOIN_BUFFER.CC |
| 721 |
# |
| 722 |
# |
| 723 |
# Test 1: Dynamic range scan with one covering index |
| 724 |
# |
| 725 |
CREATE TABLE t1 ( |
| 726 |
i1 INTEGER NOT NULL, |
| 727 |
c1 VARCHAR(1) NOT NULL |
| 728 |
); |
| 729 |
INSERT INTO t1 |
| 730 |
VALUES (10, 'c'), (10, 'i'), (2, 't'), (4, 'g'); |
| 731 |
CREATE TABLE t2 ( |
| 732 |
i1 INTEGER NOT NULL, |
| 733 |
c1 VARCHAR(1) NOT NULL |
| 734 |
); |
| 735 |
INSERT INTO t2 |
| 736 |
VALUES (2, 'k'), (9, 'k'), (7, 'o'), (5, 'n'), (7, 'e'); |
| 737 |
CREATE TABLE t3 ( |
| 738 |
pk INTEGER NOT NULL, |
| 739 |
i1 INTEGER, |
| 740 |
i2_key INTEGER GENERATED ALWAYS AS (i1 + i1) VIRTUAL NOT NULL, |
| 741 |
PRIMARY KEY (pk) |
| 742 |
); |
| 743 |
INSERT INTO t3 (pk, i1) |
| 744 |
VALUES (1, 1), (2, 48), (3, 228), (4, 3), (5, 5), |
| 745 |
(6, 39), (7, 6), (8, 8), (9, 3); |
| 746 |
CREATE TABLE t4 ( |
| 747 |
i1 INTEGER NOT NULL, |
| 748 |
c1 VARCHAR(1) NOT NULL |
| 749 |
); |
| 750 |
INSERT INTO t4 |
| 751 |
VALUES (1, 'j'), (2, 'c'), (0, 'a'); |
| 752 |
ANALYZE TABLE t1, t2, t3, t4; |
| 753 |
Table Op Msg_type Msg_text |
| 754 |
test.t1 analyze status OK |
| 755 |
test.t2 analyze status OK |
| 756 |
test.t3 analyze status OK |
| 757 |
test.t4 analyze status OK |
| 758 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 759 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 760 |
WHERE ( t3.pk IN |
| 761 |
( |
| 762 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 763 |
FROM t4 |
| 764 |
WHERE t4.c1 < 'o' |
| 765 |
) |
| 766 |
) |
| 767 |
AND t1.i1 <= t3.i2_key; |
| 768 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 769 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 770 |
1 PRIMARY t3 NULL ALL NULL NULL NULL NULL 9 33.33 Using where; Using join buffer (hash join) |
| 771 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 772 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 773 |
Warnings: |
| 774 |
Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq1`) */ `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`i1` AS `i1` from `test`.`t1` straight_join `test`.`t3` straight_join `test`.`t2` where (<in_optimizer>(`test`.`t3`.`pk`,`test`.`t3`.`pk` in ( <materialize> (/* select#2 */ select /*+ QB_NAME(`subq1`) */ `test`.`t4`.`i1` from `test`.`t4` where (`test`.`t4`.`c1` < 'o') ), <primary_index_lookup>(`test`.`t3`.`pk` in <temporary table> on <auto_distinct_key> where ((`test`.`t3`.`pk` = `<materialized_subquery>`.`i1`))))) and (`test`.`t1`.`i1` <= `test`.`t3`.`i2_key`)) |
| 775 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 776 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 777 |
WHERE ( t3.pk IN |
| 778 |
( |
| 779 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 780 |
FROM t4 |
| 781 |
WHERE t4.c1 < 'o' |
| 782 |
) |
| 783 |
) |
| 784 |
AND t1.i1 <= t3.i2_key; |
| 785 |
c1 i1 |
| 786 |
c 2 |
| 787 |
c 5 |
| 788 |
c 7 |
| 789 |
c 7 |
| 790 |
c 9 |
| 791 |
g 2 |
| 792 |
g 5 |
| 793 |
g 7 |
| 794 |
g 7 |
| 795 |
g 9 |
| 796 |
i 2 |
| 797 |
i 5 |
| 798 |
i 7 |
| 799 |
i 7 |
| 800 |
i 9 |
| 801 |
t 2 |
| 802 |
t 2 |
| 803 |
t 5 |
| 804 |
t 5 |
| 805 |
t 7 |
| 806 |
t 7 |
| 807 |
t 7 |
| 808 |
t 7 |
| 809 |
t 9 |
| 810 |
t 9 |
| 811 |
# |
| 812 |
# Test 2: Two alternative covering indexes for the range scan |
| 813 |
# |
| 814 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 815 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 816 |
WHERE ( t3.pk IN |
| 817 |
( |
| 818 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 819 |
FROM t4 |
| 820 |
WHERE t4.c1 < 'o' |
| 821 |
) |
| 822 |
) |
| 823 |
AND t1.i1 <= t3.i2_key; |
| 824 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 825 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 826 |
1 PRIMARY t3 NULL ALL NULL NULL NULL NULL 9 33.33 Using where; Using join buffer (hash join) |
| 827 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 828 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 829 |
Warnings: |
| 830 |
Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq1`) */ `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`i1` AS `i1` from `test`.`t1` straight_join `test`.`t3` straight_join `test`.`t2` where (<in_optimizer>(`test`.`t3`.`pk`,`test`.`t3`.`pk` in ( <materialize> (/* select#2 */ select /*+ QB_NAME(`subq1`) */ `test`.`t4`.`i1` from `test`.`t4` where (`test`.`t4`.`c1` < 'o') ), <primary_index_lookup>(`test`.`t3`.`pk` in <temporary table> on <auto_distinct_key> where ((`test`.`t3`.`pk` = `<materialized_subquery>`.`i1`))))) and (`test`.`t1`.`i1` <= `test`.`t3`.`i2_key`)) |
| 831 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 832 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 833 |
WHERE ( t3.pk IN |
| 834 |
( |
| 835 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 836 |
FROM t4 |
| 837 |
WHERE t4.c1 < 'o' |
| 838 |
) |
| 839 |
) |
| 840 |
AND t1.i1 <= t3.i2_key; |
| 841 |
c1 i1 |
| 842 |
c 2 |
| 843 |
c 5 |
| 844 |
c 7 |
| 845 |
c 7 |
| 846 |
c 9 |
| 847 |
g 2 |
| 848 |
g 5 |
| 849 |
g 7 |
| 850 |
g 7 |
| 851 |
g 9 |
| 852 |
i 2 |
| 853 |
i 5 |
| 854 |
i 7 |
| 855 |
i 7 |
| 856 |
i 9 |
| 857 |
t 2 |
| 858 |
t 2 |
| 859 |
t 5 |
| 860 |
t 5 |
| 861 |
t 7 |
| 862 |
t 7 |
| 863 |
t 7 |
| 864 |
t 7 |
| 865 |
t 9 |
| 866 |
t 9 |
| 867 |
# |
| 868 |
# Test 3: One covering index including the base column for the virtual |
| 869 |
# column |
| 870 |
# |
| 871 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 872 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 873 |
WHERE ( t3.pk IN |
| 874 |
( |
| 875 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 876 |
FROM t4 |
| 877 |
WHERE t4.c1 < 'o' |
| 878 |
) |
| 879 |
) |
| 880 |
AND t1.i1 <= t3.i2_key; |
| 881 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 882 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 883 |
1 PRIMARY t3 NULL ALL NULL NULL NULL NULL 9 33.33 Using where; Using join buffer (hash join) |
| 884 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 885 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 886 |
Warnings: |
| 887 |
Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq1`) */ `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`i1` AS `i1` from `test`.`t1` straight_join `test`.`t3` straight_join `test`.`t2` where (<in_optimizer>(`test`.`t3`.`pk`,`test`.`t3`.`pk` in ( <materialize> (/* select#2 */ select /*+ QB_NAME(`subq1`) */ `test`.`t4`.`i1` from `test`.`t4` where (`test`.`t4`.`c1` < 'o') ), <primary_index_lookup>(`test`.`t3`.`pk` in <temporary table> on <auto_distinct_key> where ((`test`.`t3`.`pk` = `<materialized_subquery>`.`i1`))))) and (`test`.`t1`.`i1` <= `test`.`t3`.`i2_key`)) |
| 888 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 889 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 890 |
WHERE ( t3.pk IN |
| 891 |
( |
| 892 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 893 |
FROM t4 |
| 894 |
WHERE t4.c1 < 'o' |
| 895 |
) |
| 896 |
) |
| 897 |
AND t1.i1 <= t3.i2_key; |
| 898 |
c1 i1 |
| 899 |
c 2 |
| 900 |
c 5 |
| 901 |
c 7 |
| 902 |
c 7 |
| 903 |
c 9 |
| 904 |
g 2 |
| 905 |
g 5 |
| 906 |
g 7 |
| 907 |
g 7 |
| 908 |
g 9 |
| 909 |
i 2 |
| 910 |
i 5 |
| 911 |
i 7 |
| 912 |
i 7 |
| 913 |
i 9 |
| 914 |
t 2 |
| 915 |
t 2 |
| 916 |
t 5 |
| 917 |
t 5 |
| 918 |
t 7 |
| 919 |
t 7 |
| 920 |
t 7 |
| 921 |
t 7 |
| 922 |
t 9 |
| 923 |
t 9 |
| 924 |
# |
| 925 |
# Test 4: One non-covering index |
| 926 |
# |
| 927 |
# Add more data to the table so that it will run the dynamic range scan |
| 928 |
# as both table scan and range scan (the purpose of this is to make the |
| 929 |
# table scan more expensive). |
| 930 |
INSERT INTO t3 (pk, i1) |
| 931 |
VALUES (10,1), (11,1), (12,1), (13,1), (14,1),(15,1), (16,1),(17,1), (18,1), |
| 932 |
(19,1), (20,1), (21,1), (22,1), (23,1), (24,1),(25,1),(26,1),(27,1), |
| 933 |
(28,1), (29,1); |
| 934 |
# Change the query to read an extra column (t3.i1) making the index |
| 935 |
# non-covering. |
| 936 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1 |
| 937 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 938 |
WHERE ( t3.pk IN |
| 939 |
( |
| 940 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 941 |
FROM t4 |
| 942 |
WHERE t4.c1 < 'o' |
| 943 |
) |
| 944 |
) |
| 945 |
AND t1.i1 <= t3.i2_key; |
| 946 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 947 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 948 |
1 PRIMARY t3 NULL ALL NULL NULL NULL NULL 29 33.33 Using where; Using join buffer (hash join) |
| 949 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 950 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 951 |
Warnings: |
| 952 |
Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq1`) */ `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`i1` AS `i1`,`test`.`t3`.`i1` AS `i1` from `test`.`t1` straight_join `test`.`t3` straight_join `test`.`t2` where (<in_optimizer>(`test`.`t3`.`pk`,`test`.`t3`.`pk` in ( <materialize> (/* select#2 */ select /*+ QB_NAME(`subq1`) */ `test`.`t4`.`i1` from `test`.`t4` where (`test`.`t4`.`c1` < 'o') ), <primary_index_lookup>(`test`.`t3`.`pk` in <temporary table> on <auto_distinct_key> where ((`test`.`t3`.`pk` = `<materialized_subquery>`.`i1`))))) and (`test`.`t1`.`i1` <= `test`.`t3`.`i2_key`)) |
| 953 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1 |
| 954 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 955 |
WHERE ( t3.pk IN |
| 956 |
( |
| 957 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 958 |
FROM t4 |
| 959 |
WHERE t4.c1 < 'o' |
| 960 |
) |
| 961 |
) |
| 962 |
AND t1.i1 <= t3.i2_key; |
| 963 |
c1 i1 i1 |
| 964 |
c 2 48 |
| 965 |
c 5 48 |
| 966 |
c 7 48 |
| 967 |
c 7 48 |
| 968 |
c 9 48 |
| 969 |
g 2 48 |
| 970 |
g 5 48 |
| 971 |
g 7 48 |
| 972 |
g 7 48 |
| 973 |
g 9 48 |
| 974 |
i 2 48 |
| 975 |
i 5 48 |
| 976 |
i 7 48 |
| 977 |
i 7 48 |
| 978 |
i 9 48 |
| 979 |
t 2 1 |
| 980 |
t 2 48 |
| 981 |
t 5 1 |
| 982 |
t 5 48 |
| 983 |
t 7 1 |
| 984 |
t 7 1 |
| 985 |
t 7 48 |
| 986 |
t 7 48 |
| 987 |
t 9 1 |
| 988 |
t 9 48 |
| 989 |
# |
| 990 |
# Test 5: Test where the added primary key to secondary indexes is |
| 991 |
# used after it has been included in the join buffer |
| 992 |
# |
| 993 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 994 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 995 |
WHERE ( t3.pk IN |
| 996 |
( |
| 997 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 998 |
FROM t4 |
| 999 |
WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1) |
| 1000 |
) |
| 1001 |
) |
| 1002 |
AND t1.i1 <= t3.i2_key; |
| 1003 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1004 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 1005 |
1 PRIMARY t3 NULL ALL NULL NULL NULL NULL 29 33.33 Using where; Using join buffer (hash join) |
| 1006 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (hash join) |
| 1007 |
2 DEPENDENT SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 1008 |
Warnings: |
| 1009 |
Note 1276 Field or reference 'test.t2.i1' of SELECT #2 was resolved in SELECT #1 |
| 1010 |
Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`subq1`) */ `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`i1` AS `i1` from `test`.`t1` straight_join `test`.`t3` straight_join `test`.`t2` where (<in_optimizer>(`test`.`t3`.`pk`,<exists>(/* select#2 */ select /*+ QB_NAME(`subq1`) */ `test`.`t4`.`i1` from `test`.`t4` where ((`test`.`t4`.`c1` < 'o') and (`test`.`t4`.`i1` < (`test`.`t2`.`i1` + 1)) and (<cache>(`test`.`t3`.`pk`) = `test`.`t4`.`i1`)))) and (`test`.`t1`.`i1` <= `test`.`t3`.`i2_key`)) |
| 1011 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1012 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1013 |
WHERE ( t3.pk IN |
| 1014 |
( |
| 1015 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1016 |
FROM t4 |
| 1017 |
WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1) |
| 1018 |
) |
| 1019 |
) |
| 1020 |
AND t1.i1 <= t3.i2_key; |
| 1021 |
c1 i1 |
| 1022 |
c 2 |
| 1023 |
c 5 |
| 1024 |
c 7 |
| 1025 |
c 7 |
| 1026 |
c 9 |
| 1027 |
g 2 |
| 1028 |
g 5 |
| 1029 |
g 7 |
| 1030 |
g 7 |
| 1031 |
g 9 |
| 1032 |
i 2 |
| 1033 |
i 5 |
| 1034 |
i 7 |
| 1035 |
i 7 |
| 1036 |
i 9 |
| 1037 |
t 2 |
| 1038 |
t 2 |
| 1039 |
t 5 |
| 1040 |
t 5 |
| 1041 |
t 7 |
| 1042 |
t 7 |
| 1043 |
t 7 |
| 1044 |
t 7 |
| 1045 |
t 9 |
| 1046 |
t 9 |
| 1047 |
DROP TABLE t1, t2, t3, t4; |
| 1048 |
SET optimizer_switch='derived_merge=default'; |
| 1049 |
DROP VIEW IF EXISTS v1,v2; |
| 1050 |
DROP TABLE IF EXISTS t1,t2,t3; |
| 1051 |
DROP PROCEDURE IF EXISTS p1; |
| 1052 |
DROP FUNCTION IF EXISTS f1; |
| 1053 |
DROP TRIGGER IF EXISTS trg1; |
| 1054 |
DROP TRIGGER IF EXISTS trg2; |
| 1055 |
set sql_warnings = 0; |