summaryrefslogtreecommitdiff
path: root/mysql-test/main/select_pkeycache.result
blob: c8df75c58f04ca1ec1a64046cd998bb24bf9762d (plain)
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
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
drop table if exists t1,t2,t3,t4,t11;
drop table if exists t1_1,t1_2,t9_1,t9_2,t1aa,t2aa;
drop view if exists v1;
SET optimizer_switch=ifnull(@optimizer_switch_for_select_test,'outer_join_with_cache=off');
set join_cache_level=1;
CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
);
INSERT INTO t1 VALUES (9410,9412);
select period from t1;
period
9410
select * from t1;
Period	Varor_period
9410	9412
select t1.* from t1;
Period	Varor_period
9410	9412
CREATE TABLE t2 (
auto int not null auto_increment,
fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL,
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
fld3 char(30) DEFAULT '' NOT NULL,
fld4 char(35) DEFAULT '' NOT NULL,
fld5 char(35) DEFAULT '' NOT NULL,
fld6 char(4) DEFAULT '' NOT NULL,
UNIQUE fld1 (fld1),
KEY fld3 (fld3),
PRIMARY KEY (auto)
);
select t2.fld3 from t2 where companynr = 58 and fld3 like "%imaginable%";
fld3
imaginable
select fld3 from t2 where fld3 like "%cultivation" ;
fld3
cultivation
select t2.fld3,companynr from t2 where companynr = 57+1 order by fld3;
fld3	companynr
concoct	58
druggists	58
engrossing	58
Eurydice	58
exclaimers	58
ferociousness	58
hopelessness	58
Huey	58
imaginable	58
judges	58
merging	58
ostrich	58
peering	58
Phelps	58
presumes	58
Ruth	58
sentences	58
Shylock	58
straggled	58
synergy	58
thanking	58
tying	58
unlocks	58
select fld3,companynr from t2 where companynr = 58 order by fld3;
fld3	companynr
concoct	58
druggists	58
engrossing	58
Eurydice	58
exclaimers	58
ferociousness	58
hopelessness	58
Huey	58
imaginable	58
judges	58
merging	58
ostrich	58
peering	58
Phelps	58
presumes	58
Ruth	58
sentences	58
Shylock	58
straggled	58
synergy	58
thanking	58
tying	58
unlocks	58
select fld3 from t2 order by fld3 desc limit 10;
fld3
youthfulness
yelped
Wotan
workers
Witt
witchcraft
Winsett
Willy
willed
wildcats
select fld3 from t2 order by fld3 desc limit 5;
fld3
youthfulness
yelped
Wotan
workers
Witt
select fld3 from t2 order by fld3 desc limit 5,5;
fld3
witchcraft
Winsett
Willy
willed
wildcats
select t2.fld3 from t2 where fld3 = 'honeysuckle';
fld3
honeysuckle
select t2.fld3 from t2 where fld3 LIKE 'honeysuckl_';
fld3
honeysuckle
select t2.fld3 from t2 where fld3 LIKE 'hon_ysuckl_';
fld3
honeysuckle
select t2.fld3 from t2 where fld3 LIKE 'honeysuckle%';
fld3
honeysuckle
select t2.fld3 from t2 where fld3 LIKE 'h%le';
fld3
honeysuckle
select t2.fld3 from t2 where fld3 LIKE 'honeysuckle_';
fld3
select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%';
fld3
explain select t2.fld3 from t2 where fld3 = 'honeysuckle';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	fld3	fld3	30	const	1	Using where; Using index
explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	fld3	fld3	30	const	1	Using where; Using index
explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	fld3	fld3	30	const	1	Using where; Using index
explain select fld3 from t2 ignore index (fld3,not_used);
ERROR 42000: Key 'not_used' doesn't exist in table 't2'
explain select fld3 from t2 use index (not_used);
ERROR 42000: Key 'not_used' doesn't exist in table 't2'
select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
fld3
honeysuckle
honoring
explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	fld3	fld3	30	NULL	2	Using where; Using index
select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3;
fld1	fld3
148504	Colombo
068305	Colombo
000000	nondecreasing
select fld1,fld3 from t2 where companynr = 37 and fld3 = 'appendixes';
fld1	fld3
232605	appendixes
1232605	appendixes
1232606	appendixes
1232607	appendixes
1232608	appendixes
1232609	appendixes
select fld1 from t2 where fld1=250501 or fld1="250502";
fld1
250501
250502
explain select fld1 from t2 where fld1=250501 or fld1="250502";
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	fld1	fld1	4	NULL	2	Using where; Using index
select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
fld1
250501
250502
250505
250601
explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	fld1	fld1	4	NULL	4	Using where; Using index
select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%';
fld1	fld3
012001	flanking
013602	foldout
013606	fingerings
018007	fanatic
018017	featherweight
018054	fetters
018103	flint
018104	flopping
036002	funereal
038017	fetched
038205	firearm
058004	Fenton
088303	feminine
186002	freakish
188007	flurried
188505	fitting
198006	furthermore
202301	Fitzpatrick
208101	fiftieth
208113	freest
218008	finishers
218022	feed
218401	faithful
226205	foothill
226209	furnishings
228306	forthcoming
228311	fated
231315	freezes
232102	forgivably
238007	filial
238008	fixedly
select fld3 from t2 where fld3 like "L%" and fld3 = "ok";
fld3
select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly");
fld3
Chantilly
select fld1,fld3 from t2 where fld1 like "25050%";
fld1	fld3
250501	poisoning
250502	Iraqis
250503	heaving
250504	population
250505	bomb
select fld1,fld3 from t2 where fld1 like "25050_";
fld1	fld3
250501	poisoning
250502	Iraqis
250503	heaving
250504	population
250505	bomb
select distinct companynr from t2;
companynr
00
37
36
50
58
29
40
53
65
41
34
68
select distinct companynr from t2 order by companynr;
companynr
00
29
34
36
37
40
41
50
53
58
65
68
select distinct companynr from t2 order by companynr desc;
companynr
68
65
58
53
50
41
40
37
36
34
29
00
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
fld3	period
obliterates	9410
offload	9410
opaquely	9410
organizer	9410
overestimating	9410
overlay	9410
select distinct fld3 from t2 where companynr = 34 order by fld3;
fld3
absentee
accessed
ahead
alphabetic
Asiaticizations
attitude
aye
bankruptcies
belays
Blythe
bomb
boulevard
bulldozes
cannot
caressing
charcoal
checksumming
chess
clubroom
colorful
cosy
creator
crying
Darius
diffusing
duality
Eiffel
Epiphany
Ernestine
explorers
exterminated
famine
forked
Gershwins
heaving
Hodges
Iraqis
Italianization
Lagos
landslide
libretto
Majorca
mastering
narrowed
occurred
offerers
Palestine
Peruvianizes
pharmaceutic
poisoning
population
Pygmalion
rats
realest
recording
regimented
retransmitting
reviver
rouses
scars
sicker
sleepwalk
stopped
sugars
translatable
uncles
unexpected
uprisings
versatility
vest
select distinct fld3 from t2 limit 10;
fld3
abates
abiding
Abraham
abrogating
absentee
abut
accessed
accruing
accumulating
accuracies
select distinct fld3 from t2 having fld3 like "A%" limit 10;
fld3
abates
abiding
Abraham
abrogating
absentee
abut
accessed
accruing
accumulating
accuracies
select distinct substring(fld3,1,3) from t2 where fld3 like "A%";
substring(fld3,1,3)
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
Adl
adm
Ado
ads
adv
aer
aff
afi
afl
afo
agi
ahe
aim
air
Ald
alg
ali
all
alp
alr
ama
ame
amm
ana
and
ane
Ang
ani
Ann
Ant
api
app
aqu
Ara
arc
Arm
arr
Art
Asi
ask
asp
ass
ast
att
aud
Aug
aut
ave
avo
awe
aye
Azt
select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10;
a
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10;
substring(fld3,1,3)
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
a
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
create table t3 (
period    int not null,
name      char(32) not null,
companynr int not null,
price     double(11,0),
price2     double(11,0),
key (period),
key (name)
);
create temporary table tmp engine = myisam select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
alter table t3 add t2nr int not null auto_increment primary key first;
drop table tmp;
set tmp_memory_table_size=0;
select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10;
namn
Abraham Abraham
abrogating abrogating
admonishing admonishing
Adolph Adolph
afield afield
aging aging
ammonium ammonium
analyzable analyzable
animals animals
animized animized
set tmp_memory_table_size=default;
select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10;
concat(fld3," ",fld3)
Abraham Abraham
abrogating abrogating
admonishing admonishing
Adolph Adolph
afield afield
aging aging
ammonium ammonium
analyzable analyzable
animals animals
animized animized
select distinct fld5 from t2 limit 10;
fld5
neat
Steinberg
jarring
tinily
balled
persist
attainments
fanatic
measures
rightfulness
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
fld3	count(*)
affixed	1
and	1
annoyers	1
Anthony	1
assayed	1
assurers	1
attendants	1
bedlam	1
bedpost	1
boasted	1
set tmp_memory_table_size=0;
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
fld3	count(*)
affixed	1
and	1
annoyers	1
Anthony	1
assayed	1
assurers	1
attendants	1
bedlam	1
bedpost	1
boasted	1
set tmp_memory_table_size=default;
select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10;
fld3	repeat("a",length(fld3))	count(*)
circus	aaaaaa	1
cited	aaaaa	1
Colombo	aaaaaaa	1
congresswoman	aaaaaaaaaaaaa	1
contrition	aaaaaaaaaa	1
corny	aaaaa	1
cultivation	aaaaaaaaaaa	1
definiteness	aaaaaaaaaaaa	1
demultiplex	aaaaaaaaaaa	1
disappointing	aaaaaaaaaaaaa	1
select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2;
companynr	rtrim(space(512+companynr))
37	
78	
101	
154	
311	
447	
512	
select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by fld3;
fld3
explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	fld1	NULL	NULL	NULL	1199	Using where; Using temporary; Using filesort
1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.fld1	1	Using where; Using index
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	period	NULL	NULL	NULL	41810	Using filesort
1	SIMPLE	t3	ref	period	period	4	test.t1.period	4181	
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	index	period	period	4	NULL	1	
1	SIMPLE	t1	ref	period	period	4	test.t3.period	4181	
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	period	period	4	NULL	1	
1	SIMPLE	t3	ref	period	period	4	test.t1.period	4181	
select period from t1;
period
9410
select period from t1 where period=1900;
period
select fld3,period from t1,t2 where fld1 = 011401 order by period;
fld3	period
breaking	9410
select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001;
fld3	period
breaking	1001
explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	const	fld1	fld1	4	const	1	
1	SIMPLE	t3	const	PRIMARY,period	PRIMARY	4	const	1	
select fld3,period from t2,t1 where companynr*10 = 37*10;
fld3	period
breaking	9410
Romans	9410
intercepted	9410
bewilderingly	9410
astound	9410
admonishing	9410
sumac	9410
flanking	9410
combed	9410
subjective	9410
scatterbrain	9410
Eulerian	9410
Kane	9410
overlay	9410
perturb	9410
goblins	9410
annihilates	9410
Wotan	9410
snatching	9410
concludes	9410
laterally	9410
yelped	9410
grazing	9410
Baird	9410
celery	9410
misunderstander	9410
handgun	9410
foldout	9410
mystic	9410
succumbed	9410
Nabisco	9410
fingerings	9410
aging	9410
afield	9410
ammonium	9410
boat	9410
intelligibility	9410
Augustine	9410
teethe	9410
dreaded	9410
scholastics	9410
audiology	9410
wallet	9410
parters	9410
eschew	9410
quitter	9410
neat	9410
Steinberg	9410
jarring	9410
tinily	9410
balled	9410
persist	9410
attainments	9410
fanatic	9410
measures	9410
rightfulness	9410
capably	9410
impulsive	9410
starlet	9410
terminators	9410
untying	9410
announces	9410
featherweight	9410
pessimist	9410
daughter	9410
decliner	9410
lawgiver	9410
stated	9410
readable	9410
attrition	9410
cascade	9410
motors	9410
interrogate	9410
pests	9410
stairway	9410
dopers	9410
testicle	9410
Parsifal	9410
leavings	9410
postulation	9410
squeaking	9410
contrasted	9410
leftover	9410
whiteners	9410
erases	9410
Punjab	9410
Merritt	9410
Quixotism	9410
sweetish	9410
dogging	9410
scornfully	9410
bellow	9410
bills	9410
cupboard	9410
sureties	9410
puddings	9410
fetters	9410
bivalves	9410
incurring	9410
Adolph	9410
pithed	9410
Miles	9410
trimmings	9410
tragedies	9410
skulking	9410
flint	9410
flopping	9410
relaxing	9410
offload	9410
suites	9410
lists	9410
animized	9410
multilayer	9410
standardizes	9410
Judas	9410
vacuuming	9410
dentally	9410
humanness	9410
inch	9410
Weissmuller	9410
irresponsibly	9410
luckily	9410
culled	9410
medical	9410
bloodbath	9410
subschema	9410
animals	9410
Micronesia	9410
repetitions	9410
Antares	9410
ventilate	9410
pityingly	9410
interdependent	9410
Graves	9410
neonatal	9410
chafe	9410
honoring	9410
realtor	9410
elite	9410
funereal	9410
abrogating	9410
sorters	9410
Conley	9410
lectured	9410
Abraham	9410
Hawaii	9410
cage	9410
hushes	9410
Simla	9410
reporters	9410
Dutchman	9410
descendants	9410
groupings	9410
dissociate	9410
coexist	9410
Beebe	9410
Taoism	9410
Connally	9410
fetched	9410
checkpoints	9410
rusting	9410
galling	9410
obliterates	9410
traitor	9410
resumes	9410
analyzable	9410
terminator	9410
gritty	9410
firearm	9410
minima	9410
Selfridge	9410
disable	9410
witchcraft	9410
betroth	9410
Manhattanize	9410
imprint	9410
peeked	9410
swelling	9410
interrelationships	9410
riser	9410
Gandhian	9410
peacock	9410
bee	9410
kanji	9410
dental	9410
scarf	9410
chasm	9410
insolence	9410
syndicate	9410
alike	9410
imperial	9410
convulsion	9410
railway	9410
validate	9410
normalizes	9410
comprehensive	9410
chewing	9410
denizen	9410
schemer	9410
chronicle	9410
Kline	9410
Anatole	9410
partridges	9410
brunch	9410
recruited	9410
dimensions	9410
Chicana	9410
announced	9410
praised	9410
employing	9410
linear	9410
quagmire	9410
western	9410
relishing	9410
serving	9410
scheduling	9410
lore	9410
eventful	9410
arteriole	9410
disentangle	9410
cured	9410
Fenton	9410
avoidable	9410
drains	9410
detectably	9410
husky	9410
impelling	9410
undoes	9410
evened	9410
squeezes	9410
destroyer	9410
rudeness	9410
beaner	9410
boorish	9410
Everhart	9410
encompass	9410
mushrooms	9410
Alison	9410
externally	9410
pellagra	9410
cult	9410
creek	9410
Huffman	9410
Majorca	9410
governing	9410
gadfly	9410
reassigned	9410
intentness	9410
craziness	9410
psychic	9410
squabbled	9410
burlesque	9410
capped	9410
extracted	9410
DiMaggio	9410
exclamation	9410
subdirectory	9410
Gothicism	9410
feminine	9410
metaphysically	9410
sanding	9410
Miltonism	9410
freakish	9410
index	9410
straight	9410
flurried	9410
denotative	9410
coming	9410
commencements	9410
gentleman	9410
gifted	9410
Shanghais	9410
sportswriting	9410
sloping	9410
navies	9410
leaflet	9410
shooter	9410
Joplin	9410
babies	9410
assails	9410
admiring	9410
swaying	9410
Goldstine	9410
fitting	9410
Norwalk	9410
analogy	9410
deludes	9410
cokes	9410
Clayton	9410
exhausts	9410
causality	9410
sating	9410
icon	9410
throttles	9410
communicants	9410
dehydrate	9410
priceless	9410
publicly	9410
incidentals	9410
commonplace	9410
mumbles	9410
furthermore	9410
cautioned	9410
parametrized	9410
registration	9410
sadly	9410
positioning	9410
babysitting	9410
eternal	9410
hoarder	9410
congregates	9410
rains	9410
workers	9410
sags	9410
unplug	9410
garage	9410
boulder	9410
specifics	9410
Teresa	9410
Winsett	9410
convenient	9410
buckboards	9410
amenities	9410
resplendent	9410
sews	9410
participated	9410
Simon	9410
certificates	9410
Fitzpatrick	9410
Evanston	9410
misted	9410
textures	9410
save	9410
count	9410
rightful	9410
chaperone	9410
Lizzy	9410
clenched	9410
effortlessly	9410
accessed	9410
beaters	9410
Hornblower	9410
vests	9410
indulgences	9410
infallibly	9410
unwilling	9410
excrete	9410
spools	9410
crunches	9410
overestimating	9410
ineffective	9410
humiliation	9410
sophomore	9410
star	9410
rifles	9410
dialysis	9410
arriving	9410
indulge	9410
clockers	9410
languages	9410
Antarctica	9410
percentage	9410
ceiling	9410
specification	9410
regimented	9410
ciphers	9410
pictures	9410
serpents	9410
allot	9410
realized	9410
mayoral	9410
opaquely	9410
hostess	9410
fiftieth	9410
incorrectly	9410
decomposition	9410
stranglings	9410
mixture	9410
electroencephalography	9410
similarities	9410
charges	9410
freest	9410
Greenberg	9410
tinting	9410
expelled	9410
warm	9410
smoothed	9410
deductions	9410
Romano	9410
bitterroot	9410
corset	9410
securing	9410
environing	9410
cute	9410
Crays	9410
heiress	9410
inform	9410
avenge	9410
universals	9410
Kinsey	9410
ravines	9410
bestseller	9410
equilibrium	9410
extents	9410
relatively	9410
pressure	9410
critiques	9410
befouled	9410
rightfully	9410
mechanizing	9410
Latinizes	9410
timesharing	9410
Aden	9410
embassies	9410
males	9410
shapelessly	9410
mastering	9410
Newtonian	9410
finishers	9410
abates	9410
teem	9410
kiting	9410
stodgy	9410
feed	9410
guitars	9410
airships	9410
store	9410
denounces	9410
Pyle	9410
Saxony	9410
serializations	9410
Peruvian	9410
taxonomically	9410
kingdom	9410
stint	9410
Sault	9410
faithful	9410
Ganymede	9410
tidiness	9410
gainful	9410
contrary	9410
Tipperary	9410
tropics	9410
theorizers	9410
renew	9410
already	9410
terminal	9410
Hegelian	9410
hypothesizer	9410
warningly	9410
journalizing	9410
nested	9410
Lars	9410
saplings	9410
foothill	9410
labeled	9410
imperiously	9410
reporters	9410
furnishings	9410
precipitable	9410
discounts	9410
excises	9410
Stalin	9410
despot	9410
ripeness	9410
Arabia	9410
unruly	9410
mournfulness	9410
boom	9410
slaughter	9410
Sabine	9410
handy	9410
rural	9410
organizer	9410
shipyard	9410
civics	9410
inaccuracy	9410
rules	9410
juveniles	9410
comprised	9410
investigations	9410
stabilizes	9410
seminaries	9410
Hunter	9410
sporty	9410
test	9410
weasels	9410
CERN	9410
tempering	9410
afore	9410
Galatean	9410
techniques	9410
error	9410
veranda	9410
severely	9410
Cassites	9410
forthcoming	9410
guides	9410
vanish	9410
lied	9410
sawtooth	9410
fated	9410
gradually	9410
widens	9410
preclude	9410
evenhandedly	9410
percentage	9410
disobedience	9410
humility	9410
gleaning	9410
petted	9410
bloater	9410
minion	9410
marginal	9410
apiary	9410
measures	9410
precaution	9410
repelled	9410
primary	9410
coverings	9410
Artemia	9410
navigate	9410
spatial	9410
Gurkha	9410
meanwhile	9410
Melinda	9410
Butterfield	9410
Aldrich	9410
previewing	9410
glut	9410
unaffected	9410
inmate	9410
mineral	9410
impending	9410
meditation	9410
ideas	9410
miniaturizes	9410
lewdly	9410
title	9410
youthfulness	9410
creak	9410
Chippewa	9410
clamored	9410
freezes	9410
forgivably	9410
reduce	9410
McGovern	9410
Nazis	9410
epistle	9410
socializes	9410
conceptions	9410
Kevin	9410
uncovering	9410
chews	9410
appendixes	9410
appendixes	9410
appendixes	9410
appendixes	9410
appendixes	9410
appendixes	9410
raining	9410
infest	9410
compartment	9410
minting	9410
ducks	9410
roped	9410
waltz	9410
Lillian	9410
repressions	9410
chillingly	9410
noncritical	9410
lithograph	9410
spongers	9410
parenthood	9410
posed	9410
instruments	9410
filial	9410
fixedly	9410
relives	9410
Pandora	9410
watering	9410
ungrateful	9410
secures	9410
poison	9410
dusted	9410
encompasses	9410
presentation	9410
Kantian	9410
select fld3,period,price,price2 from t2,t3 where t2.fld1=t3.t2nr and period >= 1001 and period <= 1002 and t2.companynr = 37 order by fld3,period, price;
fld3	period	price	price2
admonishing	1002	28357832	8723648
analyzable	1002	28357832	8723648
annihilates	1001	5987435	234724
Antares	1002	28357832	8723648
astound	1001	5987435	234724
audiology	1001	5987435	234724
Augustine	1002	28357832	8723648
Baird	1002	28357832	8723648
bewilderingly	1001	5987435	234724
breaking	1001	5987435	234724
Conley	1001	5987435	234724
dentally	1002	28357832	8723648
dissociate	1002	28357832	8723648
elite	1001	5987435	234724
eschew	1001	5987435	234724
Eulerian	1001	5987435	234724
flanking	1001	5987435	234724
foldout	1002	28357832	8723648
funereal	1002	28357832	8723648
galling	1002	28357832	8723648
Graves	1001	5987435	234724
grazing	1001	5987435	234724
groupings	1001	5987435	234724
handgun	1001	5987435	234724
humility	1002	28357832	8723648
impulsive	1002	28357832	8723648
inch	1001	5987435	234724
intelligibility	1001	5987435	234724
jarring	1001	5987435	234724
lawgiver	1001	5987435	234724
lectured	1002	28357832	8723648
Merritt	1002	28357832	8723648
neonatal	1001	5987435	234724
offload	1002	28357832	8723648
parters	1002	28357832	8723648
pityingly	1002	28357832	8723648
puddings	1002	28357832	8723648
Punjab	1001	5987435	234724
quitter	1002	28357832	8723648
realtor	1001	5987435	234724
relaxing	1001	5987435	234724
repetitions	1001	5987435	234724
resumes	1001	5987435	234724
Romans	1002	28357832	8723648
rusting	1001	5987435	234724
scholastics	1001	5987435	234724
skulking	1002	28357832	8723648
stated	1002	28357832	8723648
suites	1002	28357832	8723648
sureties	1001	5987435	234724
testicle	1002	28357832	8723648
tinily	1002	28357832	8723648
tragedies	1001	5987435	234724
trimmings	1001	5987435	234724
vacuuming	1001	5987435	234724
ventilate	1001	5987435	234724
wallet	1001	5987435	234724
Weissmuller	1002	28357832	8723648
Wotan	1002	28357832	8723648
select t2.fld1,fld3,period,price,price2 from t2,t3 where t2.fld1>= 18201 and t2.fld1 <= 18811 and t2.fld1=t3.t2nr and period = 1001 and t2.companynr = 37;
fld1	fld3	period	price	price2
018201	relaxing	1001	5987435	234724
018601	vacuuming	1001	5987435	234724
018801	inch	1001	5987435	234724
018811	repetitions	1001	5987435	234724
create table t4 (
companynr tinyint(2) unsigned zerofill NOT NULL default '00',
companyname char(30) NOT NULL default '',
PRIMARY KEY (companynr),
UNIQUE KEY companyname(companyname)
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
companynr	companyname
00	Unknown
29	company 1
34	company 2
36	company 3
37	company 4
40	company 5
41	company 6
50	company 11
53	company 7
58	company 8
65	company 9
68	company 10
select SQL_SMALL_RESULT t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
companynr	companyname
00	Unknown
29	company 1
34	company 2
36	company 3
37	company 4
40	company 5
41	company 6
50	company 11
53	company 7
58	company 8
65	company 9
68	company 10
select * from t1,t1 t12;
Period	Varor_period	Period	Varor_period
9410	9412	9410	9412
select t2.fld1,t22.fld1 from t2,t2 t22 where t2.fld1 >= 250501 and t2.fld1 <= 250505 and t22.fld1 >= 250501 and t22.fld1 <= 250505;
fld1	fld1
250501	250501
250502	250501
250503	250501
250504	250501
250505	250501
250501	250502
250502	250502
250503	250502
250504	250502
250505	250502
250501	250503
250502	250503
250503	250503
250504	250503
250505	250503
250501	250504
250502	250504
250503	250504
250504	250504
250505	250504
250501	250505
250502	250505
250503	250505
250504	250505
250505	250505
insert into t2 (fld1, companynr) values (999999,99);
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
companynr	companyname
99	NULL
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
count(*)
1199
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1200	
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	Using where; Not exists
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1200	Using where; Not exists
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
companynr	companyname
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
count(*)
1200
explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
delete from t2 where fld1=999999;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	PRIMARY	NULL	NULL	NULL	12	Using where
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	PRIMARY	NULL	NULL	NULL	12	Using where
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	PRIMARY	NULL	NULL	NULL	12	Using where
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	PRIMARY	NULL	NULL	NULL	12	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	PRIMARY	NULL	NULL	NULL	12	Using where
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	PRIMARY	NULL	NULL	NULL	12	Using where
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	Using where
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
companynr	companynr
37	36
41	40
explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	index	NULL	PRIMARY	1	NULL	12	Using index; Using temporary
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where; Using join buffer (flat, BNL join)
select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008;
fld1	companynr	fld3	period
038008	37	reporters	1008
038208	37	Selfridge	1008
select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t2.fld1 = 38208 or t2.fld1 = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009;
fld1	companynr	fld3	period
038008	37	reporters	1008
038208	37	Selfridge	1008
select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t3.t2nr = 38208 or t3.t2nr = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009;
fld1	companynr	fld3	period
038008	37	reporters	1008
038208	37	Selfridge	1008
select period from t1 where (((period > 0) or period < 10000 or (period = 1900)) and (period=1900 and period <= 1901) or (period=1903 and (period=1903)) and period>=1902) or ((period=1904 or period=1905) or (period=1906 or period>1907)) or (period=1908 and period = 1909);
period
9410
select period from t1 where ((period > 0 and period < 1) or (((period > 0 and period < 100) and (period > 10)) or (period > 10)) or (period > 0 and (period > 5 or period > 6)));
period
9410
select a.fld1 from t2 as a,t2 b where ((a.fld1 = 250501 and a.fld1=b.fld1) or a.fld1=250502 or a.fld1=250503 or (a.fld1=250505 and a.fld1<=b.fld1 and b.fld1>=a.fld1)) and a.fld1=b.fld1;
fld1
250501
250502
250503
250505
select fld1 from t2 where fld1 in (250502,98005,98006,250503,250605,250606) and fld1 >=250502 and fld1 not in (250605,250606);
fld1
250502
250503
select fld1 from t2 where fld1 between 250502 and 250504;
fld1
250502
250503
250504
select fld3 from t2 where (((fld3 like "_%L%" ) or (fld3 like "%ok%")) and ( fld3 like "L%" or fld3 like "G%")) and fld3 like "L%" ;
fld3
label
labeled
labeled
landslide
laterally
leaflet
lewdly
Lillian
luckily
select count(*) from t1;
count(*)
1
select companynr,count(*),sum(fld1) from t2 group by companynr;
companynr	count(*)	sum(fld1)
00	82	10355753
29	95	14473298
34	70	17788966
36	215	22786296
37	588	83602098
40	37	6618386
41	52	12816335
50	11	1595438
53	4	793210
58	23	2254293
65	10	2284055
68	12	3097288
select companynr,count(*) from t2 group by companynr order by companynr desc limit 5;
companynr	count(*)
68	12
65	10
58	23
53	4
50	11
select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
count(*)	min(fld4)	max(fld4)	sum(fld1)	avg(fld1)	std(fld1)	variance(fld1)
70	absentee	vest	17788966	254128.0857	3272.5940	10709871.3069
explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	100.00	Using where
Warnings:
Note	1003	select count(0) AS `count(*)`,min(`test`.`t2`.`fld4`) AS `min(fld4)`,max(`test`.`t2`.`fld4`) AS `max(fld4)`,sum(`test`.`t2`.`fld1`) AS `sum(fld1)`,avg(`test`.`t2`.`fld1`) AS `avg(fld1)`,std(`test`.`t2`.`fld1`) AS `std(fld1)`,variance(`test`.`t2`.`fld1`) AS `variance(fld1)` from `test`.`t2` where `test`.`t2`.`companynr` = 34 and `test`.`t2`.`fld4` <> ''
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
companynr	count(*)	min(fld4)	max(fld4)	sum(fld1)	avg(fld1)	std(fld1)	variance(fld1)
00	82	Anthony	windmills	10355753	126289.6707	115550.9757	13352027981.7087
29	95	abut	wetness	14473298	152350.5053	8368.5480	70032594.9026
34	70	absentee	vest	17788966	254128.0857	3272.5940	10709871.3069
select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
companynr	t2nr	count(price)	sum(price)	min(price)	max(price)	avg(price)
37	1	1	5987435	5987435	5987435	5987435.0000
37	2	1	28357832	28357832	28357832	28357832.0000
37	3	1	39654943	39654943	39654943	39654943.0000
37	11	1	5987435	5987435	5987435	5987435.0000
37	12	1	28357832	28357832	28357832	28357832.0000
37	13	1	39654943	39654943	39654943	39654943.0000
37	21	1	5987435	5987435	5987435	5987435.0000
37	22	1	28357832	28357832	28357832	28357832.0000
37	23	1	39654943	39654943	39654943	39654943.0000
37	31	1	5987435	5987435	5987435	5987435.0000
select /*! SQL_SMALL_RESULT */ companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
companynr	t2nr	count(price)	sum(price)	min(price)	max(price)	avg(price)
37	1	1	5987435	5987435	5987435	5987435.0000
37	2	1	28357832	28357832	28357832	28357832.0000
37	3	1	39654943	39654943	39654943	39654943.0000
37	11	1	5987435	5987435	5987435	5987435.0000
37	12	1	28357832	28357832	28357832	28357832.0000
37	13	1	39654943	39654943	39654943	39654943.0000
37	21	1	5987435	5987435	5987435	5987435.0000
37	22	1	28357832	28357832	28357832	28357832.0000
37	23	1	39654943	39654943	39654943	39654943.0000
37	31	1	5987435	5987435	5987435	5987435.0000
select companynr,count(price),sum(price),min(price),max(price),avg(price) from t3 group by companynr ;
companynr	count(price)	sum(price)	min(price)	max(price)	avg(price)
37	12543	309394878010	5987435	39654943	24666736.6667
78	8362	414611089292	726498	98439034	49582766.0000
101	4181	3489454238	834598	834598	834598.0000
154	4181	4112197254950	983543950	983543950	983543950.0000
311	4181	979599938	234298	234298	234298.0000
447	4181	9929180954	2374834	2374834	2374834.0000
512	4181	3288532102	786542	786542	786542.0000
select distinct mod(companynr,10) from t4 group by companynr;
mod(companynr,10)
0
9
4
6
7
1
3
8
5
select distinct 1 from t4 group by companynr;
1
1
select count(distinct fld1) from t2;
count(distinct fld1)
1199
select companynr,count(distinct fld1) from t2 group by companynr;
companynr	count(distinct fld1)
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
select companynr,count(*) from t2 group by companynr;
companynr	count(*)
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
select companynr,count(distinct concat(fld1,repeat(65,1000))) from t2 group by companynr;
companynr	count(distinct concat(fld1,repeat(65,1000)))
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
select companynr,count(distinct concat(fld1,repeat(65,200))) from t2 group by companynr;
companynr	count(distinct concat(fld1,repeat(65,200)))
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
select companynr,count(distinct floor(fld1/100)) from t2 group by companynr;
companynr	count(distinct floor(fld1/100))
00	47
29	35
34	14
36	69
37	108
40	16
41	11
50	9
53	1
58	1
65	1
68	1
select companynr,count(distinct concat(repeat(65,1000),floor(fld1/100))) from t2 group by companynr;
companynr	count(distinct concat(repeat(65,1000),floor(fld1/100)))
00	47
29	35
34	14
36	69
37	108
40	16
41	11
50	9
53	1
58	1
65	1
68	1
select sum(fld1),fld3 from t2 where fld3="Romans" group by fld1 limit 10;
sum(fld1)	fld3
11402	Romans
select name,count(*) from t3 where name='cloakroom' group by name;
name	count(*)
cloakroom	4181
select name,count(*) from t3 where name='cloakroom' and price>10 group by name;
name	count(*)
cloakroom	4181
select count(*) from t3 where name='cloakroom' and price2=823742;
count(*)
4181
select name,count(*) from t3 where name='cloakroom' and price2=823742 group by name;
name	count(*)
cloakroom	4181
select name,count(*) from t3 where name >= "extramarital" and price <= 39654943 group by name;
name	count(*)
extramarital	4181
gazer	4181
gems	4181
Iranizes	4181
spates	4181
tucked	4181
violinist	4181
select t2.fld3,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
fld3	count(*)
spates	4181
select companynr|0,companyname from t4 group by 1;
companynr|0	companyname
0	Unknown
29	company 1
34	company 2
36	company 3
37	company 4
40	company 5
41	company 6
50	company 11
53	company 7
58	company 8
65	company 9
68	company 10
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname;
companynr	companyname	count(*)
29	company 1	95
68	company 10	12
50	company 11	11
34	company 2	70
36	company 3	215
37	company 4	588
40	company 5	37
41	company 6	52
53	company 7	4
58	company 8	23
65	company 9	10
00	Unknown	82
select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
fld1	count(*)
158402	4181
select sum(Period)/count(*) from t1;
sum(Period)/count(*)
9410.0000
select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr;
companynr	count	sum	diff	func
37	12543	309394878010	0.0000	464091
78	8362	414611089292	0.0000	652236
101	4181	3489454238	0.0000	422281
154	4181	4112197254950	0.0000	643874
311	4181	979599938	0.0000	1300291
447	4181	9929180954	0.0000	1868907
512	4181	3288532102	0.0000	2140672
select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;
companynr	avg
154	983543950.0000
select companynr,count(*) from t2 group by companynr order by 2 desc;
companynr	count(*)
37	588
36	215
29	95
00	82
34	70
41	52
40	37
58	23
68	12
50	11
65	10
53	4
select companynr,count(*) from t2 where companynr > 40 group by companynr order by 2 desc;
companynr	count(*)
41	52
58	23
68	12
50	11
65	10
53	4
select t2.fld4,t2.fld1,count(price),sum(price),min(price),max(price),avg(price) from t3,t2 where t3.companynr = 37 and t2.fld1 = t3.t2nr group by fld1,t2.fld4;
fld4	fld1	count(price)	sum(price)	min(price)	max(price)	avg(price)
teethe	000001	1	5987435	5987435	5987435	5987435.0000
dreaded	011401	1	5987435	5987435	5987435	5987435.0000
scholastics	011402	1	28357832	28357832	28357832	28357832.0000
audiology	011403	1	39654943	39654943	39654943	39654943.0000
wallet	011501	1	5987435	5987435	5987435	5987435.0000
parters	011701	1	5987435	5987435	5987435	5987435.0000
eschew	011702	1	28357832	28357832	28357832	28357832.0000
quitter	011703	1	39654943	39654943	39654943	39654943.0000
neat	012001	1	5987435	5987435	5987435	5987435.0000
Steinberg	012003	1	39654943	39654943	39654943	39654943.0000
balled	012301	1	5987435	5987435	5987435	5987435.0000
persist	012302	1	28357832	28357832	28357832	28357832.0000
attainments	012303	1	39654943	39654943	39654943	39654943.0000
capably	012501	1	5987435	5987435	5987435	5987435.0000
impulsive	012602	1	28357832	28357832	28357832	28357832.0000
starlet	012603	1	39654943	39654943	39654943	39654943.0000
featherweight	012701	1	5987435	5987435	5987435	5987435.0000
pessimist	012702	1	28357832	28357832	28357832	28357832.0000
daughter	012703	1	39654943	39654943	39654943	39654943.0000
lawgiver	013601	1	5987435	5987435	5987435	5987435.0000
stated	013602	1	28357832	28357832	28357832	28357832.0000
readable	013603	1	39654943	39654943	39654943	39654943.0000
testicle	013801	1	5987435	5987435	5987435	5987435.0000
Parsifal	013802	1	28357832	28357832	28357832	28357832.0000
leavings	013803	1	39654943	39654943	39654943	39654943.0000
squeaking	013901	1	5987435	5987435	5987435	5987435.0000
contrasted	016001	1	5987435	5987435	5987435	5987435.0000
leftover	016201	1	5987435	5987435	5987435	5987435.0000
whiteners	016202	1	28357832	28357832	28357832	28357832.0000
erases	016301	1	5987435	5987435	5987435	5987435.0000
Punjab	016302	1	28357832	28357832	28357832	28357832.0000
Merritt	016303	1	39654943	39654943	39654943	39654943.0000
sweetish	018001	1	5987435	5987435	5987435	5987435.0000
dogging	018002	1	28357832	28357832	28357832	28357832.0000
scornfully	018003	1	39654943	39654943	39654943	39654943.0000
fetters	018012	1	28357832	28357832	28357832	28357832.0000
bivalves	018013	1	39654943	39654943	39654943	39654943.0000
skulking	018021	1	5987435	5987435	5987435	5987435.0000
flint	018022	1	28357832	28357832	28357832	28357832.0000
flopping	018023	1	39654943	39654943	39654943	39654943.0000
Judas	018032	1	28357832	28357832	28357832	28357832.0000
vacuuming	018033	1	39654943	39654943	39654943	39654943.0000
medical	018041	1	5987435	5987435	5987435	5987435.0000
bloodbath	018042	1	28357832	28357832	28357832	28357832.0000
subschema	018043	1	39654943	39654943	39654943	39654943.0000
interdependent	018051	1	5987435	5987435	5987435	5987435.0000
Graves	018052	1	28357832	28357832	28357832	28357832.0000
neonatal	018053	1	39654943	39654943	39654943	39654943.0000
sorters	018061	1	5987435	5987435	5987435	5987435.0000
epistle	018062	1	28357832	28357832	28357832	28357832.0000
Conley	018101	1	5987435	5987435	5987435	5987435.0000
lectured	018102	1	28357832	28357832	28357832	28357832.0000
Abraham	018103	1	39654943	39654943	39654943	39654943.0000
cage	018201	1	5987435	5987435	5987435	5987435.0000
hushes	018202	1	28357832	28357832	28357832	28357832.0000
Simla	018402	1	28357832	28357832	28357832	28357832.0000
reporters	018403	1	39654943	39654943	39654943	39654943.0000
coexist	018601	1	5987435	5987435	5987435	5987435.0000
Beebe	018602	1	28357832	28357832	28357832	28357832.0000
Taoism	018603	1	39654943	39654943	39654943	39654943.0000
Connally	018801	1	5987435	5987435	5987435	5987435.0000
fetched	018802	1	28357832	28357832	28357832	28357832.0000
checkpoints	018803	1	39654943	39654943	39654943	39654943.0000
gritty	018811	1	5987435	5987435	5987435	5987435.0000
firearm	018812	1	28357832	28357832	28357832	28357832.0000
minima	019101	1	5987435	5987435	5987435	5987435.0000
Selfridge	019102	1	28357832	28357832	28357832	28357832.0000
disable	019103	1	39654943	39654943	39654943	39654943.0000
witchcraft	019201	1	5987435	5987435	5987435	5987435.0000
betroth	030501	1	5987435	5987435	5987435	5987435.0000
Manhattanize	030502	1	28357832	28357832	28357832	28357832.0000
imprint	030503	1	39654943	39654943	39654943	39654943.0000
swelling	031901	1	5987435	5987435	5987435	5987435.0000
interrelationships	036001	1	5987435	5987435	5987435	5987435.0000
riser	036002	1	28357832	28357832	28357832	28357832.0000
bee	038001	1	5987435	5987435	5987435	5987435.0000
kanji	038002	1	28357832	28357832	28357832	28357832.0000
dental	038003	1	39654943	39654943	39654943	39654943.0000
railway	038011	1	5987435	5987435	5987435	5987435.0000
validate	038012	1	28357832	28357832	28357832	28357832.0000
normalizes	038013	1	39654943	39654943	39654943	39654943.0000
Kline	038101	1	5987435	5987435	5987435	5987435.0000
Anatole	038102	1	28357832	28357832	28357832	28357832.0000
partridges	038103	1	39654943	39654943	39654943	39654943.0000
recruited	038201	1	5987435	5987435	5987435	5987435.0000
dimensions	038202	1	28357832	28357832	28357832	28357832.0000
Chicana	038203	1	39654943	39654943	39654943	39654943.0000
select t3.companynr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 group by companynr,fld3;
companynr	fld3	sum(price)
512	boat	786542
512	capably	786542
512	cupboard	786542
512	decliner	786542
512	descendants	786542
512	dopers	786542
512	erases	786542
512	Micronesia	786542
512	Miles	786542
512	skies	786542
select t2.companynr,count(*),min(fld3),max(fld3),sum(price),avg(price) from t2,t3 where t3.companynr >= 30 and t3.companynr <= 58 and t3.t2nr = t2.fld1 and 1+1=2 group by t2.companynr;
companynr	count(*)	min(fld3)	max(fld3)	sum(price)	avg(price)
00	1	Omaha	Omaha	5987435	5987435.0000
36	1	dubbed	dubbed	28357832	28357832.0000
37	83	Abraham	Wotan	1908978016	22999735.1325
50	2	scribbled	tapestry	68012775	34006387.5000
select t3.companynr+0,t3.t2nr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 37 group by 1,t3.t2nr,fld3,fld3,fld3,fld3,fld3 order by fld1;
t3.companynr+0	t2nr	fld3	sum(price)
37	1	Omaha	5987435
37	11401	breaking	5987435
37	11402	Romans	28357832
37	11403	intercepted	39654943
37	11501	bewilderingly	5987435
37	11701	astound	5987435
37	11702	admonishing	28357832
37	11703	sumac	39654943
37	12001	flanking	5987435
37	12003	combed	39654943
37	12301	Eulerian	5987435
37	12302	dubbed	28357832
37	12303	Kane	39654943
37	12501	annihilates	5987435
37	12602	Wotan	28357832
37	12603	snatching	39654943
37	12701	grazing	5987435
37	12702	Baird	28357832
37	12703	celery	39654943
37	13601	handgun	5987435
37	13602	foldout	28357832
37	13603	mystic	39654943
37	13801	intelligibility	5987435
37	13802	Augustine	28357832
37	13803	teethe	39654943
37	13901	scholastics	5987435
37	16001	audiology	5987435
37	16201	wallet	5987435
37	16202	parters	28357832
37	16301	eschew	5987435
37	16302	quitter	28357832
37	16303	neat	39654943
37	18001	jarring	5987435
37	18002	tinily	28357832
37	18003	balled	39654943
37	18012	impulsive	28357832
37	18013	starlet	39654943
37	18021	lawgiver	5987435
37	18022	stated	28357832
37	18023	readable	39654943
37	18032	testicle	28357832
37	18033	Parsifal	39654943
37	18041	Punjab	5987435
37	18042	Merritt	28357832
37	18043	Quixotism	39654943
37	18051	sureties	5987435
37	18052	puddings	28357832
37	18053	tapestry	39654943
37	18061	trimmings	5987435
37	18062	humility	28357832
37	18101	tragedies	5987435
37	18102	skulking	28357832
37	18103	flint	39654943
37	18201	relaxing	5987435
37	18202	offload	28357832
37	18402	suites	28357832
37	18403	lists	39654943
37	18601	vacuuming	5987435
37	18602	dentally	28357832
37	18603	humanness	39654943
37	18801	inch	5987435
37	18802	Weissmuller	28357832
37	18803	irresponsibly	39654943
37	18811	repetitions	5987435
37	18812	Antares	28357832
37	19101	ventilate	5987435
37	19102	pityingly	28357832
37	19103	interdependent	39654943
37	19201	Graves	5987435
37	30501	neonatal	5987435
37	30502	scribbled	28357832
37	30503	chafe	39654943
37	31901	realtor	5987435
37	36001	elite	5987435
37	36002	funereal	28357832
37	38001	Conley	5987435
37	38002	lectured	28357832
37	38003	Abraham	39654943
37	38011	groupings	5987435
37	38012	dissociate	28357832
37	38013	coexist	39654943
37	38101	rusting	5987435
37	38102	galling	28357832
37	38103	obliterates	39654943
37	38201	resumes	5987435
37	38202	analyzable	28357832
37	38203	terminator	39654943
select sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1= t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008;
sum(price)
234298
select t2.fld1,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1 = t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008 or t3.t2nr = t2.fld1 and t2.fld1 = 38008 group by t2.fld1;
fld1	sum(price)
038008	234298
explain select fld3 from t2 where 1>2 or 2>3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
explain select fld3 from t2 where fld1=fld1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502;
companynr	fld1
34	250501
34	250502
select companynr,fld1 from t2 WHERE fld1>=250501 HAVING fld1<=250502;
companynr	fld1
34	250501
34	250502
select companynr,count(*) as count,sum(fld1) as sum from t2 group by companynr having count > 40 and sum/count >= 120000;
companynr	count	sum
00	82	10355753
29	95	14473298
34	70	17788966
37	588	83602098
41	52	12816335
select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ;
companynr
00
29
34
37
41
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40;
companynr	companyname	count(*)
68	company 10	12
50	company 11	11
40	company 5	37
41	company 6	52
53	company 7	4
58	company 8	23
65	company 9	10
select count(*) from t2;
count(*)
1199
select count(*) from t2 where fld1 < 098024;
count(*)
387
select min(fld1) from t2 where fld1>= 098024;
min(fld1)
98024
select max(fld1) from t2 where fld1>= 098024;
max(fld1)
1232609
select count(*) from t3 where price2=76234234;
count(*)
4181
select count(*) from t3 where companynr=512 and price2=76234234;
count(*)
4181
explain select min(fld1),max(fld1),count(*) from t2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
select min(fld1),max(fld1),count(*) from t2;
min(fld1)	max(fld1)	count(*)
0	1232609	1199
select min(t2nr),max(t2nr) from t3 where t2nr=2115 and price2=823742;
min(t2nr)	max(t2nr)
2115	2115
select count(*),min(t2nr),max(t2nr) from t3 where name='spates' and companynr=78;
count(*)	min(t2nr)	max(t2nr)
4181	4	41804
select t2nr,count(*) from t3 where name='gems' group by t2nr limit 20;
t2nr	count(*)
9	1
19	1
29	1
39	1
49	1
59	1
69	1
79	1
89	1
99	1
109	1
119	1
129	1
139	1
149	1
159	1
169	1
179	1
189	1
199	1
select max(t2nr) from t3 where price=983543950;
max(t2nr)
41807
select t1.period from t3 = t1 limit 1;
period
1001
select t1.period from t1 as t1 limit 1;
period
9410
select t1.period as "Nuvarande period" from t1 as t1 limit 1;
Nuvarande period
9410
select period as ok_period from t1 limit 1;
ok_period
9410
select period as ok_period from t1 group by ok_period limit 1;
ok_period
9410
select 1+1 as summa from t1 group by summa limit 1;
summa
2
select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1;
Nuvarande period
9410
show tables;
Tables_in_test
t1
t2
t3
t4
show tables from test like "s%";
Tables_in_test (s%)
show tables from test like "t?";
Tables_in_test (t?)
show full columns from t2;
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
auto	int(11)	NULL	NO	PRI	NULL	auto_increment	#	
fld1	int(6) unsigned zerofill	NULL	NO	UNI	000000		#	
companynr	tinyint(2) unsigned zerofill	NULL	NO		00		#	
fld3	char(30)	latin1_swedish_ci	NO	MUL			#	
fld4	char(35)	latin1_swedish_ci	NO				#	
fld5	char(35)	latin1_swedish_ci	NO				#	
fld6	char(4)	latin1_swedish_ci	NO				#	
show full columns from t2 from test like 'f%';
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
fld1	int(6) unsigned zerofill	NULL	NO	UNI	000000		#	
fld3	char(30)	latin1_swedish_ci	NO	MUL			#	
fld4	char(35)	latin1_swedish_ci	NO				#	
fld5	char(35)	latin1_swedish_ci	NO				#	
fld6	char(4)	latin1_swedish_ci	NO				#	
show full columns from t2 from test like 's%';
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
show keys from t2;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
t2	0	PRIMARY	1	auto	A	1199	NULL	NULL		BTREE		
t2	0	fld1	1	fld1	A	1199	NULL	NULL		BTREE		
t2	1	fld3	1	fld3	A	NULL	NULL	NULL		BTREE		
drop table t4, t3, t2, t1;
DO 1;
DO benchmark(100,1+1),1,1;
do default;
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 '' at line 1
do foobar;
ERROR 42S22: Unknown column 'foobar' in 'field list'
CREATE TABLE t1 (
id mediumint(8) unsigned NOT NULL auto_increment,
pseudo varchar(35) NOT NULL default '',
PRIMARY KEY  (id),
UNIQUE KEY pseudo (pseudo)
);
INSERT INTO t1 (pseudo) VALUES ('test');
INSERT INTO t1 (pseudo) VALUES ('test1');
SELECT 1 as rnd1 from t1 where rand() > 2;
rnd1
DROP TABLE t1;
CREATE TABLE t1 (gvid int(10) unsigned default NULL,  hmid int(10) unsigned default NULL,  volid int(10) unsigned default NULL,  mmid int(10) unsigned default NULL,  hdid int(10) unsigned default NULL,  fsid int(10) unsigned default NULL,  ctid int(10) unsigned default NULL,  dtid int(10) unsigned default NULL,  cost int(10) unsigned default NULL,  performance int(10) unsigned default NULL,  serialnumber bigint(20) unsigned default NULL,  monitored tinyint(3) unsigned default '1',  removed tinyint(3) unsigned default '0',  target tinyint(3) unsigned default '0',  dt_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  name varchar(255) binary default NULL,  description varchar(255) default NULL,  UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
CREATE TABLE t2 (  hmid int(10) unsigned default NULL,  volid int(10) unsigned default NULL,  sampletid smallint(5) unsigned default NULL,  sampletime datetime default NULL,  samplevalue bigint(20) unsigned default NULL,  KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
gvid	the_success	the_fail	the_size	the_time
Warnings:
Warning	1292	Truncated incorrect datetime value: 'wrong-date-value'
Warning	1292	Truncated incorrect datetime value: 'wrong-date-value'
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
gvid	the_success	the_fail	the_size	the_time
DROP TABLE t1,t2;
create table  t1 (  A_Id bigint(20) NOT NULL default '0',  A_UpdateBy char(10) NOT NULL default '',  A_UpdateDate bigint(20) NOT NULL default '0',  A_UpdateSerial int(11) NOT NULL default '0',  other_types bigint(20) NOT NULL default '0',  wss_type bigint(20) NOT NULL default '0');
INSERT INTO t1 VALUES (102935998719055004,'brade',1029359987,2,102935229116544068,102935229216544093);
select wss_type from t1 where wss_type ='102935229216544106';
wss_type
select wss_type from t1 where wss_type ='102935229216544105';
wss_type
select wss_type from t1 where wss_type ='102935229216544104';
wss_type
select wss_type from t1 where wss_type ='102935229216544093';
wss_type
102935229216544093
select wss_type from t1 where wss_type =102935229216544093;
wss_type
102935229216544093
drop table t1;
select 1+2,"aaaa",3.13*2.0 into @a,@b,@c;
select @a;
@a
3
select @b;
@b
aaaa
select @c;
@c
6.260
create table t1 (a int not null auto_increment primary key);
insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
a	a
1	1
2	1
3	1
1	2
2	2
3	2
1	3
2	3
3	3
select * from t1, (t1 as t2 left join t1 as t3 using (a));
a	a
1	1
2	1
3	1
1	2
2	2
3	2
1	3
2	3
3	3
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
a	a
1	1
2	1
3	1
1	2
2	2
3	2
1	3
2	3
3	3
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
a	a
1	1
2	1
3	1
1	2
2	2
3	2
1	3
2	3
3	3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
a	a
1	2
1	3
2	2
2	3
3	2
3	3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a	a
2	1
3	1
2	2
3	2
2	3
3	3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
a
1
2
3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
a	a
1	2
1	3
2	2
2	3
3	2
3	3
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a	a
1	NULL
2	1
2	2
2	3
3	1
3	2
3	3
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
a
1
2
3
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
a
1
2
3
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
a	a
1	2
1	3
2	2
2	3
3	2
3	3
NULL	1
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a	a
2	1
2	2
2	3
3	1
3	2
3	3
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
a
1
2
3
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
a
1
2
3
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
a
1
2
3
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
a
1
2
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
a
1
2
3
drop table t1;
CREATE TABLE t1 (  aa char(2),  id int(11) NOT NULL auto_increment,  t2_id int(11) NOT NULL default '0',  PRIMARY KEY  (id),  KEY replace_id (t2_id)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ("1",8264,2506),("2",8299,2517),("3",8301,2518),("4",8302,2519),("5",8303,2520),("6",8304,2521),("7",8305,2522);
CREATE TABLE t2 ( id int(11) NOT NULL auto_increment,  PRIMARY KEY  (id)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0   order by t1.id   LIMIT 0, 5;
aa	id	t2_id	id
2	8299	2517	2517
3	8301	2518	2518
4	8302	2519	2519
5	8303	2520	2520
6	8304	2521	2521
drop table t1,t2;
create table t1 (id1 int NOT NULL);
create table t2 (id2 int NOT NULL);
create table t3 (id3 int NOT NULL);
create table t4 (id4 int NOT NULL, id44 int NOT NULL, KEY (id4));
insert into t1 values (1);
insert into t1 values (2);
insert into t2 values (1);
insert into t4 values (1,1);
explain select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	system	NULL	NULL	NULL	NULL	0	Const row not found
1	SIMPLE	t4	const	id4	NULL	NULL	NULL	1	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where
select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
id1	id2	id3	id4	id44
1	1	NULL	NULL	NULL
drop table t1,t2,t3,t4;
create table t1(s varchar(10) not null);
create table t2(s varchar(10) not null primary key);
create table t3(s varchar(10) not null primary key);
insert into t1 values ('one\t'), ('two\t');
insert into t2 values ('one\r'), ('two\t');
insert into t3 values ('one '), ('two\t');
select * from t1 where s = 'one';
s
select * from t2 where s = 'one';
s
select * from t3 where s = 'one';
s
one 
select * from t1,t2 where t1.s = t2.s;
s	s
two		two	
select * from t2,t3 where t2.s = t3.s;
s	s
two		two	
drop table t1, t2, t3;
create table t1 (a integer,  b integer, index(a), index(b));
create table t2 (c integer,  d integer, index(c), index(d));
insert into t1 values (1,2), (2,2), (3,2), (4,2);
insert into t2 values (1,3), (2,3), (3,4), (4,4);
explain select * from t1 left join t2 on a=c where d in (4);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	c,d	d	5	const	2	
1	SIMPLE	t1	ALL	a	NULL	NULL	NULL	4	Using where; Using join buffer (flat, BNL join)
select * from t1 left join t2 on a=c where d in (4);
a	b	c	d
3	2	3	4
4	2	4	4
explain select * from t1 left join t2 on a=c where d = 4;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	c,d	d	5	const	2	
1	SIMPLE	t1	ALL	a	NULL	NULL	NULL	4	Using where; Using join buffer (flat, BNL join)
select * from t1 left join t2 on a=c where d = 4;
a	b	c	d
3	2	3	4
4	2	4	4
drop table t1, t2;
CREATE TABLE t1 (
i int(11) NOT NULL default '0',
c char(10) NOT NULL default '',
PRIMARY KEY  (i),
UNIQUE KEY c (c)
) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,'a');
INSERT INTO t1 VALUES (2,'b');
INSERT INTO t1 VALUES (3,'c');
EXPLAIN SELECT i FROM t1 WHERE i=1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
DROP TABLE t1;
CREATE TABLE t1 ( a BLOB, INDEX (a(20)) );
CREATE TABLE t2 ( a BLOB, INDEX (a(20)) );
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
1	SIMPLE	t2	ref	a	a	23	test.t1.a	2	Using where
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
1	SIMPLE	t2	ref	a	a	23	test.t1.a	2	Using where
DROP TABLE t1, t2;
CREATE TABLE t1 ( city char(30) );
INSERT INTO t1 VALUES ('London');
INSERT INTO t1 VALUES ('Paris');
SELECT * FROM t1 WHERE city='London';
city
London
SELECT * FROM t1 WHERE city='london';
city
London
EXPLAIN SELECT * FROM t1 WHERE city='London' AND city='london';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
SELECT * FROM t1 WHERE city='London' AND city='london';
city
London
EXPLAIN SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
city
London
DROP TABLE t1;
create table t1 (a int(11) unsigned, b int(11) unsigned);
insert into t1 values (1,0), (1,1), (18446744073709551615,0);
Warnings:
Warning	1264	Out of range value for column 'a' at row 3
select a-b  from t1 order by 1;
a-b
0
1
4294967295
select a-b , (a-b < 0)  from t1 order by 1;
a-b	(a-b < 0)
0	0
1	0
4294967295	0
select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;
d	(a-b >= 0)	b
1	1	0
0	1	1
select cast((a - b) as unsigned) from t1 order by 1;
cast((a - b) as unsigned)
0
1
4294967295
drop table t1;
create table t1 (a int(11));
select all all * from t1;
a
select distinct distinct * from t1;
a
select all distinct * from t1;
ERROR HY000: Incorrect usage of ALL and DISTINCT
select distinct all * from t1;
ERROR HY000: Incorrect usage of ALL and DISTINCT
drop table t1;
CREATE TABLE t1 (
kunde_intern_id int(10) unsigned NOT NULL default '0',
kunde_id int(10) unsigned NOT NULL default '0',
FK_firma_id int(10) unsigned NOT NULL default '0',
aktuell enum('Ja','Nein') NOT NULL default 'Ja',
vorname varchar(128) NOT NULL default '',
nachname varchar(128) NOT NULL default '',
geloescht enum('Ja','Nein') NOT NULL default 'Nein',
firma varchar(128) NOT NULL default ''
);
INSERT INTO t1 VALUES 
(3964,3051,1,'Ja','Vorname1','1Nachname','Nein','Print Schau XXXX'),
(3965,3051111,1,'Ja','Vorname1111','1111Nachname','Nein','Print Schau XXXX');
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname, geloescht FROM t1
WHERE
(
(
( '' != '' AND firma LIKE CONCAT('%', '', '%'))
OR
(vorname LIKE CONCAT('%', 'Vorname1', '%') AND 
nachname LIKE CONCAT('%', '1Nachname', '%') AND 
'Vorname1' != '' AND 'xxxx' != '')
)
AND
(
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
)
)
;
kunde_id	FK_firma_id	aktuell	vorname	nachname	geloescht
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname,
geloescht FROM t1
WHERE
(
(
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
)
AND
(
( '' != '' AND firma LIKE CONCAT('%', '', '%')  )
OR
(  vorname LIKE CONCAT('%', 'Vorname1', '%') AND
nachname LIKE CONCAT('%', '1Nachname', '%') AND 'Vorname1' != '' AND
'xxxx' != '')
)
)
;
kunde_id	FK_firma_id	aktuell	vorname	nachname	geloescht
SELECT COUNT(*) FROM t1 WHERE 
( 0 OR (vorname LIKE '%Vorname1%' AND nachname LIKE '%1Nachname%' AND 1)) 
AND FK_firma_id = 2;
COUNT(*)
0
drop table t1;
CREATE TABLE t1 (b BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY (b));
INSERT INTO t1 VALUES (0x8000000000000000);
SELECT b FROM t1 WHERE b=0x8000000000000000;
b
9223372036854775808
DROP TABLE t1;
CREATE TABLE `t1` ( `gid` int(11) default NULL, `uid` int(11) default NULL);
CREATE TABLE `t2` ( `ident` int(11) default NULL, `level` char(16) default NULL);
INSERT INTO `t2` VALUES (0,'READ');
CREATE TABLE `t3` ( `id` int(11) default NULL, `name` char(16) default NULL);
INSERT INTO `t3` VALUES (1,'fs');
select * from t3 left join t1 on t3.id = t1.uid, t2 where t2.ident in (0, t1.gid, t3.id, 0);
id	name	gid	uid	ident	level
1	fs	NULL	NULL	0	READ
drop table t1,t2,t3;
CREATE TABLE t1 (
acct_id int(11) NOT NULL default '0',
profile_id smallint(6) default NULL,
UNIQUE KEY t1$acct_id (acct_id),
KEY t1$profile_id (profile_id)
);
INSERT INTO t1 VALUES (132,17),(133,18);
CREATE TABLE t2 (
profile_id smallint(6) default NULL,
queue_id int(11) default NULL,
seq int(11) default NULL,
KEY t2$queue_id (queue_id)
);
INSERT INTO t2 VALUES (17,31,4),(17,30,3),(17,36,2),(17,37,1);
CREATE TABLE t3 (
id int(11) NOT NULL default '0',
qtype int(11) default NULL,
seq int(11) default NULL,
warn_lvl int(11) default NULL,
crit_lvl int(11) default NULL,
rr1 tinyint(4) NOT NULL default '0',
rr2 int(11) default NULL,
default_queue tinyint(4) NOT NULL default '0',
KEY t3$qtype (qtype),
KEY t3$id (id)
);
INSERT INTO t3 VALUES (30,1,29,NULL,NULL,0,NULL,0),(31,1,28,NULL,NULL,0,NULL,0),
(36,1,34,NULL,NULL,0,NULL,0),(37,1,35,NULL,NULL,0,121,0);
SELECT COUNT(*) FROM t1 a STRAIGHT_JOIN t2 pq STRAIGHT_JOIN t3 q 
WHERE 
(pq.profile_id = a.profile_id) AND (a.acct_id = 132) AND 
(pq.queue_id = q.id) AND (q.rr1 <> 1);
COUNT(*)
4
drop table t1,t2,t3;
create table t1 (f1 int);
insert into t1 values (1),(NULL);
create table t2 (f2 int, f3 int, f4 int);
create index idx1 on t2 (f4);
insert into t2 values (1,2,3),(2,4,6);
select A.f2 from t1 left join t2 A on A.f2 = f1 where A.f3=(select min(f3)
from  t2 C where A.f4 = C.f4) or A.f3 IS NULL;
f2
1
NULL
drop table t1,t2;
create table t2 (a tinyint unsigned);
create index t2i on t2(a);
insert into t2 values (0), (254), (255);
explain select * from t2 where a > -1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	index	t2i	t2i	2	NULL	3	Using where; Using index
select * from t2 where a > -1;
a
0
254
255
drop table t2;
CREATE TABLE t1 (a int, b int, c int);
INSERT INTO t1
SELECT 50, 3, 3 FROM DUAL
WHERE NOT EXISTS
(SELECT * FROM t1 WHERE a = 50 AND b = 3);
SELECT * FROM t1;
a	b	c
50	3	3
INSERT INTO t1
SELECT 50, 3, 3 FROM DUAL
WHERE NOT EXISTS
(SELECT * FROM t1 WHERE a = 50 AND b = 3);
select found_rows();
found_rows()
0
SELECT * FROM t1;
a	b	c
50	3	3
select count(*) from t1;
count(*)
1
select found_rows();
found_rows()
1
select count(*) from t1 limit 2,3;
count(*)
select found_rows();
found_rows()
0
select SQL_CALC_FOUND_ROWS count(*) from t1 limit 2,3;
count(*)
select found_rows();
found_rows()
1
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT);
(SELECT a, b AS c FROM t1) ORDER BY c+1;
a	c
(SELECT a, b AS c FROM t1) ORDER BY b+1;
a	c
SELECT a, b AS c FROM t1 ORDER BY c+1;
a	c
SELECT a, b AS c FROM t1 ORDER BY b+1;
a	c
drop table t1;
create table t1(f1 int, f2 int);
create table t2(f3 int);
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,1));
f1
select f1 from t1,t2 where f1=f2 and (f1,NULL) = ((1,1));
f1
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,NULL));
f1
insert into t1 values(1,1),(2,null);
insert into t2 values(2);
select * from t1,t2 where f1=f3 and (f1,f2) = (2,null);
f1	f2	f3
select * from t1,t2 where f1=f3 and (f1,f2) <=> (2,null);
f1	f2	f3
2	NULL	2
drop table t1,t2;
create table t1 (f1 int not null auto_increment primary key, f2 varchar(10));
create table t11 like t1;
insert into t1 values(1,""),(2,"");
show table status like 't1%';
Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment	Max_index_length	Temporary
t1	MyISAM	10	Dynamic	2	20	X	X	X	X	X	X	X	X	latin1_swedish_ci	NULL			X	N
t11	MyISAM	10	Dynamic	0	0	X	X	X	X	X	X	X	X	latin1_swedish_ci	NULL			X	N
select 123 as a from t1 where f1 is null;
a
drop table t1,t11;
CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, UNIQUE idx (a,b) );
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4);
CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, e INT );
INSERT INTO t2 VALUES ( 1,10,1), (1,10,2), (1,11,1), (1,11,2), (1,2,1), (1,2,2),(1,2,3);
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN
t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c;
a	b	c	d
1	2	1	1
1	2	2	1
1	2	3	1
1	10		2
1	11		2
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN
t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t1.a, t1.b, c;
a	b	c	d
1	10		4
1	2	1	1
1	2	2	1
1	2	3	1
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN
t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t2.a, t2.b, c;
a	b	c	d
1	2	1	1
1	2	2	1
1	2	3	1
1	10		2
1	11		2
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2,t1
WHERE t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c;
a	b	c	d
1	2	1	1
1	2	2	1
1	2	3	1
DROP TABLE IF EXISTS t1, t2;
create table t1 (f1 int primary key, f2 int);
create table t2 (f3 int, f4 int, primary key(f3,f4));
insert into t1 values (1,1);
insert into t2 values (1,1),(1,2);
select distinct count(f2) >0 from t1 left join t2 on f1=f3 group by f1;
count(f2) >0
1
drop table t1,t2;
create table t1 (f1 int,f2 int);
insert into t1 values(1,1);
create table t2 (f3 int, f4 int, primary key(f3,f4));
insert into t2 values(1,1);
select * from t1 where f1 in (select f3 from t2 where (f3,f4)= (select f3,f4 from t2));
f1	f2
1	1
drop table t1,t2;
CREATE TABLE t1(a int, b int, c int, KEY b(b), KEY c(c));
insert into t1 values (1,0,0),(2,0,0);
CREATE TABLE t2 (a int, b varchar(2), c varchar(2), PRIMARY KEY(a));
insert into t2 values (1,'',''), (2,'','');
CREATE TABLE t3 (a int, b int, PRIMARY KEY (a,b), KEY a (a), KEY b (b));
insert into t3 values (1,1),(1,2);
explain select straight_join DISTINCT t2.a,t2.b, t1.c from t1, t3, t2 
where (t1.c=t2.a or (t1.c=t3.a and t2.a=t3.b)) and t1.b=556476786 and 
t2.b like '%%' order by t2.b limit 0,1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	b,c	b	5	const	1	Using temporary; Using filesort
1	SIMPLE	t3	index	PRIMARY,a,b	PRIMARY	8	NULL	2	Using index; Using join buffer (flat, BNL join)
1	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	2	Range checked for each record (index map: 0x1)
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (a int, INDEX idx(a));
INSERT INTO t1 VALUES (2), (3), (1);
EXPLAIN SELECT * FROM t1 IGNORE INDEX (idx);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
EXPLAIN SELECT * FROM t1 IGNORE INDEX (a);
ERROR 42000: Key 'a' doesn't exist in table 't1'
EXPLAIN SELECT * FROM t1 FORCE INDEX (a);
ERROR 42000: Key 'a' doesn't exist in table 't1'
DROP TABLE t1;
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (1,1), (2,1), (4,10);
CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b));
INSERT INTO t2 VALUES (1,NULL), (2,10);
ALTER TABLE t1 ENABLE KEYS;
EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	index	b	b	5	NULL	2	Using index
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (flat, BNL join)
SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
a	b	a	b
1	NULL	1	1
1	NULL	2	1
1	NULL	4	10
2	10	4	10
EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	index	b	b	5	NULL	2	Using index
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (flat, BNL join)
SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
a	b	a	b
1	NULL	1	1
1	NULL	2	1
1	NULL	4	10
2	10	4	10
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1));
CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2));
INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941);
INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941);
explain select max(key1) from t1 where key1 <= 0.6158;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
explain select max(key2) from t2 where key2 <= 1.6158;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
explain select min(key1) from t1 where key1 >= 0.3762;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
explain select min(key2) from t2 where key2 >= 1.3762;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
explain select max(key1), min(key2) from t1, t2
where key1 <= 0.6158 and key2 >= 1.3762;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	key1	key1	5	NULL	3	Using where; Using index
explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	key1	key1	5	NULL	3	Using where; Using index
select max(key1) from t1 where key1 <= 0.6158;
max(key1)
0.6158
select max(key2) from t2 where key2 <= 1.6158;
max(key2)
1.6158
select min(key1) from t1 where key1 >= 0.3762;
min(key1)
0.3762
select min(key2) from t2 where key2 >= 1.3762;
min(key2)
1.3762
select max(key1), min(key2) from t1, t2
where key1 <= 0.6158 and key2 >= 1.3762;
max(key1)	min(key2)
0.6158	1.3762
select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
max(key1)
0.3845
select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
min(key1)
0.3845
DROP TABLE t1,t2;
CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
INSERT INTO t1 VALUES (10);
SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1;
i='1e+01'	i=1e+01	i in (1e+01,1e+01)	i in ('1e+01','1e+01')
1	1	1	1
DROP TABLE t1;
create table t1(a bigint unsigned, b bigint);
insert ignore into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff), 
(0x10000000000000000, 0x10000000000000000), 
(0x8fffffffffffffff, 0x8fffffffffffffff);
Warnings:
Warning	1264	Out of range value for column 'a' at row 1
Warning	1264	Out of range value for column 'b' at row 1
Warning	1264	Out of range value for column 'a' at row 2
Warning	1264	Out of range value for column 'b' at row 2
Warning	1264	Out of range value for column 'b' at row 3
select hex(a), hex(b) from t1;
hex(a)	hex(b)
FFFFFFFFFFFFFFFF	7FFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF	7FFFFFFFFFFFFFFF
8FFFFFFFFFFFFFFF	7FFFFFFFFFFFFFFF
drop table t1;
CREATE TABLE t1 (c0 int);
CREATE TABLE t2 (c0 int);
INSERT INTO t1 VALUES(@@connect_timeout);
INSERT INTO t2 VALUES(@@connect_timeout);
SELECT * FROM t1 JOIN t2 ON t1.c0 = t2.c0 WHERE (t1.c0 <=> @@connect_timeout);
c0	c0
X	X
DROP TABLE t1, t2;
End of 4.1 tests
CREATE TABLE t1 ( 
K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', 
K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', 
F2I4 int(11) NOT NULL default '0' 
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES 
('W%RT', '0100',  1), 
('W-RT', '0100', 1), 
('WART', '0100', 1), 
('WART', '0200', 1), 
('WERT', '0100', 2), 
('WORT','0200', 2), 
('WT', '0100', 2), 
('W_RT', '0100', 2), 
('WaRT', '0100', 3), 
('WART', '0300', 3), 
('WRT' , '0400', 3), 
('WURM', '0500', 3), 
('W%T', '0600', 4), 
('WA%T', '0700', 4), 
('WA_T', '0800', 4);
SELECT K2C4, K4N4, F2I4 FROM t1
WHERE  K2C4 = 'WART' AND 
(F2I4 = 2 AND K2C4 = 'WART' OR (F2I4 = 2 OR K4N4 = '0200'));
K2C4	K4N4	F2I4
WART	0200	1
SELECT K2C4, K4N4, F2I4 FROM t1
WHERE  K2C4 = 'WART' AND (K2C4 = 'WART' OR K4N4 = '0200');
K2C4	K4N4	F2I4
WART	0100	1
WART	0200	1
WART	0300	3
DROP TABLE t1;
create table t1 (a int, b int);
create table t2 like t1;
select t1.a from (t1 inner join t2 on t1.a=t2.a) where t2.a=1;
a
select t1.a from ((t1 inner join t2 on t1.a=t2.a)) where t2.a=1;
a
select x.a, y.a, z.a from ( (t1 x inner join t2 y on x.a=y.a) inner join t2 z on y.a=z.a) WHERE x.a=1;
a	a	a
drop table t1,t2;
create table t1 (s1 varchar(5));
insert into t1 values ('Wall');
select min(s1) from t1 group by s1 with rollup;
min(s1)
Wall
Wall
drop table t1;
create table t1 (s1 int) engine=myisam;
insert into t1 values (0);
select avg(distinct s1) from t1 group by s1 with rollup;
avg(distinct s1)
0.0000
0.0000
drop table t1;
create table t1 (s1 int);
insert into t1 values (null),(1);
select distinct avg(s1) as x from t1 group by s1 with rollup;
x
NULL
1.0000
drop table t1;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (a int);
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
INSERT INTO t2 VALUES (2), (4), (6);
SELECT t1.a FROM t1 STRAIGHT_JOIN t2 ON t1.a=t2.a;
a
2
4
EXPLAIN SELECT t1.a FROM t1 STRAIGHT_JOIN t2 ON t1.a=t2.a;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (flat, BNL join)
EXPLAIN SELECT t1.a FROM t1 INNER JOIN t2 ON t1.a=t2.a;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	Using where; Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
select x'3136' + 0, X'3136' + 0, b'10' + 0, B'10' + 0;
x'3136' + 0	X'3136' + 0	b'10' + 0	B'10' + 0
16	16	2	2
create table t1 (f1 varchar(6) default NULL, f2 int(6) primary key not null);
create table t2 (f3 varchar(5) not null, f4 varchar(5) not null, UNIQUE KEY UKEY (f3,f4));
insert into t1 values (" 2", 2);
insert into t2 values (" 2", " one "),(" 2", " two ");
select * from t1 left join t2 on f1 = f3;
f1	f2	f3	f4
 2	2	 2	 one 
 2	2	 2	 two 
drop table t1,t2;
create table t1 (empnum smallint, grp int);
create table t2 (empnum int, name char(5));
insert into t1 values(1,1);
insert into t2 values(1,'bob');
create view v1 as select * from t2 inner join t1 using (empnum);
select * from v1;
empnum	name	grp
1	bob	1
drop table t1,t2;
drop view v1;
create table t1 (pk int primary key, b int);
create table t2 (pk int primary key, c int);
select pk from t1 inner join t2 using (pk);
pk
drop table t1,t2;
create table t1 (s1 int, s2 char(5), s3 decimal(10));
create view v1 as select s1, s2, 'x' as s3 from t1;
select * from t1 natural join v1;
s1	s2	s3
insert into t1 values (1,'x',5);
select * from t1 natural join v1;
s1	s2	s3
Warnings:
Warning	1292	Truncated incorrect DECIMAL value: 'x'
drop table t1;
drop view v1;
create table t1(a1 int);
create table t2(a2 int);
insert into t1 values(1),(2);
insert into t2 values(1),(2);
create view v2 (c) as select a1 from t1;
select * from t1 natural left join t2;
a1	a2
1	1
1	2
2	1
2	2
select * from t1 natural right join t2;
a2	a1
1	1
1	2
2	1
2	2
select * from v2 natural left join t2;
c	a2
1	1
1	2
2	1
2	2
select * from v2 natural right join t2;
a2	c
1	1
1	2
2	1
2	2
drop table t1, t2;
drop view v2;
create table t1 (a int(10), t1_val int(10));
create table t2 (b int(10), t2_val int(10));
create table t3 (a int(10), b int(10));
insert into t1 values (1,1),(2,2);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(3,1),(4,1);
select * from t1 natural join t2 natural join t3;
a	b	t1_val	t2_val
1	1	1	1
2	1	2	1
select * from t1 natural join t3 natural join t2;
b	a	t1_val	t2_val
1	1	1	1
1	2	2	1
drop table t1, t2, t3;
DO IFNULL(NULL, NULL);
SELECT CAST(IFNULL(NULL, NULL) AS DECIMAL);
CAST(IFNULL(NULL, NULL) AS DECIMAL)
NULL
SELECT ABS(IFNULL(NULL, NULL));
ABS(IFNULL(NULL, NULL))
NULL
SELECT IFNULL(NULL, NULL);
IFNULL(NULL, NULL)
NULL
SET @OLD_SQL_MODE12595=@@SQL_MODE, @@SQL_MODE='';
SHOW LOCAL VARIABLES LIKE 'SQL_MODE';
Variable_name	Value
sql_mode	
CREATE TABLE BUG_12595(a varchar(100));
INSERT INTO BUG_12595 VALUES ('hakan%'), ('hakank'), ("ha%an");
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%';
a
hakan%
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*';
a
hakan%
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**';
ERROR HY000: Incorrect arguments to ESCAPE
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan%' ESCAPE '';
a
hakan%
hakank
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE '';
a
SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE 0x5c;
a
ha%an
SELECT * FROM BUG_12595 WHERE a LIKE 'ha%%an' ESCAPE '%';
a
ha%an
SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE '\\';
a
ha%an
SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '|';
a
ha%an
SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
SHOW LOCAL VARIABLES LIKE 'SQL_MODE';
Variable_name	Value
sql_mode	NO_BACKSLASH_ESCAPES
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%';
a
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*';
a
hakan%
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**';
ERROR HY000: Incorrect arguments to ESCAPE
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\%' ESCAPE '\\';
ERROR HY000: Incorrect arguments to ESCAPE
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan%' ESCAPE '';
ERROR HY000: Incorrect arguments to ESCAPE
SELECT * FROM BUG_12595 WHERE a LIKE 'ha\%an' ESCAPE 0x5c;
a
ha%an
SELECT * FROM BUG_12595 WHERE a LIKE 'ha|%an' ESCAPE '|';
a
ha%an
SELECT * FROM BUG_12595 WHERE a LIKE 'hakan\n%' ESCAPE '\n';
ERROR HY000: Incorrect arguments to ESCAPE
SET @@SQL_MODE=@OLD_SQL_MODE12595;
DROP TABLE BUG_12595;
create table t1 (a char(1));
create table t2 (a char(1));
insert into t1 values ('a'),('b'),('c');
insert into t2 values ('b'),('c'),('d');
select a from t1 natural join t2;
a
b
c
select * from t1 natural join t2 where a = 'b';
a
b
drop table t1, t2;
CREATE TABLE t1 (`id` TINYINT);
CREATE TABLE t2 (`id` TINYINT);
CREATE TABLE t3 (`id` TINYINT);
INSERT INTO t1 VALUES (1),(2),(3);
INSERT INTO t2 VALUES (2);
INSERT INTO t3 VALUES (3);
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.notacolumn=t1.id) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
SELECT id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
SELECT id,t3.id FROM (t1 JOIN t2 ON (t2.id=t1.id)) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
drop table t1, t2, t3;
create table t1 (a int(10),b int(10));
create table t2 (a int(10),b int(10));
insert into t1 values (1,10),(2,20),(3,30);
insert into t2 values (1,10);
select * from t1 inner join t2 using (A);
a	b	b
1	10	10
select * from t1 inner join t2 using (a);
a	b	b
1	10	10
drop table t1, t2;
create table t1 (a int, c int);
create table t2 (b int);
create table t3 (b int, a int);
create table t4 (c int);
insert into t1 values (1,1);
insert into t2 values (1);
insert into t3 values (1,1);
insert into t4 values (1);
select * from t1 join t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
a	c	b	b	a
1	1	1	1	1
select * from t1, t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
ERROR 42S22: Unknown column 't1.a' in 'on clause'
select * from t1 join t2 join t3 join t4 on (t1.a = t4.c and t2.b = t4.c);
a	c	b	b	a	c
1	1	1	1	1	1
select * from t1 join t2 join t4 using (c);
c	a	b
1	1	1
drop table t1, t2, t3, t4;
create table t1(x int, y int);
create table t2(x int, y int);
create table t3(x int, primary key(x));
insert into t1 values (1, 1), (2, 1), (3, 1), (4, 3), (5, 6), (6, 6);
insert into t2 values (1, 1), (2, 1), (3, 3), (4, 6), (5, 6);
insert into t3 values (1), (2), (3), (4), (5);
select t1.x, t3.x from t1, t2, t3  where t1.x = t2.x and t3.x >= t1.y and t3.x <= t2.y;
x	x
1	1
2	1
3	1
3	2
3	3
4	3
4	4
4	5
drop table t1,t2,t3;
create table t1 (id char(16) not null default '', primary key  (id));
insert into t1 values ('100'),('101'),('102');
create table t2 (id char(16) default null);
insert into t2 values (1);
create view v1 as select t1.id from t1;
create view v2 as select t2.id from t2;
create view v3 as select (t1.id+2) as id from t1 natural left join t2;
select t1.id from t1 left join v2 using (id);
id
100
101
102
select t1.id from v2 right join t1 using (id);
id
100
101
102
select t1.id from t1 left join v3 using (id);
id
100
101
102
select * from t1 left join v2 using (id);
id
100
101
102
select * from v2 right join t1 using (id);
id
100
101
102
select * from t1 left join v3 using (id);
id
100
101
102
select v1.id from v1 left join v2 using (id);
id
100
101
102
select v1.id from v2 right join v1 using (id);
id
100
101
102
select v1.id from v1 left join v3 using (id);
id
100
101
102
select * from v1 left join v2 using (id);
id
100
101
102
select * from v2 right join v1 using (id);
id
100
101
102
select * from v1 left join v3 using (id);
id
100
101
102
drop table t1, t2;
drop view v1, v2, v3;
create table t1 (id int(11) not null default '0');
insert into t1 values (123),(191),(192);
create table t2 (id char(16) character set utf8 not null);
insert into t2 values ('58013'),('58014'),('58015'),('58016');
create table t3 (a_id int(11) not null, b_id char(16) character set utf8);
insert into t3 values (123,null),(123,null),(123,null),(123,null),(123,null),(123,'58013');
select count(*)
from t1 inner join (t3 left join t2 on t2.id = t3.b_id) on t1.id = t3.a_id;
count(*)
6
select count(*)
from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id;
count(*)
6
drop table t1,t2,t3;
create table t1 (a int);
create table t2 (b int);
create table t3 (c int);
select * from t1 join t2 join t3 on (t1.a=t3.c);
a	b	c
select * from t1 join t2 left join t3 on (t1.a=t3.c);
a	b	c
select * from t1 join t2 right join t3 on (t1.a=t3.c);
a	b	c
select * from t1 join t2 straight_join t3 on (t1.a=t3.c);
a	b	c
drop table t1, t2 ,t3;
create table t1(f1 int, f2 date);
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
(4,'2005-10-01'),(5,'2005-12-30');
select * from t1 where f2 >= 0            order by f2;
f1	f2
1	2005-01-01
2	2005-09-01
3	2005-09-30
4	2005-10-01
5	2005-12-30
select * from t1 where f2 >= '0000-00-00' order by f2;
f1	f2
1	2005-01-01
2	2005-09-01
3	2005-09-30
4	2005-10-01
5	2005-12-30
select * from t1 where f2 >= '2005-09-31' order by f2;
f1	f2
4	2005-10-01
5	2005-12-30
select * from t1 where f2 >= '2005-09-3a' order by f2;
f1	f2
3	2005-09-30
4	2005-10-01
5	2005-12-30
Warnings:
Warning	1292	Truncated incorrect date value: '2005-09-3a'
select * from t1 where f2 <= '2005-09-31' order by f2;
f1	f2
1	2005-01-01
2	2005-09-01
3	2005-09-30
select * from t1 where f2 <= '2005-09-3a' order by f2;
f1	f2
1	2005-01-01
2	2005-09-01
Warnings:
Warning	1292	Truncated incorrect date value: '2005-09-3a'
drop table t1;
create table t1 (f1 int, f2 int);
insert into t1 values (1, 30), (2, 20), (3, 10);
create algorithm=merge view v1 as select f1, f2 from t1;
create algorithm=merge view v2 (f2, f1) as select f1, f2 from t1;
create algorithm=merge view v3 as select t1.f1 as f2, t1.f2 as f1 from t1;
select t1.f1 as x1, f1 from t1 order by t1.f1;
x1	f1
1	1
2	2
3	3
select v1.f1 as x1, f1 from v1 order by v1.f1;
x1	f1
1	1
2	2
3	3
select v2.f1 as x1, f1 from v2 order by v2.f1;
x1	f1
10	10
20	20
30	30
select v3.f1 as x1, f1 from v3 order by v3.f1;
x1	f1
10	10
20	20
30	30
select f1, f2, v1.f1 as x1 from v1 order by v1.f1;
f1	f2	x1
1	30	1
2	20	2
3	10	3
select f1, f2, v2.f1 as x1 from v2 order by v2.f1;
f1	f2	x1
10	3	10
20	2	20
30	1	30
select f1, f2, v3.f1 as x1 from v3 order by v3.f1;
f1	f2	x1
10	3	10
20	2	20
30	1	30
drop table t1;
drop view v1, v2, v3;
CREATE TABLE t1(key_a int4 NOT NULL, optimus varchar(32), PRIMARY KEY(key_a));
CREATE TABLE t2(key_a int4 NOT NULL, prime varchar(32), PRIMARY KEY(key_a));
CREATE table t3(key_a int4 NOT NULL, key_b int4 NOT NULL, foo varchar(32),
PRIMARY KEY(key_a,key_b));
INSERT INTO t1 VALUES (0,'');
INSERT INTO t1 VALUES (1,'i');
INSERT INTO t1 VALUES (2,'j');
INSERT INTO t1 VALUES (3,'k');
INSERT INTO t2 VALUES (1,'r');
INSERT INTO t2 VALUES (2,'s');
INSERT INTO t2 VALUES (3,'t');
INSERT INTO t3 VALUES (1,5,'x');
INSERT INTO t3 VALUES (1,6,'y');
INSERT INTO t3 VALUES (2,5,'xx');
INSERT INTO t3 VALUES (2,6,'yy');
INSERT INTO t3 VALUES (2,7,'zz');
INSERT INTO t3 VALUES (3,5,'xxx');
SELECT t2.key_a,foo 
FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
key_a	foo
2	xx
EXPLAIN SELECT t2.key_a,foo 
FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	Using index
1	SIMPLE	t3	const	PRIMARY	PRIMARY	8	const,const	1	
SELECT t2.key_a,foo 
FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
key_a	foo
2	xx
EXPLAIN SELECT t2.key_a,foo 
FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	Using index
1	SIMPLE	t3	const	PRIMARY	PRIMARY	8	const,const	1	
DROP TABLE t1,t2,t3;
create  table t1 (f1 int);
insert into t1 values(1),(2);
create table t2 (f2 int, f3 int, key(f2));
insert into t2 values(1,1),(2,2);
create table t3 (f4 int not null);
insert into t3 values (2),(2),(2);
select f1,(select count(*) from t2,t3 where f2=f1 and f3=f4) as count from t1;
f1	count
1	0
2	3
drop table t1,t2,t3;
create table t1 (f1 int unique);
create table t2 (f2 int unique);
create table t3 (f3 int unique);
insert into t1 values(1),(2);
insert into t2 values(1),(2);
insert into t3 values(1),(NULL);
select * from t3 where f3 is null;
f3
NULL
select t2.f2 from t1 left join t2 on f1=f2 join t3 on f1=f3 where f1=1;
f2
1
drop table t1,t2,t3;
create table t1(f1 char, f2 char not null);
insert into t1 values(null,'a');
create table t2 (f2 char not null);
insert into t2 values('b');
select * from t1 left join t2 on f1=t2.f2 where t1.f2='a';
f1	f2	f2
NULL	a	NULL
drop table t1,t2;
select * from (select * left join t on f1=f2) tt;
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 'left join t on f1=f2) tt' at line 1
CREATE TABLE t1 (sku int PRIMARY KEY, pr int);
CREATE TABLE t2 (sku int PRIMARY KEY, sppr int, name varchar(255));
INSERT INTO t1 VALUES
(10, 10), (20, 10), (30, 20), (40, 30), (50, 10), (60, 10), (70, 10);
INSERT INTO t2 VALUES 
(10, 10, 'aaa'), (20, 10, 'bbb'), (30, 10, 'ccc'), (40, 20, 'ddd'),
(50, 10, 'eee'), (60, 20, 'fff'), (70, 20, 'ggg'), (80, 30, 'hhh');
SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr
FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku);
sku	sppr	name	sku	pr
20	10	bbb	10	10
20	10	bbb	20	10
EXPLAIN
SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr
FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	Using index condition
DROP TABLE t1,t2;
SET SQL_MODE='NO_UNSIGNED_SUBTRACTION';
CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL);
INSERT t1 SET i = 0;
UPDATE t1 SET i = -1;
Warnings:
Warning	1264	Out of range value for column 'i' at row 1
SELECT * FROM t1;
i
0
UPDATE t1 SET i = CAST(i - 1 AS SIGNED);
Warnings:
Warning	1264	Out of range value for column 'i' at row 1
SELECT * FROM t1;
i
0
UPDATE t1 SET i = i - 1;
Warnings:
Warning	1264	Out of range value for column 'i' at row 1
SELECT * FROM t1;
i
0
DROP TABLE t1;
SET SQL_MODE=default;
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, c int, e int, primary key(a,b,c));
insert into t2 select A.a, B.a, C.a, C.a from t1 A, t1 B, t1 C;
analyze table t2;
Table	Op	Msg_type	Msg_text
test.t2	analyze	status	Engine-independent statistics collected
test.t2	analyze	status	OK
select 'In next EXPLAIN, B.rows must be exactly 10:' Z;
Z
In next EXPLAIN, B.rows must be exactly 10:
explain select * from t2 A, t2 B where A.a=5 and A.b=5 and A.C<5
and B.a=5 and B.b=A.e and (B.b =1 or B.b = 3 or B.b=5);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	A	range	PRIMARY	PRIMARY	12	NULL	4	Using index condition; Using where
1	SIMPLE	B	ref	PRIMARY	PRIMARY	8	const,test.A.e	10	
drop table t1, t2;
CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX(b));
INSERT INTO t1 VALUES (1, 3), (9,4), (7,5), (4,5), (6,2),
(3,1), (5,1), (8,9), (2,2), (0,9);
CREATE TABLE t2 (c int, d int, f int, INDEX(c,f));
INSERT INTO t2 VALUES
(1,0,0), (1,0,1), (2,0,0), (2,0,1), (3,0,0), (4,0,1),
(5,0,0), (5,0,1), (6,0,0), (0,0,1), (7,0,0), (7,0,1),
(0,0,0), (0,0,1), (8,0,0), (8,0,1), (9,0,0), (9,0,1);
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	c	NULL	NULL	NULL	18	Using where
1	SIMPLE	t1	eq_ref|filter	PRIMARY,b	PRIMARY|b	4|5	test.t2.c	1 (30%)	Using where; Using rowid filter
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	c	NULL	NULL	NULL	18	Using where
1	SIMPLE	t1	eq_ref|filter	PRIMARY,b	PRIMARY|b	4|5	test.t2.c	1 (30%)	Using where; Using rowid filter
DROP TABLE t1, t2;
create table t1 (
a int unsigned    not null auto_increment primary key,
b bit             not null,
c bit             not null
);
create table t2 (
a int unsigned    not null auto_increment primary key,
b bit             not null,
c int unsigned    not null,
d varchar(50)
);
insert into t1 (b,c) values (0,1), (0,1);
insert into t2 (b,c) values (0,1);
select t1.a, t1.b + 0, t1.c + 0, t2.a, t2.b + 0, t2.c, t2.d
from t1 left outer join t2 on t1.a = t2.c and t2.b <> 1
where t1.b <> 1 order by t1.a;
a	t1.b + 0	t1.c + 0	a	t2.b + 0	c	d
1	0	1	1	0	1	NULL
2	0	1	NULL	NULL	NULL	NULL
drop table t1,t2;
SELECT 0.9888889889 * 1.011111411911;
0.9888889889 * 1.011111411911
0.9998769417899202067879
prepare stmt from 'select 1 as " a "';
Warnings:
Warning	1466	Leading spaces are removed from name ' a '
execute stmt;
a 
1
CREATE TABLE t1 (a int NOT NULL PRIMARY KEY, b int NOT NULL);
INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4);
CREATE TABLE t2 (c int NOT NULL, INDEX idx(c));
INSERT INTO t2 VALUES
(1), (1), (1), (1), (1), (1), (1), (1),
(2), (2), (2), (2),
(3), (3),
(4);
EXPLAIN SELECT b FROM t1, t2 WHERE b=c AND a=1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t2	ref	idx	idx	4	const	8	Using index
EXPLAIN SELECT b FROM t1, t2 WHERE b=c AND a=4;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t2	ref	idx	idx	4	const	1	Using index
DROP TABLE t1, t2;
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a int);
INSERT INTO t1 VALUES (1,2), (2,NULL), (3,2);
CREATE TABLE t2 (b int, c INT, INDEX idx1(b));
INSERT INTO t2 VALUES (2,1), (3,2);
CREATE TABLE t3 (d int,  e int, INDEX idx1(d));
INSERT INTO t3 VALUES (2,10), (2,20), (1,30), (2,40), (2,50), (1,60), (3,70), (1,80), (3,90);
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t2	const	idx1	NULL	NULL	NULL	1	
1	SIMPLE	t3	ref	idx1	idx1	5	const	4	
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id	a	b	c	d	e
2	NULL	NULL	NULL	2	10
2	NULL	NULL	NULL	2	20
2	NULL	NULL	NULL	2	40
2	NULL	NULL	NULL	2	50
DROP TABLE t1,t2,t3;
create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int,
c7 int, c8 int, c9 int, fulltext key (`c1`));
select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8 
from t1 where c9=1 order by c2, c2;
match (`c1`) against ('z')	c2	c3	c4	c5	c6	c7	c8
drop table t1;
CREATE TABLE t1 (pk varchar(10) PRIMARY KEY, fk varchar(16));
CREATE TABLE t2 (pk varchar(16) PRIMARY KEY, fk varchar(10));
INSERT INTO t1 VALUES
('d','dddd'), ('i','iii'), ('a','aa'), ('b','bb'), ('g','gg'), 
('e','eee'), ('c','cccc'), ('h','hhh'), ('j','jjj'), ('f','fff');
INSERT INTO t2 VALUES
('jjj', 'j'), ('cc','c'), ('ccc','c'), ('aaa', 'a'), ('jjjj','j'),
('hhh','h'), ('gg','g'), ('fff','f'), ('ee','e'), ('ffff','f'),
('bbb','b'), ('ff','f'), ('cccc','c'), ('dddd','d'), ('jj','j'),
('aaaa','a'), ('bb','b'), ('eeee','e'), ('aa','a'), ('hh','h');
EXPLAIN SELECT t2.* 
FROM t1 JOIN t2 ON t2.fk=t1.pk
WHERE t2.fk < 'c' AND t2.pk=t1.fk;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	PRIMARY	PRIMARY	12	NULL	2	Using index condition; Using where
1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	18	test.t1.fk	1	Using where
EXPLAIN SELECT t2.* 
FROM t1 JOIN t2 ON t2.fk=t1.pk 
WHERE t2.fk BETWEEN 'a' AND 'b' AND t2.pk=t1.fk;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	PRIMARY	PRIMARY	12	NULL	2	Using index condition; Using where
1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	18	test.t1.fk	1	Using where
EXPLAIN SELECT t2.* 
FROM t1 JOIN t2 ON t2.fk=t1.pk 
WHERE t2.fk IN ('a','b') AND t2.pk=t1.fk;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	PRIMARY	PRIMARY	12	NULL	2	Using index condition; Using where
1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	18	test.t1.fk	1	Using where
DROP TABLE t1,t2;
CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
PRIMARY KEY (a), UNIQUE KEY (b));
INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
DROP TABLE t1,t2;
CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
INSERT INTO t1 VALUES 
(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
INSERT INTO t2 VALUES
(21,210), (41,410), (82,820), (83,830), (84,840),
(65,650), (51,510), (37,370), (94,940), (76,760),
(22,220), (33,330), (40,400), (95,950), (38,380),
(67,670), (88,880), (57,570), (96,960), (97,970);
INSERT INTO t3 VALUES
(210,'bb'), (950,'ii'), (400,'ab'), (500,'ee'), (220,'gg'),
(440,'gg'), (310,'eg'), (380,'ee'), (840,'bb'), (830,'ff'),
(230,'aa'), (960,'ii'), (410,'aa'), (510,'ee'), (290,'bb'),
(450,'gg'), (320,'dd'), (390,'hh'), (850,'jj'), (860,'ff');
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND 
t3.a=t2.a AND t3.c IN ('bb','ee');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t2	range	si	si	5	NULL	4	Using index condition; Using where
1	SIMPLE	t3	eq_ref|filter	PRIMARY,ci	PRIMARY|ci	4|5	test.t2.a	1 (30%)	Using where; Using rowid filter
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
t3.a=t2.a AND t3.c IN ('bb','ee') ;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t2	range	si,ai	si	5	NULL	4	Using index condition; Using where
1	SIMPLE	t3	eq_ref|filter	PRIMARY,ci	PRIMARY|ci	4|5	test.t2.a	1 (30%)	Using where; Using rowid filter
EXPLAIN 
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
t3.c IN ('bb','ee');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t2	range	si	si	5	NULL	2	Using index condition; Using where
1	SIMPLE	t3	eq_ref|filter	PRIMARY,ci	PRIMARY|ci	4|5	test.t2.a	1 (30%)	Using where; Using rowid filter
EXPLAIN 
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
t3.c IN ('bb','ee');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t2	range	si,ai	si	5	NULL	2	Using index condition; Using where
1	SIMPLE	t3	eq_ref|filter	PRIMARY,ci	PRIMARY|ci	4|5	test.t2.a	1 (30%)	Using where; Using rowid filter
DROP TABLE t1,t2,t3;
CREATE TABLE t1 ( f1 int primary key, f2 int, f3 int, f4 int, f5 int, f6 int, checked_out int);
CREATE TABLE t2 ( f11 int PRIMARY KEY );
INSERT INTO t1 VALUES (1,1,1,0,0,0,0),(2,1,1,3,8,1,0),(3,1,1,4,12,1,0);
INSERT INTO t2 VALUES (62);
SELECT * FROM t1 LEFT JOIN t2 ON f11 = t1.checked_out GROUP BY f1 ORDER BY f2, f3, f4, f5 LIMIT 0, 1;
f1	f2	f3	f4	f5	f6	checked_out	f11
1	1	1	0	0	0	0	NULL
DROP TABLE t1, t2;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a int);
INSERT into t1 values (1), (2), (3);
SELECT * FROM t1 LIMIT 2, -1;
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 '-1' at line 1
DROP TABLE t1;
CREATE TABLE t1 (
ID_with_null int NULL,
ID_better int NOT NULL,
INDEX idx1 (ID_with_null),
INDEX idx2 (ID_better)
);
INSERT INTO t1 VALUES (1,1), (2,1), (null,3), (null,3), (null,3), (null,3);
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
SELECT COUNT(*) FROM t1 WHERE ID_with_null IS NULL;
COUNT(*)
128
SELECT COUNT(*) FROM t1 WHERE ID_better=1;
COUNT(*)
2
EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID_with_null IS NULL;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	1	Using where
DROP INDEX idx1 ON t1;
CREATE UNIQUE INDEX idx1 ON t1(ID_with_null);
EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID_with_null IS NULL;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	1	Using where
DROP TABLE t1;
CREATE TABLE t1 (
ID1_with_null int NULL,
ID2_with_null int NULL,
ID_better int NOT NULL,
INDEX idx1 (ID1_with_null, ID2_with_null),
INDEX idx2 (ID_better)
);
INSERT INTO t1 VALUES (1,1,1), (2,2,1), (3,null,3), (null,3,3), (null,null,3),
(3,null,3), (null,3,3), (null,null,3), (3,null,3), (null,3,3), (null,null,3);
INSERT INTO t1 SELECT * FROM t1 WHERE ID1_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID2_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID1_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID2_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID1_with_null IS NULL;
INSERT INTO t1 SELECT * FROM t1 WHERE ID2_with_null IS NULL;
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
SELECT COUNT(*) FROM t1 WHERE ID1_with_null IS NULL AND ID2_with_null=3;
COUNT(*)
24
SELECT COUNT(*) FROM t1 WHERE ID1_with_null=3 AND ID2_with_null IS NULL;
COUNT(*)
24
SELECT COUNT(*) FROM t1 WHERE ID1_with_null IS NULL AND ID2_with_null IS NULL;
COUNT(*)
192
SELECT COUNT(*) FROM t1 WHERE ID_better=1;
COUNT(*)
2
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref|filter	idx1,idx2	idx2|idx1	4|10	const	2 (6%)	Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
DROP INDEX idx1 ON t1;
CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref|filter	idx1,idx2	idx2|idx1	4|10	const	2 (7%)	Using where; Using rowid filter
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND 
(ID2_with_null=1 OR ID2_with_null=2);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref|filter	idx1,idx2	idx1|idx2	5|4	const	2 (1%)	Using index condition; Using where; Using rowid filter
DROP TABLE t1;
CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts));
INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00");
ANALYZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
CREATE TABLE t2 (a INT, dt1 DATETIME, dt2 DATETIME, PRIMARY KEY (a));
INSERT INTO t2 VALUES (30, "2006-01-01 00:00:00", "2999-12-31 00:00:00");
INSERT INTO t2 SELECT a+1,dt1,dt2 FROM t2;
ANALYZE TABLE t2;
Table	Op	Msg_type	Msg_text
test.t2	analyze	status	Engine-independent statistics collected
test.t2	analyze	status	OK
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	
1	SIMPLE	t1	range	ts	ts	4	NULL	2	Using index condition; Using where
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
a	ts	a	dt1	dt2
30	2006-01-03 23:00:00	30	2006-01-01 00:00:00	2999-12-31 00:00:00
DROP TABLE t1,t2;
create table t1 (a bigint unsigned);
insert into t1 values
(if(1, 9223372036854775808, 1)),
(case when 1 then 9223372036854775808 else 1 end),
(coalesce(9223372036854775808, 1));
select * from t1;
a
9223372036854775808
9223372036854775808
9223372036854775808
drop table t1;
create table t1 select
if(1, 9223372036854775808, 1) i,
case when 1 then 9223372036854775808 else 1 end c,
coalesce(9223372036854775808, 1) co;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `i` decimal(19,0) NOT NULL,
  `c` decimal(19,0) NOT NULL,
  `co` decimal(19,0) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
select 
if(1, cast(1111111111111111111 as unsigned), 1) i,
case when 1 then cast(1111111111111111111 as unsigned) else 1 end c,
coalesce(cast(1111111111111111111 as unsigned), 1) co;
i	c	co
1111111111111111111	1111111111111111111	1111111111111111111
CREATE TABLE t1 (name varchar(255));
CREATE TABLE t2 (name varchar(255), n int, KEY (name(3)));
INSERT INTO t1 VALUES ('ccc'), ('bb'), ('cc '), ('aa  '), ('aa');
INSERT INTO t2 VALUES ('bb',1), ('aa',2), ('cc   ',3);
INSERT INTO t2 VALUES (concat('cc ', 0x06), 4);
INSERT INTO t2 VALUES ('cc',5), ('bb ',6), ('cc ',7);
INSERT INTO t2 VALUES ('bb ',8), ('aa',9), ('aa',10), ('bb',11);
SELECT * FROM t2;
name	n
bb	1
aa	2
cc   	3
cc 	4
cc	5
bb 	6
cc 	7
bb 	8
aa	9
aa	10
bb	11
SELECT * FROM t2 ORDER BY name;
name	n
aa	2
aa	10
aa	9
bb	1
bb 	8
bb 	6
bb	11
cc 	4
cc 	7
cc	5
cc   	3
SELECT name, LENGTH(name), n FROM t2 ORDER BY name;
name	LENGTH(name)	n
aa	2	2
aa	2	10
aa	2	9
bb	2	1
bb 	3	8
bb 	3	6
bb	2	11
cc 	4	4
cc 	3	7
cc	2	5
cc   	5	3
EXPLAIN SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	name	name	6	const	4	Using where
SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
name	LENGTH(name)	n
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	4	Using where
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
name	LENGTH(name)	n
cc   	5	3
cc 	4	4
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	4	Using where; Using filesort
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
name	LENGTH(name)	n
cc 	4	4
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
1	SIMPLE	t2	ref	name	name	6	test.t1.name	2	Using where
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
name	name	n
ccc	NULL	NULL
bb	bb	1
bb	bb 	6
bb	bb 	8
bb	bb	11
cc 	cc   	3
cc 	cc	5
cc 	cc 	7
aa  	aa	2
aa  	aa	9
aa  	aa	10
aa	aa	2
aa	aa	9
aa	aa	10
DROP TABLE t1,t2;
CREATE TABLE t1 (name text);
CREATE TABLE t2 (name text, n int, KEY (name(3)));
INSERT INTO t1 VALUES ('ccc'), ('bb'), ('cc '), ('aa  '), ('aa');
INSERT INTO t2 VALUES ('bb',1), ('aa',2), ('cc   ',3);
INSERT INTO t2 VALUES (concat('cc ', 0x06), 4);
INSERT INTO t2 VALUES ('cc',5), ('bb ',6), ('cc ',7);
INSERT INTO t2 VALUES ('bb ',8), ('aa',9), ('aa',10), ('bb',11);
SELECT * FROM t2;
name	n
bb	1
aa	2
cc   	3
cc 	4
cc	5
bb 	6
cc 	7
bb 	8
aa	9
aa	10
bb	11
SELECT * FROM t2 ORDER BY name;
name	n
aa	2
aa	9
aa	10
bb	1
bb 	6
bb 	8
bb	11
cc 	4
cc   	3
cc	5
cc 	7
SELECT name, LENGTH(name), n FROM t2 ORDER BY name;
name	LENGTH(name)	n
aa	2	2
aa	2	9
aa	2	10
bb	2	1
bb 	3	6
bb 	3	8
bb	2	11
cc 	4	4
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	name	name	6	const	4	Using where
SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
name	LENGTH(name)	n
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	4	Using where
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
name	LENGTH(name)	n
cc   	5	3
cc 	4	4
cc	2	5
cc 	3	7
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	name	name	6	NULL	4	Using where; Using filesort
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
name	LENGTH(name)	n
cc 	4	4
cc   	5	3
cc	2	5
cc 	3	7
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
1	SIMPLE	t2	ref	name	name	6	test.t1.name	2	Using where
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
name	name	n
ccc	NULL	NULL
bb	bb	1
bb	bb 	6
bb	bb 	8
bb	bb	11
cc 	cc   	3
cc 	cc	5
cc 	cc 	7
aa  	aa	2
aa  	aa	9
aa  	aa	10
aa	aa	2
aa	aa	9
aa	aa	10
DROP TABLE t1,t2;
CREATE TABLE t1 (
access_id int NOT NULL default '0',
name varchar(20) default NULL,
rank int NOT NULL default '0',
KEY idx (access_id)
);
CREATE TABLE t2 (
faq_group_id int NOT NULL default '0',
faq_id int NOT NULL default '0',
access_id int default NULL,
UNIQUE KEY idx1 (faq_id),
KEY idx2 (faq_group_id,faq_id)
);
INSERT INTO t1 VALUES 
(1,'Everyone',2),(2,'Help',3),(3,'Technical Support',1),(4,'Chat User',4);
INSERT INTO t2 VALUES
(261,265,1),(490,494,1);
SELECT t2.faq_id 
FROM t1 INNER JOIN t2 IGNORE INDEX (idx1)
ON (t1.access_id = t2.access_id)
LEFT JOIN t2 t
ON (t.faq_group_id = t2.faq_group_id AND
find_in_set(t.access_id, '1,4') < find_in_set(t2.access_id, '1,4'))
WHERE
t2.access_id IN (1,4) AND t.access_id IS NULL AND t2.faq_id in (265);
faq_id
265
SELECT t2.faq_id 
FROM t1 INNER JOIN t2
ON (t1.access_id = t2.access_id)
LEFT JOIN t2 t
ON (t.faq_group_id = t2.faq_group_id AND
find_in_set(t.access_id, '1,4') < find_in_set(t2.access_id, '1,4'))
WHERE
t2.access_id IN (1,4) AND t.access_id IS NULL AND t2.faq_id in (265);
faq_id
265
DROP TABLE t1,t2;
CREATE TABLE t1 (a INT, b INT, KEY inx (b,a));
INSERT INTO t1 VALUES (1,1), (1,2), (1,3), (1,4), (1,5), (1, 6), (1,7);
EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
ON ( f1.b=f2.b AND f1.a<f2.a ) 
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	f1	range	inx	inx	5	NULL	7	Using where; Using index
1	SIMPLE	f2	ref	inx	inx	5	test.f1.b	1	Using where; Using index
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
EXPLAIN SELECT c1 FROM t1 WHERE (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT COUNT(c2)))))))))))))))))))))))))))))))) > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
31	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
32	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
EXPLAIN SELECT c1 FROM t1 WHERE (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT COUNT(c2))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) > 0;
ERROR HY000: Too high level of nesting for select
DROP TABLE t1;
CREATE TABLE t1 (
c1 int(11) NOT NULL AUTO_INCREMENT,
c2 varchar(1000) DEFAULT NULL,
c3 bigint(20) DEFAULT NULL,
c4 bigint(20) DEFAULT NULL,
PRIMARY KEY (c1)
);
EXPLAIN EXTENDED 
SELECT  join_2.c1  
FROM 
t1 AS join_0, 
t1 AS join_1, 
t1 AS join_2, 
t1 AS join_3, 
t1 AS join_4, 
t1 AS join_5, 
t1 AS join_6, 
t1 AS join_7
WHERE 
join_0.c1=join_1.c1  AND 
join_1.c1=join_2.c1  AND 
join_2.c1=join_3.c1  AND 
join_3.c1=join_4.c1  AND 
join_4.c1=join_5.c1  AND 
join_5.c1=join_6.c1  AND 
join_6.c1=join_7.c1 
OR 
join_0.c2 < '?'  AND 
join_1.c2 < '?'  AND
join_2.c2 > '?'  AND
join_2.c2 < '!'  AND
join_3.c2 > '?'  AND 
join_4.c2 = '?'  AND 
join_5.c2 <> '?' AND
join_6.c2 <> '?' AND 
join_7.c2 >= '?' AND
join_0.c1=join_1.c1  AND 
join_1.c1=join_2.c1  AND 
join_2.c1=join_3.c1  AND
join_3.c1=join_4.c1  AND 
join_4.c1=join_5.c1  AND 
join_5.c1=join_6.c1  AND 
join_6.c1=join_7.c1
GROUP BY 
join_3.c1,
join_2.c1,
join_7.c1,
join_1.c1,
join_0.c1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
Warnings:
Note	1003	select NULL AS `c1` from `test`.`t1` `join_0` join `test`.`t1` `join_1` join `test`.`t1` `join_2` join `test`.`t1` `join_3` join `test`.`t1` `join_4` join `test`.`t1` `join_5` join `test`.`t1` `join_6` join `test`.`t1` `join_7` where 0 group by NULL,NULL,NULL,NULL,NULL
SHOW WARNINGS;
Level	Code	Message
Note	1003	select NULL AS `c1` from `test`.`t1` `join_0` join `test`.`t1` `join_1` join `test`.`t1` `join_2` join `test`.`t1` `join_3` join `test`.`t1` `join_4` join `test`.`t1` `join_5` join `test`.`t1` `join_6` join `test`.`t1` `join_7` where 0 group by NULL,NULL,NULL,NULL,NULL
DROP TABLE t1;
SELECT 1 AS ` `;

1
Warnings:
Warning	1474	Name ' ' has become ''
SELECT 1 AS `  `;

1
Warnings:
Warning	1474	Name '  ' has become ''
SELECT 1 AS ` x`;
x
1
Warnings:
Warning	1466	Leading spaces are removed from name ' x'
CREATE VIEW v1 AS SELECT 1 AS ``;
ERROR 42000: Incorrect column name ''
CREATE VIEW v1 AS SELECT 1 AS ` `;
ERROR 42000: Incorrect column name ' '
CREATE VIEW v1 AS SELECT 1 AS `  `;
ERROR 42000: Incorrect column name '  '
CREATE VIEW v1 AS SELECT (SELECT 1 AS `  `);
ERROR 42000: Incorrect column name '  '
CREATE VIEW v1 AS SELECT 1 AS ` x`;
Warnings:
Warning	1466	Leading spaces are removed from name ' x'
SELECT `x` FROM v1;
x
1
ALTER VIEW v1 AS SELECT 1 AS ` `;
ERROR 42000: Incorrect column name ' '
DROP VIEW v1;
select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
                                                and '2007/10/20 00:00:00 GMT';
str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
                                                and '2007/10/20 00:00:00 GMT'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007/10/01 00:00:00 GMT'
Warning	1292	Truncated incorrect datetime value: '2007/10/20 00:00:00 GMT'
select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007/10/01 00:00:00 GMT-6'
select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/20 00:00:00 GMT-6';
str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/20 00:00:00 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007/10/20 00:00:00 GMT-6'
select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6'
0
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007/10/2000:00:00 GMT-6'
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007-10-1 00:00:00 GMT-6'
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect date value: '2007-10-01 x00:00:00 GMT-6'
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007-10-01 00:00:00 GMT-6'
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007-10-01 00:x00:00 GMT-6'
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect date value: '2007-10-01 x12:34:56 GMT-6'
select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007-10-01 12:34x:56 GMT-6'
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6'
0
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007-10-01 12:34x:56 GMT-6'
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56'
1
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00'
0
select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00'
1
select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: '2007-10-01 12:34'
select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34'
1
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34'
1
select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
                                                and '2007/10/20 00:00:00';
str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
                                                and '2007/10/20 00:00:00'
1
set SQL_MODE=TRADITIONAL;
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34'
NULL
Warnings:
Warning	1411	Incorrect datetime value: '2007-10-00 12:34' for function str_to_date
select str_to_date('2007-10-01 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
str_to_date('2007-10-01 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34'
0
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-01 12:34'
NULL
Warnings:
Warning	1411	Incorrect datetime value: '2007-10-00 12:34' for function str_to_date
select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01'
                                                and '2007/10/20';
str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01'
                                                and '2007/10/20'
NULL
Warnings:
Warning	1411	Incorrect datetime value: '2007-10-00' for function str_to_date
set SQL_MODE=DEFAULT;
select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20'
1
Warnings:
Warning	1292	Truncated incorrect datetime value: ''
select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20'
0
select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34'
0
select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34'
NULL
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = ''
0
Warnings:
Warning	1292	Truncated incorrect datetime value: ''
select str_to_date('1','%Y-%m-%d') = '1';
str_to_date('1','%Y-%m-%d') = '1'
0
Warnings:
Warning	1292	Truncated incorrect datetime value: '1'
select str_to_date('1','%Y-%m-%d') = '1';
str_to_date('1','%Y-%m-%d') = '1'
0
Warnings:
Warning	1292	Truncated incorrect datetime value: '1'
select str_to_date('','%Y-%m-%d') = '';
str_to_date('','%Y-%m-%d') = ''
1
Warnings:
Warning	1292	Truncated incorrect datetime value: ''
select str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01';
str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and '2001-01-01'
1
select str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and NULL;
str_to_date('2000-01-01','%Y-%m-%d') between '1000-01-01' and NULL
NULL
select str_to_date('2000-01-01','%Y-%m-%d') between NULL and '2001-01-01';
str_to_date('2000-01-01','%Y-%m-%d') between NULL and '2001-01-01'
NULL
select str_to_date('2000-01-01','%Y-%m-%d') between '2001-01-01' and NULL;
str_to_date('2000-01-01','%Y-%m-%d') between '2001-01-01' and NULL
0
select str_to_date('2000-01-01','%Y-%m-%d') between NULL and '1000-01-01';
str_to_date('2000-01-01','%Y-%m-%d') between NULL and '1000-01-01'
0
select str_to_date('2000-01-01','%Y-%m-%d') between NULL and NULL;
str_to_date('2000-01-01','%Y-%m-%d') between NULL and NULL
NULL
CREATE TABLE t1 (c11 INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE t2 (c21 INT UNSIGNED NOT NULL, 
c22 INT DEFAULT NULL, 
KEY(c21, c22));
CREATE TABLE t3 (c31 INT UNSIGNED NOT NULL DEFAULT 0, 
c32 INT DEFAULT NULL, 
c33 INT NOT NULL, 
c34 INT UNSIGNED DEFAULT 0,
KEY (c33, c34, c32));
INSERT INTO t1 values (),(),(),(),();
INSERT INTO t2 SELECT a.c11, b.c11 FROM t1 a, t1 b;
INSERT INTO t3 VALUES (1, 1, 1, 0), 
(2, 2, 0, 0), 
(3, 3, 1, 0), 
(4, 4, 0, 0), 
(5, 5, 1, 0);
SELECT c32 FROM t1, t2, t3 WHERE t1.c11 IN (1, 3, 5) AND 
t3.c31 = t1.c11 AND t2.c21 = t1.c11 AND 
t3.c33 = 1 AND t2.c22 in (1, 3) 
ORDER BY c32;
c32
1
1
3
3
5
5
SELECT c32 FROM t1, t2, t3 WHERE t1.c11 IN (1, 3, 5) AND 
t3.c31 = t1.c11 AND t2.c21 = t1.c11 AND 
t3.c33 = 1 AND t2.c22 in (1, 3) 
ORDER BY c32 DESC;
c32
5
5
3
3
1
1
DROP TABLE t1, t2, t3;

#
# Bug#30736: Row Size Too Large Error Creating a Table and
# Inserting Data.
#
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;

CREATE TABLE t1(
c1 DECIMAL(10, 2),
c2 FLOAT);

INSERT INTO t1 VALUES (0, 1), (2, 3), (4, 5);

CREATE TABLE t2(
c3 DECIMAL(10, 2))
SELECT
c1 * c2 AS c3
FROM t1;

SELECT * FROM t1;
c1	c2
0.00	1
2.00	3
4.00	5

SELECT * FROM t2;
c3
0.00
6.00
20.00

DROP TABLE t1;
DROP TABLE t2;

CREATE TABLE t1 (c1 BIGINT NOT NULL);
INSERT INTO t1 (c1) VALUES (1);
SELECT * FROM t1 WHERE c1 > NULL + 1;
c1
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10) NOT NULL PRIMARY KEY);
INSERT INTO t1 (a) VALUES ('foo0'), ('bar0'), ('baz0');
SELECT * FROM t1 WHERE a IN (CONCAT('foo', 0), 'bar');
a
foo0
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT);
CREATE TABLE t2 (a INT, c INT, KEY(a));
INSERT INTO t1 VALUES (1, 1), (2, 2);
INSERT INTO t2 VALUES (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
(2, 1), (2, 2), (2, 3), (2, 4), (2, 5),
(3, 1), (3, 2), (3, 3), (3, 4), (3, 5),
(4, 1), (4, 2), (4, 3), (4, 4), (4, 5);
FLUSH STATUS;
SELECT DISTINCT b FROM t1 LEFT JOIN t2 USING(a) WHERE c <= 3;
b
1
2
SHOW STATUS LIKE 'Handler_read%';
Variable_name	Value
Handler_read_first	0
Handler_read_key	2
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	6
DROP TABLE t1, t2;
CREATE TABLE t1 (f1 bigint(20) NOT NULL default '0',
f2 int(11) NOT NULL default '0',
f3 bigint(20) NOT NULL default '0',
f4 varchar(255) NOT NULL default '',
PRIMARY KEY (f1),
KEY key1 (f4),
KEY key2 (f2));
CREATE TABLE t2 (f1 int(11) NOT NULL default '0',
f2 enum('A1','A2','A3') NOT NULL default 'A1',
f3 int(11) NOT NULL default '0',
PRIMARY KEY (f1),
KEY key1 (f3));
CREATE TABLE t3 (f1 bigint(20) NOT NULL default '0',
f2 datetime NOT NULL default '1980-01-01 00:00:00',
PRIMARY KEY (f1));
insert into t1 values (1, 1, 1, 'abc');
insert into t1 values (2, 1, 2, 'def');
insert into t1 values (3, 1, 2, 'def');
insert into t2 values (1, 'A1', 1);
insert into t3 values (1, '1980-01-01');
SELECT a.f3, cr.f4, count(*) count
FROM t2 a
STRAIGHT_JOIN t1 cr ON cr.f2 = a.f1
LEFT JOIN
(t1 cr2
JOIN t3 ae2 ON cr2.f3 = ae2.f1
) ON a.f1 = cr2.f2 AND ae2.f2 < now() - INTERVAL 7 DAY AND
cr.f4 = cr2.f4
GROUP BY a.f3, cr.f4;
f3	f4	count
1	abc	1
1	def	2
drop table t1, t2, t3;
CREATE TABLE t1 (a INT KEY, b INT);
INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4);
EXPLAIN EXTENDED SELECT a, b FROM t1 WHERE a > 1 AND a = b LIMIT 2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using index condition; Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = `test`.`t1`.`a` and `test`.`t1`.`a` > 1 limit 2
EXPLAIN EXTENDED SELECT a, b FROM t1 WHERE a > 1 AND b = a LIMIT 2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using index condition; Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = `test`.`t1`.`a` and `test`.`t1`.`a` > 1 limit 2
DROP TABLE t1;
#
# Bug#47019: Assertion failed: 0, file .\rt_mbr.c, line 138 when 
# forcing a spatial index
#
CREATE TABLE t1(a LINESTRING NOT NULL, SPATIAL KEY(a));
INSERT INTO t1 VALUES
(GEOMFROMTEXT('LINESTRING(-1 -1, 1 -1, -1 -1, -1 1, 1 1)')),
(GEOMFROMTEXT('LINESTRING(-1 -1, 1 -1, -1 -1, -1 1, 1 1)'));
EXPLAIN SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	2	Range checked for each record (index map: 0x1)
SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2;
1
1
1
1
1
EXPLAIN SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2 FORCE INDEX(a);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	2	Range checked for each record (index map: 0x1)
SELECT 1 FROM t1 NATURAL LEFT JOIN t1 AS t2 FORCE INDEX(a);
1
1
1
1
1
DROP TABLE t1;
#
# Bug #48291 : crash with row() operator,select into @var, and 
#   subquery returning multiple rows
#
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (2),(3);
# Should not crash
SELECT 1 FROM t1 WHERE a <> 1 AND NOT
ROW(1,a) <=> ROW(1,(SELECT 1 FROM t1))
INTO @var0;
ERROR 21000: Subquery returns more than 1 row
DROP TABLE t1;
#
# Bug #48458: simple query tries to allocate enormous amount of
#   memory
#
CREATE TABLE t1(a INT NOT NULL, b YEAR);
INSERT IGNORE INTO t1 VALUES ();
Warnings:
Warning	1364	Field 'a' doesn't have a default value
CREATE TABLE t2(c INT);
# Should not err out because of out-of-memory
SELECT 1 FROM t2 JOIN t1 ON 1=1
WHERE a != '1' AND NOT a >= b OR NOT ROW(b,a )<> ROW(a,a);
1
DROP TABLE t1,t2;
#
# Bug #49199: Optimizer handles incorrectly: 
# field='const1' AND field='const2' in some cases

CREATE TABLE t1(a DATETIME NOT NULL);
INSERT INTO t1 VALUES('2001-01-01');
SELECT * FROM t1 WHERE a='2001-01-01' AND a='2001-01-01 00:00:00';
a
2001-01-01 00:00:00
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01' AND a='2001-01-01 00:00:00';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	100.00	
Warnings:
Note	1003	select '2001-01-01 00:00:00' AS `a` from dual where 1
DROP TABLE t1;
CREATE TABLE t1(a DATE NOT NULL);
INSERT INTO t1 VALUES('2001-01-01');
SELECT * FROM t1 WHERE a='2001-01-01' AND a='2001-01-01 00:00:00';
a
2001-01-01
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01' AND a='2001-01-01 00:00:00';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	100.00	
Warnings:
Note	1003	select '2001-01-01' AS `a` from dual where 1
DROP TABLE t1;
CREATE TABLE t1(a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
INSERT INTO t1 VALUES('2001-01-01');
SELECT * FROM t1 WHERE a='2001-01-01' AND a='2001-01-01 00:00:00';
a
2001-01-01 00:00:00
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01' AND a='2001-01-01 00:00:00';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	100.00	
Warnings:
Note	1003	select '2001-01-01 00:00:00' AS `a` from dual where 1
DROP TABLE t1;
CREATE TABLE t1(a DATETIME NOT NULL, b DATE NOT NULL);
INSERT INTO t1 VALUES('2001-01-01', '2001-01-01');
SELECT * FROM t1 WHERE a='2001-01-01' AND a=b AND b='2001-01-01 00:00:00';
a	b
2001-01-01 00:00:00	2001-01-01
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01' AND a=b AND b='2001-01-01 00:00:00';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	100.00	
Warnings:
Note	1003	select '2001-01-01 00:00:00' AS `a`,'2001-01-01' AS `b` from dual where 1
DROP TABLE t1;
CREATE TABLE t1(a DATETIME NOT NULL, b VARCHAR(20) NOT NULL);
INSERT INTO t1 VALUES('2001-01-01', '2001-01-01');
SELECT * FROM t1 WHERE a='2001-01-01' AND a=b AND b='2001-01-01 00:00:00';
a	b
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01' AND a=b AND b='2001-01-01 00:00:00';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
Warnings:
Note	1003	select '2001-01-01 00:00:00' AS `a`,'2001-01-01' AS `b` from dual where 0
SELECT * FROM t1 WHERE a='2001-01-01 00:00:00' AND a=b AND b='2001-01-01';
a	b
2001-01-01 00:00:00	2001-01-01
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='2001-01-01 00:00:00' AND a=b AND b='2001-01-01';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	100.00	
Warnings:
Note	1003	select '2001-01-01 00:00:00' AS `a`,'2001-01-01' AS `b` from dual where 1
DROP TABLE t1;
CREATE TABLE t1(a DATETIME NOT NULL, b DATE NOT NULL);
INSERT INTO t1 VALUES('2001-01-01', '2001-01-01');
SELECT x.a, y.a, z.a FROM t1 x 
JOIN t1 y ON x.a=y.a 
JOIN t1 z ON y.a=z.a 
WHERE x.a='2001-01-01' AND z.a='2001-01-01 00:00:00';
a	a	a
2001-01-01 00:00:00	2001-01-01 00:00:00	2001-01-01 00:00:00
EXPLAIN EXTENDED SELECT x.a, y.a, z.a FROM t1 x 
JOIN t1 y ON x.a=y.a 
JOIN t1 z ON y.a=z.a 
WHERE x.a='2001-01-01' AND z.a='2001-01-01 00:00:00';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	x	system	NULL	NULL	NULL	NULL	1	100.00	
1	SIMPLE	y	system	NULL	NULL	NULL	NULL	1	100.00	
1	SIMPLE	z	system	NULL	NULL	NULL	NULL	1	100.00	
Warnings:
Note	1003	select '2001-01-01 00:00:00' AS `a`,'2001-01-01 00:00:00' AS `a`,'2001-01-01 00:00:00' AS `a` from dual where 1
DROP TABLE t1;
#
# Bug #49897: crash in ptr_compare when char(0) NOT NULL 
# column is used for ORDER BY
#
SET @old_sort_buffer_size= @@session.sort_buffer_size;
SET @@sort_buffer_size= 40000;
CREATE TABLE t1(a CHAR(0) NOT NULL);
INSERT IGNORE INTO t1 VALUES (0), (0), (0);
INSERT INTO t1 SELECT t11.a FROM t1 t11, t1 t12;
INSERT INTO t1 SELECT t11.a FROM t1 t11, t1 t12;
INSERT INTO t1 SELECT t11.a FROM t1 t11, t1 t12;
EXPLAIN SELECT a FROM t1 ORDER BY a;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	24492	
SELECT a FROM t1 ORDER BY a;
DROP TABLE t1;
CREATE TABLE t1(a CHAR(0) NOT NULL, b CHAR(0) NOT NULL, c int);
INSERT IGNORE INTO t1 VALUES (0, 0, 0), (0, 0, 2), (0, 0, 1);
INSERT INTO t1 SELECT t11.a, t11.b, t11.c FROM t1 t11, t1 t12;
INSERT INTO t1 SELECT t11.a, t11.b, t11.c FROM t1 t11, t1 t12;
INSERT INTO t1 SELECT t11.a, t11.b, t11.c FROM t1 t11, t1 t12;
EXPLAIN SELECT a FROM t1 ORDER BY a LIMIT 5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	24492	
SELECT a FROM t1 ORDER BY a LIMIT 5;
a





EXPLAIN SELECT * FROM t1 ORDER BY a, b LIMIT 5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	24492	
SELECT * FROM t1 ORDER BY a, b LIMIT 5;
a	b	c
		0
		2
		1
		0
		2
EXPLAIN SELECT * FROM t1 ORDER BY a, b, c LIMIT 5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	24492	Using filesort
SELECT * FROM t1 ORDER BY a, b, c LIMIT 5;
a	b	c
		0
		0
		0
		0
		0
EXPLAIN SELECT * FROM t1 ORDER BY c, a LIMIT 5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	24492	Using filesort
SELECT * FROM t1 ORDER BY c, a LIMIT 5;
a	b	c
		0
		0
		0
		0
		0
SET @@sort_buffer_size= @old_sort_buffer_size;
DROP TABLE t1;
End of 5.0 tests
create table t1(a INT, KEY (a));
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
SELECT a FROM t1 ORDER BY a LIMIT 2;
a
1
2
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296;
a
3
4
5
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297;
a
3
4
5
DROP TABLE t1;
CREATE TABLE t1 (date_key date);
CREATE TABLE t2 (
pk int,
int_nokey int,
int_key int,
date_key date NOT NULL,
date_nokey date,
varchar_key varchar(1)
);
INSERT INTO t2 VALUES 
(1,1,1,'0000-00-00',NULL,NULL),
(1,1,1,'0000-00-00',NULL,NULL);
SELECT 1 FROM t2 WHERE pk > ANY (SELECT 1 FROM t2);
1
SELECT COUNT(DISTINCT 1) FROM t2 
WHERE date_key = (SELECT 1 FROM t1 WHERE t2.date_key IS NULL) GROUP BY pk;
COUNT(DISTINCT 1)
SELECT date_nokey FROM t2
WHERE int_key IN (SELECT 1 FROM t1)
HAVING date_nokey = '10:41:7' 
ORDER BY date_key;
date_nokey
Warnings:
Warning	1292	Truncated incorrect datetime value: '10:41:7'
DROP TABLE t1,t2;
CREATE TABLE t1 (a INT NOT NULL, b INT);
INSERT INTO t1 VALUES (1, 1);
EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a=a AND a=a) OR b > 2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	100.00	
Warnings:
Note	1003	select 1 AS `a`,1 AS `b` from dual where 1
SELECT * FROM t1 WHERE (a=a AND a=a) OR b > 2;
a	b
1	1
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, c INT NOT NULL);
EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a=a AND b=b AND c=c) OR b > 20;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	0.00	Const row not found
Warnings:
Note	1003	select NULL AS `a`,NULL AS `b`,NULL AS `c` from `test`.`t1` where 1
EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a=a AND a=a AND b=b) OR b > 20;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	0.00	Const row not found
Warnings:
Note	1003	select NULL AS `a`,NULL AS `b`,NULL AS `c` from `test`.`t1` where 1
EXPLAIN EXTENDED SELECT * FROM t1 WHERE (a=a AND b=b AND a=a) OR b > 20;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	0.00	Const row not found
Warnings:
Note	1003	select NULL AS `a`,NULL AS `b`,NULL AS `c` from `test`.`t1` where 1
DROP TABLE t1;
#
# Bug#45266: Uninitialized variable lead to an empty result.
#
drop table if exists A,AA,B,BB;
CREATE TABLE `A` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`date_key` date NOT NULL,
`date_nokey` date NOT NULL,
`datetime_key` datetime NOT NULL,
`int_nokey` int(11) NOT NULL,
`time_key` time NOT NULL,
`time_nokey` time NOT NULL,
PRIMARY KEY (`pk`),
KEY `date_key` (`date_key`),
KEY `time_key` (`time_key`),
KEY `datetime_key` (`datetime_key`)
);
CREATE TABLE `AA` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`int_nokey` int(11) NOT NULL,
`time_key` time NOT NULL,
KEY `time_key` (`time_key`),
PRIMARY KEY (`pk`)
);
CREATE TABLE `B` (
`date_nokey` date NOT NULL,
`date_key` date NOT NULL,
`time_key` time NOT NULL,
`datetime_nokey` datetime NOT NULL,
`varchar_key` varchar(1) NOT NULL,
KEY `date_key` (`date_key`),
KEY `time_key` (`time_key`),
KEY `varchar_key` (`varchar_key`)
);
INSERT INTO `B` VALUES ('2003-07-28','2003-07-28','15:13:38','0000-00-00 00:00:00','f'),('0000-00-00','0000-00-00','00:05:48','2004-07-02 14:34:13','x');
CREATE TABLE `BB` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`int_nokey` int(11) NOT NULL,
`date_key` date NOT NULL,
`varchar_nokey` varchar(1) NOT NULL,
`date_nokey` date NOT NULL,
PRIMARY KEY (`pk`),
KEY `date_key` (`date_key`)
);
INSERT INTO `BB` VALUES (10,8,'0000-00-00','i','0000-00-00'),(11,0,'2005-08-18','','2005-08-18');
SELECT table1 . `pk` AS field1 
FROM 
(BB AS table1 INNER JOIN 
(AA AS table2 STRAIGHT_JOIN A AS table3 
ON ( table3 . `date_key` = table2 . `pk` ))
ON ( table3 . `datetime_key` = table2 . `int_nokey` ))
WHERE  ( table3 . `date_key` <= 4 AND table2 . `pk` = table1 . `varchar_nokey`)
GROUP BY field1 ;
field1
SELECT table3 .`date_key` field1
FROM
B table1 LEFT JOIN B table3 JOIN
(BB table6 JOIN A table7 ON table6 .`varchar_nokey`)
ON table6 .`int_nokey` ON table6 .`date_key`
  WHERE  NOT ( table1 .`varchar_key`  AND table7 .`pk`) GROUP  BY field1;
field1
NULL
SELECT table4 . `time_nokey` AS field1 FROM 
(AA AS table1 CROSS JOIN 
(AA AS table2 STRAIGHT_JOIN 
(B AS table3 STRAIGHT_JOIN A AS table4 
ON ( table4 . `date_key` = table3 . `time_key` ))
ON ( table4 . `pk` = table3 . `date_nokey` ))
ON ( table4 . `time_key` = table3 . `datetime_nokey` ))
WHERE  ( table4 . `time_key` < table1 . `time_key` AND
table1 . `int_nokey` != 'f')
GROUP BY field1  ORDER BY field1 , field1;
field1
SELECT table1 .`time_key` field2  FROM B table1  LEFT JOIN  BB JOIN A table5 ON table5 .`date_nokey`  ON table5 .`int_nokey` GROUP  BY field2;
field2
00:05:48
15:13:38
drop table A,AA,B,BB;
#end of test for bug#45266
#
# Bug#33546: Slowdown on re-evaluation of constant expressions.
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (2);
SELECT * FROM t1 WHERE a = 1 + 1;
a
2
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 1 + 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = <cache>(1 + 1)
SELECT * FROM t1 HAVING a = 1 + 1;
a
2
EXPLAIN EXTENDED SELECT * FROM t1 HAVING a = 1 + 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` having `test`.`t1`.`a` = <cache>(1 + 1)
SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
a	b
4	2
EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	1	100.00	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = <cache>(2 + (1 + 1))
SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
b	a
2	3
EXPLAIN EXTENDED SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	1	100.00	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
Warnings:
Note	1003	select 2 AS `b`,`test`.`t1`.`a` AS `a` from `test`.`t1` where 1
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > UNIX_TIMESTAMP('2009-03-10 00:00:00');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > <cache>(unix_timestamp('2009-03-10 00:00:00'))
CREATE FUNCTION f1() RETURNS INT DETERMINISTIC
BEGIN
SET @cnt := @cnt + 1;
RETURN 1;
END;|
SET @cnt := 0;
SELECT * FROM t1 WHERE a = f1();
a
1
SELECT @cnt;
@cnt
1
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = f1();
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = <cache>(`f1`())
DROP TABLE t1, t2;
DROP FUNCTION f1;
# End of bug#33546
# 
# BUG#48052: Valgrind warning - uninitialized value in init_read_record()
# 
CREATE TABLE t1 (
pk int(11) NOT NULL,
i int(11) DEFAULT NULL,
v varchar(1) DEFAULT NULL,
PRIMARY KEY (pk)
);
INSERT INTO t1 VALUES (2,7,'m');
INSERT INTO t1 VALUES (3,9,'m');
SELECT  v
FROM t1
WHERE NOT pk > 0  
HAVING v <= 't' 
ORDER BY pk;
v
DROP TABLE t1;
#
# Bug#49489 Uninitialized cache led to a wrong result.
#
CREATE TABLE t1(c1 DOUBLE(5,4));
INSERT INTO t1 VALUES (9.1234);
SELECT * FROM t1 WHERE c1 < 9.12345;
c1
9.1234
DROP TABLE t1;
# End of test for bug#49489.
#
# Bug #49517: Inconsistent behavior while using 
# NULLable BIGINT and INT columns in comparison
#
CREATE TABLE t1(a BIGINT UNSIGNED NOT NULL, b BIGINT NULL, c INT NULL);
INSERT INTO t1 VALUES(105, NULL, NULL);
SELECT * FROM t1 WHERE b < 102;
a	b	c
SELECT * FROM t1 WHERE c < 102;
a	b	c
SELECT * FROM t1 WHERE 102 < b;
a	b	c
SELECT * FROM t1 WHERE 102 < c;
a	b	c
DROP TABLE t1;
#
# Bug #54459: Assertion failed: param.sort_length, 
# file .\filesort.cc, line 149 (part II)
#
CREATE TABLE t1(a ENUM('') NOT NULL);
INSERT INTO t1 VALUES (), (), ();
EXPLAIN SELECT 1 FROM t1 ORDER BY a COLLATE latin1_german2_ci;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using filesort
SELECT 1 FROM t1 ORDER BY a COLLATE latin1_german2_ci;
1
1
1
1
DROP TABLE t1;
#
# Bug #702310: usage of 2 join buffers after ref access to an empty table 
#
CREATE TABLE t1 (f1 int) ;
INSERT INTO t1 VALUES (9);
CREATE TABLE t2 (f1 int);
INSERT INTO t2 VALUES (3),(7),(18);
INSERT INTO t2 VALUES (3),(7),(18);
INSERT INTO t2 VALUES (3),(7),(18);
INSERT INTO t2 VALUES (3),(7),(18);
CREATE TABLE t3 (f1 int);
INSERT INTO t3 VALUES (17);
CREATE TABLE t4  (f1 int PRIMARY KEY, f2 varchar(1024)) ;
CREATE TABLE t5 (f1 int) ;
INSERT INTO t5 VALUES (20),(5);
CREATE TABLE t6(f1 int);
INSERT INTO t6 VALUES (9),(7);
SET @save_join_buffer_size=@@join_buffer_size,@@join_buffer_size = 2176;
EXPLAIN
SELECT STRAIGHT_JOIN * FROM t2, (t1 LEFT JOIN (t3,t4) ON t1.f1 = t4.f1), t5, t6;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	12	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	Using join buffer (flat, BNL join)
1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	1	Using where
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	4	test.t1.f1	1	
1	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (flat, BNL join)
1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (flat, BNL join)
SELECT STRAIGHT_JOIN * FROM t2, (t1 LEFT JOIN (t3,t4) ON t1.f1 = t4.f1), t5, t6;
f1	f1	f1	f1	f2	f1	f1
3	9	NULL	NULL	NULL	20	9
7	9	NULL	NULL	NULL	20	9
18	9	NULL	NULL	NULL	20	9
3	9	NULL	NULL	NULL	20	9
7	9	NULL	NULL	NULL	20	9
3	9	NULL	NULL	NULL	20	7
7	9	NULL	NULL	NULL	20	7
18	9	NULL	NULL	NULL	20	7
3	9	NULL	NULL	NULL	20	7
7	9	NULL	NULL	NULL	20	7
18	9	NULL	NULL	NULL	20	9
3	9	NULL	NULL	NULL	20	9
3	9	NULL	NULL	NULL	5	9
7	9	NULL	NULL	NULL	5	9
18	9	NULL	NULL	NULL	5	9
18	9	NULL	NULL	NULL	20	7
3	9	NULL	NULL	NULL	20	7
3	9	NULL	NULL	NULL	5	7
7	9	NULL	NULL	NULL	5	7
18	9	NULL	NULL	NULL	5	7
3	9	NULL	NULL	NULL	5	9
7	9	NULL	NULL	NULL	5	9
18	9	NULL	NULL	NULL	5	9
3	9	NULL	NULL	NULL	5	9
7	9	NULL	NULL	NULL	20	9
3	9	NULL	NULL	NULL	5	7
7	9	NULL	NULL	NULL	5	7
18	9	NULL	NULL	NULL	5	7
3	9	NULL	NULL	NULL	5	7
7	9	NULL	NULL	NULL	20	7
18	9	NULL	NULL	NULL	20	9
3	9	NULL	NULL	NULL	20	9
7	9	NULL	NULL	NULL	20	9
18	9	NULL	NULL	NULL	20	9
7	9	NULL	NULL	NULL	5	9
18	9	NULL	NULL	NULL	20	7
3	9	NULL	NULL	NULL	20	7
7	9	NULL	NULL	NULL	20	7
18	9	NULL	NULL	NULL	20	7
7	9	NULL	NULL	NULL	5	7
18	9	NULL	NULL	NULL	5	9
3	9	NULL	NULL	NULL	5	9
7	9	NULL	NULL	NULL	5	9
18	9	NULL	NULL	NULL	5	9
18	9	NULL	NULL	NULL	5	7
3	9	NULL	NULL	NULL	5	7
7	9	NULL	NULL	NULL	5	7
18	9	NULL	NULL	NULL	5	7
SET SESSION join_buffer_size = @save_join_buffer_size;
DROP TABLE t1,t2,t3,t4,t5,t6;
#
# Bug #698882: best equality substitution not applied to ref 
#
CREATE TABLE t1 (a1 int NOT NULL, b1 char(10), INDEX idx (a1));
CREATE TABLE t2 (a2 int NOT NULL, b2 char(10), INDEX idx (a2));
CREATE TABLE t3 (a3 int NOT NULL, b3 char(10), INDEX idx (a3));
INSERT INTO t1 VALUES (2,'xx'), (1,'xxx'),  (11,'xxxxxxx');
INSERT INTO t2 VALUES
(7,'yyyy'), (2,'y'), (3,'yyy'), (1,'yy'), (1,'yyyyy'),
(3,'yy'),  (1,'y'), (4,'yyy'), (7,'y'),  (4,'yyyyy'), (7,'yyy'),
(7,'yyyy'), (2,'yy'),  (3,'yyy'), (1,'yyyyyyyy'), (1,'yyyyy'),
(3,'yy'), (1,'yyy'), (4,'yyy'), (7,'y'), (4,'yyyyy'), (7,'yyy');
INSERT INTO t3 VALUES
(9,'zzzzzzz'), (2,'zzzzz'), (1,'z'), (9,'zz'), (1,'zz'), (5,'zzzzzzz'),
(4,'zz'), (3,'z'), (5,'zzzzzz'), (3,'zz'), (4,'zzzz'), (3,'z'),
(9,'zzzzzzzz'), (2,'zz'), (1,'zz'), (9,'zzz'), (1,'zzz'), (5,'zzzzzzzz'),
(4,'zzz'), (3,'zz'), (5,'zzzzzzz'), (3,'zzz'), (4,'zzzzz'), (3,'zz'),
(9,'zzzzzz'), (2,'zzzz'), (1,'zzz'), (9,'z'), (1,'z'), (5,'zzzzzz'),
(4,'z'), (3,'zzz'), (5,'zzzzz'), (3,'z'), (4,'zzz'), (3,'zzzz'),
(9,'zzzzz'), (2,'zzz'), (1,'zzzz'), (9,'zzz'), (1,'zzzz'), (5,'zzzzz'),
(4,'zzz'), (3,'zzzz'), (5,'zzzz'), (3,'zzz'), (4,'zz'), (3,'zzzzz');
set @tmp= @@optimizer_switch;
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN SELECT * from t1,t2,t3 WHERE t3.a3=t1.a1 AND t2.a2=t1.a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	idx	NULL	NULL	NULL	3	
1	SIMPLE	t2	ref	idx	idx	4	test.t1.a1	2	
1	SIMPLE	t3	ref	idx	idx	4	test.t1.a1	5	
EXPLAIN SELECT * FROM t1,t2,t3 WHERE t2.a2=t1.a1 AND t3.a3=t1.a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	idx	NULL	NULL	NULL	3	
1	SIMPLE	t2	ref	idx	idx	4	test.t1.a1	2	
1	SIMPLE	t3	ref	idx	idx	4	test.t1.a1	5	
EXPLAIN SELECT * FROM t1,t2,t3 WHERE t2.a2=t1.a1 AND t3.a3=t2.a2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	idx	NULL	NULL	NULL	3	
1	SIMPLE	t2	ref	idx	idx	4	test.t1.a1	2	
1	SIMPLE	t3	ref	idx	idx	4	test.t1.a1	5	
SELECT * from t1,t2,t3
WHERE t3.a3=t1.a1 AND t2.a2=t1.a1 AND
LENGTH(CONCAT(CONCAT(t1.b1,t2.b2),t3.b3)) <= 7;
a1	b1	a2	b2	a3	b3
1	xxx	1	y	1	z
1	xxx	1	y	1	z
1	xxx	1	y	1	zz
1	xxx	1	y	1	zz
1	xxx	1	y	1	zzz
1	xxx	1	y	1	zzz
1	xxx	1	yy	1	z
1	xxx	1	yy	1	z
1	xxx	1	yy	1	zz
1	xxx	1	yy	1	zz
1	xxx	1	yyy	1	z
1	xxx	1	yyy	1	z
2	xx	2	y	2	zz
2	xx	2	y	2	zzz
2	xx	2	y	2	zzzz
2	xx	2	yy	2	zz
2	xx	2	yy	2	zzz
SELECT * FROM t1,t2,t3
WHERE t2.a2=t1.a1 AND t3.a3=t1.a1 AND 
LENGTH(CONCAT(CONCAT(t1.b1,t2.b2),t3.b3)) <= 7;
a1	b1	a2	b2	a3	b3
1	xxx	1	y	1	z
1	xxx	1	y	1	z
1	xxx	1	y	1	zz
1	xxx	1	y	1	zz
1	xxx	1	y	1	zzz
1	xxx	1	y	1	zzz
1	xxx	1	yy	1	z
1	xxx	1	yy	1	z
1	xxx	1	yy	1	zz
1	xxx	1	yy	1	zz
1	xxx	1	yyy	1	z
1	xxx	1	yyy	1	z
2	xx	2	y	2	zz
2	xx	2	y	2	zzz
2	xx	2	y	2	zzzz
2	xx	2	yy	2	zz
2	xx	2	yy	2	zzz
SELECT * FROM t1,t2,t3
WHERE t2.a2=t1.a1 AND t3.a3=t2.a2 AND
LENGTH(CONCAT(CONCAT(t1.b1,t2.b2),t3.b3)) <= 7;
a1	b1	a2	b2	a3	b3
1	xxx	1	y	1	z
1	xxx	1	y	1	z
1	xxx	1	y	1	zz
1	xxx	1	y	1	zz
1	xxx	1	y	1	zzz
1	xxx	1	y	1	zzz
1	xxx	1	yy	1	z
1	xxx	1	yy	1	z
1	xxx	1	yy	1	zz
1	xxx	1	yy	1	zz
1	xxx	1	yyy	1	z
1	xxx	1	yyy	1	z
2	xx	2	y	2	zz
2	xx	2	y	2	zzz
2	xx	2	y	2	zzzz
2	xx	2	yy	2	zz
2	xx	2	yy	2	zzz
SET SESSION optimizer_switch=@tmp;
DROP TABLE t1,t2,t3;
#
# Bug #707555: crash with equality substitution in ref 
#
CREATE TABLE t1 (f11 int, f12 int, PRIMARY KEY (f11), KEY (f12)) ;
INSERT INTO t1 VALUES (1,NULL), (8,NULL);
CREATE TABLE t2 (f21 int, f22 int, f23 int, KEY (f22)) ;
INSERT INTO t2 VALUES (1,NULL,3), (2,7,8);
CREATE TABLE t3 (f31 int, f32 int(11), PRIMARY KEY (f31), KEY (f32)) ;
INSERT INTO t3 VALUES (1,494862336);
CREATE TABLE t4 (f41 int, f42 int, PRIMARY KEY (f41), KEY (f42)) ;
INSERT INTO t4 VALUES (1,NULL), (8,NULL);
CREATE TABLE t5 (f51 int, PRIMARY KEY (f51)) ;
INSERT IGNORE INTO t5 VALUES (100);
CREATE TABLE t6 (f61 int, f62 int, KEY (f61)) ;
INSERT INTO t6 VALUES (NULL,1), (3,10);
CREATE TABLE t7 (f71 int, f72 int, KEY (f72)) ;
INSERT INTO t7 VALUES (1,NULL), (2,7);
EXPLAIN
SELECT t2.f23 FROM
(t1 LEFT JOIN (t2 JOIN t3 ON t2.f22=t3.f32) ON t1.f11=t3.f31)
LEFT JOIN
(((t4 JOIN t5 ON t4.f42=t5.f51) LEFT JOIN t6 ON t6.f62>0) JOIN t7 ON t6.f61>0)
ON t3.f31 = t6.f61
WHERE t7.f71>0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	system	PRIMARY,f32	NULL	NULL	NULL	1	
1	SIMPLE	t5	system	PRIMARY	NULL	NULL	NULL	1	
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
1	SIMPLE	t2	ref	f22	f22	5	const	1	
1	SIMPLE	t4	ref	f42	f42	5	const	1	Using index
1	SIMPLE	t6	ref	f61	f61	5	const	1	Using where
1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
SELECT t2.f23 FROM
(t1 LEFT JOIN (t2 JOIN t3 ON t2.f22=t3.f32) ON t1.f11=t3.f31)
LEFT JOIN
(((t4 JOIN t5 ON t4.f42=t5.f51) LEFT JOIN t6 ON t6.f62>0) JOIN t7 ON t6.f61>0)
ON t3.f31 = t6.f61
WHERE t7.f71>0;
f23
DROP TABLE t1,t2,t3,t4,t5,t6,t7;
CREATE TABLE t1(f1 int UNSIGNED) engine=myisam;
INSERT INTO t1 VALUES (3),(2),(1);
set sql_buffer_result=0;
SELECT f1 FROM t1 GROUP BY 1;
f1
1
2
3
SELECT f1 FROM t1 GROUP BY '123' = 'abc';
f1
3
SELECT 1 FROM t1 GROUP BY 1;
1
1
set sql_buffer_result=1;
SELECT f1 FROM t1 GROUP BY 1;
f1
1
2
3
SELECT f1 FROM t1 GROUP BY '123' = 'abc';
f1
3
SELECT 1 FROM t1 GROUP BY 1;
1
1
drop table t1;
set sql_buffer_result= 0;
#
# Bug #58422: Incorrect result when OUTER JOIN'ing 
# with an empty table
#
CREATE TABLE t_empty(pk INT PRIMARY KEY, i INT) ENGINE = MYISAM;
CREATE TABLE t1(pk INT PRIMARY KEY, i INT) ENGINE = MYISAM;
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
CREATE TABLE t2(pk INT PRIMARY KEY, i INT) ENGINE = MYISAM;
INSERT INTO t2 VALUES (1,1), (2,2), (3,3);
EXPLAIN
SELECT *
FROM 
t1
LEFT OUTER JOIN
(t2 INNER JOIN t_empty ON TRUE)
ON t1.pk=t2.pk
WHERE t2.pk <> 2;
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
SELECT *
FROM 
t1
LEFT OUTER JOIN
(t2 INNER JOIN t_empty ON TRUE)
ON t1.pk=t2.pk
WHERE t2.pk <> 2;
pk	i	pk	i	pk	i
EXPLAIN
SELECT *
FROM 
t1
LEFT OUTER JOIN
(t2 CROSS JOIN t_empty)
ON t1.pk=t2.pk
WHERE t2.pk <> 2;
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
SELECT *
FROM 
t1
LEFT OUTER JOIN
(t2 CROSS JOIN t_empty)
ON t1.pk=t2.pk
WHERE t2.pk <> 2;
pk	i	pk	i	pk	i
EXPLAIN
SELECT *
FROM 
t1
LEFT OUTER JOIN
(t2 INNER JOIN t_empty ON t_empty.i=t2.i)
ON t1.pk=t2.pk
WHERE t2.pk <> 2;
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
SELECT *
FROM 
t1
LEFT OUTER JOIN
(t2 INNER JOIN t_empty ON t_empty.i=t2.i)
ON t1.pk=t2.pk
WHERE t2.pk <> 2;
pk	i	pk	i	pk	i
DROP TABLE t1,t2,t_empty;
End of 5.1 tests
#
# Bug#45227: Lost HAVING clause led to a wrong result.
#
CREATE TABLE `CC` (
`int_nokey` int(11) NOT NULL,
`int_key` int(11) NOT NULL,
`varchar_key` varchar(1) NOT NULL,
`varchar_nokey` varchar(1) NOT NULL,
KEY `int_key` (`int_key`),
KEY `varchar_key` (`varchar_key`)
);
INSERT INTO `CC` VALUES
(0,8,'q','q'),(5,8,'m','m'),(7,3,'j','j'),(1,2,'z','z'),(8,2,'a','a'),(2,6,'',''),(1,8,'e'
,'e'),(8,9,'t','t'),(5,2,'q','q'),(4,6,'b','b'),(5,5,'w','w'),(3,2,'m','m'),(0,4,'x','x'),
(8,9,'',''),(0,6,'w','w'),(4,5,'x','x'),(0,0,'e','e'),(0,0,'e','e'),(2,8,'p','p'),(0,0,'x'
,'x');
EXPLAIN SELECT `varchar_nokey` G1  FROM CC  WHERE `int_nokey` AND `int_key`  <= 4
HAVING G1  ORDER  BY `varchar_key` LIMIT  6   ;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	CC	range	int_key	int_key	4	NULL	9	Using index condition; Using where; Using filesort
SELECT `varchar_nokey` G1  FROM CC  WHERE `int_nokey` AND `int_key`  <= 4
HAVING G1  ORDER  BY `varchar_key` LIMIT  6   ;
G1
Warnings:
Warning	1292	Truncated incorrect DOUBLE value: 'z'
Warning	1292	Truncated incorrect DOUBLE value: 'a'
Warning	1292	Truncated incorrect DOUBLE value: 'q'
Warning	1292	Truncated incorrect DOUBLE value: 'm'
Warning	1292	Truncated incorrect DOUBLE value: 'j'
DROP TABLE CC;
# End of test#45227
#                    
# BUG#776274: substitution of a single row table
#                    
CREATE TABLE t1 (a int NOT NULL , b int);
INSERT INTO t1 VALUES (2,2);
SELECT * FROM t1 WHERE a = b;
a	b
2	2
EXPLAIN
SELECT * FROM t1 WHERE a = b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	
DROP TABLE t1;
#
# Bug#54515: Crash in opt_range.cc::get_best_group_min_max on 
#            SELECT from VIEW with GROUP BY
#
CREATE TABLE t1 (
col_int_key int DEFAULT NULL,
KEY int_key (col_int_key)
) ;
INSERT INTO t1 VALUES (1),(2);
CREATE VIEW view_t1 AS 
SELECT t1.col_int_key AS col_int_key
FROM t1;
SELECT col_int_key FROM view_t1 GROUP BY col_int_key;
col_int_key
1
2
DROP VIEW view_t1;
DROP TABLE t1;
# End of test BUG#54515
#
# Bug #57203 Assertion `field_length <= 255' failed.
#
SELECT coalesce((avg(distinct (geomfromtext("point(25379 -22010)"))))) 
UNION ALL 
SELECT coalesce((avg(distinct (geomfromtext("point(25379 -22010)")))))
AS foo
;
ERROR HY000: Illegal parameter data type geometry for operation 'avg'
CREATE table t1(a text);
INSERT INTO t1 VALUES (''), ('');
SELECT avg(distinct(t1.a)) FROM t1, t1 t2
GROUP BY t2.a ORDER BY t1.a;
avg(distinct(t1.a))
0
DROP TABLE t1;
# End of test BUG#57203
#
# lp:822760 Wrong result with view + invalid dates
#
CREATE TABLE t1 (f1 date);
INSERT IGNORE INTO t1 VALUES ('0000-00-00');
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM t1 HAVING f1 = 'zz';
f1
0000-00-00
Warnings:
Warning	1292	Truncated incorrect datetime value: 'zz'
SELECT * FROM t1 HAVING f1 <= 'aa' ;
f1
0000-00-00
Warnings:
Warning	1292	Truncated incorrect datetime value: 'aa'
SELECT * FROM t1 HAVING f1 = 'zz' AND f1 <= 'aa' ;
f1
0000-00-00
Warnings:
Warning	1292	Truncated incorrect datetime value: 'zz'
Warning	1292	Truncated incorrect datetime value: 'aa'
SELECT * FROM t1 WHERE f1 = 'zz' AND f1 <= 'aa' ;
f1
0000-00-00
Warnings:
Warning	1292	Truncated incorrect datetime value: 'zz'
Warning	1292	Truncated incorrect datetime value: 'aa'
SELECT * FROM v1 HAVING f1 = 'zz' AND f1 <= 'aa' ;
f1
0000-00-00
Warnings:
Warning	1292	Truncated incorrect datetime value: 'zz'
Warning	1292	Truncated incorrect datetime value: 'aa'
DROP TABLE t1;
DROP VIEW v1;
#
# Bug#63020: Function "format"'s 'locale' argument is not considered
#	     when creating a "view'
#
CREATE TABLE t1 (f1 DECIMAL(10,2));
INSERT INTO t1 VALUES (11.67),(17865.3),(12345678.92);
CREATE VIEW view_t1 AS SELECT FORMAT(f1,1,'sk_SK') AS f1 FROM t1;
SHOW CREATE VIEW view_t1;
View	Create View	character_set_client	collation_connection
view_t1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_t1` AS select format(`t1`.`f1`,1,'sk_SK') AS `f1` from `t1`	latin1	latin1_swedish_ci
SELECT * FROM view_t1;
f1
11,7
17 865,3
12 345 678,9
DROP TABLE t1;
DROP VIEW view_t1;
# End of test  BUG#63020
#
# Bug #13571700 TINYBLOB NOT NULL, CRASH IN PROTOCOL::NET_STORE_DATA
#
CREATE TABLE t1 (a TINYBLOB NOT NULL);
SELECT a, COUNT(*) FROM t1 WHERE 0;
a	COUNT(*)
NULL	0
DROP TABLE t1;
SET @@optimizer_switch=@save_optimizer_switch;
#
# LP bug#994275 Assertion `real->type() == Item::FIELD_ITEM' failed
# in add_not_null_conds(JOIN*) with JOIN, ZEROFILL column, PK
#
CREATE TABLE t1 ( a INT(6) ZEROFILL );
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 ( b INT PRIMARY KEY );
INSERT INTO t2 VALUES (3),(4);
SELECT * FROM t1, t2 WHERE a=3 AND a=b;
a	b
drop table t1,t2;
#
# Bug mdev-4250: wrong transformation of WHERE condition with OR
#
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES (3,0), (2,0), (4,1), (5,0), (1,0);
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
pk	a
EXPLAIN EXTENDED 
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
Warnings:
Note	1003	select 2 AS `pk`,0 AS `a` from `test`.`t1` where 0
DROP TABLE t1;
SELECT * FROM mysql.time_zone 
WHERE ( NOT (Use_leap_seconds <= Use_leap_seconds AND Time_zone_id != 1) 
AND Time_zone_id = Time_zone_id 
OR Time_zone_id <> Time_zone_id ) 
AND Use_leap_seconds <> 'N';
Time_zone_id	Use_leap_seconds
#
# Bug mdev-4274: result of simplification of OR badly merged
#                into embedding AND  
#
CREATE TABLE t1 (a int, b int, INDEX idx(b)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (8,8);
CREATE TABLE t2 (c int, INDEX idx(c)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (8), (9);
EXPLAIN EXTENDED
SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) 
WHERE 1 IS NULL OR b < 33 AND b = c;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	system	idx	NULL	NULL	NULL	1	100.00	
1	SIMPLE	t2	ref	idx	idx	5	const	1	100.00	Using index
Warnings:
Note	1003	select 8 AS `a`,8 AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where `test`.`t2`.`c` = 8
SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) 
WHERE 1 IS NULL OR b < 33 AND b = c;
a	b	c
8	8	8
DROP TABLE t1,t2;
#
# Bug mdev-4413: another manifestations of bug mdev-4274
#                (valgrind complains)
#
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (7,1);
CREATE TABLE t2 (c int) ENGINE=MyISAM;
INSERT INTO t2 VALUES (0), (8);
SELECT * FROM t1, t2 
WHERE c = a AND
( 0 OR ( b BETWEEN 45 AND 300 OR a > 45 AND a < 100 ) AND b = c );
a	b	c
DROP TABLE t1, t2;
#
# Bug mdev-4355: equalities from the result of simplification of OR
#                are not propagated to lower AND levels
#
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,101),(2,102),(3,103),(4,104),(5,11);
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (1 != 1 OR a = 5) AND (b != 1 OR a = 1);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`a` = 5 and `test`.`t1`.`b` <> 1
SELECT * FROM t1 WHERE (1 != 1 OR a = 5) AND (b != 1 OR a = 1);
a	b
5	11
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (b != 1 OR a = 1) AND (1 != 1 OR a = 5);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`a` = 5 and `test`.`t1`.`b` <> 1
SELECT * FROM t1 WHERE (b != 1 OR a = 1) AND (1 != 1 OR a = 5);
a	b
5	11
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (b != 1 OR a = 1) AND (a = 5 OR 1 != 1);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`a` = 5 and `test`.`t1`.`b` <> 1
SELECT * FROM t1 WHERE (b != 1 OR a = 1) AND (a = 5 OR 1 != 1);
a	b
5	11
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (b = 1 OR a = 1) AND (b = 5 AND a = 5 OR 1 != 1);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where 0
SELECT * FROM t1 WHERE (b = 1 OR a = 1) AND (b = 5 AND a = 5 OR 1 != 1);
a	b
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (b = 1 OR a = 5) AND (b = 5 AND a = 5 OR 1 != 1);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 5 and `test`.`t1`.`a` = 5
SELECT * FROM t1 WHERE (b = 1 OR a = 5) AND (b = 5 AND a = 5 OR 1 != 1);
a	b
DROP TABLE t1;
#
# Bug mdev-4418: impossible multiple equality in OR formula 
#                after row substitution
#
CREATE TABLE t1 (a int, b varchar(1)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (0,'j'), (8,'v');
CREATE TABLE t2 (c varchar(1), d varchar(1)) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('k','k');
EXPLAIN EXTENDED
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	1	100.00	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,'k' AS `c`,'k' AS `d` from `test`.`t1` where `test`.`t1`.`b` = 'k' and `test`.`t1`.`a` = 136
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
a	b	c	d
DROP TABLE t1,t2;
#
# Bug mdev-4944: range conditition in OR formula with fields
#                belonging to multiple equalities 
#
CREATE TABLE t1 (i1 int, j1 int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,8);
CREATE TABLE t2 (i2 int, INDEX idx (i2)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (8), (9);
EXPLAIN EXTENDED
SELECT * FROM t1, t2 
WHERE i1 = i2 AND ( FALSE OR ( j1 > 27 AND j1 < 100 OR j1 <= 3 ) AND j1 = i2 );
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
Warnings:
Note	1003	select 1 AS `i1`,8 AS `j1`,NULL AS `i2` from `test`.`t2` where 0
SELECT * FROM t1, t2 
WHERE i1 = i2 AND ( FALSE OR ( j1 > 27 AND j1 < 100 OR j1 <= 3 ) AND j1 = i2 );
i1	j1	i2
DROP TABLE t1,t2;
#
# Bug mdev-4971: equality propagation after merging degenerate 
#                disjunction into embedding AND level 
#
CREATE TABLE t1 (pk1 int, a1 int, b1 int, PRIMARY KEY(pk1)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,10,100), (2,20,200) ;
CREATE TABLE t2 (pk2 int, a2 int, PRIMARY KEY(pk2)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1,1);
SELECT * FROM t1, t2
WHERE a1 = pk2 AND ( ( b1 = 6 OR a2 > 4 ) AND pk2 = a2 OR pk1 IS NULL );
pk1	a1	b1	pk2	a2
EXPLAIN EXTENDED
SELECT * FROM t1, t2
WHERE a1 = pk2 AND ( ( b1 = 6 OR a2 > 4 ) AND pk2 = a2 OR pk1 IS NULL );
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	system	PRIMARY	NULL	NULL	NULL	1	100.00	
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
Warnings:
Note	1003	select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,1 AS `pk2`,1 AS `a2` from `test`.`t1` where `test`.`t1`.`a1` = 1 and `test`.`t1`.`b1` = 6
INSERT INTO t1 VALUES (3,1,6);
SELECT * FROM t1, t2
WHERE a1 = pk2 AND ( ( b1 = 6 OR a2 > 4 ) AND pk2 = a2 OR pk1 IS NULL );
pk1	a1	b1	pk2	a2
3	1	6	1	1
DROP TABLE t1,t2;
End of 5.3 tests
#
# mysql BUG#1271 Undefined variable in PASSWORD() 
# function is not handled correctly
#
create table t1 (
name VARCHAR(50) NOT NULL PRIMARY KEY,
pw VARCHAR(41) NOT NULL);
INSERT INTO t1 (name, pw) 
VALUES ('tom', PASSWORD('my_pw'));
SET @pass='my_pw';
SET @wrong='incorrect';
select * from t1;
name	pw
tom	*F305E8EC27734F687F2EB6EC03CF0F7AF27C18E1
select length(PASSWORD(@pass));
length(PASSWORD(@pass))
41
SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass);
name
tom
SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong);
name
SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined);
name
select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass));
(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass))
tom
select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong));
(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong))
NULL
select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined));
(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined))
NULL
drop table t1;
#
# Bug MDEV-24262 Server crashes in st_join_table::cleanup upon
# erroneous GROUP_CONCAT
#
CREATE TABLE t1 (a INT, b INT);
INSERT INTO t1 VALUES (1,10),(2,20);
SELECT b, GROUP_CONCAT(b ORDER BY 2), MIN(a) AS f FROM t1 GROUP BY b ORDER BY f;
ERROR 42S22: Unknown column '2' in 'order clause'
DROP TABLE t1;
#
# Bug MDEV-24560 SIGSEGV in st_join_table::cleanup + server and client
# hang + cross-mysqld-interaction + double free or corruption (!prev)
#
CREATE TABLE t1 (c INT);
SET SESSION sql_buffer_result=1;
SELECT GROUP_CONCAT(c ORDER BY 2) FROM t1;
GROUP_CONCAT(c ORDER BY 2)
NULL
SELECT GROUP_CONCAT(c ORDER BY 0) FROM t1;
GROUP_CONCAT(c ORDER BY 0)
NULL
DROP TABLE t1;
CREATE TABLE t1 (grp INT,c CHAR);
SET sql_buffer_result=1;
SELECT grp,GROUP_CONCAT(c ORDER BY 2) FROM t1 GROUP BY grp;
grp	GROUP_CONCAT(c ORDER BY 2)
DROP TABLE t1;
#
# Bug MDEV-28077 "Wrong create options" with "big_tables" option enabled
#
CREATE TABLE t1(a VARCHAR(16383) CHARACTER SET UTF32, KEY k(a));
Warnings:
Note	1071	Specified key was too long; max key length is 1000 bytes
INSERT INTO t1 VALUES ('abc'), ('def'), ('FFF'), ('abc'), ('FFF');
SET SESSION big_tables=ON;
SELECT DISTINCT COUNT(DISTINCT a) FROM t1;
COUNT(DISTINCT a)
3
PREPARE stmt FROM 'SELECT DISTINCT COUNT(DISTINCT a) FROM t1';
EXECUTE stmt;
COUNT(DISTINCT a)
3
EXECUTE stmt;
COUNT(DISTINCT a)
3
DROP TABLE t1;
End of 10.0 tests