File: explain_tree.result

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (1197 lines) | stat: -rw-r--r-- 52,631 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
set optimizer_switch='batched_key_access=off,block_nested_loop=off,mrr_cost_based=off';
CREATE TABLE t1 ( f1 INT );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1;
EXPLAIN
-> Table scan on t1  (cost=0.55 rows=3)

DROP TABLE t1;
CREATE TABLE t1 ( f1 INT );
CREATE TABLE t2 ( f1 INT );
EXPLAIN FORMAT=tree INSERT INTO t2 SELECT * FROM t1;
EXPLAIN
-> Insert into t2
    -> Table scan on t1  (cost=0.35 rows=1)

DROP TABLE t1, t2;
CREATE TABLE t1 ( f1 INT );
CREATE TABLE t2 ( f2 INT );
EXPLAIN FORMAT=tree UPDATE t1, t2 SET f1=f1+2, f2=f2+1 WHERE f1 = f2;
EXPLAIN
-> Update t1 (buffered), t2 (buffered)
    -> Nested loop inner join  (cost=0.7 rows=1)
        -> Table scan on t1  (cost=0.35 rows=1)
        -> Filter: (t2.f2 = t1.f1)  (cost=0.35 rows=1)
            -> Table scan on t2  (cost=0.35 rows=1)

DROP TABLE t1, t2;
CREATE TABLE t1 ( f1 INT );
CREATE TABLE t2 ( f2 INT );
EXPLAIN FORMAT=tree DELETE t1, t2 FROM t1, t2;
EXPLAIN
-> Delete from t1 (immediate), t2 (buffered)  (cost=0.8 rows=1)
    -> Nested loop inner join  (cost=0.7 rows=1)
        -> Table scan on t1  (cost=0.35 rows=1)
        -> Table scan on t2  (cost=0.35 rows=1)

DROP TABLE t1, t2;
CREATE TABLE t1 ( f1 INT );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT f1, (SELECT MIN(f1) FROM t1 i WHERE i.f1 > t1.f1) < 3 FROM t1;
EXPLAIN
-> Table scan on t1  (cost=0.55 rows=3)
-> Select #2 (subquery in projection; dependent)
    -> Aggregate: min(i.f1)  (cost=0.45 rows=1)
        -> Filter: (i.f1 > t1.f1)  (cost=0.35 rows=1)
            -> Table scan on i  (cost=0.35 rows=3)

Warnings:
Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
DROP TABLE t1;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 ORDER BY f1 DESC;
EXPLAIN
-> Index scan on t1 using PRIMARY (reverse)  (cost=0.55 rows=3)

DROP TABLE t1;
CREATE TABLE t1 ( f1 INT, INDEX ( f1 ) );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT SUM(f1) FROM t1;
EXPLAIN
-> Aggregate: sum(t1.f1)  (cost=0.85 rows=1)
    -> Index scan on t1 using f1  (cost=0.55 rows=3)

EXPLAIN FORMAT=tree SELECT f1 FROM t1 GROUP BY f1;
EXPLAIN
-> Group (no aggregates)  (cost=0.85 rows=1.73)
    -> Index scan on t1 using f1  (cost=0.55 rows=3)

EXPLAIN FORMAT=tree SELECT f1,COUNT(*) FROM t1 GROUP BY f1;
EXPLAIN
-> Group aggregate: count(0)  (cost=0.85 rows=1.73)
    -> Index scan on t1 using f1  (cost=0.55 rows=3)

EXPLAIN FORMAT=tree SELECT f1,COUNT(*) FROM t1 GROUP BY f1 WITH ROLLUP;
EXPLAIN
-> Group aggregate with rollup: count(0)  (cost=0.85 rows=2.73)
    -> Index scan on t1 using f1  (cost=0.55 rows=3)

DROP TABLE t1;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE f1=2;
EXPLAIN
-> Rows fetched before execution  (cost=0..0 rows=1)

DROP TABLE t1;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
CREATE TABLE t2 ( f1 INT PRIMARY KEY );
INSERT INTO t2 SELECT * FROM t1;
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 LEFT JOIN t2 ON t1.f1 = t2.f1 + 2 AND t2.f1 = 3;
EXPLAIN
-> Nested loop left join  (cost=1.1 rows=3)
    -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
    -> Filter: (t1.f1 = <cache>((3 + 2)))  (cost=0.117..0.117 rows=1)
        -> Constant row from t2  (cost=0.117..0.117 rows=1)

DROP TABLE t1, t2;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
CREATE TABLE t2 AS SELECT * FROM t1;
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 LEFT JOIN t2 USING (f1) WHERE t1.f1=2;
EXPLAIN
-> Nested loop left join  (cost=0.55 rows=3)
    -> Rows fetched before execution  (cost=0..0 rows=1)
    -> Filter: (t2.f1 = 2)  (cost=0.55 rows=3)
        -> Table scan on t2  (cost=0.55 rows=3)

DROP TABLE t1, t2;
CREATE TABLE t1 ( a INT );
CREATE TABLE t2 ( a INT );
CREATE TABLE t3 ( a INT, b INT );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t2 VALUES ( 3 );
INSERT INTO t3 VALUES ( 2, 0 );
ANALYZE TABLE t1, t2, t3;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
test.t3	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 LEFT JOIN ( t2 LEFT JOIN t3 USING (a) ) ON t3.b IS NULL;
EXPLAIN
-> Nested loop left join  (cost=0.7 rows=1)
    -> Table scan on t1  (cost=0.35 rows=1)
    -> Filter: (t3.b is null)  (cost=0.7 rows=1)
        -> Nested loop left join  (cost=0.7 rows=1)
            -> Table scan on t2  (cost=0.35 rows=1)
            -> Filter: (t3.a = t2.a)  (cost=0.35 rows=1)
                -> Table scan on t3  (cost=0.35 rows=1)

DROP TABLE t1, t2, t3;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
CREATE TABLE t2 AS SELECT * FROM t1;
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 LEFT JOIN t2 USING (f1) WHERE t2.f1 IS NULL;
EXPLAIN
-> Filter: (t2.f1 is null)  (cost=2.8 rows=3)
    -> Nested loop antijoin  (cost=2.8 rows=3)
        -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
        -> Filter: (t2.f1 = t1.f1)  (cost=0.483 rows=1)
            -> Table scan on t2  (cost=0.483 rows=3)

DROP TABLE t1, t2;
CREATE TABLE t1 (a INT, b INT);
CREATE TABLE t2 (a INT, c INT, KEY(a));
INSERT INTO t1 VALUES (1, 1), (2, 2);
INSERT INTO t2 VALUES (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
(2, 1), (2, 2), (2, 3), (2, 4), (2, 5),
(3, 1), (3, 2), (3, 3), (3, 4), (3, 5),
(4, 1), (4, 2), (4, 3), (4, 4), (4, 5);
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
FLUSH STATUS;
EXPLAIN FORMAT=tree SELECT DISTINCT b FROM t1 LEFT JOIN t2 USING(a) WHERE c <= 3;
EXPLAIN
-> Table scan on <temporary>  (cost=3.51..4.76 rows=2)
    -> Temporary table with deduplication  (cost=2.25..2.25 rows=2)
        -> Nested loop inner join  (cost=2.05 rows=2)
            -> Table scan on t1  (cost=0.45 rows=2)
            -> Limit: 1 row(s)  (cost=0.583 rows=1)
                -> Filter: (t2.c <= 3)  (cost=0.583 rows=1.67)
                    -> Index lookup on t2 using a (a=t1.a)  (cost=0.583 rows=5)

DROP TABLE t1, t2;
CREATE TABLE t1 ( f1 INT );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 ORDER BY f1 DESC;
EXPLAIN
-> Sort: t1.f1 DESC  (cost=0.55 rows=3)
    -> Table scan on t1  (cost=0.55 rows=3)

DROP TABLE t1;
CREATE TABLE t1 ( a LONGBLOB, b INT );
INSERT INTO t1 VALUES ('a', 0);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT 0 AS foo FROM t1 WHERE 0 = (SELECT group_concat(b) FROM t1 t GROUP BY t1.a) ;
EXPLAIN
-> Filter: (0 = (select #2))  (cost=0.35 rows=1)
    -> Table scan on t1  (cost=0.35 rows=1)
    -> Select #2 (subquery in condition; dependent)
        -> Group aggregate: group_concat(t1.b separator ',')
            -> Sort row IDs: t1.a
                -> Table scan on <temporary>  (cost=2.96..2.96 rows=1)
                    -> Temporary table  (cost=0.45..0.45 rows=1)
                        -> Table scan on t  (cost=0.35 rows=1)

Warnings:
Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
DROP TABLE t1;
CREATE TABLE t1 (a text, b varchar(10));
INSERT INTO t1 VALUES (repeat('1', 1300),'one'), (repeat('1', 1300),'two');
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT SUBSTRING(a,1,10), LENGTH(a) FROM t1 GROUP BY a;
EXPLAIN
-> Table scan on <temporary>  (cost=1.91..3.18 rows=2)
    -> Temporary table with deduplication  (cost=0.65..0.65 rows=2)
        -> Table scan on t1  (cost=0.45 rows=2)

DROP TABLE t1;
CREATE TABLE t1 ( f1 VARCHAR(100) );
INSERT INTO t1 VALUES ('abc');
INSERT INTO t1 VALUES ('abc');
INSERT INTO t1 VALUES ('def');
INSERT INTO t1 VALUES ('def');
INSERT INTO t1 VALUES ('ghi');
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT DISTINCT f1 FROM t1 LIMIT 2;
EXPLAIN
-> Limit: 2 row(s)  (cost=1.76..2.28 rows=2)
    -> Table scan on <temporary>  (cost=1.76..3.81 rows=5)
        -> Temporary table with deduplication  (cost=1.25..1.25 rows=5)
            -> Limit table size: 2 unique row(s)
                -> Table scan on t1  (cost=0.75 rows=5)

DROP TABLE t1;
CREATE TABLE t1 (a int PRIMARY KEY);
INSERT INTO t1 values (1), (2);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
EXPLAIN
-> Insert into t1
    -> Limit: 1 row(s)  (cost=1.91..1.91 rows=1)
        -> Table scan on <temporary>  (cost=1.91..3.18 rows=2)
            -> Temporary table  (cost=0.65..0.65 rows=2)
                -> Limit table size: 1 row(s)
                    -> Index scan on t1 using PRIMARY  (cost=0.45 rows=2)

DROP TABLE t1;
CREATE TABLE t1 (a INTEGER, b INTEGER);
INSERT INTO t1 VALUES (1,3), (2,4), (1,5),
(1,3), (2,1), (1,5), (1,7), (3,1),
(3,2), (3,1), (2,4);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT DISTINCT (COUNT(DISTINCT b) + 1) AS c FROM t1 GROUP BY a;
EXPLAIN
-> Table scan on <temporary>  (cost=6.42..8.19 rows=3.32)
    -> Temporary table with deduplication  (cost=5.65..5.65 rows=3.32)
        -> Table scan on <temporary>  (cost=3.55..5.32 rows=3.32)
            -> Temporary table  (cost=2.78..2.78 rows=3.32)
                -> Group aggregate: count(distinct t1.b)  (cost=2.45 rows=3.32)
                    -> Sort: t1.a  (cost=1.35 rows=11)
                        -> Table scan on t1  (cost=1.35 rows=11)

DROP TABLE t1;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE f1 = ( SELECT MIN(f1) FROM t1 AS i WHERE i.f1 > t1.f1 );
EXPLAIN
-> Filter: (t1.f1 = (select #2))  (cost=0.55 rows=3)
    -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
    -> Select #2 (subquery in condition; dependent)
        -> Aggregate: min(i.f1)  (cost=0.45 rows=1)
            -> Filter: (i.f1 > t1.f1)  (cost=0.35 rows=1)
                -> Index range scan on i (re-planned for each iteration)  (cost=0.35 rows=3)

Warnings:
Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE f1 > ( SELECT f1 FROM t1 LIMIT 1 );
EXPLAIN
-> Filter: (t1.f1 > (select #2))  (cost=0.55 rows=2)
    -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
    -> Select #2 (subquery in condition; run only once)
        -> Limit: 1 row(s)  (cost=0.55 rows=1)
            -> Covering index scan on t1 using PRIMARY  (cost=0.55 rows=3)

DROP TABLE t1;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE f1 = ( SELECT ( SELECT MIN(f1) FROM t1 AS ii WHERE ii.f1 > t1.f1 ) > i.f1 FROM t1 AS i ) ;
EXPLAIN
-> Filter: (t1.f1 = (select #2))  (cost=0.55 rows=3)
    -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
    -> Select #2 (subquery in condition; dependent)
        -> Index scan on i using PRIMARY  (cost=0.55 rows=3)
        -> Select #3 (subquery in projection; dependent)
            -> Aggregate: min(ii.f1)  (cost=0.45 rows=1)
                -> Filter: (ii.f1 > t1.f1)  (cost=0.35 rows=1)
                    -> Index range scan on ii (re-planned for each iteration)  (cost=0.35 rows=3)

Warnings:
Note	1276	Field or reference 'test.t1.f1' of SELECT #3 was resolved in SELECT #1
DROP TABLE t1;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT ( SELECT ( SELECT ( SELECT MIN(f1) FROM t1 i WHERE i.f1 > t1.f1 ) + 1 ) + 1 ) FROM t1;
EXPLAIN
-> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
-> Select #4 (subquery in projection; dependent)
    -> Aggregate: min(i.f1)  (cost=0.45 rows=1)
        -> Filter: (i.f1 > t1.f1)  (cost=0.35 rows=1)
            -> Index range scan on i (re-planned for each iteration)  (cost=0.35 rows=3)

Warnings:
Note	1276	Field or reference 'test.t1.f1' of SELECT #4 was resolved in SELECT #1
Note	1249	Select 3 was reduced during optimization
Note	1249	Select 2 was reduced during optimization
DROP TABLE t1;
CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES ( 1 );
INSERT INTO t1 VALUES ( 2 );
INSERT INTO t1 VALUES ( 3 );
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT ( SELECT f1 FROM t1 AS inner_t1 WHERE inner_t1.f1 > t1.f1 LIMIT 1 ) AS tmp1 FROM t1 ORDER BY tmp1;
EXPLAIN
-> Sort: tmp1
    -> Stream results  (cost=0.55 rows=3)
        -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
-> Select #2 (subquery in projection; dependent)
    -> Limit: 1 row(s)  (cost=0.35 rows=1)
        -> Filter: (inner_t1.f1 > t1.f1)  (cost=0.35 rows=1)
            -> Index range scan on inner_t1 (re-planned for each iteration)  (cost=0.35 rows=3)

Warnings:
Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
DROP TABLE t1;
CREATE TABLE t1 (a INTEGER, b INTEGER);
INSERT INTO t1 VALUES (1,3), (2,4), (1,5),
(1,3), (2,1), (1,5), (1,7), (3,1),
(3,2), (3,1), (2,4);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE a > 3 ORDER BY b;
EXPLAIN
-> Sort: t1.b  (cost=1.35 rows=11)
    -> Filter: (t1.a > 3)  (cost=1.35 rows=11)
        -> Table scan on t1  (cost=1.35 rows=11)

DROP TABLE t1;
CREATE TABLE t1 (i INT);
EXPLAIN INSERT INTO t1 VALUES (10);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	INSERT	t1	NULL	ALL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
Warnings:
Note	1003	insert into `test`.`t1` values (10)
EXPLAIN FORMAT=tree INSERT INTO t1 VALUES (10);
EXPLAIN
<not executable by iterator executor>

DROP TABLE t1;
CREATE TABLE t1 (a INTEGER, b INTEGER);
INSERT INTO t1 VALUES (1,3), (2,4), (1,5),
(1,3), (2,1), (1,5), (1,7), (3,1),
(3,2), (3,1), (2,4);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 ORDER BY b LIMIT 3;
EXPLAIN
-> Limit: 3 row(s)  (cost=1.35 rows=3)
    -> Sort: t1.b, limit input to 3 row(s) per chunk  (cost=1.35 rows=11)
        -> Table scan on t1  (cost=1.35 rows=11)

DROP TABLE t1;
CREATE TABLE t1 ( a INTEGER );
CREATE TABLE t2 ( a INTEGER );
CREATE TABLE t3 ( a INTEGER );
EXPLAIN FORMAT=tree SELECT * FROM t1 LEFT JOIN t2 USING ( a ),
LATERAL ( SELECT * FROM t3 WHERE t3.a = t2.a LIMIT 1 ) t3d,
LATERAL ( SELECT * FROM t3 WHERE t3.a > t1.a LIMIT 1 ) t4d;
EXPLAIN
-> Nested loop inner join  (cost=9.3 rows=1)
    -> Nested loop inner join  (cost=3.87 rows=1)
        -> Invalidate materialized tables (row from t2)  (cost=0.7 rows=1)
            -> Nested loop left join  (cost=0.7 rows=1)
                -> Invalidate materialized tables (row from t1)  (cost=0.35 rows=1)
                    -> Table scan on t1  (cost=0.35 rows=1)
                -> Filter: (t2.a = t1.a)  (cost=0.35 rows=1)
                    -> Table scan on t2  (cost=0.35 rows=1)
        -> Table scan on t3d  (cost=2.96..2.96 rows=1)
            -> Materialize (invalidate on row from t2)  (cost=0.45..0.45 rows=1)
                -> Limit: 1 row(s)  (cost=0.35 rows=1)
                    -> Filter: (t3.a = t2.a)  (cost=0.35 rows=1)
                        -> Table scan on t3  (cost=0.35 rows=1)
    -> Table scan on t4d  (cost=2.96..2.96 rows=1)
        -> Materialize (invalidate on row from t1)  (cost=0.45..0.45 rows=1)
            -> Limit: 1 row(s)  (cost=0.35 rows=1)
                -> Filter: (t3.a > t1.a)  (cost=0.35 rows=1)
                    -> Table scan on t3  (cost=0.35 rows=1)

Warnings:
Note	1276	Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
DROP TABLE t1, t2, t3;
CREATE TABLE t1 ( a INTEGER );
CREATE TABLE t2 ( a INTEGER );
CREATE TABLE t3 ( a INTEGER );
CREATE TABLE t4 ( a INTEGER );
EXPLAIN FORMAT=tree SELECT * FROM t1 LEFT JOIN (
t2 LEFT JOIN t3 USING ( a ) CROSS JOIN
LATERAL ( SELECT * FROM t4 WHERE t4.a = t3.a LIMIT 1 ) t4d
) ON t1.a = t4d.a;
EXPLAIN
-> Nested loop left join  (cost=0.7 rows=1)
    -> Table scan on t1  (cost=0.35 rows=1)
    -> Nested loop inner join  (cost=1.85 rows=1)
        -> Invalidate materialized tables (row from t3)  (cost=0.7 rows=1)
            -> Nested loop left join  (cost=0.7 rows=1)
                -> Table scan on t2  (cost=0.35 rows=1)
                -> Filter: (t3.a = t2.a)  (cost=0.35 rows=1)
                    -> Table scan on t3  (cost=0.35 rows=1)
        -> Covering index lookup on t4d using <auto_key0> (a=t1.a)  (cost=1.07..1.7 rows=2)
            -> Materialize (invalidate on row from t3)  (cost=0.45..0.45 rows=1)
                -> Limit: 1 row(s)  (cost=0.35 rows=1)
                    -> Filter: (t4.a = t3.a)  (cost=0.35 rows=1)
                        -> Table scan on t4  (cost=0.35 rows=1)

Warnings:
Note	1276	Field or reference 'test.t3.a' of SELECT #2 was resolved in SELECT #1
DROP TABLE t1, t2, t3, t4;
CREATE TABLE t1 ( f1 INTEGER );
EXPLAIN FORMAT=TREE SELECT * FROM ( SELECT * FROM t1 LIMIT 2 OFFSET 1 ) AS alias1
WHERE f1 <= ANY ( SELECT f1 FROM t1 ) ORDER BY f1;
EXPLAIN
-> Sort: alias1.f1  (cost=2.95..2.95 rows=0)
    -> Filter: <nop>((alias1.f1 <= (select #3)))  (cost=2.85..2.85 rows=0)
        -> Table scan on alias1  (cost=2.85..2.85 rows=0)
            -> Materialize  (cost=0.35..0.35 rows=0)
                -> Limit/Offset: 2/1 row(s)  (cost=0.35 rows=0)
                    -> Table scan on t1  (cost=0.35 rows=1)
        -> Select #3 (subquery in condition; run only once)
            -> Aggregate: max(t1.f1)  (cost=0.45 rows=1)
                -> Table scan on t1  (cost=0.35 rows=1)

DROP TABLE t1;
CREATE TABLE t1 ( f1 INT );
CREATE TABLE t2 ( f1 INT );
EXPLAIN format=tree WITH my_cte AS ( SELECT * FROM t1 LIMIT 3 ) SELECT * FROM my_cte, t2;
EXPLAIN
-> Nested loop inner join  (cost=2.98 rows=1)
    -> Table scan on t2  (cost=0.35 rows=1)
    -> Table scan on my_cte  (cost=2.96..2.96 rows=1)
        -> Materialize CTE my_cte  (cost=0.45..0.45 rows=1)
            -> Limit: 3 row(s)  (cost=0.35 rows=1)
                -> Table scan on t1  (cost=0.35 rows=1)

DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1 (i INTEGER);
CREATE TABLE t2 (i INTEGER);
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE (t1.i) IN (SELECT t2.i FROM t2);
EXPLAIN
-> Nested loop semijoin  (cost=0.7 rows=1)
    -> Table scan on t1  (cost=0.35 rows=1)
    -> Filter: (t2.i = t1.i)  (cost=0.35 rows=1)
        -> Table scan on t2  (cost=0.35 rows=1)

DROP TABLE t1, t2;
CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER);
CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER);
CREATE TABLE t3 (i INTEGER);
CREATE TABLE t4 (i INTEGER);
INSERT INTO t1 VALUES (2, 3);
INSERT INTO t2 VALUES (4, 5);
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1,t2 WHERE (t1.i) IN (SELECT t3.i FROM t3,t4) AND t1.pk = 2 AND t2.pk = 4;
EXPLAIN
-> Limit: 1 row(s)  (cost=0.7 rows=1)
    -> Nested loop inner join  (cost=0.7 rows=1)
        -> Filter: (t3.i = '3')  (cost=0.35 rows=1)
            -> Table scan on t3  (cost=0.35 rows=1)
        -> Table scan on t4  (cost=0.35 rows=1)

DROP TABLE t1, t2, t3, t4;
CREATE TABLE t1 (i INTEGER);
CREATE TABLE t2 (i INTEGER);
CREATE TABLE t3 (i INTEGER, j INTEGER);
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE t1.i IN ( SELECT i FROM t2 LEFT JOIN t3 USING (i) WHERE t3.j = 1234 OR t3.j IS NULL );
EXPLAIN
-> Nested loop semijoin  (cost=0.7 rows=1)
    -> Table scan on t1  (cost=0.35 rows=1)
    -> Filter: ((t3.j = 1234) or (t3.j is null))  (cost=0.7 rows=1)
        -> Nested loop left join  (cost=0.7 rows=1)
            -> Filter: (t2.i = t1.i)  (cost=0.35 rows=1)
                -> Table scan on t2  (cost=0.35 rows=1)
            -> Filter: (t2.i = t3.i)  (cost=0.35 rows=1)
                -> Table scan on t3  (cost=0.35 rows=1)

DROP TABLE t1, t2, t3;
set @old_opt_switch=@@optimizer_switch;
set optimizer_switch='firstmatch=off';
CREATE TABLE t1 ( a INTEGER, b INTEGER );
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 );
EXPLAIN
-> Nested loop inner join  (cost=3.71 rows=1)
    -> Table scan on <subquery2>  (cost=3.16..3.16 rows=1)
        -> Materialize with deduplication  (cost=0.65..0.65 rows=1)
            -> Filter: (t1.a is not null)  (cost=0.55 rows=1)
                -> Filter: (t1.b = 2)  (cost=0.55 rows=1)
                    -> Table scan on t1  (cost=0.55 rows=3)
    -> Filter: (t1.a = `<subquery2>`.a)  (cost=0.35 rows=1)
        -> Table scan on t1  (cost=0.35 rows=3)

DROP TABLE t1;
set @@optimizer_switch=@old_opt_switch;
set @old_opt_switch=@@optimizer_switch;
set optimizer_switch='firstmatch=off';
CREATE TABLE t1 ( a INTEGER NOT NULL, b INTEGER NOT NULL );
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT a FROM t1 WHERE a NOT IN ( SELECT b FROM t1 WHERE b > 2 );
EXPLAIN
-> Nested loop antijoin  (cost=1.75 rows=9)
    -> Table scan on t1  (cost=0.55 rows=3)
    -> Single-row index lookup on <subquery2> using <auto_distinct_key> (b=t1.a)  (cost=0.983..0.983 rows=1)
        -> Materialize with deduplication  (cost=0.85..0.85 rows=3)
            -> Filter: (t1.b is not null)  (cost=0.55 rows=3)
                -> Filter: (t1.b > 2)  (cost=0.55 rows=3)
                    -> Table scan on t1  (cost=0.55 rows=3)

DROP TABLE t1;
set @@optimizer_switch=@old_opt_switch;
set @old_opt_switch=@@optimizer_switch;
set optimizer_switch='firstmatch=off';
CREATE TABLE t1 ( a INTEGER, b INTEGER );
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT a FROM t1 WHERE a = ANY ( SELECT MAX(a) FROM t1 WHERE b = 2 );
EXPLAIN
-> Filter: <in_optimizer>(t1.a,<exists>(select #2))  (cost=0.55 rows=3)
    -> Table scan on t1  (cost=0.55 rows=3)
    -> Select #2 (subquery in condition; dependent)
        -> Limit: 1 row(s)  (cost=0.65 rows=1)
            -> Filter: (<cache>(t1.a) = <ref_null_helper>(max(t1.a)))  (cost=0.65 rows=1)
                -> Aggregate: max(t1.a)  (cost=0.65 rows=1)
                    -> Filter: (t1.b = 2)  (cost=0.55 rows=1)
                        -> Table scan on t1  (cost=0.55 rows=3)

DROP TABLE t1;
set @@optimizer_switch=@old_opt_switch;
set @old_opt_switch=@@optimizer_switch;
set optimizer_switch='firstmatch=off,materialization=off,loosescan=off';
CREATE TABLE t1 ( i INTEGER );
CREATE TABLE t2 ( i INTEGER );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (2);
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE (t1.i) IN (SELECT t2.i FROM t2);
EXPLAIN
-> Remove duplicate t1 rows using temporary table (weedout)  (cost=0.9 rows=1)
    -> Nested loop inner join  (cost=0.9 rows=1)
        -> Table scan on t2  (cost=0.35 rows=1)
        -> Filter: (t1.i = t2.i)  (cost=0.35 rows=1)
            -> Table scan on t1  (cost=0.35 rows=3)

DROP TABLE t1;
DROP TABLE t2;
set @@optimizer_switch=@old_opt_switch;
set @old_opt_switch=@@optimizer_switch;
set optimizer_switch='firstmatch=off,materialization=off,loosescan=off';
CREATE TABLE t1 ( i INTEGER );
CREATE TABLE t2 ( i INTEGER );
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1), (2), (3), (4);
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE (t1.i) IN (SELECT t2.i FROM t2);
EXPLAIN
-> Nested loop inner join  (cost=2.5 rows=3)
    -> Table scan on t1  (cost=0.55 rows=3)
    -> Limit: 1 row(s)  (cost=0.283 rows=1)
        -> Filter: (t2.i = t1.i)  (cost=0.283 rows=1)
            -> Table scan on t2  (cost=0.283 rows=4)

DROP TABLE t1;
DROP TABLE t2;
set @@optimizer_switch=@old_opt_switch;
set @old_opt_switch=@@optimizer_switch;
set optimizer_switch='firstmatch=off,materialization=off,duplicateweedout=off,loosescan=on';
CREATE TABLE t1 ( i INTEGER, PRIMARY KEY (i) );
CREATE TABLE t2 ( i INTEGER, INDEX i1 (i) );
INSERT INTO t1 VALUES (2), (3), (4), (5);
INSERT INTO t2 VALUES (1), (2), (3), (4);
ANALYZE TABLE t1, t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN format=tree SELECT * FROM t1 WHERE t1.i IN (SELECT t2.i FROM t2);
EXPLAIN
-> Nested loop inner join  (cost=2.05 rows=4)
    -> Remove duplicates from input sorted on i1  (cost=0.651 rows=4)
        -> Filter: (t2.i is not null)  (cost=0.651 rows=4)
            -> Index scan on t2 using i1  (cost=0.651 rows=4)
    -> Single-row covering index lookup on t1 using PRIMARY (i=t2.i)  (cost=1.1 rows=1)

DROP TABLE t1;
DROP TABLE t2;
set @@optimizer_switch=@old_opt_switch;
#
# Bug#29904996 EXPLAIN FORMAT=TREE PRINTS OUT HIDDEN COLUMN NAME INSTEAD
#              OF INDEXED EXPRESSION
#
CREATE TABLE t1 (
col_int_key INTEGER,
col_json JSON,
KEY mv_idx ((CAST(col_json->'$[*]' AS CHAR(40) ARRAY)))
);
CREATE TABLE t2 (col_int INTEGER);
# See that we print the indexed expression, and not the hidden column
# name.
EXPLAIN FORMAT=tree SELECT /*+ NO_BNL(t1, t2) */ * FROM t2
JOIN t1 ON 1 WHERE (CAST("1" AS JSON) MEMBER OF( t1.col_json->'$[*]'));
EXPLAIN
-> Nested loop inner join  (cost=0.7 rows=1)
    -> Table scan on t2  (cost=0.35 rows=1)
    -> Filter: json'"1"' member of (cast(json_extract(col_json,_utf8mb4'$[*]') as char(40) array))  (cost=0.35 rows=1)
        -> Index lookup on t1 using mv_idx (cast(json_extract(col_json,_utf8mb4'$[*]') as char(40) array)=json'"1"')  (cost=0.35 rows=1)

DROP TABLE t1, t2;
CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY ( a ));
INSERT INTO t1 VALUES (1,3), (2,4), (3,5);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN ANALYZE SELECT * FROM t1 AS a JOIN t1 AS b ON a.a=b.b ORDER BY a.b+b.a LIMIT 3;
EXPLAIN
-> Limit: 3 row(s)  (actual rows=1 loops=1)
    -> Sort: `(a.b + b.a)`, limit input to 3 row(s) per chunk  (actual rows=1 loops=1)
        -> Stream results  (cost=1.6 rows=3) (actual rows=1 loops=1)
            -> Nested loop inner join  (cost=1.6 rows=3) (actual rows=1 loops=1)
                -> Filter: (b.b is not null)  (cost=0.55 rows=3) (actual rows=3 loops=1)
                    -> Table scan on b  (cost=0.55 rows=3) (actual rows=3 loops=1)
                -> Single-row index lookup on a using PRIMARY (a=b.b)  (cost=0.283 rows=1) (actual rows=0.333 loops=3)

EXPLAIN ANALYZE SELECT * FROM t1 AS a, t1 AS b WHERE a.b=500;
EXPLAIN
-> Nested loop inner join  (cost=1.1 rows=3) (actual rows=0 loops=1)
    -> Filter: (a.b = 500)  (cost=0.55 rows=1) (actual rows=0 loops=1)
        -> Table scan on a  (cost=0.55 rows=3) (actual rows=3 loops=1)
    -> Table scan on b  (cost=0.55 rows=3) (never executed)

DROP TABLE t1;
EXPLAIN ANALYZE FOR CONNECTION 1;
ERROR 42000: This version of MySQL doesn't yet support 'EXPLAIN ANALYZE FOR CONNECTION'
EXPLAIN ANALYZE FORMAT=TRADITIONAL SELECT 1;
ERROR 42000: This version of MySQL doesn't yet support 'EXPLAIN ANALYZE with TRADITIONAL format'
EXPLAIN ANALYZE FORMAT=JSON SELECT 1;
ERROR 42000: This version of MySQL doesn't yet support 'EXPLAIN ANALYZE with JSON format'
EXPLAIN ANALYZE FORMAT=TREE SELECT 1;
EXPLAIN
-> Rows fetched before execution  (cost=0..0 rows=1) (actual rows=1 loops=1)

EXPLAIN FORMAT=tree SELECT * FROM INFORMATION_SCHEMA.ENGINES;
EXPLAIN
-> Table scan on ENGINES  (cost=2.73 rows=2)
    -> Fill information schema table ENGINES

CREATE TABLE t1 ( f1 INT PRIMARY KEY );
INSERT INTO t1 VALUES (1), (2), (3);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t1, ( SELECT f1 FROM t1 UNION SELECT f1 + 10 FROM t1 ) d1;
EXPLAIN
-> Nested loop inner join  (cost=10.1 rows=18)
    -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
    -> Table scan on d1  (cost=2.13..4.28 rows=6)
        -> Union materialize with deduplication  (cost=1.7..1.7 rows=6)
            -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
            -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)

EXPLAIN FORMAT=tree SELECT * FROM t1, ( SELECT f1 FROM t1 UNION ALL SELECT f1 + 10 FROM t1 ) d1;
EXPLAIN
-> Nested loop inner join  (cost=10.1 rows=18)
    -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
    -> Table scan on d1  (cost=2.13..4.28 rows=6)
        -> Union all materialize  (cost=1.7..1.7 rows=6)
            -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)
            -> Index scan on t1 using PRIMARY  (cost=0.55 rows=3)

DROP TABLE t1;
#
# Bug #30444266: EXPLAIN ANALYZE DOES NOT EXECUTE THE SUBQUERIES IN THE SELECT LIST
#
CREATE TABLE t1 ( f1 INTEGER );
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN ANALYZE SELECT f1, ( SELECT COUNT(*) FROM t1 AS inner_t1 WHERE inner_t1.f1 < t1.f1 ) FROM t1;
EXPLAIN
-> Table scan on t1  (cost=1.25 rows=10) (actual rows=10 loops=1)
-> Select #2 (subquery in projection; dependent)
    -> Aggregate: count(0)  (cost=0.917 rows=1) (actual rows=1 loops=10)
        -> Filter: (inner_t1.f1 < t1.f1)  (cost=0.583 rows=3.33) (actual rows=4.5 loops=10)
            -> Table scan on inner_t1  (cost=0.583 rows=10) (actual rows=10 loops=10)

Warnings:
Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
DROP TABLE t1;
#
# Bug#17978975 EXPLAIN FOR MULTI-TABLE UPDATE/DELETE DOES NOT MENTION TEMPORARY TABLE
#
CREATE TABLE t1(a INT, b INT);
CREATE TABLE t2(a INT, b INT);
ANALYZE TABLE t1,t2;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
test.t2	analyze	status	OK
EXPLAIN FORMAT=TREE UPDATE t1,t2 SET t1.a=1,t2.b=1;
EXPLAIN
-> Update t1 (immediate), t2 (buffered)
    -> Nested loop inner join  (cost=0.7 rows=1)
        -> Table scan on t1  (cost=0.35 rows=1)
        -> Table scan on t2  (cost=0.35 rows=1)

EXPLAIN FORMAT=TREE UPDATE t1,t2 SET t1.a=1,t2.b=1 WHERE t2.a=t1.a;
EXPLAIN
-> Update t1 (buffered), t2 (buffered)
    -> Nested loop inner join  (cost=0.7 rows=1)
        -> Table scan on t1  (cost=0.35 rows=1)
        -> Filter: (t2.a = t1.a)  (cost=0.35 rows=1)
            -> Table scan on t2  (cost=0.35 rows=1)

EXPLAIN FORMAT=TREE DELETE t1.*,t2.* FROM t1,t2;
EXPLAIN
-> Delete from t1 (immediate), t2 (buffered)  (cost=0.8 rows=1)
    -> Nested loop inner join  (cost=0.7 rows=1)
        -> Table scan on t1  (cost=0.35 rows=1)
        -> Table scan on t2  (cost=0.35 rows=1)

EXPLAIN FORMAT=TREE DELETE t1.*,t1bis.* FROM t1, t1 AS t1bis;
EXPLAIN
-> Delete from t1 (buffered), t1bis (buffered)  (cost=0.9 rows=1)
    -> Nested loop inner join  (cost=0.7 rows=1)
        -> Table scan on t1  (cost=0.35 rows=1)
        -> Table scan on t1bis  (cost=0.35 rows=1)

DROP TABLE t1,t2;
#
# Bug #30941336: EXPLAIN ANAYLZE SELECT COUNT(*) FROM MYSQL.USER COREDUMP UNDER DEBUG VERSION
#
CREATE TABLE t1 ( a INTEGER );
EXPLAIN ANALYZE SELECT COUNT(*) FROM t1;
EXPLAIN
-> Count rows in t1  (actual rows=1 loops=1)

DROP TABLE t1;
#
# Bug #31559245: REGRESSION: CRASH/ASSERT IN SUBSELECT_HASH_SJ_ENGINE::ROOT_ACCESS_PATH
#
CREATE TABLE t1 (a INTEGER);
EXPLAIN FORMAT=tree SELECT (1 IN (SELECT 1 FROM t1)) WHERE FALSE;
EXPLAIN
-> Zero rows (Impossible WHERE)  (cost=0..0 rows=0)

DROP TABLE t1;
#
# Bug #32688540: MATERIALIZE ITERATORS HAVE SKEWED TIMINGS FROM SKIPPED MATERIALIZATIONS
#
CREATE TABLE t1 (a INTEGER);
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN ANALYZE SELECT * FROM t1 LEFT JOIN ( SELECT * FROM t1 ORDER BY t1.a LIMIT 3 ) d1 ON TRUE;
EXPLAIN
-> Nested loop left join  (cost=14.9 rows=15) (actual rows=15 loops=1)
    -> Table scan on t1  (cost=0.75 rows=5) (actual rows=5 loops=1)
    -> Table scan on d1  (cost=1.57..2.6 rows=3) (actual rows=3 loops=5)
        -> Materialize  (cost=1.05..1.05 rows=3) (actual rows=3 loops=1)
            -> Limit: 3 row(s)  (cost=0.75 rows=3) (actual rows=3 loops=1)
                -> Sort: t1.a, limit input to 3 row(s) per chunk  (cost=0.75 rows=5) (actual rows=3 loops=1)
                    -> Table scan on t1  (cost=0.75 rows=5) (actual rows=5 loops=1)

DROP TABLE t1;
#
# Bug #32915233: RECENT REGRESSION:ASSERTION `EXPLAIN.CHILDREN.SIZE() <= 1' FAILED.
#
CREATE TABLE t1 (a int);
SET sql_mode='';
EXPLAIN FORMAT=tree SELECT a IN (SELECT a FROM (table t1) AS d) FROM t1 GROUP BY (@b:=5);
EXPLAIN
-> Group (no aggregates)  (cost=0.45 rows=1)
    -> Table scan on t1  (cost=0.35 rows=1)
-> Select #2 (subquery in projection; dependent)
    -> Limit: 1 row(s)  (cost=1.95..1.95 rows=1)
        -> Filter: <if>(outer_field_is_not_null, <is_not_null_test>(d.a), true)  (cost=1.95..1.95 rows=1)
            -> Filter: <if>(outer_field_is_not_null, ((<cache>(t1.a) = d.a) or (d.a is null)), true)  (cost=1.95..1.95 rows=1)
                -> Alternative plans for IN subquery: Index lookup unless a IS NULL  (cost=0.8..1.85 rows=4)
                    -> Covering index lookup on d using <auto_key0> (a=<cache>(t1.a) or NULL)  (cost=1.4 rows=4)
                        -> Materialize  (cost=0.45..0.45 rows=1)
                            -> Table scan on t1  (cost=0.35 rows=1)
                    -> Table scan on d  (cost=2.52 rows=2)

Warnings:
Warning	1287	Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'.
SET sql_mode=DEFAULT;
DROP TABLE t1;
#
# Bug #33030136: EXPLAIN: ASSERTION `CURRENT_THD->LEX->USING_HYPERGRAPH_OPTIMIZER' FAILED.
#
CREATE TABLE t1 (a INTEGER);
EXPLAIN FORMAT=tree
(SELECT 1 FROM t1)
UNION ALL
SELECT 1 IN (SELECT 1 FROM t1) FROM t1 WHERE 1=2;
EXPLAIN
-> Append  (cost=0.35 rows=1)
    -> Stream results  (cost=0.35 rows=1)
        -> Table scan on t1  (cost=0.35 rows=1)
    -> Stream results  (cost=0..0 rows=0)
        -> Zero rows (Impossible WHERE)  (cost=0..0 rows=0)

DROP TABLE t1;
CREATE TABLE t1 (pk INTEGER NOT NULL, a INTEGER, b INTEGER, KEY (a), KEY (b), PRIMARY KEY (pk));
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree
SELECT * FROM t1 WHERE a IN (2,4,6,8,10);
EXPLAIN
-> Index range scan on t1 using a over (a = 2) OR (a = 4) OR (3 more), with index condition: (t1.a in (2,4,6,8,10))  (cost=2.07 rows=5)

EXPLAIN FORMAT=tree
SELECT * FROM t1 WHERE a IN (2,4,6,8,10) ORDER BY a DESC;
EXPLAIN
-> Index range scan on t1 using a over (a = 2) OR (a = 4) OR (3 more) (reverse), with index condition: (t1.a in (2,4,6,8,10))  (cost=2.07 rows=5)

EXPLAIN ANALYZE
SELECT /*+ INDEX_MERGE(t1) */ * FROM t1 WHERE pk > 1 OR a > 2 OR b > 3;
EXPLAIN
-> Filter: ((t1.pk > 1) or (t1.a > 2) or (t1.b > 3))  (cost=1.97 rows=1) (actual rows=0 loops=1)
    -> Sort-deduplicate by row ID  (cost=1.97 rows=1) (actual rows=0 loops=1)
        -> Clustered primary key (scanned separately)
            -> Index range scan on t1 using PRIMARY over (1 < pk)  (cost=0.36 rows=1) (actual rows=0 loops=1)
        -> Index range scan on t1 using a over (2 < a)  (cost=0.36 rows=1) (actual rows=0 loops=1)
        -> Index range scan on t1 using b over (3 < b)  (cost=0.36 rows=1) (actual rows=0 loops=1)

DROP TABLE t1;
CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER, d INTEGER, e INTEGER, KEY idx1 (a,b,c,d,e));
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN FORMAT=tree
SELECT /*+ SKIP_SCAN(t1) */ * FROM t1 WHERE a IN (2,4,6,8,10) AND b=5 AND e BETWEEN 100 AND 200;
EXPLAIN
-> Filter: ((t1.b = 5) and (t1.a in (2,4,6,8,10)) and (t1.e between 100 and 200))  (cost=1.5 rows=5)
    -> Covering index skip scan on t1 using idx1 over a IN (2, 4, (3 more)), b = 5, 100 <= e <= 200  (cost=1.5 rows=5)

DROP TABLE t1;
#
# Bug#33343948: Multi-valued index ranges are printed as binary
#
CREATE TABLE t(a VARCHAR(10) COLLATE utf8mb4_0900_bin, KEY (a));
INSERT INTO t VALUES ('abc'), ('def'), ('ghi');
ANALYZE TABLE t;
Table	Op	Msg_type	Msg_text
test.t	analyze	status	OK
EXPLAIN FORMAT=tree SELECT * FROM t WHERE a > 'abc' AND a < 'ghi';
EXPLAIN
-> Filter: ((t.a > 'abc') and (t.a < 'ghi'))  (cost=0.46 rows=1)
    -> Covering index range scan on t using a over ('abc' < a < 'ghi')  (cost=0.46 rows=1)

EXPLAIN FORMAT=tree
SELECT * FROM t WHERE a > 'abc''def' AND a < CONCAT('z', UNHEX('090A1A5C0D'));
EXPLAIN
-> Filter: ((t.a > 'abc\'def') and (t.a < <cache>(concat('z',unhex('090A1A5C0D')))))  (cost=0.661 rows=2)
    -> Covering index range scan on t using a over ('abc\'def' < a < 'z	\n\Z\\\r')  (cost=0.661 rows=2)

DROP TABLE t;
#
# Bug#33364732: Preliminary fixes for WL#14673
#
CREATE TABLE t(x INTEGER);
INSERT INTO t VALUES (1), (2), (3);
ANALYZE TABLE t;
Table	Op	Msg_type	Msg_text
test.t	analyze	status	OK
EXPLAIN FORMAT=TREE DELETE t FROM t WHERE 0=1;
EXPLAIN
-> Delete from t (buffered)  (cost=0..0 rows=0)
    -> Zero rows (Impossible WHERE)  (cost=0..0 rows=0)

EXPLAIN ANALYZE DELETE t1 FROM t t1, t t2 WHERE t1.x = t2.x + 1;
EXPLAIN
-> Delete from t1 (buffered)  (cost=3.1 rows=9) (actual rows=0 loops=1)
    -> Nested loop inner join  (cost=2.2 rows=9) (actual rows=2 loops=1)
        -> Table scan on t1  (cost=0.55 rows=3) (actual rows=3 loops=1)
        -> Filter: (t1.x = (t2.x + 1))  (cost=0.35 rows=3) (actual rows=0.667 loops=3)
            -> Table scan on t2  (cost=0.35 rows=3) (actual rows=3 loops=3)

SELECT * FROM t;
x
1
2
3
DROP TABLE t;
#
# WL#14672: Enable the hypergraph optimizer for UPDATE
#
CREATE TABLE t(x INTEGER, y INTEGER);
INSERT INTO t VALUES (1, 2), (2, 3), (3, 4);
ANALYZE TABLE t;
Table	Op	Msg_type	Msg_text
test.t	analyze	status	OK
EXPLAIN ANALYZE UPDATE t t1, t t2 SET t1.x = t2.y WHERE t1.x = t2.x;
EXPLAIN
-> Update t1 (buffered)  (actual rows=0 loops=1)
    -> Nested loop inner join  (cost=2.2 rows=3) (actual rows=3 loops=1)
        -> Table scan on t1  (cost=0.55 rows=3) (actual rows=3 loops=1)
        -> Filter: (t2.x = t1.x)  (cost=0.283 rows=1) (actual rows=1 loops=3)
            -> Table scan on t2  (cost=0.283 rows=3) (actual rows=3 loops=3)

SELECT * FROM t;
x	y
1	2
2	3
3	4
DROP TABLE t;
#
# Bug#33905399 Missing profiling data for CTE
#
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
INSERT INTO t1 VALUES (1,1);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN ANALYZE
WITH tx AS (SELECT FLOOR(5*RAND(0)) i1 FROM t1 j1 JOIN t1 j2 ON j1.b=j2.a)
(SELECT 1 FROM t1 d1 JOIN t1 d2 ON d1.a=10*d2.a JOIN tx ON d2.b=i1) UNION
SELECT 2 FROM tx;
EXPLAIN
-> Table scan on <union temporary>  (cost=5.86..7.55 rows=3) (actual rows=1 loops=1)
    -> Union materialize with deduplication  (cost=5.01..5.01 rows=3) (actual rows=1 loops=1)
        -> Nested loop inner join  (cost=1.4 rows=2) (actual rows=0 loops=1)
            -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=0 loops=1)
                -> Filter: (d2.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Table scan on d2  (cost=0.35 rows=1) (actual rows=1 loops=1)
                -> Filter: (d1.a = (10 * d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
                    -> Single-row covering index lookup on d1 using PRIMARY (a=(10 * d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
            -> Filter: (d2.b = tx.i1)  (cost=0.75..0.7 rows=2) (never executed)
                -> Covering index lookup on tx using <auto_key0> (i1=d2.b)  (cost=1.15..1.5 rows=2) (never executed)
                    -> Materialize CTE tx if needed (query plan printed elsewhere)  (cost=0.8..0.8 rows=1) (never executed)
        -> Table scan on tx  (cost=3.31..3.31 rows=1) (actual rows=1 loops=1)
            -> Materialize CTE tx if needed  (cost=0.8..0.8 rows=1) (actual rows=1 loops=1)
                -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=1 loops=1)
                    -> Filter: (j1.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                        -> Table scan on j1  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Single-row covering index lookup on j2 using PRIMARY (a=j1.b)  (cost=0.35 rows=1) (actual rows=1 loops=1)

EXPLAIN FORMAT=TREE
WITH tx AS (SELECT FLOOR(5*RAND(0)) i1 FROM t1 j1 JOIN t1 j2 ON j1.b=j2.a)
(SELECT 1 FROM t1 d1 JOIN t1 d2 ON d1.a=-d2.a JOIN tx ON d2.b=i1) UNION
SELECT 2 FROM tx;
EXPLAIN
-> Table scan on <union temporary>  (cost=5.86..7.55 rows=3)
    -> Union materialize with deduplication  (cost=5.01..5.01 rows=3)
        -> Nested loop inner join  (cost=1.4 rows=2)
            -> Nested loop inner join  (cost=0.7 rows=1)
                -> Filter: (d2.b is not null)  (cost=0.35 rows=1)
                    -> Table scan on d2  (cost=0.35 rows=1)
                -> Filter: (d1.a = -(d2.a))  (cost=0.35 rows=1)
                    -> Single-row covering index lookup on d1 using PRIMARY (a=-(d2.a))  (cost=0.35 rows=1)
            -> Filter: (d2.b = tx.i1)  (cost=0.75..0.7 rows=2)
                -> Covering index lookup on tx using <auto_key0> (i1=d2.b)  (cost=1.15..1.5 rows=2)
                    -> Materialize CTE tx if needed  (cost=0.8..0.8 rows=1)
                        -> Nested loop inner join  (cost=0.7 rows=1)
                            -> Filter: (j1.b is not null)  (cost=0.35 rows=1)
                                -> Table scan on j1  (cost=0.35 rows=1)
                            -> Single-row covering index lookup on j2 using PRIMARY (a=j1.b)  (cost=0.35 rows=1)
        -> Table scan on tx  (cost=3.31..3.31 rows=1)
            -> Materialize CTE tx if needed (query plan printed elsewhere)  (cost=0.8..0.8 rows=1)

EXPLAIN ANALYZE
WITH tx AS (SELECT FLOOR(5*RAND(0)) i1 FROM t1 j1 JOIN t1 j2 ON j1.b=j2.a)
SELECT 2 FROM tx UNION
(SELECT 1 FROM t1 d1 JOIN t1 d2 ON d1.a=-d2.a JOIN tx ON d2.b=i1);
EXPLAIN
-> Table scan on <union temporary>  (cost=5.86..7.55 rows=3) (actual rows=1 loops=1)
    -> Union materialize with deduplication  (cost=5.01..5.01 rows=3) (actual rows=1 loops=1)
        -> Table scan on tx  (cost=3.31..3.31 rows=1) (actual rows=1 loops=1)
            -> Materialize CTE tx if needed  (cost=0.8..0.8 rows=1) (actual rows=1 loops=1)
                -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=1 loops=1)
                    -> Filter: (j1.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                        -> Table scan on j1  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Single-row covering index lookup on j2 using PRIMARY (a=j1.b)  (cost=0.35 rows=1) (actual rows=1 loops=1)
        -> Nested loop inner join  (cost=1.4 rows=2) (actual rows=0 loops=1)
            -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=0 loops=1)
                -> Filter: (d2.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Table scan on d2  (cost=0.35 rows=1) (actual rows=1 loops=1)
                -> Filter: (d1.a = -(d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
                    -> Single-row covering index lookup on d1 using PRIMARY (a=-(d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
            -> Filter: (d2.b = tx.i1)  (cost=0.75..0.7 rows=2) (never executed)
                -> Covering index lookup on tx using <auto_key0> (i1=d2.b)  (cost=1.15..1.5 rows=2) (never executed)
                    -> Materialize CTE tx if needed (query plan printed elsewhere)  (cost=0.8..0.8 rows=1) (never executed)

EXPLAIN ANALYZE
WITH tx AS (SELECT FLOOR(5*RAND(0)) i1 FROM t1 j1 JOIN t1 j2 ON j1.b=j2.a)
SELECT 2 FROM tx UNION
(SELECT 1 FROM t1 d1 JOIN t1 d2 ON d1.a=d2.a JOIN tx ON d2.b=i1);
EXPLAIN
-> Table scan on <union temporary>  (cost=5.86..7.55 rows=3) (actual rows=1 loops=1)
    -> Union materialize with deduplication  (cost=5.01..5.01 rows=3) (actual rows=1 loops=1)
        -> Table scan on tx  (cost=3.31..3.31 rows=1) (actual rows=1 loops=1)
            -> Materialize CTE tx if needed  (cost=0.8..0.8 rows=1) (actual rows=1 loops=1)
                -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=1 loops=1)
                    -> Filter: (j1.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                        -> Table scan on j1  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Single-row covering index lookup on j2 using PRIMARY (a=j1.b)  (cost=0.35 rows=1) (actual rows=1 loops=1)
        -> Nested loop inner join  (cost=1.4 rows=2) (actual rows=0 loops=1)
            -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=1 loops=1)
                -> Covering index scan on d1 using PRIMARY  (cost=0.35 rows=1) (actual rows=1 loops=1)
                -> Filter: (d2.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Single-row index lookup on d2 using PRIMARY (a=d1.a)  (cost=0.35 rows=1) (actual rows=1 loops=1)
            -> Filter: (d2.b = tx.i1)  (cost=0.75..0.7 rows=2) (actual rows=0 loops=1)
                -> Covering index lookup on tx using <auto_key0> (i1=d2.b)  (cost=1.15..1.5 rows=2) (actual rows=0 loops=1)
                    -> Materialize CTE tx if needed (query plan printed elsewhere)  (cost=0.8..0.8 rows=1) (never executed)

EXPLAIN ANALYZE
WITH tx AS (SELECT FLOOR(5*RAND(0)) i1 FROM t1 j1 JOIN t1 j2 ON j1.b=j2.a)
(SELECT 1 FROM t1 d1 JOIN t1 d2 ON d1.a=10*d2.a JOIN tx ON d2.b=i1) UNION
(SELECT 1 FROM t1 d1 JOIN t1 d2 ON d1.a=-d2.a JOIN tx ON d2.b=i1);
EXPLAIN
-> Table scan on <union temporary>  (cost=3.84..5.75 rows=4) (actual rows=0 loops=1)
    -> Union materialize with deduplication  (cost=3.2..3.2 rows=4) (actual rows=0 loops=1)
        -> Nested loop inner join  (cost=1.4 rows=2) (actual rows=0 loops=1)
            -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=0 loops=1)
                -> Filter: (d2.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Table scan on d2  (cost=0.35 rows=1) (actual rows=1 loops=1)
                -> Filter: (d1.a = (10 * d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
                    -> Single-row covering index lookup on d1 using PRIMARY (a=(10 * d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
            -> Filter: (d2.b = tx.i1)  (cost=0.75..0.7 rows=2) (never executed)
                -> Covering index lookup on tx using <auto_key0> (i1=d2.b)  (cost=1.15..1.5 rows=2) (never executed)
                    -> Materialize CTE tx if needed  (cost=0.8..0.8 rows=1) (never executed)
                        -> Nested loop inner join  (cost=0.7 rows=1) (never executed)
                            -> Filter: (j1.b is not null)  (cost=0.35 rows=1) (never executed)
                                -> Table scan on j1  (cost=0.35 rows=1) (never executed)
                            -> Single-row covering index lookup on j2 using PRIMARY (a=j1.b)  (cost=0.35 rows=1) (never executed)
        -> Nested loop inner join  (cost=1.4 rows=2) (actual rows=0 loops=1)
            -> Nested loop inner join  (cost=0.7 rows=1) (actual rows=0 loops=1)
                -> Filter: (d2.b is not null)  (cost=0.35 rows=1) (actual rows=1 loops=1)
                    -> Table scan on d2  (cost=0.35 rows=1) (actual rows=1 loops=1)
                -> Filter: (d1.a = -(d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
                    -> Single-row covering index lookup on d1 using PRIMARY (a=-(d2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
            -> Filter: (d2.b = tx.i1)  (cost=0.75..0.7 rows=2) (never executed)
                -> Covering index lookup on tx using <auto_key0> (i1=d2.b)  (cost=1.15..1.5 rows=2) (never executed)
                    -> Materialize CTE tx if needed (query plan printed elsewhere)  (cost=0.8..0.8 rows=1) (never executed)

EXPLAIN ANALYZE
WITH x1 AS (SELECT MAX(a) AS m1 FROM t1 GROUP BY b)
SELECT * FROM x1 y1 WHERE y1.m1 = (SELECT MAX(m1) FROM x1);
EXPLAIN
-> Filter: (y1.m1 = (select #3))  (cost=0.35..0.35 rows=1) (actual rows=1 loops=1)
    -> Covering index lookup on y1 using <auto_key0> (m1=(select #3))  (cost=0.35..0.35 rows=1) (actual rows=1 loops=1)
        -> Materialize CTE x1 if needed (query plan printed elsewhere)  (cost=0..0 rows=0) (never executed)
    -> Select #3 (subquery in condition; run only once)
        -> Aggregate: max(x1.m1)  (cost=2.5..2.5 rows=1) (actual rows=1 loops=1)
            -> Table scan on x1  (cost=2.5..2.5 rows=0) (actual rows=1 loops=1)
                -> Materialize CTE x1 if needed  (cost=0..0 rows=0) (actual rows=1 loops=1)
                    -> Table scan on <temporary>  (actual rows=1 loops=1)
                        -> Aggregate using temporary table  (actual rows=1 loops=1)
                            -> Table scan on t1  (cost=0.35 rows=1) (actual rows=1 loops=1)

#
#  Bug#34051681 mysqld asan crash at ExplainMaterializeAccessPath
#
EXPLAIN ANALYZE
WITH x1 AS (SELECT MAX(a) AS m1 FROM t1 GROUP BY b)
SELECT * FROM t1 y1 LEFT JOIN t1 y2 ON y1.a=-y2.a
WHERE y1.b+y2.b = (SELECT MAX(m1) FROM x1);
EXPLAIN
-> Nested loop inner join  (cost=0.7 rows=1) (actual rows=0 loops=1)
    -> Table scan on y2  (cost=0.35 rows=1) (actual rows=1 loops=1)
    -> Filter: (((y1.b + y2.b) = (select #2)) and (y1.a = -(y2.a)))  (cost=0.35 rows=1) (actual rows=0 loops=1)
        -> Single-row index lookup on y1 using PRIMARY (a=-(y2.a))  (cost=0.35 rows=1) (actual rows=0 loops=1)
        -> Select #2 (subquery in condition; run only once)
            -> Aggregate: max(x1.m1)  (cost=2.5..2.5 rows=1) (never executed)
                -> Table scan on x1  (cost=2.5..2.5 rows=0) (never executed)
                    -> Materialize CTE x1  (cost=0..0 rows=0) (never executed)
                        -> Table scan on <temporary>  (never executed)
                            -> Aggregate using temporary table  (never executed)
                                -> Table scan on t1  (cost=0.35 rows=1) (never executed)

DROP TABLE t1;
#
# Bug #34135465 	EXPLAIN ANALYZE: 'Aggregate using temporary table'
# shows wrong number of rows
#
CREATE TABLE t1(i INT, j INT);
INSERT INTO t1 VALUES (0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2);
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
EXPLAIN ANALYZE INSERT INTO t1 SELECT 4, SUM(i) k1 FROM t1 GROUP BY j LIMIT 2;
EXPLAIN
-> Insert into t1
    -> Limit: 2 row(s)  (actual rows=2 loops=1)
        -> Table scan on <temporary>  (actual rows=2 loops=1)
            -> Aggregate using temporary table  (actual rows=3 loops=1)
                -> Table scan on t1  (cost=1.15 rows=9) (actual rows=9 loops=1)

EXPLAIN ANALYZE WITH cte AS (SELECT SUM(i) k1 FROM t1 GROUP BY j)
SELECT * FROM cte LIMIT 2;
EXPLAIN
-> Limit: 2 row(s)  (cost=0..0 rows=0) (actual rows=2 loops=1)
    -> Table scan on cte  (cost=2.5..2.5 rows=0) (actual rows=2 loops=1)
        -> Materialize CTE cte  (cost=0..0 rows=0) (actual rows=3 loops=1)
            -> Table scan on <temporary>  (actual rows=3 loops=1)
                -> Aggregate using temporary table  (actual rows=3 loops=1)
                    -> Table scan on t1  (cost=1.15 rows=9) (actual rows=9 loops=1)

DROP TABLE t1;