| 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 = 'InnoDB'; |
| 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 ALL NULL NULL NULL NULL 1 100.00 NULL |
| 33 |
Warnings: |
| 34 |
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` |
| 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 ref c c 5 const 1 100.00 NULL |
| 41 |
Warnings: |
| 42 |
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where (`test`.`t2`.`c` = -(1)) |
| 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 1 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 t3 NULL index c c 5 NULL 3 100.00 Using index |
| 92 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 20.00 Using where; Using join buffer (hash join) |
| 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`.`t1`.`b` = `test`.`t3`.`c`) |
| 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 2 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 ALL 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 `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` |
| 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 t1 NULL index NULL c 5 NULL 5 100.00 Using index |
| 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 5 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 2 100.00 Using where |
| 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 2 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 |
# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <non-indexed gcol> |
| 219 |
select * from t3 where a between 1 and 2 order by b; |
| 220 |
a b c |
| 221 |
2 -2 -2 |
| 222 |
1 -1 -1 |
| 223 |
explain select * from t3 where a between 1 and 2 order by b; |
| 224 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 225 |
1 SIMPLE t3 NULL range PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using filesort |
| 226 |
Warnings: |
| 227 |
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`.`b` |
| 228 |
# bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC |
| 229 |
# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <non-indexed stored gcol> |
| 230 |
select * from t3 where a between 1 and 2 order by c; |
| 231 |
a b c |
| 232 |
2 -2 -2 |
| 233 |
1 -1 -1 |
| 234 |
explain select * from t3 where a between 1 and 2 order by c; |
| 235 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 236 |
1 SIMPLE t3 NULL range PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using filesort |
| 237 |
Warnings: |
| 238 |
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` |
| 239 |
# bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC |
| 240 |
CREATE TABLE t4 ( |
| 241 |
`pk` int(11) NOT NULL , |
| 242 |
`col_int_nokey` int(11) GENERATED ALWAYS AS (pk + col_int_key) STORED, |
| 243 |
`col_int_key` int(11) DEFAULT NULL, |
| 244 |
`col_date_nokey` date DEFAULT NULL, |
| 245 |
`col_datetime_key` datetime DEFAULT NULL, |
| 246 |
PRIMARY KEY (`pk`), |
| 247 |
KEY `col_int_key` (`col_int_key`), |
| 248 |
KEY `col_datetime_key` (`col_datetime_key`) |
| 249 |
); |
| 250 |
Warnings: |
| 251 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 252 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 253 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 254 |
INSERT INTO t4 VALUES |
| 255 |
(1,default,4,'2008-12-05','1900-01-01 00:00:00'); |
| 256 |
SELECT |
| 257 |
SQL_BIG_RESULT |
| 258 |
GRANDPARENT1 . `col_int_nokey` AS g1 |
| 259 |
FROM t4 AS GRANDPARENT1 LEFT JOIN t4 AS GRANDPARENT2 ON ( GRANDPARENT2 . |
| 260 |
`col_datetime_key` <= GRANDPARENT1 . `col_date_nokey` ) |
| 261 |
GROUP BY GRANDPARENT1 . `pk`; |
| 262 |
g1 |
| 263 |
5 |
| 264 |
DROP TABLE t4; |
| 265 |
# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <indexed gcol> |
| 266 |
select * from t3 where a between 1 and 2 order by c; |
| 267 |
a b c |
| 268 |
2 -2 -2 |
| 269 |
1 -1 -1 |
| 270 |
explain select * from t3 where a between 1 and 2 order by c; |
| 271 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 272 |
1 SIMPLE t3 NULL range PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using filesort |
| 273 |
Warnings: |
| 274 |
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` |
| 275 |
# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-gcol> |
| 276 |
select * from t3 where b between -2 and -1 order by a; |
| 277 |
a b c |
| 278 |
1 -1 -1 |
| 279 |
2 -2 -2 |
| 280 |
explain select * from t3 where b between -2 and -1 order by a; |
| 281 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 282 |
1 SIMPLE t3 NULL index NULL PRIMARY 4 NULL 3 33.33 Using where |
| 283 |
Warnings: |
| 284 |
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` |
| 285 |
# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-indexed gcol> |
| 286 |
select * from t3 where b between -2 and -1 order by b; |
| 287 |
a b c |
| 288 |
2 -2 -2 |
| 289 |
1 -1 -1 |
| 290 |
explain select * from t3 where b between -2 and -1 order by b; |
| 291 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 292 |
1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using filesort |
| 293 |
Warnings: |
| 294 |
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` |
| 295 |
# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-indexed gcol> |
| 296 |
select * from t3 where c between -2 and -1 order by b; |
| 297 |
a b c |
| 298 |
2 -2 -2 |
| 299 |
1 -1 -1 |
| 300 |
explain select * from t3 where c between -2 and -1 order by b; |
| 301 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 302 |
1 SIMPLE t3 NULL range c c 5 NULL 2 100.00 Using index condition; Using filesort |
| 303 |
Warnings: |
| 304 |
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` |
| 305 |
# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <indexed gcol> |
| 306 |
select * from t3 where b between -2 and -1 order by c; |
| 307 |
a b c |
| 308 |
2 -2 -2 |
| 309 |
1 -1 -1 |
| 310 |
explain select * from t3 where b between -2 and -1 order by c; |
| 311 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 312 |
1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using filesort |
| 313 |
Warnings: |
| 314 |
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` |
| 315 |
# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <indexed gcol> |
| 316 |
select * from t3 where c between -2 and -1 order by c; |
| 317 |
a b c |
| 318 |
2 -2 -2 |
| 319 |
1 -1 -1 |
| 320 |
explain select * from t3 where c between -2 and -1 order by c; |
| 321 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 322 |
1 SIMPLE t3 NULL range c c 5 NULL 2 100.00 Using index condition |
| 323 |
Warnings: |
| 324 |
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` |
| 325 |
# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol> |
| 326 |
select sum(b) from t1 group by b; |
| 327 |
sum(b) |
| 328 |
-2 |
| 329 |
-2 |
| 330 |
-3 |
| 331 |
NULL |
| 332 |
explain select sum(b) from t1 group by b; |
| 333 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 334 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 Using temporary |
| 335 |
Warnings: |
| 336 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`b`) AS `sum(b)` from `test`.`t1` group by `test`.`t1`.`b` |
| 337 |
# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <indexed gcol> |
| 338 |
select sum(c) from t1 group by c; |
| 339 |
sum(c) |
| 340 |
NULL |
| 341 |
-3 |
| 342 |
-2 |
| 343 |
-2 |
| 344 |
explain select sum(c) from t1 group by c; |
| 345 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 346 |
1 SIMPLE t1 NULL index c c 5 NULL 5 100.00 Using index |
| 347 |
Warnings: |
| 348 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`c`) AS `sum(c)` from `test`.`t1` group by `test`.`t1`.`c` |
| 349 |
# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <indexed gcol> |
| 350 |
select sum(b) from t1 group by c; |
| 351 |
sum(b) |
| 352 |
NULL |
| 353 |
-3 |
| 354 |
-2 |
| 355 |
-2 |
| 356 |
explain select sum(b) from t1 group by c; |
| 357 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 358 |
1 SIMPLE t1 NULL index c c 5 NULL 5 100.00 NULL |
| 359 |
Warnings: |
| 360 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`b`) AS `sum(b)` from `test`.`t1` group by `test`.`t1`.`c` |
| 361 |
# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol> |
| 362 |
select sum(c) from t1 group by b; |
| 363 |
sum(c) |
| 364 |
-2 |
| 365 |
-2 |
| 366 |
-3 |
| 367 |
NULL |
| 368 |
explain select sum(c) from t1 group by b; |
| 369 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 370 |
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 Using temporary |
| 371 |
Warnings: |
| 372 |
Note 1003 /* select#1 */ select sum(`test`.`t1`.`c`) AS `sum(c)` from `test`.`t1` group by `test`.`t1`.`b` |
| 373 |
drop table t1; |
| 374 |
# |
| 375 |
# Bug#20241655: WL411:FAILING ASSERTION ASSERTION |
| 376 |
# |
| 377 |
CREATE TABLE BB ( |
| 378 |
col_time_key time NOT NULL, |
| 379 |
col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL, |
| 380 |
col_datetime_key datetime NOT NULL); |
| 381 |
INSERT INTO BB VALUES('23:28:02', default, '2005-03-15 22:48:25'); |
| 382 |
CREATE TABLE CC ( |
| 383 |
col_time_key time NOT NULL, |
| 384 |
col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL, |
| 385 |
col_datetime_key datetime NOT NULL |
| 386 |
); |
| 387 |
INSERT INTO CC VALUES('16:22:51', default, '1900-01-01 00:00:00'); |
| 388 |
SELECT 1 AS g1 FROM BB AS gp1 LEFT JOIN BB AS gp2 USING ( col_time_nokey); |
| 389 |
g1 |
| 390 |
1 |
| 391 |
DROP TABLE BB, CC; |
| 392 |
# |
| 393 |
# Bug#20328786: WL411:VALGRIND WARNINGS OF CONDITIONAL |
| 394 |
# JUMP WHILE SELECTING FROM VIEW |
| 395 |
# |
| 396 |
CREATE TABLE A ( |
| 397 |
pk INTEGER AUTO_INCREMENT, |
| 398 |
col_int_nokey INTEGER, |
| 399 |
col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED, |
| 400 |
PRIMARY KEY (pk) |
| 401 |
); |
| 402 |
CREATE TABLE C ( |
| 403 |
pk INTEGER AUTO_INCREMENT, |
| 404 |
col_int_nokey INTEGER, |
| 405 |
col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED, |
| 406 |
col_varchar_nokey VARCHAR(1), |
| 407 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 408 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED, |
| 409 |
PRIMARY KEY (pk), |
| 410 |
KEY (col_int_key), |
| 411 |
KEY (col_varchar_key, col_int_key) |
| 412 |
); |
| 413 |
INSERT INTO C ( |
| 414 |
col_int_nokey, |
| 415 |
col_varchar_nokey |
| 416 |
) 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'); |
| 417 |
CREATE OR REPLACE ALGORITHM=MERGE VIEW V1 AS SELECT alias1. |
| 418 |
col_varchar_key AS field1 , alias1.pk AS field2, alias2. |
| 419 |
col_int_nokey AS field3 FROM C AS alias1 LEFT JOIN A AS alias2 ON |
| 420 |
alias1.pk = alias2.col_int_key WHERE alias1.pk > 8 AND alias1 |
| 421 |
.pk < ( 9 + 2 ) AND alias1.col_int_key <> 1 OR alias1.col_int_key |
| 422 |
> 0 AND alias1.col_int_key <= ( 3 + 2 ) ORDER BY field1, field2, field3 |
| 423 |
LIMIT 100 OFFSET 6; |
| 424 |
Warnings: |
| 425 |
Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm) |
| 426 |
SELECT * FROM V1; |
| 427 |
field1 field2 field3 |
| 428 |
qq 14 NULL |
| 429 |
rr 17 NULL |
| 430 |
ss 9 NULL |
| 431 |
xx 5 NULL |
| 432 |
DROP VIEW V1; |
| 433 |
DROP TABLE A,C; |
| 434 |
# |
| 435 |
# Bug#20406510: WL411:VALGRIND WARNINGS WITH |
| 436 |
# COUNT DISTINCT QUERY ON VIRTUAL GC VARCHAR COLUMN |
| 437 |
# |
| 438 |
CREATE TABLE A ( |
| 439 |
pk INTEGER AUTO_INCREMENT, |
| 440 |
col_time_key TIME NOT NULL, |
| 441 |
col_datetime_key DATETIME NOT NULL, |
| 442 |
PRIMARY KEY (pk), |
| 443 |
KEY (col_time_key), |
| 444 |
KEY (col_datetime_key) |
| 445 |
); |
| 446 |
CREATE TABLE C ( |
| 447 |
pk INTEGER AUTO_INCREMENT, |
| 448 |
col_int_key INTEGER NOT NULL, |
| 449 |
col_varchar_key VARCHAR(1) NOT NULL, |
| 450 |
col_varchar_nokey VARCHAR(2) GENERATED ALWAYS AS |
| 451 |
(CONCAT(col_varchar_key, col_varchar_key)), |
| 452 |
PRIMARY KEY (pk), |
| 453 |
KEY (col_int_key), |
| 454 |
KEY (col_varchar_key, col_int_key) |
| 455 |
); |
| 456 |
INSERT INTO C (col_int_key,col_varchar_key) VALUES (0, 'j'),(8, 'v'),(1, 'c'),(8, 'm'),(9, 'd'); |
| 457 |
SELECT MIN( alias2 . col_int_key ) AS field1, |
| 458 |
COUNT( DISTINCT alias2 . col_varchar_nokey ) AS field2 |
| 459 |
FROM ( A AS alias1 , C AS alias2 ) |
| 460 |
ORDER BY alias1.col_time_key, alias1.col_datetime_key, alias1.pk ASC; |
| 461 |
field1 field2 |
| 462 |
NULL 0 |
| 463 |
DROP TABLE A,C; |
| 464 |
# |
| 465 |
# Bug#20566325: WL8149: INNODB: FAILING ASSERTION: |
| 466 |
# COL_NR < TABLE->N_DEF |
| 467 |
# |
| 468 |
CREATE TABLE A ( |
| 469 |
pk INTEGER AUTO_INCREMENT, |
| 470 |
col_varchar_nokey VARCHAR(1) NOT NULL, |
| 471 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 472 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 473 |
PRIMARY KEY (pk) |
| 474 |
); |
| 475 |
INSERT /*! IGNORE */ INTO A (col_varchar_nokey) VALUES ('k'); |
| 476 |
CREATE TABLE CC ( |
| 477 |
pk INTEGER AUTO_INCREMENT, |
| 478 |
col_datetime_nokey DATETIME /*! NULL */, |
| 479 |
col_time_nokey TIME /*! NULL */, |
| 480 |
col_time_key TIME GENERATED ALWAYS AS |
| 481 |
(ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 482 |
col_varchar_nokey VARCHAR(1) /*! NULL */, |
| 483 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 484 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 485 |
PRIMARY KEY (pk)); |
| 486 |
INSERT INTO CC (col_time_nokey,col_datetime_nokey,col_varchar_nokey) VALUES |
| 487 |
('13:06:13.033877','1900-01-01 00:00:00', 'p'), |
| 488 |
(NULL, '2007-05-25 11:58:54.015689', 'g'); |
| 489 |
SELECT |
| 490 |
table1.col_time_key AS field1, |
| 491 |
'z' AS field2 |
| 492 |
FROM |
| 493 |
(CC AS table1 LEFT OUTER JOIN (A AS table2 STRAIGHT_JOIN CC AS table3 ON |
| 494 |
(table3.col_varchar_key = table2.col_varchar_nokey)) ON |
| 495 |
(table3.col_varchar_key = table2.col_varchar_nokey)) |
| 496 |
WHERE |
| 497 |
table2.pk != 6 |
| 498 |
AND table1.col_varchar_key IN ('l', 's' , 'b' ) |
| 499 |
AND table3.col_varchar_key != table1.col_varchar_key |
| 500 |
ORDER BY table1.col_varchar_key , field1 , field2; |
| 501 |
field1 field2 |
| 502 |
DROP TABLE A,CC; |
| 503 |
# |
| 504 |
# Bug#20573302: WL8149: SEGV IN HA_INNOBASE:: |
| 505 |
# BUILD_TEMPLATE AT INNOBASE/HANDLER/HA_INNODB.CC:665 |
| 506 |
# |
| 507 |
CREATE TABLE c ( |
| 508 |
pk INTEGER AUTO_INCREMENT, |
| 509 |
col_int_nokey INTEGER NOT NULL, |
| 510 |
col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey) VIRTUAL, |
| 511 |
col_date_nokey DATE NOT NULL, |
| 512 |
col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL, |
| 513 |
col_datetime_nokey DATETIME NOT NULL, |
| 514 |
col_time_nokey TIME NOT NULL, |
| 515 |
col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 516 |
col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 517 |
col_varchar_nokey VARCHAR(1) NOT NULL, |
| 518 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 519 |
PRIMARY KEY (pk), |
| 520 |
KEY (col_int_key), |
| 521 |
KEY (col_varchar_key), |
| 522 |
KEY (col_date_key), |
| 523 |
KEY (col_time_key), |
| 524 |
KEY (col_datetime_key), |
| 525 |
KEY (col_int_key, col_varchar_key), |
| 526 |
KEY (col_int_key, col_varchar_key, col_date_key, |
| 527 |
col_time_key, col_datetime_key)); |
| 528 |
INSERT /*! IGNORE */ INTO c ( |
| 529 |
col_int_nokey, |
| 530 |
col_date_nokey, |
| 531 |
col_time_nokey, |
| 532 |
col_datetime_nokey, |
| 533 |
col_varchar_nokey |
| 534 |
) VALUES |
| 535 |
(1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'), |
| 536 |
(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'), |
| 537 |
(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'), |
| 538 |
(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'), |
| 539 |
(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'), |
| 540 |
(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't'), |
| 541 |
(6, '2007-06-18', NULL, '2002-08-20 22:48:00.035785', 'd'), |
| 542 |
(2, '2002-10-13', '00:00:00', '1900-01-01 00:00:00', 's'), |
| 543 |
(4, '1900-01-01', '15:57:25.019666', '2005-08-15 00:00:00', 'r'), |
| 544 |
(8, NULL, '07:05:51.006712', '1900-01-01 00:00:00', 'm'), |
| 545 |
(4, '2006-03-09', '19:22:21.057406', '2008-05-16 08:09:06.002924', 'b'), |
| 546 |
(4, '2001-06-05', '03:53:16.001370', '2001-01-20 12:47:23.022022', 'x'), |
| 547 |
(7, '2006-05-28', '09:16:38.034570', '2008-07-02 00:00:00', 'g'), |
| 548 |
(4, '2001-04-19', '15:37:26.028315', '1900-01-01 00:00:00', 'p'), |
| 549 |
(1, '1900-01-01', '00:00:00', '2002-12-08 11:34:58.001571', 'q'), |
| 550 |
(9, '2004-08-20', '05:03:03.047452', '1900-01-01 00:00:00', 'w'), |
| 551 |
(4, '2004-10-10', '02:59:24.063764', '1900-01-01 00:00:00', 'd'), |
| 552 |
(8, '2000-04-02', '00:01:58.064243', '2002-08-25 20:35:06.064634', 'e'), |
| 553 |
(4, '2006-11-02', '00:00:00', '2001-10-22 11:13:24.048128', 'b'), |
| 554 |
(8, '2009-01-28', '02:20:16.024931', '2003-03-12 02:00:34.029335', 'y'); |
| 555 |
Warnings: |
| 556 |
Warning 1048 Column 'col_time_nokey' cannot be null |
| 557 |
Warning 1048 Column 'col_date_nokey' cannot be null |
| 558 |
CREATE TABLE cc ( |
| 559 |
pk INTEGER AUTO_INCREMENT, |
| 560 |
col_int_nokey INTEGER NOT NULL, |
| 561 |
col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey) VIRTUAL, |
| 562 |
col_date_nokey DATE NOT NULL, |
| 563 |
col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL, |
| 564 |
col_datetime_nokey DATETIME NOT NULL, |
| 565 |
col_time_nokey TIME NOT NULL, |
| 566 |
col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 567 |
col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 568 |
col_varchar_nokey VARCHAR(1) NOT NULL, |
| 569 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 570 |
PRIMARY KEY (pk), |
| 571 |
KEY (col_int_key), |
| 572 |
KEY (col_varchar_key), |
| 573 |
KEY (col_date_key), |
| 574 |
KEY (col_time_key), |
| 575 |
KEY (col_datetime_key), |
| 576 |
KEY (col_int_key, col_varchar_key), |
| 577 |
KEY (col_int_key, col_varchar_key, col_date_key, |
| 578 |
col_time_key, col_datetime_key)); |
| 579 |
INSERT /*! IGNORE */ INTO cc ( |
| 580 |
col_int_nokey, |
| 581 |
col_date_nokey, |
| 582 |
col_time_nokey, |
| 583 |
col_datetime_nokey, |
| 584 |
col_varchar_nokey |
| 585 |
) VALUES |
| 586 |
(0, '2003-02-06', '22:02:09.059926', '2003-08-07 14:43:09.011144', 'x'), |
| 587 |
(0, '2005-04-16', '19:33:15.014160', '2005-12-11 00:00:00', 'n'), |
| 588 |
(1, '2005-07-23', '22:03:16.058787', '2005-12-26 20:48:07.043628', 'w'), |
| 589 |
(7, '2001-11-15', '06:31:23.027263', '2008-06-12 06:41:21.012493', 's'), |
| 590 |
(0, '2006-03-24', '02:19:08.013275', '2007-10-11 18:46:28.030000', 'a'), |
| 591 |
(4, '2008-07-10', NULL, '2006-04-04 22:22:40.057947', 'd'), |
| 592 |
(1, '2009-12-07', NULL, '2002-08-10 20:52:58.035137', 'w'), |
| 593 |
(1, '2008-05-01', '10:28:01.038587', '2008-10-03 11:17:23.005299', 'j'), |
| 594 |
(1, '2008-06-22', '00:00:00', '2009-01-06 20:11:01.034339', 'm'), |
| 595 |
(4, '2001-11-11', '15:02:50.048785', '2009-09-19 00:00:00', 'k'), |
| 596 |
(7, '2000-12-21', '05:29:13.012729', '2007-09-02 12:14:27.029187', 't'), |
| 597 |
(4, '2007-09-03', '23:45:33.048507', '2003-09-26 00:00:00', 'k'), |
| 598 |
(2, '2003-02-18', '19:10:53.057455', '2001-11-18 18:10:16.063189', 'e'), |
| 599 |
(0, '2008-12-01', '01:45:27.037313', '2005-02-15 04:08:17.015554', 'i'), |
| 600 |
(1, '2008-10-18', '03:56:03.060218', '2009-06-13 23:04:40.013006', 't'), |
| 601 |
(91, '2004-08-28', '12:43:17.023797', '1900-01-01 00:00:00', 'm'), |
| 602 |
(6, '2006-10-05', '13:33:46.053634', '2005-03-20 02:48:24.045653', 'z'), |
| 603 |
(3, '2003-05-16', NULL, '2002-03-16 11:47:27.045297', 'c'), |
| 604 |
(6, '2008-10-10', NULL, '2000-05-22 00:00:00', 'i'), |
| 605 |
(8, '2002-01-19', '05:18:40.006865', '2009-02-12 00:00:00', 'v'); |
| 606 |
Warnings: |
| 607 |
Warning 1048 Column 'col_time_nokey' cannot be null |
| 608 |
EXPLAIN |
| 609 |
SELECT subquery2_t2.col_int_key AS subquery2_field1 |
| 610 |
FROM (c AS subquery2_t1 RIGHT JOIN |
| 611 |
(c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON |
| 612 |
(subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON |
| 613 |
(subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key)) |
| 614 |
ORDER BY subquery2_field1; |
| 615 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 616 |
1 SIMPLE subquery2_t2 NULL index NULL col_int_key_2 16 NULL # # Using index; Using temporary; Using filesort |
| 617 |
1 SIMPLE subquery2_t3 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) |
| 618 |
1 SIMPLE subquery2_t1 NULL index NULL col_date_key 4 NULL # # Using where; Using index; Using join buffer (hash join) |
| 619 |
Warnings: |
| 620 |
Note 1003 /* select#1 */ select `test`.`subquery2_t2`.`col_int_key` AS `subquery2_field1` from `test`.`c` `subquery2_t2` left join `test`.`cc` `subquery2_t3` on((`test`.`subquery2_t3`.`col_int_nokey` = `test`.`subquery2_t2`.`col_int_key`)) left join `test`.`c` `subquery2_t1` on((`test`.`subquery2_t3`.`col_varchar_key` = `test`.`subquery2_t2`.`col_varchar_key`)) where true order by `subquery2_field1` |
| 621 |
SELECT subquery2_t2.col_int_key AS subquery2_field1 |
| 622 |
FROM (c AS subquery2_t1 RIGHT JOIN |
| 623 |
(c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON |
| 624 |
(subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON |
| 625 |
(subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key)) |
| 626 |
ORDER BY subquery2_field1; |
| 627 |
subquery2_field1 |
| 628 |
1 |
| 629 |
1 |
| 630 |
1 |
| 631 |
1 |
| 632 |
1 |
| 633 |
1 |
| 634 |
1 |
| 635 |
1 |
| 636 |
1 |
| 637 |
1 |
| 638 |
1 |
| 639 |
1 |
| 640 |
1 |
| 641 |
1 |
| 642 |
1 |
| 643 |
1 |
| 644 |
1 |
| 645 |
1 |
| 646 |
1 |
| 647 |
1 |
| 648 |
1 |
| 649 |
1 |
| 650 |
1 |
| 651 |
1 |
| 652 |
1 |
| 653 |
1 |
| 654 |
1 |
| 655 |
1 |
| 656 |
1 |
| 657 |
1 |
| 658 |
1 |
| 659 |
1 |
| 660 |
1 |
| 661 |
1 |
| 662 |
2 |
| 663 |
4 |
| 664 |
4 |
| 665 |
4 |
| 666 |
4 |
| 667 |
4 |
| 668 |
4 |
| 669 |
4 |
| 670 |
4 |
| 671 |
4 |
| 672 |
4 |
| 673 |
4 |
| 674 |
4 |
| 675 |
4 |
| 676 |
4 |
| 677 |
4 |
| 678 |
4 |
| 679 |
4 |
| 680 |
4 |
| 681 |
4 |
| 682 |
4 |
| 683 |
4 |
| 684 |
4 |
| 685 |
4 |
| 686 |
4 |
| 687 |
4 |
| 688 |
4 |
| 689 |
4 |
| 690 |
4 |
| 691 |
4 |
| 692 |
4 |
| 693 |
4 |
| 694 |
4 |
| 695 |
4 |
| 696 |
4 |
| 697 |
4 |
| 698 |
4 |
| 699 |
4 |
| 700 |
6 |
| 701 |
6 |
| 702 |
6 |
| 703 |
6 |
| 704 |
7 |
| 705 |
7 |
| 706 |
8 |
| 707 |
8 |
| 708 |
8 |
| 709 |
8 |
| 710 |
9 |
| 711 |
9 |
| 712 |
24 |
| 713 |
SELECT subquery2_t2.col_int_key AS subquery2_field1 |
| 714 |
FROM (c AS subquery2_t1 RIGHT JOIN |
| 715 |
(c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON |
| 716 |
(subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON |
| 717 |
(subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key)) |
| 718 |
ORDER BY subquery2_field1; |
| 719 |
subquery2_field1 |
| 720 |
1 |
| 721 |
1 |
| 722 |
1 |
| 723 |
1 |
| 724 |
1 |
| 725 |
1 |
| 726 |
1 |
| 727 |
1 |
| 728 |
1 |
| 729 |
1 |
| 730 |
1 |
| 731 |
1 |
| 732 |
1 |
| 733 |
1 |
| 734 |
1 |
| 735 |
1 |
| 736 |
1 |
| 737 |
1 |
| 738 |
1 |
| 739 |
1 |
| 740 |
1 |
| 741 |
1 |
| 742 |
1 |
| 743 |
1 |
| 744 |
1 |
| 745 |
1 |
| 746 |
1 |
| 747 |
1 |
| 748 |
1 |
| 749 |
1 |
| 750 |
1 |
| 751 |
1 |
| 752 |
1 |
| 753 |
1 |
| 754 |
2 |
| 755 |
4 |
| 756 |
4 |
| 757 |
4 |
| 758 |
4 |
| 759 |
4 |
| 760 |
4 |
| 761 |
4 |
| 762 |
4 |
| 763 |
4 |
| 764 |
4 |
| 765 |
4 |
| 766 |
4 |
| 767 |
4 |
| 768 |
4 |
| 769 |
4 |
| 770 |
4 |
| 771 |
4 |
| 772 |
4 |
| 773 |
4 |
| 774 |
4 |
| 775 |
4 |
| 776 |
4 |
| 777 |
4 |
| 778 |
4 |
| 779 |
4 |
| 780 |
4 |
| 781 |
4 |
| 782 |
4 |
| 783 |
4 |
| 784 |
4 |
| 785 |
4 |
| 786 |
4 |
| 787 |
4 |
| 788 |
4 |
| 789 |
4 |
| 790 |
4 |
| 791 |
4 |
| 792 |
6 |
| 793 |
6 |
| 794 |
6 |
| 795 |
6 |
| 796 |
7 |
| 797 |
7 |
| 798 |
8 |
| 799 |
8 |
| 800 |
8 |
| 801 |
8 |
| 802 |
9 |
| 803 |
9 |
| 804 |
24 |
| 805 |
DROP TABLE c,cc; |
| 806 |
# |
| 807 |
# Bug#2081065: WL8149:RESULT DIFF SEEN FOR SIMPLE |
| 808 |
# RANGE QUERIES WITH ORDER BY |
| 809 |
# |
| 810 |
CREATE TABLE cc ( |
| 811 |
pk INTEGER AUTO_INCREMENT, |
| 812 |
col_int_nokey INTEGER NOT NULL, |
| 813 |
col_int_key INTEGER GENERATED ALWAYS AS |
| 814 |
(col_int_nokey + col_int_nokey) VIRTUAL, |
| 815 |
PRIMARY KEY (pk), |
| 816 |
KEY (col_int_key) |
| 817 |
); |
| 818 |
INSERT INTO cc (col_int_nokey) VALUES (0),(1),(7),(0),(4),(5); |
| 819 |
EXPLAIN SELECT pk FROM cc WHERE col_int_key > 3; |
| 820 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 821 |
1 SIMPLE cc NULL range col_int_key col_int_key 5 NULL # # Using where; Using index |
| 822 |
Warnings: |
| 823 |
Note 1003 /* select#1 */ select `test`.`cc`.`pk` AS `pk` from `test`.`cc` where (`test`.`cc`.`col_int_key` > 3) |
| 824 |
SELECT pk FROM cc WHERE col_int_key > 3; |
| 825 |
pk |
| 826 |
3 |
| 827 |
5 |
| 828 |
6 |
| 829 |
EXPLAIN SELECT pk FROM cc WHERE col_int_key > 3 ORDER BY 1; |
| 830 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 831 |
1 SIMPLE cc NULL range col_int_key col_int_key 5 NULL # # Using where; Using index; Using filesort |
| 832 |
Warnings: |
| 833 |
Note 1003 /* select#1 */ select `test`.`cc`.`pk` AS `pk` from `test`.`cc` where (`test`.`cc`.`col_int_key` > 3) order by `test`.`cc`.`pk` |
| 834 |
SELECT pk FROM cc WHERE col_int_key > 3 ORDER BY 1; |
| 835 |
pk |
| 836 |
3 |
| 837 |
5 |
| 838 |
6 |
| 839 |
DROP TABLE cc; |
| 840 |
# |
| 841 |
# Bug#20849676 :WL8149:ASSERTION `!TABLE || (!TABLE->READ_SET |
| 842 |
# || BITMAP_IS_SET(TABLE->READ_SET |
| 843 |
# |
| 844 |
CREATE TABLE c ( |
| 845 |
pk INTEGER AUTO_INCREMENT, |
| 846 |
col_int_nokey INTEGER NOT NULL, |
| 847 |
col_int_key INTEGER GENERATED ALWAYS AS |
| 848 |
(col_int_nokey + col_int_nokey) VIRTUAL, |
| 849 |
col_varchar_nokey VARCHAR(1) NOT NULL, |
| 850 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 851 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 852 |
PRIMARY KEY (pk), |
| 853 |
KEY (col_int_key), |
| 854 |
KEY (col_varchar_key), |
| 855 |
KEY (col_int_key, col_varchar_key) |
| 856 |
) ; |
| 857 |
INSERT INTO c (col_int_nokey, col_varchar_nokey) VALUES |
| 858 |
(1, 'c'),(8, 'm'),(9, 'd'),(24, 'd'),(6, 'y'),(1, 't'),(6, 'd'), |
| 859 |
(2, 'r'),(8, 'm'),(4, 'b'),(4, 'x'),(7, 'g'),(4, 'p'),(1, 'q'), |
| 860 |
(9, 'w'),(4, 'd'),(8, 'e'),(4, 'b'),(8, 'y'); |
| 861 |
CREATE TABLE a ( |
| 862 |
pk INTEGER AUTO_INCREMENT, |
| 863 |
col_datetime_nokey DATETIME NOT NULL, |
| 864 |
col_time_nokey TIME NOT NULL, |
| 865 |
col_datetime_key DATETIME GENERATED ALWAYS AS |
| 866 |
(ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 867 |
col_time_key TIME GENERATED ALWAYS AS |
| 868 |
(ADDTIME(col_datetime_nokey, col_time_nokey)), |
| 869 |
col_varchar_nokey VARCHAR(1) NOT NULL, |
| 870 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 871 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 872 |
PRIMARY KEY (pk), |
| 873 |
KEY (col_varchar_key), |
| 874 |
KEY (col_time_key), |
| 875 |
KEY (col_datetime_key), |
| 876 |
KEY (col_varchar_key, col_time_key, col_datetime_key) |
| 877 |
); |
| 878 |
INSERT INTO a ( |
| 879 |
col_time_nokey, |
| 880 |
col_datetime_nokey, |
| 881 |
col_varchar_nokey) VALUES |
| 882 |
('04:08:02.046897', '2001-11-04 19:07:55.051133', 'k'); |
| 883 |
ANALYZE TABLE a, c; |
| 884 |
Table Op Msg_type Msg_text |
| 885 |
test.a analyze status OK |
| 886 |
test.c analyze status OK |
| 887 |
EXPLAIN |
| 888 |
SELECT |
| 889 |
table1.pk AS field1 , |
| 890 |
table1.col_datetime_key AS field2 |
| 891 |
FROM |
| 892 |
( a AS table1 LEFT JOIN ( ( c AS table2 STRAIGHT_JOIN ( SELECT |
| 893 |
SUBQUERY1_t1.* FROM ( c AS SUBQUERY1_t1 INNER JOIN ( c AS SUBQUERY1_t2 |
| 894 |
STRAIGHT_JOIN c AS SUBQUERY1_t3 ON (SUBQUERY1_t3.col_varchar_key = |
| 895 |
SUBQUERY1_t2.col_varchar_key ) ) |
| 896 |
ON (SUBQUERY1_t3.pk = SUBQUERY1_t2.col_int_key |
| 897 |
OR SUBQUERY1_t1.col_int_key <> 1 ) ) |
| 898 |
WHERE SUBQUERY1_t2.pk >= 9 ) AS table3 |
| 899 |
ON (table3.col_int_key = table2.col_int_key ) ) ) |
| 900 |
ON (table3.col_int_nokey = table2.pk ) ) |
| 901 |
GROUP BY field1, field2; |
| 902 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 903 |
1 PRIMARY table1 NULL index col_datetime_key,col_varchar_key_2 col_datetime_key 6 NULL # 100.00 Using index; Using temporary |
| 904 |
1 PRIMARY table2 NULL index PRIMARY,col_int_key,col_int_key_2 col_int_key 5 NULL # 100.00 Using index |
| 905 |
1 PRIMARY <derived2> NULL ref <auto_key0> <auto_key0> 9 test.table2.pk,test.table2.col_int_key # 100.00 NULL |
| 906 |
2 DERIVED SUBQUERY1_t2 NULL range PRIMARY,col_int_key,col_varchar_key,col_int_key_2 PRIMARY 4 NULL # 100.00 Using where |
| 907 |
2 DERIVED SUBQUERY1_t3 NULL ref PRIMARY,col_varchar_key col_varchar_key 11 test.SUBQUERY1_t2.col_varchar_key # 100.00 Using index |
| 908 |
2 DERIVED SUBQUERY1_t1 NULL ALL col_int_key,col_int_key_2 NULL NULL NULL # 100.00 Using where; Using join buffer (hash join) |
| 909 |
SELECT |
| 910 |
table1.pk AS field1 , |
| 911 |
table1.col_datetime_key AS field2 |
| 912 |
FROM |
| 913 |
( a AS table1 LEFT JOIN ( ( c AS table2 STRAIGHT_JOIN ( SELECT |
| 914 |
SUBQUERY1_t1.* FROM ( c AS SUBQUERY1_t1 INNER JOIN ( c AS SUBQUERY1_t2 |
| 915 |
STRAIGHT_JOIN c AS SUBQUERY1_t3 ON (SUBQUERY1_t3.col_varchar_key = |
| 916 |
SUBQUERY1_t2.col_varchar_key ) ) |
| 917 |
ON (SUBQUERY1_t3.pk = SUBQUERY1_t2.col_int_key |
| 918 |
OR SUBQUERY1_t1.col_int_key <> 1 ) ) |
| 919 |
WHERE SUBQUERY1_t2.pk >= 9 ) AS table3 |
| 920 |
ON (table3.col_int_key = table2.col_int_key ) ) ) |
| 921 |
ON (table3.col_int_nokey = table2.pk ) ) |
| 922 |
GROUP BY field1, field2; |
| 923 |
field1 field2 |
| 924 |
1 2001-11-04 23:15:57 |
| 925 |
DROP TABLE IF EXISTS c,a; |
| 926 |
CREATE TABLE c ( |
| 927 |
col_int_nokey INTEGER NOT NULL, |
| 928 |
col_int_key INTEGER GENERATED ALWAYS AS |
| 929 |
(col_int_nokey + col_int_nokey) VIRTUAL, |
| 930 |
col_varchar_nokey VARCHAR(1) NOT NULL, |
| 931 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 932 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 933 |
KEY (col_int_key), |
| 934 |
KEY (col_int_key, col_varchar_key) |
| 935 |
) ; |
| 936 |
INSERT INTO c ( |
| 937 |
col_int_nokey, |
| 938 |
col_varchar_nokey |
| 939 |
) VALUES (1, 'c'),(8, 'm'),(9, 'd'),(24, 'd'),(6, 'y'),(1, 't'), |
| 940 |
(6, 'd'),(2, 's'),(4, 'r'),(8, 'm'),(4, 'b'),(4, 'x'),(7, 'g'),(4, 'p'), |
| 941 |
(1, 'q'),(9, 'w'),(4, 'd'),(8, 'e'),(4, 'b'),(8, 'y'); |
| 942 |
CREATE TABLE cc ( |
| 943 |
col_int_nokey INTEGER, |
| 944 |
col_int_key INTEGER GENERATED ALWAYS AS |
| 945 |
(col_int_nokey + col_int_nokey) VIRTUAL, |
| 946 |
col_varchar_nokey VARCHAR(1), |
| 947 |
col_varchar_key VARCHAR(2) GENERATED ALWAYS AS |
| 948 |
(CONCAT(col_varchar_nokey, col_varchar_nokey)), |
| 949 |
KEY (col_int_key), |
| 950 |
KEY (col_varchar_key), |
| 951 |
KEY (col_int_key, col_varchar_key), |
| 952 |
KEY (col_int_key, col_int_nokey), |
| 953 |
KEY (col_varchar_key, col_varchar_nokey) |
| 954 |
); |
| 955 |
INSERT INTO cc ( |
| 956 |
col_int_nokey, |
| 957 |
col_varchar_nokey |
| 958 |
) VALUES (8, 'p'),(9, 'g'),(9, 'i'),(4, 'p'),(7, 'h'),(1, 'e'),(8, 'e'),(6, 'u'), |
| 959 |
(6, 'j'),(6, 'e'),(1, 'z'),(227, 'w'),(NULL, 't'),(9, 'i'),(1, 'i'),(8, 'i'), |
| 960 |
(5, 'b'),(8,'m'),(7, 'j'),(2, 'v'); |
| 961 |
ANALYZE TABLE c, cc; |
| 962 |
Table Op Msg_type Msg_text |
| 963 |
test.c analyze status OK |
| 964 |
test.cc analyze status OK |
| 965 |
EXPLAIN SELECT |
| 966 |
alias2 . col_varchar_key AS field1 |
| 967 |
FROM ( cc AS alias1 , cc AS alias2 ) |
| 968 |
WHERE |
| 969 |
( alias2 . col_int_key , alias1 . col_int_nokey ) |
| 970 |
NOT IN |
| 971 |
( |
| 972 |
SELECT |
| 973 |
DISTINCT SQ1_alias2 . col_int_nokey AS SQ1_field1 , |
| 974 |
SQ1_alias1 . col_int_key AS SQ1_field2 |
| 975 |
FROM ( cc AS SQ1_alias1 , c AS SQ1_alias2 ) |
| 976 |
GROUP BY SQ1_field1 , SQ1_field2 |
| 977 |
) |
| 978 |
GROUP BY field1; |
| 979 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 980 |
1 PRIMARY alias1 NULL index NULL col_int_key_3 10 NULL # 100.00 Using index; Using temporary |
| 981 |
1 PRIMARY alias2 NULL index col_varchar_key,col_int_key_2,col_varchar_key_2 col_int_key_2 16 NULL # 100.00 Using where; Using index; Using join buffer (hash join) |
| 982 |
2 DEPENDENT SUBQUERY SQ1_alias1 NULL ref_or_null col_int_key,col_int_key_2,col_int_key_3 col_int_key 5 func # 100.00 Using where; Using index; Full scan on NULL key |
| 983 |
2 DEPENDENT SUBQUERY SQ1_alias2 NULL ALL NULL NULL NULL NULL # 100.00 Using where; Using join buffer (hash join) |
| 984 |
SELECT |
| 985 |
alias2 . col_varchar_key AS field1 |
| 986 |
FROM ( cc AS alias1 , cc AS alias2 ) |
| 987 |
WHERE |
| 988 |
( alias2 . col_int_key , alias1 . col_int_nokey ) |
| 989 |
NOT IN |
| 990 |
( |
| 991 |
SELECT |
| 992 |
DISTINCT SQ1_alias2 . col_int_nokey AS SQ1_field1 , |
| 993 |
SQ1_alias1 . col_int_key AS SQ1_field2 |
| 994 |
FROM ( cc AS SQ1_alias1 , c AS SQ1_alias2 ) |
| 995 |
GROUP BY SQ1_field1 , SQ1_field2 |
| 996 |
) |
| 997 |
GROUP BY field1; |
| 998 |
field1 |
| 999 |
bb |
| 1000 |
ee |
| 1001 |
gg |
| 1002 |
hh |
| 1003 |
ii |
| 1004 |
jj |
| 1005 |
mm |
| 1006 |
pp |
| 1007 |
uu |
| 1008 |
ww |
| 1009 |
DROP TABLE IF EXISTS c,cc; |
| 1010 |
SET @save_old_sql_mode= @@sql_mode; |
| 1011 |
SET sql_mode=""; |
| 1012 |
CREATE TABLE d ( |
| 1013 |
col_int int(11) DEFAULT NULL, |
| 1014 |
col_varchar_10_utf8 varchar(10) CHARACTER SET utf8 DEFAULT NULL, |
| 1015 |
pk int(11) NOT NULL AUTO_INCREMENT, |
| 1016 |
col_int_key int(11) GENERATED ALWAYS AS (col_int+col_int) VIRTUAL, |
| 1017 |
col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT(SUBSTRING(col_varchar_10_utf8, -1), 5)) VIRTUAL, |
| 1018 |
PRIMARY KEY (pk), |
| 1019 |
KEY col_int_key (col_int_key), |
| 1020 |
KEY col_varchar_10_utf8_key (col_varchar_10_utf8_key), |
| 1021 |
KEY cover_key1 (col_int_key, col_varchar_10_utf8_key) |
| 1022 |
); |
| 1023 |
INSERT INTO d (col_int, col_varchar_10_utf8) VALUES ('qhlhtrovam',1),('how',2),('htrovamzqr',3),('rovamzqrdc',4),('well',5),('g',6),('rdcenchyhu',7),('want',8); |
| 1024 |
SELECT table1.pk AS field1 FROM d AS table1 LEFT JOIN d AS table2 ON table1.col_varchar_10_utf8_key = table2.col_varchar_10_utf8_key WHERE table1.col_int_key IS NULL GROUP BY table1.pk ; |
| 1025 |
field1 |
| 1026 |
DROP TABLE d; |
| 1027 |
# |
| 1028 |
# Bug#21153237: WL8149: QUERIES USING FILESORT |
| 1029 |
# ON VIRTUAL GC HAVING INDEX GIVES WRONG RESULTS |
| 1030 |
# |
| 1031 |
CREATE TABLE j ( |
| 1032 |
col_int int(11), |
| 1033 |
pk int(11) NOT NULL, |
| 1034 |
col_varchar_10_utf8 varchar(10) CHARACTER SET utf8 DEFAULT NULL, |
| 1035 |
col_varchar_255_utf8_key varchar(255) CHARACTER SET utf8 GENERATED ALWAYS AS |
| 1036 |
(col_varchar_10_utf8) VIRTUAL, |
| 1037 |
PRIMARY KEY (pk), |
| 1038 |
KEY cover_key1 (col_int, col_varchar_255_utf8_key)); |
| 1039 |
INSERT INTO j(col_int, pk, col_varchar_10_utf8) VALUES(9, 1, '951910400'), |
| 1040 |
(-1934295040, 2, '1235025920'),(-584581120, 3, '-1176633344'),(3, 4, '1074462720'); |
| 1041 |
EXPLAIN SELECT col_varchar_255_utf8_key FROM j ORDER BY 1; |
| 1042 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1043 |
1 SIMPLE j NULL index NULL cover_key1 773 NULL # 100.00 Using index; Using filesort |
| 1044 |
SELECT col_varchar_255_utf8_key FROM j ORDER BY col_varchar_255_utf8_key; |
| 1045 |
col_varchar_255_utf8_key |
| 1046 |
-117663334 |
| 1047 |
1074462720 |
| 1048 |
1235025920 |
| 1049 |
951910400 |
| 1050 |
DROP TABLE j; |
| 1051 |
set sql_mode= @save_old_sql_mode; |
| 1052 |
CREATE TABLE cc ( |
| 1053 |
pk int(11) NOT NULL AUTO_INCREMENT, |
| 1054 |
col_int_nokey int(11) NOT NULL, |
| 1055 |
col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) STORED, |
| 1056 |
col_date_nokey date NOT NULL, |
| 1057 |
col_date_key date GENERATED ALWAYS AS (col_date_nokey) STORED, |
| 1058 |
col_datetime_nokey datetime NOT NULL, |
| 1059 |
col_time_nokey time NOT NULL, |
| 1060 |
col_datetime_key datetime GENERATED ALWAYS AS (col_datetime_nokey)STORED, |
| 1061 |
col_time_key time GENERATED ALWAYS AS (col_time_nokey) STORED, |
| 1062 |
col_varchar_nokey varchar(1) NOT NULL, |
| 1063 |
col_varchar_key varchar(1) GENERATED ALWAYS AS (col_varchar_nokey)STORED, |
| 1064 |
PRIMARY KEY (pk), |
| 1065 |
KEY gc_idx1 (col_int_key), |
| 1066 |
KEY gc_idx2 (col_varchar_key), |
| 1067 |
KEY gc_idx3 (col_date_key), |
| 1068 |
KEY gc_idx4 (col_time_key), |
| 1069 |
KEY gc_idx5 (col_datetime_key), |
| 1070 |
KEY gc_idx6 (col_varchar_key,col_int_key), |
| 1071 |
KEY gc_idx7 (col_date_key,col_datetime_key,col_time_key), |
| 1072 |
KEY gc_idx8(col_int_key,col_varchar_key,col_date_key,col_time_key, |
| 1073 |
col_datetime_key) |
| 1074 |
); |
| 1075 |
Warnings: |
| 1076 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 1077 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 1078 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 1079 |
INSERT INTO cc ( |
| 1080 |
col_int_nokey, |
| 1081 |
col_date_nokey, |
| 1082 |
col_time_nokey, |
| 1083 |
col_datetime_nokey, |
| 1084 |
col_varchar_nokey |
| 1085 |
) VALUES (1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'), |
| 1086 |
(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'), |
| 1087 |
(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'), |
| 1088 |
(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'), |
| 1089 |
(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'), |
| 1090 |
(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't'); |
| 1091 |
SET @save_old_sql_mode= @@sql_mode; |
| 1092 |
SET sql_mode=""; |
| 1093 |
SELECT DISTINCT alias1.col_varchar_key AS field1 |
| 1094 |
FROM ( cc AS alias1 STRAIGHT_JOIN |
| 1095 |
(( cc AS alias2 STRAIGHT_JOIN cc AS alias3 ON |
| 1096 |
(alias3.col_varchar_key > alias2.col_varchar_key ) ) ) ON |
| 1097 |
(( alias3 .pk >= alias2.col_int_nokey ) AND |
| 1098 |
(alias3 .pk >= alias2.col_int_nokey ) )) |
| 1099 |
WHERE alias1.col_varchar_key <= 'v' |
| 1100 |
GROUP BY field1 HAVING field1 = 91 |
| 1101 |
ORDER BY field1, alias1.col_date_key, field1 ASC, field1 DESC, |
| 1102 |
alias1.col_time_key ASC, field1; |
| 1103 |
field1 |
| 1104 |
DROP TABLE cc; |
| 1105 |
SET sql_mode=@save_old_sql_mode; |
| 1106 |
# |
| 1107 |
# Bug#20797941: WL8149:ASSERTION !TABLE || |
| 1108 |
# (!TABLE->READ_SET || BITMAP_IS_SET(TABLE->READ_SET |
| 1109 |
# |
| 1110 |
CREATE TABLE t(a int, b int as(a+1)); |
| 1111 |
INSERT INTO t(a) values(1),(2); |
| 1112 |
SELECT * FROM t ORDER BY b; |
| 1113 |
a b |
| 1114 |
1 2 |
| 1115 |
2 3 |
| 1116 |
DROP TABLE t; |
| 1117 |
# |
| 1118 |
# Testing a few index-based accesses on the virtual column |
| 1119 |
# |
| 1120 |
CREATE TABLE t1 ( |
| 1121 |
id int(11) NOT NULL, |
| 1122 |
b int(11) GENERATED ALWAYS AS (id+1) VIRTUAL NOT NULL, |
| 1123 |
UNIQUE KEY (b) ); |
| 1124 |
Warnings: |
| 1125 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 1126 |
Warning 1681 Integer display width is deprecated and will be removed in a future release. |
| 1127 |
INSERT INTO t1 (id) VALUES(NULL); |
| 1128 |
ERROR 23000: Column 'id' cannot be null |
| 1129 |
INSERT INTO t1 VALUES(2,3); |
| 1130 |
ERROR HY000: The value specified for generated column 'b' in table 't1' is not allowed. |
| 1131 |
INSERT INTO t1 (id) VALUES(2),(3); |
| 1132 |
EXPLAIN SELECT * FROM t1 FORCE INDEX(b) WHERE b=3; |
| 1133 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1134 |
1 SIMPLE t1 NULL const b b 4 const 1 100.00 NULL |
| 1135 |
Warnings: |
| 1136 |
Note 1003 /* select#1 */ select '2' AS `id`,'3' AS `b` from `test`.`t1` FORCE INDEX (`b`) where true |
| 1137 |
EXPLAIN SELECT * FROM t1 AS t2 STRAIGHT_JOIN t1 FORCE INDEX(b) WHERE t1.b=t2.b; |
| 1138 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1139 |
1 SIMPLE t2 NULL ALL b NULL NULL NULL 2 100.00 NULL |
| 1140 |
1 SIMPLE t1 NULL eq_ref b b 4 test.t2.b 1 100.00 NULL |
| 1141 |
Warnings: |
| 1142 |
Note 1003 /* select#1 */ select `test`.`t2`.`id` AS `id`,`test`.`t2`.`b` AS `b`,`test`.`t1`.`id` AS `id`,`test`.`t1`.`b` AS `b` from `test`.`t1` `t2` straight_join `test`.`t1` FORCE INDEX (`b`) where (`test`.`t1`.`b` = `test`.`t2`.`b`) |
| 1143 |
EXPLAIN SELECT b FROM t1 FORCE INDEX(b); |
| 1144 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1145 |
1 SIMPLE t1 NULL index NULL b 4 NULL 2 100.00 Using index |
| 1146 |
Warnings: |
| 1147 |
Note 1003 /* select#1 */ select `test`.`t1`.`b` AS `b` from `test`.`t1` FORCE INDEX (`b`) |
| 1148 |
INSERT INTO t1 (id) VALUES(4),(5),(6),(7),(8),(9),(10); |
| 1149 |
EXPLAIN SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5; |
| 1150 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1151 |
1 SIMPLE t1 NULL range b b 4 NULL 1 100.00 Using where; Using index |
| 1152 |
Warnings: |
| 1153 |
Note 1003 /* select#1 */ select `test`.`t1`.`b` AS `b` from `test`.`t1` FORCE INDEX (`b`) where (`test`.`t1`.`b` between 1 and 5) |
| 1154 |
EXPLAIN SELECT * FROM t2 AS t1 WHERE b NOT IN (SELECT b FROM t1 FORCE INDEX(b)); |
| 1155 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1156 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using where |
| 1157 |
2 DEPENDENT SUBQUERY t1 NULL unique_subquery b b 4 func 1 100.00 Using where; Using index; Full scan on NULL key |
| 1158 |
Warnings: |
| 1159 |
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t2` `t1` where <in_optimizer>(`test`.`t1`.`b`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`b`) in t1 on b where <if>(outer_field_is_not_null, (<cache>(`test`.`t1`.`b`) = `test`.`t1`.`b`), true))) is false) |
| 1160 |
DROP TABLE t1; |
| 1161 |
DROP TABLE t2, t3; |
| 1162 |
# |
| 1163 |
# Bug#21317507:GC: STORED COLUMN REJECTED, BUT VIRTUAL IS ACCEPTED |
| 1164 |
# |
| 1165 |
CREATE TABLE t1(a INT); |
| 1166 |
INSERT INTO t1 VALUES(2147483647); |
| 1167 |
ALTER TABLE t1 ADD INDEX idx(a), WITH VALIDATION; |
| 1168 |
ERROR HY000: Incorrect usage of ALTER and WITH VALIDATION |
| 1169 |
ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL; |
| 1170 |
ALTER TABLE t1 DROP COLUMN b; |
| 1171 |
ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL, WITH VALIDATION; |
| 1172 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 1173 |
ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION; |
| 1174 |
ALTER TABLE t1 DROP COLUMN d; |
| 1175 |
ALTER TABLE t1 ADD COLUMN c INT AS(a) VIRTUAL; |
| 1176 |
ALTER TABLE t1 CHANGE c c SMALLINT AS(a) VIRTUAL, WITH VALIDATION; |
| 1177 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 1178 |
ALTER TABLE t1 CHANGE c c SMALLINT AS(a) VIRTUAL, WITHOUT VALIDATION; |
| 1179 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 1180 |
ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL, WITH VALIDATION; |
| 1181 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 1182 |
ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL, WITHOUT VALIDATION; |
| 1183 |
ERROR 22003: Out of range value for column 'c' at row 1 |
| 1184 |
SELECT * FROM t1; |
| 1185 |
a c |
| 1186 |
2147483647 2147483647 |
| 1187 |
DROP TABLE t1; |
| 1188 |
CREATE TABLE t1(a INT); |
| 1189 |
INSERT INTO t1 VALUES(2147483647); |
| 1190 |
ALTER TABLE t1 ADD COLUMN h INT AS (a) VIRTUAL, WITHOUT VALIDATION; |
| 1191 |
ALTER TABLE t1 CHANGE h i INT AS (a) VIRTUAL, WITH VALIDATION, |
| 1192 |
ALGORITHM=INPLACE; |
| 1193 |
Got one of the listed errors |
| 1194 |
ALTER TABLE t1 CHANGE h i INT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 1195 |
ALGORITHM=INPLACE; |
| 1196 |
ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL, WITH VALIDATION, |
| 1197 |
ALGORITHM=INPLACE, LOCK=NONE; |
| 1198 |
Got one of the listed errors |
| 1199 |
ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL, WITH VALIDATION, |
| 1200 |
ALGORITHM=INPLACE, LOCK=SHARED; |
| 1201 |
Got one of the listed errors |
| 1202 |
ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL, WITH VALIDATION, |
| 1203 |
ALGORITHM=INPLACE, LOCK=EXCLUSIVE; |
| 1204 |
Got one of the listed errors |
| 1205 |
Shouldn't fail on Innodb |
| 1206 |
ALTER TABLE t1 ADD COLUMN e SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 1207 |
ALGORITHM=INPLACE, LOCK=NONE; |
| 1208 |
Shouldn't fail on Innodb |
| 1209 |
ALTER TABLE t1 ADD COLUMN f SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 1210 |
ALGORITHM=INPLACE, LOCK=SHARED; |
| 1211 |
Shouldn't fail on Innodb |
| 1212 |
ALTER TABLE t1 ADD COLUMN g SMALLINT AS (a) VIRTUAL, WITHOUT VALIDATION, |
| 1213 |
ALGORITHM=INPLACE, LOCK=EXCLUSIVE; |
| 1214 |
DROP TABLE t1; |
| 1215 |
# |
| 1216 |
# Bug#21980430 GCOLS: CRASHING |
| 1217 |
# |
| 1218 |
CREATE TABLE t ( |
| 1219 |
a INT, |
| 1220 |
b BLOB, |
| 1221 |
c BLOB GENERATED ALWAYS AS (a+b) VIRTUAL, |
| 1222 |
UNIQUE KEY i0008 (a) |
| 1223 |
); |
| 1224 |
INSERT INTO t(a,b) VALUES(1,'cccc'); |
| 1225 |
EXPLAIN SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c |
| 1226 |
WHERE b.b>c.a; |
| 1227 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1228 |
1 SIMPLE c NULL ALL i0008 NULL NULL NULL 1 100.00 NULL |
| 1229 |
1 SIMPLE b NULL ALL i0008 NULL NULL NULL 1 100.00 Range checked for each record (index map: 0x1) |
| 1230 |
Warnings: |
| 1231 |
Note 1003 /* select#1 */ select /*+ BKA(@`select#1`) */ 1 AS `c` from `test`.`t` `c` join `test`.`t` `b` where ((cast(`test`.`b`.`b` as double) > cast(`test`.`c`.`a` as double)) and (cast(`test`.`b`.`a` as double) > cast(`test`.`c`.`c` as double))) |
| 1232 |
SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c |
| 1233 |
WHERE b.b>c.a; |
| 1234 |
c |
| 1235 |
DROP TABLE t; |
| 1236 |
set @optimizer_switch_save = @@optimizer_switch; |
| 1237 |
set optimizer_switch='mrr_cost_based=off'; |
| 1238 |
set @read_rnd_buffer_size_save= @@read_rnd_buffer_size; |
| 1239 |
set read_rnd_buffer_size=32; |
| 1240 |
CREATE TABLE t0 ( |
| 1241 |
i1 INTEGER NOT NULL |
| 1242 |
); |
| 1243 |
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); |
| 1244 |
CREATE TABLE t1 ( |
| 1245 |
pk INTEGER NOT NULL, |
| 1246 |
i1 INTEGER NOT NULL, |
| 1247 |
i2 INTEGER NOT NULL, |
| 1248 |
v1 INTEGER GENERATED ALWAYS AS (i2 + 1) VIRTUAL, |
| 1249 |
v2 INTEGER GENERATED ALWAYS AS (i1 / (i1 - i2 + 57)) VIRTUAL, |
| 1250 |
PRIMARY KEY (pk), |
| 1251 |
INDEX idx(i1) |
| 1252 |
); |
| 1253 |
INSERT INTO t1 (pk, i1, i2) |
| 1254 |
SELECT a0.i1 + a1.i1*10 + a2.i1*100, |
| 1255 |
a0.i1 + a1.i1*10, |
| 1256 |
a0.i1 + a1.i1*10 |
| 1257 |
FROM t0 AS a0, t0 AS a1, t0 AS a2; |
| 1258 |
EXPLAIN SELECT * FROM t1 |
| 1259 |
WHERE i1 > 41 AND i1 <= 43; |
| 1260 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1261 |
1 SIMPLE t1 NULL range idx idx 4 NULL 20 100.00 Using index condition; Using MRR |
| 1262 |
Warnings: |
| 1263 |
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)) |
| 1264 |
SELECT * FROM t1 |
| 1265 |
WHERE i1 > 41 AND i1 <= 43; |
| 1266 |
pk i1 i2 v1 v2 |
| 1267 |
142 42 42 43 1 |
| 1268 |
143 43 43 44 1 |
| 1269 |
242 42 42 43 1 |
| 1270 |
243 43 43 44 1 |
| 1271 |
342 42 42 43 1 |
| 1272 |
343 43 43 44 1 |
| 1273 |
42 42 42 43 1 |
| 1274 |
43 43 43 44 1 |
| 1275 |
442 42 42 43 1 |
| 1276 |
443 43 43 44 1 |
| 1277 |
542 42 42 43 1 |
| 1278 |
543 43 43 44 1 |
| 1279 |
642 42 42 43 1 |
| 1280 |
643 43 43 44 1 |
| 1281 |
742 42 42 43 1 |
| 1282 |
743 43 43 44 1 |
| 1283 |
842 42 42 43 1 |
| 1284 |
843 43 43 44 1 |
| 1285 |
942 42 42 43 1 |
| 1286 |
943 43 43 44 1 |
| 1287 |
ALTER TABLE t1 ADD INDEX idx2(v1); |
| 1288 |
EXPLAIN SELECT * FROM t1 |
| 1289 |
WHERE v1 > 41 AND v1 <= 43; |
| 1290 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1291 |
1 SIMPLE t1 NULL range idx2 idx2 5 NULL 20 100.00 Using where; Using MRR |
| 1292 |
Warnings: |
| 1293 |
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)) |
| 1294 |
SELECT * FROM t1 |
| 1295 |
WHERE v1 > 41 AND v1 <= 43; |
| 1296 |
pk i1 i2 v1 v2 |
| 1297 |
141 41 41 42 1 |
| 1298 |
142 42 42 43 1 |
| 1299 |
241 41 41 42 1 |
| 1300 |
242 42 42 43 1 |
| 1301 |
341 41 41 42 1 |
| 1302 |
342 42 42 43 1 |
| 1303 |
41 41 41 42 1 |
| 1304 |
42 42 42 43 1 |
| 1305 |
441 41 41 42 1 |
| 1306 |
442 42 42 43 1 |
| 1307 |
541 41 41 42 1 |
| 1308 |
542 42 42 43 1 |
| 1309 |
641 41 41 42 1 |
| 1310 |
642 42 42 43 1 |
| 1311 |
741 41 41 42 1 |
| 1312 |
742 42 42 43 1 |
| 1313 |
841 41 41 42 1 |
| 1314 |
842 42 42 43 1 |
| 1315 |
941 41 41 42 1 |
| 1316 |
942 42 42 43 1 |
| 1317 |
DROP TABLE t0, t1; |
| 1318 |
set optimizer_switch= @optimizer_switch_save; |
| 1319 |
set @@read_rnd_buffer_size= @read_rnd_buffer_size_save; |
| 1320 |
# |
| 1321 |
# Bug#21872184 CONDITIONAL JUMP AT JOIN_CACHE::WRITE_RECORD_DATA IN |
| 1322 |
# SQL_JOIN_BUFFER.CC |
| 1323 |
# |
| 1324 |
# |
| 1325 |
# Test 1: Dynamic range scan with one covering index |
| 1326 |
# |
| 1327 |
CREATE TABLE t1 ( |
| 1328 |
i1 INTEGER NOT NULL, |
| 1329 |
c1 VARCHAR(1) NOT NULL |
| 1330 |
); |
| 1331 |
INSERT INTO t1 |
| 1332 |
VALUES (10, 'c'), (10, 'i'), (2, 't'), (4, 'g'); |
| 1333 |
CREATE TABLE t2 ( |
| 1334 |
i1 INTEGER NOT NULL, |
| 1335 |
c1 VARCHAR(1) NOT NULL |
| 1336 |
); |
| 1337 |
INSERT INTO t2 |
| 1338 |
VALUES (2, 'k'), (9, 'k'), (7, 'o'), (5, 'n'), (7, 'e'); |
| 1339 |
CREATE TABLE t3 ( |
| 1340 |
pk INTEGER NOT NULL, |
| 1341 |
i1 INTEGER, |
| 1342 |
i2_key INTEGER GENERATED ALWAYS AS (i1 + i1) VIRTUAL NOT NULL, |
| 1343 |
PRIMARY KEY (pk) |
| 1344 |
); |
| 1345 |
# Add a covering index. The reason for this index being covering is that |
| 1346 |
# secondary indexes in InnoDB include the primary key. |
| 1347 |
ALTER TABLE t3 ADD INDEX v_idx (i2_key); |
| 1348 |
INSERT INTO t3 (pk, i1) |
| 1349 |
VALUES (1, 1), (2, 48), (3, 228), (4, 3), (5, 5), |
| 1350 |
(6, 39), (7, 6), (8, 8), (9, 3); |
| 1351 |
CREATE TABLE t4 ( |
| 1352 |
i1 INTEGER NOT NULL, |
| 1353 |
c1 VARCHAR(1) NOT NULL |
| 1354 |
); |
| 1355 |
INSERT INTO t4 |
| 1356 |
VALUES (1, 'j'), (2, 'c'), (0, 'a'); |
| 1357 |
ANALYZE TABLE t1, t2, t3, t4; |
| 1358 |
Table Op Msg_type Msg_text |
| 1359 |
test.t1 analyze status OK |
| 1360 |
test.t2 analyze status OK |
| 1361 |
test.t3 analyze status OK |
| 1362 |
test.t4 analyze status OK |
| 1363 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1364 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1365 |
WHERE ( t3.pk IN |
| 1366 |
( |
| 1367 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1368 |
FROM t4 |
| 1369 |
WHERE t4.c1 < 'o' |
| 1370 |
) |
| 1371 |
) |
| 1372 |
AND t1.i1 <= t3.i2_key; |
| 1373 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1374 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 1375 |
1 PRIMARY t3 NULL ALL v_idx NULL NULL NULL 9 33.33 Range checked for each record (index map: 0x2) |
| 1376 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 1377 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 1378 |
Warnings: |
| 1379 |
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`)) |
| 1380 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1381 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1382 |
WHERE ( t3.pk IN |
| 1383 |
( |
| 1384 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1385 |
FROM t4 |
| 1386 |
WHERE t4.c1 < 'o' |
| 1387 |
) |
| 1388 |
) |
| 1389 |
AND t1.i1 <= t3.i2_key; |
| 1390 |
c1 i1 |
| 1391 |
c 2 |
| 1392 |
c 5 |
| 1393 |
c 7 |
| 1394 |
c 7 |
| 1395 |
c 9 |
| 1396 |
g 2 |
| 1397 |
g 5 |
| 1398 |
g 7 |
| 1399 |
g 7 |
| 1400 |
g 9 |
| 1401 |
i 2 |
| 1402 |
i 5 |
| 1403 |
i 7 |
| 1404 |
i 7 |
| 1405 |
i 9 |
| 1406 |
t 2 |
| 1407 |
t 2 |
| 1408 |
t 5 |
| 1409 |
t 5 |
| 1410 |
t 7 |
| 1411 |
t 7 |
| 1412 |
t 7 |
| 1413 |
t 7 |
| 1414 |
t 9 |
| 1415 |
t 9 |
| 1416 |
# |
| 1417 |
# Test 2: Two alternative covering indexes for the range scan |
| 1418 |
# |
| 1419 |
ALTER TABLE t3 ADD INDEX v_idx2 (i2_key, i1); |
| 1420 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1421 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1422 |
WHERE ( t3.pk IN |
| 1423 |
( |
| 1424 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1425 |
FROM t4 |
| 1426 |
WHERE t4.c1 < 'o' |
| 1427 |
) |
| 1428 |
) |
| 1429 |
AND t1.i1 <= t3.i2_key; |
| 1430 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1431 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 1432 |
1 PRIMARY t3 NULL ALL v_idx,v_idx2 NULL NULL NULL 9 33.33 Range checked for each record (index map: 0x6) |
| 1433 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 1434 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 1435 |
Warnings: |
| 1436 |
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`)) |
| 1437 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1438 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1439 |
WHERE ( t3.pk IN |
| 1440 |
( |
| 1441 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1442 |
FROM t4 |
| 1443 |
WHERE t4.c1 < 'o' |
| 1444 |
) |
| 1445 |
) |
| 1446 |
AND t1.i1 <= t3.i2_key; |
| 1447 |
c1 i1 |
| 1448 |
c 2 |
| 1449 |
c 5 |
| 1450 |
c 7 |
| 1451 |
c 7 |
| 1452 |
c 9 |
| 1453 |
g 2 |
| 1454 |
g 5 |
| 1455 |
g 7 |
| 1456 |
g 7 |
| 1457 |
g 9 |
| 1458 |
i 2 |
| 1459 |
i 5 |
| 1460 |
i 7 |
| 1461 |
i 7 |
| 1462 |
i 9 |
| 1463 |
t 2 |
| 1464 |
t 2 |
| 1465 |
t 5 |
| 1466 |
t 5 |
| 1467 |
t 7 |
| 1468 |
t 7 |
| 1469 |
t 7 |
| 1470 |
t 7 |
| 1471 |
t 9 |
| 1472 |
t 9 |
| 1473 |
# |
| 1474 |
# Test 3: One covering index including the base column for the virtual |
| 1475 |
# column |
| 1476 |
# |
| 1477 |
# Drop the index with only the virtual column |
| 1478 |
ALTER TABLE t3 DROP INDEX v_idx; |
| 1479 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1480 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1481 |
WHERE ( t3.pk IN |
| 1482 |
( |
| 1483 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1484 |
FROM t4 |
| 1485 |
WHERE t4.c1 < 'o' |
| 1486 |
) |
| 1487 |
) |
| 1488 |
AND t1.i1 <= t3.i2_key; |
| 1489 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1490 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 1491 |
1 PRIMARY t3 NULL ALL v_idx2 NULL NULL NULL 9 33.33 Range checked for each record (index map: 0x2) |
| 1492 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 1493 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 1494 |
Warnings: |
| 1495 |
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`)) |
| 1496 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1497 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1498 |
WHERE ( t3.pk IN |
| 1499 |
( |
| 1500 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1501 |
FROM t4 |
| 1502 |
WHERE t4.c1 < 'o' |
| 1503 |
) |
| 1504 |
) |
| 1505 |
AND t1.i1 <= t3.i2_key; |
| 1506 |
c1 i1 |
| 1507 |
c 2 |
| 1508 |
c 5 |
| 1509 |
c 7 |
| 1510 |
c 7 |
| 1511 |
c 9 |
| 1512 |
g 2 |
| 1513 |
g 5 |
| 1514 |
g 7 |
| 1515 |
g 7 |
| 1516 |
g 9 |
| 1517 |
i 2 |
| 1518 |
i 5 |
| 1519 |
i 7 |
| 1520 |
i 7 |
| 1521 |
i 9 |
| 1522 |
t 2 |
| 1523 |
t 2 |
| 1524 |
t 5 |
| 1525 |
t 5 |
| 1526 |
t 7 |
| 1527 |
t 7 |
| 1528 |
t 7 |
| 1529 |
t 7 |
| 1530 |
t 9 |
| 1531 |
t 9 |
| 1532 |
# |
| 1533 |
# Test 4: One non-covering index |
| 1534 |
# |
| 1535 |
# Drop the index on two columns, add index on just one virtual column |
| 1536 |
ALTER TABLE t3 DROP INDEX v_idx2; |
| 1537 |
ALTER TABLE t3 ADD INDEX v_idx (i2_key); |
| 1538 |
# Add more data to the table so that it will run the dynamic range scan |
| 1539 |
# as both table scan and range scan (the purpose of this is to make the |
| 1540 |
# table scan more expensive). |
| 1541 |
INSERT INTO t3 (pk, i1) |
| 1542 |
VALUES (10,1), (11,1), (12,1), (13,1), (14,1),(15,1), (16,1),(17,1), (18,1), |
| 1543 |
(19,1), (20,1), (21,1), (22,1), (23,1), (24,1),(25,1),(26,1),(27,1), |
| 1544 |
(28,1), (29,1); |
| 1545 |
# Change the query to read an extra column (t3.i1) making the index |
| 1546 |
# non-covering. |
| 1547 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1 |
| 1548 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1549 |
WHERE ( t3.pk IN |
| 1550 |
( |
| 1551 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1552 |
FROM t4 |
| 1553 |
WHERE t4.c1 < 'o' |
| 1554 |
) |
| 1555 |
) |
| 1556 |
AND t1.i1 <= t3.i2_key; |
| 1557 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1558 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 1559 |
1 PRIMARY t3 NULL ALL v_idx NULL NULL NULL 29 33.33 Range checked for each record (index map: 0x2) |
| 1560 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using join buffer (hash join) |
| 1561 |
2 SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 1562 |
Warnings: |
| 1563 |
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`)) |
| 1564 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1 |
| 1565 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1566 |
WHERE ( t3.pk IN |
| 1567 |
( |
| 1568 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1569 |
FROM t4 |
| 1570 |
WHERE t4.c1 < 'o' |
| 1571 |
) |
| 1572 |
) |
| 1573 |
AND t1.i1 <= t3.i2_key; |
| 1574 |
c1 i1 i1 |
| 1575 |
c 2 48 |
| 1576 |
c 5 48 |
| 1577 |
c 7 48 |
| 1578 |
c 7 48 |
| 1579 |
c 9 48 |
| 1580 |
g 2 48 |
| 1581 |
g 5 48 |
| 1582 |
g 7 48 |
| 1583 |
g 7 48 |
| 1584 |
g 9 48 |
| 1585 |
i 2 48 |
| 1586 |
i 5 48 |
| 1587 |
i 7 48 |
| 1588 |
i 7 48 |
| 1589 |
i 9 48 |
| 1590 |
t 2 1 |
| 1591 |
t 2 48 |
| 1592 |
t 5 1 |
| 1593 |
t 5 48 |
| 1594 |
t 7 1 |
| 1595 |
t 7 1 |
| 1596 |
t 7 48 |
| 1597 |
t 7 48 |
| 1598 |
t 9 1 |
| 1599 |
t 9 48 |
| 1600 |
# |
| 1601 |
# Test 5: Test where the added primary key to secondary indexes is |
| 1602 |
# used after it has been included in the join buffer |
| 1603 |
# |
| 1604 |
EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1605 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1606 |
WHERE ( t3.pk IN |
| 1607 |
( |
| 1608 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1609 |
FROM t4 |
| 1610 |
WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1) |
| 1611 |
) |
| 1612 |
) |
| 1613 |
AND t1.i1 <= t3.i2_key; |
| 1614 |
id select_type table partitions type possible_keys key key_len ref rows filtered Extra |
| 1615 |
1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL |
| 1616 |
1 PRIMARY t3 NULL ALL v_idx NULL NULL NULL 29 33.33 Range checked for each record (index map: 0x2) |
| 1617 |
1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (hash join) |
| 1618 |
2 DEPENDENT SUBQUERY t4 NULL ALL NULL NULL NULL NULL 3 33.33 Using where |
| 1619 |
Warnings: |
| 1620 |
Note 1276 Field or reference 'test.t2.i1' of SELECT #2 was resolved in SELECT #1 |
| 1621 |
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`)) |
| 1622 |
SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1 |
| 1623 |
FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2 |
| 1624 |
WHERE ( t3.pk IN |
| 1625 |
( |
| 1626 |
SELECT /*+ QB_NAME(subq1) */ t4.i1 |
| 1627 |
FROM t4 |
| 1628 |
WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1) |
| 1629 |
) |
| 1630 |
) |
| 1631 |
AND t1.i1 <= t3.i2_key; |
| 1632 |
c1 i1 |
| 1633 |
c 2 |
| 1634 |
c 5 |
| 1635 |
c 7 |
| 1636 |
c 7 |
| 1637 |
c 9 |
| 1638 |
g 2 |
| 1639 |
g 5 |
| 1640 |
g 7 |
| 1641 |
g 7 |
| 1642 |
g 9 |
| 1643 |
i 2 |
| 1644 |
i 5 |
| 1645 |
i 7 |
| 1646 |
i 7 |
| 1647 |
i 9 |
| 1648 |
t 2 |
| 1649 |
t 2 |
| 1650 |
t 5 |
| 1651 |
t 5 |
| 1652 |
t 7 |
| 1653 |
t 7 |
| 1654 |
t 7 |
| 1655 |
t 7 |
| 1656 |
t 9 |
| 1657 |
t 9 |
| 1658 |
DROP TABLE t1, t2, t3, t4; |
| 1659 |
SET optimizer_switch='derived_merge=default'; |
| 1660 |
DROP VIEW IF EXISTS v1,v2; |
| 1661 |
DROP TABLE IF EXISTS t1,t2,t3; |
| 1662 |
DROP PROCEDURE IF EXISTS p1; |
| 1663 |
DROP FUNCTION IF EXISTS f1; |
| 1664 |
DROP TRIGGER IF EXISTS trg1; |
| 1665 |
DROP TRIGGER IF EXISTS trg2; |
| 1666 |
set sql_warnings = 0; |