1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
#
# Tests for "ANALYZE FORMAT=JSON $statement" syntax
#
--disable_warnings
drop table if exists t0,t1,t2,t3;
--enable_warnings
--source include/default_optimizer_switch.inc
create table t0 (a int);
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
--echo # r_filtered=30%, because 3 rows match: 0,1,2
--source include/analyze-format.inc
analyze format=json select * from t0 where a<3;
create table t1 (a int, b int, c int, key(a));
insert into t1 select A.a*10 + B.a, A.a*10 + B.a, A.a*10 + B.a from t0 A, t0 B;
--source include/analyze-format.inc
analyze
select * from t0, t1 where t1.a=t0.a and t0.a > 9;
--source include/analyze-format.inc
analyze format=json
select * from t0, t1 where t1.a=t0.a and t0.a > 9;
analyze
select * from t0, t1 where t1.a=t0.a and t1.b<4;
--source include/analyze-format.inc
analyze format=json
select * from t0, t1 where t1.a=t0.a and t1.b<4;
analyze
select * from t1 tbl1, t1 tbl2 where tbl1.b<2 and tbl2.b>5;
--source include/analyze-format.inc
analyze format=json
select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60;
--source include/analyze-format.inc
analyze format=json
select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60 and tbl1.c > tbl2.c;
drop table t1;
drop table t0;
--echo #
--echo # MDEV-7674: ANALYZE shows r_rows=0
--echo #
create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, key(a));
insert into t2 values (0),(1);
--source include/analyze-format.inc
analyze format=json select * from t1 straight_join t2 force index(a) where t2.a=t1.a;
drop table t1,t2;
create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
--echo #
--echo # MDEV-7679: ANALYZE crashes when printing WHERE when no default db
--echo #
select database();
connect (con1,localhost,root,,*NO-ONE*);
connection con1;
select database();
--source include/analyze-format.inc
analyze format=json select * from test.t1 where t1.a<5;
disconnect con1;
connection default;
drop table t1;
--echo #
--echo # MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print
--echo # the r_total_time_ms
--echo #
create table t2(a int);
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t3(a int);
insert into t3 select A.a + B.a* 10 + C.a * 100 from t2 A, t2 B, t2 C;
create table t1 (pk int primary key);
insert into t1 select a from t3;
alter table t1 add b int;
--source include/analyze-format.inc
analyze format=json
update t1 set b=pk;
--source include/analyze-format.inc
analyze format=json
select * from t1 where pk < 10 and b > 4;
--source include/analyze-format.inc
analyze format=json
delete from t1 where pk < 10 and b > 4;
drop table t1, t3, t2;
--echo #
--echo # MDEV-7833:ANALYZE FORMAT=JSON and Range checked for each record
--echo #
create table t3(a int);
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t4(a int);
insert into t4 select A.a + B.a* 10 + C.a * 100 from t3 A, t3 B, t3 C;
create table t1 (lb1 int, rb1 int, lb2 int, rb2 int, c1 int, c2 int);
insert into t1 values (1,2,10,20,15,15);
insert into t1 values (3,5,10,20,15,15);
insert into t1 values (10,20,10,20,15,15);
insert into t1 values (10,20,1,2,15,15);
insert into t1 values (10,20,10,20,1,3);
create table t2 (key1 int, key2 int, key3 int, key4 int, col1 int,
key(key1), key(key2), key(key3), key(key4));
insert into t2 select a,a,a,a,a from t3;
insert into t2 select 15,15,15,15,15 from t4;
--source include/analyze-format.inc
analyze format=json
select * from t1, t2 where (t2.key1 between t1.lb1 and t1.rb1) and
(t2.key2 between t1.lb2 and t1.rb2) and
(t2.key3=t1.c1 OR t2.key4=t1.c2);
drop table t1,t2,t3,t4;
--echo #
--echo # MDEV-7904: ANALYZE FORMAT=JSON SELECT .. UNION SELECT doesn't print r_rows for union output
--echo #
create table t0 (a int);
INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int);
INSERT INTO t1 select * from t0;
--source include/analyze-format.inc
analyze format=json (select * from t1 tbl1 where a<5) union (select * from t1 tbl2 where a in (2,3));
drop table t0, t1;
--echo #
--echo # MDEV-7970: EXPLAIN FORMAT=JSON does not print HAVING
--source include/explain-no-costs.inc
--echo #
create table t0(a int);
insert into t0 values (0),(1),(2),(3);
create table t1(a int);
insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C;
create table t2 (
a int,
b int,
key (a)
);
insert into t2 select A.a*1000 + B.a, A.a*1000 + B.a from t0 A, t1 B;
--echo # normal HAVING
--source include/analyze-format.inc
analyze format=json select a, max(b) as TOP from t2 group by a having TOP > a;
--echo # HAVING is always TRUE (not printed)
--source include/analyze-format.inc
analyze format=json select a, max(b) as TOP from t2 group by a having 1<>2;
--echo # HAVING is always FALSE (intercepted by message)
--source include/analyze-format.inc
analyze format=json select a, max(b) as TOP from t2 group by a having 1=2;
--echo # HAVING is absent
--source include/analyze-format.inc
analyze format=json select a, max(b) as TOP from t2 group by a;
drop table t0, t1, t2;
--echo #
--echo # MDEV-7267: Server crashes in Item_field::print on ANALYZE FORMAT=JSON
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (3),(4);
--source include/analyze-format.inc
ANALYZE FORMAT=JSON SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 );
SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 );
drop table t1,t2;
--echo #
--echo # MDEV-8864: Server crash #2 in Item_field::print on ANALYZE FORMAT=JSON
--echo #
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (2),(3);
CREATE TABLE t3 (f3 INT) ENGINE=MyISAM;
INSERT INTO t3 VALUES (3),(4);
--source include/analyze-format.inc
ANALYZE FORMAT=JSON
SELECT GROUP_CONCAT(f3) AS gc, ( SELECT MAX(f1) FROM t1, t2 WHERE f2 = f3 ) sq
FROM t2, t3
WHERE f3 IN ( 1, 2 )
GROUP BY sq ORDER BY gc;
drop table t1,t2,t3;
--echo #
--echo # MDEV-13286: Floating point exception in Filesort_tracker::print_json_members(Json_writer*)
--echo #
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int, b int, c int);
insert into t1 select a,a,a from t0;
create table t2 as select * from t1;
--source include/analyze-format.inc
analyze format=json select a, (select t2.b from t2 where t2.a<t1.a order by t2.c limit 1) from t1 where t1.a<0;
drop table t0,t1,t2;
--echo #
--echo # MDEV-30806: ANALYZE FORMAT=JSON: better support for BNL and BNL-H joins
--echo #
--source include/have_sequence.inc
create table t10 (
a int,
b int
);
insert into t10 select seq, seq/3 from seq_0_to_999;
create table t11 (
a int,
b int
);
insert into t11 select seq, seq/5 from seq_0_to_999;
analyze table t10,t11 persistent for all;
--source include/analyze-format.inc
analyze format=json
select * from t10, t11
where
t10.a < 700 and
t11.a < 100
and t10.b=t11.b;
set @tmp=@@join_cache_level, join_cache_level=6;
--source include/analyze-format.inc
analyze format=json
select * from t10, t11
where
t10.a < 700 and
t11.a < 100
and t10.b=t11.b;
set join_cache_level=@tmp;
drop table t10, t11;
--echo #
--echo # MDEV-18478: ANALYZE for statement should show selectivity of
--echo # pushed index condition
--echo #
create table t12 (a int, b varchar(10), c int, index(a,b), index(c));
create table t13 (a int not null primary key, b int, index(b));
insert into t12(a,b,c) values (1,"abc",100),
(2,"abd",200),(2,"bfd",300),(2,"efg",400),
(3,"abc",410),(3,"def",420),(3,"ghi",430),(3,"jkl",440),
(4,"abc",600),(4,"def",700),(4,"ghi",800),(4,"jkl",900);
insert into t13(a,b) values(1,1),(2,2),(3,3),(4,4),(5,5);
analyze table t12;
analyze table t13;
-- echo # eq key condition only, no pushed condition
# no r_pushed_condition in output because there is no pushed condition
# a=2 qualifies 3 rows (r_rows=3)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2;
-- echo # pushed index condition
# key condition a=2 gets 3 rows
# pushed condition b like '%f%' filters down to two of the 3 rows (66.667%)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2 and t12.b like '%f%';
-- echo # rowid filter only, no pushed condition
# key condition a=2 gets 3 rows
# rowid filter condition between 400 and 500 qualifies 1 of the 3 key rows (33.33%)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2 and t12.c
between 400 and 500;
-- echo # pushed index condition and rowid filter
# key condition a=2 gets 3 rows
# pushed condition b like '%f%' filters down to 2 of the 3 key rows (66.667%)
# rowid filter condition between 400 and 500 filters down to 1 of the icp 2 rows (50%)
--source include/analyze-format.inc
analyze format=json select * from t12 where t12.a=2 and t12.c
between 400 and 500 and t12.b like '%f%';
-- echo # pushed index condition on the inner table (t12) of a join
# for inner table t12, key t12.a=t13.a
# for t13.a=1, 1 matching row in t12, 100% filtered by the index condition (t12.b like '%f%')
# for t13.a=2, 3 matching rows in t12, 66% filtered by the index cond
# r_rows_idx=2 (average 4 (1+3)/2 scans = 2 rows per scan)
# r_icp_filtered=50 (4 rows total, 2 survive the icp, both in the second scan)
--source include/analyze-format.inc
analyze format=json select * from t13,t12
where t13.a between 1 and 2 and t12.a=t13.a and t12.b like '%f%';
-- echo # rowid filter on inner table of a join, no ICP
# inner table t12, key t12.a=t13.a
# for t13.a=1, 1 matching row in t12, 0% survive the rowid filter (t12.c between 400 and 500)
# for t13.a=2, 3 matching rows in t12, 33% (1/3) survive the rowid filter
# rowid_filter r_lookups=2 (1+3 / 2 loops)
# rowid_filter r_selectivity_pct = 25 (1 / (1+3))
--source include/analyze-format.inc
analyze format=json select * from t13,t12 where t13.b between 1 and 2 and t12.a=t13.a and t12.c
between 400 and 450;
-- echo # rowid filter and ICP on inner table of a join
# inner table t12, key t12.a=t13.a
# for t13.a=1, 1 matching row in t12, 100% filtered by the index condition (t12.b like '%f%')
# for t13.a=2, 3 matching rows in t12, 66% filtered by the index cond
# r_rows_idx=2 (average 4 (1+3)/2 scans = 2 rows per scan)
# r_icp_filtered=50 (4 rows total, 2 survive the icp, both in the second scan)
# for t13.a=1, 0 rows after ICP
# for t13.a=2, 2 rows after ICP, 1 survives the rowid_filter (t12.c bewteen 400 and 500)
# rowid_filter r_lookups=2 (2 / 2 loops)
# rowid_filter r_selectivity_pct = 50 (1 survived / 2 rows after ICP)
--source include/analyze-format.inc
analyze format=json select * from t13,t12 where t13.b between 1 and 2 and t12.a=t13.a and t12.c
between 400 and 450 and t12.b like '%f%';
drop table t12,t13;
|