1set optimizer_trace_max_mem_size=1048576; 2set end_markers_in_json=on; 3set optimizer_trace="enabled=on"; 4# check that if a sub-statement should not be traced, 5# it is not traced even if inside a traced top statement 6 7set optimizer_trace_offset=0, optimizer_trace_limit=100; 8create function f1(arg char(1)) returns int 9begin 10declare res int; 11declare dummy varchar(1); 12select 1 into res from dual; 13select TRACE+NULL into dummy from information_schema.OPTIMIZER_TRACE limit 1; 14select 2 into res from dual; 15return 3; 16end| 17select f1("c")| 18f1("c") 193 20 21select * from information_schema.OPTIMIZER_TRACE| 22QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 23select f1("c") { 24 "steps": [ 25 { 26 "join_preparation": { 27 "select#": 1, 28 "steps": [ 29 { 30 "expanded_query": "/* select#1 */ select `f1`('c') AS `f1(\"c\")`" 31 } 32 ] /* steps */ 33 } /* join_preparation */ 34 }, 35 { 36 "join_optimization": { 37 "select#": 1, 38 "steps": [ 39 ] /* steps */ 40 } /* join_optimization */ 41 }, 42 { 43 "join_execution": { 44 "select#": 1, 45 "steps": [ 46 ] /* steps */ 47 } /* join_execution */ 48 } 49 ] /* steps */ 50} 0 0 51set res@1 NULL { 52 "steps": [ 53 ] /* steps */ 54} 0 0 55set dummy@2 NULL { 56 "steps": [ 57 ] /* steps */ 58} 0 0 59select 1 into res from dual { 60 "steps": [ 61 { 62 "join_preparation": { 63 "select#": 1, 64 "steps": [ 65 { 66 "expanded_query": "/* select#1 */ select 1 AS `1`" 67 } 68 ] /* steps */ 69 } /* join_preparation */ 70 }, 71 { 72 "join_optimization": { 73 "select#": 1, 74 "steps": [ 75 ] /* steps */ 76 } /* join_optimization */ 77 }, 78 { 79 "join_execution": { 80 "select#": 1, 81 "steps": [ 82 ] /* steps */ 83 } /* join_execution */ 84 } 85 ] /* steps */ 86} 0 0 87select 2 into res from dual { 88 "steps": [ 89 { 90 "join_preparation": { 91 "select#": 1, 92 "steps": [ 93 { 94 "expanded_query": "/* select#1 */ select 2 AS `2`" 95 } 96 ] /* steps */ 97 } /* join_preparation */ 98 }, 99 { 100 "join_optimization": { 101 "select#": 1, 102 "steps": [ 103 ] /* steps */ 104 } /* join_optimization */ 105 }, 106 { 107 "join_execution": { 108 "select#": 1, 109 "steps": [ 110 ] /* steps */ 111 } /* join_execution */ 112 } 113 ] /* steps */ 114} 0 0 115freturn 3 3 { 116 "steps": [ 117 ] /* steps */ 118} 0 0 119set optimizer_trace_offset=default, optimizer_trace_limit=default; 120drop function f1; 121# check that if a tracing gets disabled in a routine's body, 122# substatements are not traced 123 124set optimizer_trace_offset=0, optimizer_trace_limit=100; 125create function f1(arg char(1)) returns int 126begin 127declare res int; 128declare dummy varchar(1); 129set optimizer_trace="enabled=off"; 130select 1 into res from dual; 131select TRACE+NULL into dummy from information_schema.OPTIMIZER_TRACE limit 1; 132select 2 into res from dual; 133return 3; 134end| 135select f1("c")| 136f1("c") 1373 138 139select * from information_schema.OPTIMIZER_TRACE| 140QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 141select f1("c") { 142 "steps": [ 143 { 144 "join_preparation": { 145 "select#": 1, 146 "steps": [ 147 { 148 "expanded_query": "/* select#1 */ select `f1`('c') AS `f1(\"c\")`" 149 } 150 ] /* steps */ 151 } /* join_preparation */ 152 }, 153 { 154 "join_optimization": { 155 "select#": 1, 156 "steps": [ 157 ] /* steps */ 158 } /* join_optimization */ 159 }, 160 { 161 "join_execution": { 162 "select#": 1, 163 "steps": [ 164 ] /* steps */ 165 } /* join_execution */ 166 } 167 ] /* steps */ 168} 0 0 169set res@1 NULL { 170 "steps": [ 171 ] /* steps */ 172} 0 0 173set dummy@2 NULL { 174 "steps": [ 175 ] /* steps */ 176} 0 0 177set optimizer_trace_offset=default, optimizer_trace_limit=default; 178select @@optimizer_trace; 179@@optimizer_trace 180enabled=off,one_line=off 181set optimizer_trace="enabled=on"; 182drop function f1; 183 184# Check that if a sub-statement reads OPTIMIZER_TRACE, 185# thus reading the unfinished trace of its caller statement, 186# there is no crash. 187 188create temporary table optt 189(id int primary key auto_increment, 190QUERY varchar(200), 191TRACE text); 192create table t1 (a int, key(a)); 193insert into t1 values(2); 194set optimizer_trace_offset=0, optimizer_trace_limit=100; 195create function f1(arg char(1)) returns int 196begin 197declare res int; 198insert into optt select NULL, QUERY, TRACE from information_schema.OPTIMIZER_TRACE; 199return 3; 200end| 201select * from t1 where a in (select f1("c") from t1)| 202a 203 204set optimizer_trace="enabled=off"; 205this should find unfinished traces 206select count(*) from optt where TRACE NOT LIKE "%] /* steps */\n}"; 207count(*) 2081 209select count(*)<>0 from optt; 210count(*)<>0 2111 212this should not 213select count(*) from information_schema.OPTIMIZER_TRACE where TRACE NOT LIKE "%] /* steps */\n}"; 214count(*) 2150 216select count(*)<>0 from information_schema.OPTIMIZER_TRACE; 217count(*)<>0 2181 219set optimizer_trace_offset=default, optimizer_trace_limit=default; 220drop temporary table optt; 221drop function f1; 222drop table t1; 223set optimizer_trace="enabled=on"; 224 225# check of crash with I_S.VIEWS (TABLE_LIST::alias==NULL) 226 227create table t1(a int, b int); 228create view v1 as select a from t1; 229select VIEW_DEFINITION from information_schema.VIEWS 230where TABLE_SCHEMA="test" and TABLE_NAME="v1"; 231VIEW_DEFINITION 232select `test`.`t1`.`a` AS `a` from `test`.`t1` 233drop table t1; 234drop view v1; 235 236# check for readable display of BIT values 237 238create table t1 (a bit(5), key(a)); 239insert into t1 values(b'00000'),(b'01101'); 240select cast(a as unsigned) from t1 where a > b'01100'; 241cast(a as unsigned) 24213 243select TRACE from information_schema.OPTIMIZER_TRACE; 244TRACE 245{ 246 "steps": [ 247 { 248 "join_preparation": { 249 "select#": 1, 250 "steps": [ 251 { 252 "expanded_query": "/* select#1 */ select cast(`t1`.`a` as unsigned) AS `cast(a as unsigned)` from `t1` where (`t1`.`a` > 0x0c)" 253 } 254 ] /* steps */ 255 } /* join_preparation */ 256 }, 257 { 258 "join_optimization": { 259 "select#": 1, 260 "steps": [ 261 { 262 "condition_processing": { 263 "condition": "WHERE", 264 "original_condition": "(`t1`.`a` > 0x0c)", 265 "steps": [ 266 { 267 "transformation": "equality_propagation", 268 "resulting_condition": "(`t1`.`a` > 0x0c)" 269 }, 270 { 271 "transformation": "constant_propagation", 272 "resulting_condition": "(`t1`.`a` > 0x0c)" 273 }, 274 { 275 "transformation": "trivial_condition_removal", 276 "resulting_condition": "(`t1`.`a` > 0x0c)" 277 } 278 ] /* steps */ 279 } /* condition_processing */ 280 }, 281 { 282 "substitute_generated_columns": { 283 } /* substitute_generated_columns */ 284 }, 285 { 286 "table_dependencies": [ 287 { 288 "table": "`t1`", 289 "row_may_be_null": false, 290 "map_bit": 0, 291 "depends_on_map_bits": [ 292 ] /* depends_on_map_bits */ 293 } 294 ] /* table_dependencies */ 295 }, 296 { 297 "ref_optimizer_key_uses": [ 298 ] /* ref_optimizer_key_uses */ 299 }, 300 { 301 "rows_estimation": [ 302 { 303 "table": "`t1`", 304 "range_analysis": { 305 "table_scan": { 306 "rows": 2, 307 "cost": 4.5034 308 } /* table_scan */, 309 "potential_range_indexes": [ 310 { 311 "index": "a", 312 "usable": true, 313 "key_parts": [ 314 "a" 315 ] /* key_parts */ 316 } 317 ] /* potential_range_indexes */, 318 "best_covering_index_scan": { 319 "index": "a", 320 "cost": 1.4175, 321 "chosen": true 322 } /* best_covering_index_scan */, 323 "setup_range_conditions": [ 324 ] /* setup_range_conditions */, 325 "group_index_range": { 326 "chosen": false, 327 "cause": "not_group_by_or_distinct" 328 } /* group_index_range */, 329 "analyzing_range_alternatives": { 330 "range_scan_alternatives": [ 331 { 332 "index": "a", 333 "ranges": [ 334 "12 < a" 335 ] /* ranges */, 336 "index_dives_for_eq_ranges": true, 337 "rowid_ordered": false, 338 "using_mrr": false, 339 "index_only": true, 340 "rows": 2, 341 "cost": 1.4275, 342 "chosen": false, 343 "cause": "cost" 344 } 345 ] /* range_scan_alternatives */, 346 "analyzing_roworder_intersect": { 347 "usable": false, 348 "cause": "too_few_roworder_scans" 349 } /* analyzing_roworder_intersect */ 350 } /* analyzing_range_alternatives */ 351 } /* range_analysis */ 352 } 353 ] /* rows_estimation */ 354 }, 355 { 356 "considered_execution_plans": [ 357 { 358 "plan_prefix": [ 359 ] /* plan_prefix */, 360 "table": "`t1`", 361 "best_access_path": { 362 "considered_access_paths": [ 363 { 364 "rows_to_scan": 2, 365 "access_type": "scan", 366 "resulting_rows": 2, 367 "cost": 2.4034, 368 "chosen": true 369 } 370 ] /* considered_access_paths */ 371 } /* best_access_path */, 372 "condition_filtering_pct": 100, 373 "rows_for_plan": 2, 374 "cost_for_plan": 2.4034, 375 "chosen": true 376 } 377 ] /* considered_execution_plans */ 378 }, 379 { 380 "attaching_conditions_to_tables": { 381 "original_condition": "(`t1`.`a` > 0x0c)", 382 "attached_conditions_computation": [ 383 ] /* attached_conditions_computation */, 384 "attached_conditions_summary": [ 385 { 386 "table": "`t1`", 387 "attached": "(`t1`.`a` > 0x0c)" 388 } 389 ] /* attached_conditions_summary */ 390 } /* attaching_conditions_to_tables */ 391 }, 392 { 393 "refine_plan": [ 394 { 395 "table": "`t1`" 396 } 397 ] /* refine_plan */ 398 } 399 ] /* steps */ 400 } /* join_optimization */ 401 }, 402 { 403 "join_execution": { 404 "select#": 1, 405 "steps": [ 406 ] /* steps */ 407 } /* join_execution */ 408 } 409 ] /* steps */ 410} 411drop table t1; 412 413# check that trace lists all pushed down ON conditions 414 415create table t1 (i int not null); 416insert into t1 values (0), (2),(3),(4); 417create table t2 (i int not null); 418insert into t2 values (0),(1), (3),(4); 419create table t3 (i int not null); 420insert into t3 values (0),(1),(2), (4); 421select * from 422t1 LEFT JOIN 423( t2 LEFT JOIN 424( t3 425) 426ON t3.i = t2.i 427) 428ON t2.i = t1.i 429WHERE t3.i IS NULL 430; 431i i i 4323 3 NULL 4332 NULL NULL 434select TRACE from information_schema.OPTIMIZER_TRACE; 435TRACE 436{ 437 "steps": [ 438 { 439 "join_preparation": { 440 "select#": 1, 441 "steps": [ 442 { 443 "expanded_query": "/* select#1 */ select `t1`.`i` AS `i`,`t2`.`i` AS `i`,`t3`.`i` AS `i` from (`t1` left join (`t2` left join `t3` on((`t3`.`i` = `t2`.`i`))) on((`t2`.`i` = `t1`.`i`))) where isnull(`t3`.`i`)" 444 }, 445 { 446 "transformations_to_nested_joins": { 447 "transformations": [ 448 "parenthesis_removal" 449 ] /* transformations */, 450 "expanded_query": "/* select#1 */ select `t1`.`i` AS `i`,`t2`.`i` AS `i`,`t3`.`i` AS `i` from `t1` left join (`t2` left join `t3` on((`t3`.`i` = `t2`.`i`))) on((`t2`.`i` = `t1`.`i`)) where isnull(`t3`.`i`)" 451 } /* transformations_to_nested_joins */ 452 } 453 ] /* steps */ 454 } /* join_preparation */ 455 }, 456 { 457 "join_optimization": { 458 "select#": 1, 459 "steps": [ 460 { 461 "condition_processing": { 462 "condition": "WHERE", 463 "original_condition": "isnull(`t3`.`i`)", 464 "steps": [ 465 { 466 "transformation": "equality_propagation", 467 "resulting_condition": "isnull(`t3`.`i`)" 468 }, 469 { 470 "transformation": "constant_propagation", 471 "resulting_condition": "isnull(`t3`.`i`)" 472 }, 473 { 474 "transformation": "trivial_condition_removal", 475 "resulting_condition": "isnull(`t3`.`i`)" 476 } 477 ] /* steps */ 478 } /* condition_processing */ 479 }, 480 { 481 "substitute_generated_columns": { 482 } /* substitute_generated_columns */ 483 }, 484 { 485 "table_dependencies": [ 486 { 487 "table": "`t1`", 488 "row_may_be_null": false, 489 "map_bit": 0, 490 "depends_on_map_bits": [ 491 ] /* depends_on_map_bits */ 492 }, 493 { 494 "table": "`t2`", 495 "row_may_be_null": true, 496 "map_bit": 1, 497 "depends_on_map_bits": [ 498 0 499 ] /* depends_on_map_bits */ 500 }, 501 { 502 "table": "`t3`", 503 "row_may_be_null": true, 504 "map_bit": 2, 505 "depends_on_map_bits": [ 506 0, 507 1 508 ] /* depends_on_map_bits */ 509 } 510 ] /* table_dependencies */ 511 }, 512 { 513 "ref_optimizer_key_uses": [ 514 ] /* ref_optimizer_key_uses */ 515 }, 516 { 517 "rows_estimation": [ 518 { 519 "table": "`t1`", 520 "table_scan": { 521 "rows": 4, 522 "cost": 2 523 } /* table_scan */ 524 }, 525 { 526 "table": "`t2`", 527 "table_scan": { 528 "rows": 4, 529 "cost": 2 530 } /* table_scan */ 531 }, 532 { 533 "table": "`t3`", 534 "table_scan": { 535 "rows": 4, 536 "cost": 2 537 } /* table_scan */ 538 } 539 ] /* rows_estimation */ 540 }, 541 { 542 "considered_execution_plans": [ 543 { 544 "plan_prefix": [ 545 ] /* plan_prefix */, 546 "table": "`t1`", 547 "best_access_path": { 548 "considered_access_paths": [ 549 { 550 "rows_to_scan": 4, 551 "access_type": "scan", 552 "resulting_rows": 4, 553 "cost": 2.8068, 554 "chosen": true 555 } 556 ] /* considered_access_paths */ 557 } /* best_access_path */, 558 "condition_filtering_pct": 100, 559 "rows_for_plan": 4, 560 "cost_for_plan": 2.8068, 561 "rest_of_plan": [ 562 { 563 "plan_prefix": [ 564 "`t1`" 565 ] /* plan_prefix */, 566 "table": "`t2`", 567 "best_access_path": { 568 "considered_access_paths": [ 569 { 570 "rows_to_scan": 4, 571 "access_type": "scan", 572 "using_join_cache": true, 573 "buffers_needed": 1, 574 "resulting_rows": 4, 575 "cost": 5.207, 576 "chosen": true 577 } 578 ] /* considered_access_paths */ 579 } /* best_access_path */, 580 "condition_filtering_pct": 100, 581 "rows_for_plan": 16, 582 "cost_for_plan": 8.0138, 583 "rest_of_plan": [ 584 { 585 "plan_prefix": [ 586 "`t1`", 587 "`t2`" 588 ] /* plan_prefix */, 589 "table": "`t3`", 590 "best_access_path": { 591 "considered_access_paths": [ 592 { 593 "rows_to_scan": 4, 594 "access_type": "scan", 595 "using_join_cache": true, 596 "buffers_needed": 1, 597 "resulting_rows": 1, 598 "cost": 5.8083, 599 "chosen": true 600 } 601 ] /* considered_access_paths */ 602 } /* best_access_path */, 603 "condition_filtering_pct": 100, 604 "rows_for_plan": 16, 605 "cost_for_plan": 13.822, 606 "chosen": true 607 } 608 ] /* rest_of_plan */ 609 } 610 ] /* rest_of_plan */ 611 } 612 ] /* considered_execution_plans */ 613 }, 614 { 615 "attaching_conditions_to_tables": { 616 "original_condition": "isnull(`t3`.`i`)", 617 "attached_conditions_computation": [ 618 ] /* attached_conditions_computation */, 619 "attached_conditions_summary": [ 620 { 621 "table": "`t1`", 622 "attached": null 623 }, 624 { 625 "table": "`t2`", 626 "attached": "<if>(is_not_null_compl(t2..t3), (`t2`.`i` = `t1`.`i`), true)" 627 }, 628 { 629 "table": "`t3`", 630 "attached": "(<if>(found_match(t2..t3), <if>(found_match(t3), isnull(`t3`.`i`), true), true) and <if>(is_not_null_compl(t3), (`t3`.`i` = `t1`.`i`), true))" 631 } 632 ] /* attached_conditions_summary */ 633 } /* attaching_conditions_to_tables */ 634 }, 635 { 636 "refine_plan": [ 637 { 638 "table": "`t1`" 639 }, 640 { 641 "table": "`t2`" 642 }, 643 { 644 "table": "`t3`" 645 } 646 ] /* refine_plan */ 647 } 648 ] /* steps */ 649 } /* join_optimization */ 650 }, 651 { 652 "join_execution": { 653 "select#": 1, 654 "steps": [ 655 ] /* steps */ 656 } /* join_execution */ 657 } 658 ] /* steps */ 659} 660drop table t1,t2,t3; 661 662# test of tracing a query with an HAVING condition, in 663# ps-protocol, does not crash 664 665CREATE TABLE t1 (f1 INT, f2 VARCHAR(1)); 666INSERT INTO t1 VALUES (16,'f'); 667INSERT INTO t1 VALUES (16,'f'); 668CREATE TABLE t2 (f1 INT, f2 VARCHAR(1)); 669INSERT INTO t2 VALUES (13,'f'); 670INSERT INTO t2 VALUES (20,'f'); 671CREATE TABLE t3 (f1 INT, f2 VARCHAR(1)); 672INSERT INTO t3 VALUES (7,'f'); 673EXPLAIN SELECT t1.f2 FROM t1 674STRAIGHT_JOIN (t2 JOIN t3 ON t3.f2 = t2.f2 ) ON t3 .f2 = t2 .f2 675HAVING ('v', 'i') NOT IN (SELECT f2, MIN(f2) FROM t1) 676ORDER BY f2; 677id select_type table partitions type possible_keys key key_len ref rows filtered Extra 6781 PRIMARY t1 NULL ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort 6791 PRIMARY t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using join buffer (Block Nested Loop) 6801 PRIMARY t2 NULL ALL NULL NULL NULL NULL 2 50.00 Using where; Using join buffer (Block Nested Loop) 6812 SUBQUERY t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 682Warnings: 683Note 1003 /* select#1 */ select `test`.`t1`.`f2` AS `f2` from `test`.`t1` join `test`.`t2` join `test`.`t3` where (`test`.`t2`.`f2` = `test`.`t3`.`f2`) having (not(<in_optimizer>(<cache>(('v','i')),<exists>(/* select#2 */ select 1,1 from `test`.`t1` having (((<cache>('v') = `test`.`t1`.`f2`) or isnull(`test`.`t1`.`f2`)) and ((<cache>('i') = min(`test`.`t1`.`f2`)) or isnull(min(`test`.`t1`.`f2`))) and <is_not_null_test>(`test`.`t1`.`f2`) and <is_not_null_test>(min(`test`.`t1`.`f2`))))))) order by `test`.`t1`.`f2` 684SELECT t1.f2 FROM t1 685STRAIGHT_JOIN (t2 JOIN t3 ON t3.f2 = t2.f2 ) ON t3 .f2 = t2 .f2 686HAVING ('v', 'i') NOT IN (SELECT f2, MIN(f2) FROM t1) 687ORDER BY f2; 688f2 689f 690f 691f 692f 693select TRACE from information_schema.OPTIMIZER_TRACE; 694TRACE 695{ 696 "steps": [ 697 { 698 "join_preparation": { 699 "select#": 1, 700 "steps": [ 701 { 702 "join_preparation": { 703 "select#": 2, 704 "steps": [ 705 { 706 "expanded_query": "/* select#2 */ select `t1`.`f2`,min(`t1`.`f2`) from `t1`" 707 }, 708 { 709 "transformation": { 710 "select#": 2, 711 "from": "IN (SELECT)", 712 "to": "semijoin", 713 "chosen": false 714 } /* transformation */ 715 }, 716 { 717 "transformation": { 718 "select#": 2, 719 "from": "IN (SELECT)", 720 "to": "EXISTS (CORRELATED SELECT)", 721 "chosen": true, 722 "evaluating_constant_having_conditions": [ 723 ] /* evaluating_constant_having_conditions */ 724 } /* transformation */ 725 } 726 ] /* steps */ 727 } /* join_preparation */ 728 }, 729 { 730 "expanded_query": "/* select#1 */ select `t1`.`f2` AS `f2` from (`t1` straight_join (`t2` join `t3` on((`t3`.`f2` = `t2`.`f2`))) on((`t3`.`f2` = `t2`.`f2`))) having (not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `t1`.`f2`,min(`t1`.`f2`) from `t1` having (((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`))))))) order by `t1`.`f2`" 731 }, 732 { 733 "transformations_to_nested_joins": { 734 "transformations": [ 735 "JOIN_condition_to_WHERE", 736 "parenthesis_removal" 737 ] /* transformations */, 738 "expanded_query": "/* select#1 */ select `t1`.`f2` AS `f2` from `t1` join `t2` join `t3` where ((`t3`.`f2` = `t2`.`f2`) and (`t3`.`f2` = `t2`.`f2`)) having (not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `t1`.`f2`,min(`t1`.`f2`) from `t1` having (((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`))))))) order by `t1`.`f2`" 739 } /* transformations_to_nested_joins */ 740 } 741 ] /* steps */ 742 } /* join_preparation */ 743 }, 744 { 745 "join_optimization": { 746 "select#": 1, 747 "steps": [ 748 { 749 "condition_processing": { 750 "condition": "WHERE", 751 "original_condition": "((`t3`.`f2` = `t2`.`f2`) and (`t3`.`f2` = `t2`.`f2`))", 752 "steps": [ 753 { 754 "transformation": "equality_propagation", 755 "resulting_condition": "(multiple equal(`t3`.`f2`, `t2`.`f2`))" 756 }, 757 { 758 "transformation": "constant_propagation", 759 "resulting_condition": "(multiple equal(`t3`.`f2`, `t2`.`f2`))" 760 }, 761 { 762 "transformation": "trivial_condition_removal", 763 "resulting_condition": "multiple equal(`t3`.`f2`, `t2`.`f2`)" 764 } 765 ] /* steps */ 766 } /* condition_processing */ 767 }, 768 { 769 "condition_processing": { 770 "condition": "HAVING", 771 "original_condition": "(not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `t1`.`f2`,min(`t1`.`f2`) from `t1` having (((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`)))))))", 772 "steps": [ 773 { 774 "transformation": "constant_propagation", 775 "subselect_evaluation": [ 776 ] /* subselect_evaluation */, 777 "resulting_condition": "(not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `t1`.`f2`,min(`t1`.`f2`) from `t1` having (((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`)))))))" 778 }, 779 { 780 "transformation": "trivial_condition_removal", 781 "subselect_evaluation": [ 782 ] /* subselect_evaluation */, 783 "resulting_condition": "(not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `t1`.`f2`,min(`t1`.`f2`) from `t1` having (((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`)))))))" 784 } 785 ] /* steps */ 786 } /* condition_processing */ 787 }, 788 { 789 "substitute_generated_columns": { 790 } /* substitute_generated_columns */ 791 }, 792 { 793 "table_dependencies": [ 794 { 795 "table": "`t1`", 796 "row_may_be_null": false, 797 "map_bit": 0, 798 "depends_on_map_bits": [ 799 ] /* depends_on_map_bits */ 800 }, 801 { 802 "table": "`t2`", 803 "row_may_be_null": false, 804 "map_bit": 1, 805 "depends_on_map_bits": [ 806 0 807 ] /* depends_on_map_bits */ 808 }, 809 { 810 "table": "`t3`", 811 "row_may_be_null": false, 812 "map_bit": 2, 813 "depends_on_map_bits": [ 814 0 815 ] /* depends_on_map_bits */ 816 } 817 ] /* table_dependencies */ 818 }, 819 { 820 "ref_optimizer_key_uses": [ 821 ] /* ref_optimizer_key_uses */ 822 }, 823 { 824 "rows_estimation": [ 825 { 826 "table": "`t1`", 827 "table_scan": { 828 "rows": 2, 829 "cost": 2 830 } /* table_scan */ 831 }, 832 { 833 "table": "`t2`", 834 "table_scan": { 835 "rows": 2, 836 "cost": 2 837 } /* table_scan */ 838 }, 839 { 840 "table": "`t3`", 841 "table_scan": { 842 "rows": 1, 843 "cost": 2 844 } /* table_scan */ 845 } 846 ] /* rows_estimation */ 847 }, 848 { 849 "considered_execution_plans": [ 850 { 851 "plan_prefix": [ 852 ] /* plan_prefix */, 853 "table": "`t1`", 854 "best_access_path": { 855 "considered_access_paths": [ 856 { 857 "rows_to_scan": 2, 858 "access_type": "scan", 859 "resulting_rows": 2, 860 "cost": 2.4098, 861 "chosen": true, 862 "use_tmp_table": true 863 } 864 ] /* considered_access_paths */ 865 } /* best_access_path */, 866 "condition_filtering_pct": 100, 867 "rows_for_plan": 2, 868 "cost_for_plan": 2.4098, 869 "rest_of_plan": [ 870 { 871 "plan_prefix": [ 872 "`t1`" 873 ] /* plan_prefix */, 874 "table": "`t3`", 875 "best_access_path": { 876 "considered_access_paths": [ 877 { 878 "rows_to_scan": 1, 879 "access_type": "scan", 880 "using_join_cache": true, 881 "buffers_needed": 1, 882 "resulting_rows": 1, 883 "cost": 2.4049, 884 "chosen": true 885 } 886 ] /* considered_access_paths */ 887 } /* best_access_path */, 888 "condition_filtering_pct": 100, 889 "rows_for_plan": 2, 890 "cost_for_plan": 4.8147, 891 "rest_of_plan": [ 892 { 893 "plan_prefix": [ 894 "`t1`", 895 "`t3`" 896 ] /* plan_prefix */, 897 "table": "`t2`", 898 "best_access_path": { 899 "considered_access_paths": [ 900 { 901 "rows_to_scan": 2, 902 "access_type": "scan", 903 "using_join_cache": true, 904 "buffers_needed": 1, 905 "resulting_rows": 2, 906 "cost": 2.8099, 907 "chosen": true 908 } 909 ] /* considered_access_paths */ 910 } /* best_access_path */, 911 "condition_filtering_pct": 100, 912 "rows_for_plan": 4, 913 "cost_for_plan": 7.6246, 914 "sort_cost": 4, 915 "new_cost_for_plan": 11.625, 916 "chosen": true 917 } 918 ] /* rest_of_plan */ 919 }, 920 { 921 "plan_prefix": [ 922 "`t1`" 923 ] /* plan_prefix */, 924 "table": "`t2`", 925 "best_access_path": { 926 "considered_access_paths": [ 927 { 928 "rows_to_scan": 2, 929 "access_type": "scan", 930 "using_join_cache": true, 931 "buffers_needed": 1, 932 "resulting_rows": 2, 933 "cost": 2.8098, 934 "chosen": true 935 } 936 ] /* considered_access_paths */ 937 } /* best_access_path */, 938 "condition_filtering_pct": 100, 939 "rows_for_plan": 4, 940 "cost_for_plan": 5.2196, 941 "pruned_by_heuristic": true 942 } 943 ] /* rest_of_plan */ 944 } 945 ] /* considered_execution_plans */ 946 }, 947 { 948 "attaching_conditions_to_tables": { 949 "original_condition": "(`t2`.`f2` = `t3`.`f2`)", 950 "attached_conditions_computation": [ 951 ] /* attached_conditions_computation */, 952 "attached_conditions_summary": [ 953 { 954 "table": "`t1`", 955 "attached": null 956 }, 957 { 958 "table": "`t3`", 959 "attached": null 960 }, 961 { 962 "table": "`t2`", 963 "attached": "(`t2`.`f2` = `t3`.`f2`)" 964 } 965 ] /* attached_conditions_summary */ 966 } /* attaching_conditions_to_tables */ 967 }, 968 { 969 "clause_processing": { 970 "clause": "ORDER BY", 971 "original_clause": "`t1`.`f2`", 972 "items": [ 973 { 974 "item": "`t1`.`f2`" 975 } 976 ] /* items */, 977 "resulting_clause_is_simple": true, 978 "resulting_clause": "`t1`.`f2`" 979 } /* clause_processing */ 980 }, 981 { 982 "refine_plan": [ 983 { 984 "table": "`t1`" 985 }, 986 { 987 "table": "`t3`" 988 }, 989 { 990 "table": "`t2`" 991 } 992 ] /* refine_plan */ 993 }, 994 { 995 "sort_using_internal_table": { 996 "condition_for_sort": "(not(<in_optimizer>(<cache>(('v','i')),<exists>(/* select#2 */ select `t1`.`f2`,min(`t1`.`f2`) from `t1` having (((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`)))))))", 997 "having_after_sort": null 998 } /* sort_using_internal_table */ 999 } 1000 ] /* steps */ 1001 } /* join_optimization */ 1002 }, 1003 { 1004 "join_optimization": { 1005 "select#": 2, 1006 "steps": [ 1007 { 1008 "condition_processing": { 1009 "condition": "HAVING", 1010 "original_condition": "(((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`)))", 1011 "steps": [ 1012 { 1013 "transformation": "constant_propagation", 1014 "resulting_condition": "(((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`)))" 1015 }, 1016 { 1017 "transformation": "trivial_condition_removal", 1018 "resulting_condition": "(((<cache>('v') = `t1`.`f2`) or isnull(`t1`.`f2`)) and ((<cache>('i') = min(`t1`.`f2`)) or isnull(min(`t1`.`f2`))) and <is_not_null_test>(`t1`.`f2`) and <is_not_null_test>(min(`t1`.`f2`)))" 1019 } 1020 ] /* steps */ 1021 } /* condition_processing */ 1022 }, 1023 { 1024 "table_dependencies": [ 1025 { 1026 "table": "`t1`", 1027 "row_may_be_null": false, 1028 "map_bit": 0, 1029 "depends_on_map_bits": [ 1030 ] /* depends_on_map_bits */ 1031 } 1032 ] /* table_dependencies */ 1033 }, 1034 { 1035 "rows_estimation": [ 1036 { 1037 "table": "`t1`", 1038 "table_scan": { 1039 "rows": 2, 1040 "cost": 2 1041 } /* table_scan */ 1042 } 1043 ] /* rows_estimation */ 1044 }, 1045 { 1046 "considered_execution_plans": [ 1047 { 1048 "plan_prefix": [ 1049 ] /* plan_prefix */, 1050 "table": "`t1`", 1051 "best_access_path": { 1052 "considered_access_paths": [ 1053 { 1054 "rows_to_scan": 2, 1055 "access_type": "scan", 1056 "resulting_rows": 2, 1057 "cost": 2.4098, 1058 "chosen": true 1059 } 1060 ] /* considered_access_paths */ 1061 } /* best_access_path */, 1062 "condition_filtering_pct": 100, 1063 "rows_for_plan": 2, 1064 "cost_for_plan": 2.4098, 1065 "chosen": true 1066 } 1067 ] /* considered_execution_plans */ 1068 }, 1069 { 1070 "transformation": { 1071 "select#": 2, 1072 "from": "IN (SELECT)", 1073 "to": "materialization", 1074 "has_nullable_expressions": true, 1075 "treat_UNKNOWN_as_FALSE": false, 1076 "possible": false, 1077 "cause": "cannot_handle_partial_matches" 1078 } /* transformation */ 1079 }, 1080 { 1081 "transformation": { 1082 "select#": 2, 1083 "from": "IN (SELECT)", 1084 "to": "EXISTS (CORRELATED SELECT)", 1085 "put_1_in_SELECT_list": true 1086 } /* transformation */ 1087 }, 1088 { 1089 "attaching_conditions_to_tables": { 1090 "original_condition": null, 1091 "attached_conditions_computation": [ 1092 ] /* attached_conditions_computation */, 1093 "attached_conditions_summary": [ 1094 { 1095 "table": "`t1`", 1096 "attached": null 1097 } 1098 ] /* attached_conditions_summary */ 1099 } /* attaching_conditions_to_tables */ 1100 }, 1101 { 1102 "refine_plan": [ 1103 { 1104 "table": "`t1`" 1105 } 1106 ] /* refine_plan */ 1107 } 1108 ] /* steps */ 1109 } /* join_optimization */ 1110 }, 1111 { 1112 "join_execution": { 1113 "select#": 1, 1114 "steps": [ 1115 { 1116 "creating_tmp_table": { 1117 "tmp_table_info": { 1118 "table": "intermediate_tmp_table", 1119 "row_length": 3, 1120 "key_length": 0, 1121 "unique_constraint": false, 1122 "location": "memory (heap)", 1123 "row_limit_estimate": 349525 1124 } /* tmp_table_info */ 1125 } /* creating_tmp_table */ 1126 }, 1127 { 1128 "filesort_information": [ 1129 { 1130 "direction": "asc", 1131 "table": "intermediate_tmp_table", 1132 "field": "f2" 1133 } 1134 ] /* filesort_information */, 1135 "filesort_priority_queue_optimization": { 1136 "usable": false, 1137 "cause": "not applicable (no LIMIT)" 1138 } /* filesort_priority_queue_optimization */, 1139 "filesort_execution": [ 1140 { 1141 "subselect_execution": { 1142 "select#": 2, 1143 "steps": [ 1144 { 1145 "join_execution": { 1146 "select#": 2, 1147 "steps": [ 1148 ] /* steps */ 1149 } /* join_execution */ 1150 } 1151 ] /* steps */ 1152 } /* subselect_execution */ 1153 }, 1154 { 1155 "subselect_execution": { 1156 "select#": 2, 1157 "steps": [ 1158 ] /* steps */ 1159 } /* subselect_execution */ 1160 }, 1161 { 1162 "subselect_execution": { 1163 "select#": 2, 1164 "steps": [ 1165 ] /* steps */ 1166 } /* subselect_execution */ 1167 }, 1168 { 1169 "subselect_execution": { 1170 "select#": 2, 1171 "steps": [ 1172 ] /* steps */ 1173 } /* subselect_execution */ 1174 } 1175 ] /* filesort_execution */, 1176 "filesort_summary": { 1177 "rows": 4, 1178 "examined_rows": 4, 1179 "number_of_tmp_files": 0, 1180 "sort_buffer_size": "NNN", 1181 "sort_mode": "<sort_key, rowid>" 1182 } /* filesort_summary */ 1183 } 1184 ] /* steps */ 1185 } /* join_execution */ 1186 } 1187 ] /* steps */ 1188} 1189DROP TABLES t1,t2,t3; 1190 1191# Test that tracing a query with a materialized FROM-clause 1192# derived table using a GROUP BY, does not crash 1193 1194create table t1 (a int, b int); 1195insert into t1 values (1,1), (2,null), (3, 4); 1196select max(x) from (select sum(a) as x from t1 group by b) as teeone; 1197max(x) 11983 1199select TRACE from information_schema.OPTIMIZER_TRACE; 1200TRACE 1201{ 1202 "steps": [ 1203 { 1204 "join_preparation": { 1205 "select#": 1, 1206 "steps": [ 1207 { 1208 "join_preparation": { 1209 "select#": 2, 1210 "steps": [ 1211 { 1212 "expanded_query": "/* select#2 */ select sum(`t1`.`a`) AS `x` from `t1` group by `t1`.`b`" 1213 } 1214 ] /* steps */ 1215 } /* join_preparation */ 1216 }, 1217 { 1218 "derived": { 1219 "table": " `teeone`", 1220 "select#": 2, 1221 "materialized": true 1222 } /* derived */ 1223 }, 1224 { 1225 "expanded_query": "/* select#1 */ select max(`teeone`.`x`) AS `max(x)` from (/* select#2 */ select sum(`t1`.`a`) AS `x` from `t1` group by `t1`.`b`) `teeone`" 1226 } 1227 ] /* steps */ 1228 } /* join_preparation */ 1229 }, 1230 { 1231 "join_optimization": { 1232 "select#": 1, 1233 "steps": [ 1234 { 1235 "join_optimization": { 1236 "select#": 2, 1237 "steps": [ 1238 { 1239 "substitute_generated_columns": { 1240 } /* substitute_generated_columns */ 1241 }, 1242 { 1243 "table_dependencies": [ 1244 { 1245 "table": "`t1`", 1246 "row_may_be_null": false, 1247 "map_bit": 0, 1248 "depends_on_map_bits": [ 1249 ] /* depends_on_map_bits */ 1250 } 1251 ] /* table_dependencies */ 1252 }, 1253 { 1254 "rows_estimation": [ 1255 { 1256 "table": "`t1`", 1257 "table_scan": { 1258 "rows": 3, 1259 "cost": 2 1260 } /* table_scan */ 1261 } 1262 ] /* rows_estimation */ 1263 }, 1264 { 1265 "considered_execution_plans": [ 1266 { 1267 "plan_prefix": [ 1268 ] /* plan_prefix */, 1269 "table": "`t1`", 1270 "best_access_path": { 1271 "considered_access_paths": [ 1272 { 1273 "rows_to_scan": 3, 1274 "access_type": "scan", 1275 "resulting_rows": 3, 1276 "cost": 2.6066, 1277 "chosen": true, 1278 "use_tmp_table": true 1279 } 1280 ] /* considered_access_paths */ 1281 } /* best_access_path */, 1282 "condition_filtering_pct": 100, 1283 "rows_for_plan": 3, 1284 "cost_for_plan": 2.6066, 1285 "sort_cost": 3, 1286 "new_cost_for_plan": 5.6066, 1287 "chosen": true 1288 } 1289 ] /* considered_execution_plans */ 1290 }, 1291 { 1292 "attaching_conditions_to_tables": { 1293 "original_condition": null, 1294 "attached_conditions_computation": [ 1295 ] /* attached_conditions_computation */, 1296 "attached_conditions_summary": [ 1297 { 1298 "table": "`t1`", 1299 "attached": null 1300 } 1301 ] /* attached_conditions_summary */ 1302 } /* attaching_conditions_to_tables */ 1303 }, 1304 { 1305 "clause_processing": { 1306 "clause": "GROUP BY", 1307 "original_clause": "`t1`.`b`", 1308 "items": [ 1309 { 1310 "item": "`t1`.`b`" 1311 } 1312 ] /* items */, 1313 "resulting_clause_is_simple": true, 1314 "resulting_clause": "`t1`.`b`" 1315 } /* clause_processing */ 1316 }, 1317 { 1318 "refine_plan": [ 1319 { 1320 "table": "`t1`" 1321 } 1322 ] /* refine_plan */ 1323 } 1324 ] /* steps */ 1325 } /* join_optimization */ 1326 }, 1327 { 1328 "table_dependencies": [ 1329 { 1330 "table": " `teeone`", 1331 "row_may_be_null": false, 1332 "map_bit": 0, 1333 "depends_on_map_bits": [ 1334 ] /* depends_on_map_bits */ 1335 } 1336 ] /* table_dependencies */ 1337 }, 1338 { 1339 "rows_estimation": [ 1340 { 1341 "table": " `teeone`", 1342 "table_scan": { 1343 "rows": 3, 1344 "cost": 10 1345 } /* table_scan */ 1346 } 1347 ] /* rows_estimation */ 1348 }, 1349 { 1350 "considered_execution_plans": [ 1351 { 1352 "plan_prefix": [ 1353 ] /* plan_prefix */, 1354 "table": " `teeone`", 1355 "best_access_path": { 1356 "considered_access_paths": [ 1357 { 1358 "rows_to_scan": 3, 1359 "access_type": "scan", 1360 "resulting_rows": 3, 1361 "cost": 10.75, 1362 "chosen": true 1363 } 1364 ] /* considered_access_paths */ 1365 } /* best_access_path */, 1366 "condition_filtering_pct": 100, 1367 "rows_for_plan": 3, 1368 "cost_for_plan": 10.75, 1369 "chosen": true 1370 } 1371 ] /* considered_execution_plans */ 1372 }, 1373 { 1374 "attaching_conditions_to_tables": { 1375 "original_condition": null, 1376 "attached_conditions_computation": [ 1377 ] /* attached_conditions_computation */, 1378 "attached_conditions_summary": [ 1379 { 1380 "table": " `teeone`", 1381 "attached": null 1382 } 1383 ] /* attached_conditions_summary */ 1384 } /* attaching_conditions_to_tables */ 1385 }, 1386 { 1387 "refine_plan": [ 1388 { 1389 "table": " `teeone`" 1390 } 1391 ] /* refine_plan */ 1392 } 1393 ] /* steps */ 1394 } /* join_optimization */ 1395 }, 1396 { 1397 "join_execution": { 1398 "select#": 1, 1399 "steps": [ 1400 { 1401 "creating_tmp_table": { 1402 "tmp_table_info": { 1403 "table": " `teeone`", 1404 "row_length": 16, 1405 "key_length": 0, 1406 "unique_constraint": false, 1407 "location": "memory (heap)", 1408 "row_limit_estimate": 65536 1409 } /* tmp_table_info */ 1410 } /* creating_tmp_table */ 1411 }, 1412 { 1413 "join_execution": { 1414 "select#": 2, 1415 "steps": [ 1416 { 1417 "creating_tmp_table": { 1418 "tmp_table_info": { 1419 "table": "intermediate_tmp_table", 1420 "row_length": 22, 1421 "key_length": 5, 1422 "unique_constraint": false, 1423 "location": "memory (heap)", 1424 "row_limit_estimate": 47662 1425 } /* tmp_table_info */ 1426 } /* creating_tmp_table */ 1427 }, 1428 { 1429 "filesort_information": [ 1430 { 1431 "direction": "asc", 1432 "table": "intermediate_tmp_table", 1433 "field": "b" 1434 } 1435 ] /* filesort_information */, 1436 "filesort_priority_queue_optimization": { 1437 "usable": false, 1438 "cause": "not applicable (no LIMIT)" 1439 } /* filesort_priority_queue_optimization */, 1440 "filesort_execution": [ 1441 ] /* filesort_execution */, 1442 "filesort_summary": { 1443 "rows": 3, 1444 "examined_rows": 3, 1445 "number_of_tmp_files": 0, 1446 "sort_buffer_size": "NNN", 1447 "sort_mode": "<sort_key, rowid>" 1448 } /* filesort_summary */ 1449 } 1450 ] /* steps */ 1451 } /* join_execution */ 1452 } 1453 ] /* steps */ 1454 } /* join_execution */ 1455 } 1456 ] /* steps */ 1457} 1458drop table t1; 1459 1460# To have no crash above, we had to restore the ref_array at 1461# end of JOIN::exec(). This impacts how the query looks like, 1462# but not too much, as seen in the error message below. 1463# Comes from func_gconcat.test. 1464 1465CREATE TABLE t1(f1 int); 1466INSERT INTO t1 values (0),(0); 1467set optimizer_trace="enabled=off"; 1468SELECT POLYGON((SELECT 1 FROM (SELECT 1 IN (GROUP_CONCAT(t1.f1)) FROM t1, t1 t GROUP BY t.f1 ) d)); 1469ERROR 22007: Illegal non geometric '(select 1 from (select (1 = group_concat(`test`.`t1`.`f1` separator ',')) AS `1 IN (GROUP_CONCAT(t1.f1))` from `test`.`t1` join `test`.`t1` `t` group by `test`.`t`.`f1`) `d`)' value found during parsing 1470set optimizer_trace="enabled=on"; 1471SELECT POLYGON((SELECT 1 FROM (SELECT 1 IN (GROUP_CONCAT(t1.f1)) FROM t1, t1 t GROUP BY t.f1 ) d)); 1472ERROR 22007: Illegal non geometric '(select 1 from (select (1 = group_concat(`test`.`t1`.`f1` separator ',')) AS `1 IN (GROUP_CONCAT(t1.f1))` from `test`.`t1` join `test`.`t1` `t` group by `test`.`t`.`f1`) `d`)' value found during parsing 1473DROP TABLE t1; 1474 1475# Check that SQL PREPARE and SQL EXECUTE each produce one trace. 1476 1477set optimizer_trace_offset=0, optimizer_trace_limit=100; 1478prepare stmt from "select 1"; 1479select * from information_schema.OPTIMIZER_TRACE; 1480QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 1481select 1 { 1482 "steps": [ 1483 { 1484 "join_preparation": { 1485 "select#": 1, 1486 "steps": [ 1487 { 1488 "expanded_query": "/* select#1 */ select 1 AS `1`" 1489 } 1490 ] /* steps */ 1491 } /* join_preparation */ 1492 } 1493 ] /* steps */ 1494} 0 0 1495set optimizer_trace_offset=0, optimizer_trace_limit=100; 1496execute stmt; 14971 14981 1499select * from information_schema.OPTIMIZER_TRACE; 1500QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 1501select 1 { 1502 "steps": [ 1503 { 1504 "join_preparation": { 1505 "select#": 1, 1506 "steps": [ 1507 { 1508 "expanded_query": "/* select#1 */ select 1 AS `1`" 1509 } 1510 ] /* steps */ 1511 } /* join_preparation */ 1512 }, 1513 { 1514 "join_optimization": { 1515 "select#": 1, 1516 "steps": [ 1517 ] /* steps */ 1518 } /* join_optimization */ 1519 }, 1520 { 1521 "join_execution": { 1522 "select#": 1, 1523 "steps": [ 1524 ] /* steps */ 1525 } /* join_execution */ 1526 } 1527 ] /* steps */ 1528} 0 0 1529deallocate prepare stmt; 1530set optimizer_trace_offset=default, optimizer_trace_limit=default; 1531 1532# Test of SELECTs in IF in stored routine. 1533# Same test for CASE WHEN. 1534 1535create table t1 (a int); 1536create procedure p1() 1537begin 1538if exists(select 1) then 1539insert into t1 values(1); 1540end if; 1541if exists(select 2) then 1542insert into t1 values(2); 1543end if; 1544if (select count(*) from t1) then 1545insert into t1 values(3); 1546end if; 1547set @a=(select count(a) from t1 where a>0); 1548case (select count(a) from t1 where a>1) 1549when 2 then set @b=2; 1550else set @b=3; 1551end case; 1552end| 1553set optimizer_trace_offset=0, optimizer_trace_limit=100; 1554set @old_max=@@optimizer_trace_max_mem_size; 1555set optimizer_trace_max_mem_size=40000; 1556call p1(); 1557select * from information_schema.OPTIMIZER_TRACE; 1558QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 1559set @old_max=@@optimizer_trace_max_mem_size { 1560 "steps": [ 1561 ] /* steps */ 1562} 0 0 1563set optimizer_trace_max_mem_size=40000 { 1564 "steps": [ 1565 ] /* steps */ 1566} 0 0 1567call p1() { 1568 "steps": [ 1569 ] /* steps */ 1570} 0 0 1571jump_if_not 2(2) exists(select 1) { 1572 "steps": [ 1573 { 1574 "join_preparation": { 1575 "select#": 2, 1576 "steps": [ 1577 { 1578 "expanded_query": "/* select#2 */ select 1" 1579 } 1580 ] /* steps */ 1581 } /* join_preparation */ 1582 }, 1583 { 1584 "subselect_execution": { 1585 "select#": 2, 1586 "steps": [ 1587 { 1588 "join_optimization": { 1589 "select#": 2, 1590 "steps": [ 1591 ] /* steps */ 1592 } /* join_optimization */ 1593 }, 1594 { 1595 "join_execution": { 1596 "select#": 2, 1597 "steps": [ 1598 ] /* steps */ 1599 } /* join_execution */ 1600 } 1601 ] /* steps */ 1602 } /* subselect_execution */ 1603 } 1604 ] /* steps */ 1605} 0 0 1606insert into t1 values(1) { 1607 "steps": [ 1608 ] /* steps */ 1609} 0 0 1610jump_if_not 4(4) exists(select 2) { 1611 "steps": [ 1612 { 1613 "join_preparation": { 1614 "select#": 2, 1615 "steps": [ 1616 { 1617 "expanded_query": "/* select#2 */ select 2" 1618 } 1619 ] /* steps */ 1620 } /* join_preparation */ 1621 }, 1622 { 1623 "subselect_execution": { 1624 "select#": 2, 1625 "steps": [ 1626 { 1627 "join_optimization": { 1628 "select#": 2, 1629 "steps": [ 1630 ] /* steps */ 1631 } /* join_optimization */ 1632 }, 1633 { 1634 "join_execution": { 1635 "select#": 2, 1636 "steps": [ 1637 ] /* steps */ 1638 } /* join_execution */ 1639 } 1640 ] /* steps */ 1641 } /* subselect_execution */ 1642 } 1643 ] /* steps */ 1644} 0 0 1645insert into t1 values(2) { 1646 "steps": [ 1647 ] /* steps */ 1648} 0 0 1649jump_if_not 6(6) (select count(0) from `test`.`t1`) { 1650 "steps": [ 1651 { 1652 "join_preparation": { 1653 "select#": 2, 1654 "steps": [ 1655 { 1656 "expanded_query": "/* select#2 */ select count(0) from `t1`" 1657 } 1658 ] /* steps */ 1659 } /* join_preparation */ 1660 }, 1661 { 1662 "subselect_execution": { 1663 "select#": 2, 1664 "steps": [ 1665 { 1666 "join_optimization": { 1667 "select#": 2, 1668 "steps": [ 1669 ] /* steps */, 1670 "empty_result": { 1671 "cause": "Select tables optimized away" 1672 } /* empty_result */ 1673 } /* join_optimization */ 1674 }, 1675 { 1676 "join_execution": { 1677 "select#": 2, 1678 "steps": [ 1679 ] /* steps */ 1680 } /* join_execution */ 1681 } 1682 ] /* steps */ 1683 } /* subselect_execution */ 1684 } 1685 ] /* steps */ 1686} 0 0 1687insert into t1 values(3) { 1688 "steps": [ 1689 ] /* steps */ 1690} 0 0 1691SET @a=(select count(a) from t1 where a>0) { 1692 "steps": [ 1693 { 1694 "join_preparation": { 1695 "select#": 2, 1696 "steps": [ 1697 { 1698 "expanded_query": "/* select#2 */ select count(`t1`.`a`) from `t1` where (`t1`.`a` > 0)" 1699 } 1700 ] /* steps */ 1701 } /* join_preparation */ 1702 }, 1703 { 1704 "subselect_execution": { 1705 "select#": 2, 1706 "steps": [ 1707 { 1708 "join_optimization": { 1709 "select#": 2, 1710 "steps": [ 1711 { 1712 "condition_processing": { 1713 "condition": "WHERE", 1714 "original_condition": "(`t1`.`a` > 0)", 1715 "steps": [ 1716 { 1717 "transformation": "equality_propagation", 1718 "resulting_condition": "(`t1`.`a` > 0)" 1719 }, 1720 { 1721 "transformation": "constant_propagation", 1722 "resulting_condition": "(`t1`.`a` > 0)" 1723 }, 1724 { 1725 "transformation": "trivial_condition_removal", 1726 "resulting_condition": "(`t1`.`a` > 0)" 1727 } 1728 ] /* steps */ 1729 } /* condition_processing */ 1730 }, 1731 { 1732 "substitute_generated_columns": { 1733 } /* substitute_generated_columns */ 1734 }, 1735 { 1736 "table_dependencies": [ 1737 { 1738 "table": "`t1`", 1739 "row_may_be_null": false, 1740 "map_bit": 0, 1741 "depends_on_map_bits": [ 1742 ] /* depends_on_map_bits */ 1743 } 1744 ] /* table_dependencies */ 1745 }, 1746 { 1747 "ref_optimizer_key_uses": [ 1748 ] /* ref_optimizer_key_uses */ 1749 }, 1750 { 1751 "rows_estimation": [ 1752 { 1753 "table": "`t1`", 1754 "table_scan": { 1755 "rows": 3, 1756 "cost": 2 1757 } /* table_scan */ 1758 } 1759 ] /* rows_estimation */ 1760 }, 1761 { 1762 "considered_execution_plans": [ 1763 { 1764 "plan_prefix": [ 1765 ] /* plan_prefix */, 1766 "table": "`t1`", 1767 "best_access_path": { 1768 "considered_access_paths": [ 1769 { 1770 "rows_to_scan": 3, 1771 "access_type": "scan", 1772 "resulting_rows": 1, 1773 "cost": 2.6051, 1774 "chosen": true 1775 } 1776 ] /* considered_access_paths */ 1777 } /* best_access_path */, 1778 "condition_filtering_pct": 100, 1779 "rows_for_plan": 1, 1780 "cost_for_plan": 2.6051, 1781 "chosen": true 1782 } 1783 ] /* considered_execution_plans */ 1784 }, 1785 { 1786 "attaching_conditions_to_tables": { 1787 "original_condition": "(`t1`.`a` > 0)", 1788 "attached_conditions_computation": [ 1789 ] /* attached_conditions_computation */, 1790 "attached_conditions_summary": [ 1791 { 1792 "table": "`t1`", 1793 "attached": "(`t1`.`a` > 0)" 1794 } 1795 ] /* attached_conditions_summary */ 1796 } /* attaching_conditions_to_tables */ 1797 }, 1798 { 1799 "refine_plan": [ 1800 { 1801 "table": "`t1`" 1802 } 1803 ] /* refine_plan */ 1804 } 1805 ] /* steps */ 1806 } /* join_optimization */ 1807 }, 1808 { 1809 "join_execution": { 1810 "select#": 2, 1811 "steps": [ 1812 ] /* steps */ 1813 } /* join_execution */ 1814 } 1815 ] /* steps */ 1816 } /* subselect_execution */ 1817 } 1818 ] /* steps */ 1819} 0 0 1820set_case_expr (15) 0 (select count(`a`) from `test`.`t1` where (`a` > 1)) { 1821 "steps": [ 1822 { 1823 "join_preparation": { 1824 "select#": 2, 1825 "steps": [ 1826 { 1827 "expanded_query": "/* select#2 */ select count(`t1`.`a`) from `t1` where (`t1`.`a` > 1)" 1828 } 1829 ] /* steps */ 1830 } /* join_preparation */ 1831 }, 1832 { 1833 "subselect_execution": { 1834 "select#": 2, 1835 "steps": [ 1836 { 1837 "join_optimization": { 1838 "select#": 2, 1839 "steps": [ 1840 { 1841 "condition_processing": { 1842 "condition": "WHERE", 1843 "original_condition": "(`t1`.`a` > 1)", 1844 "steps": [ 1845 { 1846 "transformation": "equality_propagation", 1847 "resulting_condition": "(`t1`.`a` > 1)" 1848 }, 1849 { 1850 "transformation": "constant_propagation", 1851 "resulting_condition": "(`t1`.`a` > 1)" 1852 }, 1853 { 1854 "transformation": "trivial_condition_removal", 1855 "resulting_condition": "(`t1`.`a` > 1)" 1856 } 1857 ] /* steps */ 1858 } /* condition_processing */ 1859 }, 1860 { 1861 "substitute_generated_columns": { 1862 } /* substitute_generated_columns */ 1863 }, 1864 { 1865 "table_dependencies": [ 1866 { 1867 "table": "`t1`", 1868 "row_may_be_null": false, 1869 "map_bit": 0, 1870 "depends_on_map_bits": [ 1871 ] /* depends_on_map_bits */ 1872 } 1873 ] /* table_dependencies */ 1874 }, 1875 { 1876 "ref_optimizer_key_uses": [ 1877 ] /* ref_optimizer_key_uses */ 1878 }, 1879 { 1880 "rows_estimation": [ 1881 { 1882 "table": "`t1`", 1883 "table_scan": { 1884 "rows": 3, 1885 "cost": 2 1886 } /* table_scan */ 1887 } 1888 ] /* rows_estimation */ 1889 }, 1890 { 1891 "considered_execution_plans": [ 1892 { 1893 "plan_prefix": [ 1894 ] /* plan_prefix */, 1895 "table": "`t1`", 1896 "best_access_path": { 1897 "considered_access_paths": [ 1898 { 1899 "rows_to_scan": 3, 1900 "access_type": "scan", 1901 "resulting_rows": 1, 1902 "cost": 2.6051, 1903 "chosen": true 1904 } 1905 ] /* considered_access_paths */ 1906 } /* best_access_path */, 1907 "condition_filtering_pct": 100, 1908 "rows_for_plan": 1, 1909 "cost_for_plan": 2.6051, 1910 "chosen": true 1911 } 1912 ] /* considered_execution_plans */ 1913 }, 1914 { 1915 "attaching_conditions_to_tables": { 1916 "original_condition": "(`t1`.`a` > 1)", 1917 "attached_conditions_computation": [ 1918 ] /* attached_conditions_computation */, 1919 "attached_conditions_summary": [ 1920 { 1921 "table": "`t1`", 1922 "attached": "(`t1`.`a` > 1)" 1923 } 1924 ] /* attached_conditions_summary */ 1925 } /* attaching_conditions_to_tables */ 1926 }, 1927 { 1928 "refine_plan": [ 1929 { 1930 "table": "`t1`" 1931 } 1932 ] /* refine_plan */ 1933 } 1934 ] /* steps */ 1935 } /* join_optimization */ 1936 }, 1937 { 1938 "join_execution": { 1939 "select#": 2, 1940 "steps": [ 1941 ] /* steps */ 1942 } /* join_execution */ 1943 } 1944 ] /* steps */ 1945 } /* subselect_execution */ 1946 } 1947 ] /* steps */ 1948} 0 0 1949jump_if_not_case_when 11(15) (case_expr@0 = 2) { 1950 "steps": [ 1951 ] /* steps */ 1952} 0 0 1953SET @b=2 { 1954 "steps": [ 1955 ] /* steps */ 1956} 0 0 1957select * from t1; 1958a 19591 19602 19613 1962select @a,@b; 1963@a @b 19643 2 1965set optimizer_trace_max_mem_size=@old_max; 1966drop procedure p1; 1967drop table t1; 1968 1969# Test of tracing of DO. 1970 1971set optimizer_trace_offset=0, optimizer_trace_limit=100; 1972do (select 42); 1973select * from information_schema.OPTIMIZER_TRACE; 1974QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 1975do (select 42) { 1976 "steps": [ 1977 { 1978 "join_preparation": { 1979 "select#": 1, 1980 "steps": [ 1981 { 1982 "join_preparation": { 1983 "select#": 2, 1984 "steps": [ 1985 { 1986 "expanded_query": "/* select#2 */ select 42" 1987 } 1988 ] /* steps */ 1989 } /* join_preparation */ 1990 }, 1991 { 1992 "expanded_query": "/* select#1 */ select 42 AS `(select 42)`" 1993 } 1994 ] /* steps */ 1995 } /* join_preparation */ 1996 }, 1997 { 1998 "join_optimization": { 1999 "select#": 1, 2000 "steps": [ 2001 ] /* steps */ 2002 } /* join_optimization */ 2003 }, 2004 { 2005 "join_execution": { 2006 "select#": 1, 2007 "steps": [ 2008 ] /* steps */ 2009 } /* join_execution */ 2010 } 2011 ] /* steps */ 2012} 0 0 2013 2014# Test of tracing of subquery used in parameter of routine call 2015 2016create table t1(a int); 2017insert into t1 values(1),(2); 2018create procedure p1(x int) 2019begin 2020declare b int; 2021set b=(select 2+x from dual); 2022end| 2023set optimizer_trace_offset=0, optimizer_trace_limit=100; 2024call p1((select a from t1 limit 1)); 2025select * from information_schema.OPTIMIZER_TRACE; 2026QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 2027call p1((select a from t1 limit 1)) { 2028 "steps": [ 2029 { 2030 "join_preparation": { 2031 "select#": 2, 2032 "steps": [ 2033 { 2034 "expanded_query": "/* select#2 */ select `t1`.`a` from `t1` limit 1" 2035 } 2036 ] /* steps */ 2037 } /* join_preparation */ 2038 }, 2039 { 2040 "subselect_execution": { 2041 "select#": 2, 2042 "steps": [ 2043 { 2044 "join_optimization": { 2045 "select#": 2, 2046 "steps": [ 2047 { 2048 "table_dependencies": [ 2049 { 2050 "table": "`t1`", 2051 "row_may_be_null": false, 2052 "map_bit": 0, 2053 "depends_on_map_bits": [ 2054 ] /* depends_on_map_bits */ 2055 } 2056 ] /* table_dependencies */ 2057 }, 2058 { 2059 "rows_estimation": [ 2060 { 2061 "table": "`t1`", 2062 "table_scan": { 2063 "rows": 2, 2064 "cost": 2 2065 } /* table_scan */ 2066 } 2067 ] /* rows_estimation */ 2068 }, 2069 { 2070 "considered_execution_plans": [ 2071 { 2072 "plan_prefix": [ 2073 ] /* plan_prefix */, 2074 "table": "`t1`", 2075 "best_access_path": { 2076 "considered_access_paths": [ 2077 { 2078 "rows_to_scan": 2, 2079 "access_type": "scan", 2080 "resulting_rows": 2, 2081 "cost": 2.4034, 2082 "chosen": true 2083 } 2084 ] /* considered_access_paths */ 2085 } /* best_access_path */, 2086 "condition_filtering_pct": 100, 2087 "rows_for_plan": 2, 2088 "cost_for_plan": 2.4034, 2089 "chosen": true 2090 } 2091 ] /* considered_execution_plans */ 2092 }, 2093 { 2094 "attaching_conditions_to_tables": { 2095 "original_condition": null, 2096 "attached_conditions_computation": [ 2097 ] /* attached_conditions_computation */, 2098 "attached_conditions_summary": [ 2099 { 2100 "table": "`t1`", 2101 "attached": null 2102 } 2103 ] /* attached_conditions_summary */ 2104 } /* attaching_conditions_to_tables */ 2105 }, 2106 { 2107 "refine_plan": [ 2108 { 2109 "table": "`t1`" 2110 } 2111 ] /* refine_plan */ 2112 } 2113 ] /* steps */ 2114 } /* join_optimization */ 2115 }, 2116 { 2117 "join_execution": { 2118 "select#": 2, 2119 "steps": [ 2120 ] /* steps */ 2121 } /* join_execution */ 2122 } 2123 ] /* steps */ 2124 } /* subselect_execution */ 2125 } 2126 ] /* steps */ 2127} 0 0 2128set b@1 NULL { 2129 "steps": [ 2130 ] /* steps */ 2131} 0 0 2132set b@1 (select (2 + x@0)) { 2133 "steps": [ 2134 { 2135 "join_preparation": { 2136 "select#": 2, 2137 "steps": [ 2138 { 2139 "expanded_query": "/* select#2 */ select (2 + x@0)" 2140 } 2141 ] /* steps */ 2142 } /* join_preparation */ 2143 }, 2144 { 2145 "subselect_execution": { 2146 "select#": 2, 2147 "steps": [ 2148 { 2149 "join_optimization": { 2150 "select#": 2, 2151 "steps": [ 2152 ] /* steps */ 2153 } /* join_optimization */ 2154 }, 2155 { 2156 "join_execution": { 2157 "select#": 2, 2158 "steps": [ 2159 ] /* steps */ 2160 } /* join_execution */ 2161 } 2162 ] /* steps */ 2163 } /* subselect_execution */ 2164 } 2165 ] /* steps */ 2166} 0 0 2167drop procedure p1; 2168drop table t1; 2169set optimizer_trace_offset=default, optimizer_trace_limit=default; 2170 2171# Test that printing expanded query does not alter query's 2172# results. 2173# Comes from ctype_utf8mb4_heap.test 2174 2175create table t1 (f1 varchar(1) not null) default charset utf8mb4; 2176insert into t1 values (''), (''); 2177select concat(concat(_latin1'->',f1),_latin1'<-') from t1; 2178concat(concat(_latin1'->',f1),_latin1'<-') 2179-><- 2180-><- 2181select * from information_schema.optimizer_trace; 2182QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 2183select concat(concat(_latin1'->',f1),_latin1'<-') from t1 { 2184 "steps": [ 2185 { 2186 "join_preparation": { 2187 "select#": 1, 2188 "steps": [ 2189 { 2190 "expanded_query": "/* select#1 */ select concat(concat('->',`t1`.`f1`),'<-') AS `concat(concat(_latin1'->',f1),_latin1'<-')` from `t1`" 2191 } 2192 ] /* steps */ 2193 } /* join_preparation */ 2194 }, 2195 { 2196 "join_optimization": { 2197 "select#": 1, 2198 "steps": [ 2199 { 2200 "table_dependencies": [ 2201 { 2202 "table": "`t1`", 2203 "row_may_be_null": false, 2204 "map_bit": 0, 2205 "depends_on_map_bits": [ 2206 ] /* depends_on_map_bits */ 2207 } 2208 ] /* table_dependencies */ 2209 }, 2210 { 2211 "rows_estimation": [ 2212 { 2213 "table": "`t1`", 2214 "table_scan": { 2215 "rows": 2, 2216 "cost": 2 2217 } /* table_scan */ 2218 } 2219 ] /* rows_estimation */ 2220 }, 2221 { 2222 "considered_execution_plans": [ 2223 { 2224 "plan_prefix": [ 2225 ] /* plan_prefix */, 2226 "table": "`t1`", 2227 "best_access_path": { 2228 "considered_access_paths": [ 2229 { 2230 "rows_to_scan": 2, 2231 "access_type": "scan", 2232 "resulting_rows": 2, 2233 "cost": 2.4098, 2234 "chosen": true 2235 } 2236 ] /* considered_access_paths */ 2237 } /* best_access_path */, 2238 "condition_filtering_pct": 100, 2239 "rows_for_plan": 2, 2240 "cost_for_plan": 2.4098, 2241 "chosen": true 2242 } 2243 ] /* considered_execution_plans */ 2244 }, 2245 { 2246 "attaching_conditions_to_tables": { 2247 "original_condition": null, 2248 "attached_conditions_computation": [ 2249 ] /* attached_conditions_computation */, 2250 "attached_conditions_summary": [ 2251 { 2252 "table": "`t1`", 2253 "attached": null 2254 } 2255 ] /* attached_conditions_summary */ 2256 } /* attaching_conditions_to_tables */ 2257 }, 2258 { 2259 "refine_plan": [ 2260 { 2261 "table": "`t1`" 2262 } 2263 ] /* refine_plan */ 2264 } 2265 ] /* steps */ 2266 } /* join_optimization */ 2267 }, 2268 { 2269 "join_execution": { 2270 "select#": 1, 2271 "steps": [ 2272 ] /* steps */ 2273 } /* join_execution */ 2274 } 2275 ] /* steps */ 2276} 0 0 2277drop table t1; 2278 2279# Bug#12546331 - SEGFAULT IN SUBSELECT_INDEXSUBQUERY_ENGINE::PRINT WITH OPTIMIZER TRACE 2280 2281CREATE TABLE t1 ( 2282col_int_nokey INT, 2283col_int_key INT, 2284col_varchar_key varchar(1), 2285KEY col_int_key (col_int_key), 2286KEY col_varchar_key (col_varchar_key,col_int_key) 2287); 2288INSERT INTO t1 VALUES 2289(NULL,8,'x'), 2290(8,7,'d'), 2291(1,1,'r'), 2292(9,7,'f'), 2293(4,9,'y'), 2294(3,NULL,'u'), 2295(2,1,'m'), 2296(NULL,9,NULL), 2297(2,2,'o'), 2298(NULL,9,'w'), 2299(6,2,'m'), 2300(7,4,'q'), 2301(2,0,NULL), 2302(5,4,'d'), 2303(7,8,'g'), 2304(6,NULL,'x'), 2305(6,NULL,'f'), 2306(2,0,'p'), 2307(9,NULL,'j'), 2308(6,8,'c') 2309; 2310CREATE TABLE t2 ( 2311col_int_nokey INT, 2312col_int_key INT, 2313col_varchar_key varchar(1), 2314KEY col_int_key (col_int_key), 2315KEY col_varchar_key (col_varchar_key,col_int_key) 2316); 2317INSERT INTO t2 VALUES 2318(2,4,'v'), 2319(150,62,'v'), 2320(NULL,7,'c'), 2321(2,1,NULL), 2322(5,0,'x'), 2323(3,7,'i'), 2324(1,7,'e'), 2325(4,1,'p'), 2326(NULL,7,'s'), 2327(2,1,'j'), 2328(6,5,'z'), 2329(6,2,'c'), 2330(8,0,'a'), 2331(2,1,'q'), 2332(6,8,'y'), 2333(8,1,NULL), 2334(3,1,'r'), 2335(3,9,'v'), 2336(9,1,NULL), 2337(6,5,'r') 2338; 2339SELECT col_int_nokey 2340FROM ( 2341SELECT * 2342FROM t2 2343WHERE col_varchar_key > 'a' 2344 OR ( 7 , 5 ) NOT IN ( 2345SELECT col_int_nokey , col_int_key 2346FROM t1 ) 2347) AS alias1; 2348col_int_nokey 23492 2350150 2351NULL 23522 23535 23543 23551 23564 2357NULL 23582 23596 23606 23618 23622 23636 23648 23653 23663 23679 23686 2369DROP TABLE t1; 2370DROP TABLE t2; 2371 2372BUG#12552262 - INVALID JSON WITH TWO CALLS TO TEST_QUICK_SELECT 2373 2374CREATE TABLE t1 ( 2375col_varchar_10_latin1_key varchar(10) DEFAULT NULL, 2376col_int_key INT, 2377KEY col_int_key (col_int_key) 2378); 2379CREATE TABLE t2 ( 2380col_varchar_10_latin1_key varchar(10) DEFAULT NULL, 2381col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8 DEFAULT NULL, 2382col_int_key INT, 2383KEY col_varchar_10_utf8_key (col_varchar_10_utf8_key), 2384KEY col_int_key (col_int_key) 2385); 2386INSERT INTO t2 VALUES ('qykbaqfyhz','l',NULL); 2387CREATE TABLE t3 ( 2388col_int_key INT, 2389col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8 DEFAULT NULL, 2390col_varchar_10_latin1_key varchar(10) DEFAULT NULL, 2391KEY col_varchar_10_utf8_key (col_varchar_10_utf8_key), 2392KEY col_varchar_10_latin1_key (col_varchar_10_latin1_key) 2393); 2394INSERT INTO t3 VALUES (0,'s','it'); 2395INSERT INTO t3 VALUES (9,'IQTHK','JCAQM'); 2396SELECT table2.col_int_key 2397FROM t3 AS table1 2398LEFT JOIN t1 AS table2 ON table1.col_int_key < table2.col_int_key 2399LEFT JOIN t2 AS table3 ON table2.col_varchar_10_latin1_key >= 2400table3.col_varchar_10_utf8_key 2401; 2402col_int_key 2403NULL 2404NULL 2405select * from information_schema.optimizer_trace; 2406QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 2407SELECT table2.col_int_key 2408FROM t3 AS table1 2409LEFT JOIN t1 AS table2 ON table1.col_int_key < table2.col_int_key 2410LEFT JOIN t2 AS table3 ON table2.col_varchar_10_latin1_key >= 2411table3.col_varchar_10_utf8_key { 2412 "steps": [ 2413 { 2414 "join_preparation": { 2415 "select#": 1, 2416 "steps": [ 2417 { 2418 "expanded_query": "/* select#1 */ select `table2`.`col_int_key` AS `col_int_key` from ((`t3` `table1` left join `t1` `table2` on((`table1`.`col_int_key` < `table2`.`col_int_key`))) left join `t2` `table3` on((convert(`table2`.`col_varchar_10_latin1_key` using utf8) >= `table3`.`col_varchar_10_utf8_key`)))" 2419 }, 2420 { 2421 "transformations_to_nested_joins": { 2422 "transformations": [ 2423 "parenthesis_removal" 2424 ] /* transformations */, 2425 "expanded_query": "/* select#1 */ select `table2`.`col_int_key` AS `col_int_key` from `t3` `table1` left join `t1` `table2` on((`table1`.`col_int_key` < `table2`.`col_int_key`)) left join `t2` `table3` on((convert(`table2`.`col_varchar_10_latin1_key` using utf8) >= `table3`.`col_varchar_10_utf8_key`))" 2426 } /* transformations_to_nested_joins */ 2427 } 2428 ] /* steps */ 2429 } /* join_preparation */ 2430 }, 2431 { 2432 "join_optimization": { 2433 "select#": 1, 2434 "steps": [ 2435 { 2436 "condition_processing": { 2437 "condition": "WHERE", 2438 "original_condition": null, 2439 "steps": [ 2440 { 2441 "transformation": "equality_propagation", 2442 "resulting_condition": null 2443 } 2444 ] /* steps */ 2445 } /* condition_processing */ 2446 }, 2447 { 2448 "table_dependencies": [ 2449 { 2450 "table": "`t3` `table1`", 2451 "row_may_be_null": false, 2452 "map_bit": 0, 2453 "depends_on_map_bits": [ 2454 ] /* depends_on_map_bits */ 2455 }, 2456 { 2457 "table": "`t1` `table2`", 2458 "row_may_be_null": true, 2459 "map_bit": 1, 2460 "depends_on_map_bits": [ 2461 0 2462 ] /* depends_on_map_bits */ 2463 }, 2464 { 2465 "table": "`t2` `table3`", 2466 "row_may_be_null": true, 2467 "map_bit": 2, 2468 "depends_on_map_bits": [ 2469 0, 2470 1 2471 ] /* depends_on_map_bits */ 2472 } 2473 ] /* table_dependencies */ 2474 }, 2475 { 2476 "ref_optimizer_key_uses": [ 2477 ] /* ref_optimizer_key_uses */ 2478 }, 2479 { 2480 "rows_estimation": [ 2481 { 2482 "table": "`t3` `table1`", 2483 "table_scan": { 2484 "rows": 2, 2485 "cost": 2 2486 } /* table_scan */ 2487 }, 2488 { 2489 "table": "`t1` `table2`", 2490 "rows": 1, 2491 "cost": 1, 2492 "table_type": "system", 2493 "empty": true 2494 }, 2495 { 2496 "table": "`t2` `table3`", 2497 "table_scan": { 2498 "rows": 1, 2499 "cost": 2 2500 } /* table_scan */ 2501 } 2502 ] /* rows_estimation */ 2503 }, 2504 { 2505 "considered_execution_plans": [ 2506 { 2507 "plan_prefix": [ 2508 "`t1` `table2`" 2509 ] /* plan_prefix */, 2510 "table": "`t3` `table1`", 2511 "best_access_path": { 2512 "considered_access_paths": [ 2513 { 2514 "rows_to_scan": 2, 2515 "access_type": "scan", 2516 "resulting_rows": 2, 2517 "cost": 2.4107, 2518 "chosen": true 2519 } 2520 ] /* considered_access_paths */ 2521 } /* best_access_path */, 2522 "condition_filtering_pct": 100, 2523 "rows_for_plan": 2, 2524 "cost_for_plan": 2.4107, 2525 "rest_of_plan": [ 2526 { 2527 "plan_prefix": [ 2528 "`t1` `table2`", 2529 "`t3` `table1`" 2530 ] /* plan_prefix */, 2531 "table": "`t2` `table3`", 2532 "best_access_path": { 2533 "considered_access_paths": [ 2534 { 2535 "rows_to_scan": 1, 2536 "access_type": "scan", 2537 "using_join_cache": true, 2538 "buffers_needed": 1, 2539 "resulting_rows": 1, 2540 "cost": 2.405, 2541 "chosen": true 2542 } 2543 ] /* considered_access_paths */ 2544 } /* best_access_path */, 2545 "condition_filtering_pct": 100, 2546 "rows_for_plan": 2, 2547 "cost_for_plan": 4.8157, 2548 "chosen": true 2549 } 2550 ] /* rest_of_plan */ 2551 } 2552 ] /* considered_execution_plans */ 2553 }, 2554 { 2555 "condition_on_constant_tables": "1", 2556 "condition_value": true 2557 }, 2558 { 2559 "attaching_conditions_to_tables": { 2560 "original_condition": "1", 2561 "attached_conditions_computation": [ 2562 { 2563 "table": "`t2` `table3`", 2564 "rechecking_index_usage": { 2565 "recheck_reason": "not_first_table", 2566 "range_analysis": { 2567 "table_scan": { 2568 "rows": 1, 2569 "cost": 4.3049 2570 } /* table_scan */, 2571 "potential_range_indexes": [ 2572 { 2573 "index": "col_varchar_10_utf8_key", 2574 "usable": true, 2575 "key_parts": [ 2576 "col_varchar_10_utf8_key" 2577 ] /* key_parts */ 2578 }, 2579 { 2580 "index": "col_int_key", 2581 "usable": false, 2582 "cause": "not_applicable" 2583 } 2584 ] /* potential_range_indexes */, 2585 "best_covering_index_scan": { 2586 "index": "col_varchar_10_utf8_key", 2587 "cost": 1.2, 2588 "chosen": true 2589 } /* best_covering_index_scan */, 2590 "setup_range_conditions": [ 2591 { 2592 "impossible_condition": { 2593 "cause": "comparison_with_null_always_false" 2594 } /* impossible_condition */ 2595 } 2596 ] /* setup_range_conditions */, 2597 "impossible_range": true 2598 } /* range_analysis */, 2599 "without_ON_clause": { 2600 "range_analysis": { 2601 "table_scan": { 2602 "rows": 1, 2603 "cost": 4.3049 2604 } /* table_scan */, 2605 "potential_range_indexes": [ 2606 { 2607 "index": "col_varchar_10_utf8_key", 2608 "usable": true, 2609 "key_parts": [ 2610 "col_varchar_10_utf8_key" 2611 ] /* key_parts */ 2612 }, 2613 { 2614 "index": "col_int_key", 2615 "usable": false, 2616 "cause": "not_applicable" 2617 } 2618 ] /* potential_range_indexes */, 2619 "best_covering_index_scan": { 2620 "index": "col_varchar_10_utf8_key", 2621 "cost": 1.2, 2622 "chosen": true 2623 } /* best_covering_index_scan */, 2624 "group_index_range": { 2625 "chosen": false, 2626 "cause": "not_single_table" 2627 } /* group_index_range */ 2628 } /* range_analysis */ 2629 } /* without_ON_clause */ 2630 } /* rechecking_index_usage */ 2631 } 2632 ] /* attached_conditions_computation */, 2633 "attached_conditions_summary": [ 2634 { 2635 "table": "`t3` `table1`", 2636 "attached": null 2637 }, 2638 { 2639 "table": "`t2` `table3`", 2640 "attached": "<if>(is_not_null_compl(table3), (convert(NULL using utf8) >= `table3`.`col_varchar_10_utf8_key`), true)" 2641 } 2642 ] /* attached_conditions_summary */ 2643 } /* attaching_conditions_to_tables */ 2644 }, 2645 { 2646 "refine_plan": [ 2647 { 2648 "table": "`t3` `table1`" 2649 }, 2650 { 2651 "table": "`t2` `table3`" 2652 } 2653 ] /* refine_plan */ 2654 } 2655 ] /* steps */ 2656 } /* join_optimization */ 2657 }, 2658 { 2659 "join_execution": { 2660 "select#": 1, 2661 "steps": [ 2662 ] /* steps */ 2663 } /* join_execution */ 2664 } 2665 ] /* steps */ 2666} 0 0 2667DROP TABLE t1,t2,t3; 2668 2669Tests of tracing of the "eq_ref optimization" of plan search 2670 2671create table t0 (a int); 2672insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); 2673create table t1 (a int, b int, key(a)); 2674create table t2 (a int, b int, key(a)); 2675create table t3 (a int, b int, key(a)); 2676insert into t1 select a,a from t0; 2677insert into t2 select a,a from t0; 2678insert into t3 select a,a from t0; 2679set @old_opt_switch=@@optimizer_switch; 2680explain select * 2681from t0 where a in 2682(select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a); 2683id select_type table partitions type possible_keys key key_len ref rows filtered Extra 26841 PRIMARY t0 NULL ALL NULL NULL NULL NULL 10 100.00 Using where 26852 DEPENDENT SUBQUERY t1 NULL index a a 5 NULL 10 100.00 Using where; Using index 26862 DEPENDENT SUBQUERY t2 NULL ref a a 5 test.t1.a 1 100.00 Using index 26872 DEPENDENT SUBQUERY t3 NULL ref a a 5 test.t1.a 1 100.00 Using index 2688Warnings: 2689Note 1003 /* select#1 */ select `test`.`t0`.`a` AS `a` from `test`.`t0` where <in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`) and (<cache>(`test`.`t0`.`a`) = (`test`.`t1`.`a` + `test`.`t1`.`a`))))) 2690select * from information_schema.optimizer_trace; 2691QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 2692explain select * 2693from t0 where a in 2694(select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a) { 2695 "steps": [ 2696 { 2697 "join_preparation": { 2698 "select#": 1, 2699 "steps": [ 2700 { 2701 "join_preparation": { 2702 "select#": 2, 2703 "steps": [ 2704 { 2705 "expanded_query": "/* select#2 */ select (`t2`.`a` + `t3`.`a`) from (`t1` left join (`t2` join `t3`) on(((`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))))" 2706 }, 2707 { 2708 "transformation": { 2709 "select#": 2, 2710 "from": "IN (SELECT)", 2711 "to": "semijoin", 2712 "chosen": false 2713 } /* transformation */ 2714 }, 2715 { 2716 "transformation": { 2717 "select#": 2, 2718 "from": "IN (SELECT)", 2719 "to": "EXISTS (CORRELATED SELECT)", 2720 "chosen": true, 2721 "evaluating_constant_where_conditions": [ 2722 ] /* evaluating_constant_where_conditions */ 2723 } /* transformation */ 2724 } 2725 ] /* steps */ 2726 } /* join_preparation */ 2727 }, 2728 { 2729 "expanded_query": "/* select#1 */ select `t0`.`a` AS `a` from `t0` where <in_optimizer>(`t0`.`a`,<exists>(/* select#2 */ select (`t2`.`a` + `t3`.`a`) from (`t1` left join (`t2` join `t3`) on(((`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`)))) where (<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`))))" 2730 }, 2731 { 2732 "transformations_to_nested_joins": { 2733 "transformations": [ 2734 "outer_join_to_inner_join", 2735 "JOIN_condition_to_WHERE", 2736 "parenthesis_removal" 2737 ] /* transformations */, 2738 "expanded_query": "/* select#2 */ select (`t2`.`a` + `t3`.`a`) from `t1` join `t2` join `t3` where ((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))" 2739 } /* transformations_to_nested_joins */ 2740 } 2741 ] /* steps */ 2742 } /* join_preparation */ 2743 }, 2744 { 2745 "join_optimization": { 2746 "select#": 1, 2747 "steps": [ 2748 { 2749 "condition_processing": { 2750 "condition": "WHERE", 2751 "original_condition": "<in_optimizer>(`t0`.`a`,<exists>(/* select#2 */ select (`t2`.`a` + `t3`.`a`) from `t1` join `t2` join `t3` where ((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))))", 2752 "steps": [ 2753 { 2754 "transformation": "equality_propagation", 2755 "subselect_evaluation": [ 2756 ] /* subselect_evaluation */, 2757 "resulting_condition": "<in_optimizer>(`t0`.`a`,<exists>(/* select#2 */ select (`t2`.`a` + `t3`.`a`) from `t1` join `t2` join `t3` where ((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))))" 2758 }, 2759 { 2760 "transformation": "constant_propagation", 2761 "subselect_evaluation": [ 2762 ] /* subselect_evaluation */, 2763 "resulting_condition": "<in_optimizer>(`t0`.`a`,<exists>(/* select#2 */ select (`t2`.`a` + `t3`.`a`) from `t1` join `t2` join `t3` where ((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))))" 2764 }, 2765 { 2766 "transformation": "trivial_condition_removal", 2767 "subselect_evaluation": [ 2768 ] /* subselect_evaluation */, 2769 "resulting_condition": "<in_optimizer>(`t0`.`a`,<exists>(/* select#2 */ select (`t2`.`a` + `t3`.`a`) from `t1` join `t2` join `t3` where ((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))))" 2770 } 2771 ] /* steps */ 2772 } /* condition_processing */ 2773 }, 2774 { 2775 "substitute_generated_columns": { 2776 } /* substitute_generated_columns */ 2777 }, 2778 { 2779 "table_dependencies": [ 2780 { 2781 "table": "`t0`", 2782 "row_may_be_null": false, 2783 "map_bit": 0, 2784 "depends_on_map_bits": [ 2785 ] /* depends_on_map_bits */ 2786 } 2787 ] /* table_dependencies */ 2788 }, 2789 { 2790 "ref_optimizer_key_uses": [ 2791 ] /* ref_optimizer_key_uses */ 2792 }, 2793 { 2794 "rows_estimation": [ 2795 { 2796 "table": "`t0`", 2797 "table_scan": { 2798 "rows": 10, 2799 "cost": 2 2800 } /* table_scan */ 2801 } 2802 ] /* rows_estimation */ 2803 }, 2804 { 2805 "considered_execution_plans": [ 2806 { 2807 "plan_prefix": [ 2808 ] /* plan_prefix */, 2809 "table": "`t0`", 2810 "best_access_path": { 2811 "considered_access_paths": [ 2812 { 2813 "rows_to_scan": 10, 2814 "access_type": "scan", 2815 "resulting_rows": 10, 2816 "cost": 4.0171, 2817 "chosen": true 2818 } 2819 ] /* considered_access_paths */ 2820 } /* best_access_path */, 2821 "condition_filtering_pct": 100, 2822 "rows_for_plan": 10, 2823 "cost_for_plan": 4.0171, 2824 "chosen": true 2825 } 2826 ] /* considered_execution_plans */ 2827 }, 2828 { 2829 "attaching_conditions_to_tables": { 2830 "original_condition": "<in_optimizer>(`t0`.`a`,<exists>(/* select#2 */ select (`t2`.`a` + `t3`.`a`) from `t1` join `t2` join `t3` where ((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))))", 2831 "attached_conditions_computation": [ 2832 ] /* attached_conditions_computation */, 2833 "attached_conditions_summary": [ 2834 { 2835 "table": "`t0`", 2836 "attached": "<in_optimizer>(`t0`.`a`,<exists>(/* select#2 */ select (`t2`.`a` + `t3`.`a`) from `t1` join `t2` join `t3` where ((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))))" 2837 } 2838 ] /* attached_conditions_summary */ 2839 } /* attaching_conditions_to_tables */ 2840 }, 2841 { 2842 "refine_plan": [ 2843 { 2844 "table": "`t0`" 2845 } 2846 ] /* refine_plan */ 2847 } 2848 ] /* steps */ 2849 } /* join_optimization */ 2850 }, 2851 { 2852 "join_optimization": { 2853 "select#": 2, 2854 "steps": [ 2855 { 2856 "condition_processing": { 2857 "condition": "WHERE", 2858 "original_condition": "((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and (`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`))", 2859 "steps": [ 2860 { 2861 "transformation": "equality_propagation", 2862 "resulting_condition": "((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and multiple equal(`t2`.`a`, `t1`.`a`, `t3`.`a`))" 2863 }, 2864 { 2865 "transformation": "constant_propagation", 2866 "resulting_condition": "((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and multiple equal(`t2`.`a`, `t1`.`a`, `t3`.`a`))" 2867 }, 2868 { 2869 "transformation": "trivial_condition_removal", 2870 "resulting_condition": "((<cache>(`t0`.`a`) = (`t2`.`a` + `t3`.`a`)) and multiple equal(`t2`.`a`, `t1`.`a`, `t3`.`a`))" 2871 } 2872 ] /* steps */ 2873 } /* condition_processing */ 2874 }, 2875 { 2876 "substitute_generated_columns": { 2877 } /* substitute_generated_columns */ 2878 }, 2879 { 2880 "table_dependencies": [ 2881 { 2882 "table": "`t1`", 2883 "row_may_be_null": false, 2884 "map_bit": 0, 2885 "depends_on_map_bits": [ 2886 ] /* depends_on_map_bits */ 2887 }, 2888 { 2889 "table": "`t2`", 2890 "row_may_be_null": true, 2891 "map_bit": 1, 2892 "depends_on_map_bits": [ 2893 ] /* depends_on_map_bits */ 2894 }, 2895 { 2896 "table": "`t3`", 2897 "row_may_be_null": true, 2898 "map_bit": 2, 2899 "depends_on_map_bits": [ 2900 ] /* depends_on_map_bits */ 2901 } 2902 ] /* table_dependencies */ 2903 }, 2904 { 2905 "ref_optimizer_key_uses": [ 2906 { 2907 "table": "`t1`", 2908 "field": "a", 2909 "equals": "`t2`.`a`", 2910 "null_rejecting": true 2911 }, 2912 { 2913 "table": "`t1`", 2914 "field": "a", 2915 "equals": "`t3`.`a`", 2916 "null_rejecting": true 2917 }, 2918 { 2919 "table": "`t2`", 2920 "field": "a", 2921 "equals": "`t1`.`a`", 2922 "null_rejecting": true 2923 }, 2924 { 2925 "table": "`t2`", 2926 "field": "a", 2927 "equals": "`t3`.`a`", 2928 "null_rejecting": true 2929 }, 2930 { 2931 "table": "`t3`", 2932 "field": "a", 2933 "equals": "`t2`.`a`", 2934 "null_rejecting": true 2935 }, 2936 { 2937 "table": "`t3`", 2938 "field": "a", 2939 "equals": "`t1`.`a`", 2940 "null_rejecting": true 2941 } 2942 ] /* ref_optimizer_key_uses */ 2943 }, 2944 { 2945 "rows_estimation": [ 2946 { 2947 "table": "`t1`", 2948 "table_scan": { 2949 "rows": 10, 2950 "cost": 2 2951 } /* table_scan */ 2952 }, 2953 { 2954 "table": "`t2`", 2955 "table_scan": { 2956 "rows": 10, 2957 "cost": 2 2958 } /* table_scan */ 2959 }, 2960 { 2961 "table": "`t3`", 2962 "table_scan": { 2963 "rows": 10, 2964 "cost": 2 2965 } /* table_scan */ 2966 } 2967 ] /* rows_estimation */ 2968 }, 2969 { 2970 "considered_execution_plans": [ 2971 { 2972 "plan_prefix": [ 2973 ] /* plan_prefix */, 2974 "table": "`t1`", 2975 "best_access_path": { 2976 "considered_access_paths": [ 2977 { 2978 "access_type": "ref", 2979 "index": "a", 2980 "usable": false, 2981 "chosen": false 2982 }, 2983 { 2984 "rows_to_scan": 10, 2985 "access_type": "scan", 2986 "resulting_rows": 10, 2987 "cost": 4.022, 2988 "chosen": true 2989 } 2990 ] /* considered_access_paths */ 2991 } /* best_access_path */, 2992 "condition_filtering_pct": 100, 2993 "rows_for_plan": 10, 2994 "cost_for_plan": 4.022, 2995 "rest_of_plan": [ 2996 { 2997 "plan_prefix": [ 2998 "`t1`" 2999 ] /* plan_prefix */, 3000 "table": "`t2`", 3001 "best_access_path": { 3002 "considered_access_paths": [ 3003 { 3004 "access_type": "ref", 3005 "index": "a", 3006 "rows": 1, 3007 "cost": 12, 3008 "chosen": true 3009 }, 3010 { 3011 "rows_to_scan": 10, 3012 "access_type": "scan", 3013 "using_join_cache": true, 3014 "buffers_needed": 1, 3015 "resulting_rows": 10, 3016 "cost": 22.022, 3017 "chosen": false 3018 } 3019 ] /* considered_access_paths */ 3020 } /* best_access_path */, 3021 "condition_filtering_pct": 100, 3022 "rows_for_plan": 10, 3023 "cost_for_plan": 16.022, 3024 "rest_of_plan": [ 3025 { 3026 "plan_prefix": [ 3027 "`t1`", 3028 "`t2`" 3029 ] /* plan_prefix */, 3030 "table": "`t3`", 3031 "best_access_path": { 3032 "considered_access_paths": [ 3033 { 3034 "access_type": "ref", 3035 "index": "a", 3036 "rows": 1, 3037 "cost": 12, 3038 "chosen": true 3039 }, 3040 { 3041 "rows_to_scan": 10, 3042 "access_type": "scan", 3043 "using_join_cache": true, 3044 "buffers_needed": 1, 3045 "resulting_rows": 10, 3046 "cost": 22.023, 3047 "chosen": false 3048 } 3049 ] /* considered_access_paths */ 3050 } /* best_access_path */, 3051 "added_to_eq_ref_extension": true, 3052 "condition_filtering_pct": 100, 3053 "rows_for_plan": 10, 3054 "cost_for_plan": 28.022, 3055 "chosen": true 3056 } 3057 ] /* rest_of_plan */ 3058 } 3059 ] /* rest_of_plan */ 3060 }, 3061 { 3062 "plan_prefix": [ 3063 ] /* plan_prefix */, 3064 "table": "`t2`", 3065 "best_access_path": { 3066 "considered_access_paths": [ 3067 { 3068 "access_type": "ref", 3069 "index": "a", 3070 "usable": false, 3071 "chosen": false 3072 }, 3073 { 3074 "rows_to_scan": 10, 3075 "access_type": "scan", 3076 "resulting_rows": 10, 3077 "cost": 4.022, 3078 "chosen": true 3079 } 3080 ] /* considered_access_paths */ 3081 } /* best_access_path */, 3082 "condition_filtering_pct": 100, 3083 "rows_for_plan": 10, 3084 "cost_for_plan": 4.022, 3085 "rest_of_plan": [ 3086 { 3087 "plan_prefix": [ 3088 "`t2`" 3089 ] /* plan_prefix */, 3090 "table": "`t1`", 3091 "best_access_path": { 3092 "considered_access_paths": [ 3093 { 3094 "access_type": "ref", 3095 "index": "a", 3096 "rows": 1, 3097 "cost": 12, 3098 "chosen": true 3099 }, 3100 { 3101 "rows_to_scan": 10, 3102 "access_type": "scan", 3103 "using_join_cache": true, 3104 "buffers_needed": 1, 3105 "resulting_rows": 10, 3106 "cost": 22.022, 3107 "chosen": false 3108 } 3109 ] /* considered_access_paths */ 3110 } /* best_access_path */, 3111 "condition_filtering_pct": 100, 3112 "rows_for_plan": 10, 3113 "cost_for_plan": 16.022, 3114 "rest_of_plan": [ 3115 { 3116 "plan_prefix": [ 3117 "`t2`", 3118 "`t1`" 3119 ] /* plan_prefix */, 3120 "table": "`t3`", 3121 "best_access_path": { 3122 "considered_access_paths": [ 3123 { 3124 "access_type": "ref", 3125 "index": "a", 3126 "rows": 1, 3127 "cost": 12, 3128 "chosen": true 3129 }, 3130 { 3131 "rows_to_scan": 10, 3132 "access_type": "scan", 3133 "using_join_cache": true, 3134 "buffers_needed": 1, 3135 "resulting_rows": 10, 3136 "cost": 22.023, 3137 "chosen": false 3138 } 3139 ] /* considered_access_paths */ 3140 } /* best_access_path */, 3141 "added_to_eq_ref_extension": true, 3142 "condition_filtering_pct": 100, 3143 "rows_for_plan": 10, 3144 "cost_for_plan": 28.022, 3145 "pruned_by_cost": true 3146 }, 3147 { 3148 "plan_prefix": [ 3149 "`t2`", 3150 "`t1`" 3151 ] /* plan_prefix */, 3152 "table": "`t3`", 3153 "best_access_path": { 3154 "considered_access_paths": [ 3155 { 3156 "access_type": "ref", 3157 "index": "a", 3158 "rows": 1, 3159 "cost": 12, 3160 "chosen": true 3161 }, 3162 { 3163 "rows_to_scan": 10, 3164 "access_type": "scan", 3165 "using_join_cache": true, 3166 "buffers_needed": 1, 3167 "resulting_rows": 10, 3168 "cost": 22.023, 3169 "chosen": false 3170 } 3171 ] /* considered_access_paths */ 3172 } /* best_access_path */, 3173 "condition_filtering_pct": 100, 3174 "rows_for_plan": 10, 3175 "cost_for_plan": 28.022, 3176 "pruned_by_cost": true 3177 } 3178 ] /* rest_of_plan */ 3179 }, 3180 { 3181 "plan_prefix": [ 3182 "`t2`" 3183 ] /* plan_prefix */, 3184 "table": "`t3`", 3185 "best_access_path": { 3186 "considered_access_paths": [ 3187 { 3188 "access_type": "ref", 3189 "index": "a", 3190 "rows": 1, 3191 "cost": 12, 3192 "chosen": true 3193 }, 3194 { 3195 "rows_to_scan": 10, 3196 "access_type": "scan", 3197 "using_join_cache": true, 3198 "buffers_needed": 1, 3199 "resulting_rows": 10, 3200 "cost": 22.022, 3201 "chosen": false 3202 } 3203 ] /* considered_access_paths */ 3204 } /* best_access_path */, 3205 "condition_filtering_pct": 100, 3206 "rows_for_plan": 10, 3207 "cost_for_plan": 16.022, 3208 "pruned_by_heuristic": true 3209 } 3210 ] /* rest_of_plan */ 3211 }, 3212 { 3213 "plan_prefix": [ 3214 ] /* plan_prefix */, 3215 "table": "`t3`", 3216 "best_access_path": { 3217 "considered_access_paths": [ 3218 { 3219 "access_type": "ref", 3220 "index": "a", 3221 "usable": false, 3222 "chosen": false 3223 }, 3224 { 3225 "rows_to_scan": 10, 3226 "access_type": "scan", 3227 "resulting_rows": 10, 3228 "cost": 4.022, 3229 "chosen": true 3230 } 3231 ] /* considered_access_paths */ 3232 } /* best_access_path */, 3233 "condition_filtering_pct": 100, 3234 "rows_for_plan": 10, 3235 "cost_for_plan": 4.022, 3236 "rest_of_plan": [ 3237 { 3238 "plan_prefix": [ 3239 "`t3`" 3240 ] /* plan_prefix */, 3241 "table": "`t1`", 3242 "best_access_path": { 3243 "considered_access_paths": [ 3244 { 3245 "access_type": "ref", 3246 "index": "a", 3247 "rows": 1, 3248 "cost": 12, 3249 "chosen": true 3250 }, 3251 { 3252 "rows_to_scan": 10, 3253 "access_type": "scan", 3254 "using_join_cache": true, 3255 "buffers_needed": 1, 3256 "resulting_rows": 10, 3257 "cost": 22.022, 3258 "chosen": false 3259 } 3260 ] /* considered_access_paths */ 3261 } /* best_access_path */, 3262 "condition_filtering_pct": 100, 3263 "rows_for_plan": 10, 3264 "cost_for_plan": 16.022, 3265 "rest_of_plan": [ 3266 { 3267 "plan_prefix": [ 3268 "`t3`", 3269 "`t1`" 3270 ] /* plan_prefix */, 3271 "table": "`t2`", 3272 "best_access_path": { 3273 "considered_access_paths": [ 3274 { 3275 "access_type": "ref", 3276 "index": "a", 3277 "rows": 1, 3278 "cost": 12, 3279 "chosen": true 3280 }, 3281 { 3282 "rows_to_scan": 10, 3283 "access_type": "scan", 3284 "using_join_cache": true, 3285 "buffers_needed": 1, 3286 "resulting_rows": 10, 3287 "cost": 22.023, 3288 "chosen": false 3289 } 3290 ] /* considered_access_paths */ 3291 } /* best_access_path */, 3292 "added_to_eq_ref_extension": true, 3293 "condition_filtering_pct": 100, 3294 "rows_for_plan": 10, 3295 "cost_for_plan": 28.022, 3296 "pruned_by_cost": true 3297 }, 3298 { 3299 "plan_prefix": [ 3300 "`t3`", 3301 "`t1`" 3302 ] /* plan_prefix */, 3303 "table": "`t2`", 3304 "best_access_path": { 3305 "considered_access_paths": [ 3306 { 3307 "access_type": "ref", 3308 "index": "a", 3309 "rows": 1, 3310 "cost": 12, 3311 "chosen": true 3312 }, 3313 { 3314 "rows_to_scan": 10, 3315 "access_type": "scan", 3316 "using_join_cache": true, 3317 "buffers_needed": 1, 3318 "resulting_rows": 10, 3319 "cost": 22.023, 3320 "chosen": false 3321 } 3322 ] /* considered_access_paths */ 3323 } /* best_access_path */, 3324 "condition_filtering_pct": 100, 3325 "rows_for_plan": 10, 3326 "cost_for_plan": 28.022, 3327 "pruned_by_cost": true 3328 } 3329 ] /* rest_of_plan */ 3330 }, 3331 { 3332 "plan_prefix": [ 3333 "`t3`" 3334 ] /* plan_prefix */, 3335 "table": "`t2`", 3336 "best_access_path": { 3337 "considered_access_paths": [ 3338 { 3339 "access_type": "ref", 3340 "index": "a", 3341 "rows": 1, 3342 "cost": 12, 3343 "chosen": true 3344 }, 3345 { 3346 "rows_to_scan": 10, 3347 "access_type": "scan", 3348 "using_join_cache": true, 3349 "buffers_needed": 1, 3350 "resulting_rows": 10, 3351 "cost": 22.022, 3352 "chosen": false 3353 } 3354 ] /* considered_access_paths */ 3355 } /* best_access_path */, 3356 "condition_filtering_pct": 100, 3357 "rows_for_plan": 10, 3358 "cost_for_plan": 16.022, 3359 "pruned_by_heuristic": true 3360 } 3361 ] /* rest_of_plan */ 3362 } 3363 ] /* considered_execution_plans */ 3364 }, 3365 { 3366 "transformation": { 3367 "select#": 2, 3368 "from": "IN (SELECT)", 3369 "to": "EXISTS (CORRELATED SELECT)", 3370 "put_1_in_SELECT_list": true 3371 } /* transformation */ 3372 }, 3373 { 3374 "attaching_conditions_to_tables": { 3375 "original_condition": "((`t2`.`a` = `t1`.`a`) and (`t3`.`a` = `t1`.`a`) and (<cache>(`t0`.`a`) = (`t1`.`a` + `t1`.`a`)))", 3376 "attached_conditions_computation": [ 3377 { 3378 "table": "`t1`", 3379 "rechecking_index_usage": { 3380 "recheck_reason": "not_first_table", 3381 "range_analysis": { 3382 "table_scan": { 3383 "rows": 10, 3384 "cost": 14 3385 } /* table_scan */, 3386 "potential_range_indexes": [ 3387 { 3388 "index": "a", 3389 "usable": true, 3390 "key_parts": [ 3391 "a" 3392 ] /* key_parts */ 3393 } 3394 ] /* potential_range_indexes */, 3395 "best_covering_index_scan": { 3396 "index": "a", 3397 "cost": 3.2093, 3398 "chosen": true 3399 } /* best_covering_index_scan */, 3400 "setup_range_conditions": [ 3401 ] /* setup_range_conditions */, 3402 "group_index_range": { 3403 "chosen": false, 3404 "cause": "not_single_table" 3405 } /* group_index_range */ 3406 } /* range_analysis */ 3407 } /* rechecking_index_usage */ 3408 } 3409 ] /* attached_conditions_computation */, 3410 "attached_conditions_summary": [ 3411 { 3412 "table": "`t1`", 3413 "attached": "(<cache>(`t0`.`a`) = (`t1`.`a` + `t1`.`a`))" 3414 }, 3415 { 3416 "table": "`t2`", 3417 "attached": null 3418 }, 3419 { 3420 "table": "`t3`", 3421 "attached": null 3422 } 3423 ] /* attached_conditions_summary */ 3424 } /* attaching_conditions_to_tables */ 3425 }, 3426 { 3427 "refine_plan": [ 3428 { 3429 "table": "`t1`" 3430 }, 3431 { 3432 "table": "`t2`" 3433 }, 3434 { 3435 "table": "`t3`" 3436 } 3437 ] /* refine_plan */ 3438 } 3439 ] /* steps */ 3440 } /* join_optimization */ 3441 }, 3442 { 3443 "join_explain": { 3444 "select#": 1, 3445 "steps": [ 3446 { 3447 "join_explain": { 3448 "select#": 2, 3449 "steps": [ 3450 ] /* steps */ 3451 } /* join_explain */ 3452 } 3453 ] /* steps */ 3454 } /* join_explain */ 3455 } 3456 ] /* steps */ 3457} 0 0 3458set optimizer_switch=@old_opt_switch; 3459drop table t0,t1,t2,t3; 3460CREATE TABLE t1 ( 3461OBJECTID int(11) NOT NULL default '0', 3462SORTORDER int(11) NOT NULL auto_increment, 3463KEY t1_SortIndex (SORTORDER), 3464KEY t1_IdIndex (OBJECTID) 3465) ENGINE=MyISAM DEFAULT CHARSET=latin1; 3466CREATE TABLE t2 ( 3467ID int(11) default NULL, 3468PARID int(11) default NULL, 3469UNIQUE KEY t2_ID_IDX (ID), 3470KEY t2_PARID_IDX (PARID) 3471) engine=MyISAM DEFAULT CHARSET=latin1; 3472INSERT INTO t2 VALUES (1000,0),(1001,0),(1002,0),(1003,0),(1008,1),(1009,1),(1010,1),(1011,1),(1016,2); 3473CREATE TABLE t3 ( 3474ID int(11) default NULL, 3475DATA decimal(10,2) default NULL, 3476UNIQUE KEY t3_ID_IDX (ID) 3477) engine=MyISAM DEFAULT CHARSET=latin1; 3478INSERT INTO t3 VALUES (1000,0.00),(1001,0.25),(1002,0.50),(1003,0.75),(1008,1.00),(1009,1.25),(1010,1.50),(1011,1.75); 3479select 497, tmp.ID, NULL from (select 497 as ID, MAX(t3.DATA) as DATA from t1 join t2 on (t1.ObjectID = t2.ID) join t3 on (t1.ObjectID = t3.ID) group by t2.ParID order by DATA DESC) as tmp; 3480497 ID NULL 3481select * from information_schema.optimizer_trace; 3482QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 3483select 497, tmp.ID, NULL from (select 497 as ID, MAX(t3.DATA) as DATA from t1 join t2 on (t1.ObjectID = t2.ID) join t3 on (t1.ObjectID = t3.ID) group by t2.ParID order by DATA DESC) as tmp { 3484 "steps": [ 3485 { 3486 "join_preparation": { 3487 "select#": 1, 3488 "steps": [ 3489 { 3490 "join_preparation": { 3491 "select#": 2, 3492 "steps": [ 3493 { 3494 "expanded_query": "/* select#2 */ select 497 AS `ID`,max(`t3`.`DATA`) AS `DATA` from ((`t1` join `t2` on((`t1`.`OBJECTID` = `t2`.`ID`))) join `t3` on((`t1`.`OBJECTID` = `t3`.`ID`))) group by `t2`.`PARID` order by `DATA` desc" 3495 } 3496 ] /* steps */ 3497 } /* join_preparation */ 3498 }, 3499 { 3500 "derived": { 3501 "table": " `tmp`", 3502 "select#": 2, 3503 "materialized": true 3504 } /* derived */ 3505 }, 3506 { 3507 "expanded_query": "/* select#1 */ select 497 AS `497`,`tmp`.`ID` AS `ID`,NULL AS `NULL` from (/* select#2 */ select 497 AS `ID`,max(`t3`.`DATA`) AS `DATA` from ((`t1` join `t2` on((`t1`.`OBJECTID` = `t2`.`ID`))) join `t3` on((`t1`.`OBJECTID` = `t3`.`ID`))) group by `t2`.`PARID` order by `DATA` desc) `tmp`" 3508 }, 3509 { 3510 "transformations_to_nested_joins": { 3511 "transformations": [ 3512 "JOIN_condition_to_WHERE", 3513 "parenthesis_removal" 3514 ] /* transformations */, 3515 "expanded_query": "/* select#2 */ select 497 AS `ID`,max(`t3`.`DATA`) AS `DATA` from `t1` join `t2` join `t3` where ((`t1`.`OBJECTID` = `t3`.`ID`) and (`t1`.`OBJECTID` = `t2`.`ID`)) group by `t2`.`PARID` order by `DATA` desc" 3516 } /* transformations_to_nested_joins */ 3517 } 3518 ] /* steps */ 3519 } /* join_preparation */ 3520 }, 3521 { 3522 "join_optimization": { 3523 "select#": 1, 3524 "steps": [ 3525 { 3526 "join_optimization": { 3527 "select#": 2, 3528 "steps": [ 3529 { 3530 "condition_processing": { 3531 "condition": "WHERE", 3532 "original_condition": "((`t1`.`OBJECTID` = `t3`.`ID`) and (`t1`.`OBJECTID` = `t2`.`ID`))", 3533 "steps": [ 3534 { 3535 "transformation": "equality_propagation", 3536 "resulting_condition": "(multiple equal(`t1`.`OBJECTID`, `t3`.`ID`, `t2`.`ID`))" 3537 }, 3538 { 3539 "transformation": "constant_propagation", 3540 "resulting_condition": "(multiple equal(`t1`.`OBJECTID`, `t3`.`ID`, `t2`.`ID`))" 3541 }, 3542 { 3543 "transformation": "trivial_condition_removal", 3544 "resulting_condition": "multiple equal(`t1`.`OBJECTID`, `t3`.`ID`, `t2`.`ID`)" 3545 } 3546 ] /* steps */ 3547 } /* condition_processing */ 3548 }, 3549 { 3550 "substitute_generated_columns": { 3551 } /* substitute_generated_columns */ 3552 }, 3553 { 3554 "table_dependencies": [ 3555 { 3556 "table": "`t1`", 3557 "row_may_be_null": false, 3558 "map_bit": 0, 3559 "depends_on_map_bits": [ 3560 ] /* depends_on_map_bits */ 3561 }, 3562 { 3563 "table": "`t2`", 3564 "row_may_be_null": false, 3565 "map_bit": 1, 3566 "depends_on_map_bits": [ 3567 ] /* depends_on_map_bits */ 3568 }, 3569 { 3570 "table": "`t3`", 3571 "row_may_be_null": false, 3572 "map_bit": 2, 3573 "depends_on_map_bits": [ 3574 ] /* depends_on_map_bits */ 3575 } 3576 ] /* table_dependencies */ 3577 }, 3578 { 3579 "ref_optimizer_key_uses": [ 3580 { 3581 "table": "`t1`", 3582 "field": "OBJECTID", 3583 "equals": "`t3`.`ID`", 3584 "null_rejecting": true 3585 }, 3586 { 3587 "table": "`t1`", 3588 "field": "OBJECTID", 3589 "equals": "`t2`.`ID`", 3590 "null_rejecting": true 3591 }, 3592 { 3593 "table": "`t2`", 3594 "field": "ID", 3595 "equals": "`t1`.`OBJECTID`", 3596 "null_rejecting": false 3597 }, 3598 { 3599 "table": "`t2`", 3600 "field": "ID", 3601 "equals": "`t3`.`ID`", 3602 "null_rejecting": true 3603 }, 3604 { 3605 "table": "`t3`", 3606 "field": "ID", 3607 "equals": "`t1`.`OBJECTID`", 3608 "null_rejecting": false 3609 }, 3610 { 3611 "table": "`t3`", 3612 "field": "ID", 3613 "equals": "`t2`.`ID`", 3614 "null_rejecting": true 3615 } 3616 ] /* ref_optimizer_key_uses */ 3617 }, 3618 { 3619 "rows_estimation": [ 3620 { 3621 "table": "`t1`", 3622 "rows": 1, 3623 "cost": 1, 3624 "table_type": "system", 3625 "empty": true 3626 }, 3627 { 3628 "table": "`t2`", 3629 "const_keys_added": { 3630 "keys": [ 3631 "t2_PARID_IDX" 3632 ] /* keys */, 3633 "cause": "group_by" 3634 } /* const_keys_added */, 3635 "range_analysis": { 3636 "table_scan": { 3637 "rows": 9, 3638 "cost": 5.9198 3639 } /* table_scan */, 3640 "potential_range_indexes": [ 3641 { 3642 "index": "t2_ID_IDX", 3643 "usable": false, 3644 "cause": "not_applicable" 3645 }, 3646 { 3647 "index": "t2_PARID_IDX", 3648 "usable": true, 3649 "key_parts": [ 3650 "PARID" 3651 ] /* key_parts */ 3652 } 3653 ] /* potential_range_indexes */, 3654 "setup_range_conditions": [ 3655 ] /* setup_range_conditions */, 3656 "group_index_range": { 3657 "chosen": false, 3658 "cause": "not_single_table" 3659 } /* group_index_range */ 3660 } /* range_analysis */ 3661 }, 3662 { 3663 "table": "`t3`", 3664 "table_scan": { 3665 "rows": 8, 3666 "cost": 2 3667 } /* table_scan */ 3668 } 3669 ] /* rows_estimation */ 3670 }, 3671 { 3672 "considered_execution_plans": [ 3673 { 3674 "plan_prefix": [ 3675 "`t1`" 3676 ] /* plan_prefix */, 3677 "table": "`t3`", 3678 "best_access_path": { 3679 "considered_access_paths": [ 3680 { 3681 "access_type": "ref", 3682 "index": "t3_ID_IDX", 3683 "rows": 1, 3684 "cost": 1.2, 3685 "chosen": true 3686 }, 3687 { 3688 "access_type": "scan", 3689 "cost": 3.6, 3690 "rows": 8, 3691 "chosen": false, 3692 "cause": "cost" 3693 } 3694 ] /* considered_access_paths */ 3695 } /* best_access_path */, 3696 "condition_filtering_pct": 100, 3697 "rows_for_plan": 1, 3698 "cost_for_plan": 1.2, 3699 "rest_of_plan": [ 3700 { 3701 "plan_prefix": [ 3702 "`t1`", 3703 "`t3`" 3704 ] /* plan_prefix */, 3705 "table": "`t2`", 3706 "best_access_path": { 3707 "considered_access_paths": [ 3708 { 3709 "access_type": "ref", 3710 "index": "t2_ID_IDX", 3711 "rows": 2, 3712 "cost": 2.4, 3713 "chosen": true 3714 }, 3715 { 3716 "access_type": "scan", 3717 "cost": 3.8, 3718 "rows": 9, 3719 "chosen": false, 3720 "cause": "cost" 3721 } 3722 ] /* considered_access_paths */ 3723 } /* best_access_path */, 3724 "added_to_eq_ref_extension": false 3725 }, 3726 { 3727 "plan_prefix": [ 3728 "`t1`", 3729 "`t3`" 3730 ] /* plan_prefix */, 3731 "table": "`t2`", 3732 "best_access_path": { 3733 "considered_access_paths": [ 3734 { 3735 "access_type": "ref", 3736 "index": "t2_ID_IDX", 3737 "rows": 2, 3738 "cost": 2.4, 3739 "chosen": true 3740 }, 3741 { 3742 "access_type": "scan", 3743 "cost": 3.8, 3744 "rows": 9, 3745 "chosen": false, 3746 "cause": "cost" 3747 } 3748 ] /* considered_access_paths */ 3749 } /* best_access_path */, 3750 "condition_filtering_pct": 100, 3751 "rows_for_plan": 2, 3752 "cost_for_plan": 3.6, 3753 "chosen": true 3754 } 3755 ] /* rest_of_plan */ 3756 }, 3757 { 3758 "plan_prefix": [ 3759 "`t1`" 3760 ] /* plan_prefix */, 3761 "table": "`t2`", 3762 "best_access_path": { 3763 "considered_access_paths": [ 3764 { 3765 "access_type": "ref", 3766 "index": "t2_ID_IDX", 3767 "rows": 1, 3768 "cost": 1.2, 3769 "chosen": true 3770 }, 3771 { 3772 "access_type": "scan", 3773 "cost": 3.8, 3774 "rows": 9, 3775 "chosen": false, 3776 "cause": "cost" 3777 } 3778 ] /* considered_access_paths */ 3779 } /* best_access_path */, 3780 "condition_filtering_pct": 100, 3781 "rows_for_plan": 1, 3782 "cost_for_plan": 1.2, 3783 "pruned_by_heuristic": true 3784 } 3785 ] /* considered_execution_plans */ 3786 } 3787 ] /* steps */, 3788 "empty_result": { 3789 "cause": "no matching row in const table" 3790 } /* empty_result */ 3791 } /* join_optimization */ 3792 }, 3793 { 3794 "table_dependencies": [ 3795 { 3796 "table": " `tmp`", 3797 "row_may_be_null": false, 3798 "map_bit": 0, 3799 "depends_on_map_bits": [ 3800 ] /* depends_on_map_bits */ 3801 } 3802 ] /* table_dependencies */ 3803 }, 3804 { 3805 "rows_estimation": [ 3806 { 3807 "table": " `tmp`", 3808 "table_scan": { 3809 "rows": 2, 3810 "cost": 10 3811 } /* table_scan */ 3812 } 3813 ] /* rows_estimation */ 3814 }, 3815 { 3816 "considered_execution_plans": [ 3817 { 3818 "plan_prefix": [ 3819 ] /* plan_prefix */, 3820 "table": " `tmp`", 3821 "best_access_path": { 3822 "considered_access_paths": [ 3823 { 3824 "rows_to_scan": 2, 3825 "access_type": "scan", 3826 "resulting_rows": 2, 3827 "cost": 10.5, 3828 "chosen": true 3829 } 3830 ] /* considered_access_paths */ 3831 } /* best_access_path */, 3832 "condition_filtering_pct": 100, 3833 "rows_for_plan": 2, 3834 "cost_for_plan": 10.5, 3835 "chosen": true 3836 } 3837 ] /* considered_execution_plans */ 3838 }, 3839 { 3840 "attaching_conditions_to_tables": { 3841 "original_condition": null, 3842 "attached_conditions_computation": [ 3843 ] /* attached_conditions_computation */, 3844 "attached_conditions_summary": [ 3845 { 3846 "table": " `tmp`", 3847 "attached": null 3848 } 3849 ] /* attached_conditions_summary */ 3850 } /* attaching_conditions_to_tables */ 3851 }, 3852 { 3853 "refine_plan": [ 3854 { 3855 "table": " `tmp`" 3856 } 3857 ] /* refine_plan */ 3858 } 3859 ] /* steps */ 3860 } /* join_optimization */ 3861 }, 3862 { 3863 "join_execution": { 3864 "select#": 1, 3865 "steps": [ 3866 { 3867 "creating_tmp_table": { 3868 "tmp_table_info": { 3869 "table": " `tmp`", 3870 "row_length": 10, 3871 "key_length": 0, 3872 "unique_constraint": false, 3873 "location": "memory (heap)", 3874 "row_limit_estimate": 104857 3875 } /* tmp_table_info */ 3876 } /* creating_tmp_table */ 3877 }, 3878 { 3879 "join_execution": { 3880 "select#": 2, 3881 "steps": [ 3882 ] /* steps */ 3883 } /* join_execution */ 3884 } 3885 ] /* steps */ 3886 } /* join_execution */ 3887 } 3888 ] /* steps */ 3889} 0 0 3890drop table t1,t2,t3; 3891CREATE TABLE t1 ( 3892t1_id bigint(21) NOT NULL auto_increment, 3893_field_72 varchar(128) DEFAULT '' NOT NULL, 3894_field_95 varchar(32), 3895_field_115 tinyint(4) DEFAULT '0' NOT NULL, 3896_field_122 tinyint(4) DEFAULT '0' NOT NULL, 3897_field_126 tinyint(4), 3898_field_134 tinyint(4), 3899PRIMARY KEY (t1_id), 3900UNIQUE _field_72 (_field_72), 3901KEY _field_115 (_field_115), 3902KEY _field_122 (_field_122) 3903); 3904INSERT INTO t1 VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',0,1,NULL,NULL); 3905INSERT INTO t1 VALUES (2,'hroberts','7415275a8c95952901e42b13a6b78566',0,1,NULL,NULL); 3906INSERT INTO t1 VALUES (3,'guest','d41d8cd98f00b204e9800998ecf8427e',1,0,NULL,NULL); 3907CREATE TABLE t2 ( 3908seq_0_id bigint(21) DEFAULT '0' NOT NULL, 3909seq_1_id bigint(21) DEFAULT '0' NOT NULL, 3910PRIMARY KEY (seq_0_id,seq_1_id) 3911); 3912INSERT INTO t2 VALUES (1,1); 3913INSERT INTO t2 VALUES (2,1); 3914INSERT INTO t2 VALUES (2,2); 3915SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; 3916Warnings: 3917Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release. 3918CREATE TABLE t3 ( 3919t3_id bigint(21) NOT NULL auto_increment, 3920_field_131 varchar(128), 3921_field_133 tinyint(4) DEFAULT '0' NOT NULL, 3922_field_135 datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, 3923_field_137 tinyint(4), 3924_field_139 datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, 3925_field_140 blob, 3926_field_142 tinyint(4) DEFAULT '0' NOT NULL, 3927_field_145 tinyint(4) DEFAULT '0' NOT NULL, 3928_field_148 tinyint(4) DEFAULT '0' NOT NULL, 3929PRIMARY KEY (t3_id), 3930KEY _field_133 (_field_133), 3931KEY _field_135 (_field_135), 3932KEY _field_139 (_field_139), 3933KEY _field_142 (_field_142), 3934KEY _field_145 (_field_145), 3935KEY _field_148 (_field_148) 3936); 3937INSERT INTO t3 VALUES (1,'test job 1',0,'0000-00-00 00:00:00',0,'1999-02-25 22:43:32','test\r\njob\r\n1',0,0,0); 3938INSERT INTO t3 VALUES (2,'test job 2',0,'0000-00-00 00:00:00',0,'1999-02-26 21:08:04','',0,0,0); 3939SET sql_mode = default; 3940CREATE TABLE t4 ( 3941seq_0_id bigint(21) DEFAULT '0' NOT NULL, 3942seq_1_id bigint(21) DEFAULT '0' NOT NULL, 3943PRIMARY KEY (seq_0_id,seq_1_id) 3944); 3945INSERT INTO t4 VALUES (1,1); 3946INSERT INTO t4 VALUES (2,1); 3947CREATE TABLE t5 ( 3948t5_id bigint(21) NOT NULL auto_increment, 3949_field_149 tinyint(4), 3950_field_156 varchar(128) DEFAULT '' NOT NULL, 3951_field_157 varchar(128) DEFAULT '' NOT NULL, 3952_field_158 varchar(128) DEFAULT '' NOT NULL, 3953_field_159 varchar(128) DEFAULT '' NOT NULL, 3954_field_160 varchar(128) DEFAULT '' NOT NULL, 3955_field_161 varchar(128) DEFAULT '' NOT NULL, 3956PRIMARY KEY (t5_id), 3957KEY _field_156 (_field_156), 3958KEY _field_157 (_field_157), 3959KEY _field_158 (_field_158), 3960KEY _field_159 (_field_159), 3961KEY _field_160 (_field_160), 3962KEY _field_161 (_field_161) 3963); 3964INSERT INTO t5 VALUES (1,0,'tomato','','','','',''); 3965INSERT INTO t5 VALUES (2,0,'cilantro','','','','',''); 3966CREATE TABLE t6 ( 3967seq_0_id bigint(21) DEFAULT '0' NOT NULL, 3968seq_1_id bigint(21) DEFAULT '0' NOT NULL, 3969PRIMARY KEY (seq_0_id,seq_1_id) 3970); 3971INSERT INTO t6 VALUES (1,1); 3972INSERT INTO t6 VALUES (1,2); 3973INSERT INTO t6 VALUES (2,2); 3974CREATE TABLE t7 ( 3975t7_id bigint(21) NOT NULL auto_increment, 3976_field_143 tinyint(4), 3977_field_165 varchar(32), 3978_field_166 smallint(6) DEFAULT '0' NOT NULL, 3979PRIMARY KEY (t7_id), 3980KEY _field_166 (_field_166) 3981); 3982INSERT INTO t7 VALUES (1,0,'High',1); 3983INSERT INTO t7 VALUES (2,0,'Medium',2); 3984INSERT INTO t7 VALUES (3,0,'Low',3); 3985select 3986replace(t3._field_140, "\r","^M"), 3987t3_id, 3988min(t3._field_131), 3989min(t3._field_135), 3990min(t3._field_139), 3991min(t3._field_137), 3992min(link_alias_142._field_165), 3993min(link_alias_133._field_72), 3994min(t3._field_145), 3995min(link_alias_148._field_156), 3996replace(min(t3._field_140), "\r","^M"), 3997t3.t3_id 3998from 3999t3 left join t4 on t4.seq_0_id = t3.t3_id 4000left join t7 link_alias_142 on t4.seq_1_id = link_alias_142.t7_id 4001left join t6 on t6.seq_0_id = t3.t3_id 4002left join t1 link_alias_133 on t6.seq_1_id = link_alias_133.t1_id 4003left join t2 on t2.seq_0_id = t3.t3_id 4004left join t5 link_alias_148 on t2.seq_1_id = link_alias_148.t5_id 4005where 4006t3.t3_id in (1) 4007group by 4008t3.t3_id 4009order by 4010link_alias_142._field_166, 4011_field_139, 4012link_alias_133._field_72, 4013_field_135, 4014link_alias_148._field_156 4015; 4016replace(t3._field_140, "\r","^M") t3_id min(t3._field_131) min(t3._field_135) min(t3._field_139) min(t3._field_137) min(link_alias_142._field_165) min(link_alias_133._field_72) min(t3._field_145) min(link_alias_148._field_156) replace(min(t3._field_140), "\r","^M") t3_id 4017test^M 4018job^M 40191 1 test job 1 0000-00-00 00:00:00 1999-02-25 22:43:32 0 High admin 0 tomato test^M 4020job^M 40211 1 4022select * from information_schema.optimizer_trace; 4023QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 4024select 4025replace(t3._field_140, "\r","^M"), 4026t3_id, 4027min(t3._field_131), 4028min(t3._field_135), 4029min(t3._field_139), 4030min(t3._field_137), 4031min(link_alias_142._field_165), 4032min(link_alias_133._field_72), 4033min(t3._field_145), 4034min(link_alias_148._field_156), 4035replace(min(t3._field_140), "\r","^M"), 4036t3.t3_id 4037from 4038t3 left join t4 on t4.seq_0_id = t3.t3_id 4039left join t7 link_alias_142 on t4.seq_1_id = link_alias_142.t7_id 4040left join t6 on t6.seq_0_id = t3.t3_id 4041left join t1 link_alias_133 on t6.seq_1_id = link_alias_133.t1_id 4042left join t2 on t2.seq_0_id = t3.t3_id 4043left join t5 link_alias_148 on t2.seq_1_id = link_alias_148.t5_id 4044where 4045t3.t3_id in (1) 4046group by 4047t3.t3_id 4048order by 4049link_alias_142._field_166, 4050_field_139, 4051link_alias_133._field_72, 4052_field_135, 4053link_alias_148._field_156 { 4054 "steps": [ 4055 { 4056 "join_preparation": { 4057 "select#": 1, 4058 "steps": [ 4059 { 4060 "expanded_query": "/* select#1 */ select replace(`t3`.`_field_140`,'\\r','^M') AS `replace(t3._field_140, \"\\r\",\"^M\")`,`t3`.`t3_id` AS `t3_id`,min(`t3`.`_field_131`) AS `min(t3._field_131)`,min(`t3`.`_field_135`) AS `min(t3._field_135)`,min(`t3`.`_field_139`) AS `min(t3._field_139)`,min(`t3`.`_field_137`) AS `min(t3._field_137)`,min(`link_alias_142`.`_field_165`) AS `min(link_alias_142._field_165)`,min(`link_alias_133`.`_field_72`) AS `min(link_alias_133._field_72)`,min(`t3`.`_field_145`) AS `min(t3._field_145)`,min(`link_alias_148`.`_field_156`) AS `min(link_alias_148._field_156)`,replace(min(`t3`.`_field_140`),'\\r','^M') AS `replace(min(t3._field_140), \"\\r\",\"^M\")`,`t3`.`t3_id` AS `t3_id` from ((((((`t3` left join `t4` on((`t4`.`seq_0_id` = `t3`.`t3_id`))) left join `t7` `link_alias_142` on((`t4`.`seq_1_id` = `link_alias_142`.`t7_id`))) left join `t6` on((`t6`.`seq_0_id` = `t3`.`t3_id`))) left join `t1` `link_alias_133` on((`t6`.`seq_1_id` = `link_alias_133`.`t1_id`))) left join `t2` on((`t2`.`seq_0_id` = `t3`.`t3_id`))) left join `t5` `link_alias_148` on((`t2`.`seq_1_id` = `link_alias_148`.`t5_id`))) where (`t3`.`t3_id` = 1) group by `t3`.`t3_id` order by `link_alias_142`.`_field_166`,`t3`.`_field_139`,`link_alias_133`.`_field_72`,`t3`.`_field_135`,`link_alias_148`.`_field_156`" 4061 }, 4062 { 4063 "transformations_to_nested_joins": { 4064 "transformations": [ 4065 "parenthesis_removal" 4066 ] /* transformations */, 4067 "expanded_query": "/* select#1 */ select replace(`t3`.`_field_140`,'\\r','^M') AS `replace(t3._field_140, \"\\r\",\"^M\")`,`t3`.`t3_id` AS `t3_id`,min(`t3`.`_field_131`) AS `min(t3._field_131)`,min(`t3`.`_field_135`) AS `min(t3._field_135)`,min(`t3`.`_field_139`) AS `min(t3._field_139)`,min(`t3`.`_field_137`) AS `min(t3._field_137)`,min(`link_alias_142`.`_field_165`) AS `min(link_alias_142._field_165)`,min(`link_alias_133`.`_field_72`) AS `min(link_alias_133._field_72)`,min(`t3`.`_field_145`) AS `min(t3._field_145)`,min(`link_alias_148`.`_field_156`) AS `min(link_alias_148._field_156)`,replace(min(`t3`.`_field_140`),'\\r','^M') AS `replace(min(t3._field_140), \"\\r\",\"^M\")`,`t3`.`t3_id` AS `t3_id` from `t3` left join `t4` on((`t4`.`seq_0_id` = `t3`.`t3_id`)) left join `t7` `link_alias_142` on((`t4`.`seq_1_id` = `link_alias_142`.`t7_id`)) left join `t6` on((`t6`.`seq_0_id` = `t3`.`t3_id`)) left join `t1` `link_alias_133` on((`t6`.`seq_1_id` = `link_alias_133`.`t1_id`)) left join `t2` on((`t2`.`seq_0_id` = `t3`.`t3_id`)) left join `t5` `link_alias_148` on((`t2`.`seq_1_id` = `link_alias_148`.`t5_id`)) where (`t3`.`t3_id` = 1) group by `t3`.`t3_id` order by `link_alias_142`.`_field_166`,`t3`.`_field_139`,`link_alias_133`.`_field_72`,`t3`.`_field_135`,`link_alias_148`.`_field_156`" 4068 } /* transformations_to_nested_joins */ 4069 } 4070 ] /* steps */ 4071 } /* join_preparation */ 4072 }, 4073 { 4074 "join_optimization": { 4075 "select#": 1, 4076 "steps": [ 4077 { 4078 "condition_processing": { 4079 "condition": "WHERE", 4080 "original_condition": "(`t3`.`t3_id` = 1)", 4081 "steps": [ 4082 { 4083 "transformation": "equality_propagation", 4084 "resulting_condition": "multiple equal(1, `t3`.`t3_id`)" 4085 }, 4086 { 4087 "transformation": "constant_propagation", 4088 "resulting_condition": "multiple equal(1, `t3`.`t3_id`)" 4089 }, 4090 { 4091 "transformation": "trivial_condition_removal", 4092 "resulting_condition": "multiple equal(1, `t3`.`t3_id`)" 4093 } 4094 ] /* steps */ 4095 } /* condition_processing */ 4096 }, 4097 { 4098 "substitute_generated_columns": { 4099 } /* substitute_generated_columns */ 4100 }, 4101 { 4102 "table_dependencies": [ 4103 { 4104 "table": "`t3`", 4105 "row_may_be_null": false, 4106 "map_bit": 0, 4107 "depends_on_map_bits": [ 4108 ] /* depends_on_map_bits */ 4109 }, 4110 { 4111 "table": "`t4`", 4112 "row_may_be_null": true, 4113 "map_bit": 1, 4114 "depends_on_map_bits": [ 4115 0 4116 ] /* depends_on_map_bits */ 4117 }, 4118 { 4119 "table": "`t7` `link_alias_142`", 4120 "row_may_be_null": true, 4121 "map_bit": 2, 4122 "depends_on_map_bits": [ 4123 0, 4124 1 4125 ] /* depends_on_map_bits */ 4126 }, 4127 { 4128 "table": "`t6`", 4129 "row_may_be_null": true, 4130 "map_bit": 3, 4131 "depends_on_map_bits": [ 4132 0, 4133 1, 4134 2 4135 ] /* depends_on_map_bits */ 4136 }, 4137 { 4138 "table": "`t1` `link_alias_133`", 4139 "row_may_be_null": true, 4140 "map_bit": 4, 4141 "depends_on_map_bits": [ 4142 0, 4143 1, 4144 2, 4145 3 4146 ] /* depends_on_map_bits */ 4147 }, 4148 { 4149 "table": "`t2`", 4150 "row_may_be_null": true, 4151 "map_bit": 5, 4152 "depends_on_map_bits": [ 4153 0, 4154 1, 4155 2, 4156 3, 4157 4 4158 ] /* depends_on_map_bits */ 4159 }, 4160 { 4161 "table": "`t5` `link_alias_148`", 4162 "row_may_be_null": true, 4163 "map_bit": 6, 4164 "depends_on_map_bits": [ 4165 0, 4166 1, 4167 2, 4168 3, 4169 4, 4170 5 4171 ] /* depends_on_map_bits */ 4172 } 4173 ] /* table_dependencies */ 4174 }, 4175 { 4176 "ref_optimizer_key_uses": [ 4177 { 4178 "table": "`t3`", 4179 "field": "t3_id", 4180 "equals": "1", 4181 "null_rejecting": false 4182 }, 4183 { 4184 "table": "`t4`", 4185 "field": "seq_0_id", 4186 "equals": "1", 4187 "null_rejecting": false 4188 }, 4189 { 4190 "table": "`t7` `link_alias_142`", 4191 "field": "t7_id", 4192 "equals": "`t4`.`seq_1_id`", 4193 "null_rejecting": true 4194 }, 4195 { 4196 "table": "`t6`", 4197 "field": "seq_0_id", 4198 "equals": "1", 4199 "null_rejecting": false 4200 }, 4201 { 4202 "table": "`t1` `link_alias_133`", 4203 "field": "t1_id", 4204 "equals": "`t6`.`seq_1_id`", 4205 "null_rejecting": true 4206 }, 4207 { 4208 "table": "`t2`", 4209 "field": "seq_0_id", 4210 "equals": "1", 4211 "null_rejecting": false 4212 }, 4213 { 4214 "table": "`t5` `link_alias_148`", 4215 "field": "t5_id", 4216 "equals": "`t2`.`seq_1_id`", 4217 "null_rejecting": true 4218 } 4219 ] /* ref_optimizer_key_uses */ 4220 }, 4221 { 4222 "rows_estimation": [ 4223 { 4224 "table": "`t3`", 4225 "rows": 1, 4226 "cost": 1, 4227 "table_type": "const", 4228 "empty": false 4229 }, 4230 { 4231 "table": "`t4`", 4232 "range_analysis": { 4233 "table_scan": { 4234 "rows": 2, 4235 "cost": 4.5083 4236 } /* table_scan */, 4237 "potential_range_indexes": [ 4238 { 4239 "index": "PRIMARY", 4240 "usable": true, 4241 "key_parts": [ 4242 "seq_0_id", 4243 "seq_1_id" 4244 ] /* key_parts */ 4245 } 4246 ] /* potential_range_indexes */, 4247 "best_covering_index_scan": { 4248 "index": "PRIMARY", 4249 "cost": 1.4435, 4250 "chosen": true 4251 } /* best_covering_index_scan */, 4252 "setup_range_conditions": [ 4253 ] /* setup_range_conditions */, 4254 "group_index_range": { 4255 "chosen": false, 4256 "cause": "not_single_table" 4257 } /* group_index_range */, 4258 "analyzing_range_alternatives": { 4259 "range_scan_alternatives": [ 4260 { 4261 "index": "PRIMARY", 4262 "ranges": [ 4263 "1 <= seq_0_id <= 1" 4264 ] /* ranges */, 4265 "index_dives_for_eq_ranges": true, 4266 "rowid_ordered": false, 4267 "using_mrr": false, 4268 "index_only": true, 4269 "rows": 1, 4270 "cost": 1.21, 4271 "chosen": true 4272 } 4273 ] /* range_scan_alternatives */, 4274 "analyzing_roworder_intersect": { 4275 "usable": false, 4276 "cause": "too_few_roworder_scans" 4277 } /* analyzing_roworder_intersect */ 4278 } /* analyzing_range_alternatives */, 4279 "chosen_range_access_summary": { 4280 "range_access_plan": { 4281 "type": "range_scan", 4282 "index": "PRIMARY", 4283 "rows": 1, 4284 "ranges": [ 4285 "1 <= seq_0_id <= 1" 4286 ] /* ranges */ 4287 } /* range_access_plan */, 4288 "rows_for_plan": 1, 4289 "cost_for_plan": 1.21, 4290 "chosen": true 4291 } /* chosen_range_access_summary */ 4292 } /* range_analysis */ 4293 }, 4294 { 4295 "table": "`t7` `link_alias_142`", 4296 "table_scan": { 4297 "rows": 3, 4298 "cost": 2 4299 } /* table_scan */ 4300 }, 4301 { 4302 "table": "`t6`", 4303 "range_analysis": { 4304 "table_scan": { 4305 "rows": 3, 4306 "cost": 4.7125 4307 } /* table_scan */, 4308 "potential_range_indexes": [ 4309 { 4310 "index": "PRIMARY", 4311 "usable": true, 4312 "key_parts": [ 4313 "seq_0_id", 4314 "seq_1_id" 4315 ] /* key_parts */ 4316 } 4317 ] /* potential_range_indexes */, 4318 "best_covering_index_scan": { 4319 "index": "PRIMARY", 4320 "cost": 1.687, 4321 "chosen": true 4322 } /* best_covering_index_scan */, 4323 "setup_range_conditions": [ 4324 ] /* setup_range_conditions */, 4325 "group_index_range": { 4326 "chosen": false, 4327 "cause": "not_single_table" 4328 } /* group_index_range */, 4329 "analyzing_range_alternatives": { 4330 "range_scan_alternatives": [ 4331 { 4332 "index": "PRIMARY", 4333 "ranges": [ 4334 "1 <= seq_0_id <= 1" 4335 ] /* ranges */, 4336 "index_dives_for_eq_ranges": true, 4337 "rowid_ordered": false, 4338 "using_mrr": false, 4339 "index_only": true, 4340 "rows": 1, 4341 "cost": 1.21, 4342 "chosen": true 4343 } 4344 ] /* range_scan_alternatives */, 4345 "analyzing_roworder_intersect": { 4346 "usable": false, 4347 "cause": "too_few_roworder_scans" 4348 } /* analyzing_roworder_intersect */ 4349 } /* analyzing_range_alternatives */, 4350 "chosen_range_access_summary": { 4351 "range_access_plan": { 4352 "type": "range_scan", 4353 "index": "PRIMARY", 4354 "rows": 1, 4355 "ranges": [ 4356 "1 <= seq_0_id <= 1" 4357 ] /* ranges */ 4358 } /* range_access_plan */, 4359 "rows_for_plan": 1, 4360 "cost_for_plan": 1.21, 4361 "chosen": true 4362 } /* chosen_range_access_summary */ 4363 } /* range_analysis */ 4364 }, 4365 { 4366 "table": "`t1` `link_alias_133`", 4367 "table_scan": { 4368 "rows": 3, 4369 "cost": 2 4370 } /* table_scan */ 4371 }, 4372 { 4373 "table": "`t2`", 4374 "range_analysis": { 4375 "table_scan": { 4376 "rows": 3, 4377 "cost": 4.7125 4378 } /* table_scan */, 4379 "potential_range_indexes": [ 4380 { 4381 "index": "PRIMARY", 4382 "usable": true, 4383 "key_parts": [ 4384 "seq_0_id", 4385 "seq_1_id" 4386 ] /* key_parts */ 4387 } 4388 ] /* potential_range_indexes */, 4389 "best_covering_index_scan": { 4390 "index": "PRIMARY", 4391 "cost": 1.687, 4392 "chosen": true 4393 } /* best_covering_index_scan */, 4394 "setup_range_conditions": [ 4395 ] /* setup_range_conditions */, 4396 "group_index_range": { 4397 "chosen": false, 4398 "cause": "not_single_table" 4399 } /* group_index_range */, 4400 "analyzing_range_alternatives": { 4401 "range_scan_alternatives": [ 4402 { 4403 "index": "PRIMARY", 4404 "ranges": [ 4405 "1 <= seq_0_id <= 1" 4406 ] /* ranges */, 4407 "index_dives_for_eq_ranges": true, 4408 "rowid_ordered": false, 4409 "using_mrr": false, 4410 "index_only": true, 4411 "rows": 1, 4412 "cost": 1.21, 4413 "chosen": true 4414 } 4415 ] /* range_scan_alternatives */, 4416 "analyzing_roworder_intersect": { 4417 "usable": false, 4418 "cause": "too_few_roworder_scans" 4419 } /* analyzing_roworder_intersect */ 4420 } /* analyzing_range_alternatives */, 4421 "chosen_range_access_summary": { 4422 "range_access_plan": { 4423 "type": "range_scan", 4424 "index": "PRIMARY", 4425 "rows": 1, 4426 "ranges": [ 4427 "1 <= seq_0_id <= 1" 4428 ] /* ranges */ 4429 } /* range_access_plan */, 4430 "rows_for_plan": 1, 4431 "cost_for_plan": 1.21, 4432 "chosen": true 4433 } /* chosen_range_access_summary */ 4434 } /* range_analysis */ 4435 }, 4436 { 4437 "table": "`t5` `link_alias_148`", 4438 "table_scan": { 4439 "rows": 2, 4440 "cost": 2 4441 } /* table_scan */ 4442 } 4443 ] /* rows_estimation */ 4444 }, 4445 { 4446 "considered_execution_plans": [ 4447 { 4448 "plan_prefix": [ 4449 "`t3`" 4450 ] /* plan_prefix */, 4451 "table": "`t4`", 4452 "best_access_path": { 4453 "considered_access_paths": [ 4454 { 4455 "access_type": "ref", 4456 "index": "PRIMARY", 4457 "rows": 1, 4458 "cost": 1.2, 4459 "chosen": true 4460 }, 4461 { 4462 "access_type": "range", 4463 "range_details": { 4464 "used_index": "PRIMARY" 4465 } /* range_details */, 4466 "chosen": false, 4467 "cause": "heuristic_index_cheaper" 4468 } 4469 ] /* considered_access_paths */ 4470 } /* best_access_path */, 4471 "condition_filtering_pct": 100, 4472 "rows_for_plan": 1, 4473 "cost_for_plan": 1.2, 4474 "rest_of_plan": [ 4475 { 4476 "plan_prefix": [ 4477 "`t3`", 4478 "`t4`" 4479 ] /* plan_prefix */, 4480 "table": "`t7` `link_alias_142`", 4481 "best_access_path": { 4482 "considered_access_paths": [ 4483 { 4484 "access_type": "eq_ref", 4485 "index": "PRIMARY", 4486 "rows": 1, 4487 "cost": 1.2, 4488 "chosen": true 4489 }, 4490 { 4491 "access_type": "scan", 4492 "cost": 2.6, 4493 "rows": 3, 4494 "chosen": false, 4495 "cause": "cost" 4496 } 4497 ] /* considered_access_paths */ 4498 } /* best_access_path */, 4499 "added_to_eq_ref_extension": true, 4500 "condition_filtering_pct": 100, 4501 "rows_for_plan": 1, 4502 "cost_for_plan": 2.4, 4503 "rest_of_plan": [ 4504 { 4505 "plan_prefix": [ 4506 "`t3`", 4507 "`t4`", 4508 "`t7` `link_alias_142`" 4509 ] /* plan_prefix */, 4510 "table": "`t6`", 4511 "best_access_path": { 4512 "considered_access_paths": [ 4513 { 4514 "access_type": "ref", 4515 "index": "PRIMARY", 4516 "rows": 1, 4517 "cost": 1.2, 4518 "chosen": true 4519 }, 4520 { 4521 "access_type": "range", 4522 "range_details": { 4523 "used_index": "PRIMARY" 4524 } /* range_details */, 4525 "chosen": false, 4526 "cause": "heuristic_index_cheaper" 4527 } 4528 ] /* considered_access_paths */ 4529 } /* best_access_path */, 4530 "added_to_eq_ref_extension": true, 4531 "condition_filtering_pct": 100, 4532 "rows_for_plan": 1, 4533 "cost_for_plan": 3.6, 4534 "rest_of_plan": [ 4535 { 4536 "plan_prefix": [ 4537 "`t3`", 4538 "`t4`", 4539 "`t7` `link_alias_142`", 4540 "`t6`" 4541 ] /* plan_prefix */, 4542 "table": "`t1` `link_alias_133`", 4543 "best_access_path": { 4544 "considered_access_paths": [ 4545 { 4546 "access_type": "eq_ref", 4547 "index": "PRIMARY", 4548 "rows": 1, 4549 "cost": 1.2, 4550 "chosen": true 4551 }, 4552 { 4553 "access_type": "scan", 4554 "cost": 2.6, 4555 "rows": 3, 4556 "chosen": false, 4557 "cause": "cost" 4558 } 4559 ] /* considered_access_paths */ 4560 } /* best_access_path */, 4561 "added_to_eq_ref_extension": true, 4562 "condition_filtering_pct": 100, 4563 "rows_for_plan": 1, 4564 "cost_for_plan": 4.8, 4565 "rest_of_plan": [ 4566 { 4567 "plan_prefix": [ 4568 "`t3`", 4569 "`t4`", 4570 "`t7` `link_alias_142`", 4571 "`t6`", 4572 "`t1` `link_alias_133`" 4573 ] /* plan_prefix */, 4574 "table": "`t2`", 4575 "best_access_path": { 4576 "considered_access_paths": [ 4577 { 4578 "access_type": "ref", 4579 "index": "PRIMARY", 4580 "rows": 1, 4581 "cost": 1.2, 4582 "chosen": true 4583 }, 4584 { 4585 "access_type": "range", 4586 "range_details": { 4587 "used_index": "PRIMARY" 4588 } /* range_details */, 4589 "chosen": false, 4590 "cause": "heuristic_index_cheaper" 4591 } 4592 ] /* considered_access_paths */ 4593 } /* best_access_path */, 4594 "added_to_eq_ref_extension": true, 4595 "condition_filtering_pct": 100, 4596 "rows_for_plan": 1, 4597 "cost_for_plan": 6, 4598 "rest_of_plan": [ 4599 { 4600 "plan_prefix": [ 4601 "`t3`", 4602 "`t4`", 4603 "`t7` `link_alias_142`", 4604 "`t6`", 4605 "`t1` `link_alias_133`", 4606 "`t2`" 4607 ] /* plan_prefix */, 4608 "table": "`t5` `link_alias_148`", 4609 "best_access_path": { 4610 "considered_access_paths": [ 4611 { 4612 "access_type": "eq_ref", 4613 "index": "PRIMARY", 4614 "rows": 1, 4615 "cost": 1.2, 4616 "chosen": true 4617 }, 4618 { 4619 "access_type": "scan", 4620 "cost": 2.4, 4621 "rows": 2, 4622 "chosen": false, 4623 "cause": "cost" 4624 } 4625 ] /* considered_access_paths */ 4626 } /* best_access_path */, 4627 "added_to_eq_ref_extension": true, 4628 "condition_filtering_pct": 100, 4629 "rows_for_plan": 1, 4630 "cost_for_plan": 7.2, 4631 "chosen": true 4632 } 4633 ] /* rest_of_plan */ 4634 } 4635 ] /* rest_of_plan */ 4636 } 4637 ] /* rest_of_plan */ 4638 } 4639 ] /* rest_of_plan */ 4640 } 4641 ] /* rest_of_plan */ 4642 } 4643 ] /* considered_execution_plans */ 4644 }, 4645 { 4646 "condition_on_constant_tables": "1", 4647 "condition_value": true 4648 }, 4649 { 4650 "attaching_conditions_to_tables": { 4651 "original_condition": "1", 4652 "attached_conditions_computation": [ 4653 ] /* attached_conditions_computation */, 4654 "attached_conditions_summary": [ 4655 { 4656 "table": "`t4`", 4657 "attached": null 4658 }, 4659 { 4660 "table": "`t7` `link_alias_142`", 4661 "attached": null 4662 }, 4663 { 4664 "table": "`t6`", 4665 "attached": null 4666 }, 4667 { 4668 "table": "`t1` `link_alias_133`", 4669 "attached": null 4670 }, 4671 { 4672 "table": "`t2`", 4673 "attached": null 4674 }, 4675 { 4676 "table": "`t5` `link_alias_148`", 4677 "attached": null 4678 } 4679 ] /* attached_conditions_summary */ 4680 } /* attaching_conditions_to_tables */ 4681 }, 4682 { 4683 "clause_processing": { 4684 "clause": "ORDER BY", 4685 "original_clause": "`link_alias_142`.`_field_166`,'1999-02-25 22:43:32',`link_alias_133`.`_field_72`,'0000-00-00 00:00:00',`link_alias_148`.`_field_156`", 4686 "items": [ 4687 { 4688 "item": "`link_alias_142`.`_field_166`" 4689 }, 4690 { 4691 "item": "'1999-02-25 22:43:32'", 4692 "uses_only_constant_tables": true 4693 }, 4694 { 4695 "item": "`link_alias_133`.`_field_72`" 4696 }, 4697 { 4698 "item": "'0000-00-00 00:00:00'", 4699 "uses_only_constant_tables": true 4700 }, 4701 { 4702 "item": "`link_alias_148`.`_field_156`" 4703 } 4704 ] /* items */, 4705 "resulting_clause_is_simple": false, 4706 "resulting_clause": "`link_alias_142`.`_field_166`,`link_alias_133`.`_field_72`,`link_alias_148`.`_field_156`" 4707 } /* clause_processing */ 4708 }, 4709 { 4710 "clause_processing": { 4711 "clause": "GROUP BY", 4712 "original_clause": "'1'", 4713 "items": [ 4714 { 4715 "item": "'1'", 4716 "uses_only_constant_tables": true 4717 } 4718 ] /* items */, 4719 "resulting_clause_is_simple": true, 4720 "resulting_clause": "" 4721 } /* clause_processing */ 4722 }, 4723 { 4724 "refine_plan": [ 4725 { 4726 "table": "`t4`" 4727 }, 4728 { 4729 "table": "`t7` `link_alias_142`" 4730 }, 4731 { 4732 "table": "`t6`" 4733 }, 4734 { 4735 "table": "`t1` `link_alias_133`" 4736 }, 4737 { 4738 "table": "`t2`" 4739 }, 4740 { 4741 "table": "`t5` `link_alias_148`" 4742 } 4743 ] /* refine_plan */ 4744 } 4745 ] /* steps */ 4746 } /* join_optimization */ 4747 }, 4748 { 4749 "join_execution": { 4750 "select#": 1, 4751 "steps": [ 4752 ] /* steps */ 4753 } /* join_execution */ 4754 } 4755 ] /* steps */ 4756} 0 0 4757drop table t1,t2,t3,t4,t5,t6,t7; 4758# 4759# Tracing of ORDER BY & GROUP BY simplification. 4760# 4761CREATE TABLE t1 ( 4762pk INT, col_int_key INT, 4763col_varchar_key VARCHAR(1), col_varchar_nokey VARCHAR(1) 4764); 4765INSERT INTO t1 VALUES 4766(10,7,'v','v'),(11,0,'s','s'),(12,9,'l','l'),(13,3,'y','y'),(14,4,'c','c'), 4767(15,2,'i','i'),(16,5,'h','h'),(17,3,'q','q'),(18,1,'a','a'),(19,3,'v','v'), 4768(20,6,'u','u'),(21,7,'s','s'),(22,5,'y','y'),(23,1,'z','z'),(24,204,'h','h'), 4769(25,224,'p','p'),(26,9,'e','e'),(27,5,'i','i'),(28,0,'y','y'),(29,3,'w','w'); 4770CREATE TABLE t2 ( 4771pk INT, col_int_key INT, 4772col_varchar_key VARCHAR(1), col_varchar_nokey VARCHAR(1), 4773PRIMARY KEY (pk) 4774); 4775INSERT INTO t2 VALUES 4776(1,4,'b','b'),(2,8,'y','y'),(3,0,'p','p'),(4,0,'f','f'),(5,0,'p','p'), 4777(6,7,'d','d'),(7,7,'f','f'),(8,5,'j','j'),(9,3,'e','e'),(10,188,'u','u'), 4778(11,4,'v','v'),(12,9,'u','u'),(13,6,'i','i'),(14,1,'x','x'),(15,5,'l','l'), 4779(16,6,'q','q'),(17,2,'n','n'),(18,4,'r','r'),(19,231,'c','c'),(20,4,'h','h'), 4780(21,3,'k','k'),(22,3,'t','t'),(23,7,'t','t'),(24,6,'k','k'),(25,7,'g','g'), 4781(26,9,'z','z'),(27,4,'n','n'),(28,4,'j','j'),(29,2,'l','l'),(30,1,'d','d'), 4782(31,2,'t','t'),(32,194,'y','y'),(33,2,'i','i'),(34,3,'j','j'),(35,8,'r','r'), 4783(36,4,'b','b'),(37,9,'o','o'),(38,4,'k','k'),(39,5,'a','a'),(40,5,'f','f'), 4784(41,9,'t','t'),(42,3,'c','c'),(43,8,'c','c'),(44,0,'r','r'),(45,98,'k','k'), 4785(46,3,'l','l'),(47,1,'o','o'),(48,0,'t','t'),(49,189,'v','v'),(50,8,'x','x'), 4786(51,3,'j','j'),(52,3,'x','x'),(53,9,'k','k'),(54,6,'o','o'),(55,8,'z','z'), 4787(56,3,'n','n'),(57,9,'c','c'),(58,5,'d','d'),(59,9,'s','s'),(60,2,'j','j'), 4788(61,2,'w','w'),(62,5,'f','f'),(63,8,'p','p'),(64,6,'o','o'),(65,9,'f','f'), 4789(66,0,'x','x'),(67,3,'q','q'),(68,6,'g','g'),(69,5,'x','x'),(70,8,'p','p'), 4790(71,2,'q','q'),(72,120,'q','q'),(73,25,'v','v'),(74,1,'g','g'),(75,3,'l','l'), 4791(76,1,'w','w'),(77,3,'h','h'),(78,153,'c','c'),(79,5,'o','o'),(80,9,'o','o'), 4792(81,1,'v','v'),(82,8,'y','y'),(83,7,'d','d'),(84,6,'p','p'),(85,2,'z','z'), 4793(86,4,'t','t'),(87,7,'b','b'),(88,3,'y','y'),(89,8,'k','k'),(90,4,'c','c'), 4794(91,6,'z','z'),(92,1,'t','t'),(93,7,'o','o'),(94,1,'u','u'),(95,0,'t','t'), 4795(96,2,'k','k'),(97,7,'u','u'),(98,2,'b','b'),(99,1,'m','m'),(100,5,'o','o'); 4796SELECT SUM(alias2.col_varchar_nokey) , alias2.pk AS field2 FROM t1 AS alias1 4797STRAIGHT_JOIN t2 AS alias2 ON alias2.pk = alias1.col_int_key WHERE alias1.pk 4798GROUP BY field2 ORDER BY alias1.col_int_key,alias2.pk ; 4799SUM(alias2.col_varchar_nokey) field2 48000 1 48010 2 48020 3 48030 4 48040 5 48050 6 48060 7 48070 9 4808Warnings: 4809Warning 1292 Truncated incorrect DOUBLE value: 'f' 4810Warning 1292 Truncated incorrect DOUBLE value: 'e' 4811Warning 1292 Truncated incorrect DOUBLE value: 'p' 4812Warning 1292 Truncated incorrect DOUBLE value: 'f' 4813Warning 1292 Truncated incorrect DOUBLE value: 'y' 4814Warning 1292 Truncated incorrect DOUBLE value: 'p' 4815Warning 1292 Truncated incorrect DOUBLE value: 'p' 4816Warning 1292 Truncated incorrect DOUBLE value: 'b' 4817Warning 1292 Truncated incorrect DOUBLE value: 'p' 4818Warning 1292 Truncated incorrect DOUBLE value: 'd' 4819Warning 1292 Truncated incorrect DOUBLE value: 'f' 4820Warning 1292 Truncated incorrect DOUBLE value: 'p' 4821Warning 1292 Truncated incorrect DOUBLE value: 'b' 4822Warning 1292 Truncated incorrect DOUBLE value: 'e' 4823Warning 1292 Truncated incorrect DOUBLE value: 'p' 4824Warning 1292 Truncated incorrect DOUBLE value: 'p' 4825SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; 4826QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 4827SELECT SUM(alias2.col_varchar_nokey) , alias2.pk AS field2 FROM t1 AS alias1 4828STRAIGHT_JOIN t2 AS alias2 ON alias2.pk = alias1.col_int_key WHERE alias1.pk 4829GROUP BY field2 ORDER BY alias1.col_int_key,alias2.pk { 4830 "steps": [ 4831 { 4832 "join_preparation": { 4833 "select#": 1, 4834 "steps": [ 4835 { 4836 "expanded_query": "/* select#1 */ select sum(`alias2`.`col_varchar_nokey`) AS `SUM(alias2.col_varchar_nokey)`,`alias2`.`pk` AS `field2` from (`t1` `alias1` straight_join `t2` `alias2` on((`alias2`.`pk` = `alias1`.`col_int_key`))) where `alias1`.`pk` group by `field2` order by `alias1`.`col_int_key`,`alias2`.`pk`" 4837 }, 4838 { 4839 "transformations_to_nested_joins": { 4840 "transformations": [ 4841 "JOIN_condition_to_WHERE", 4842 "parenthesis_removal" 4843 ] /* transformations */, 4844 "expanded_query": "/* select#1 */ select sum(`alias2`.`col_varchar_nokey`) AS `SUM(alias2.col_varchar_nokey)`,`alias2`.`pk` AS `field2` from `t1` `alias1` straight_join `t2` `alias2` where (`alias1`.`pk` and (`alias2`.`pk` = `alias1`.`col_int_key`)) group by `field2` order by `alias1`.`col_int_key`,`alias2`.`pk`" 4845 } /* transformations_to_nested_joins */ 4846 }, 4847 { 4848 "functional_dependencies_of_GROUP_columns": { 4849 "all_columns_of_table_map_bits": [ 4850 1 4851 ] /* all_columns_of_table_map_bits */, 4852 "columns": [ 4853 "test.alias2.pk", 4854 "test.alias1.col_int_key" 4855 ] /* columns */ 4856 } /* functional_dependencies_of_GROUP_columns */ 4857 } 4858 ] /* steps */ 4859 } /* join_preparation */ 4860 }, 4861 { 4862 "join_optimization": { 4863 "select#": 1, 4864 "steps": [ 4865 { 4866 "condition_processing": { 4867 "condition": "WHERE", 4868 "original_condition": "(`alias1`.`pk` and (`alias2`.`pk` = `alias1`.`col_int_key`))", 4869 "steps": [ 4870 { 4871 "transformation": "equality_propagation", 4872 "resulting_condition": "(`alias1`.`pk` and multiple equal(`alias2`.`pk`, `alias1`.`col_int_key`))" 4873 }, 4874 { 4875 "transformation": "constant_propagation", 4876 "resulting_condition": "(`alias1`.`pk` and multiple equal(`alias2`.`pk`, `alias1`.`col_int_key`))" 4877 }, 4878 { 4879 "transformation": "trivial_condition_removal", 4880 "resulting_condition": "(`alias1`.`pk` and multiple equal(`alias2`.`pk`, `alias1`.`col_int_key`))" 4881 } 4882 ] /* steps */ 4883 } /* condition_processing */ 4884 }, 4885 { 4886 "substitute_generated_columns": { 4887 } /* substitute_generated_columns */ 4888 }, 4889 { 4890 "table_dependencies": [ 4891 { 4892 "table": "`t1` `alias1`", 4893 "row_may_be_null": false, 4894 "map_bit": 0, 4895 "depends_on_map_bits": [ 4896 ] /* depends_on_map_bits */ 4897 }, 4898 { 4899 "table": "`t2` `alias2`", 4900 "row_may_be_null": false, 4901 "map_bit": 1, 4902 "depends_on_map_bits": [ 4903 0 4904 ] /* depends_on_map_bits */ 4905 } 4906 ] /* table_dependencies */ 4907 }, 4908 { 4909 "ref_optimizer_key_uses": [ 4910 { 4911 "table": "`t2` `alias2`", 4912 "field": "pk", 4913 "equals": "`alias1`.`col_int_key`", 4914 "null_rejecting": true 4915 } 4916 ] /* ref_optimizer_key_uses */ 4917 }, 4918 { 4919 "rows_estimation": [ 4920 { 4921 "table": "`t1` `alias1`", 4922 "table_scan": { 4923 "rows": 20, 4924 "cost": 2 4925 } /* table_scan */ 4926 }, 4927 { 4928 "table": "`t2` `alias2`", 4929 "const_keys_added": { 4930 "keys": [ 4931 "PRIMARY" 4932 ] /* keys */, 4933 "cause": "group_by" 4934 } /* const_keys_added */, 4935 "range_analysis": { 4936 "table_scan": { 4937 "rows": 100, 4938 "cost": 24.588 4939 } /* table_scan */, 4940 "potential_range_indexes": [ 4941 { 4942 "index": "PRIMARY", 4943 "usable": true, 4944 "key_parts": [ 4945 "pk" 4946 ] /* key_parts */ 4947 } 4948 ] /* potential_range_indexes */, 4949 "setup_range_conditions": [ 4950 ] /* setup_range_conditions */, 4951 "group_index_range": { 4952 "chosen": false, 4953 "cause": "not_single_table" 4954 } /* group_index_range */ 4955 } /* range_analysis */ 4956 } 4957 ] /* rows_estimation */ 4958 }, 4959 { 4960 "considered_execution_plans": [ 4961 { 4962 "plan_prefix": [ 4963 ] /* plan_prefix */, 4964 "table": "`t1` `alias1`", 4965 "best_access_path": { 4966 "considered_access_paths": [ 4967 { 4968 "rows_to_scan": 20, 4969 "access_type": "scan", 4970 "resulting_rows": 18, 4971 "cost": 6.0977, 4972 "chosen": true 4973 } 4974 ] /* considered_access_paths */ 4975 } /* best_access_path */, 4976 "condition_filtering_pct": 100, 4977 "rows_for_plan": 18, 4978 "cost_for_plan": 6.0977, 4979 "rest_of_plan": [ 4980 { 4981 "plan_prefix": [ 4982 "`t1` `alias1`" 4983 ] /* plan_prefix */, 4984 "table": "`t2` `alias2`", 4985 "best_access_path": { 4986 "considered_access_paths": [ 4987 { 4988 "access_type": "eq_ref", 4989 "index": "PRIMARY", 4990 "rows": 1, 4991 "cost": 21.6, 4992 "chosen": true 4993 }, 4994 { 4995 "rows_to_scan": 100, 4996 "access_type": "scan", 4997 "using_join_cache": true, 4998 "buffers_needed": 1, 4999 "resulting_rows": 100, 5000 "cost": 362.49, 5001 "chosen": false 5002 } 5003 ] /* considered_access_paths */ 5004 } /* best_access_path */, 5005 "condition_filtering_pct": 100, 5006 "rows_for_plan": 18, 5007 "cost_for_plan": 27.698, 5008 "chosen": true 5009 } 5010 ] /* rest_of_plan */ 5011 } 5012 ] /* considered_execution_plans */ 5013 }, 5014 { 5015 "attaching_conditions_to_tables": { 5016 "original_condition": "((`alias2`.`pk` = `alias1`.`col_int_key`) and `alias1`.`pk`)", 5017 "attached_conditions_computation": [ 5018 ] /* attached_conditions_computation */, 5019 "attached_conditions_summary": [ 5020 { 5021 "table": "`t1` `alias1`", 5022 "attached": "(`alias1`.`pk` and (`alias1`.`col_int_key` is not null))" 5023 }, 5024 { 5025 "table": "`t2` `alias2`", 5026 "attached": null 5027 } 5028 ] /* attached_conditions_summary */ 5029 } /* attaching_conditions_to_tables */ 5030 }, 5031 { 5032 "clause_processing": { 5033 "clause": "ORDER BY", 5034 "original_clause": "`alias1`.`col_int_key`,`alias2`.`pk`", 5035 "items": [ 5036 { 5037 "item": "`alias1`.`col_int_key`" 5038 }, 5039 { 5040 "item": "`alias2`.`pk`", 5041 "eq_ref_to_preceding_items": true 5042 } 5043 ] /* items */, 5044 "resulting_clause_is_simple": true, 5045 "resulting_clause": "`alias1`.`col_int_key`" 5046 } /* clause_processing */ 5047 }, 5048 { 5049 "clause_processing": { 5050 "clause": "GROUP BY", 5051 "original_clause": "`field2`", 5052 "items": [ 5053 { 5054 "item": "`alias2`.`pk`" 5055 } 5056 ] /* items */, 5057 "resulting_clause_is_simple": false, 5058 "resulting_clause": "`field2`" 5059 } /* clause_processing */ 5060 }, 5061 { 5062 "refine_plan": [ 5063 { 5064 "table": "`t1` `alias1`" 5065 }, 5066 { 5067 "table": "`t2` `alias2`" 5068 } 5069 ] /* refine_plan */ 5070 } 5071 ] /* steps */ 5072 } /* join_optimization */ 5073 }, 5074 { 5075 "join_execution": { 5076 "select#": 1, 5077 "steps": [ 5078 { 5079 "creating_tmp_table": { 5080 "tmp_table_info": { 5081 "table": "intermediate_tmp_table", 5082 "row_length": 18, 5083 "key_length": 4, 5084 "unique_constraint": false, 5085 "location": "memory (heap)", 5086 "row_limit_estimate": 58254 5087 } /* tmp_table_info */ 5088 } /* creating_tmp_table */ 5089 }, 5090 { 5091 "filesort_information": [ 5092 { 5093 "direction": "asc", 5094 "table": "intermediate_tmp_table", 5095 "field": "col_int_key" 5096 } 5097 ] /* filesort_information */, 5098 "filesort_priority_queue_optimization": { 5099 "usable": false, 5100 "cause": "not applicable (no LIMIT)" 5101 } /* filesort_priority_queue_optimization */, 5102 "filesort_execution": [ 5103 ] /* filesort_execution */, 5104 "filesort_summary": { 5105 "rows": 8, 5106 "examined_rows": 8, 5107 "number_of_tmp_files": 0, 5108 "sort_buffer_size": "NNN", 5109 "sort_mode": "<sort_key, rowid>" 5110 } /* filesort_summary */ 5111 } 5112 ] /* steps */ 5113 } /* join_execution */ 5114 } 5115 ] /* steps */ 5116} 0 0 5117DROP TABLE t1,t2; 5118# 5119# Trace of "condition on constant tables" 5120# 5121create table t1(a int) engine=myisam; 5122insert into t1 values(26); 5123create table t2(b int primary key, c int) engine=myisam; 5124insert into t2 values(1,100),(2,200),(3,300); 5125select * from t1,t2 where t1.a+t2.c=cos(10) and t2.b=2; 5126a b c 5127SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; 5128QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 5129select * from t1,t2 where t1.a+t2.c=cos(10) and t2.b=2 { 5130 "steps": [ 5131 { 5132 "join_preparation": { 5133 "select#": 1, 5134 "steps": [ 5135 { 5136 "expanded_query": "/* select#1 */ select `t1`.`a` AS `a`,`t2`.`b` AS `b`,`t2`.`c` AS `c` from `t1` join `t2` where (((`t1`.`a` + `t2`.`c`) = cos(10)) and (`t2`.`b` = 2))" 5137 } 5138 ] /* steps */ 5139 } /* join_preparation */ 5140 }, 5141 { 5142 "join_optimization": { 5143 "select#": 1, 5144 "steps": [ 5145 { 5146 "condition_processing": { 5147 "condition": "WHERE", 5148 "original_condition": "(((`t1`.`a` + `t2`.`c`) = cos(10)) and (`t2`.`b` = 2))", 5149 "steps": [ 5150 { 5151 "transformation": "equality_propagation", 5152 "resulting_condition": "(((`t1`.`a` + `t2`.`c`) = cos(10)) and multiple equal(2, `t2`.`b`))" 5153 }, 5154 { 5155 "transformation": "constant_propagation", 5156 "resulting_condition": "(((`t1`.`a` + `t2`.`c`) = cos(10)) and multiple equal(2, `t2`.`b`))" 5157 }, 5158 { 5159 "transformation": "trivial_condition_removal", 5160 "resulting_condition": "(((`t1`.`a` + `t2`.`c`) = cos(10)) and multiple equal(2, `t2`.`b`))" 5161 } 5162 ] /* steps */ 5163 } /* condition_processing */ 5164 }, 5165 { 5166 "substitute_generated_columns": { 5167 } /* substitute_generated_columns */ 5168 }, 5169 { 5170 "table_dependencies": [ 5171 { 5172 "table": "`t1`", 5173 "row_may_be_null": false, 5174 "map_bit": 0, 5175 "depends_on_map_bits": [ 5176 ] /* depends_on_map_bits */ 5177 }, 5178 { 5179 "table": "`t2`", 5180 "row_may_be_null": false, 5181 "map_bit": 1, 5182 "depends_on_map_bits": [ 5183 ] /* depends_on_map_bits */ 5184 } 5185 ] /* table_dependencies */ 5186 }, 5187 { 5188 "ref_optimizer_key_uses": [ 5189 { 5190 "table": "`t2`", 5191 "field": "b", 5192 "equals": "2", 5193 "null_rejecting": false 5194 } 5195 ] /* ref_optimizer_key_uses */ 5196 }, 5197 { 5198 "rows_estimation": [ 5199 { 5200 "table": "`t1`", 5201 "rows": 1, 5202 "cost": 1, 5203 "table_type": "system", 5204 "empty": false 5205 }, 5206 { 5207 "table": "`t2`", 5208 "rows": 1, 5209 "cost": 1, 5210 "table_type": "const", 5211 "empty": false 5212 } 5213 ] /* rows_estimation */ 5214 }, 5215 { 5216 "condition_on_constant_tables": "(('26' + '200') = cos(10))", 5217 "condition_value": false 5218 } 5219 ] /* steps */, 5220 "empty_result": { 5221 "cause": "Impossible WHERE noticed after reading const tables" 5222 } /* empty_result */ 5223 } /* join_optimization */ 5224 }, 5225 { 5226 "join_execution": { 5227 "select#": 1, 5228 "steps": [ 5229 ] /* steps */ 5230 } /* join_execution */ 5231 } 5232 ] /* steps */ 5233} 0 0 5234drop table t1,t2; 5235# 5236# Trace of non-default db 5237# 5238create table t1(a int); 5239insert into t1 values(1),(2),(3); 5240create database mysqltest2; 5241create table mysqltest2.t2(a int); 5242insert into mysqltest2.t2 values(1),(2); 5243select * from t1,mysqltest2.t2; 5244a a 52451 1 52461 2 52472 1 52482 2 52493 1 52503 2 5251SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; 5252QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES 5253select * from t1,mysqltest2.t2 { 5254 "steps": [ 5255 { 5256 "join_preparation": { 5257 "select#": 1, 5258 "steps": [ 5259 { 5260 "expanded_query": "/* select#1 */ select `t1`.`a` AS `a`,`mysqltest2`.`t2`.`a` AS `a` from `t1` join `mysqltest2`.`t2`" 5261 } 5262 ] /* steps */ 5263 } /* join_preparation */ 5264 }, 5265 { 5266 "join_optimization": { 5267 "select#": 1, 5268 "steps": [ 5269 { 5270 "table_dependencies": [ 5271 { 5272 "table": "`t1`", 5273 "row_may_be_null": false, 5274 "map_bit": 0, 5275 "depends_on_map_bits": [ 5276 ] /* depends_on_map_bits */ 5277 }, 5278 { 5279 "table": "`mysqltest2`.`t2`", 5280 "row_may_be_null": false, 5281 "map_bit": 1, 5282 "depends_on_map_bits": [ 5283 ] /* depends_on_map_bits */ 5284 } 5285 ] /* table_dependencies */ 5286 }, 5287 { 5288 "rows_estimation": [ 5289 { 5290 "table": "`t1`", 5291 "table_scan": { 5292 "rows": 3, 5293 "cost": 2 5294 } /* table_scan */ 5295 }, 5296 { 5297 "table": "`mysqltest2`.`t2`", 5298 "table_scan": { 5299 "rows": 2, 5300 "cost": 2 5301 } /* table_scan */ 5302 } 5303 ] /* rows_estimation */ 5304 }, 5305 { 5306 "considered_execution_plans": [ 5307 { 5308 "plan_prefix": [ 5309 ] /* plan_prefix */, 5310 "table": "`mysqltest2`.`t2`", 5311 "best_access_path": { 5312 "considered_access_paths": [ 5313 { 5314 "rows_to_scan": 2, 5315 "access_type": "scan", 5316 "resulting_rows": 2, 5317 "cost": 2.4034, 5318 "chosen": true 5319 } 5320 ] /* considered_access_paths */ 5321 } /* best_access_path */, 5322 "condition_filtering_pct": 100, 5323 "rows_for_plan": 2, 5324 "cost_for_plan": 2.4034, 5325 "rest_of_plan": [ 5326 { 5327 "plan_prefix": [ 5328 "`mysqltest2`.`t2`" 5329 ] /* plan_prefix */, 5330 "table": "`t1`", 5331 "best_access_path": { 5332 "considered_access_paths": [ 5333 { 5334 "rows_to_scan": 3, 5335 "access_type": "scan", 5336 "using_join_cache": true, 5337 "buffers_needed": 1, 5338 "resulting_rows": 3, 5339 "cost": 3.2052, 5340 "chosen": true 5341 } 5342 ] /* considered_access_paths */ 5343 } /* best_access_path */, 5344 "condition_filtering_pct": 100, 5345 "rows_for_plan": 6, 5346 "cost_for_plan": 5.6086, 5347 "chosen": true 5348 } 5349 ] /* rest_of_plan */ 5350 }, 5351 { 5352 "plan_prefix": [ 5353 ] /* plan_prefix */, 5354 "table": "`t1`", 5355 "best_access_path": { 5356 "considered_access_paths": [ 5357 { 5358 "rows_to_scan": 3, 5359 "access_type": "scan", 5360 "resulting_rows": 3, 5361 "cost": 2.6051, 5362 "chosen": true 5363 } 5364 ] /* considered_access_paths */ 5365 } /* best_access_path */, 5366 "condition_filtering_pct": 100, 5367 "rows_for_plan": 3, 5368 "cost_for_plan": 2.6051, 5369 "pruned_by_heuristic": true 5370 } 5371 ] /* considered_execution_plans */ 5372 }, 5373 { 5374 "attaching_conditions_to_tables": { 5375 "original_condition": null, 5376 "attached_conditions_computation": [ 5377 ] /* attached_conditions_computation */, 5378 "attached_conditions_summary": [ 5379 { 5380 "table": "`mysqltest2`.`t2`", 5381 "attached": null 5382 }, 5383 { 5384 "table": "`t1`", 5385 "attached": null 5386 } 5387 ] /* attached_conditions_summary */ 5388 } /* attaching_conditions_to_tables */ 5389 }, 5390 { 5391 "refine_plan": [ 5392 { 5393 "table": "`mysqltest2`.`t2`" 5394 }, 5395 { 5396 "table": "`t1`" 5397 } 5398 ] /* refine_plan */ 5399 } 5400 ] /* steps */ 5401 } /* join_optimization */ 5402 }, 5403 { 5404 "join_execution": { 5405 "select#": 1, 5406 "steps": [ 5407 ] /* steps */ 5408 } /* join_execution */ 5409 } 5410 ] /* steps */ 5411} 0 0 5412drop table t1; 5413drop database mysqltest2; 5414