MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
general2.inc
1 # Continuation of tests for optimizer trace
2 
3 --source include/have_optimizer_trace.inc
4 
5 let $DEFAULT_TRACE_MEM_SIZE=1048576; # 1MB
6 eval set optimizer_trace_max_mem_size=$DEFAULT_TRACE_MEM_SIZE;
7 
8 set end_markers_in_json=on;
9 set optimizer_trace="enabled=on";
10 
11 --echo # check that if a sub-statement should not be traced,
12 --echo # it is not traced even if inside a traced top statement
13 --echo
14 set optimizer_trace_offset=0, optimizer_trace_limit=100;
15 delimiter |;
16 create function f1(arg char(1)) returns int
17 begin
18  declare res int;
19  declare dummy varchar(1);
20  select 1 into res from dual;
21  select TRACE+NULL into dummy from information_schema.OPTIMIZER_TRACE limit 1;
22  select 2 into res from dual;
23  return 3;
24 end|
25 # ps-protocol specific note: as we asked to retain all traces,
26 # we see the one of PREPARE too.
27 select f1("c")|
28 --echo
29 # we should not see the trace of "select TRACE+NULL..."
30 # because tracing is disabled when OPTIMIZER_TRACE table is used.
31 select * from information_schema.OPTIMIZER_TRACE|
32 delimiter ;|
33 set optimizer_trace_offset=default, optimizer_trace_limit=default;
34 drop function f1;
35 
36 --echo # check that if a tracing gets disabled in a routine's body,
37 --echo # substatements are not traced
38 --echo
39 set optimizer_trace_offset=0, optimizer_trace_limit=100;
40 delimiter |;
41 create function f1(arg char(1)) returns int
42 begin
43  declare res int;
44  declare dummy varchar(1);
45  set optimizer_trace="enabled=off";
46  select 1 into res from dual;
47  select TRACE+NULL into dummy from information_schema.OPTIMIZER_TRACE limit 1;
48  select 2 into res from dual;
49  return 3;
50 end|
51 select f1("c")|
52 --echo
53 select * from information_schema.OPTIMIZER_TRACE|
54 delimiter ;|
55 set optimizer_trace_offset=default, optimizer_trace_limit=default;
56 select @@optimizer_trace;
57 set optimizer_trace="enabled=on";
58 drop function f1;
59 
60 --echo
61 --echo # Check that if a sub-statement reads OPTIMIZER_TRACE,
62 --echo # thus reading the unfinished trace of its caller statement,
63 --echo # there is no crash.
64 --echo
65 
66 create temporary table optt
67 (id int primary key auto_increment,
68 QUERY varchar(200),
69 TRACE text);
70 create table t1 (a int, key(a));
71 insert into t1 values(2);
72 set optimizer_trace_offset=0, optimizer_trace_limit=100;
73 delimiter |;
74 create function f1(arg char(1)) returns int
75 begin
76  declare res int;
77  insert into optt select NULL, QUERY, TRACE from information_schema.OPTIMIZER_TRACE;
78  return 3;
79 end|
80 select * from t1 where a in (select f1("c") from t1)|
81 --echo
82 delimiter ;|
83 set optimizer_trace="enabled=off";
84 --echo this should find unfinished traces
85 select count(*) from optt where TRACE NOT LIKE "%] /* steps */\n}";
86 select count(*)<>0 from optt;
87 --echo this should not
88 select count(*) from information_schema.OPTIMIZER_TRACE where TRACE NOT LIKE "%] /* steps */\n}";
89 select count(*)<>0 from information_schema.OPTIMIZER_TRACE;
90 
91 set optimizer_trace_offset=default, optimizer_trace_limit=default;
92 drop temporary table optt;
93 drop function f1;
94 drop table t1;
95 set optimizer_trace="enabled=on";
96 
97 --echo
98 --echo # check of crash with I_S.VIEWS (TABLE_LIST::alias==NULL)
99 --echo
100 create table t1(a int, b int);
101 create view v1 as select a from t1;
102 select VIEW_DEFINITION from information_schema.VIEWS
103 where TABLE_SCHEMA="test" and TABLE_NAME="v1";
104 select locate("\"view\": \"v1\"", TRACE) != 0
105 from information_schema.OPTIMIZER_TRACE;
106 drop table t1;
107 drop view v1;
108 
109 --echo
110 --echo # check for readable display of BIT values
111 --echo
112 create table t1 (a bit(5), key(a));
113 insert into t1 values(b'00000'),(b'01101');
114 select cast(a as unsigned) from t1 where a > b'01100';
115 # Note that in the trace we get either 0x0c or 12
116 select TRACE from information_schema.OPTIMIZER_TRACE;
117 drop table t1;
118 
119 --echo
120 --echo # check that trace lists all pushed down ON conditions
121 --echo
122 create table t1 (i int not null);
123 insert into t1 values (0), (2),(3),(4);
124 create table t2 (i int not null);
125 insert into t2 values (0),(1), (3),(4);
126 create table t3 (i int not null);
127 insert into t3 values (0),(1),(2), (4);
128 select * from
129  t1 LEFT JOIN
130  ( t2 LEFT JOIN
131  ( t3
132  )
133  ON t3.i = t2.i
134  )
135  ON t2.i = t1.i
136  WHERE t3.i IS NULL
137  ;
138 select TRACE from information_schema.OPTIMIZER_TRACE;
139 drop table t1,t2,t3;
140 
141 --echo
142 --echo # test of tracing a query with an HAVING condition, in
143 --echo # ps-protocol, does not crash
144 --echo
145 # Comes from having.test
146 
147 CREATE TABLE t1 (f1 INT, f2 VARCHAR(1));
148 INSERT INTO t1 VALUES (16,'f');
149 INSERT INTO t1 VALUES (16,'f');
150 CREATE TABLE t2 (f1 INT, f2 VARCHAR(1));
151 INSERT INTO t2 VALUES (13,'f');
152 INSERT INTO t2 VALUES (20,'f');
153 CREATE TABLE t3 (f1 INT, f2 VARCHAR(1));
154 INSERT INTO t3 VALUES (7,'f');
155 
156 SELECT t1.f2 FROM t1
157 STRAIGHT_JOIN (t2 JOIN t3 ON t3.f2 = t2.f2 ) ON t3 .f2 = t2 .f2
158 HAVING ('v', 'i') NOT IN (SELECT f2, MIN(f2) FROM t1)
159 ORDER BY f2;
160 --replace_regex /("sort_buffer_size":) [0-9]+/\1 "NNN"/
161 select TRACE from information_schema.OPTIMIZER_TRACE;
162 
163 DROP TABLES t1,t2,t3;
164 
165 --echo
166 --echo # Test that tracing a query with a materialized FROM-clause
167 --echo # derived table using a GROUP BY, does not crash
168 --echo
169 # Comes from profiling.test
170 create table t1 (a int, b int);
171 insert into t1 values (1,1), (2,null), (3, 4);
172 select max(x) from (select sum(a) as x from t1 group by b) as teeone;
173 --replace_regex /("sort_buffer_size":) [0-9]+/\1 "NNN"/
174 select TRACE from information_schema.OPTIMIZER_TRACE;
175 drop table t1;
176 
177 --echo
178 --echo # To have no crash above, we had to restore the ref_array at
179 --echo # end of JOIN::exec(). This impacts how the query looks like,
180 --echo # but not too much, as seen in the error message below.
181 --echo # Comes from func_gconcat.test.
182 --echo
183 CREATE TABLE t1(f1 int);
184 INSERT INTO t1 values (0),(0);
185 set optimizer_trace="enabled=off";
186 --disable_ps_protocol
187 --error ER_ILLEGAL_VALUE_FOR_TYPE
188 SELECT POLYGON((SELECT 1 FROM (SELECT 1 IN (GROUP_CONCAT(t1.f1)) FROM t1, t1 t GROUP BY t.f1 ) d));
189 --enable_ps_protocol
190 set optimizer_trace="enabled=on";
191 --disable_ps_protocol
192 --error ER_ILLEGAL_VALUE_FOR_TYPE
193 SELECT POLYGON((SELECT 1 FROM (SELECT 1 IN (GROUP_CONCAT(t1.f1)) FROM t1, t1 t GROUP BY t.f1 ) d));
194 --enable_ps_protocol
195 DROP TABLE t1;
196 
197 --echo
198 --echo # Check that SQL PREPARE and SQL EXECUTE each produce one trace.
199 --echo
200 set optimizer_trace_offset=0, optimizer_trace_limit=100;
201 prepare stmt from "select 1";
202 select * from information_schema.OPTIMIZER_TRACE;
203 set optimizer_trace_offset=0, optimizer_trace_limit=100;
204 execute stmt;
205 select * from information_schema.OPTIMIZER_TRACE;
206 deallocate prepare stmt;
207 set optimizer_trace_offset=default, optimizer_trace_limit=default;
208 
209 --echo
210 --echo # Test of SELECTs in IF in stored routine.
211 --echo # Same test for CASE WHEN.
212 --echo
213 create table t1 (a int);
214 delimiter |;
215 create procedure p1()
216 begin
217  if exists(select 1) then
218  insert into t1 values(1);
219  end if;
220  if exists(select 2) then
221  insert into t1 values(2);
222  end if;
223  if (select count(*) from t1) then
224  insert into t1 values(3);
225  end if;
226  set @a=(select count(a) from t1 where a>0);
227  case (select count(a) from t1 where a>1)
228  when 2 then set @b=2;
229  else set @b=3;
230  end case;
231 end|
232 delimiter ;|
233 set optimizer_trace_offset=0, optimizer_trace_limit=100;
234 set @old_max=@@optimizer_trace_max_mem_size;
235 set optimizer_trace_max_mem_size=40000;
236 call p1();
237 # SET @a=(SELECT) is not traced because part of SET
238 # which is a real command and not traced.
239 select * from information_schema.OPTIMIZER_TRACE;
240 select * from t1;
241 select @a,@b;
242 set optimizer_trace_max_mem_size=@old_max;
243 drop procedure p1;
244 drop table t1;
245 
246 --echo
247 --echo # Test of tracing of DO.
248 --echo
249 
250 set optimizer_trace_offset=0, optimizer_trace_limit=100;
251 do (select 42);
252 select * from information_schema.OPTIMIZER_TRACE;
253 
254 --echo
255 --echo # Test of tracing of subquery used in parameter of routine call
256 --echo
257 create table t1(a int);
258 insert into t1 values(1),(2);
259 delimiter |;
260 create procedure p1(x int)
261 begin
262  declare b int;
263  set b=(select 2+x from dual);
264 end|
265 delimiter ;|
266 set optimizer_trace_offset=0, optimizer_trace_limit=100;
267 call p1((select a from t1 limit 1));
268 select * from information_schema.OPTIMIZER_TRACE;
269 drop procedure p1;
270 drop table t1;
271 set optimizer_trace_offset=default, optimizer_trace_limit=default;
272 
273 --echo
274 --echo # Test that printing expanded query does not alter query's
275 --echo # results.
276 --echo # Comes from ctype_utf8mb4_heap.test
277 --echo
278 create table t1 (f1 varchar(1) not null) default charset utf8mb4;
279 insert into t1 values (''), ('');
280 select concat(concat(_latin1'->',f1),_latin1'<-') from t1;
281 select * from information_schema.optimizer_trace;
282 drop table t1;
283 
284 --echo
285 --echo # Bug#12546331 - SEGFAULT IN SUBSELECT_INDEXSUBQUERY_ENGINE::PRINT WITH OPTIMIZER TRACE
286 --echo
287 
288 CREATE TABLE t1 (
289  col_int_nokey INT,
290  col_int_key INT,
291  col_varchar_key varchar(1),
292  KEY col_int_key (col_int_key),
293  KEY col_varchar_key (col_varchar_key,col_int_key)
294 );
295 
296 INSERT INTO t1 VALUES
297  (NULL,8,'x'),
298  (8,7,'d'),
299  (1,1,'r'),
300  (9,7,'f'),
301  (4,9,'y'),
302  (3,NULL,'u'),
303  (2,1,'m'),
304  (NULL,9,NULL),
305  (2,2,'o'),
306  (NULL,9,'w'),
307  (6,2,'m'),
308  (7,4,'q'),
309  (2,0,NULL),
310  (5,4,'d'),
311  (7,8,'g'),
312  (6,NULL,'x'),
313  (6,NULL,'f'),
314  (2,0,'p'),
315  (9,NULL,'j'),
316  (6,8,'c')
317 ;
318 
319 CREATE TABLE t2 (
320  col_int_nokey INT,
321  col_int_key INT,
322  col_varchar_key varchar(1),
323  KEY col_int_key (col_int_key),
324  KEY col_varchar_key (col_varchar_key,col_int_key)
325 );
326 
327 INSERT INTO t2 VALUES
328  (2,4,'v'),
329  (150,62,'v'),
330  (NULL,7,'c'),
331  (2,1,NULL),
332  (5,0,'x'),
333  (3,7,'i'),
334  (1,7,'e'),
335  (4,1,'p'),
336  (NULL,7,'s'),
337  (2,1,'j'),
338  (6,5,'z'),
339  (6,2,'c'),
340  (8,0,'a'),
341  (2,1,'q'),
342  (6,8,'y'),
343  (8,1,NULL),
344  (3,1,'r'),
345  (3,9,'v'),
346  (9,1,NULL),
347  (6,5,'r')
348 ;
349 
350 SELECT col_int_nokey
351 FROM (
352  SELECT *
353  FROM t2
354  WHERE col_varchar_key > 'a'
355  OR ( 7 , 5 ) NOT IN (
356  SELECT col_int_nokey , col_int_key
357  FROM t1 )
358  ) AS alias1;
359 
360 DROP TABLE t1;
361 DROP TABLE t2;
362 
363 --echo
364 --echo BUG#12552262 - INVALID JSON WITH TWO CALLS TO TEST_QUICK_SELECT
365 --echo
366 
367 CREATE TABLE t1 (
368  col_varchar_10_latin1_key varchar(10) DEFAULT NULL,
369  col_int_key INT,
370  KEY col_int_key (col_int_key)
371 );
372 
373 CREATE TABLE t2 (
374  col_varchar_10_latin1_key varchar(10) DEFAULT NULL,
375  col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8 DEFAULT NULL,
376  col_int_key INT,
377  KEY col_varchar_10_utf8_key (col_varchar_10_utf8_key),
378  KEY col_int_key (col_int_key)
379 );
380 
381 INSERT INTO t2 VALUES ('qykbaqfyhz','l',NULL);
382 
383 CREATE TABLE t3 (
384  col_int_key INT,
385  col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8 DEFAULT NULL,
386  col_varchar_10_latin1_key varchar(10) DEFAULT NULL,
387  KEY col_varchar_10_utf8_key (col_varchar_10_utf8_key),
388  KEY col_varchar_10_latin1_key (col_varchar_10_latin1_key)
389 );
390 
391 INSERT INTO t3 VALUES (0,'s','it');
392 INSERT INTO t3 VALUES (9,'IQTHK','JCAQM');
393 
394 SELECT table2.col_int_key
395 FROM t3 AS table1
396  LEFT JOIN t1 AS table2 ON table1.col_int_key < table2.col_int_key
397  LEFT JOIN t2 AS table3 ON table2.col_varchar_10_latin1_key >=
398 table3.col_varchar_10_utf8_key
399 ;
400 
401 select * from information_schema.optimizer_trace;
402 
403 DROP TABLE t1,t2,t3;
404 
405 --echo
406 --echo Tests of tracing of the "eq_ref optimization" of plan search
407 --echo
408 
409 # test for trace point "chosen:true","pruned_by_cost:true" and
410 # "added_to_eq_ref_extension:true" (from main.subquery_sj_none_jcl7)
411 
412 create table t0 (a int);
413 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
414 create table t1 (a int, b int, key(a));
415 create table t2 (a int, b int, key(a));
416 create table t3 (a int, b int, key(a));
417 insert into t1 select a,a from t0;
418 insert into t2 select a,a from t0;
419 insert into t3 select a,a from t0;
420 
421 set @old_opt_switch=@@optimizer_switch;
422 # The SET below must not be output, because only servers supporting
423 # semijoin will execute it (would make varying output).
424 if (`select locate('semijoin', @@optimizer_switch) > 0`)
425 {
426 --disable_query_log
427  set optimizer_switch="semijoin=off,materialization=off";
428 --enable_query_log
429 }
430 explain select *
431 from t0 where a in
432 (select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a);
433 
434 select * from information_schema.optimizer_trace;
435 set optimizer_switch=@old_opt_switch;
436 drop table t0,t1,t2,t3;
437 
438 # test for trace point "added_to_eq_ref_extension:false" (from main.derived)
439 
440 CREATE TABLE t1 (
441 OBJECTID int(11) NOT NULL default '0',
442 SORTORDER int(11) NOT NULL auto_increment,
443 KEY t1_SortIndex (SORTORDER),
444 KEY t1_IdIndex (OBJECTID)
445 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
446 CREATE TABLE t2 (
447 ID int(11) default NULL,
448 PARID int(11) default NULL,
449 UNIQUE KEY t2_ID_IDX (ID),
450 KEY t2_PARID_IDX (PARID)
451 ) engine=MyISAM DEFAULT CHARSET=latin1;
452 INSERT INTO t2 VALUES (1000,0),(1001,0),(1002,0),(1003,0),(1008,1),(1009,1),(1010,1),(1011,1),(1016,2);
453 CREATE TABLE t3 (
454 ID int(11) default NULL,
455 DATA decimal(10,2) default NULL,
456 UNIQUE KEY t3_ID_IDX (ID)
457 ) engine=MyISAM DEFAULT CHARSET=latin1;
458 INSERT 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);
459 
460 select 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;
461 select * from information_schema.optimizer_trace;
462 drop table t1,t2,t3;
463 
464 # test of multiple nested trace points "added_to_eq_ref_extension:true"
465 # (eq_ref optimization finding a sequence of eq_ref-joined tables) (from
466 # main.type_blob)
467 
468 CREATE TABLE t1 (
469 t1_id bigint(21) NOT NULL auto_increment,
470 _field_72 varchar(128) DEFAULT '' NOT NULL,
471 _field_95 varchar(32),
472 _field_115 tinyint(4) DEFAULT '0' NOT NULL,
473 _field_122 tinyint(4) DEFAULT '0' NOT NULL,
474 _field_126 tinyint(4),
475 _field_134 tinyint(4),
476 PRIMARY KEY (t1_id),
477 UNIQUE _field_72 (_field_72),
478 KEY _field_115 (_field_115),
479 KEY _field_122 (_field_122)
480 );
481 INSERT INTO t1 VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',0,1,NULL,NULL);
482 INSERT INTO t1 VALUES (2,'hroberts','7415275a8c95952901e42b13a6b78566',0,1,NULL,NULL);
483 INSERT INTO t1 VALUES (3,'guest','d41d8cd98f00b204e9800998ecf8427e',1,0,NULL,NULL);
484 
485 CREATE TABLE t2 (
486 seq_0_id bigint(21) DEFAULT '0' NOT NULL,
487 seq_1_id bigint(21) DEFAULT '0' NOT NULL,
488 PRIMARY KEY (seq_0_id,seq_1_id)
489 );
490 INSERT INTO t2 VALUES (1,1);
491 INSERT INTO t2 VALUES (2,1);
492 INSERT INTO t2 VALUES (2,2);
493 
494 CREATE TABLE t3 (
495 t3_id bigint(21) NOT NULL auto_increment,
496 _field_131 varchar(128),
497 _field_133 tinyint(4) DEFAULT '0' NOT NULL,
498 _field_135 datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
499 _field_137 tinyint(4),
500 _field_139 datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
501 _field_140 blob,
502 _field_142 tinyint(4) DEFAULT '0' NOT NULL,
503 _field_145 tinyint(4) DEFAULT '0' NOT NULL,
504 _field_148 tinyint(4) DEFAULT '0' NOT NULL,
505 PRIMARY KEY (t3_id),
506 KEY _field_133 (_field_133),
507 KEY _field_135 (_field_135),
508 KEY _field_139 (_field_139),
509 KEY _field_142 (_field_142),
510 KEY _field_145 (_field_145),
511 KEY _field_148 (_field_148)
512 );
513 INSERT 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);
514 INSERT INTO t3 VALUES (2,'test job 2',0,'0000-00-00 00:00:00',0,'1999-02-26 21:08:04','',0,0,0);
515 
516 CREATE TABLE t4 (
517 seq_0_id bigint(21) DEFAULT '0' NOT NULL,
518 seq_1_id bigint(21) DEFAULT '0' NOT NULL,
519 PRIMARY KEY (seq_0_id,seq_1_id)
520 );
521 INSERT INTO t4 VALUES (1,1);
522 INSERT INTO t4 VALUES (2,1);
523 
524 CREATE TABLE t5 (
525 t5_id bigint(21) NOT NULL auto_increment,
526 _field_149 tinyint(4),
527 _field_156 varchar(128) DEFAULT '' NOT NULL,
528 _field_157 varchar(128) DEFAULT '' NOT NULL,
529 _field_158 varchar(128) DEFAULT '' NOT NULL,
530 _field_159 varchar(128) DEFAULT '' NOT NULL,
531 _field_160 varchar(128) DEFAULT '' NOT NULL,
532 _field_161 varchar(128) DEFAULT '' NOT NULL,
533 PRIMARY KEY (t5_id),
534 KEY _field_156 (_field_156),
535 KEY _field_157 (_field_157),
536 KEY _field_158 (_field_158),
537 KEY _field_159 (_field_159),
538 KEY _field_160 (_field_160),
539 KEY _field_161 (_field_161)
540 );
541 INSERT INTO t5 VALUES (1,0,'tomato','','','','','');
542 INSERT INTO t5 VALUES (2,0,'cilantro','','','','','');
543 
544 CREATE TABLE t6 (
545 seq_0_id bigint(21) DEFAULT '0' NOT NULL,
546 seq_1_id bigint(21) DEFAULT '0' NOT NULL,
547 PRIMARY KEY (seq_0_id,seq_1_id)
548 );
549 INSERT INTO t6 VALUES (1,1);
550 INSERT INTO t6 VALUES (1,2);
551 INSERT INTO t6 VALUES (2,2);
552 
553 CREATE TABLE t7 (
554 t7_id bigint(21) NOT NULL auto_increment,
555 _field_143 tinyint(4),
556 _field_165 varchar(32),
557 _field_166 smallint(6) DEFAULT '0' NOT NULL,
558 PRIMARY KEY (t7_id),
559 KEY _field_166 (_field_166)
560 );
561 INSERT INTO t7 VALUES (1,0,'High',1);
562 INSERT INTO t7 VALUES (2,0,'Medium',2);
563 INSERT INTO t7 VALUES (3,0,'Low',3);
564 
565 select replace(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.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 in (1) group by t3.t3_id order by link_alias_142._field_166, _field_139, link_alias_133._field_72, _field_135, link_alias_148._field_156;
566 select * from information_schema.optimizer_trace;
567 drop table t1,t2,t3,t4,t5,t6,t7;
568 
569 --echo #
570 --echo # Tracing of ORDER BY & GROUP BY simplification.
571 --echo #
572 
573 # this is originally the testcase for
574 # Bug#12699645 SELECT SUM() + STRAIGHT_JOIN QUERY MISSES ROWS
575 CREATE TABLE t1 (
576 pk INT, col_int_key INT,
577 col_varchar_key VARCHAR(1), col_varchar_nokey VARCHAR(1)
578 );
579 INSERT INTO t1 VALUES
580 (10,7,'v','v'),(11,0,'s','s'),(12,9,'l','l'),(13,3,'y','y'),(14,4,'c','c'),
581 (15,2,'i','i'),(16,5,'h','h'),(17,3,'q','q'),(18,1,'a','a'),(19,3,'v','v'),
582 (20,6,'u','u'),(21,7,'s','s'),(22,5,'y','y'),(23,1,'z','z'),(24,204,'h','h'),
583 (25,224,'p','p'),(26,9,'e','e'),(27,5,'i','i'),(28,0,'y','y'),(29,3,'w','w');
584 
585 CREATE TABLE t2 (
586 pk INT, col_int_key INT,
587 col_varchar_key VARCHAR(1), col_varchar_nokey VARCHAR(1),
588 PRIMARY KEY (pk)
589 );
590 INSERT INTO t2 VALUES
591 (1,4,'b','b'),(2,8,'y','y'),(3,0,'p','p'),(4,0,'f','f'),(5,0,'p','p'),
592 (6,7,'d','d'),(7,7,'f','f'),(8,5,'j','j'),(9,3,'e','e'),(10,188,'u','u'),
593 (11,4,'v','v'),(12,9,'u','u'),(13,6,'i','i'),(14,1,'x','x'),(15,5,'l','l'),
594 (16,6,'q','q'),(17,2,'n','n'),(18,4,'r','r'),(19,231,'c','c'),(20,4,'h','h'),
595 (21,3,'k','k'),(22,3,'t','t'),(23,7,'t','t'),(24,6,'k','k'),(25,7,'g','g'),
596 (26,9,'z','z'),(27,4,'n','n'),(28,4,'j','j'),(29,2,'l','l'),(30,1,'d','d'),
597 (31,2,'t','t'),(32,194,'y','y'),(33,2,'i','i'),(34,3,'j','j'),(35,8,'r','r'),
598 (36,4,'b','b'),(37,9,'o','o'),(38,4,'k','k'),(39,5,'a','a'),(40,5,'f','f'),
599 (41,9,'t','t'),(42,3,'c','c'),(43,8,'c','c'),(44,0,'r','r'),(45,98,'k','k'),
600 (46,3,'l','l'),(47,1,'o','o'),(48,0,'t','t'),(49,189,'v','v'),(50,8,'x','x'),
601 (51,3,'j','j'),(52,3,'x','x'),(53,9,'k','k'),(54,6,'o','o'),(55,8,'z','z'),
602 (56,3,'n','n'),(57,9,'c','c'),(58,5,'d','d'),(59,9,'s','s'),(60,2,'j','j'),
603 (61,2,'w','w'),(62,5,'f','f'),(63,8,'p','p'),(64,6,'o','o'),(65,9,'f','f'),
604 (66,0,'x','x'),(67,3,'q','q'),(68,6,'g','g'),(69,5,'x','x'),(70,8,'p','p'),
605 (71,2,'q','q'),(72,120,'q','q'),(73,25,'v','v'),(74,1,'g','g'),(75,3,'l','l'),
606 (76,1,'w','w'),(77,3,'h','h'),(78,153,'c','c'),(79,5,'o','o'),(80,9,'o','o'),
607 (81,1,'v','v'),(82,8,'y','y'),(83,7,'d','d'),(84,6,'p','p'),(85,2,'z','z'),
608 (86,4,'t','t'),(87,7,'b','b'),(88,3,'y','y'),(89,8,'k','k'),(90,4,'c','c'),
609 (91,6,'z','z'),(92,1,'t','t'),(93,7,'o','o'),(94,1,'u','u'),(95,0,'t','t'),
610 (96,2,'k','k'),(97,7,'u','u'),(98,2,'b','b'),(99,1,'m','m'),(100,5,'o','o');
611 
612 let $query=
613 SELECT SUM(alias2.col_varchar_nokey) , alias2.pk AS field2 FROM t1 AS alias1
614 STRAIGHT_JOIN t2 AS alias2 ON alias2.pk = alias1.col_int_key WHERE alias1.pk
615 GROUP BY field2 ORDER BY alias1.col_int_key,alias2.pk ;
616 eval $query;
617 --replace_regex /("sort_buffer_size":) [0-9]+/\1 "NNN"/
618 SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
619 
620 DROP TABLE t1,t2;
621 
622 --echo #
623 --echo # Trace of "condition on constant tables"
624 --echo #
625 create table t1(a int) engine=myisam;
626 insert into t1 values(26);
627 create table t2(b int primary key, c int) engine=myisam;
628 insert into t2 values(1,100),(2,200),(3,300);
629 select * from t1,t2 where t1.a+t2.c=cos(10) and t2.b=2;
630 SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
631 drop table t1,t2;
632 
633 --echo #
634 --echo # Trace of non-default db
635 --echo #
636 create table t1(a int);
637 insert into t1 values(1),(2),(3);
638 create database mysqltest2;
639 create table mysqltest2.t2(a int);
640 insert into mysqltest2.t2 values(1),(2);
641 select * from t1,mysqltest2.t2;
642 SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
643 drop table t1;
644 drop database mysqltest2;