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
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
|
drop table if exists t1,t2,t3;
drop view if exists v1,v2;
SET @save_optimizer_switch=@@optimizer_switch;
SET optimizer_switch='outer_join_with_cache=off';
CREATE TABLE t1 (S1 INT);
CREATE TABLE t2 (S1 INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (2);
SELECT * FROM t1 JOIN t2;
S1 S1
1 2
SELECT * FROM t1 INNER JOIN t2;
S1 S1
1 2
SELECT * from t1 JOIN t2 USING (S1);
S1
SELECT * FROM t1 INNER JOIN t2 USING (S1);
S1
SELECT * from t1 CROSS JOIN t2;
S1 S1
1 2
SELECT * from t1 LEFT JOIN t2 USING(S1);
S1
1
SELECT * from t1 LEFT JOIN t2 ON(t2.S1=2);
S1 S1
1 2
SELECT * from t1 RIGHT JOIN t2 USING(S1);
S1
2
SELECT * from t1 RIGHT JOIN t2 ON(t1.S1=1);
S1 S1
1 2
drop table t1,t2;
create table t1 (id int primary key);
create table t2 (id int);
insert into t1 values (75);
insert into t1 values (79);
insert into t1 values (78);
insert into t1 values (77);
replace into t1 values (76);
replace into t1 values (76);
insert into t1 values (104);
insert into t1 values (103);
insert into t1 values (102);
insert into t1 values (101);
insert into t1 values (105);
insert into t1 values (106);
insert into t1 values (107);
insert into t2 values (107),(75),(1000);
select t1.id, t2.id from t1, t2 where t2.id = t1.id;
id id
107 107
75 75
select t1.id, count(t2.id) from t1,t2 where t2.id = t1.id group by t1.id;
id count(t2.id)
75 1
107 1
select t1.id, count(t2.id) from t1,t2 where t2.id = t1.id group by t2.id;
id count(t2.id)
75 1
107 1
select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
id id
NULL 75
explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY NULL NULL NULL 1 Impossible ON condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where
explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
drop table t1,t2;
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
token varchar(100) DEFAULT '' NOT NULL,
count int(11) DEFAULT '0' NOT NULL,
qty int(11),
phone char(1) DEFAULT '' NOT NULL,
timestamp datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
PRIMARY KEY (id),
KEY token (token(15)),
KEY timestamp (timestamp),
UNIQUE token_2 (token(75),count,phone)
);
INSERT INTO t1 VALUES (21,'e45703b64de71482360de8fec94c3ade',3,7800,'n','1999-12-23 17:22:21');
INSERT INTO t1 VALUES (22,'e45703b64de71482360de8fec94c3ade',4,5000,'y','1999-12-23 17:22:21');
INSERT INTO t1 VALUES (18,'346d1cb63c89285b2351f0ca4de40eda',3,13200,'b','1999-12-23 11:58:04');
INSERT INTO t1 VALUES (17,'ca6ddeb689e1b48a04146b1b5b6f936a',4,15000,'b','1999-12-23 11:36:53');
INSERT INTO t1 VALUES (16,'ca6ddeb689e1b48a04146b1b5b6f936a',3,13200,'b','1999-12-23 11:36:53');
INSERT INTO t1 VALUES (26,'a71250b7ed780f6ef3185bfffe027983',5,1500,'b','1999-12-27 09:44:24');
INSERT INTO t1 VALUES (24,'4d75906f3c37ecff478a1eb56637aa09',3,5400,'y','1999-12-23 17:29:12');
INSERT INTO t1 VALUES (25,'4d75906f3c37ecff478a1eb56637aa09',4,6500,'y','1999-12-23 17:29:12');
INSERT INTO t1 VALUES (27,'a71250b7ed780f6ef3185bfffe027983',3,6200,'b','1999-12-27 09:44:24');
INSERT INTO t1 VALUES (28,'a71250b7ed780f6ef3185bfffe027983',3,5400,'y','1999-12-27 09:44:36');
INSERT INTO t1 VALUES (29,'a71250b7ed780f6ef3185bfffe027983',4,17700,'b','1999-12-27 09:45:05');
CREATE TABLE t2 (
id int(11) NOT NULL auto_increment,
category int(11) DEFAULT '0' NOT NULL,
county int(11) DEFAULT '0' NOT NULL,
state int(11) DEFAULT '0' NOT NULL,
phones int(11) DEFAULT '0' NOT NULL,
nophones int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (id),
KEY category (category,county,state)
);
INSERT INTO t2 VALUES (3,2,11,12,5400,7800);
INSERT INTO t2 VALUES (4,2,25,12,6500,11200);
INSERT INTO t2 VALUES (5,1,37,6,10000,12000);
select a.id, b.category as catid, b.state as stateid, b.county as countyid from t1 a, t2 b ignore index (primary) where (a.token ='a71250b7ed780f6ef3185bfffe027983') and (a.count = b.id);
id catid stateid countyid
27 2 12 11
28 2 12 11
29 2 12 25
26 1 6 37
select a.id, b.category as catid, b.state as stateid, b.county as
countyid from t1 a, t2 b where (a.token =
'a71250b7ed780f6ef3185bfffe027983') and (a.count = b.id) order by a.id;
id catid stateid countyid
26 1 6 37
27 2 12 11
28 2 12 11
29 2 12 25
drop table t1, t2;
create table t1 (a int primary key);
insert into t1 values(1),(2);
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
a
1
2
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
ERROR HY000: Too many tables; MariaDB can only use XX tables in a join
select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
a
1
2
select a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
ERROR HY000: Too many tables; MariaDB can only use XX tables in a join
drop table t1;
CREATE TABLE t1 (
a int(11) NOT NULL,
b int(11) NOT NULL,
PRIMARY KEY (a,b)
) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(2,3);
CREATE TABLE t2 (
a int(11) default NULL
) ENGINE=MyISAM;
INSERT INTO t2 VALUES (2),(3);
SELECT t1.a,t2.a,b FROM t1,t2 WHERE t1.a=t2.a AND (t1.a=1 OR t1.a=2) AND b>=1 AND b<=3;
a a b
2 2 3
DROP TABLE t1, t2;
CREATE TABLE t1 (d DATE NOT NULL);
CREATE TABLE t2 (d DATE NOT NULL);
INSERT INTO t1 (d) VALUES ('2001-08-01'),('0000-00-00');
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE t2.d IS NULL;
d
2001-08-01
0000-00-00
SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE d IS NULL;
d
0000-00-00
SELECT * from t1 WHERE t1.d IS NULL;
d
0000-00-00
SELECT * FROM t1 WHERE 1/0 IS NULL;
d
2001-08-01
0000-00-00
Warnings:
Warning 1365 Division by 0
DROP TABLE t1,t2;
CREATE TABLE t1 (
Document_ID varchar(50) NOT NULL default '',
Contractor_ID varchar(6) NOT NULL default '',
Language_ID char(3) NOT NULL default '',
Expiration_Date datetime default NULL,
Publishing_Date datetime default NULL,
Title text,
Column_ID varchar(50) NOT NULL default '',
PRIMARY KEY (Language_ID,Document_ID,Contractor_ID)
);
INSERT INTO t1 VALUES ('xep80','1','ger','2001-12-31 20:00:00','2001-11-12 10:58:00','Kartenbestellung - jetzt auch online','anle'),('','999998','',NULL,NULL,NULL,'');
CREATE TABLE t2 (
Contractor_ID char(6) NOT NULL default '',
Language_ID char(3) NOT NULL default '',
Document_ID char(50) NOT NULL default '',
CanRead char(1) default NULL,
Customer_ID int(11) NOT NULL default '0',
PRIMARY KEY (Contractor_ID,Language_ID,Document_ID,Customer_ID)
);
INSERT INTO t2 VALUES ('5','ger','xep80','1',999999),('1','ger','xep80','1',999999);
CREATE TABLE t3 (
Language_ID char(3) NOT NULL default '',
Column_ID char(50) NOT NULL default '',
Contractor_ID char(6) NOT NULL default '',
CanRead char(1) default NULL,
Active char(1) default NULL,
PRIMARY KEY (Language_ID,Column_ID,Contractor_ID)
);
INSERT INTO t3 VALUES ('ger','home','1','1','1'),('ger','Test','1','0','0'),('ger','derclu','1','0','0'),('ger','clubne','1','0','0'),('ger','philos','1','0','0'),('ger','clubko','1','0','0'),('ger','clubim','1','1','1'),('ger','progra','1','0','0'),('ger','progvo','1','0','0'),('ger','progsp','1','0','0'),('ger','progau','1','0','0'),('ger','progku','1','0','0'),('ger','progss','1','0','0'),('ger','nachl','1','0','0'),('ger','mitgli','1','0','0'),('ger','mitsu','1','0','0'),('ger','mitbus','1','0','0'),('ger','ergmar','1','1','1'),('ger','home','4','1','1'),('ger','derclu','4','1','1'),('ger','clubne','4','0','0'),('ger','philos','4','1','1'),('ger','clubko','4','1','1'),('ger','clubim','4','1','1'),('ger','progra','4','1','1'),('ger','progvo','4','1','1'),('ger','progsp','4','1','1'),('ger','progau','4','0','0'),('ger','progku','4','1','1'),('ger','progss','4','1','1'),('ger','nachl','4','1','1'),('ger','mitgli','4','0','0'),('ger','mitsu','4','0','0'),('ger','mitbus','4','0','0'),('ger','ergmar','4','1','1'),('ger','progra2','1','0','0'),('ger','archiv','4','1','1'),('ger','anmeld','4','1','1'),('ger','thema','4','1','1'),('ger','edito','4','1','1'),('ger','madis','4','1','1'),('ger','enma','4','1','1'),('ger','madis','1','1','1'),('ger','enma','1','1','1'),('ger','vorsch','4','0','0'),('ger','veranst','4','0','0'),('ger','anle','4','1','1'),('ger','redak','4','1','1'),('ger','nele','4','1','1'),('ger','aukt','4','1','1'),('ger','callcenter','4','1','1'),('ger','anle','1','0','0');
delete from t1 where Contractor_ID='999998';
insert into t1 (Contractor_ID) Values ('999998');
SELECT DISTINCT COUNT(t1.Title) FROM t1,
t2, t3 WHERE
t1.Document_ID='xep80' AND t1.Contractor_ID='1' AND
t1.Language_ID='ger' AND '2001-12-21 23:14:24' >=
Publishing_Date AND '2001-12-21 23:14:24' <= Expiration_Date AND
t1.Document_ID = t2.Document_ID AND
t1.Language_ID = t2.Language_ID AND
t1.Contractor_ID = t2.Contractor_ID AND (
t2.Customer_ID = '4' OR
t2.Customer_ID = '999999' OR
t2.Customer_ID = '1' )AND t2.CanRead
= '1' AND t1.Column_ID=t3.Column_ID AND
t1.Language_ID=t3.Language_ID AND (
t3.Contractor_ID = '4' OR
t3.Contractor_ID = '999999' OR
t3.Contractor_ID = '1') AND
t3.CanRead='1' AND t3.Active='1';
COUNT(t1.Title)
1
SELECT DISTINCT COUNT(t1.Title) FROM t1,
t2, t3 WHERE
t1.Document_ID='xep80' AND t1.Contractor_ID='1' AND
t1.Language_ID='ger' AND '2001-12-21 23:14:24' >=
Publishing_Date AND '2001-12-21 23:14:24' <= Expiration_Date AND
t1.Document_ID = t2.Document_ID AND
t1.Language_ID = t2.Language_ID AND
t1.Contractor_ID = t2.Contractor_ID AND (
t2.Customer_ID = '4' OR
t2.Customer_ID = '999999' OR
t2.Customer_ID = '1' )AND t2.CanRead
= '1' AND t1.Column_ID=t3.Column_ID AND
t1.Language_ID=t3.Language_ID AND (
t3.Contractor_ID = '4' OR
t3.Contractor_ID = '999999' OR
t3.Contractor_ID = '1') AND
t3.CanRead='1' AND t3.Active='1';
COUNT(t1.Title)
1
drop table t1,t2,t3;
CREATE TABLE t1 (
t1_id int(11) default NULL,
t2_id int(11) default NULL,
type enum('Cost','Percent') default NULL,
cost_unit enum('Cost','Unit') default NULL,
min_value double default NULL,
max_value double default NULL,
t3_id int(11) default NULL,
item_id int(11) default NULL
) ENGINE=MyISAM;
INSERT INTO t1 VALUES (12,5,'Percent','Cost',-1,0,-1,-1),(14,4,'Percent','Cost',-1,0,-1,-1),(18,5,'Percent','Cost',-1,0,-1,-1),(19,4,'Percent','Cost',-1,0,-1,-1),(20,5,'Percent','Cost',100,-1,22,291),(21,5,'Percent','Cost',100,-1,18,291),(22,1,'Percent','Cost',100,-1,6,291),(23,1,'Percent','Cost',100,-1,21,291),(24,1,'Percent','Cost',100,-1,9,291),(25,1,'Percent','Cost',100,-1,4,291),(26,1,'Percent','Cost',100,-1,20,291),(27,4,'Percent','Cost',100,-1,7,202),(28,1,'Percent','Cost',50,-1,-1,137),(29,2,'Percent','Cost',100,-1,4,354),(30,2,'Percent','Cost',100,-1,9,137),(93,2,'Cost','Cost',-1,10000000,-1,-1);
CREATE TABLE t2 (
id int(10) unsigned NOT NULL auto_increment,
name varchar(255) default NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,'s1'),(2,'s2'),(3,'s3'),(4,'s4'),(5,'s5');
select t1.*, t2.* from t1, t2 where t2.id=t1.t2_id limit 2;
t1_id t2_id type cost_unit min_value max_value t3_id item_id id name
12 5 Percent Cost -1 0 -1 -1 5 s5
14 4 Percent Cost -1 0 -1 -1 4 s4
drop table t1,t2;
CREATE TABLE t1 (
siteid varchar(25) NOT NULL default '',
emp_id varchar(30) NOT NULL default '',
rate_code varchar(10) default NULL,
UNIQUE KEY site_emp (siteid,emp_id),
KEY siteid (siteid)
) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('rivercats','psmith','cust'), ('rivercats','KWalker','cust');
CREATE TABLE t2 (
siteid varchar(25) NOT NULL default '',
rate_code varchar(10) NOT NULL default '',
base_rate float NOT NULL default '0',
PRIMARY KEY (siteid,rate_code),
FULLTEXT KEY rate_code (rate_code)
) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('rivercats','cust',20);
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND lr.siteid = 'rivercats';
rate_code base_rate
cust 20
SELECT emp.rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE lr.siteid = 'rivercats' AND emp.emp_id = 'psmith';
rate_code base_rate
cust 20
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE emp.emp_id = 'psmith' AND siteid = 'rivercats';
rate_code base_rate
cust 20
SELECT rate_code, lr.base_rate FROM t1 AS emp LEFT JOIN t2 AS lr USING (siteid, rate_code) WHERE siteid = 'rivercats' AND emp.emp_id = 'psmith';
rate_code base_rate
cust 20
drop table t1,t2;
CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, Value1 VARCHAR(255));
CREATE TABLE t2 (ID INTEGER NOT NULL PRIMARY KEY, Value2 VARCHAR(255));
INSERT INTO t1 VALUES (1, 'A');
INSERT INTO t2 VALUES (1, 'B');
SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND (Value1 = 'A' AND Value2 <> 'B');
ID Value1 Value2
SELECT * FROM t1 NATURAL JOIN t2 WHERE 1 AND Value1 = 'A' AND Value2 <> 'B';
ID Value1 Value2
SELECT * FROM t1 NATURAL JOIN t2 WHERE (Value1 = 'A' AND Value2 <> 'B') AND 1;
ID Value1 Value2
drop table t1,t2;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
CREATE TABLE t3 (c int);
SELECT * FROM t1 NATURAL JOIN t2 NATURAL JOIN t3;
a b c
DROP TABLE t1, t2, t3;
create table t1 (i int);
create table t2 (i int);
create table t3 (i int);
insert into t1 values(1),(2);
insert into t2 values(2),(3);
insert into t3 values (2),(4);
select * from t1 natural left join t2;
i
1
2
select * from t1 left join t2 on (t1.i=t2.i);
i i
1 NULL
2 2
select * from t1 natural left join t2 natural left join t3;
i
1
2
select * from t1 left join t2 on (t1.i=t2.i) left join t3 on (t2.i=t3.i);
i i i
1 NULL NULL
2 2 2
select * from t3 natural right join t2;
i
2
3
select * from t3 right join t2 on (t3.i=t2.i);
i i
2 2
NULL 3
select * from t3 natural right join t2 natural right join t1;
i
1
2
select * from t3 right join t2 on (t3.i=t2.i) right join t1 on (t2.i=t1.i);
i i i
NULL NULL 1
2 2 2
select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i;
i i
1 2
1 3
2 2
2 3
select * from t1,t2 left join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
i i i
1 2 2
1 3 NULL
2 2 2
2 3 NULL
select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i;
i i i
1 2 2
1 3 NULL
2 2 2
2 3 NULL
select t1.i,t2.i,t3.i from t2 left join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
i i i
1 2 2
1 3 NULL
2 2 2
2 3 NULL
select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i;
i i
1 4
1 2
2 4
2 2
select * from t1,t2 right join t3 on (t2.i=t3.i) order by t1.i,t2.i,t3.i;
i i i
1 NULL 4
1 2 2
2 NULL 4
2 2 2
select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i;
i i i
1 NULL 4
1 2 2
2 NULL 4
2 2 2
select t1.i,t2.i,t3.i from t2 right join t3 on (t2.i=t3.i),t1 order by t1.i,t2.i,t3.i;
i i i
1 NULL 4
1 2 2
2 NULL 4
2 2 2
drop table t1,t2,t3;
CREATE TABLE t1 (a int, b int default 0, c int default 1);
INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8);
INSERT INTO t1 (a) SELECT a + 8 FROM t1;
INSERT INTO t1 (a) SELECT a + 16 FROM t1;
CREATE TABLE t2 (a int, d int, e int default 0);
INSERT INTO t2 (a, d) VALUES (1,1),(2,2),(3,3),(4,4);
INSERT INTO t2 (a, d) SELECT a+4, a+4 FROM t2;
INSERT INTO t2 (a, d) SELECT a+8, a+8 FROM t2;
EXPLAIN
SELECT STRAIGHT_JOIN t2.e FROM t1,t2 WHERE t2.d=1 AND t1.b=t2.e
ORDER BY t1.b, t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 32 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 16 Using where; Using join buffer (flat, BNL join)
SELECT STRAIGHT_JOIN t2.e FROM t1,t2 WHERE t2.d=1 AND t1.b=t2.e
ORDER BY t1.b, t1.c;
e
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
DROP TABLE t1,t2;
create table t1 (c int, b int);
create table t2 (a int, b int);
create table t3 (b int, c int);
create table t4 (y int, c int);
create table t5 (y int, z int);
create table t6 (a int, c int);
insert into t1 values (10,1);
insert into t1 values (3 ,1);
insert into t1 values (3 ,2);
insert into t2 values (2, 1);
insert into t3 values (1, 3);
insert into t3 values (1,10);
insert into t4 values (11,3);
insert into t4 values (2, 3);
insert into t5 values (11,4);
insert into t6 values (2, 3);
create algorithm=merge view v1a as
select * from t1 natural join t2;
create algorithm=merge view v1b(a,b,c) as
select * from t1 natural join t2;
create algorithm=merge view v1c as
select b as a, c as b, a as c from t1 natural join t2;
create algorithm=merge view v1d(b, a, c) as
select a as c, c as b, b as a from t1 natural join t2;
create algorithm=merge view v2a as
select t1.c, t1.b, t2.a from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c;
create algorithm=merge view v2b as
select t1.c as b, t1.b as a, t2.a as c
from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c;
create algorithm=merge view v3a as
select * from t1 natural join t2 natural join t3;
create algorithm=merge view v3b as
select * from t1 natural join (t2 natural join t3);
create algorithm=merge view v4 as
select * from v2a natural join v3a;
select * from (t1 natural join t2) natural join (t3 natural join t4);
b c a y
1 3 2 11
1 3 2 2
select * from (t1 natural join t2) natural left join (t3 natural join t4);
b c a y
1 10 2 NULL
1 3 2 11
1 3 2 2
select * from (t3 natural join t4) natural right join (t1 natural join t2);
b c a y
1 10 2 NULL
1 3 2 11
1 3 2 2
select * from (t1 natural left join t2) natural left join (t3 natural left join t4);
b c a y
1 10 2 NULL
1 3 2 11
1 3 2 2
2 3 NULL NULL
select * from (t4 natural right join t3) natural right join (t2 natural right join t1);
b c a y
1 10 2 NULL
1 3 2 11
1 3 2 2
2 3 NULL NULL
select * from t1 natural join t2 natural join t3 natural join t4;
c b a y
3 1 2 11
3 1 2 2
select * from ((t1 natural join t2) natural join t3) natural join t4;
c b a y
3 1 2 11
3 1 2 2
select * from t1 natural join (t2 natural join (t3 natural join t4));
c b a y
3 1 2 11
3 1 2 2
select * from t5 natural right join (t4 natural right join ((t2 natural right join t1) natural right join t3));
y c b a z
11 3 1 2 4
2 3 1 2 NULL
NULL 10 1 2 NULL
select * from (t1 natural join t2), (t3 natural join t4);
b c a c b y
1 10 2 3 1 11
1 10 2 3 1 2
1 3 2 3 1 11
1 3 2 3 1 2
select * from t5 natural join ((t1 natural join t2), (t3 natural join t4));
y z b c a c b
11 4 1 10 2 3 1
11 4 1 3 2 3 1
select * from ((t1 natural join t2), (t3 natural join t4)) natural join t5;
y b c a c b z
11 1 10 2 3 1 4
11 1 3 2 3 1 4
select * from t5 natural join ((t1 natural join t2) cross join (t3 natural join t4));
y z b c a c b
11 4 1 10 2 3 1
11 4 1 3 2 3 1
select * from ((t1 natural join t2) cross join (t3 natural join t4)) natural join t5;
y b c a c b z
11 1 10 2 3 1 4
11 1 3 2 3 1 4
select * from (t1 join t2 using (b)) join (t3 join t4 using (c)) using (c);
c b a b y
3 1 2 1 11
3 1 2 1 2
select * from (t1 join t2 using (b)) natural join (t3 join t4 using (c));
b c a y
1 3 2 11
1 3 2 2
select a,b,c from (t1 natural join t2) natural join (t3 natural join t4)
where b + 1 = y or b + 10 = y group by b,c,a having min(b) < max(y) order by a;
a b c
2 1 3
select * from (t1 natural join t2) natural left join (t3 natural join t4)
where b + 1 = y or b + 10 = y group by b,c,a,y having min(b) < max(y) order by a, y;
b c a y
1 3 2 2
1 3 2 11
select * from (t3 natural join t4) natural right join (t1 natural join t2)
where b + 1 = y or b + 10 = y group by b,c,a,y having min(b) < max(y) order by a, y;
b c a y
1 3 2 2
1 3 2 11
select * from t1 natural join t2 where t1.c > t2.a;
b c a
1 10 2
1 3 2
select * from t1 natural join t2 where t1.b > t2.b;
b c a
select * from t1 natural left join (t4 natural join t5) where t5.z is not NULL;
c b y z
3 1 11 4
3 2 11 4
select * from t1 join (t2 join t4 on b + 1 = y) on t1.c = t4.c;
c b a b y c
3 1 2 1 2 3
3 2 2 1 2 3
select * from (t2 join t4 on b + 1 = y) join t1 on t1.c = t4.c;
a b y c c b
2 1 2 3 3 1
2 1 2 3 3 2
select * from t1 natural join (t2 join t4 on b + 1 = y);
c b a y
3 1 2 2
select * from (t1 cross join t2) join (t3 cross join t4) on (a < y and t2.b < t3.c);
c b a b b c y c
10 1 2 1 1 3 11 3
10 1 2 1 1 10 11 3
3 1 2 1 1 3 11 3
3 1 2 1 1 10 11 3
3 2 2 1 1 3 11 3
3 2 2 1 1 10 11 3
select * from (t1, t2) join (t3, t4) on (a < y and t2.b < t3.c);
c b a b b c y c
10 1 2 1 1 3 11 3
10 1 2 1 1 10 11 3
3 1 2 1 1 3 11 3
3 1 2 1 1 10 11 3
3 2 2 1 1 3 11 3
3 2 2 1 1 10 11 3
select * from (t1 natural join t2) join (t3 natural join t4) on a = y;
b c a c b y
1 10 2 3 1 2
1 3 2 3 1 2
select * from ((t3 join (t1 join t2 on c > a) on t3.b < t2.a) join t4 on y > t1.c) join t5 on z = t1.b + 3;
b c c b a b y c y z
1 3 10 1 2 1 11 3 11 4
1 10 10 1 2 1 11 3 11 4
1 3 3 1 2 1 11 3 11 4
1 10 3 1 2 1 11 3 11 4
select * from t1 natural join t2 where t1.b > 0;
b c a
1 10 2
1 3 2
select * from t1 natural join (t4 natural join t5) where t4.y > 7;
c b y z
3 1 11 4
3 2 11 4
select * from (t4 natural join t5) natural join t1 where t4.y > 7;
c y z b
3 11 4 1
3 11 4 2
select * from t1 natural left join (t4 natural join t5) where t4.y > 7;
c b y z
3 1 11 4
3 2 11 4
select * from (t4 natural join t5) natural right join t1 where t4.y > 7;
c b y z
3 1 11 4
3 2 11 4
select * from (t1 natural join t2) join (t3 natural join t4) on t1.b = t3.b;
b c a c b y
1 10 2 3 1 11
1 10 2 3 1 2
1 3 2 3 1 11
1 3 2 3 1 2
select t1.*, t2.* from t1 natural join t2;
c b a b
10 1 2 1
3 1 2 1
select t1.*, t2.*, t3.*, t4.* from (t1 natural join t2) natural join (t3 natural join t4);
c b a b b c y c
3 1 2 1 1 3 11 3
3 1 2 1 1 3 2 3
select * from (select * from t1 natural join t2) as t12
natural join
(select * from t3 natural join t4) as t34;
b c a y
1 3 2 11
1 3 2 2
select * from (select * from t1 natural join t2) as t12
natural left join
(select * from t3 natural join t4) as t34;
b c a y
1 10 2 NULL
1 3 2 11
1 3 2 2
select * from (select * from t3 natural join t4) as t34
natural right join
(select * from t1 natural join t2) as t12;
b c a y
1 10 2 NULL
1 3 2 11
1 3 2 2
select * from v1a;
b c a
1 10 2
1 3 2
select * from v1b;
a b c
1 10 2
1 3 2
select * from v1c;
a b c
1 10 2
1 3 2
select * from v1d;
b a c
2 10 1
2 3 1
select * from v2a;
c b a
3 1 2
3 2 2
select * from v2b;
b a c
3 1 2
3 2 2
select * from v3a;
b c a
1 10 2
1 3 2
select * from v3b;
c b a
10 1 2
3 1 2
select * from v4;
c b a
3 1 2
select * from v1a natural join v2a;
b c a
1 3 2
select v2a.* from v1a natural join v2a;
c b a
3 1 2
select * from v1b join v2a on v1b.b = v2a.c;
a b c c b a
1 3 2 3 1 2
1 3 2 3 2 2
select * from v1c join v2a on v1c.b = v2a.c;
a b c c b a
1 3 2 3 1 2
1 3 2 3 2 2
select * from v1d join v2a on v1d.a = v2a.c;
b a c c b a
2 3 1 3 1 2
2 3 1 3 2 2
select * from v1a join (t3 natural join t4) on a = y;
b c a c b y
1 10 2 3 1 2
1 3 2 3 1 2
select * from t1 natural join (t3 cross join t4);
ERROR 23000: Column 'c' in from clause is ambiguous
select * from (t3 cross join t4) natural join t1;
ERROR 23000: Column 'c' in from clause is ambiguous
select * from t1 join (t2, t3) using (b);
ERROR 23000: Column 'b' in from clause is ambiguous
select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6;
ERROR 23000: Column 'c' in from clause is ambiguous
select * from ((t1 natural join t2), (t3 natural join t4)) natural join t6;
ERROR 23000: Column 'c' in from clause is ambiguous
select * from t6 natural join ((t1 natural join t2), (t3 natural join t4));
ERROR 23000: Column 'c' in from clause is ambiguous
select * from (t1 join t2 on t1.b=t2.b) natural join (t3 natural join t4);
ERROR 23000: Column 'b' in from clause is ambiguous
select * from (t3 natural join t4) natural join (t1 join t2 on t1.b=t2.b);
ERROR 23000: Column 'b' in from clause is ambiguous
select * from (t3 join (t4 natural join t5) on (b < z))
natural join
(t1 natural join t2);
ERROR 23000: Column 'c' in from clause is ambiguous
select * from (t1 natural join t2) natural join (t3 join (t4 natural join t5) on (b < z));
ERROR 23000: Column 'c' in from clause is ambiguous
select t1.b from v1a;
ERROR 42S22: Unknown column 't1.b' in 'field list'
select * from v1a join v1b on t1.b = t2.b;
ERROR 42S22: Unknown column 't1.b' in 'on clause'
select
statistics.TABLE_NAME, statistics.COLUMN_NAME, statistics.TABLE_CATALOG, statistics.TABLE_SCHEMA, statistics.NON_UNIQUE, statistics.INDEX_SCHEMA, statistics.INDEX_NAME, statistics.SEQ_IN_INDEX, statistics.COLLATION, statistics.SUB_PART, statistics.PACKED, statistics.NULLABLE, statistics.INDEX_TYPE, statistics.COMMENT,
columns.TABLE_CATALOG, columns.TABLE_SCHEMA, columns.COLUMN_DEFAULT, columns.IS_NULLABLE, columns.DATA_TYPE, columns.CHARACTER_MAXIMUM_LENGTH, columns.CHARACTER_OCTET_LENGTH, columns.NUMERIC_PRECISION, columns.NUMERIC_SCALE, columns.CHARACTER_SET_NAME, columns.COLLATION_NAME, columns.COLUMN_TYPE, columns.COLUMN_KEY, columns.EXTRA, columns.COLUMN_COMMENT
from information_schema.statistics join information_schema.columns using(table_name,column_name) where table_name='global_priv';
TABLE_NAME COLUMN_NAME TABLE_CATALOG TABLE_SCHEMA NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLLATION SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT TABLE_CATALOG TABLE_SCHEMA COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT
global_priv Host def mysql 0 mysql PRIMARY 1 A NULL NULL BTREE def mysql '' NO char 60 180 NULL NULL utf8 utf8_bin char(60) PRI
global_priv User def mysql 0 mysql PRIMARY 2 A NULL NULL BTREE def mysql '' NO char 80 240 NULL NULL utf8 utf8_bin char(80) PRI
Warnings:
Warning 1286 Unknown storage engine 'InnoDB'
Warning 1286 Unknown storage engine 'InnoDB'
Warning 1286 Unknown storage engine 'InnoDB'
drop table t1;
drop table t2;
drop table t3;
drop table t4;
drop table t5;
drop table t6;
drop view v1a;
drop view v1b;
drop view v1c;
drop view v1d;
drop view v2a;
drop view v2b;
drop view v3a;
drop view v3b;
drop view v4;
create table t1 (a1 int, a2 int);
create table t2 (a1 int, b int);
create table t3 (c1 int, c2 int);
create table t4 (c2 int);
insert into t1 values (1,1);
insert into t2 values (1,1);
insert into t3 values (1,1);
insert into t4 values (1);
select * from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2);
c2 a1 a2 b c1
1 1 1 1 1
select * from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2);
c2 c1 a1 a2 b
1 1 1 1 1
select a2 from t1 join t2 using (a1) join t3 on b=c1 join t4 using (c2);
a2
1
select a2 from t3 join (t1 join t2 using (a1)) on b=c1 join t4 using (c2);
a2
1
select a2 from ((t1 join t2 using (a1)) join t3 on b=c1) join t4 using (c2);
a2
1
select a2 from ((t1 natural join t2) join t3 on b=c1) natural join t4;
a2
1
drop table t1,t2,t3,t4;
create table t1 (c int, b int);
create table t2 (a int, b int);
create table t3 (b int, c int);
create table t4 (y int, c int);
create table t5 (y int, z int);
insert into t1 values (3,2);
insert into t2 values (1,2);
insert into t3 values (2,3);
insert into t4 values (1,3);
insert into t5 values (1,4);
prepare stmt1 from "select * from ((t3 natural join (t1 natural join t2))
natural join t4) natural join t5";
execute stmt1;
y c b a z
1 3 2 1 4
select * from ((t3 natural join (t1 natural join t2)) natural join t4)
natural join t5;
y c b a z
1 3 2 1 4
drop table t1, t2, t3, t4, t5;
CREATE TABLE t1 (ID INTEGER, Name VARCHAR(50));
CREATE TABLE t2 (Test_ID INTEGER);
CREATE VIEW v1 (Test_ID, Description) AS SELECT ID, Name FROM t1;
CREATE TABLE tv1 SELECT Description AS Name FROM v1 JOIN t2
USING (Test_ID);
DESCRIBE tv1;
Field Type Null Key Default Extra
Name varchar(50) YES NULL
CREATE TABLE tv2 SELECT Description AS Name FROM v1 JOIN t2
ON v1.Test_ID = t2.Test_ID;
DESCRIBE tv2;
Field Type Null Key Default Extra
Name varchar(50) YES NULL
DROP VIEW v1;
DROP TABLE t1,t2,tv1,tv2;
create table t1 (a int, b int);
insert into t1 values
(NULL, 1),
(NULL, 2),
(NULL, 3),
(NULL, 4);
create table t2 (a int not null, primary key(a));
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t3 (a int not null, primary key(a));
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
flush status;
select * from t1, t2, t3 where t3.a=t1.a and t2.a=t1.b;
a b a a
explain select * from t1, t2, t3 where t3.a=t1.a and t2.a=t1.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index
We expect rnd_next=5, and read_key must be 0 because of short-cutting:
show status like 'Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 0
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 5
drop table t1, t2, t3;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, filler char(100), key(a), key(b));
create table t3 (a int, b int, filler char(100), key(a), key(b));
insert into t2
select @a:= A.a + 10*(B.a + 10*C.a), @a, 'filler' from t1 A, t1 B, t1 C;
insert into t3 select * from t2 where a < 800;
explain select * from t2,t3 where t2.a < 200 and t2.b=t3.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL a,b NULL NULL NULL 1000 Using where
1 SIMPLE t3 ref b b 5 test.t2.b 1
drop table t1, t2, t3;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, primary key(a));
insert into t2 select @v:=A.a+10*B.a, @v from t1 A, t1 B;
explain select * from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
show status like '%cost%';
Variable_name Value
Last_query_cost 4.016090
select 'The cost of accessing t1 (dont care if it changes' '^';
The cost of accessing t1 (dont care if it changes
The cost of accessing t1 (dont care if it changes^
select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z;
Z
vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv
explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
1 SIMPLE A eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where
1 SIMPLE B eq_ref PRIMARY PRIMARY 4 test.A.b 1
show status like '%cost%';
Variable_name Value
Last_query_cost 28.016090
select '^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error' Z;
Z
^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error
drop table t1, t2;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
CREATE TABLE t2 (c INT PRIMARY KEY, d INT);
INSERT INTO t1 VALUES(1,NULL),(2,NULL),(3,NULL),(4,NULL);
INSERT INTO t1 SELECT a + 4, b FROM t1;
INSERT INTO t1 SELECT a + 8, b FROM t1;
INSERT INTO t1 SELECT a + 16, b FROM t1;
INSERT INTO t1 SELECT a + 32, b FROM t1;
INSERT INTO t1 SELECT a + 64, b FROM t1;
INSERT INTO t2 SELECT a, b FROM t1;
EXPLAIN SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a LIMIT 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1
EXPLAIN SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a LIMIT 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 2
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1
SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a LIMIT 2;
a b c d
SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a LIMIT 2;
a b c d
1 NULL 1 NULL
2 NULL 2 NULL
EXPLAIN SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using where; Using filesort
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1
EXPLAIN SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 128 Using filesort
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1
SELECT * FROM t1 JOIN t2 ON b=c ORDER BY a;
a b c d
SELECT * FROM t1 JOIN t2 ON a=c ORDER BY a;
a b c d
1 NULL 1 NULL
2 NULL 2 NULL
3 NULL 3 NULL
4 NULL 4 NULL
5 NULL 5 NULL
6 NULL 6 NULL
7 NULL 7 NULL
8 NULL 8 NULL
9 NULL 9 NULL
10 NULL 10 NULL
11 NULL 11 NULL
12 NULL 12 NULL
13 NULL 13 NULL
14 NULL 14 NULL
15 NULL 15 NULL
16 NULL 16 NULL
17 NULL 17 NULL
18 NULL 18 NULL
19 NULL 19 NULL
20 NULL 20 NULL
21 NULL 21 NULL
22 NULL 22 NULL
23 NULL 23 NULL
24 NULL 24 NULL
25 NULL 25 NULL
26 NULL 26 NULL
27 NULL 27 NULL
28 NULL 28 NULL
29 NULL 29 NULL
30 NULL 30 NULL
31 NULL 31 NULL
32 NULL 32 NULL
33 NULL 33 NULL
34 NULL 34 NULL
35 NULL 35 NULL
36 NULL 36 NULL
37 NULL 37 NULL
38 NULL 38 NULL
39 NULL 39 NULL
40 NULL 40 NULL
41 NULL 41 NULL
42 NULL 42 NULL
43 NULL 43 NULL
44 NULL 44 NULL
45 NULL 45 NULL
46 NULL 46 NULL
47 NULL 47 NULL
48 NULL 48 NULL
49 NULL 49 NULL
50 NULL 50 NULL
51 NULL 51 NULL
52 NULL 52 NULL
53 NULL 53 NULL
54 NULL 54 NULL
55 NULL 55 NULL
56 NULL 56 NULL
57 NULL 57 NULL
58 NULL 58 NULL
59 NULL 59 NULL
60 NULL 60 NULL
61 NULL 61 NULL
62 NULL 62 NULL
63 NULL 63 NULL
64 NULL 64 NULL
65 NULL 65 NULL
66 NULL 66 NULL
67 NULL 67 NULL
68 NULL 68 NULL
69 NULL 69 NULL
70 NULL 70 NULL
71 NULL 71 NULL
72 NULL 72 NULL
73 NULL 73 NULL
74 NULL 74 NULL
75 NULL 75 NULL
76 NULL 76 NULL
77 NULL 77 NULL
78 NULL 78 NULL
79 NULL 79 NULL
80 NULL 80 NULL
81 NULL 81 NULL
82 NULL 82 NULL
83 NULL 83 NULL
84 NULL 84 NULL
85 NULL 85 NULL
86 NULL 86 NULL
87 NULL 87 NULL
88 NULL 88 NULL
89 NULL 89 NULL
90 NULL 90 NULL
91 NULL 91 NULL
92 NULL 92 NULL
93 NULL 93 NULL
94 NULL 94 NULL
95 NULL 95 NULL
96 NULL 96 NULL
97 NULL 97 NULL
98 NULL 98 NULL
99 NULL 99 NULL
100 NULL 100 NULL
101 NULL 101 NULL
102 NULL 102 NULL
103 NULL 103 NULL
104 NULL 104 NULL
105 NULL 105 NULL
106 NULL 106 NULL
107 NULL 107 NULL
108 NULL 108 NULL
109 NULL 109 NULL
110 NULL 110 NULL
111 NULL 111 NULL
112 NULL 112 NULL
113 NULL 113 NULL
114 NULL 114 NULL
115 NULL 115 NULL
116 NULL 116 NULL
117 NULL 117 NULL
118 NULL 118 NULL
119 NULL 119 NULL
120 NULL 120 NULL
121 NULL 121 NULL
122 NULL 122 NULL
123 NULL 123 NULL
124 NULL 124 NULL
125 NULL 125 NULL
126 NULL 126 NULL
127 NULL 127 NULL
128 NULL 128 NULL
DROP TABLE IF EXISTS t1,t2;
#
# Bug #42116: Mysql crash on specific query
#
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
CREATE TABLE t3 (a INT, INDEX (a));
CREATE TABLE t4 (a INT);
CREATE TABLE t5 (a INT);
CREATE TABLE t6 (a INT);
INSERT INTO t1 VALUES (1), (1), (1);
INSERT INTO t2 VALUES
(2), (2), (2), (2), (2), (2), (2), (2), (2), (2);
INSERT INTO t3 VALUES
(3), (3), (3), (3), (3), (3), (3), (3), (3), (3);
EXPLAIN
SELECT *
FROM
t1 JOIN t2 ON t1.a = t2.a
LEFT JOIN
(
(
t3 LEFT JOIN t4 ON t3.a = t4.a
)
LEFT JOIN
(
t5 LEFT JOIN t6 ON t5.a = t6.a
)
ON t4.a = t5.a
)
ON t1.a = t3.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3
1 SIMPLE t3 ref a a 5 test.t1.a 2 Using where; Using index
1 SIMPLE t4 ALL NULL NULL NULL NULL 0 Using where
1 SIMPLE t5 ALL NULL NULL NULL NULL 0 Using where
1 SIMPLE t6 ALL NULL NULL NULL NULL 0 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
SELECT *
FROM
t1 JOIN t2 ON t1.a = t2.a
LEFT JOIN
(
(
t3 LEFT JOIN t4 ON t3.a = t4.a
)
LEFT JOIN
(
t5 LEFT JOIN t6 ON t5.a = t6.a
)
ON t4.a = t5.a
)
ON t1.a = t3.a;
a a a a a a
DROP TABLE t1,t2,t3,t4,t5,t6;
#
# Bug#48483: crash in get_best_combination()
#
CREATE TABLE t1(f1 INT);
INSERT INTO t1 VALUES (1),(2);
CREATE VIEW v1 AS SELECT 1 FROM t1 LEFT JOIN t1 AS t2 on 1=1;
EXPLAIN EXTENDED
SELECT 1 FROM v1 right join v1 AS v2 ON RAND();
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` left join `test`.`t1` `t2` on(1 = 1) left join (`test`.`t1` left join `test`.`t1` `t2` on(1 = 1)) on(rand()) where 1
DROP VIEW v1;
DROP TABLE t1;
#
# Bug#52177 crash with explain, row comparison, join, text field
#
CREATE TABLE t1 (a TINYINT, b TEXT, KEY (a));
INSERT INTO t1 VALUES (0,''),(0,'');
FLUSH TABLES;
EXPLAIN SELECT 1 FROM t1 LEFT JOIN t1 a ON 1
WHERE ROW(t1.a, 1111.11) = ROW(1111.11, 1111.11) AND
ROW(t1.b, 1111.11) <=> ROW('','');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
DROP TABLE t1;
#
# Bug #50335: Assertion `!(order->used & map)' in eq_ref_table
#
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b));
INSERT INTO t1 VALUES (0,0), (1,1);
SELECT * FROM t1 STRAIGHT_JOIN t1 t2 ON t1.a=t2.a AND t1.a=t2.b ORDER BY t2.a, t1.a;
a b a b
0 0 0 0
1 1 1 1
DROP TABLE t1;
End of 5.0 tests.
CREATE TABLE t1 (f1 int);
CREATE TABLE t2 (f1 int);
INSERT INTO t2 VALUES (1);
CREATE VIEW v1 AS SELECT * FROM t2;
PREPARE stmt FROM 'UPDATE t2 AS A NATURAL JOIN v1 B SET B.f1 = 1';
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP VIEW v1;
DROP TABLE t1, t2;
CREATE TABLE t1(a CHAR(9),b INT,KEY(b),KEY(a)) ENGINE=MYISAM;
CREATE TABLE t2(a CHAR(9),b INT,KEY(b),KEY(a)) ENGINE=MYISAM;
INSERT INTO t1 VALUES ('1',null),(null,null);
INSERT INTO t2 VALUES ('1',null),(null,null);
CREATE TABLE mm1(a CHAR(9),b INT,KEY(b),KEY(a))
ENGINE=MERGE UNION=(t1,t2);
SELECT t1.a FROM mm1,t1;
a
NULL
1
NULL
1
NULL
1
NULL
1
DROP TABLE t1, t2, mm1;
#
# Bug #54468: crash after item's print() function when ordering/grouping
# by subquery
#
CREATE TABLE t1(a INT, b INT);
INSERT INTO t1 VALUES (), ();
SELECT 1 FROM t1
GROUP BY
GREATEST(t1.a,
(SELECT 1 FROM
(SELECT t1.b FROM t1,t1 t2
ORDER BY t1.a, t1.a LIMIT 1) AS d)
);
1
1
DROP TABLE t1;
#
# Bug #53544: Server hangs during JOIN query in stored procedure called
# twice in a row
#
CREATE TABLE t1(c INT);
INSERT INTO t1 VALUES (1), (2);
PREPARE stmt FROM "SELECT t2.c AS f1 FROM t1 LEFT JOIN
t1 t2 ON t1.c=t2.c RIGHT JOIN
t1 t3 ON t1.c=t3.c
GROUP BY f1;";
EXECUTE stmt;
f1
1
2
EXECUTE stmt;
f1
1
2
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#
# Bug LP:798597: Incorrect "Duplicate entry" error with views and
# GROUP BY
#
CREATE TABLE t1 ( f1 int NOT NULL , f2 int NOT NULL ) ;
INSERT INTO t1 VALUES (214,0),(6,6);
CREATE TABLE t2 ( f2 int) ;
INSERT INTO t2 VALUES (88),(88);
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT t1.f1, t2.f2 FROM (t2 LEFT JOIN t1 ON (t2.f2 <> t1.f1)) WHERE (t1.f2 <= 0) ;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT t1.f1, t2.f2 FROM (t2 LEFT JOIN t1 ON (t2.f2 <> t1.f1)) WHERE (t1.f2 <= 0 or t1.f2 is null) ;
SELECT f1 , MIN(f2) FROM v1 GROUP BY f1;
f1 MIN(f2)
214 88
SELECT f1 , MIN(f2) FROM v2 GROUP BY f1;
f1 MIN(f2)
214 88
drop table t1,t2;
drop view v1,v2;
#
# BUG#47217 Lost optimization caused slowdown & wrong result.
#
CREATE TABLE t1 (pk INT, v VARCHAR(2), PRIMARY KEY(pk));
CREATE INDEX ix1 ON t1(v);
CREATE TABLE t2 (pk INT, v VARCHAR(2), PRIMARY KEY(pk));
CREATE INDEX ix2 ON t2(v);
INSERT INTO t1 VALUES (1,'a'),(2,NULL);
INSERT INTO t2 VALUES (1,NULL);
EXPLAIN SELECT * FROM t1 JOIN t2 ON t1.v = t2.v ORDER BY 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
EXPLAIN SELECT * FROM t1 JOIN t2 ON t1.v = t2.v;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
INSERT INTO t1 VALUES (3,'b'),(4,NULL),(5,'c'),(6,'cc'),(7,'d'),
(8,'dd'),(9,'e'),(10,'ee');
INSERT INTO t2 VALUES (2,NULL);
ANALYZE TABLE t1,t2;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
FLUSH STATUS;
SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1;
pk v pk v
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 14
Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 1
DROP TABLE t1, t2;
End of 5.1 tests
#
# Bug #43368: STRAIGHT_JOIN DOESN'T WORK FOR NESTED JOINS
#
create table t1(c1 int primary key, c2 char(10)) engine=myisam;
create table t2(c1 int primary key, c2 char(10), ref_t1 int) engine=myisam;
create table t3(c1 int primary key, c2 char(10), ref_t1 int) engine=myisam;
create table t4(c1 int primary key, c2 char(10), ref_t1 int) engine=myisam;
insert into t1 values(1,'a');
insert into t2 values(1,'a', 1);
insert into t3 values(1,'a', 1);
insert into t3 values(2,'b',2);
insert into t4 values(1,'a', 1);
insert into t4 values(2,'a', 2);
insert into t4 values(3,'a', 3);
insert into t4 values(4,'a', 4);
insert into t1 values(2,'b');
insert into t1 values(3,'c');
EXPLAIN
SELECT *
FROM t4 JOIN
(t1 JOIN t3 ON t3.ref_t1=t1.c1 JOIN t2 ON t2.ref_t1=t1.c1)
ON t4.ref_t1=t1.c1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 system NULL NULL NULL NULL 1
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
EXPLAIN
SELECT STRAIGHT_JOIN *
FROM t4 JOIN
(t1 JOIN t3 ON t3.ref_t1=t1.c1 JOIN t2 ON t2.ref_t1=t1.c1)
ON t4.ref_t1=t1.c1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join)
EXPLAIN
SELECT *
FROM t4 STRAIGHT_JOIN
(t1 JOIN t3 ON t3.ref_t1=t1.c1 JOIN t2 ON t2.ref_t1=t1.c1)
ON t4.ref_t1=t1.c1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
drop table t1,t2,t3,t4;
End of 5.2 tests
#
# BUG#724275: Crash in JOIN::optimize in maria-5.3
#
create table t1 (a int);
insert into t1 values (1),(2);
insert into t1 select * from t1;
create table t2 (a int, b int, key(a,b));
insert into t2 values (1,1),(1,2),(1,3),(1,4),(2,5),(2,6),(2,7),(2,8),(2,9);
insert into t2 select * from t2;
insert into t2 select * from t2;
insert into t2 select * from t2;
create table t3 (a int, b int, key(a));
insert into t3 values (1,1),(2,2);
select * from
t3 straight_join t1 straight_join t2 force index(a)
where t2.a=1 and t2.b=t1.a and t1.a=t3.b and t3.a=1;
a b a a b
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
drop table t1,t2,t3;
#
# BUG#729067/730466: unexpected 'Range checked for each record'
# for queries with OR in WHERE clause
#
CREATE TABLE t1 (f1 int, f2 int) ;
INSERT INTO t1 VALUES (4,0),(5,1);
CREATE TABLE t2 (f1 int, f2 int, KEY (f2)) ;
INSERT INTO t2 VALUES (5,7), (8,9);
EXPLAIN
SELECT * FROM t1 STRAIGHT_JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1<>0 OR t1.f2<>0 AND t1.f1 = t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t2 ALL f2 NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
SELECT * FROM t1 STRAIGHT_JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1<>0 OR t1.f2<>0 AND t1.f1 = t2.f2;
f1 f2 f1 f2
5 1 5 7
DROP TABLE t1,t2;
CREATE TABLE t1(f1 int PRIMARY KEY, f2 int) ;
INSERT INTO t1 VALUES (9,4), (10,9);
CREATE TABLE t2(f1 int PRIMARY KEY, f2 int) ;
INSERT INTO t2 VALUES (9,4), (10,9);
EXPLAIN
SELECT STRAIGHT_JOIN * FROM t1 JOIN t2 ON t2.f2 = t1.f1
WHERE t1.f1 IN (SELECT f1 FROM t1) AND t1.f1 = t2.f1 OR t1.f1 = 9;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where
1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index
SELECT STRAIGHT_JOIN * FROM t1 JOIN t2 ON t2.f2 = t1.f1
WHERE t1.f1 IN (SELECT f1 FROM t1) AND t1.f1 = t2.f1 OR t1.f1 = 9;
f1 f2 f1 f2
9 4 10 9
DROP TABLE t1,t2;
create table t1 (i time key);
insert into t1 values ('1:1:1'), ('2:2:2');
create table t2 (i time);
insert into t2 values ('1:1:1');
select t2.i from t1 left join t2 on t2.i = t1.i where t1.i = '1:1:1';
i
01:01:01
drop table t1,t2;
#
# BUG#954900: unexpected empty set due to an invalid build of key ref
#
CREATE TABLE t1 (dog_id int(10), birthday date, PRIMARY KEY (dog_id,birthday));
INSERT INTO t1 VALUES (5918,'2004-07-22');
CREATE TABLE t2 (dog_id int(10) unsigned, t_id char(1), birthday date, a_id int(10),
PRIMARY KEY (dog_id,t_id,birthday,a_id));
INSERT INTO t2 VALUES
(5918,'N','2004-07-22',5216551), (5918,'N','2004-07-22',5223640),
(5918,'N','2004-07-22',5389491), (5918,'N','2004-07-22',5749434),
(5918,'N','2004-07-22',5992424), (5922,'N','2005-06-30',5076957),
(5924,'N','2000-08-11',20264), (5924,'N','2000-08-11',64251),
(5924,'N','2000-08-11',74748), (5924,'N','2000-08-11',87590),
(5924,'N','2000-08-11',104695), (5924,'N','2000-08-11',133136),
(5924,'N','2000-08-11',5027806), (5924,'N','2000-08-11',5076957),
(5924,'N','2000-08-11',5166821), (5924,'N','2000-08-11',5181896),
(5924,'N','2000-08-11',5217908), (5924,'N','2000-08-11',5220812),
(5924,'N','2000-08-11',5226473), (5924,'N','2000-08-11',5339111),
(5925,'N','2005-02-10',19227), (5925,'N','2005-02-10',74529),
(5925,'N','2005-02-10',74748), (5927,'N','2005-08-18',20264),
(5927,'N','2005-08-18',58364), (5929,'N','2005-01-19',58364),
(5935,'N','2006-03-10',19227), (5935,'N','2006-03-10',64251),
(5935,'N','2006-03-10',5222400), (5935,'N','2006-03-10',5226473),
(5936,'N','2004-10-29',5015032), (5937,'N','2002-04-05',11237),
(5937,'N','2002-04-05',23911), (5937,'N','2002-04-05',112133),
(5937,'N','2002-04-05',169721), (5937,'N','2002-04-05',170650),
(5937,'N','2002-04-05',5014494), (5937,'N','2002-04-05',5166009),
(5937,'N','2002-04-05',5181871), (5937,'N','2002-04-05',5213380),
(5937,'N','2002-04-05',5214875), (5937,'N','2002-04-05',5895062),
(5938,'N','2006-03-24',11237), (5938,'N','2006-03-24',19227),
(5938,'N','2006-03-24',23911), (5938,'N','2006-03-24',58364),
(5938,'N','2006-03-24',64251), (5938,'N','2006-03-24',111716),
(5938,'N','2006-03-24',112702), (5938,'N','2006-03-24',133136),
(5938,'N','2006-03-24',168718), (5938,'N','2006-03-24',5137136),
(5938,'N','2006-03-24',5161519), (5938,'N','2006-03-24',5168120),
(5938,'N','2006-03-24',5219034), (6234,'N','2006-06-02',103058),
(6234,'N','2006-06-02',5146844), (6235,'N','2006-06-01',12900),
(6235,'N','2006-06-01',20264), (6235,'N','2006-06-01',64251),
(6235,'N','2006-06-01',75160), (6235,'N','2006-06-01',5014494),
(6235,'N','2006-06-01',5181638), (6236,'N','2006-06-06',112595),
(6236,'N','2006-06-06',5219601), (6236,'N','2006-06-06',5808374);
CREATE TABLE t3 (dog_id int(10) unsigned);
INSERT INTO t3 VALUES (5918);
CREATE TABLE t4 (dog_id int(10), t_id char(1), birthday date, KEY (t_id));
INSERT INTO t4 VALUES (5918,'N','2004-07-22'), (5919,'N','2004-07-20');
CREATE TABLE t5 (dog_id int(10) unsigned, UNIQUE KEY (dog_id));
INSERT INTO t5 VALUES (5918);
SET @tmp_optimizer_switch=@@optimizer_switch;
SET optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT * FROM t5 DU, t1 D, t4 DT, t2 DSA, t3 DSAR
WHERE DU.dog_id=D.dog_id AND D.dog_id=DT.dog_id AND D.birthday=DT.birthday AND
DT.t_id=DSA.t_id AND DT.birthday=DSA.birthday AND DSA.dog_id=DSAR.dog_id;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE DU system dog_id NULL NULL NULL 1
1 SIMPLE D system PRIMARY NULL NULL NULL 1
1 SIMPLE DSAR system NULL NULL NULL NULL 1
1 SIMPLE DT range t_id t_id 2 NULL 2 Using where
1 SIMPLE DSA ref PRIMARY PRIMARY 8 const,test.DT.t_id,func 1 Using index
SELECT * FROM t5 DU, t1 D, t4 DT, t2 DSA, t3 DSAR
WHERE DU.dog_id=D.dog_id AND D.dog_id=DT.dog_id AND D.birthday=DT.birthday AND
DT.t_id=DSA.t_id AND DT.birthday=DSA.birthday AND DSA.dog_id=DSAR.dog_id;
dog_id dog_id birthday dog_id t_id birthday dog_id t_id birthday a_id dog_id
5918 5918 2004-07-22 5918 N 2004-07-22 5918 N 2004-07-22 5216551 5918
5918 5918 2004-07-22 5918 N 2004-07-22 5918 N 2004-07-22 5223640 5918
5918 5918 2004-07-22 5918 N 2004-07-22 5918 N 2004-07-22 5389491 5918
5918 5918 2004-07-22 5918 N 2004-07-22 5918 N 2004-07-22 5749434 5918
5918 5918 2004-07-22 5918 N 2004-07-22 5918 N 2004-07-22 5992424 5918
SET optimizer_switch=@tmp_optimizer_switch;
DROP TABLE t1,t2,t3,t4,t5;
#
# MDEV-4752: Segfault during parsing of illegal query
#
SELECT * FROM t5 JOIN (t1 JOIN t2 UNION SELECT * FROM t3 JOIN t4);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UNION SELECT * FROM t3 JOIN t4)' at line 1
#
# MDEV-4959: join of const table with NULL fields
#
CREATE TABLE t1 (i1 int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (NULL);
CREATE TABLE t2 (i2 int, a int, b int) ENGINE=MyISAM;
CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
INSERT INTO t2 VALUES (NULL,1,2),(NULL,2,3);
SELECT * FROM t1 JOIN v2 ON i1 = i2 WHERE a < b;
i1 i2 a b
EXPLAIN EXTENDED
SELECT * FROM t1 JOIN v2 ON i1 = i2 WHERE a < b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DERIVED t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select NULL AS `i1`,`v2`.`i2` AS `i2`,`v2`.`a` AS `a`,`v2`.`b` AS `b` from `test`.`v2` where `v2`.`i2` = NULL and `v2`.`a` < `v2`.`b`
DROP VIEW v2;
DROP TABLE t1,t2;
SET optimizer_switch=@save_optimizer_switch;
#
# MDEV-16512
# Server crashes in find_field_in_table_ref on 2nd execution of SP referring to
# non-existing field
#
CREATE TABLE t (i INT);
CREATE PROCEDURE p() SELECT t1.f FROM t AS t1 JOIN t AS t2 USING (f);
CALL p;
ERROR 42S22: Unknown column 'f' in 'from clause'
CALL p;
ERROR 42S22: Unknown column 'f' in 'from clause'
FLUSH TABLES;
CALL p;
ERROR 42S22: Unknown column 'f' in 'from clause'
DROP TABLE t;
CREATE TABLE t (f INT);
CALL p;
f
DROP TABLE t;
CREATE TABLE t (i INT);
CALL p;
ERROR 42S22: Unknown column 't1.f' in 'field list'
CALL p;
ERROR 42S22: Unknown column 't1.f' in 'field list'
DROP PROCEDURE p;
DROP TABLE t;
CREATE TABLE t1 (a INT, b INT);
CREATE TABLE t2 (a INT);
CREATE TABLE t3 (a INT, c INT);
CREATE TABLE t4 (a INT, c INT);
CREATE TABLE t5 (a INT, c INT);
CREATE PROCEDURE p1() SELECT c FROM t1 JOIN (t2 LEFT JOIN t3 USING (a) LEFT JOIN t4 USING (a)
LEFT JOIN t5 USING (a)) USING (a);
CALL p1;
ERROR 23000: Column 'c' in field list is ambiguous
CALL p1;
ERROR 23000: Column 'c' in field list is ambiguous
DROP PROCEDURE p1;
DROP TABLE t1,t2,t3,t4,t5;
#
# MDEV-19421: Embedding inner joins
#
create table t1 (a int);
insert into t1 values (7), (5), (3);
create table s1 (b int);
insert into s1 values (7), (5), (3);
create table t2 (a int);
insert into t2 values (5), (1), (7);
create table s2 (b int);
insert into s2 values (5), (1), (7);
create table t3 (a int);
insert into t3 values (2), (7), (3);
create table t4 (a int);
insert into t4 values (4), (7), (9), (5);
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 on t2.a=t3.a on t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t3`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 on t2.a=t3.a on t1.a=t2.a;
t1_a t2_a t3_a
7 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 on t2.a=t3.a on t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t1`.`a`) where `test`.`t2`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 on t2.a=t3.a on t1.a=t2.a;
t1_a t2_a t3_a
7 7 7
5 5 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 on t2.a=t3.a on t1.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t3` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) where `test`.`t3`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 on t2.a=t3.a on t1.a=t3.a;
t1_a t2_a t3_a
7 7 7
3 NULL 3
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 using(a) using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t3`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 using(a) using(a);
t1_a t2_a t3_a
7 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 using(a) using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t1`.`a`) where `test`.`t2`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 using(a) using(a);
t1_a t2_a t3_a
7 7 7
5 5 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 using(a) using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t3` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) where `test`.`t3`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 using(a) using(a);
t1_a t2_a t3_a
7 7 7
3 NULL 3
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 on t2.a=t3.a;
t1_a t2_a t3_a
7 7 7
5 7 7
3 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t2`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 on t2.a=t3.a;
t1_a t2_a t3_a
7 7 7
5 7 7
3 7 7
7 5 NULL
5 5 NULL
3 5 NULL
7 1 NULL
5 1 NULL
3 1 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t3` left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 on t2.a=t3.a;
t1_a t2_a t3_a
7 7 7
5 7 7
3 7 7
NULL NULL 2
NULL NULL 3
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 on t1.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3 on t1.a=t3.a;
t1_a t2_a t3_a
7 5 7
7 1 7
7 7 7
3 5 3
3 1 3
3 7 3
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 on t1.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t1`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 left join t3 on t1.a=t3.a;
t1_a t2_a t3_a
7 5 7
7 1 7
7 7 7
3 5 3
3 1 3
3 7 3
5 5 NULL
5 1 NULL
5 7 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 on t1.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t3` left join (`test`.`t1` join `test`.`t2`) on(`test`.`t1`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 right join t3 on t1.a=t3.a;
t1_a t2_a t3_a
7 5 7
3 5 3
7 1 7
3 1 3
7 7 7
3 7 3
NULL NULL 2
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join (t2 join t3 on t2.a=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join (t2 join t3 on t2.a=t3.a);
t1_a t2_a t3_a
7 7 7
5 7 7
3 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join (t2 left join t3 on t2.a=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t2`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join (t2 left join t3 on t2.a=t3.a);
t1_a t2_a t3_a
7 7 7
5 7 7
3 7 7
7 5 NULL
5 5 NULL
3 5 NULL
7 1 NULL
5 1 NULL
3 1 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join (t2 right join t3 on t2.a=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t3` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join (t2 right join t3 on t2.a=t3.a);
t1_a t2_a t3_a
7 7 7
5 7 7
3 7 7
7 NULL 2
5 NULL 2
3 NULL 2
7 NULL 3
5 NULL 3
3 NULL 3
explain extended select *
from s1 join t2 join t3 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`s1`.`b` AS `b` from `test`.`s1` join `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a`
select *
from s1 join t2 join t3 using(a);
a b
7 7
7 5
7 3
explain extended select *
from s1 join t2 left join t3 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`s1`.`b` AS `b` from `test`.`s1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t2`.`a`) where 1
select *
from s1 join t2 left join t3 using(a);
a b
7 7
7 5
7 3
5 7
5 5
5 3
1 7
1 5
1 3
explain extended select *
from s1 join t2 right join t3 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`s1`.`b` AS `b` from `test`.`t3` left join (`test`.`s1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select *
from s1 join t2 right join t3 using(a);
a b
7 7
7 5
7 3
2 NULL
3 NULL
explain extended select s1.b, t2.a as t2_a, t3.a as t3_a
from s1 join t2 join t3 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `b`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`s1` join `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a`
select s1.b, t2.a as t2_a, t3.a as t3_a
from s1 join t2 join t3 using(a);
b t2_a t3_a
7 7 7
5 7 7
3 7 7
explain extended select s1.b, t2.a as t2_a, t3.a as t3_a
from s1 join t2 left join t3 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `b`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`s1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t2`.`a`) where 1
select s1.b, t2.a as t2_a, t3.a as t3_a
from s1 join t2 left join t3 using(a);
b t2_a t3_a
7 7 7
5 7 7
3 7 7
7 5 NULL
5 5 NULL
3 5 NULL
7 1 NULL
5 1 NULL
3 1 NULL
explain extended select s1.b, t2.a as t2_a, t3.a as t3_a
from s1 join t2 right join t3 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `b`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t3` left join (`test`.`s1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select s1.b, t2.a as t2_a, t3.a as t3_a
from s1 join t2 right join t3 using(a);
b t2_a t3_a
7 7 7
5 7 7
3 7 7
NULL NULL 2
NULL NULL 3
explain extended select s1.b, t2.a as t2_a, t3.a as t3_a
from (s1 join t2) right join t3 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `b`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t3` left join (`test`.`s1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select s1.b, t2.a as t2_a, t3.a as t3_a
from (s1 join t2) right join t3 using(a);
b t2_a t3_a
7 7 7
5 7 7
3 7 7
NULL NULL 2
NULL NULL 3
explain extended select *
from s1 join t2 natural join t3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`s1`.`b` AS `b` from `test`.`s1` join `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a`
select *
from s1 join t2 natural join t3;
a b
7 7
7 5
7 3
explain extended select *
from s1 join t2 natural left join t3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`s1`.`b` AS `b` from `test`.`s1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t2`.`a`) where 1
select *
from s1 join t2 natural left join t3;
a b
7 7
7 5
7 3
5 7
5 5
5 3
1 7
1 5
1 3
explain extended select *
from s1 join t2 natural right join t3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`s1`.`b` AS `b` from `test`.`t3` left join (`test`.`s1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select *
from s1 join t2 natural right join t3;
a b
7 7
7 5
7 3
2 NULL
3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` join `test`.`t3`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3;
t1_a t2_a t3_a
7 5 2
5 5 2
3 5 2
7 1 2
5 1 2
3 1 2
7 7 2
5 7 2
3 7 2
7 5 7
5 5 7
3 5 7
7 1 7
5 1 7
3 1 7
7 7 7
5 7 7
3 7 7
7 5 3
5 5 3
3 5 3
7 1 3
5 1 3
3 1 3
7 7 3
5 7 3
3 7 3
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3
where t1.a=t2.a and t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t3`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from t1 join t2 join t3
where t1.a=t2.a and t2.a=t3.a;
t1_a t2_a t3_a
7 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where `test`.`t3`.`a` = `test`.`t2`.`a` and `test`.`t4`.`a` = `test`.`t2`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = `test`.`t2`.`a` and `test`.`t4`.`a` = `test`.`t2`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
7 5 NULL NULL
5 5 NULL NULL
3 5 NULL NULL
7 1 NULL NULL
5 1 NULL NULL
3 1 NULL NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 left join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` left join (`test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t2`.`a`)) on(`test`.`t3`.`a` = `test`.`t2`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 left join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
7 5 NULL NULL
5 5 NULL NULL
3 5 NULL NULL
7 1 NULL NULL
5 1 NULL NULL
3 1 NULL NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` left join (`test`.`t4` join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t2`.`a` and `test`.`t4`.`a` = `test`.`t2`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
7 5 NULL NULL
5 5 NULL NULL
3 5 NULL NULL
7 1 NULL NULL
5 1 NULL NULL
3 1 NULL NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t3` join `test`.`t4` left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where `test`.`t4`.`a` = `test`.`t3`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 left join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 left join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
NULL NULL 2 NULL
NULL NULL 3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t4`.`a`) left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 left join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 left join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
7 5 2 NULL
5 5 2 NULL
3 5 2 NULL
7 1 2 NULL
5 1 2 NULL
3 1 2 NULL
7 7 2 NULL
5 7 2 NULL
3 7 2 NULL
7 5 3 NULL
5 5 3 NULL
3 5 3 NULL
7 1 3 NULL
5 1 3 NULL
3 1 3 NULL
7 7 3 NULL
5 7 3 NULL
3 7 3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 right join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join (`test`.`t1` join `test`.`t2` join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t4`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 right join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select s1.b as s1_b, s2.b as s2_b, t3.a as t3_a, t4.a as t4_a
from s1 join s2 join t3 join t4 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`s2`.`b` AS `s2_b`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`s1` join `test`.`s2` join `test`.`t3` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a`
select s1.b as s1_b, s2.b as s2_b, t3.a as t3_a, t4.a as t4_a
from s1 join s2 join t3 join t4 using(a);
s1_b s2_b t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
explain extended select s1.b as s1_b, s2.b as s2_b, t3.a as t3_a, t4.a as t4_a
from s1 join s2 join t3 left join t4 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`s2`.`b` AS `s2_b`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`s1` join `test`.`s2` join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) where 1
select s1.b as s1_b, s2.b as s2_b, t3.a as t3_a, t4.a as t4_a
from s1 join s2 join t3 left join t4 using(a);
s1_b s2_b t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
7 5 2 NULL
5 5 2 NULL
3 5 2 NULL
7 1 2 NULL
5 1 2 NULL
3 1 2 NULL
7 7 2 NULL
5 7 2 NULL
3 7 2 NULL
7 5 3 NULL
5 5 3 NULL
3 5 3 NULL
7 1 3 NULL
5 1 3 NULL
3 1 3 NULL
7 7 3 NULL
5 7 3 NULL
3 7 3 NULL
explain extended select s1.b as s1_b, s2.b as s2_b, t3.a as t3_a, t4.a as t4_a
from s1 join s2 join t3 right join t4 using(a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE s2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`s2`.`b` AS `s2_b`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join (`test`.`s1` join `test`.`s2` join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t4`.`a`) where 1
select s1.b as s1_b, s2.b as s2_b, t3.a as t3_a, t4.a as t4_a
from s1 join s2 join t3 right join t4 using(a);
s1_b s2_b t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 on t2.a=t3.a join t4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where `test`.`t3`.`a` = `test`.`t2`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 join t3 on t2.a=t3.a join t4;
t1_a t2_a t3_a t4_a
7 7 7 4
5 7 7 4
3 7 7 4
7 7 7 7
5 7 7 7
3 7 7 7
7 7 7 9
5 7 7 9
3 7 7 9
7 7 7 5
5 7 7 5
3 7 7 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 on t2.a=t3.a join t4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t2`.`a`) join `test`.`t4` where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 left join t3 on t2.a=t3.a join t4;
t1_a t2_a t3_a t4_a
7 7 7 4
5 7 7 4
3 7 7 4
7 5 NULL 4
5 5 NULL 4
3 5 NULL 4
7 1 NULL 4
5 1 NULL 4
3 1 NULL 4
7 7 7 7
5 7 7 7
3 7 7 7
7 5 NULL 7
5 5 NULL 7
3 5 NULL 7
7 1 NULL 7
5 1 NULL 7
3 1 NULL 7
7 7 7 9
5 7 7 9
3 7 7 9
7 5 NULL 9
5 5 NULL 9
3 5 NULL 9
7 1 NULL 9
5 1 NULL 9
3 1 NULL 9
7 7 7 5
5 7 7 5
3 7 7 5
7 5 NULL 5
5 5 NULL 5
3 5 NULL 5
7 1 NULL 5
5 1 NULL 5
3 1 NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 on t2.a=t3.a join t4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t3` left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) join `test`.`t4` where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 on t2.a=t3.a join t4;
t1_a t2_a t3_a t4_a
7 7 7 4
5 7 7 4
3 7 7 4
7 7 7 7
5 7 7 7
3 7 7 7
7 7 7 9
5 7 7 9
3 7 7 9
7 7 7 5
5 7 7 5
3 7 7 5
NULL NULL 2 4
NULL NULL 3 4
NULL NULL 2 7
NULL NULL 3 7
NULL NULL 2 9
NULL NULL 3 9
NULL NULL 2 5
NULL NULL 3 5
explain extended select s1.b as s1_b, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t2 join t3 using(a) join t4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`s1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where `test`.`t3`.`a` = `test`.`t2`.`a`
select s1.b as s1_b, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t2 join t3 using(a) join t4;
s1_b t2_a t3_a t4_a
7 7 7 4
5 7 7 4
3 7 7 4
7 7 7 7
5 7 7 7
3 7 7 7
7 7 7 9
5 7 7 9
3 7 7 9
7 7 7 5
5 7 7 5
3 7 7 5
explain extended select s1.b as s1_b, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t2 left join t3 using(a) join t4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`s1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t2`.`a`) join `test`.`t4` where 1
select s1.b as s1_b, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t2 left join t3 using(a) join t4;
s1_b t2_a t3_a t4_a
7 7 7 4
5 7 7 4
3 7 7 4
7 5 NULL 4
5 5 NULL 4
3 5 NULL 4
7 1 NULL 4
5 1 NULL 4
3 1 NULL 4
7 7 7 7
5 7 7 7
3 7 7 7
7 5 NULL 7
5 5 NULL 7
3 5 NULL 7
7 1 NULL 7
5 1 NULL 7
3 1 NULL 7
7 7 7 9
5 7 7 9
3 7 7 9
7 5 NULL 9
5 5 NULL 9
3 5 NULL 9
7 1 NULL 9
5 1 NULL 9
3 1 NULL 9
7 7 7 5
5 7 7 5
3 7 7 5
7 5 NULL 5
5 5 NULL 5
3 5 NULL 5
7 1 NULL 5
5 1 NULL 5
3 1 NULL 5
explain extended select s1.b as s1_b, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t2 right join t3 using(a) join t4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t3` left join (`test`.`s1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) join `test`.`t4` where 1
select s1.b as s1_b, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t2 right join t3 using(a) join t4;
s1_b t2_a t3_a t4_a
7 7 7 4
5 7 7 4
3 7 7 4
7 7 7 7
5 7 7 7
3 7 7 7
7 7 7 9
5 7 7 9
3 7 7 9
7 7 7 5
5 7 7 5
3 7 7 5
NULL NULL 2 4
NULL NULL 3 4
NULL NULL 2 7
NULL NULL 3 7
NULL NULL 2 9
NULL NULL 3 9
NULL NULL 2 5
NULL NULL 3 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 on t1.a=t2.a join t3 join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a` and `test`.`t2`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 on t1.a=t2.a join t3 join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
5 5 7 7
7 7 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 on t1.a=t2.a join t3 left join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) where `test`.`t2`.`a` = `test`.`t1`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 on t1.a=t2.a join t3 left join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
5 5 7 7
7 7 7 7
5 5 2 NULL
7 7 2 NULL
5 5 3 NULL
7 7 3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 on t1.a=t2.a join t3 right join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join (`test`.`t1` join `test`.`t2` join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t4`.`a` and `test`.`t2`.`a` = `test`.`t1`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 on t1.a=t2.a join t3 right join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
5 5 7 7
7 7 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 left join t2 on t1.a=t2.a join t3 join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) join `test`.`t3` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 left join t2 on t1.a=t2.a join t3 join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
5 5 7 7
7 7 7 7
3 NULL 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 left join t2 on t1.a=t2.a join t3 left join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 left join t2 on t1.a=t2.a join t3 left join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
5 5 7 7
7 7 7 7
3 NULL 7 7
5 5 2 NULL
7 7 2 NULL
3 NULL 2 NULL
5 5 3 NULL
7 7 3 NULL
3 NULL 3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 left join t2 on t1.a=t2.a join t3 right join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join (`test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t4`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 left join t2 on t1.a=t2.a join t3 right join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
5 5 7 7
7 7 7 7
3 NULL 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 right join t2 on t1.a=t2.a join t3 join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t2` left join `test`.`t1` on(`test`.`t1`.`a` = `test`.`t2`.`a`) join `test`.`t3` join `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a`
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 right join t2 on t1.a=t2.a join t3 join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 5 7 7
NULL 1 7 7
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 right join t2 on t1.a=t2.a join t3 left join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t2` left join `test`.`t1` on(`test`.`t1`.`a` = `test`.`t2`.`a`) join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 right join t2 on t1.a=t2.a join t3 left join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 5 7 7
NULL 1 7 7
7 7 2 NULL
5 5 2 NULL
NULL 1 2 NULL
7 7 3 NULL
5 5 3 NULL
NULL 1 3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 right join t2 on t1.a=t2.a join t3 right join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join (`test`.`t2` left join `test`.`t1` on(`test`.`t1`.`a` = `test`.`t2`.`a`) join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t4`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 right join t2 on t1.a=t2.a join t3 right join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 5 7 7
NULL 1 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select s1.b as s1_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t1 left join t2 on s1.b=t2.a join t3 join t4 on t4.a=s1.b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`s1` join `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`s1`.`b`) join `test`.`t3` join `test`.`t4` where `test`.`t4`.`a` = `test`.`s1`.`b`
select s1.b as s1_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t1 left join t2 on s1.b=t2.a join t3 join t4 on t4.a=s1.b;
s1_b t1_a t2_a t3_a t4_a
7 7 7 2 7
7 5 7 2 7
7 3 7 2 7
7 7 7 7 7
7 5 7 7 7
7 3 7 7 7
7 7 7 3 7
7 5 7 3 7
7 3 7 3 7
5 7 5 2 5
5 5 5 2 5
5 3 5 2 5
5 7 5 7 5
5 5 5 7 5
5 3 5 7 5
5 7 5 3 5
5 5 5 3 5
5 3 5 3 5
explain extended select s1.b as s1_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t1 left join t2 on s1.b=t2.a join t3 left join t4 on t4.a=s1.b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`s1` join `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`s1`.`b`) join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`s1`.`b`) where 1
select s1.b as s1_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t1 left join t2 on s1.b=t2.a join t3 left join t4 on t4.a=s1.b;
s1_b t1_a t2_a t3_a t4_a
7 7 7 2 7
7 5 7 2 7
7 3 7 2 7
7 7 7 7 7
7 5 7 7 7
7 3 7 7 7
7 7 7 3 7
7 5 7 3 7
7 3 7 3 7
5 7 5 2 5
5 5 5 2 5
5 3 5 2 5
5 7 5 7 5
5 5 5 7 5
5 3 5 7 5
5 7 5 3 5
5 5 5 3 5
5 3 5 3 5
3 7 NULL 2 NULL
3 5 NULL 2 NULL
3 3 NULL 2 NULL
3 7 NULL 7 NULL
3 5 NULL 7 NULL
3 3 NULL 7 NULL
3 7 NULL 3 NULL
3 5 NULL 3 NULL
3 3 NULL 3 NULL
explain extended select s1.b as s1_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t1 left join t2 on s1.b=t2.a join t3 right join t4 on t4.a=s1.b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join (`test`.`s1` join `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t4`.`a`) join `test`.`t3`) on(`test`.`s1`.`b` = `test`.`t4`.`a`) where 1
select s1.b as s1_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from s1 join t1 left join t2 on s1.b=t2.a join t3 right join t4 on t4.a=s1.b;
s1_b t1_a t2_a t3_a t4_a
5 7 5 2 5
5 5 5 2 5
5 3 5 2 5
7 7 7 2 7
7 5 7 2 7
7 3 7 2 7
5 7 5 7 5
5 5 5 7 5
5 3 5 7 5
7 7 7 7 7
7 5 7 7 7
7 3 7 7 7
5 7 5 3 5
5 5 5 3 5
5 3 5 3 5
7 7 7 3 7
7 5 7 3 7
7 3 7 3 7
NULL NULL NULL NULL 4
NULL NULL NULL NULL 9
explain extended select s1.b as s1_b, s2.b as s2_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from s1 join s2 on s1.b=s2.b join t1 right join t2 on t1.a=t2.a join t3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE s2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`s2`.`b` AS `s2_b`,`test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t2` left join (`test`.`s1` join `test`.`s2` join `test`.`t1`) on(`test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`s2`.`b` = `test`.`s1`.`b`) join `test`.`t3` where 1
select s1.b as s1_b, s2.b as s2_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from s1 join s2 on s1.b=s2.b join t1 right join t2 on t1.a=t2.a join t3;
s1_b s2_b t1_a t2_a t3_a
5 5 7 7 2
7 7 7 7 2
5 5 5 5 2
7 7 5 5 2
5 5 7 7 7
7 7 7 7 7
5 5 5 5 7
7 7 5 5 7
5 5 7 7 3
7 7 7 7 3
5 5 5 5 3
7 7 5 5 3
NULL NULL NULL 1 2
NULL NULL NULL 1 7
NULL NULL NULL 1 3
explain extended select s1.b as s1_b, s2.b as s2_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from s1 left join s2 on s1.b=s2.b join t1 right join t2 on t1.a=t2.a join t3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE s2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`s2`.`b` AS `s2_b`,`test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t2` left join (`test`.`s1` left join `test`.`s2` on(`test`.`s2`.`b` = `test`.`s1`.`b`) join `test`.`t1`) on(`test`.`t1`.`a` = `test`.`t2`.`a`) join `test`.`t3` where 1
select s1.b as s1_b, s2.b as s2_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from s1 left join s2 on s1.b=s2.b join t1 right join t2 on t1.a=t2.a join t3;
s1_b s2_b t1_a t2_a t3_a
5 5 7 7 2
7 7 7 7 2
3 NULL 7 7 2
5 5 5 5 2
7 7 5 5 2
3 NULL 5 5 2
5 5 7 7 7
7 7 7 7 7
3 NULL 7 7 7
5 5 5 5 7
7 7 5 5 7
3 NULL 5 5 7
5 5 7 7 3
7 7 7 7 3
3 NULL 7 7 3
5 5 5 5 3
7 7 5 5 3
3 NULL 5 5 3
NULL NULL NULL 1 2
NULL NULL NULL 1 7
NULL NULL NULL 1 3
explain extended select s1.b as s1_b, s2.b as s2_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from s1 right join s2 on s1.b=s2.b join t1 right join t2 on t1.a=t2.a join t3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE s2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE s1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`s1`.`b` AS `s1_b`,`test`.`s2`.`b` AS `s2_b`,`test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a` from `test`.`t2` left join (`test`.`s2` left join `test`.`s1` on(`test`.`s1`.`b` = `test`.`s2`.`b`) join `test`.`t1`) on(`test`.`t1`.`a` = `test`.`t2`.`a`) join `test`.`t3` where 1
select s1.b as s1_b, s2.b as s2_b, t1.a as t1_a, t2.a as t2_a, t3.a as t3_a
from s1 right join s2 on s1.b=s2.b join t1 right join t2 on t1.a=t2.a join t3;
s1_b s2_b t1_a t2_a t3_a
7 7 7 7 2
5 5 7 7 2
NULL 1 7 7 2
7 7 5 5 2
5 5 5 5 2
NULL 1 5 5 2
7 7 7 7 7
5 5 7 7 7
NULL 1 7 7 7
7 7 5 5 7
5 5 5 5 7
NULL 1 5 5 7
7 7 7 7 3
5 5 7 7 3
NULL 1 7 7 3
7 7 5 5 3
5 5 5 5 3
NULL 1 5 5 3
NULL NULL NULL 1 2
NULL NULL NULL 1 7
NULL NULL NULL 1 3
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t4`.`a`) left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1 join t2 right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from (t1 join t2) right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t4`.`a`) left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from (t1 join t2) right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from (t1, t2) right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t4` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t4`.`a`) left join (`test`.`t1` join `test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from (t1, t2) right join t3 right join t4 on t3.a=t4.a on t2.a=t3.a;
t1_a t2_a t3_a t4_a
7 7 7 7
5 7 7 7
3 7 7 7
NULL NULL NULL 4
NULL NULL NULL 9
NULL NULL NULL 5
drop table t1,t2,t3,t4,s1,s2;
#
# MDEV-20265: Mix of comma joins with JOIN expressions
# (correction of the fix for MDEV-19421)
# MDEV-20330: duplicate
#
create table t1 (a int);
insert into t1 values (7), (5), (3);
create table t2 (a int);
insert into t2 values (5), (1), (7);
create table t3 (a int);
insert into t3 values (2), (7), (3);
create table t4 (a int);
insert into t4 values (4), (7), (9), (5);
create table t5 (a int);
insert into t5 values (3), (7), (9), (2);
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 left join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` left join `test`.`t4` on(`test`.`t4`.`a` = `test`.`t3`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 left join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
7 5 2 NULL
5 5 2 NULL
3 5 2 NULL
7 1 2 NULL
5 1 2 NULL
3 1 2 NULL
7 7 2 NULL
5 7 2 NULL
3 7 2 NULL
7 5 3 NULL
5 5 3 NULL
3 5 3 NULL
7 1 3 NULL
5 1 3 NULL
3 1 3 NULL
7 7 3 NULL
5 7 3 NULL
3 7 3 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 right join t4 on t3.a=t4.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a` from `test`.`t1` join `test`.`t4` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t3`.`a` = `test`.`t4`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a
from t1, t2 join t3 right join t4 on t3.a=t4.a;
t1_a t2_a t3_a t4_a
7 5 7 7
5 5 7 7
3 5 7 7
7 1 7 7
5 1 7 7
3 1 7 7
7 7 7 7
5 7 7 7
3 7 7 7
7 NULL NULL 4
5 NULL NULL 4
3 NULL NULL 4
7 NULL NULL 9
5 NULL NULL 9
3 NULL NULL 9
7 NULL NULL 5
5 NULL NULL 5
3 NULL NULL 5
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` left join `test`.`t5` on(`test`.`t5`.`a` = `test`.`t4`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 left join t5 on t4.a=t5.a;
t1_a t2_a t3_a t4_a t5_a
7 5 2 7 7
5 5 2 7 7
3 5 2 7 7
7 1 2 7 7
5 1 2 7 7
3 1 2 7 7
7 7 2 7 7
5 7 2 7 7
3 7 2 7 7
7 5 7 7 7
5 5 7 7 7
3 5 7 7 7
7 1 7 7 7
5 1 7 7 7
3 1 7 7 7
7 7 7 7 7
5 7 7 7 7
3 7 7 7 7
7 5 3 7 7
5 5 3 7 7
3 5 3 7 7
7 1 3 7 7
5 1 3 7 7
3 1 3 7 7
7 7 3 7 7
5 7 3 7 7
3 7 3 7 7
7 5 2 9 9
5 5 2 9 9
3 5 2 9 9
7 1 2 9 9
5 1 2 9 9
3 1 2 9 9
7 7 2 9 9
5 7 2 9 9
3 7 2 9 9
7 5 7 9 9
5 5 7 9 9
3 5 7 9 9
7 1 7 9 9
5 1 7 9 9
3 1 7 9 9
7 7 7 9 9
5 7 7 9 9
3 7 7 9 9
7 5 3 9 9
5 5 3 9 9
3 5 3 9 9
7 1 3 9 9
5 1 3 9 9
3 1 3 9 9
7 7 3 9 9
5 7 3 9 9
3 7 3 9 9
7 5 2 4 NULL
5 5 2 4 NULL
3 5 2 4 NULL
7 1 2 4 NULL
5 1 2 4 NULL
3 1 2 4 NULL
7 7 2 4 NULL
5 7 2 4 NULL
3 7 2 4 NULL
7 5 7 4 NULL
5 5 7 4 NULL
3 5 7 4 NULL
7 1 7 4 NULL
5 1 7 4 NULL
3 1 7 4 NULL
7 7 7 4 NULL
5 7 7 4 NULL
3 7 7 4 NULL
7 5 3 4 NULL
5 5 3 4 NULL
3 5 3 4 NULL
7 1 3 4 NULL
5 1 3 4 NULL
3 1 3 4 NULL
7 7 3 4 NULL
5 7 3 4 NULL
3 7 3 4 NULL
7 5 2 5 NULL
5 5 2 5 NULL
3 5 2 5 NULL
7 1 2 5 NULL
5 1 2 5 NULL
3 1 2 5 NULL
7 7 2 5 NULL
5 7 2 5 NULL
3 7 2 5 NULL
7 5 7 5 NULL
5 5 7 5 NULL
3 5 7 5 NULL
7 1 7 5 NULL
5 1 7 5 NULL
3 1 7 5 NULL
7 7 7 5 NULL
5 7 7 5 NULL
3 7 7 5 NULL
7 5 3 5 NULL
5 5 3 5 NULL
3 5 3 5 NULL
7 1 3 5 NULL
5 1 3 5 NULL
3 1 3 5 NULL
7 7 3 5 NULL
5 7 3 5 NULL
3 7 3 5 NULL
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` join `test`.`t5` left join (`test`.`t2` join `test`.`t3` join `test`.`t4`) on(`test`.`t4`.`a` = `test`.`t5`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1, t2 join t3 join t4 right join t5 on t4.a=t5.a;
t1_a t2_a t3_a t4_a t5_a
7 5 2 7 7
5 5 2 7 7
3 5 2 7 7
7 1 2 7 7
5 1 2 7 7
3 1 2 7 7
7 7 2 7 7
5 7 2 7 7
3 7 2 7 7
7 5 7 7 7
5 5 7 7 7
3 5 7 7 7
7 1 7 7 7
5 1 7 7 7
3 1 7 7 7
7 7 7 7 7
5 7 7 7 7
3 7 7 7 7
7 5 3 7 7
5 5 3 7 7
3 5 3 7 7
7 1 3 7 7
5 1 3 7 7
3 1 3 7 7
7 7 3 7 7
5 7 3 7 7
3 7 3 7 7
7 5 2 9 9
5 5 2 9 9
3 5 2 9 9
7 1 2 9 9
5 1 2 9 9
3 1 2 9 9
7 7 2 9 9
5 7 2 9 9
3 7 2 9 9
7 5 7 9 9
5 5 7 9 9
3 5 7 9 9
7 1 7 9 9
5 1 7 9 9
3 1 7 9 9
7 7 7 9 9
5 7 7 9 9
3 7 7 9 9
7 5 3 9 9
5 5 3 9 9
3 5 3 9 9
7 1 3 9 9
5 1 3 9 9
3 1 3 9 9
7 7 3 9 9
5 7 3 9 9
3 7 3 9 9
7 NULL NULL NULL 3
5 NULL NULL NULL 3
3 NULL NULL NULL 3
7 NULL NULL NULL 2
5 NULL NULL NULL 2
3 NULL NULL NULL 2
explain extended select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `t1_a`,`test`.`t2`.`a` AS `t2_a`,`test`.`t3`.`a` AS `t3_a`,`test`.`t4`.`a` AS `t4_a`,`test`.`t5`.`a` AS `t5_a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) join `test`.`t5` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t4`.`a` = `test`.`t5`.`a`) where 1
select t1.a as t1_a, t2.a as t2_a, t3.a as t3_a, t4.a as t4_a, t5.a as t5_a
from t1 left join t2 on t1.a=t2.a, t3 join t4 right join t5 on t4.a=t5.a;
t1_a t2_a t3_a t4_a t5_a
5 5 2 7 7
7 7 2 7 7
3 NULL 2 7 7
5 5 7 7 7
7 7 7 7 7
3 NULL 7 7 7
5 5 3 7 7
7 7 3 7 7
3 NULL 3 7 7
5 5 2 9 9
7 7 2 9 9
3 NULL 2 9 9
5 5 7 9 9
7 7 7 9 9
3 NULL 7 9 9
5 5 3 9 9
7 7 3 9 9
3 NULL 3 9 9
5 5 NULL NULL 3
7 7 NULL NULL 3
3 NULL NULL NULL 3
5 5 NULL NULL 2
7 7 NULL NULL 2
3 NULL NULL NULL 2
drop table t1,t2,t3,t4,t5;
select a.a
from (select 1 as a) a,
(select 2 as b) b
cross join
(select 3 as c) c
left join
(select 4 as d) d
on 1;
a
1
#
# End of MariaDB 5.5 tests
#
#
# Bug #35268: Parser can't handle STRAIGHT_JOIN with USING
#
CREATE TABLE t1 (a int);
INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8);
CREATE TABLE t2 (a int);
INSERT INTO t2 (a) VALUES (1),(2),(3),(4);
EXPLAIN
SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort
1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a;
a
1
2
3
4
EXPLAIN
SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a;
a
1
2
3
4
EXPLAIN
SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a;
a
1
2
3
4
DROP TABLE t1,t2;
#
# MDEV-5635: join of a const table with non-const tables
#
CREATE TABLE t1 (a varchar(3) NOT NULL) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo');
CREATE TABLE t2 (b varchar(3), c varchar(3), INDEX(b)) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('bar', 'bar'),( 'qux', 'qux');
SELECT STRAIGHT_JOIN * FROM t1, t2 AS t2_1, t2 AS t2_2
WHERE t2_2.c = t2_1.c AND t2_2.b = t2_1.b AND ( a IS NULL OR t2_1.c = a );
a b c b c
DROP TABLE t1,t2;
#
# MDEV-19600: The optimizer should be able to produce rows=1 estimate for unique index with NULLable columns
#
create table t0(a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (
pk int not null primary key auto_increment,
a int,
b int,
unique key(a)
);
insert into t1 (a,b) select null, 12345 from t0 A, t0 B, t0 C;
insert into t1 (a,b) select a,a from t0;
# Simulate InnoDB's persistent statistics (It always uses nulls_equal)
set @tmp1= @@myisam_stats_method;
set myisam_stats_method=nulls_equal;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
set myisam_stats_method=@tmp1;
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 0 PRIMARY 1 pk A 1010 NULL NULL BTREE
t1 0 a 1 a A 1010 NULL NULL YES BTREE
# t1 must use eq_ref(t1.a=t0.a) and rows must be 1 (and not 45):
explain select * from t0,t1 where t0.a=t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where
1 SIMPLE t1 eq_ref a a 5 test.t0.a 1
drop table t0,t1;
#
# MDEV-21383: Possible range plan is not used under certain conditions
#
drop table if exists t10, t1000, t03;
create table t10(a int);
insert into t10 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1000(a int);
insert into t1000 select A.a + B.a* 10 + C.a * 100 from t10 A, t10 B, t10 C;
create table t03(a int);
insert into t03 values (0),(1),(2);
create table t1 (
stationid int
);
insert into t1 select a from t10;
CREATE TABLE t2 (
stationId int,
startTime int,
filler char(100),
key1 int,
key2 int,
key(key1),
key(key2),
PRIMARY KEY (`stationId`,`startTime`)
);
insert into t2 select
A.a,
B.a,
repeat('filler=data-', 4),
B.a,
1
from
t03 A,
t1000 B;
analyze table t2;
Table Op Msg_type Msg_text
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
create table t3(a int, filler char(100), key(a));
insert into t3 select A.a+1000*B.a, 'filler-data' from t1000 A, t10 B;
# This should produce a join order of t1,t2,t3
# t2 should have type=range, key=PRIMARY key_len=8 (not type=ALL or key_len<8)
explain
SELECT *
FROM
t1,t2,t3
WHERE
t2.startTime <= 100 and
t2.stationId = t1.stationId and
(t1.stationid = 1 or t1.stationid = 2 or t1.stationid = 3) and
key1 >0 and
t2.key2=t3.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
1 SIMPLE t2 range PRIMARY,key1,key2 PRIMARY 8 NULL 219 Using index condition; Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ref a a 5 test.t2.key2 1
drop table t1,t2,t3;
drop table t1000,t10,t03;
|