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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
|
--echo # WL#6369: EXPLAIN for other query
# JSON format is different in hypergraph. And TRADITIONAL format does not work
# with hypergraph.
--source include/not_hypergraph.inc
#
# We need the Debug Sync Facility.
#
--source include/have_debug.inc
--source include/have_debug_sync.inc
CREATE DATABASE mysqltest1;
USE mysqltest1;
CREATE TABLE t1 (f1 int);
INSERT INTO t1 VALUES (1),(2);
let $QID= `SELECT CONNECTION_ID()`;
# Hide connection ID
--disable_query_log
--error 1295
--eval PREPARE stmt FROM "EXPLAIN FOR CONNECTION $QID";
--enable_query_log
connect (ce, localhost, root,, mysqltest1);
connect (cq, localhost, root,, mysqltest1);
# Kill explaining query
# Test could be enabled when mysqltest will be able to 'send' two commands
# at once. Meanwhile, one could use 3 command line clients to run this test
# manually.
#connection ce;
#let $EID= `SELECT CONNECTION_ID()`;
#
#connection cq;
#let $QID= `SELECT CONNECTION_ID()`;
#SET DEBUG_SYNC="before_join_exec SIGNAL explain_me WAIT_FOR killed";
#send SELECT * FROM t1;
#
#connection ce;
#SET DEBUG_SYNC="now WAIT_FOR explain_me";
#SET DEBUG_SYNC="explain_other_got_thd SIGNAL killme WAIT_FOR killed";
#send EXPLAIN FOR CONNECTION $QID;
#
#connect (ck, localhost, root,, mysqltest1);
#connection ck;
#SET DEBUG_SYNC="now WAIT_FOR killme";
#SET DEBUG_SYNC="kill_thd_end SIGNAL killed";
#eval KILL $EID;
#
#connection ce;
#reap;
#
#connection cq;
#reap;
# Kill query being explained
# Test could be enabled when mysqltest will be able to 'send' two commands
# at once. Meanwhile, one could use 3 command line clients to run this test
# manually.
#connection ce;
#let $EID= `SELECT CONNECTION_ID()`;
#
#connection cq;
#let $QID= `SELECT CONNECTION_ID()`;
#SET DEBUG_SYNC="before_join_exec SIGNAL explain_me WAIT_FOR killed";
#send SELECT * FROM t1;
#
#connection ce;
#SET DEBUG_SYNC="now WAIT_FOR explain_me";
#SET DEBUG_SYNC="explain_other_got_thd SIGNAL killme WAIT_FOR killed";
#send EXPLAIN FOR CONNECTION $QID;
#
#connect (ck, localhost, root,, mysqltest1);
#connection ck;
#SET DEBUG_SYNC="now WAIT_FOR killme";
#SET DEBUG_SYNC="kill_thd_end SIGNAL killed";
#eval KILL $QID;
#
#connection ce;
#reap;
#
#connection cq;
#reap;
connection cq;
--echo Test error throwing
# Can''t explain EXPLAIN
let $point= before_set_plan;
let $err=ER_EXPLAIN_NOT_SUPPORTED;
let $query= EXPLAIN SELECT f1 FROM t1;
--source include/explain_other.inc
# Can''t explain statements not supported by regular EXPLAIN
let $point= before_join_exec;
let $query= SHOW FIELDS IN t1;
--source include/explain_other.inc
# Can''t be used in prepared statement
--error 1295
PREPARE stmt FROM 'EXPLAIN FOR CONNECTION 1';
# Can''t explain prepared statement
connection cq;
PREPARE stmt FROM 'SELECT * FROM t1';
connection ce;
let $query= EXECUTE stmt;
--source include/explain_other.inc
# Can''t be used from a procedure
--error 1235
CREATE PROCEDURE proc6369()
EXPLAIN FOR CONNECTION 1;
# Can''t explain a statement in a procedure
CREATE PROCEDURE proc6369()
SELECT * FROM t1;
let $point= before_join_exec;
let $query= CALL proc6369();
let $err= ER_EXPLAIN_NOT_SUPPORTED;
--source include/explain_other.inc
DROP PROCEDURE proc6369;
# Can''t explain itself
# Connection id could vary, hide it.
--disable_query_log
let $qid= `SELECT CONNECTION_ID()`;
--error ER_EXPLAIN_NOT_SUPPORTED
eval EXPLAIN FOR CONNECTION $qid;
--enable_query_log
# Explain for non-existing connection
--error ER_NO_SUCH_THREAD
EXPLAIN FOR CONNECTION 11111111;
--echo Explain queries with ready plan
let $err=0;
let $query= SELECT f1 FROM t1;
--source include/explain_other.inc
let $query= SELECT * FROM (SELECT * FROM t1) tt;
--source include/explain_other.inc
let $query= SELECT * FROM t1 WHERE f1 IN (SELECT * FROM t1);
--source include/explain_other.inc
let $query= SELECT * FROM t1 UNION ALL SELECT * FROM t1 ORDER BY 1;
--source include/explain_other.inc
let $format= json;
let $query= SELECT f1 FROM t1;
--source include/explain_other.inc
let $query= SELECT * FROM (SELECT * FROM t1) tt;
--source include/explain_other.inc
let $query= SELECT * FROM t1 WHERE f1 IN (SELECT * FROM t1);
--source include/explain_other.inc
let $query= SELECT * FROM t1 UNION ALL SELECT * FROM t1 ORDER BY 1;
--source include/explain_other.inc
# Show zero result cause
let $query= SELECT * FROM t1 WHERE 1=0;
--source include/explain_other.inc
--source include/turn_off_only_full_group_by.inc
let $query= SELECT * FROM t1
GROUP BY f1 NOT IN
(SELECT f1+10 AS f2 FROM t1 AS t2
GROUP BY f2 NOT IN
(SELECT f1+100 AS f3 FROM t1 AS t3));
--source include/explain_other.inc
--source include/restore_sql_mode_after_turn_off_only_full_group_by.inc
--echo Explain for non-select queries
let $point= planned_single_insert;
let $query= INSERT INTO t1 VALUES (3);
--source include/explain_other.inc
let $point= before_join_exec;
let $query= INSERT INTO t1 SELECT 4;
--source include/explain_other.inc
let $query= INSERT INTO t1 SELECT f1 + 4 FROM t1;
--source include/explain_other.inc
let $point= before_single_update;
let $query= UPDATE t1 SET f1=4 WHERE f1=4;
--source include/explain_other.inc
let $point= planned_single_update;
let $query= UPDATE t1 SET f1=4 WHERE f1=4;
--source include/explain_other.inc
CREATE TABLE t2 (f2 int);
let $query= UPDATE t1 SET f1=f1+0
ORDER BY f1 NOT IN
(SELECT f1+10 AS f2 FROM t2
GROUP BY f2 NOT IN
(SELECT f1+100 AS f3 FROM t2 AS t3));
--source include/explain_other.inc
CREATE VIEW v1 AS SELECT t1.f1 FROM t1 JOIN t1 tt on t1.f1=tt.f1;
let $point= before_join_exec;
let $query= UPDATE v1 SET f1=5 WHERE f1=5;
--source include/explain_other.inc
let $point= planned_single_delete;
let $query= DELETE FROM t1 WHERE f1=4;
--source include/explain_other.inc
let $format= traditional;
let $point= planned_single_insert;
let $query= INSERT INTO t1 VALUES (3);
--source include/explain_other.inc
let $point= before_join_exec;
let $query= INSERT INTO t1 SELECT 4;
--source include/explain_other.inc
let $query= INSERT INTO t1 SELECT f1 + 4 FROM t1;
--source include/explain_other.inc
let $point= planned_single_update;
let $query= UPDATE t1 SET f1=4 WHERE f1=4;
--source include/explain_other.inc
let $point= before_join_exec;
let $query= UPDATE v1 SET f1=5 WHERE f1=5;
--source include/explain_other.inc
let $point= planned_single_delete;
let $query= DELETE FROM t1 WHERE f1=4;
--source include/explain_other.inc
--echo Explain queries with plan only partially ready
let $point= after_join_optimize;
let $format= traditional;
let $query= SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt;
--source include/explain_other.inc
let $query= SELECT * FROM t1 UNION ALL SELECT * FROM t1 ORDER BY
(SELECT * FROM t1 LIMIT 1);
--source include/explain_other.inc
let $format= json;
let $query= SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt;
--source include/explain_other.inc
let $query= SELECT * FROM t1 UNION ALL SELECT * FROM t1 ORDER BY
(SELECT * FROM t1 LIMIT 1);
--source include/explain_other.inc
--echo Ensure materialized derived still has plans after materialization
set @optimizer_switch_saved= @@optimizer_switch;
set optimizer_switch='derived_merge=off';
let $point= after_materialize_derived;
let $format= traditional;
let $query= SELECT * FROM (SELECT * FROM t1) tt;
--source include/explain_other.inc
let $format= json;
--source include/explain_other.inc
set optimizer_switch= @optimizer_switch_saved;
--echo WHERE subqueries, neither parent query nor subquery has plan
let $point= before_set_plan;
let $err=0;
let $query= SELECT t2.f1 FROM t1 STRAIGHT_JOIN t1 AS t2
WHERE t1.f1>(SELECT t3.f1 FROM t1 AS t3 LIMIT 1);
--source include/explain_other.inc
--echo the same, parent query has a plan
let $point= after_join_optimize;
let $err=0;
let $query= SELECT t2.f1 FROM t1 STRAIGHT_JOIN t1 AS t2
WHERE t1.f1>(SELECT t3.f1 FROM t1 AS t3 LIMIT 1);
--source include/explain_other.inc
--echo the same, both have a plan
let $point= before_reset_query_plan;
let $err=0;
let $query= SELECT t2.f1 FROM t1 STRAIGHT_JOIN t1 AS t2
WHERE t1.f1>(SELECT t3.f1 FROM t1 AS t3 LIMIT 1);
--source include/explain_other.inc
--echo To be compared with regular EXPLAIN:
eval EXPLAIN FORMAT=JSON $query;
let $query= SELECT 1 FROM t1 WHERE
ROW(f1,f1) >= ROW('1', (SELECT 1 FROM t1 WHERE f1 > 1234));
--source include/explain_other.inc
eval EXPLAIN FORMAT=JSON $query;
CREATE TABLE t3 (pk INT PRIMARY KEY);
INSERT INTO t3 SELECT DISTINCT * FROM t1;
let $query= SELECT * FROM t3 WHERE pk=(SELECT f1 FROM t1 limit 1);
--source include/explain_other.inc
connection default;
disconnect ce;
--echo # Check access rights checking
connection cq;
CREATE USER 'privtest'@'localhost';
GRANT SUPER ON *.* TO 'privtest'@'localhost';
GRANT SELECT ON mysqltest1.t2 TO 'privtest'@'localhost';
CREATE VIEW v2 AS SELECT * FROM t2;
GRANT SELECT,INSERT,UPDATE ON mysqltest1.v2 TO 'privtest'@'localhost';
connect (ce, localhost, privtest,, mysqltest1);
# Show ACCESS DENIED for queries of other users
let $point= before_join_exec;
let $format= traditional;
let $query= SELECT f1 FROM t1;
let $err= 1045;
--source include/explain_other.inc
SELECT f2 FROM v2;
let $query= SELECT f2 FROM v2;
let $err=1045;
--source include/explain_other.inc
disconnect cq;
connect (cq, localhost, privtest,, mysqltest1);
# Show EXPLAIN CAN''T BE ISSUED if user lacks EXPLAIN rights, but can
# execute statement.
UPDATE v2 SET f2=1;
let $query= UPDATE v2 SET f2=1;
let $point= planned_single_update;
let $err=1345;
--source include/explain_other.inc
INSERT INTO v2 VALUES(1);
let $query= INSERT INTO v2 VALUES(1);
let $point= planned_single_insert;
let $err=1345;
--source include/explain_other.inc
INSERT INTO v2 SELECT 3 FROM t2;
let $query= INSERT INTO v2 SELECT 3 FROM t2;
let $point= before_join_exec;
let $err=1345;
--source include/explain_other.inc
SELECT f2 FROM v2;
--error 1345
EXPLAIN SELECT f2 FROM v2;
connection default;
DROP USER 'privtest'@localhost;
DROP VIEW v1, v2;
DROP TABLE t1, t2, t3;
disconnect ce;
disconnect cq;
# Reconnect as root for non-priv bugs tests
connect (ce, localhost, root,, mysqltest1);
connect (cq, localhost, root,, mysqltest1);
connection ce;
--echo #
--echo # Bug#14586538: EXPLAIN OTHER RESULT NOT MATCHING WITH EXPLAIN
--echo #
CREATE TABLE h2 (
pk int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (pk)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
insert into h2 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
ANALYZE TABLE h2;
CREATE TABLE aa3 (
col_int_key int(11) DEFAULT NULL,
KEY col_int_key (col_int_key)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
let $point= before_join_exec;
let $err= 0;
let $query= SELECT alias1.pk AS field1 FROM h2 AS alias1 LEFT JOIN aa3 AS alias2 ON alias1.pk = alias2.col_int_key WHERE alias1.pk <> 9 GROUP BY field1 ORDER BY field1 LIMIT 1 OFFSET 3;
--eval EXPLAIN $query;
--echo Should show same # of rows as above
--source include/explain_other.inc
DROP TABLE h2, aa3;
--echo #
--echo # Bug#14591376: EXPLAIN OTHER RESULT NOT MATCHING WITH EXPLAIN - REF
--echo #
CREATE TABLE t1 (
pk int(11),
col_int_key int(11) DEFAULT NULL,
KEY col_int_key (col_int_key)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (NULL,NULL);
INSERT INTO t1 VALUES (6,NULL);
INSERT INTO t1 VALUES (8,-1131610112);
INSERT INTO t1 VALUES (2,-1009057792);
INSERT INTO t1 VALUES (-1220345856,1);
INSERT INTO t1 VALUES (NULL,-185204736);
let $query= SELECT pk FROM t1 WHERE col_int_key= 8;
--source include/explain_other.inc
DROP TABLE t1;
--echo # From Bug#14463247 MYSQL CRASHES ON THE QUERY
--echo #
CREATE TABLE tbl1 (
login int(11) NOT NULL,
numb decimal(15,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (login),
KEY numb (numb)
) ;
CREATE TABLE tbl2 (
login int(11) NOT NULL,
cmd tinyint(4) NOT NULL,
nump decimal(15,2) NOT NULL DEFAULT '0.00',
KEY cmd (cmd),
KEY login (login)
) ;
insert into tbl1 (login) values(1),(2);
insert ignore into tbl2 (login) values(1),(2);
-- disable_query_log
-- disable_result_log
ANALYZE TABLE tbl1, tbl2;
-- enable_result_log
-- enable_query_log
let $point= before_reset_query_plan;
let $query=
SELECT
t1.login AS tlogin,
numb -
IFNULL((SELECT sum(nump) FROM tbl2 WHERE login=t1.login), 0) -
IFNULL((SELECT sum(nump) FROM tbl2 WHERE login=t1.login), 0) as sp
FROM tbl1 t1, tbl2 t2
WHERE t1.login=t2.login
GROUP BY t1.login
ORDER BY numb - IFNULL((SELECT sum(nump) FROM tbl2 WHERE login=t1.login), 0)
- IFNULL((SELECT sum(nump) FROM tbl2 WHERE login=t1.login), 0)
;
--source include/explain_other.inc
let $format= json;
--source include/explain_other.inc
DROP TABLE tbl1, tbl2;
--echo # End of tests for WL#6369
--echo #
--echo # Bug#19822146 EXPLAIN FOR CONNECTION CRASHES IN
--echo # EXPLAIN_JOIN::EXPLAIN_QEP_TAB
--echo #
connection default;
create table t1(a char(10) charset latin1, key(a)) engine=innodb;
create table t2(a binary(10), key(a)) engine=innodb;
insert into t1 values('1'),('2'),('3'),('4');
insert into t2 values('1'),('2'),('s');
analyze table t1,t2;
let $query= select 1 from t1 inner join t2 using(a);
--echo # Connection cq
connection cq;
--disable_query_log
let $QID= `SELECT CONNECTION_ID()`;
--enable_query_log
--echo # Let thread1 to suspend itself right before creating Quick object.
SET DEBUG_SYNC= 'quick_not_created SIGNAL ready_for_explain WAIT_FOR explained';
--send_eval $query;
--echo # Connection ce
connection ce;
SET DEBUG_SYNC= 'now WAIT_FOR ready_for_explain';
SET DEBUG_SYNC= 'after_explain_other SIGNAL explained';
--disable_query_log
eval EXPLAIN FOR CONNECTION $QID;
--enable_query_log
connection cq;
--echo connection: cq
--reap
connection default;
SET DEBUG_SYNC= 'RESET';
--echo # Connection cq
connection cq;
--echo # Let thread1 to suspend itself right before the mutex section.
SET DEBUG_SYNC= 'quick_created_before_mutex SIGNAL ready_for_explain WAIT_FOR explained';
--send_eval $query;
--echo # Connection ce
connection ce;
SET DEBUG_SYNC= 'now WAIT_FOR ready_for_explain';
SET DEBUG_SYNC= 'after_explain_other SIGNAL explained';
--disable_query_log
eval EXPLAIN FOR CONNECTION $QID;
--enable_query_log
connection cq;
--echo connection: cq
--reap
connection default;
SET DEBUG_SYNC= 'RESET';
--echo # Connection cq
connection cq;
--echo # Let thread1 to suspend itself right after quick object is droped.
SET DEBUG_SYNC= 'quick_droped_after_mutex SIGNAL ready_for_explain WAIT_FOR explained';
--send_eval $query;
--echo # Connection ce
connection ce;
SET DEBUG_SYNC= 'now WAIT_FOR ready_for_explain';
SET DEBUG_SYNC= 'after_explain_other SIGNAL explained';
--disable_query_log
eval EXPLAIN FOR CONNECTION $QID;
--enable_query_log
connection cq;
--echo connection: cq
--reap
--echo # Connection default
connection default;
DROP TABLE t1, t2;
--echo # End of test Bug#19822146
--echo #
--echo # Bug#25422034 CRASH IN TABLE_LIST::QUERY_BLOCK_ID_FOR_EXPLAIN DURING EXPLAIN FOR CONNECTION
--echo #
connection default;
create table t1(a int);
insert into t1 values(1),(2);
let $query= select * from (select * from t1) dt;
let $point= derived_not_set;
let $format= traditional;
# Stmt is of a supported type, but cannot be explained while in resolution
let $err= ER_EXPLAIN_NOT_SUPPORTED;
--source include/explain_other.inc
let $err=0;
DROP TABLE t1;
SET DEBUG_SYNC= 'RESET';
USE test;
DROP DATABASE mysqltest1;
--echo # End of test
disconnect cq;
disconnect ce;
|