summaryrefslogtreecommitdiff
path: root/mysql-test/r
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2010-12-29 13:45:38 -0800
committerIgor Babaev <igor@askmonty.org>2010-12-29 13:45:38 -0800
commita2a09f06bf151ca7637f867d904fd6604b5fd216 (patch)
tree1738e74f33808d69bbb72c3ea5231147cc925506 /mysql-test/r
parent18dc64eca2bbe29697043dc0ae51ae21d19af365 (diff)
parentf844a7bae7793a8595c68d544246ae7bb68a5e79 (diff)
downloadmariadb-git-a2a09f06bf151ca7637f867d904fd6604b5fd216.tar.gz
Merge.
Diffstat (limited to 'mysql-test/r')
-rw-r--r--mysql-test/r/archive.result1
-rw-r--r--mysql-test/r/connect.result4
-rw-r--r--mysql-test/r/index_intersect.result1039
-rw-r--r--mysql-test/r/index_intersect_innodb.result1038
-rw-r--r--mysql-test/r/index_merge_innodb.result5
-rw-r--r--mysql-test/r/index_merge_myisam.result23
-rw-r--r--mysql-test/r/optimizer_switch.result37
-rw-r--r--mysql-test/r/order_by.result4
-rw-r--r--mysql-test/r/partition_innodb_semi_consistent.result10
-rw-r--r--mysql-test/r/range.result4
-rw-r--r--mysql-test/r/range_vs_index_merge.result1370
-rw-r--r--mysql-test/r/range_vs_index_merge_innodb.result1372
-rw-r--r--mysql-test/r/subselect.result4
-rw-r--r--mysql-test/r/subselect_no_mat.result4
-rw-r--r--mysql-test/r/subselect_no_opts.result4
-rw-r--r--mysql-test/r/subselect_no_semijoin.result4
-rw-r--r--mysql-test/r/variables.result1
17 files changed, 4875 insertions, 49 deletions
diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result
index 5a731e6476c..ae79e237ade 100644
--- a/mysql-test/r/archive.result
+++ b/mysql-test/r/archive.result
@@ -12717,6 +12717,7 @@ COUNT(t1.a)
729
DROP TABLE t1;
SET @@join_buffer_size= @save_join_buffer_size;
+flush tables;
SHOW CREATE TABLE t1;
ERROR HY000: Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
SELECT * FROM t1;
diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result
index 690a6fb3bc3..00602093425 100644
--- a/mysql-test/r/connect.result
+++ b/mysql-test/r/connect.result
@@ -237,5 +237,9 @@ ERROR 28000: Access denied for user 'mysqltest_up2'@'localhost' (using password:
select user(), current_user();
user() current_user()
mysqltest_up2@localhost mysqltest_up2@%
+connect(localhost,mysqltest_nouser,newpw,test,MASTER_PORT,MASTER_SOCKET);
+ERROR 28000: Access denied for user 'mysqltest_nouser'@'localhost' (using password: YES)
+connect(localhost,mysqltest_nouser,,test,MASTER_PORT,MASTER_SOCKET);
+ERROR 28000: Access denied for user 'mysqltest_nouser'@'localhost' (using password: NO)
DROP USER mysqltest_up1@'%';
DROP USER mysqltest_up2@'%';
diff --git a/mysql-test/r/index_intersect.result b/mysql-test/r/index_intersect.result
new file mode 100644
index 00000000000..d8e1db97fdd
--- /dev/null
+++ b/mysql-test/r/index_intersect.result
@@ -0,0 +1,1039 @@
+DROP TABLE IF EXISTS t1,t2,t3,t4;
+DROP DATABASE IF EXISTS world;
+set names utf8;
+CREATE DATABASE world;
+use world;
+CREATE TABLE Country (
+Code char(3) NOT NULL default '',
+Name char(52) NOT NULL default '',
+SurfaceArea float(10,2) NOT NULL default '0.00',
+Population int(11) NOT NULL default '0',
+Capital int(11) default NULL,
+PRIMARY KEY (Code),
+UNIQUE INDEX (Name)
+);
+CREATE TABLE City (
+ID int(11) NOT NULL auto_increment,
+Name char(35) NOT NULL default '',
+Country char(3) NOT NULL default '',
+Population int(11) NOT NULL default '0',
+PRIMARY KEY (ID),
+INDEX (Population),
+INDEX (Country)
+);
+CREATE TABLE CountryLanguage (
+Country char(3) NOT NULL default '',
+Language char(30) NOT NULL default '',
+Percentage float(3,1) NOT NULL default '0.0',
+PRIMARY KEY (Country, Language),
+INDEX (Percentage)
+);
+SELECT COUNT(*) FROM Country;
+COUNT(*)
+239
+SELECT COUNT(*) FROM City;
+COUNT(*)
+4079
+SELECT COUNT(*) FROM CountryLanguage;
+COUNT(*)
+984
+CREATE INDEX Name ON City(Name);
+SET SESSION optimizer_switch='index_merge_sort_intersection=on';
+SELECT COUNT(*) FROM City;
+COUNT(*)
+4079
+SELECT COUNT(*) FROM City WHERE Name LIKE 'C%';
+COUNT(*)
+281
+SELECT COUNT(*) FROM City WHERE Name LIKE 'M%';
+COUNT(*)
+301
+SELECT COUNT(*) FROM City WHERE Population > 1000000;
+COUNT(*)
+237
+SELECT COUNT(*) FROM City WHERE Population > 1500000;
+COUNT(*)
+129
+SELECT COUNT(*) FROM City WHERE Population > 300000;
+COUNT(*)
+1062
+SELECT COUNT(*) FROM City WHERE Population > 7000000;
+COUNT(*)
+14
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'C%' AND Population > 1000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Name,Population 35,4 NULL 9 Using sort_intersect(Name,Population); Using where
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'M%' AND Population > 1500000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population,Name 4,35 NULL 5 Using sort_intersect(Population,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 300000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Name 35 NULL 164 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 7000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population 4 NULL 15 Using index condition; Using where; Using MRR
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'C%' AND Population > 1000000;
+ID Name Country Population
+1026 Calcutta [Kolkata] IND 4399819
+1027 Chennai (Madras) IND 3841396
+151 Chittagong BGD 1392860
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+212 Curitiba BRA 1584232
+2258 Cali COL 2077386
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+3539 Caracas VEN 1975294
+3795 Chicago USA 2896016
+608 Cairo EGY 6789479
+71 Córdoba ARG 1157507
+712 Cape Town ZAF 2352121
+926 Conakry GIN 1090610
+SELECT * FROM City
+WHERE Name LIKE 'C%' AND Population > 1000000;
+ID Name Country Population
+1026 Calcutta [Kolkata] IND 4399819
+1027 Chennai (Madras) IND 3841396
+151 Chittagong BGD 1392860
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+212 Curitiba BRA 1584232
+2258 Cali COL 2077386
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+3539 Caracas VEN 1975294
+3795 Chicago USA 2896016
+608 Cairo EGY 6789479
+71 Córdoba ARG 1157507
+712 Cape Town ZAF 2352121
+926 Conakry GIN 1090610
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'M%' AND Population > 1500000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+131 Melbourne AUS 2865329
+1381 Mashhad IRN 1887405
+2259 Medellín COL 1861265
+3520 Minsk BLR 1674000
+3580 Moscow RUS 8389200
+653 Madrid ESP 2879052
+766 Manila PHL 1581082
+942 Medan IDN 1843919
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 1500000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+131 Melbourne AUS 2865329
+1381 Mashhad IRN 1887405
+2259 Medellín COL 1861265
+3520 Minsk BLR 1674000
+3580 Moscow RUS 8389200
+653 Madrid ESP 2879052
+766 Manila PHL 1581082
+942 Medan IDN 1843919
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'M%' AND Population > 300000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+1042 Madurai IND 977856
+1051 Meerut IND 753778
+1074 Mysore IND 480692
+1081 Moradabad IND 429214
+1098 Malegaon IND 342595
+131 Melbourne AUS 2865329
+1366 Mosul IRQ 879000
+1381 Mashhad IRN 1887405
+1465 Milano ITA 1300977
+1559 Matsuyama JPN 466133
+1560 Matsudo JPN 461126
+1578 Machida JPN 364197
+1595 Miyazaki JPN 303784
+1810 Montréal CAN 1016376
+1816 Mississauga CAN 608072
+1882 Mombasa KEN 461753
+1945 Mudanjiang CHN 570000
+2005 Ma´anshan CHN 305421
+215 Manaus BRA 1255049
+223 Maceió BRA 786288
+2259 Medellín COL 1861265
+2267 Manizales COL 337580
+2300 Mbuji-Mayi COD 806475
+2348 Masan KOR 441242
+2440 Monrovia LBR 850000
+2454 Macao MAC 437500
+2487 Marrakech MAR 621914
+2491 Meknès MAR 460000
+250 Mauá BRA 375055
+2523 Monterrey MEX 1108499
+2526 Mexicali MEX 764902
+2530 Mérida MEX 703324
+2537 Morelia MEX 619958
+2554 Matamoros MEX 416428
+2557 Mazatlán MEX 380265
+256 Moji das Cruzes BRA 339194
+2698 Maputo MOZ 1018938
+2699 Matola MOZ 424662
+2711 Mandalay MMR 885300
+2712 Moulmein (Mawlamyine) MMR 307900
+2734 Managua NIC 959000
+2756 Mushin NGA 333200
+2757 Maiduguri NGA 320000
+2826 Multan PAK 1182441
+2975 Marseille FRA 798430
+3070 Munich [München] DEU 1194560
+3086 Mannheim DEU 307730
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3214 Mogadishu SOM 997000
+3364 Mersin (Içel) TUR 587212
+3371 Malatya TUR 330312
+3434 Mykolajiv UKR 508000
+3435 Mariupol UKR 490000
+3438 Makijivka UKR 384000
+3492 Montevideo URY 1236000
+3520 Minsk BLR 1674000
+3522 Mogiljov BLR 356000
+3540 Maracaíbo VEN 1304776
+3545 Maracay VEN 444443
+3547 Maturín VEN 319726
+3580 Moscow RUS 8389200
+3622 Magnitogorsk RUS 427900
+3625 Murmansk RUS 376300
+3636 Mahat?kala RUS 332800
+3810 Memphis USA 650100
+3811 Milwaukee USA 596974
+3834 Mesa USA 396375
+3837 Minneapolis USA 382618
+3839 Miami USA 362470
+462 Manchester GBR 430000
+653 Madrid ESP 2879052
+658 Málaga ESP 530553
+661 Murcia ESP 353504
+766 Manila PHL 1581082
+77 Mar del Plata ARG 512880
+778 Makati PHL 444867
+781 Marikina PHL 391170
+783 Muntinlupa PHL 379310
+786 Malabon PHL 338855
+80 Merlo ARG 463846
+83 Moreno ARG 356993
+87 Morón ARG 349246
+942 Medan IDN 1843919
+947 Malang IDN 716862
+962 Manado IDN 332288
+963 Mataram IDN 306600
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 300000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+1042 Madurai IND 977856
+1051 Meerut IND 753778
+1074 Mysore IND 480692
+1081 Moradabad IND 429214
+1098 Malegaon IND 342595
+131 Melbourne AUS 2865329
+1366 Mosul IRQ 879000
+1381 Mashhad IRN 1887405
+1465 Milano ITA 1300977
+1559 Matsuyama JPN 466133
+1560 Matsudo JPN 461126
+1578 Machida JPN 364197
+1595 Miyazaki JPN 303784
+1810 Montréal CAN 1016376
+1816 Mississauga CAN 608072
+1882 Mombasa KEN 461753
+1945 Mudanjiang CHN 570000
+2005 Ma´anshan CHN 305421
+215 Manaus BRA 1255049
+223 Maceió BRA 786288
+2259 Medellín COL 1861265
+2267 Manizales COL 337580
+2300 Mbuji-Mayi COD 806475
+2348 Masan KOR 441242
+2440 Monrovia LBR 850000
+2454 Macao MAC 437500
+2487 Marrakech MAR 621914
+2491 Meknès MAR 460000
+250 Mauá BRA 375055
+2523 Monterrey MEX 1108499
+2526 Mexicali MEX 764902
+2530 Mérida MEX 703324
+2537 Morelia MEX 619958
+2554 Matamoros MEX 416428
+2557 Mazatlán MEX 380265
+256 Moji das Cruzes BRA 339194
+2698 Maputo MOZ 1018938
+2699 Matola MOZ 424662
+2711 Mandalay MMR 885300
+2712 Moulmein (Mawlamyine) MMR 307900
+2734 Managua NIC 959000
+2756 Mushin NGA 333200
+2757 Maiduguri NGA 320000
+2826 Multan PAK 1182441
+2975 Marseille FRA 798430
+3070 Munich [München] DEU 1194560
+3086 Mannheim DEU 307730
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3214 Mogadishu SOM 997000
+3364 Mersin (Içel) TUR 587212
+3371 Malatya TUR 330312
+3434 Mykolajiv UKR 508000
+3435 Mariupol UKR 490000
+3438 Makijivka UKR 384000
+3492 Montevideo URY 1236000
+3520 Minsk BLR 1674000
+3522 Mogiljov BLR 356000
+3540 Maracaíbo VEN 1304776
+3545 Maracay VEN 444443
+3547 Maturín VEN 319726
+3580 Moscow RUS 8389200
+3622 Magnitogorsk RUS 427900
+3625 Murmansk RUS 376300
+3636 Mahat?kala RUS 332800
+3810 Memphis USA 650100
+3811 Milwaukee USA 596974
+3834 Mesa USA 396375
+3837 Minneapolis USA 382618
+3839 Miami USA 362470
+462 Manchester GBR 430000
+653 Madrid ESP 2879052
+658 Málaga ESP 530553
+661 Murcia ESP 353504
+766 Manila PHL 1581082
+77 Mar del Plata ARG 512880
+778 Makati PHL 444867
+781 Marikina PHL 391170
+783 Muntinlupa PHL 379310
+786 Malabon PHL 338855
+80 Merlo ARG 463846
+83 Moreno ARG 356993
+87 Morón ARG 349246
+942 Medan IDN 1843919
+947 Malang IDN 716862
+962 Manado IDN 332288
+963 Mataram IDN 306600
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'M%' AND Population > 7000000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+3580 Moscow RUS 8389200
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 7000000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+3580 Moscow RUS 8389200
+SELECT COUNT(*) FROM City WHERE Name BETWEEN 'M' AND 'N';
+COUNT(*)
+301
+SELECT COUNT(*) FROM City WHERE Name BETWEEN 'G' AND 'J';
+COUNT(*)
+408
+SELECT COUNT(*) FROM City WHERE Name BETWEEN 'G' AND 'K';
+COUNT(*)
+512
+SELECT COUNT(*) FROM City WHERE Population > 1000000;
+COUNT(*)
+237
+SELECT COUNT(*) FROM City WHERE Population > 500000;
+COUNT(*)
+539
+SELECT COUNT(*) FROM City WHERE Country LIKE 'C%';
+COUNT(*)
+551
+SELECT COUNT(*) FROM City WHERE Country LIKE 'B%';
+COUNT(*)
+339
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Name,Population 35,4 NULL 9 Using sort_intersect(Name,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population,Country 4,3 NULL 19 Using sort_intersect(Population,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Name 35 NULL 283 Using index condition; Using where; Using MRR
+SELECT * FROM City USE INDEX ()
+WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
+ID Name Country Population
+1810 Montréal CAN 1016376
+2259 Medellín COL 1861265
+SELECT * FROM City
+WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
+ID Name Country Population
+1810 Montréal CAN 1016376
+2259 Medellín COL 1861265
+SELECT * FROM City USE INDEX ()
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+ID Name Country Population
+217 Guarulhos BRA 1095874
+218 Goiânia BRA 1056330
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+ID Name Country Population
+217 Guarulhos BRA 1095874
+218 Goiânia BRA 1056330
+SELECT * FROM City USE INDEX ()
+WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
+ID Name Country Population
+1895 Harbin CHN 4289800
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1914 Guiyang CHN 1465200
+1916 Hefei CHN 1369100
+1923 Jilin CHN 1040000
+1927 Hohhot CHN 916700
+1928 Handan CHN 840000
+1937 Huainan CHN 700000
+1938 Jixi CHN 683885
+1944 Jinzhou CHN 570000
+1950 Hegang CHN 520000
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
+ID Name Country Population
+1895 Harbin CHN 4289800
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1914 Guiyang CHN 1465200
+1916 Hefei CHN 1369100
+1923 Jilin CHN 1040000
+1927 Hohhot CHN 916700
+1928 Handan CHN 840000
+1937 Huainan CHN 700000
+1938 Jixi CHN 683885
+1944 Jinzhou CHN 570000
+1950 Hegang CHN 520000
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 501 AND 1000;
+COUNT(*)
+500
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 1 AND 500;
+COUNT(*)
+500
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 2001 AND 2500;
+COUNT(*)
+500
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 3701 AND 4000;
+COUNT(*)
+300
+SELECT COUNT(*) FROM City WHERE Population > 700000;
+COUNT(*)
+358
+SELECT COUNT(*) FROM City WHERE Population > 1000000;
+COUNT(*)
+237
+SELECT COUNT(*) FROM City WHERE Population > 300000;
+COUNT(*)
+1062
+SELECT COUNT(*) FROM City WHERE Population > 600000;
+COUNT(*)
+428
+SELECT COUNT(*) FROM City WHERE Country LIKE 'C%';
+COUNT(*)
+551
+SELECT COUNT(*) FROM City WHERE Country LIKE 'A%';
+COUNT(*)
+107
+SELECT COUNT(*) FROM City WHERE Country LIKE 'H%';
+COUNT(*)
+22
+SELECT COUNT(*) FROM City WHERE Country BETWEEN 'S' AND 'Z';
+COUNT(*)
+682
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country Population 4 NULL 359 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country Country,Population 3,4 NULL 6 Using sort_intersect(Country,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country Country 3 NULL 21 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 3701 AND 4000 AND Population > 1000000
+AND Country BETWEEN 'S' AND 'Z';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country Population,PRIMARY 4,4 NULL 17 Using sort_intersect(Population,PRIMARY); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z' ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country Population 4 NULL 429 Using index condition; Using where; Using MRR
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
+ID Name Country Population
+554 Santiago de Chile CHL 4703954
+SELECT * FROM City
+WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
+ID Name Country Population
+554 Santiago de Chile CHL 4703954
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+ID Name Country Population
+1 Kabul AFG 1780000
+126 Yerevan ARM 1248700
+130 Sydney AUS 3276207
+131 Melbourne AUS 2865329
+132 Brisbane AUS 1291117
+133 Perth AUS 1096829
+144 Baku AZE 1787800
+56 Luanda AGO 2022000
+69 Buenos Aires ARG 2982146
+70 La Matanza ARG 1266461
+71 Córdoba ARG 1157507
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+ID Name Country Population
+1 Kabul AFG 1780000
+126 Yerevan ARM 1248700
+130 Sydney AUS 3276207
+131 Melbourne AUS 2865329
+132 Brisbane AUS 1291117
+133 Perth AUS 1096829
+144 Baku AZE 1787800
+56 Luanda AGO 2022000
+69 Buenos Aires ARG 2982146
+70 La Matanza ARG 1266461
+71 Córdoba ARG 1157507
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
+ID Name Country Population
+2409 Zagreb HRV 706770
+SELECT * FROM City
+WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
+ID Name Country Population
+2409 Zagreb HRV 706770
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 3701 AND 4000 AND Population > 700000
+AND Country BETWEEN 'S' AND 'Z';
+ID Name Country Population
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+SELECT * FROM City
+WHERE ID BETWEEN 3701 AND 4000 AND Population > 700000
+AND Country BETWEEN 'S' AND 'Z';
+ID Name Country Population
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z' ;
+ID Name Country Population
+3048 Stockholm SWE 750348
+3173 Riyadh SAU 3324000
+3174 Jedda SAU 2046300
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3197 Pikine SEN 855287
+3198 Dakar SEN 785071
+3207 Freetown SLE 850000
+3208 Singapore SGP 4017733
+3214 Mogadishu SOM 997000
+3224 Omdurman SDN 1271403
+3225 Khartum SDN 947483
+3226 Sharq al-Nil SDN 700887
+3250 Damascus SYR 1347000
+3251 Aleppo SYR 1261983
+3263 Taipei TWN 2641312
+3264 Kaohsiung TWN 1475505
+3265 Taichung TWN 940589
+3266 Tainan TWN 728060
+3305 Dar es Salaam TZA 1747000
+3320 Bangkok THA 6320174
+3349 Tunis TUN 690600
+3357 Istanbul TUR 8787958
+3358 Ankara TUR 3038159
+3359 Izmir TUR 2130359
+3360 Adana TUR 1131198
+3361 Bursa TUR 1095842
+3362 Gaziantep TUR 789056
+3363 Konya TUR 628364
+3425 Kampala UGA 890800
+3426 Kyiv UKR 2624000
+3427 Harkova [Harkiv] UKR 1500000
+3428 Dnipropetrovsk UKR 1103000
+3429 Donetsk UKR 1050000
+3430 Odesa UKR 1011000
+3431 Zaporizzja UKR 848000
+3432 Lviv UKR 788000
+3433 Kryvyi Rig UKR 703000
+3492 Montevideo URY 1236000
+3503 Toskent UZB 2117500
+3539 Caracas VEN 1975294
+3540 Maracaíbo VEN 1304776
+3541 Barquisimeto VEN 877239
+3542 Valencia VEN 794246
+3543 Ciudad Guayana VEN 663713
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+3808 Austin USA 656562
+3809 Baltimore USA 651154
+3810 Memphis USA 650100
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z' ;
+ID Name Country Population
+3048 Stockholm SWE 750348
+3173 Riyadh SAU 3324000
+3174 Jedda SAU 2046300
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3197 Pikine SEN 855287
+3198 Dakar SEN 785071
+3207 Freetown SLE 850000
+3208 Singapore SGP 4017733
+3214 Mogadishu SOM 997000
+3224 Omdurman SDN 1271403
+3225 Khartum SDN 947483
+3226 Sharq al-Nil SDN 700887
+3250 Damascus SYR 1347000
+3251 Aleppo SYR 1261983
+3263 Taipei TWN 2641312
+3264 Kaohsiung TWN 1475505
+3265 Taichung TWN 940589
+3266 Tainan TWN 728060
+3305 Dar es Salaam TZA 1747000
+3320 Bangkok THA 6320174
+3349 Tunis TUN 690600
+3357 Istanbul TUR 8787958
+3358 Ankara TUR 3038159
+3359 Izmir TUR 2130359
+3360 Adana TUR 1131198
+3361 Bursa TUR 1095842
+3362 Gaziantep TUR 789056
+3363 Konya TUR 628364
+3425 Kampala UGA 890800
+3426 Kyiv UKR 2624000
+3427 Harkova [Harkiv] UKR 1500000
+3428 Dnipropetrovsk UKR 1103000
+3429 Donetsk UKR 1050000
+3430 Odesa UKR 1011000
+3431 Zaporizzja UKR 848000
+3432 Lviv UKR 788000
+3433 Kryvyi Rig UKR 703000
+3492 Montevideo URY 1236000
+3503 Toskent UZB 2117500
+3539 Caracas VEN 1975294
+3540 Maracaíbo VEN 1304776
+3541 Barquisimeto VEN 877239
+3542 Valencia VEN 794246
+3543 Ciudad Guayana VEN 663713
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+3808 Austin USA 656562
+3809 Baltimore USA 651154
+3810 Memphis USA 650100
+SET SESSION sort_buffer_size = 2048;
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'C%' AND Population > 1000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Name,Population 35,4 NULL 9 Using sort_intersect(Name,Population); Using where
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'M%' AND Population > 1500000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population,Name 4,35 NULL 5 Using sort_intersect(Population,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population,Country 4,3 NULL 19 Using sort_intersect(Population,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Name 35 NULL 225 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country Country,Population 3,4 NULL 6 Using sort_intersect(Country,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country Population 4 NULL 429 Using index condition; Using where; Using MRR
+SELECT * FROM City WHERE
+Name LIKE 'C%' AND Population > 1000000;
+ID Name Country Population
+1026 Calcutta [Kolkata] IND 4399819
+1027 Chennai (Madras) IND 3841396
+151 Chittagong BGD 1392860
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+212 Curitiba BRA 1584232
+2258 Cali COL 2077386
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+3539 Caracas VEN 1975294
+3795 Chicago USA 2896016
+608 Cairo EGY 6789479
+71 Córdoba ARG 1157507
+712 Cape Town ZAF 2352121
+926 Conakry GIN 1090610
+SELECT * FROM City WHERE
+Name LIKE 'M%' AND Population > 1500000;
+ID Name Country Population
+131 Melbourne AUS 2865329
+653 Madrid ESP 2879052
+766 Manila PHL 1581082
+942 Medan IDN 1843919
+1024 Mumbai (Bombay) IND 10500000
+1381 Mashhad IRN 1887405
+2259 Medellín COL 1861265
+3520 Minsk BLR 1674000
+3580 Moscow RUS 8389200
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 700000 AND Country LIKE 'B%';
+ID Name Country Population
+217 Guarulhos BRA 1095874
+218 Goiânia BRA 1056330
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%';
+ID Name Country Population
+1895 Harbin CHN 4289800
+1905 Hangzhou CHN 2190500
+1914 Guiyang CHN 1465200
+1916 Hefei CHN 1369100
+1927 Hohhot CHN 916700
+1928 Handan CHN 840000
+1937 Huainan CHN 700000
+1950 Hegang CHN 520000
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+ID Name Country Population
+1 Kabul AFG 1780000
+56 Luanda AGO 2022000
+69 Buenos Aires ARG 2982146
+70 La Matanza ARG 1266461
+71 Córdoba ARG 1157507
+126 Yerevan ARM 1248700
+130 Sydney AUS 3276207
+131 Melbourne AUS 2865329
+132 Brisbane AUS 1291117
+133 Perth AUS 1096829
+144 Baku AZE 1787800
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z';
+ID Name Country Population
+3048 Stockholm SWE 750348
+3173 Riyadh SAU 3324000
+3174 Jedda SAU 2046300
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3197 Pikine SEN 855287
+3198 Dakar SEN 785071
+3207 Freetown SLE 850000
+3208 Singapore SGP 4017733
+3214 Mogadishu SOM 997000
+3224 Omdurman SDN 1271403
+3225 Khartum SDN 947483
+3226 Sharq al-Nil SDN 700887
+3250 Damascus SYR 1347000
+3251 Aleppo SYR 1261983
+3263 Taipei TWN 2641312
+3264 Kaohsiung TWN 1475505
+3265 Taichung TWN 940589
+3266 Tainan TWN 728060
+3305 Dar es Salaam TZA 1747000
+3320 Bangkok THA 6320174
+3349 Tunis TUN 690600
+3357 Istanbul TUR 8787958
+3358 Ankara TUR 3038159
+3359 Izmir TUR 2130359
+3360 Adana TUR 1131198
+3361 Bursa TUR 1095842
+3362 Gaziantep TUR 789056
+3363 Konya TUR 628364
+3425 Kampala UGA 890800
+3426 Kyiv UKR 2624000
+3427 Harkova [Harkiv] UKR 1500000
+3428 Dnipropetrovsk UKR 1103000
+3429 Donetsk UKR 1050000
+3430 Odesa UKR 1011000
+3431 Zaporizzja UKR 848000
+3432 Lviv UKR 788000
+3433 Kryvyi Rig UKR 703000
+3492 Montevideo URY 1236000
+3503 Toskent UZB 2117500
+3539 Caracas VEN 1975294
+3540 Maracaíbo VEN 1304776
+3541 Barquisimeto VEN 877239
+3542 Valencia VEN 794246
+3543 Ciudad Guayana VEN 663713
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+3808 Austin USA 656562
+3809 Baltimore USA 651154
+3810 Memphis USA 650100
+SET SESSION sort_buffer_size = default;
+DROP INDEX Country ON City;
+CREATE INDEX CountryID ON City(Country,ID);
+CREATE INDEX CountryName ON City(Country,Name);
+EXPLAIN
+SELECT * FROM City
+WHERE Country LIKE 'M%' AND Population > 1000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,CountryID,CountryName Population,CountryID 4,3 NULL 15 Using sort_intersect(Population,CountryID); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,CountryID,CountryName Population,CountryID 4,3 NULL 11 Using sort_intersect(Population,CountryID); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000 AND Name LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name,CountryID,CountryName CountryName,Population 38,4 NULL 1 Using sort_intersect(CountryName,Population); Using where
+SELECT * FROM City USE INDEX ()
+WHERE Country LIKE 'M%' AND Population > 1000000;
+ID Name Country Population
+2464 Kuala Lumpur MYS 1297526
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+2516 Guadalajara MEX 1647720
+2517 Ecatepec de Morelos MEX 1620303
+2518 Puebla MEX 1346176
+2519 Nezahualcóyotl MEX 1224924
+2520 Juárez MEX 1217818
+2521 Tijuana MEX 1212232
+2522 León MEX 1133576
+2523 Monterrey MEX 1108499
+2524 Zapopan MEX 1002239
+2698 Maputo MOZ 1018938
+2710 Rangoon (Yangon) MMR 3361700
+SELECT * FROM City
+WHERE Country LIKE 'M%' AND Population > 1000000;
+ID Name Country Population
+2464 Kuala Lumpur MYS 1297526
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+2516 Guadalajara MEX 1647720
+2517 Ecatepec de Morelos MEX 1620303
+2518 Puebla MEX 1346176
+2519 Nezahualcóyotl MEX 1224924
+2520 Juárez MEX 1217818
+2521 Tijuana MEX 1212232
+2522 León MEX 1133576
+2523 Monterrey MEX 1108499
+2524 Zapopan MEX 1002239
+2698 Maputo MOZ 1018938
+2710 Rangoon (Yangon) MMR 3361700
+SELECT * FROM City USE INDEX ()
+WHERE Country='CHN' AND Population > 1500000;
+ID Name Country Population
+1890 Shanghai CHN 9696300
+1891 Peking CHN 7472000
+1892 Chongqing CHN 6351600
+1893 Tianjin CHN 5286800
+1894 Wuhan CHN 4344600
+1895 Harbin CHN 4289800
+1896 Shenyang CHN 4265200
+1897 Kanton [Guangzhou] CHN 4256300
+1898 Chengdu CHN 3361500
+1899 Nanking [Nanjing] CHN 2870300
+1900 Changchun CHN 2812000
+1901 Xi´an CHN 2761400
+1902 Dalian CHN 2697000
+1903 Qingdao CHN 2596000
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1906 Zhengzhou CHN 2107200
+1907 Shijiazhuang CHN 2041500
+1908 Taiyuan CHN 1968400
+1909 Kunming CHN 1829500
+1910 Changsha CHN 1809800
+1911 Nanchang CHN 1691600
+1912 Fuzhou CHN 1593800
+1913 Lanzhou CHN 1565800
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000;
+ID Name Country Population
+1890 Shanghai CHN 9696300
+1891 Peking CHN 7472000
+1892 Chongqing CHN 6351600
+1893 Tianjin CHN 5286800
+1894 Wuhan CHN 4344600
+1895 Harbin CHN 4289800
+1896 Shenyang CHN 4265200
+1897 Kanton [Guangzhou] CHN 4256300
+1898 Chengdu CHN 3361500
+1899 Nanking [Nanjing] CHN 2870300
+1900 Changchun CHN 2812000
+1901 Xi´an CHN 2761400
+1902 Dalian CHN 2697000
+1903 Qingdao CHN 2596000
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1906 Zhengzhou CHN 2107200
+1907 Shijiazhuang CHN 2041500
+1908 Taiyuan CHN 1968400
+1909 Kunming CHN 1829500
+1910 Changsha CHN 1809800
+1911 Nanchang CHN 1691600
+1912 Fuzhou CHN 1593800
+1913 Lanzhou CHN 1565800
+SELECT * FROM City USE INDEX ()
+WHERE Country='CHN' AND Population > 1500000 AND Name LIKE 'C%';
+ID Name Country Population
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000 AND Name LIKE 'C%';
+ID Name Country Population
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+DROP DATABASE world;
+use test;
+CREATE TABLE t1 (
+f1 int,
+f4 varchar(32),
+f5 int,
+PRIMARY KEY (f1),
+KEY (f4)
+) ENGINE=InnoDB;
+Warnings:
+Warning 1286 Unknown table engine 'InnoDB'
+Warning 1266 Using storage engine MyISAM for table 't1'
+INSERT INTO t1 VALUES
+(5,'H',1), (9,'g',0), (527,'i',0), (528,'y',1), (529,'S',6),
+(530,'m',7), (531,'b',2), (532,'N',1), (533,'V',NULL), (534,'l',1),
+(535,'M',0), (536,'w',1), (537,'j',5), (538,'l',0), (539,'n',2),
+(540,'m',2), (541,'r',2), (542,'l',2), (543,'h',3),(544,'o',0),
+(956,'h',0), (957,'g',0), (958,'W',5), (959,'s',3), (960,'w',0),
+(961,'q',0), (962,'e',NULL), (963,'u',7), (964,'q',1), (965,'N',NULL),
+(966,'e',0), (967,'t',3), (968,'e',6), (969,'f',NULL), (970,'j',0),
+(971,'s',3), (972,'I',0), (973,'h',4), (974,'g',1), (975,'s',0),
+(976,'r',3), (977,'x',1), (978,'v',8), (979,'j',NULL), (980,'z',7),
+(981,'t',9), (982,'j',5), (983,'u',NULL), (984,'g',6), (985,'w',1),
+(986,'h',1), (987,'v',0), (988,'v',0), (989,'c',2), (990,'b',7),
+(991,'z',0), (992,'M',1), (993,'u',2), (994,'r',2), (995,'b',4),
+(996,'A',2), (997,'u',0), (998,'a',0), (999,'j',2), (1,'I',2);
+EXPLAIN
+SELECT * FROM t1
+WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range PRIMARY,f4 f4 35 NULL 5 Using index condition; Using where; Using MRR
+SELECT * FROM t1
+WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ;
+f1 f4 f5
+994 r 2
+996 A 2
+998 a 0
+DROP TABLE t1;
+SET SESSION optimizer_switch='index_merge_sort_intersection=on';
diff --git a/mysql-test/r/index_intersect_innodb.result b/mysql-test/r/index_intersect_innodb.result
new file mode 100644
index 00000000000..937e1e56292
--- /dev/null
+++ b/mysql-test/r/index_intersect_innodb.result
@@ -0,0 +1,1038 @@
+SET SESSION STORAGE_ENGINE='InnoDB';
+DROP TABLE IF EXISTS t1,t2,t3,t4;
+DROP DATABASE IF EXISTS world;
+set names utf8;
+CREATE DATABASE world;
+use world;
+CREATE TABLE Country (
+Code char(3) NOT NULL default '',
+Name char(52) NOT NULL default '',
+SurfaceArea float(10,2) NOT NULL default '0.00',
+Population int(11) NOT NULL default '0',
+Capital int(11) default NULL,
+PRIMARY KEY (Code),
+UNIQUE INDEX (Name)
+);
+CREATE TABLE City (
+ID int(11) NOT NULL auto_increment,
+Name char(35) NOT NULL default '',
+Country char(3) NOT NULL default '',
+Population int(11) NOT NULL default '0',
+PRIMARY KEY (ID),
+INDEX (Population),
+INDEX (Country)
+);
+CREATE TABLE CountryLanguage (
+Country char(3) NOT NULL default '',
+Language char(30) NOT NULL default '',
+Percentage float(3,1) NOT NULL default '0.0',
+PRIMARY KEY (Country, Language),
+INDEX (Percentage)
+);
+SELECT COUNT(*) FROM Country;
+COUNT(*)
+239
+SELECT COUNT(*) FROM City;
+COUNT(*)
+4079
+SELECT COUNT(*) FROM CountryLanguage;
+COUNT(*)
+984
+CREATE INDEX Name ON City(Name);
+SET SESSION optimizer_switch='index_merge_sort_intersection=on';
+SELECT COUNT(*) FROM City;
+COUNT(*)
+4079
+SELECT COUNT(*) FROM City WHERE Name LIKE 'C%';
+COUNT(*)
+281
+SELECT COUNT(*) FROM City WHERE Name LIKE 'M%';
+COUNT(*)
+301
+SELECT COUNT(*) FROM City WHERE Population > 1000000;
+COUNT(*)
+237
+SELECT COUNT(*) FROM City WHERE Population > 1500000;
+COUNT(*)
+129
+SELECT COUNT(*) FROM City WHERE Population > 300000;
+COUNT(*)
+1062
+SELECT COUNT(*) FROM City WHERE Population > 7000000;
+COUNT(*)
+14
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'C%' AND Population > 1000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population,Name 4,35 NULL 16 Using sort_intersect(Population,Name); Using where
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'M%' AND Population > 1500000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population,Name 4,35 NULL 9 Using sort_intersect(Population,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 300000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Name,Population 35,4 NULL 79 Using sort_intersect(Name,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 7000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population,Name 4,35 NULL 1 Using sort_intersect(Population,Name); Using where
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'C%' AND Population > 1000000;
+ID Name Country Population
+1026 Calcutta [Kolkata] IND 4399819
+1027 Chennai (Madras) IND 3841396
+151 Chittagong BGD 1392860
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+212 Curitiba BRA 1584232
+2258 Cali COL 2077386
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+3539 Caracas VEN 1975294
+3795 Chicago USA 2896016
+608 Cairo EGY 6789479
+71 Córdoba ARG 1157507
+712 Cape Town ZAF 2352121
+926 Conakry GIN 1090610
+SELECT * FROM City
+WHERE Name LIKE 'C%' AND Population > 1000000;
+ID Name Country Population
+1026 Calcutta [Kolkata] IND 4399819
+1027 Chennai (Madras) IND 3841396
+151 Chittagong BGD 1392860
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+212 Curitiba BRA 1584232
+2258 Cali COL 2077386
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+3539 Caracas VEN 1975294
+3795 Chicago USA 2896016
+608 Cairo EGY 6789479
+71 Córdoba ARG 1157507
+712 Cape Town ZAF 2352121
+926 Conakry GIN 1090610
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'M%' AND Population > 1500000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+131 Melbourne AUS 2865329
+1381 Mashhad IRN 1887405
+2259 Medellín COL 1861265
+3520 Minsk BLR 1674000
+3580 Moscow RUS 8389200
+653 Madrid ESP 2879052
+766 Manila PHL 1581082
+942 Medan IDN 1843919
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 1500000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+131 Melbourne AUS 2865329
+1381 Mashhad IRN 1887405
+2259 Medellín COL 1861265
+3520 Minsk BLR 1674000
+3580 Moscow RUS 8389200
+653 Madrid ESP 2879052
+766 Manila PHL 1581082
+942 Medan IDN 1843919
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'M%' AND Population > 300000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+1042 Madurai IND 977856
+1051 Meerut IND 753778
+1074 Mysore IND 480692
+1081 Moradabad IND 429214
+1098 Malegaon IND 342595
+131 Melbourne AUS 2865329
+1366 Mosul IRQ 879000
+1381 Mashhad IRN 1887405
+1465 Milano ITA 1300977
+1559 Matsuyama JPN 466133
+1560 Matsudo JPN 461126
+1578 Machida JPN 364197
+1595 Miyazaki JPN 303784
+1810 Montréal CAN 1016376
+1816 Mississauga CAN 608072
+1882 Mombasa KEN 461753
+1945 Mudanjiang CHN 570000
+2005 Ma´anshan CHN 305421
+215 Manaus BRA 1255049
+223 Maceió BRA 786288
+2259 Medellín COL 1861265
+2267 Manizales COL 337580
+2300 Mbuji-Mayi COD 806475
+2348 Masan KOR 441242
+2440 Monrovia LBR 850000
+2454 Macao MAC 437500
+2487 Marrakech MAR 621914
+2491 Meknès MAR 460000
+250 Mauá BRA 375055
+2523 Monterrey MEX 1108499
+2526 Mexicali MEX 764902
+2530 Mérida MEX 703324
+2537 Morelia MEX 619958
+2554 Matamoros MEX 416428
+2557 Mazatlán MEX 380265
+256 Moji das Cruzes BRA 339194
+2698 Maputo MOZ 1018938
+2699 Matola MOZ 424662
+2711 Mandalay MMR 885300
+2712 Moulmein (Mawlamyine) MMR 307900
+2734 Managua NIC 959000
+2756 Mushin NGA 333200
+2757 Maiduguri NGA 320000
+2826 Multan PAK 1182441
+2975 Marseille FRA 798430
+3070 Munich [München] DEU 1194560
+3086 Mannheim DEU 307730
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3214 Mogadishu SOM 997000
+3364 Mersin (Içel) TUR 587212
+3371 Malatya TUR 330312
+3434 Mykolajiv UKR 508000
+3435 Mariupol UKR 490000
+3438 Makijivka UKR 384000
+3492 Montevideo URY 1236000
+3520 Minsk BLR 1674000
+3522 Mogiljov BLR 356000
+3540 Maracaíbo VEN 1304776
+3545 Maracay VEN 444443
+3547 Maturín VEN 319726
+3580 Moscow RUS 8389200
+3622 Magnitogorsk RUS 427900
+3625 Murmansk RUS 376300
+3636 Mahat?kala RUS 332800
+3810 Memphis USA 650100
+3811 Milwaukee USA 596974
+3834 Mesa USA 396375
+3837 Minneapolis USA 382618
+3839 Miami USA 362470
+462 Manchester GBR 430000
+653 Madrid ESP 2879052
+658 Málaga ESP 530553
+661 Murcia ESP 353504
+766 Manila PHL 1581082
+77 Mar del Plata ARG 512880
+778 Makati PHL 444867
+781 Marikina PHL 391170
+783 Muntinlupa PHL 379310
+786 Malabon PHL 338855
+80 Merlo ARG 463846
+83 Moreno ARG 356993
+87 Morón ARG 349246
+942 Medan IDN 1843919
+947 Malang IDN 716862
+962 Manado IDN 332288
+963 Mataram IDN 306600
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 300000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+1042 Madurai IND 977856
+1051 Meerut IND 753778
+1074 Mysore IND 480692
+1081 Moradabad IND 429214
+1098 Malegaon IND 342595
+131 Melbourne AUS 2865329
+1366 Mosul IRQ 879000
+1381 Mashhad IRN 1887405
+1465 Milano ITA 1300977
+1559 Matsuyama JPN 466133
+1560 Matsudo JPN 461126
+1578 Machida JPN 364197
+1595 Miyazaki JPN 303784
+1810 Montréal CAN 1016376
+1816 Mississauga CAN 608072
+1882 Mombasa KEN 461753
+1945 Mudanjiang CHN 570000
+2005 Ma´anshan CHN 305421
+215 Manaus BRA 1255049
+223 Maceió BRA 786288
+2259 Medellín COL 1861265
+2267 Manizales COL 337580
+2300 Mbuji-Mayi COD 806475
+2348 Masan KOR 441242
+2440 Monrovia LBR 850000
+2454 Macao MAC 437500
+2487 Marrakech MAR 621914
+2491 Meknès MAR 460000
+250 Mauá BRA 375055
+2523 Monterrey MEX 1108499
+2526 Mexicali MEX 764902
+2530 Mérida MEX 703324
+2537 Morelia MEX 619958
+2554 Matamoros MEX 416428
+2557 Mazatlán MEX 380265
+256 Moji das Cruzes BRA 339194
+2698 Maputo MOZ 1018938
+2699 Matola MOZ 424662
+2711 Mandalay MMR 885300
+2712 Moulmein (Mawlamyine) MMR 307900
+2734 Managua NIC 959000
+2756 Mushin NGA 333200
+2757 Maiduguri NGA 320000
+2826 Multan PAK 1182441
+2975 Marseille FRA 798430
+3070 Munich [München] DEU 1194560
+3086 Mannheim DEU 307730
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3214 Mogadishu SOM 997000
+3364 Mersin (Içel) TUR 587212
+3371 Malatya TUR 330312
+3434 Mykolajiv UKR 508000
+3435 Mariupol UKR 490000
+3438 Makijivka UKR 384000
+3492 Montevideo URY 1236000
+3520 Minsk BLR 1674000
+3522 Mogiljov BLR 356000
+3540 Maracaíbo VEN 1304776
+3545 Maracay VEN 444443
+3547 Maturín VEN 319726
+3580 Moscow RUS 8389200
+3622 Magnitogorsk RUS 427900
+3625 Murmansk RUS 376300
+3636 Mahat?kala RUS 332800
+3810 Memphis USA 650100
+3811 Milwaukee USA 596974
+3834 Mesa USA 396375
+3837 Minneapolis USA 382618
+3839 Miami USA 362470
+462 Manchester GBR 430000
+653 Madrid ESP 2879052
+658 Málaga ESP 530553
+661 Murcia ESP 353504
+766 Manila PHL 1581082
+77 Mar del Plata ARG 512880
+778 Makati PHL 444867
+781 Marikina PHL 391170
+783 Muntinlupa PHL 379310
+786 Malabon PHL 338855
+80 Merlo ARG 463846
+83 Moreno ARG 356993
+87 Morón ARG 349246
+942 Medan IDN 1843919
+947 Malang IDN 716862
+962 Manado IDN 332288
+963 Mataram IDN 306600
+SELECT * FROM City USE INDEX ()
+WHERE Name LIKE 'M%' AND Population > 7000000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+3580 Moscow RUS 8389200
+SELECT * FROM City
+WHERE Name LIKE 'M%' AND Population > 7000000;
+ID Name Country Population
+1024 Mumbai (Bombay) IND 10500000
+3580 Moscow RUS 8389200
+SELECT COUNT(*) FROM City WHERE Name BETWEEN 'M' AND 'N';
+COUNT(*)
+301
+SELECT COUNT(*) FROM City WHERE Name BETWEEN 'G' AND 'J';
+COUNT(*)
+408
+SELECT COUNT(*) FROM City WHERE Name BETWEEN 'G' AND 'K';
+COUNT(*)
+512
+SELECT COUNT(*) FROM City WHERE Population > 1000000;
+COUNT(*)
+237
+SELECT COUNT(*) FROM City WHERE Population > 500000;
+COUNT(*)
+539
+SELECT COUNT(*) FROM City WHERE Country LIKE 'C%';
+COUNT(*)
+551
+SELECT COUNT(*) FROM City WHERE Country LIKE 'B%';
+COUNT(*)
+339
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population,Name,Country 4,35,3 NULL 2 Using sort_intersect(Population,Name,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population,Country,Name 4,3,35 NULL 2 Using sort_intersect(Population,Country,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population,Name,Country 4,35,3 NULL 26 Using sort_intersect(Population,Name,Country); Using where
+SELECT * FROM City USE INDEX ()
+WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
+ID Name Country Population
+1810 Montréal CAN 1016376
+2259 Medellín COL 1861265
+SELECT * FROM City
+WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
+ID Name Country Population
+1810 Montréal CAN 1016376
+2259 Medellín COL 1861265
+SELECT * FROM City USE INDEX ()
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+ID Name Country Population
+217 Guarulhos BRA 1095874
+218 Goiânia BRA 1056330
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+ID Name Country Population
+217 Guarulhos BRA 1095874
+218 Goiânia BRA 1056330
+SELECT * FROM City USE INDEX ()
+WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
+ID Name Country Population
+1895 Harbin CHN 4289800
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1914 Guiyang CHN 1465200
+1916 Hefei CHN 1369100
+1923 Jilin CHN 1040000
+1927 Hohhot CHN 916700
+1928 Handan CHN 840000
+1937 Huainan CHN 700000
+1938 Jixi CHN 683885
+1944 Jinzhou CHN 570000
+1950 Hegang CHN 520000
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
+ID Name Country Population
+1895 Harbin CHN 4289800
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1914 Guiyang CHN 1465200
+1916 Hefei CHN 1369100
+1923 Jilin CHN 1040000
+1927 Hohhot CHN 916700
+1928 Handan CHN 840000
+1937 Huainan CHN 700000
+1938 Jixi CHN 683885
+1944 Jinzhou CHN 570000
+1950 Hegang CHN 520000
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 501 AND 1000;
+COUNT(*)
+500
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 1 AND 500;
+COUNT(*)
+500
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 2001 AND 2500;
+COUNT(*)
+500
+SELECT COUNT(*) FROM City WHERE ID BETWEEN 3701 AND 4000;
+COUNT(*)
+300
+SELECT COUNT(*) FROM City WHERE Population > 700000;
+COUNT(*)
+358
+SELECT COUNT(*) FROM City WHERE Population > 1000000;
+COUNT(*)
+237
+SELECT COUNT(*) FROM City WHERE Population > 300000;
+COUNT(*)
+1062
+SELECT COUNT(*) FROM City WHERE Population > 600000;
+COUNT(*)
+428
+SELECT COUNT(*) FROM City WHERE Country LIKE 'C%';
+COUNT(*)
+551
+SELECT COUNT(*) FROM City WHERE Country LIKE 'A%';
+COUNT(*)
+107
+SELECT COUNT(*) FROM City WHERE Country LIKE 'H%';
+COUNT(*)
+22
+SELECT COUNT(*) FROM City WHERE Country BETWEEN 'S' AND 'Z';
+COUNT(*)
+682
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country PRIMARY,Country,Population 4,3,4 NULL 11 Using sort_intersect(PRIMARY,Country,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country PRIMARY,Population,Country 4,4,3 NULL 1 Using sort_intersect(PRIMARY,Population,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country PRIMARY,Country 4,3 NULL 7 Using sort_intersect(PRIMARY,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 3701 AND 4000 AND Population > 1000000
+AND Country BETWEEN 'S' AND 'Z';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country PRIMARY,Country,Population 4,3,4 NULL 2 Using sort_intersect(PRIMARY,Country,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z' ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country PRIMARY,Population,Country 4,4,3 NULL 30 Using sort_intersect(PRIMARY,Population,Country); Using where
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
+ID Name Country Population
+554 Santiago de Chile CHL 4703954
+SELECT * FROM City
+WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
+ID Name Country Population
+554 Santiago de Chile CHL 4703954
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+ID Name Country Population
+1 Kabul AFG 1780000
+126 Yerevan ARM 1248700
+130 Sydney AUS 3276207
+131 Melbourne AUS 2865329
+132 Brisbane AUS 1291117
+133 Perth AUS 1096829
+144 Baku AZE 1787800
+56 Luanda AGO 2022000
+69 Buenos Aires ARG 2982146
+70 La Matanza ARG 1266461
+71 Córdoba ARG 1157507
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+ID Name Country Population
+1 Kabul AFG 1780000
+126 Yerevan ARM 1248700
+130 Sydney AUS 3276207
+131 Melbourne AUS 2865329
+132 Brisbane AUS 1291117
+133 Perth AUS 1096829
+144 Baku AZE 1787800
+56 Luanda AGO 2022000
+69 Buenos Aires ARG 2982146
+70 La Matanza ARG 1266461
+71 Córdoba ARG 1157507
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
+ID Name Country Population
+2409 Zagreb HRV 706770
+SELECT * FROM City
+WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
+ID Name Country Population
+2409 Zagreb HRV 706770
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 3701 AND 4000 AND Population > 700000
+AND Country BETWEEN 'S' AND 'Z';
+ID Name Country Population
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+SELECT * FROM City
+WHERE ID BETWEEN 3701 AND 4000 AND Population > 700000
+AND Country BETWEEN 'S' AND 'Z';
+ID Name Country Population
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+SELECT * FROM City USE INDEX ()
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z' ;
+ID Name Country Population
+3048 Stockholm SWE 750348
+3173 Riyadh SAU 3324000
+3174 Jedda SAU 2046300
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3197 Pikine SEN 855287
+3198 Dakar SEN 785071
+3207 Freetown SLE 850000
+3208 Singapore SGP 4017733
+3214 Mogadishu SOM 997000
+3224 Omdurman SDN 1271403
+3225 Khartum SDN 947483
+3226 Sharq al-Nil SDN 700887
+3250 Damascus SYR 1347000
+3251 Aleppo SYR 1261983
+3263 Taipei TWN 2641312
+3264 Kaohsiung TWN 1475505
+3265 Taichung TWN 940589
+3266 Tainan TWN 728060
+3305 Dar es Salaam TZA 1747000
+3320 Bangkok THA 6320174
+3349 Tunis TUN 690600
+3357 Istanbul TUR 8787958
+3358 Ankara TUR 3038159
+3359 Izmir TUR 2130359
+3360 Adana TUR 1131198
+3361 Bursa TUR 1095842
+3362 Gaziantep TUR 789056
+3363 Konya TUR 628364
+3425 Kampala UGA 890800
+3426 Kyiv UKR 2624000
+3427 Harkova [Harkiv] UKR 1500000
+3428 Dnipropetrovsk UKR 1103000
+3429 Donetsk UKR 1050000
+3430 Odesa UKR 1011000
+3431 Zaporizzja UKR 848000
+3432 Lviv UKR 788000
+3433 Kryvyi Rig UKR 703000
+3492 Montevideo URY 1236000
+3503 Toskent UZB 2117500
+3539 Caracas VEN 1975294
+3540 Maracaíbo VEN 1304776
+3541 Barquisimeto VEN 877239
+3542 Valencia VEN 794246
+3543 Ciudad Guayana VEN 663713
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+3808 Austin USA 656562
+3809 Baltimore USA 651154
+3810 Memphis USA 650100
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z' ;
+ID Name Country Population
+3048 Stockholm SWE 750348
+3173 Riyadh SAU 3324000
+3174 Jedda SAU 2046300
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3197 Pikine SEN 855287
+3198 Dakar SEN 785071
+3207 Freetown SLE 850000
+3208 Singapore SGP 4017733
+3214 Mogadishu SOM 997000
+3224 Omdurman SDN 1271403
+3225 Khartum SDN 947483
+3226 Sharq al-Nil SDN 700887
+3250 Damascus SYR 1347000
+3251 Aleppo SYR 1261983
+3263 Taipei TWN 2641312
+3264 Kaohsiung TWN 1475505
+3265 Taichung TWN 940589
+3266 Tainan TWN 728060
+3305 Dar es Salaam TZA 1747000
+3320 Bangkok THA 6320174
+3349 Tunis TUN 690600
+3357 Istanbul TUR 8787958
+3358 Ankara TUR 3038159
+3359 Izmir TUR 2130359
+3360 Adana TUR 1131198
+3361 Bursa TUR 1095842
+3362 Gaziantep TUR 789056
+3363 Konya TUR 628364
+3425 Kampala UGA 890800
+3426 Kyiv UKR 2624000
+3427 Harkova [Harkiv] UKR 1500000
+3428 Dnipropetrovsk UKR 1103000
+3429 Donetsk UKR 1050000
+3430 Odesa UKR 1011000
+3431 Zaporizzja UKR 848000
+3432 Lviv UKR 788000
+3433 Kryvyi Rig UKR 703000
+3492 Montevideo URY 1236000
+3503 Toskent UZB 2117500
+3539 Caracas VEN 1975294
+3540 Maracaíbo VEN 1304776
+3541 Barquisimeto VEN 877239
+3542 Valencia VEN 794246
+3543 Ciudad Guayana VEN 663713
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+3808 Austin USA 656562
+3809 Baltimore USA 651154
+3810 Memphis USA 650100
+SET SESSION sort_buffer_size = 2048;
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'C%' AND Population > 1000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population,Name 4,35 NULL 16 Using sort_intersect(Population,Name); Using where
+EXPLAIN
+SELECT * FROM City WHERE
+Name LIKE 'M%' AND Population > 1500000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Population,Name 4,35 NULL 9 Using sort_intersect(Population,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 1000000 AND Country LIKE 'B%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population,Country,Name 4,3,35 NULL 2 Using sort_intersect(Population,Country,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Name,Population,Country 35,4,3 NULL 7 Using sort_intersect(Name,Population,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country PRIMARY,Population,Country 4,4,3 NULL 1 Using sort_intersect(PRIMARY,Population,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country PRIMARY,Country,Population 4,3,4 NULL 30 Using sort_intersect(PRIMARY,Country,Population); Using where
+SELECT * FROM City WHERE
+Name LIKE 'C%' AND Population > 1000000;
+ID Name Country Population
+1026 Calcutta [Kolkata] IND 4399819
+1027 Chennai (Madras) IND 3841396
+151 Chittagong BGD 1392860
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+212 Curitiba BRA 1584232
+2258 Cali COL 2077386
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+3539 Caracas VEN 1975294
+3795 Chicago USA 2896016
+608 Cairo EGY 6789479
+71 Córdoba ARG 1157507
+712 Cape Town ZAF 2352121
+926 Conakry GIN 1090610
+SELECT * FROM City WHERE
+Name LIKE 'M%' AND Population > 1500000;
+ID Name Country Population
+131 Melbourne AUS 2865329
+653 Madrid ESP 2879052
+766 Manila PHL 1581082
+942 Medan IDN 1843919
+1024 Mumbai (Bombay) IND 10500000
+1381 Mashhad IRN 1887405
+2259 Medellín COL 1861265
+3520 Minsk BLR 1674000
+3580 Moscow RUS 8389200
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 700000 AND Country LIKE 'B%';
+ID Name Country Population
+217 Guarulhos BRA 1095874
+218 Goiânia BRA 1056330
+SELECT * FROM City
+WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%';
+ID Name Country Population
+1895 Harbin CHN 4289800
+1905 Hangzhou CHN 2190500
+1914 Guiyang CHN 1465200
+1916 Hefei CHN 1369100
+1927 Hohhot CHN 916700
+1928 Handan CHN 840000
+1937 Huainan CHN 700000
+1950 Hegang CHN 520000
+SELECT * FROM City
+WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
+ID Name Country Population
+1 Kabul AFG 1780000
+56 Luanda AGO 2022000
+69 Buenos Aires ARG 2982146
+70 La Matanza ARG 1266461
+71 Córdoba ARG 1157507
+126 Yerevan ARM 1248700
+130 Sydney AUS 3276207
+131 Melbourne AUS 2865329
+132 Brisbane AUS 1291117
+133 Perth AUS 1096829
+144 Baku AZE 1787800
+SELECT * FROM City
+WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
+AND Country BETWEEN 'S' AND 'Z';
+ID Name Country Population
+3048 Stockholm SWE 750348
+3173 Riyadh SAU 3324000
+3174 Jedda SAU 2046300
+3175 Mekka SAU 965700
+3176 Medina SAU 608300
+3197 Pikine SEN 855287
+3198 Dakar SEN 785071
+3207 Freetown SLE 850000
+3208 Singapore SGP 4017733
+3214 Mogadishu SOM 997000
+3224 Omdurman SDN 1271403
+3225 Khartum SDN 947483
+3226 Sharq al-Nil SDN 700887
+3250 Damascus SYR 1347000
+3251 Aleppo SYR 1261983
+3263 Taipei TWN 2641312
+3264 Kaohsiung TWN 1475505
+3265 Taichung TWN 940589
+3266 Tainan TWN 728060
+3305 Dar es Salaam TZA 1747000
+3320 Bangkok THA 6320174
+3349 Tunis TUN 690600
+3357 Istanbul TUR 8787958
+3358 Ankara TUR 3038159
+3359 Izmir TUR 2130359
+3360 Adana TUR 1131198
+3361 Bursa TUR 1095842
+3362 Gaziantep TUR 789056
+3363 Konya TUR 628364
+3425 Kampala UGA 890800
+3426 Kyiv UKR 2624000
+3427 Harkova [Harkiv] UKR 1500000
+3428 Dnipropetrovsk UKR 1103000
+3429 Donetsk UKR 1050000
+3430 Odesa UKR 1011000
+3431 Zaporizzja UKR 848000
+3432 Lviv UKR 788000
+3433 Kryvyi Rig UKR 703000
+3492 Montevideo URY 1236000
+3503 Toskent UZB 2117500
+3539 Caracas VEN 1975294
+3540 Maracaíbo VEN 1304776
+3541 Barquisimeto VEN 877239
+3542 Valencia VEN 794246
+3543 Ciudad Guayana VEN 663713
+3769 Ho Chi Minh City VNM 3980000
+3770 Hanoi VNM 1410000
+3771 Haiphong VNM 783133
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+3801 San Antonio USA 1144646
+3802 Detroit USA 951270
+3803 San Jose USA 894943
+3804 Indianapolis USA 791926
+3805 San Francisco USA 776733
+3806 Jacksonville USA 735167
+3807 Columbus USA 711470
+3808 Austin USA 656562
+3809 Baltimore USA 651154
+3810 Memphis USA 650100
+SET SESSION sort_buffer_size = default;
+DROP INDEX Country ON City;
+CREATE INDEX CountryID ON City(Country,ID);
+CREATE INDEX CountryName ON City(Country,Name);
+EXPLAIN
+SELECT * FROM City
+WHERE Country LIKE 'M%' AND Population > 1000000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,CountryID,CountryName Population,CountryID 4,3 NULL 16 Using sort_intersect(Population,CountryID); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,CountryID,CountryName Population,CountryID 4,3 NULL 11 Using sort_intersect(Population,CountryID); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000 AND Name LIKE 'C%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name,CountryID,CountryName CountryName,Population 38,4 NULL 1 Using sort_intersect(CountryName,Population); Using where
+SELECT * FROM City USE INDEX ()
+WHERE Country LIKE 'M%' AND Population > 1000000;
+ID Name Country Population
+2464 Kuala Lumpur MYS 1297526
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+2516 Guadalajara MEX 1647720
+2517 Ecatepec de Morelos MEX 1620303
+2518 Puebla MEX 1346176
+2519 Nezahualcóyotl MEX 1224924
+2520 Juárez MEX 1217818
+2521 Tijuana MEX 1212232
+2522 León MEX 1133576
+2523 Monterrey MEX 1108499
+2524 Zapopan MEX 1002239
+2698 Maputo MOZ 1018938
+2710 Rangoon (Yangon) MMR 3361700
+SELECT * FROM City
+WHERE Country LIKE 'M%' AND Population > 1000000;
+ID Name Country Population
+2464 Kuala Lumpur MYS 1297526
+2485 Casablanca MAR 2940623
+2515 Ciudad de México MEX 8591309
+2516 Guadalajara MEX 1647720
+2517 Ecatepec de Morelos MEX 1620303
+2518 Puebla MEX 1346176
+2519 Nezahualcóyotl MEX 1224924
+2520 Juárez MEX 1217818
+2521 Tijuana MEX 1212232
+2522 León MEX 1133576
+2523 Monterrey MEX 1108499
+2524 Zapopan MEX 1002239
+2698 Maputo MOZ 1018938
+2710 Rangoon (Yangon) MMR 3361700
+SELECT * FROM City USE INDEX ()
+WHERE Country='CHN' AND Population > 1500000;
+ID Name Country Population
+1890 Shanghai CHN 9696300
+1891 Peking CHN 7472000
+1892 Chongqing CHN 6351600
+1893 Tianjin CHN 5286800
+1894 Wuhan CHN 4344600
+1895 Harbin CHN 4289800
+1896 Shenyang CHN 4265200
+1897 Kanton [Guangzhou] CHN 4256300
+1898 Chengdu CHN 3361500
+1899 Nanking [Nanjing] CHN 2870300
+1900 Changchun CHN 2812000
+1901 Xi´an CHN 2761400
+1902 Dalian CHN 2697000
+1903 Qingdao CHN 2596000
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1906 Zhengzhou CHN 2107200
+1907 Shijiazhuang CHN 2041500
+1908 Taiyuan CHN 1968400
+1909 Kunming CHN 1829500
+1910 Changsha CHN 1809800
+1911 Nanchang CHN 1691600
+1912 Fuzhou CHN 1593800
+1913 Lanzhou CHN 1565800
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000;
+ID Name Country Population
+1890 Shanghai CHN 9696300
+1891 Peking CHN 7472000
+1892 Chongqing CHN 6351600
+1893 Tianjin CHN 5286800
+1894 Wuhan CHN 4344600
+1895 Harbin CHN 4289800
+1896 Shenyang CHN 4265200
+1897 Kanton [Guangzhou] CHN 4256300
+1898 Chengdu CHN 3361500
+1899 Nanking [Nanjing] CHN 2870300
+1900 Changchun CHN 2812000
+1901 Xi´an CHN 2761400
+1902 Dalian CHN 2697000
+1903 Qingdao CHN 2596000
+1904 Jinan CHN 2278100
+1905 Hangzhou CHN 2190500
+1906 Zhengzhou CHN 2107200
+1907 Shijiazhuang CHN 2041500
+1908 Taiyuan CHN 1968400
+1909 Kunming CHN 1829500
+1910 Changsha CHN 1809800
+1911 Nanchang CHN 1691600
+1912 Fuzhou CHN 1593800
+1913 Lanzhou CHN 1565800
+SELECT * FROM City USE INDEX ()
+WHERE Country='CHN' AND Population > 1500000 AND Name LIKE 'C%';
+ID Name Country Population
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+SELECT * FROM City
+WHERE Country='CHN' AND Population > 1500000 AND Name LIKE 'C%';
+ID Name Country Population
+1892 Chongqing CHN 6351600
+1898 Chengdu CHN 3361500
+1900 Changchun CHN 2812000
+1910 Changsha CHN 1809800
+DROP DATABASE world;
+use test;
+CREATE TABLE t1 (
+f1 int,
+f4 varchar(32),
+f5 int,
+PRIMARY KEY (f1),
+KEY (f4)
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+(5,'H',1), (9,'g',0), (527,'i',0), (528,'y',1), (529,'S',6),
+(530,'m',7), (531,'b',2), (532,'N',1), (533,'V',NULL), (534,'l',1),
+(535,'M',0), (536,'w',1), (537,'j',5), (538,'l',0), (539,'n',2),
+(540,'m',2), (541,'r',2), (542,'l',2), (543,'h',3),(544,'o',0),
+(956,'h',0), (957,'g',0), (958,'W',5), (959,'s',3), (960,'w',0),
+(961,'q',0), (962,'e',NULL), (963,'u',7), (964,'q',1), (965,'N',NULL),
+(966,'e',0), (967,'t',3), (968,'e',6), (969,'f',NULL), (970,'j',0),
+(971,'s',3), (972,'I',0), (973,'h',4), (974,'g',1), (975,'s',0),
+(976,'r',3), (977,'x',1), (978,'v',8), (979,'j',NULL), (980,'z',7),
+(981,'t',9), (982,'j',5), (983,'u',NULL), (984,'g',6), (985,'w',1),
+(986,'h',1), (987,'v',0), (988,'v',0), (989,'c',2), (990,'b',7),
+(991,'z',0), (992,'M',1), (993,'u',2), (994,'r',2), (995,'b',4),
+(996,'A',2), (997,'u',0), (998,'a',0), (999,'j',2), (1,'I',2);
+EXPLAIN
+SELECT * FROM t1
+WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range PRIMARY,f4 PRIMARY,f4 4,35 NULL 1 Using sort_intersect(PRIMARY,f4); Using where
+SELECT * FROM t1
+WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ;
+f1 f4 f5
+994 r 2
+996 A 2
+998 a 0
+DROP TABLE t1;
+SET SESSION optimizer_switch='index_merge_sort_intersection=on';
+SET SESSION STORAGE_ENGINE=DEFAULT;
diff --git a/mysql-test/r/index_merge_innodb.result b/mysql-test/r/index_merge_innodb.result
index 4c561da6420..e8fda5b4655 100644
--- a/mysql-test/r/index_merge_innodb.result
+++ b/mysql-test/r/index_merge_innodb.result
@@ -1,3 +1,5 @@
+set @optimizer_switch_save= @@optimizer_switch;
+set optimizer_switch='index_merge_sort_intersection=off';
#---------------- Index merge test 2 -------------------------------------------
SET SESSION STORAGE_ENGINE = InnoDB;
drop table if exists t1,t2;
@@ -692,7 +694,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
2 DERIVED t1 index_merge PRIMARY,idx idx,PRIMARY 5,4 NULL 11419 Using sort_union(idx,PRIMARY); Using where
SELECT COUNT(*) FROM
-(SELECT * FROM t1
+(SELECT * FROM t1 FORCE INDEX(primary,idx)
WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
COUNT(*)
6145
@@ -709,3 +711,4 @@ WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
COUNT(*)
6145
DROP TABLE t1;
+set optimizer_switch= @optimizer_switch_save;
diff --git a/mysql-test/r/index_merge_myisam.result b/mysql-test/r/index_merge_myisam.result
index e5ace9b92fc..71834ff6b5b 100644
--- a/mysql-test/r/index_merge_myisam.result
+++ b/mysql-test/r/index_merge_myisam.result
@@ -1,3 +1,5 @@
+set @optimizer_switch_save= @@optimizer_switch;
+set optimizer_switch='index_merge_sort_intersection=off';
#---------------- Index merge test 1 -------------------------------------------
SET SESSION STORAGE_ENGINE = MyISAM;
drop table if exists t0, t1, t2, t3, t4;
@@ -115,11 +117,11 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select * from t0 where
(key1 < 3 or key2 < 3) and (key3 < 100);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t0 range i1,i2,i3 i3 4 NULL 95 Using index condition; Using where; Using MRR
+1 SIMPLE t0 index_merge i1,i2,i3 i1,i2 4,4 NULL 6 Using sort_union(i1,i2); Using where
explain select * from t0 where
(key1 < 3 or key2 < 3) and (key3 < 1000);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t0 ALL i1,i2,i3 NULL NULL NULL 1024 Using where
+1 SIMPLE t0 index_merge i1,i2,i3 i1,i2 4,4 NULL 6 Using sort_union(i1,i2); Using where
explain select * from t0 where
((key1 < 4 or key2 < 4) and (key2 <5 or key3 < 4))
or
@@ -203,12 +205,12 @@ alter table t2 add index i321(key3, key2, key1);
explain select key3 from t2 where key1 = 100 or key2 = 100;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index_merge i1_3,i2_3 i1_3,i2_3 4,4 NULL 2 Using sort_union(i1_3,i2_3); Using where
-explain select key3 from t2 where key1 <100 or key2 < 100;
+explain select key3 from t2 where key1 < 500 or key2 < 500;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index i1_3,i2_3 i321 12 NULL 1024 Using where; Using index
explain select key7 from t2 where key1 <100 or key2 < 100;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL i1_3,i2_3 NULL NULL NULL 1024 Using where
+1 SIMPLE t2 index_merge i1_3,i2_3 i1_3,i2_3 4,4 NULL 188 Using sort_union(i1_3,i2_3); Using where
create table t4 (
key1a int not null,
key1b int not null,
@@ -259,7 +261,7 @@ explain
select * from t0,t1 where (t0.key1=t1.key1) and
(t0.key1=3 or t0.key2=4) and t1.key1<200;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t0 ALL i1,i2 NULL NULL NULL 1024 Using where
+1 SIMPLE t0 index_merge i1,i2 i1,i2 4,4 NULL 2 Using union(i1,i2); Using where
1 SIMPLE t1 ref i1 i1 4 test.t0.key1 1
explain
select * from t0,t1 where (t0.key1=t1.key1) and
@@ -372,14 +374,14 @@ max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.ke
alter table t0 add filler1 char(200), add filler2 char(200), add filler3 char(200);
update t0 set key2=1, key3=1, key4=1, key5=1,key6=1,key7=1 where key7 < 500;
explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
-from t0 as A, t0 as B
+from t0 as A straight_join t0 as B
where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE A index_merge i1,i2,i3,i4,i5,i6,i7?,i8 i2,i3,i4,i5,i6,i7?,i8 X NULL # Using union(intersect(i2,i3,i4,i5,i6,i7?),i8); Using where
1 SIMPLE B index_merge i1,i2,i3,i4,i5,i6,i7?,i8 i2,i3,i4,i5,i6,i7?,i8 X NULL # Using union(intersect(i2,i3,i4,i5,i6,i7?),i8); Using where; Using join buffer (flat, BNL join)
select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
-from t0 as A, t0 as B
+from t0 as A straight_join t0 as B
where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);
max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
@@ -567,9 +569,7 @@ INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
-SET SESSION sort_buffer_size=1;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '1'
+SET SESSION sort_buffer_size=1024*8;
EXPLAIN
SELECT * FROM t1 FORCE INDEX(a,b) WHERE a LIKE 'a%' OR b LIKE 'b%'
ORDER BY a,b;
@@ -1562,7 +1562,7 @@ explain select * from t1 where a=10 and b=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a,b a 5 const 49 Using where
No intersect if it is disabled:
-set optimizer_switch='default,index_merge_intersection=off';
+set optimizer_switch='default,index_merge_sort_intersection=off,index_merge_intersection=off';
explain select * from t1 where a=10 and b=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a,b a 5 const 49 Using where
@@ -1594,3 +1594,4 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge a,b,c a,c 5,5 NULL 54 Using sort_union(a,c); Using where
set optimizer_switch=default;
drop table t0, t1;
+set optimizer_switch= @optimizer_switch_save;
diff --git a/mysql-test/r/optimizer_switch.result b/mysql-test/r/optimizer_switch.result
index 6c9b7254a7c..b9833c118bc 100644
--- a/mysql-test/r/optimizer_switch.result
+++ b/mysql-test/r/optimizer_switch.result
@@ -4,19 +4,19 @@
#
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='index_merge=off,index_merge_union=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='index_merge_union=on';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,index_merge_sort_union=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch=4;
ERROR 42000: Variable 'optimizer_switch' can't be set to the value of '4'
set optimizer_switch=NULL;
@@ -43,57 +43,60 @@ set optimizer_switch=default;
set optimizer_switch='index_merge=off,index_merge_union=off,default';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch=default;
select @@global.optimizer_switch;
@@global.optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set @@global.optimizer_switch=default;
select @@global.optimizer_switch;
@@global.optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
#
# Check index_merge's @@optimizer_switch flags
#
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
BUG#37120 optimizer_switch allowable values not according to specification
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,materialization=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,semijoin=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,loosescan=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,semijoin=off,materialization=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,materialization=off,semijoin=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,semijoin=off,materialization=off,loosescan=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,semijoin=off,loosescan=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch='default,materialization=off,loosescan=off';
select @@optimizer_switch;
@@optimizer_switch
-index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch=default;
+select @@optimizer_switch;
+@@optimizer_switch
+index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr_sort_keys=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,table_elimination=on
diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result
index ab4a5fa220e..89c8b6c8c81 100644
--- a/mysql-test/r/order_by.result
+++ b/mysql-test/r/order_by.result
@@ -1426,9 +1426,9 @@ DROP TABLE t1;
#
create table t1(a int, b tinytext);
insert into t1 values (1,2),(3,2);
-set session sort_buffer_size= 30000;
+set session sort_buffer_size= 1000;
Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '30000'
+Warning 1292 Truncated incorrect sort_buffer_size value: '1000'
set session max_sort_length= 2180;
select * from t1 order by b;
ERROR HY001: Out of sort memory; increase server sort buffer size
diff --git a/mysql-test/r/partition_innodb_semi_consistent.result b/mysql-test/r/partition_innodb_semi_consistent.result
index 471da4c1c2e..fbdd70528c5 100644
--- a/mysql-test/r/partition_innodb_semi_consistent.result
+++ b/mysql-test/r/partition_innodb_semi_consistent.result
@@ -75,7 +75,17 @@ TRUNCATE t1;
INSERT INTO t1 VALUES (1,'init');
CREATE PROCEDURE p1()
BEGIN
+# retry the UPDATE in case it times out the lock before con1 has time
+# to COMMIT.
+DECLARE do_retry INT DEFAULT 0;
+DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET do_retry = 1;
+retry_loop:LOOP
UPDATE t1 SET b = CONCAT(b, '+con2') WHERE a = 1;
+IF do_retry = 0 THEN
+LEAVE retry_loop;
+END IF;
+SET do_retry = 0;
+END LOOP;
INSERT INTO t2 VALUES ();
END|
BEGIN;
diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result
index 7653b824b0c..4342b66867e 100644
--- a/mysql-test/r/range.result
+++ b/mysql-test/r/range.result
@@ -1085,10 +1085,10 @@ id b c
0 3 4
EXPLAIN SELECT * FROM t1 WHERE 0 < b OR 0 > c;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL idx1,idx2 NULL NULL NULL 10 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx1,idx2 4,4 NULL 4 Using sort_union(idx1,idx2); Using where
EXPLAIN SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL idx1,idx2 NULL NULL NULL 10 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx1,idx2 4,4 NULL 4 Using sort_union(idx1,idx2); Using where
DROP TABLE t1;
CREATE TABLE t1 (
item char(20) NOT NULL default '',
diff --git a/mysql-test/r/range_vs_index_merge.result b/mysql-test/r/range_vs_index_merge.result
new file mode 100644
index 00000000000..c9be1779197
--- /dev/null
+++ b/mysql-test/r/range_vs_index_merge.result
@@ -0,0 +1,1370 @@
+DROP TABLE IF EXISTS t1,t2,t3,t4;
+DROP DATABASE IF EXISTS world;
+set names utf8;
+CREATE DATABASE world;
+use world;
+CREATE TABLE Country (
+Code char(3) NOT NULL default '',
+Name char(52) NOT NULL default '',
+SurfaceArea float(10,2) NOT NULL default '0.00',
+Population int(11) NOT NULL default '0',
+Capital int(11) default NULL,
+PRIMARY KEY (Code),
+UNIQUE INDEX (Name)
+);
+CREATE TABLE City (
+ID int(11) NOT NULL auto_increment,
+Name char(35) NOT NULL default '',
+Country char(3) NOT NULL default '',
+Population int(11) NOT NULL default '0',
+PRIMARY KEY (ID),
+INDEX (Population),
+INDEX (Country)
+);
+CREATE TABLE CountryLanguage (
+Country char(3) NOT NULL default '',
+Language char(30) NOT NULL default '',
+Percentage float(3,1) NOT NULL default '0.0',
+PRIMARY KEY (Country, Language),
+INDEX (Percentage)
+);
+SELECT COUNT(*) FROM Country;
+COUNT(*)
+239
+SELECT COUNT(*) FROM City;
+COUNT(*)
+4079
+SELECT COUNT(*) FROM CountryLanguage;
+COUNT(*)
+984
+CREATE INDEX Name ON City(Name);
+set session optimizer_switch='index_merge_sort_intersection=off';
+EXPLAIN
+SELECT * FROM City
+WHERE (Population >= 100000 OR Name LIKE 'P%' OR Population < 100000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ALL Population,Name NULL NULL NULL 4079 Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Population >= 100000 OR Name LIKE 'P%') AND Country='CAN' OR
+(Population < 100000 OR Name Like 'T%') AND Country='ARG';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Country 3 NULL 104 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE Population < 200000 AND Name LIKE 'P%' AND
+(Population > 300000 OR Name LIKE 'T%') AND
+(Population < 100000 OR Name LIKE 'Pa%');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Name 35 NULL 135 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE Population > 100000 AND Name LIKE 'Aba%' OR
+Country IN ('CAN', 'ARG') AND ID < 3800 OR
+Country < 'U' AND Name LIKE 'Zhu%' OR
+ID BETWEEN 3800 AND 3810;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 132 Using sort_union(Name,Country,PRIMARY); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Population > 101000 AND Population < 115000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 459 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE (Population > 101000 AND Population < 102000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 39 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Country,Name Name,Country 35,3 NULL 172 Using sort_union(Name,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 115000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Name,Country 35,3 NULL 172 Using sort_union(Name,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 102000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population 4 NULL 39 Using index condition; Using where; Using MRR
+SELECT * FROM City USE INDEX ()
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 115000);
+ID Name Country Population
+403 Catanduva BRA 107761
+412 Cachoeirinha BRA 103240
+636 Bilbays EGY 113608
+637 Mit Ghamr EGY 101801
+701 Tarragona ESP 113016
+702 Lleida (Lérida) ESP 112207
+703 Jaén ESP 109247
+704 Ourense (Orense) ESP 109120
+705 Mataró ESP 104095
+706 Algeciras ESP 103106
+707 Marbella ESP 101144
+759 Gonder ETH 112249
+869 Cabuyao PHL 106630
+870 Calapan PHL 105910
+873 Cauayan PHL 103952
+1844 Cape Breton CAN 114733
+1847 Cambridge CAN 109186
+2908 Cajamarca PER 108009
+3003 Caen FRA 113987
+3411 Ceyhan TUR 102412
+3571 Calabozo VEN 107146
+3786 Cam Ranh VNM 114041
+3792 Tartu EST 101246
+4002 Carrollton USA 109576
+4027 Cape Coral USA 102286
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 115000);
+ID Name Country Population
+403 Catanduva BRA 107761
+412 Cachoeirinha BRA 103240
+636 Bilbays EGY 113608
+637 Mit Ghamr EGY 101801
+701 Tarragona ESP 113016
+702 Lleida (Lérida) ESP 112207
+703 Jaén ESP 109247
+704 Ourense (Orense) ESP 109120
+705 Mataró ESP 104095
+706 Algeciras ESP 103106
+707 Marbella ESP 101144
+759 Gonder ETH 112249
+869 Cabuyao PHL 106630
+870 Calapan PHL 105910
+873 Cauayan PHL 103952
+1844 Cape Breton CAN 114733
+1847 Cambridge CAN 109186
+2908 Cajamarca PER 108009
+3003 Caen FRA 113987
+3411 Ceyhan TUR 102412
+3571 Calabozo VEN 107146
+3786 Cam Ranh VNM 114041
+3792 Tartu EST 101246
+4002 Carrollton USA 109576
+4027 Cape Coral USA 102286
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 102000);
+ID Name Country Population
+637 Mit Ghamr EGY 101801
+707 Marbella ESP 101144
+3792 Tartu EST 101246
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 102000);
+ID Name Country Population
+637 Mit Ghamr EGY 101801
+707 Marbella ESP 101144
+3792 Tartu EST 101246
+4032 Cambridge USA 101355
+EXPLAIN
+SELECT * FROM City WHERE (Name < 'Ac');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 13 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Name < 'Bb');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 208 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Country > 'A' AND Country < 'B');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 104 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Name BETWEEN 'P' AND 'Pb');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 39 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Name BETWEEN 'P' AND 'S');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 221 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 110000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 328 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 103000 AND Population < 104000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 37 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Name 35 NULL 52 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Name,Population 35,4 NULL 50 Using sort_union(Name,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Country,Name 3,35 NULL 143 Using sort_union(Country,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Country,Population 3,4 NULL 141 Using sort_union(Country,Population); Using where
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+EXPLAIN
+SELECT * FROM City WHERE (ID < 10) OR (ID BETWEEN 100 AND 110);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 21 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (ID < 200) OR (ID BETWEEN 100 AND 200);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 201 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1500);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ALL PRIMARY NULL NULL NULL 4079 Using where
+EXPLAIN
+SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 19 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'H%' OR Name LIKE 'P%' ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 222 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'Ha%' OR Name LIKE 'Pa%' ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 72 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 110) AND
+(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 21 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 900 AND 1500) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,Population 35,3,4 NULL 128 Using sort_union(Name,Country,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 200) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,Population 35,3,4 NULL 128 Using sort_union(Name,Country,Population); Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 110) AND
+(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+100 Paraná ARG 207041
+102 Posadas ARG 201273
+SELECT * FROM City
+WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 110) AND
+(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+100 Paraná ARG 207041
+102 Posadas ARG 201273
+SELECT * FROM City USE INDEX()
+WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 900 AND 1500) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+129 Oranjestad ABW 29034
+191 Hamilton BMU 1200
+528 Hartlepool GBR 92000
+529 Halifax GBR 91069
+914 Sekondi-Takoradi GHA 103653
+943 Palembang IDN 1222764
+950 Padang IDN 534474
+983 Palu IDN 142800
+984 Pasuruan IDN 134019
+991 Pangkal Pinang IDN 124000
+1003 Pemalang IDN 103500
+1004 Klaten IDN 103300
+1007 Palangka Raya IDN 99693
+1020 Padang Sidempuan IDN 91200
+1045 Patna IND 917243
+1114 Panihati IND 275990
+1129 Patiala IND 238368
+1142 Panipat IND 215218
+1159 Parbhani IND 190255
+1231 Pali IND 136842
+1263 Pathankot IND 123930
+1265 Palghat (Palakkad) IND 123289
+1293 Pallavaram IND 111866
+1319 Tellicherry (Thalassery) IND 103579
+1339 Palayankottai IND 97662
+1345 Patan IND 96109
+1436 Marv Dasht IRN 103579
+1468 Palermo ITA 683794
+1478 Padova ITA 211391
+1484 Parma ITA 168717
+SELECT * FROM City
+WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 900 AND 1500) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+129 Oranjestad ABW 29034
+191 Hamilton BMU 1200
+528 Hartlepool GBR 92000
+529 Halifax GBR 91069
+914 Sekondi-Takoradi GHA 103653
+943 Palembang IDN 1222764
+950 Padang IDN 534474
+983 Palu IDN 142800
+984 Pasuruan IDN 134019
+991 Pangkal Pinang IDN 124000
+1003 Pemalang IDN 103500
+1004 Klaten IDN 103300
+1007 Palangka Raya IDN 99693
+1020 Padang Sidempuan IDN 91200
+1045 Patna IND 917243
+1114 Panihati IND 275990
+1129 Patiala IND 238368
+1142 Panipat IND 215218
+1159 Parbhani IND 190255
+1231 Pali IND 136842
+1263 Pathankot IND 123930
+1265 Palghat (Palakkad) IND 123289
+1293 Pallavaram IND 111866
+1319 Tellicherry (Thalassery) IND 103579
+1339 Palayankottai IND 97662
+1345 Patan IND 96109
+1436 Marv Dasht IRN 103579
+1468 Palermo ITA 683794
+1478 Padova ITA 211391
+1484 Parma ITA 168717
+SELECT * FROM City USE INDEX ()
+WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 200) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+100 Paraná ARG 207041
+129 Oranjestad ABW 29034
+167 Jamalpur BGD 103556
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+191 Hamilton BMU 1200
+SELECT * FROM City
+WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 200) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+100 Paraná ARG 207041
+129 Oranjestad ABW 29034
+167 Jamalpur BGD 103556
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+191 Hamilton BMU 1200
+EXPLAIN
+SELECT * FROM City WHERE Population > 101000 AND Population < 102000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 39 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Population > 101000 AND Population < 110000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 328 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Country < 'C';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 436 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Country < 'AGO';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 6 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name BETWEEN 'P' AND 'S';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 221 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name BETWEEN 'P' AND 'Pb';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 39 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3400 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 401 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'P%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 135 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) AND
+(Country < 'C' OR Name BETWEEN 'P' AND 'S')) OR
+((ID BETWEEN 3400 AND 3800) AND
+(Country < 'AGO' OR Name LIKE 'Pa%'));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Country,Name,Population 3,35,4 NULL 84 Using sort_union(Country,Name,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 110000) AND
+(Country < 'AGO' OR Name BETWEEN 'P' AND 'Pb')) OR
+((ID BETWEEN 3790 AND 3800) AND
+(Country < 'C' OR Name LIKE 'P%'));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Country,Name,PRIMARY 3,35,4 NULL 56 Using sort_union(Country,Name,PRIMARY); Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) AND
+(Country < 'C' OR Name BETWEEN 'P' AND 'S')) OR
+((ID BETWEEN 3400 AND 3800) AND
+(Country < 'AGO' OR Name LIKE 'Pa%'));
+ID Name Country Population
+169 Naogaon BGD 101266
+205 Francistown BWA 101805
+417 Itaituba BRA 101320
+418 Araras BRA 101046
+751 Potchefstroom ZAF 101817
+2909 Puno PER 101578
+3463 Pavlograd UKR 127000
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) AND
+(Country < 'C' OR Name BETWEEN 'P' AND 'S')) OR
+((ID BETWEEN 3400 AND 3800) AND
+(Country < 'AGO' OR Name LIKE 'Pa%'));
+ID Name Country Population
+169 Naogaon BGD 101266
+205 Francistown BWA 101805
+417 Itaituba BRA 101320
+418 Araras BRA 101046
+751 Potchefstroom ZAF 101817
+2909 Puno PER 101578
+3463 Pavlograd UKR 127000
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 110000) AND
+(Country < 'AGO' OR Name BETWEEN 'P' AND 'Pb')) OR
+((ID BETWEEN 3790 AND 3800) AND
+(Country < 'C' OR Name LIKE 'P%'));
+ID Name Country Population
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 110000) AND
+(Country < 'AGO' OR Name BETWEEN 'P' AND 'Pb')) OR
+((ID BETWEEN 3790 AND 3800) AND
+(Country < 'C' OR Name LIKE 'P%'));
+ID Name Country Population
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+CREATE INDEX CountryPopulation ON City(Country,Population);
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'Pas%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 5 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'P%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 135 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 103000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 81 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Country='USA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation Country 3 const 267 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE Country='FIN';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation Country 3 const 6 Using index condition
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'Pas%')
+AND Country='USA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name,CountryPopulation CountryPopulation,Name 7,35 NULL 15 Using sort_union(CountryPopulation,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
+AND Country='FIN';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Population,Country,Name,CountryPopulation Country 3 const 6 Using index condition; Using where
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'Pas%')
+AND Country='USA';
+ID Name Country Population
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+4023 Gary USA 102746
+4024 Berkeley USA 102743
+4025 Santa Clara USA 102361
+4026 Green Bay USA 102313
+4027 Cape Coral USA 102286
+4028 Arvada USA 102153
+4029 Pueblo USA 102121
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'Pas%')
+AND Country='USA';
+ID Name Country Population
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+4023 Gary USA 102746
+4024 Berkeley USA 102743
+4025 Santa Clara USA 102361
+4026 Green Bay USA 102313
+4027 Cape Coral USA 102286
+4028 Arvada USA 102153
+4029 Pueblo USA 102121
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
+AND Country='FIN';
+ID Name Country Population
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
+AND Country='FIN';
+ID Name Country Population
+CREATE INDEX CountryName ON City(Country,Name);
+EXPLAIN
+SELECT * FROM City WHERE Country='USA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation,CountryName Country 3 const 267 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE Country='FIN';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation,CountryName CountryName 3 const 5 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE Country='BRA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation,CountryName CountryName 3 const 221 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 4025 AND 4035;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 4028 AND 4032;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 5 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3500 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 301 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 4000 AND 4300;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 80 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 250 and 260 ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 102000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 39 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 103000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 81 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'Pa%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 41 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryPopulation,PRIMARY 7,4 NULL 14 Using sort_union(CountryPopulation,PRIMARY); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4028 AND 4032);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryName,PRIMARY 38,4 NULL 11 Using sort_union(CountryName,PRIMARY); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 110000) OR
+ID BETWEEN 3500 AND 3800) AND Country='FIN'
+ AND (Name BETWEEN 'P' AND 'T' OR ID BETWEEN 4000 AND 4300);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryName 3 const 5 Using index condition; Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4028 AND 4032);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4028 AND 4032);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='FIN'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='FIN'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 and Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ OR (Name LIKE 'Pa%' OR ID BETWEEN 250 AND 260) AND Country='BRA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryPopulation,PRIMARY,CountryName 7,4,38 NULL 35 Using sort_union(CountryPopulation,PRIMARY,CountryName); Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 and Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ OR (Name LIKE 'Pa%' OR ID BETWEEN 250 AND 260) AND Country='BRA';
+ID Name Country Population
+250 Mauá BRA 375055
+251 Carapicuíba BRA 357552
+252 Olinda BRA 354732
+253 Campina Grande BRA 352497
+254 São José do Rio Preto BRA 351944
+255 Caxias do Sul BRA 349581
+256 Moji das Cruzes BRA 339194
+257 Diadema BRA 335078
+258 Aparecida de Goiânia BRA 324662
+259 Piracicaba BRA 319104
+260 Cariacica BRA 319033
+285 Paulista BRA 248473
+339 Passo Fundo BRA 166343
+364 Parnaíba BRA 129756
+372 Paranaguá BRA 126076
+379 Palmas BRA 121919
+386 Patos de Minas BRA 119262
+424 Passos BRA 98570
+430 Paulo Afonso BRA 97291
+435 Parnamirim BRA 96210
+448 Patos BRA 90519
+451 Palhoça BRA 89465
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 and Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ OR (Name LIKE 'Pa%' OR ID BETWEEN 250 AND 260) AND Country='BRA';
+ID Name Country Population
+250 Mauá BRA 375055
+251 Carapicuíba BRA 357552
+252 Olinda BRA 354732
+253 Campina Grande BRA 352497
+254 São José do Rio Preto BRA 351944
+255 Caxias do Sul BRA 349581
+256 Moji das Cruzes BRA 339194
+257 Diadema BRA 335078
+258 Aparecida de Goiânia BRA 324662
+259 Piracicaba BRA 319104
+260 Cariacica BRA 319033
+285 Paulista BRA 248473
+339 Passo Fundo BRA 166343
+364 Parnaíba BRA 129756
+372 Paranaguá BRA 126076
+379 Palmas BRA 121919
+386 Patos de Minas BRA 119262
+424 Passos BRA 98570
+430 Paulo Afonso BRA 97291
+435 Parnamirim BRA 96210
+448 Patos BRA 90519
+451 Palhoça BRA 89465
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'P%' OR ID BETWEEN 4000 AND 4300);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryName 38 NULL 23 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pho%' OR ID BETWEEN 4000 AND 4300);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country,Name,CountryPopulation,CountryName Name 35 NULL 1 Using where; Using MRR
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'P%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'P%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pho%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3798 Phoenix USA 1321045
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pho%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3798 Phoenix USA 1321045
+DROP INDEX Population ON City;
+DROP INDEX Name ON City;
+EXPLAIN
+SELECT * FROM City
+WHERE Country='USA' AND Population BETWEEN 101000 AND 102000 OR
+Country='USA' AND Name LIKE 'Pa%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Country,CountryPopulation,CountryName CountryPopulation,CountryName 7,38 NULL 10 Using sort_union(CountryPopulation,CountryName); Using where
+SELECT * FROM City USE INDEX()
+WHERE Country='USA' AND Population BETWEEN 101000 AND 102000 OR
+Country='USA' AND Name LIKE 'Pa%';
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE Country='USA' AND Population BETWEEN 101000 AND 102000 OR
+Country='USA' AND Name LIKE 'Pa%';
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+EXPLAIN
+SELECT * FROM City
+WHERE Country='USA' AND
+(Population BETWEEN 101000 AND 102000 OR Name LIKE 'Pa%');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Country,CountryPopulation,CountryName CountryPopulation,CountryName 7,38 NULL 10 Using sort_union(CountryPopulation,CountryName); Using where
+SELECT * FROM City
+WHERE Country='USA' AND
+(Population BETWEEN 101000 AND 102000 OR Name LIKE 'Pa%');
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE Country='USA' AND
+(Population BETWEEN 101000 AND 102000 OR Name LIKE 'Pa%');
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+DROP DATABASE world;
+use test;
+CREATE TABLE t1 (
+id int(10) unsigned NOT NULL auto_increment,
+account_id int(10) unsigned NOT NULL,
+first_name varchar(50) default NULL,
+middle_name varchar(50) default NULL,
+last_name varchar(100) default NULL,
+home_address_1 varchar(150) default NULL,
+home_city varchar(75) default NULL,
+home_state char(2) default NULL,
+home_postal_code varchar(50) default NULL,
+home_county varchar(75) default NULL,
+home_country char(3) default NULL,
+work_address_1 varchar(150) default NULL,
+work_city varchar(75) default NULL,
+work_state char(2) default NULL,
+work_postal_code varchar(50) default NULL,
+work_county varchar(75) default NULL,
+work_country char(3) default NULL,
+login varchar(50) NOT NULL,
+PRIMARY KEY (id),
+KEY login (login,account_id),
+KEY account_id (account_id),
+KEY user_home_country_indx (home_country),
+KEY user_work_country_indx (work_country),
+KEY user_home_state_indx (home_state),
+KEY user_work_state_indx (work_state),
+KEY user_home_city_indx (home_city),
+KEY user_work_city_indx (work_city),
+KEY user_first_name_indx (first_name),
+KEY user_last_name_indx (last_name)
+);
+insert into t1(account_id, login, home_state, work_state) values
+(1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia'),
+(1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia');
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+select count(*) from t1 where account_id = 1;
+count(*)
+3072
+select * from t1
+where (home_state = 'ia' or work_state='ia') and account_id = 1;
+id account_id first_name middle_name last_name home_address_1 home_city home_state home_postal_code home_county home_country work_address_1 work_city work_state work_postal_code work_county work_country login
+1 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+2 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+3 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+4 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+5 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+6 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+explain
+select * from t1
+where (home_state = 'ia' or work_state='ia') and account_id = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge account_id,user_home_state_indx,user_work_state_indx user_home_state_indx,user_work_state_indx 3,3 NULL 6 Using union(user_home_state_indx,user_work_state_indx); Using where
+drop table t1;
+CREATE TABLE t1 (
+c1 int(11) NOT NULL auto_increment,
+c2 decimal(10,0) default NULL,
+c3 decimal(10,0) default NULL,
+c4 decimal(10,0) default NULL,
+c5 decimal(10,0) default NULL,
+cp decimal(1,0) default NULL,
+ce decimal(10,0) default NULL,
+cdata char(20),
+PRIMARY KEY (c1),
+KEY k1 (c2,c3,cp,ce),
+KEY k2 (c4,c5,cp,ce)
+);
+insert into t1 (c2, c3, c4, c5, cp) values(1,1,1,1,1);
+insert into t1 (c2, c3, c4, c5, cp) values(2,1,1,1,4);
+insert into t1 (c2, c3, c4, c5, cp) values(2,1,2,1,1);
+insert into t1 (c2, c3, c4, c5, cp) values(2,1,3,1,4);
+insert into t1 (c2, c3, c4, c5, cp) values(3,1,4,1,4);
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+explain
+select * from t1 where (c2=1 and c3=1) or (c4=2 and c5=1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 12,12 NULL 2 Using sort_union(k1,k2); Using where
+explain
+select * from t1
+where (c2=1 and c3=1 and cp=1) or (c4=2 and c5=1 and cp=1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 14,14 NULL 2 Using sort_union(k1,k2); Using where
+explain
+select * from t1
+where ((c2=1 and c3=1) or (c4=2 and c5=1)) and cp=1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 14,14 NULL 2 Using sort_union(k1,k2); Using where
+select * from t1
+where (c2=1 and c3=1 and cp=1) or (c4=2 and c5=1 and cp=1);
+c1 c2 c3 c4 c5 cp ce cdata
+1 1 1 1 1 1 NULL NULL
+3 2 1 2 1 1 NULL NULL
+select * from t1
+where ((c2=1 and c3=1) or (c4=2 and c5=1)) and cp=1;
+c1 c2 c3 c4 c5 cp ce cdata
+1 1 1 1 1 1 NULL NULL
+3 2 1 2 1 1 NULL NULL
+drop table t1;
+create table t1 (
+c1 int auto_increment primary key,
+c2 char(20),
+c3 char (20),
+c4 int
+);
+alter table t1 add key k1 (c2);
+alter table t1 add key k2 (c3);
+alter table t1 add key k3 (c4);
+insert into t1 values(null, 'a', 'b', 0);
+insert into t1 values(null, 'c', 'b', 0);
+insert into t1 values(null, 'a', 'd', 0);
+insert into t1 values(null, 'ccc', 'qqq', 0);
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,1 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,2 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,3 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,4 from t1 where c2 != 'a';
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+select count(*) from t1 where (c2='e' OR c3='q');
+count(*)
+0
+select count(*) from t1 where c4 != 0;
+count(*)
+3840
+explain
+select distinct c1 from t1 where (c2='e' OR c3='q');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 21,21 NULL 2 Using union(k1,k2); Using where
+explain
+select distinct c1 from t1 where (c4!= 0) AND (c2='e' OR c3='q');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2,k3 k1,k2 21,21 NULL 2 Using union(k1,k2); Using where
+drop table t1;
+create table t1 (
+id int unsigned auto_increment primary key,
+c1 char(12),
+c2 char(15),
+c3 char(1)
+);
+insert into t1 (c3) values ('1'), ('2');
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+update t1 set c1=lpad(id+1000, 12, ' '), c2=lpad(id+10000, 15, ' ');
+alter table t1 add unique index (c1), add unique index (c2), add index (c3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+explain
+select * from t1 where (c1=' 100000' or c2=' 2000000');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge c1,c2 c1,c2 13,16 NULL 2 Using union(c1,c2); Using where
+explain
+select * from t1 where (c1=' 100000' or c2=' 2000000') and c3='2';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge c1,c2,c3 c1,c2 13,16 NULL 2 Using union(c1,c2); Using where
+select * from t1 where (c1=' 100000' or c2=' 2000000');
+id c1 c2 c3
+select * from t1 where (c1=' 100000' or c2=' 2000000') and c3='2';
+id c1 c2 c3
+drop table t1;
+CREATE TABLE t1 (
+a smallint DEFAULT NULL,
+pk int NOT NULL AUTO_INCREMENT PRIMARY KEY,
+b varchar(10) DEFAULT NULL,
+c varchar(64) DEFAULT NULL,
+INDEX idx1 (a),
+INDEX idx2 (b),
+INDEX idx3 (c)
+);
+SELECT COUNT(*) FROM t1 IGNORE INDEX (idx2,idx3)
+WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
+(pk BETWEEN 120 AND 79 + 255 OR a IN ( 4 , 179 , 1 ) ) AND a > 8 ;
+COUNT(*)
+5
+SELECT COUNT(*) FROM t1
+WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
+(pk BETWEEN 120 AND 79 + 255 OR a IN ( 4 , 179 , 1 ) ) AND a > 8 ;
+COUNT(*)
+5
+EXPLAIN
+SELECT COUNT(*) FROM t1
+WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
+(pk BETWEEN 120 AND 79 + 255 OR a IN ( 4 , 179 , 1 ) ) AND a > 8 ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge PRIMARY,idx1,idx2,idx3 idx3,idx2,PRIMARY,idx1 67,13,4,3 NULL 8 Using sort_union(idx3,idx2,PRIMARY,idx1); Using where
+DROP TABLE t1;
+CREATE TABLE t1 (
+f1 int, f2 int, f3 int, f4 int, f5 int,
+PRIMARY KEY (f4), KEY (f1), KEY (f2), KEY (f3)
+) ;
+INSERT INTO t1 VALUES (0,0,NULL,9,5), (0,0,1,9425,NULL);
+SELECT f5 FROM t1
+WHERE f2 != 1 OR f1 IS NULL OR f4 = 4 OR
+f2 AND (f4 BETWEEN 6 AND 255 OR f3 IS NULL);
+f5
+5
+NULL
+DROP TABLE t1;
+CREATE TABLE t1 (
+f1 int, f2 int, f3 int, f4 int,
+PRIMARY KEY (f1), KEY (f3), KEY (f4)
+);
+INSERT INTO t1 VALUES (9,0,2,6), (9930,0,0,NULL);
+SET SESSION optimizer_switch='index_merge_intersection=off';
+SET SESSION optimizer_switch='index_merge_sort_union=off';
+SET SESSION optimizer_switch='index_merge_union=off';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL PRIMARY,f3,f4 NULL NULL NULL 2 Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+SET SESSION optimizer_switch='index_merge_union=on';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL PRIMARY,f3,f4 NULL NULL NULL 2 Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+INSERT INTO t1 VALUES
+(93,0,3,6), (9933,0,3,3), (94,0,4,6), (9934,0,4,4),
+(95,0,5,6), (9935,0,5,5), (96,0,6,6), (9936,0,6,6),
+(97,0,7,6), (9937,0,7,7), (98,0,8,6), (9938,0,8,8),
+(99,0,9,6), (9939,0,9,9);
+SET SESSION optimizer_switch='index_merge_union=off';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL PRIMARY,f3,f4 NULL NULL NULL 16 Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+SET SESSION optimizer_switch='index_merge_union=on';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge PRIMARY,f3,f4 f3,PRIMARY,f3 5,4,5 NULL 3 Using union(f3,PRIMARY,f3); Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+SET SESSION optimizer_switch=DEFAULT;
+DROP TABLE t1;
+set session optimizer_switch='index_merge_sort_intersection=default';
diff --git a/mysql-test/r/range_vs_index_merge_innodb.result b/mysql-test/r/range_vs_index_merge_innodb.result
new file mode 100644
index 00000000000..73cff1068a9
--- /dev/null
+++ b/mysql-test/r/range_vs_index_merge_innodb.result
@@ -0,0 +1,1372 @@
+SET SESSION STORAGE_ENGINE='InnoDB';
+DROP TABLE IF EXISTS t1,t2,t3,t4;
+DROP DATABASE IF EXISTS world;
+set names utf8;
+CREATE DATABASE world;
+use world;
+CREATE TABLE Country (
+Code char(3) NOT NULL default '',
+Name char(52) NOT NULL default '',
+SurfaceArea float(10,2) NOT NULL default '0.00',
+Population int(11) NOT NULL default '0',
+Capital int(11) default NULL,
+PRIMARY KEY (Code),
+UNIQUE INDEX (Name)
+);
+CREATE TABLE City (
+ID int(11) NOT NULL auto_increment,
+Name char(35) NOT NULL default '',
+Country char(3) NOT NULL default '',
+Population int(11) NOT NULL default '0',
+PRIMARY KEY (ID),
+INDEX (Population),
+INDEX (Country)
+);
+CREATE TABLE CountryLanguage (
+Country char(3) NOT NULL default '',
+Language char(30) NOT NULL default '',
+Percentage float(3,1) NOT NULL default '0.0',
+PRIMARY KEY (Country, Language),
+INDEX (Percentage)
+);
+SELECT COUNT(*) FROM Country;
+COUNT(*)
+239
+SELECT COUNT(*) FROM City;
+COUNT(*)
+4079
+SELECT COUNT(*) FROM CountryLanguage;
+COUNT(*)
+984
+CREATE INDEX Name ON City(Name);
+set session optimizer_switch='index_merge_sort_intersection=off';
+EXPLAIN
+SELECT * FROM City
+WHERE (Population >= 100000 OR Name LIKE 'P%' OR Population < 100000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ALL Population,Name NULL NULL NULL 4079 Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Population >= 100000 OR Name LIKE 'P%') AND Country='CAN' OR
+(Population < 100000 OR Name Like 'T%') AND Country='ARG';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Country 3 NULL 106 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE Population < 200000 AND Name LIKE 'P%' AND
+(Population > 300000 OR Name LIKE 'T%') AND
+(Population < 100000 OR Name LIKE 'Pa%');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Name Name 35 NULL 235 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE Population > 100000 AND Name LIKE 'Aba%' OR
+Country IN ('CAN', 'ARG') AND ID < 3800 OR
+Country < 'U' AND Name LIKE 'Zhu%' OR
+ID BETWEEN 3800 AND 3810;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 125 Using sort_union(Name,Country,PRIMARY); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Population > 101000 AND Population < 115000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 458 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE (Population > 101000 AND Population < 102000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 38 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Country,Name Name,Country 35,3 NULL 213 Using sort_union(Name,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 115000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Name,Country 35,3 NULL 213 Using sort_union(Name,Country); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 102000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Population 4 NULL 38 Using index condition; Using where; Using MRR
+SELECT * FROM City USE INDEX ()
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 115000);
+ID Name Country Population
+403 Catanduva BRA 107761
+412 Cachoeirinha BRA 103240
+636 Bilbays EGY 113608
+637 Mit Ghamr EGY 101801
+701 Tarragona ESP 113016
+702 Lleida (Lérida) ESP 112207
+703 Jaén ESP 109247
+704 Ourense (Orense) ESP 109120
+705 Mataró ESP 104095
+706 Algeciras ESP 103106
+707 Marbella ESP 101144
+759 Gonder ETH 112249
+869 Cabuyao PHL 106630
+870 Calapan PHL 105910
+873 Cauayan PHL 103952
+1844 Cape Breton CAN 114733
+1847 Cambridge CAN 109186
+2908 Cajamarca PER 108009
+3003 Caen FRA 113987
+3411 Ceyhan TUR 102412
+3571 Calabozo VEN 107146
+3786 Cam Ranh VNM 114041
+3792 Tartu EST 101246
+4002 Carrollton USA 109576
+4027 Cape Coral USA 102286
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 115000);
+ID Name Country Population
+403 Catanduva BRA 107761
+412 Cachoeirinha BRA 103240
+636 Bilbays EGY 113608
+637 Mit Ghamr EGY 101801
+701 Tarragona ESP 113016
+702 Lleida (Lérida) ESP 112207
+703 Jaén ESP 109247
+704 Ourense (Orense) ESP 109120
+705 Mataró ESP 104095
+706 Algeciras ESP 103106
+707 Marbella ESP 101144
+759 Gonder ETH 112249
+869 Cabuyao PHL 106630
+870 Calapan PHL 105910
+873 Cauayan PHL 103952
+1844 Cape Breton CAN 114733
+1847 Cambridge CAN 109186
+2908 Cajamarca PER 108009
+3003 Caen FRA 113987
+3411 Ceyhan TUR 102412
+3571 Calabozo VEN 107146
+3786 Cam Ranh VNM 114041
+3792 Tartu EST 101246
+4002 Carrollton USA 109576
+4027 Cape Coral USA 102286
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 102000);
+ID Name Country Population
+637 Mit Ghamr EGY 101801
+707 Marbella ESP 101144
+3792 Tartu EST 101246
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
+AND (Population > 101000 AND Population < 102000);
+ID Name Country Population
+637 Mit Ghamr EGY 101801
+707 Marbella ESP 101144
+3792 Tartu EST 101246
+4032 Cambridge USA 101355
+EXPLAIN
+SELECT * FROM City WHERE (Name < 'Ac');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 23 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Name < 'Bb');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 373 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Country > 'A' AND Country < 'B');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 106 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Name BETWEEN 'P' AND 'Pb');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 71 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Name BETWEEN 'P' AND 'S');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 384 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 110000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 327 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 103000 AND Population < 104000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 36 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population,Country,Name Name 35 NULL 94 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Name,Population 35,4 NULL 59 Using sort_union(Name,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Country,Name 3,35 NULL 177 Using sort_union(Country,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name Country,Population 3,4 NULL 142 Using sort_union(Country,Population); Using where
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+SELECT * FROM City
+WHERE (Name < 'Ac' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+65 Abu Dhabi ARE 398695
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'Pb' AND (Population > 101000 AND Population < 110000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+SELECT * FROM City USE INDEX ()
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+SELECT * FROM City
+WHERE (Name < 'Bb' AND (Country > 'A' AND Country < 'B')) OR
+(Name BETWEEN 'P' AND 'S' AND (Population > 103000 AND Population < 104000));
+ID Name Country Population
+55 Andorra la Vella AND 21189
+65 Abu Dhabi ARE 398695
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+75 Almirante Brown ARG 538918
+85 Avellaneda ARG 353046
+96 Bahía Blanca ARG 239810
+134 Adelaide AUS 978100
+144 Baku AZE 1787800
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+1003 Pemalang IDN 103500
+2663 Río Bravo MEX 103901
+EXPLAIN
+SELECT * FROM City WHERE (ID < 10) OR (ID BETWEEN 100 AND 110);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 20 Using where
+EXPLAIN
+SELECT * FROM City WHERE (ID < 200) OR (ID BETWEEN 100 AND 200);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 199 Using where
+EXPLAIN
+SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1500);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 2006 Using where
+EXPLAIN
+SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 19 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'H%' OR Name LIKE 'P%' ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 394 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'Ha%' OR Name LIKE 'Pa%' ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 133 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 110) AND
+(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 20 Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 900 AND 1500) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,Population 35,3,4 NULL 188 Using sort_union(Name,Country,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 200) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 199 Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 110) AND
+(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+100 Paraná ARG 207041
+102 Posadas ARG 201273
+SELECT * FROM City
+WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 110) AND
+(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+100 Paraná ARG 207041
+102 Posadas ARG 201273
+SELECT * FROM City USE INDEX()
+WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 900 AND 1500) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+129 Oranjestad ABW 29034
+191 Hamilton BMU 1200
+528 Hartlepool GBR 92000
+529 Halifax GBR 91069
+914 Sekondi-Takoradi GHA 103653
+943 Palembang IDN 1222764
+950 Padang IDN 534474
+983 Palu IDN 142800
+984 Pasuruan IDN 134019
+991 Pangkal Pinang IDN 124000
+1003 Pemalang IDN 103500
+1004 Klaten IDN 103300
+1007 Palangka Raya IDN 99693
+1020 Padang Sidempuan IDN 91200
+1045 Patna IND 917243
+1114 Panihati IND 275990
+1129 Patiala IND 238368
+1142 Panipat IND 215218
+1159 Parbhani IND 190255
+1231 Pali IND 136842
+1263 Pathankot IND 123930
+1265 Palghat (Palakkad) IND 123289
+1293 Pallavaram IND 111866
+1319 Tellicherry (Thalassery) IND 103579
+1339 Palayankottai IND 97662
+1345 Patan IND 96109
+1436 Marv Dasht IRN 103579
+1468 Palermo ITA 683794
+1478 Padova ITA 211391
+1484 Parma ITA 168717
+SELECT * FROM City
+WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 900 AND 1500) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+129 Oranjestad ABW 29034
+191 Hamilton BMU 1200
+528 Hartlepool GBR 92000
+529 Halifax GBR 91069
+914 Sekondi-Takoradi GHA 103653
+943 Palembang IDN 1222764
+950 Padang IDN 534474
+983 Palu IDN 142800
+984 Pasuruan IDN 134019
+991 Pangkal Pinang IDN 124000
+1003 Pemalang IDN 103500
+1004 Klaten IDN 103300
+1007 Palangka Raya IDN 99693
+1020 Padang Sidempuan IDN 91200
+1045 Patna IND 917243
+1114 Panihati IND 275990
+1129 Patiala IND 238368
+1142 Panipat IND 215218
+1159 Parbhani IND 190255
+1231 Pali IND 136842
+1263 Pathankot IND 123930
+1265 Palghat (Palakkad) IND 123289
+1293 Pallavaram IND 111866
+1319 Tellicherry (Thalassery) IND 103579
+1339 Palayankottai IND 97662
+1345 Patan IND 96109
+1436 Marv Dasht IRN 103579
+1468 Palermo ITA 683794
+1478 Padova ITA 211391
+1484 Parma ITA 168717
+SELECT * FROM City USE INDEX ()
+WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 200) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+100 Paraná ARG 207041
+129 Oranjestad ABW 29034
+167 Jamalpur BGD 103556
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+191 Hamilton BMU 1200
+SELECT * FROM City
+WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
+OR ((ID BETWEEN 100 AND 200) AND
+(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
+ID Name Country Population
+1 Kabul AFG 1780000
+2 Qandahar AFG 237500
+3 Herat AFG 186800
+4 Mazar-e-Sharif AFG 127800
+7 Haag NLD 440900
+16 Haarlem NLD 148772
+25 Haarlemmermeer NLD 110722
+33 Willemstad ANT 2345
+34 Tirana ALB 270000
+55 Andorra la Vella AND 21189
+56 Luanda AGO 2022000
+57 Huambo AGO 163100
+58 Lobito AGO 130000
+59 Benguela AGO 128300
+60 Namibe AGO 118200
+61 South Hill AIA 961
+62 The Valley AIA 595
+64 Dubai ARE 669181
+65 Abu Dhabi ARE 398695
+66 Sharja ARE 320095
+67 al-Ayn ARE 225970
+68 Ajman ARE 114395
+100 Paraná ARG 207041
+129 Oranjestad ABW 29034
+167 Jamalpur BGD 103556
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+191 Hamilton BMU 1200
+EXPLAIN
+SELECT * FROM City WHERE Population > 101000 AND Population < 102000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 38 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Population > 101000 AND Population < 110000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 327 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Country < 'C';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 446 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Country < 'AGO';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Country Country 3 NULL 5 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name BETWEEN 'P' AND 'S';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 384 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name BETWEEN 'P' AND 'Pb';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 71 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3400 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 944 Using where
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'P%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 235 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) AND
+(Country < 'C' OR Name BETWEEN 'P' AND 'S')) OR
+((ID BETWEEN 3400 AND 3800) AND
+(Country < 'AGO' OR Name LIKE 'Pa%'));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Country,Name,Population 3,35,4 NULL 114 Using sort_union(Country,Name,Population); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 110000) AND
+(Country < 'AGO' OR Name BETWEEN 'P' AND 'Pb')) OR
+((ID BETWEEN 3790 AND 3800) AND
+(Country < 'C' OR Name LIKE 'P%'));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Country,Name,PRIMARY 3,35,4 NULL 87 Using sort_union(Country,Name,PRIMARY); Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) AND
+(Country < 'C' OR Name BETWEEN 'P' AND 'S')) OR
+((ID BETWEEN 3400 AND 3800) AND
+(Country < 'AGO' OR Name LIKE 'Pa%'));
+ID Name Country Population
+169 Naogaon BGD 101266
+205 Francistown BWA 101805
+417 Itaituba BRA 101320
+418 Araras BRA 101046
+751 Potchefstroom ZAF 101817
+2909 Puno PER 101578
+3463 Pavlograd UKR 127000
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) AND
+(Country < 'C' OR Name BETWEEN 'P' AND 'S')) OR
+((ID BETWEEN 3400 AND 3800) AND
+(Country < 'AGO' OR Name LIKE 'Pa%'));
+ID Name Country Population
+169 Naogaon BGD 101266
+205 Francistown BWA 101805
+417 Itaituba BRA 101320
+418 Araras BRA 101046
+751 Potchefstroom ZAF 101817
+2909 Puno PER 101578
+3463 Pavlograd UKR 127000
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 110000) AND
+(Country < 'AGO' OR Name BETWEEN 'P' AND 'Pb')) OR
+((ID BETWEEN 3790 AND 3800) AND
+(Country < 'C' OR Name LIKE 'P%'));
+ID Name Country Population
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 110000) AND
+(Country < 'AGO' OR Name BETWEEN 'P' AND 'Pb')) OR
+((ID BETWEEN 3790 AND 3800) AND
+(Country < 'C' OR Name LIKE 'P%'));
+ID Name Country Population
+168 Pabna BGD 103277
+189 Parakou BEN 103577
+750 Paarl ZAF 105768
+2865 Pak Pattan PAK 107800
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+CREATE INDEX CountryPopulation ON City(Country,Population);
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'Pas%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 8 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'P%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 235 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 103000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 80 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Country='USA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation Country 3 const 274 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE Country='FIN';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation Country 3 const 7 Using index condition
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'Pas%')
+AND Country='USA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Population,Country,Name,CountryPopulation CountryPopulation,Name 7,35 NULL 17 Using sort_union(CountryPopulation,Name); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
+AND Country='FIN';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Population,Country,Name,CountryPopulation Country 3 const 7 Using index condition; Using where
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'Pas%')
+AND Country='USA';
+ID Name Country Population
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+4023 Gary USA 102746
+4024 Berkeley USA 102743
+4025 Santa Clara USA 102361
+4026 Green Bay USA 102313
+4027 Cape Coral USA 102286
+4028 Arvada USA 102153
+4029 Pueblo USA 102121
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'Pas%')
+AND Country='USA';
+ID Name Country Population
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+4023 Gary USA 102746
+4024 Berkeley USA 102743
+4025 Santa Clara USA 102361
+4026 Green Bay USA 102313
+4027 Cape Coral USA 102286
+4028 Arvada USA 102153
+4029 Pueblo USA 102121
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
+AND Country='FIN';
+ID Name Country Population
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
+AND Country='FIN';
+ID Name Country Population
+CREATE INDEX CountryName ON City(Country,Name);
+EXPLAIN
+SELECT * FROM City WHERE Country='USA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation,CountryName Country 3 const 274 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE Country='FIN';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation,CountryName Country 3 const 7 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE Country='BRA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref Country,CountryPopulation,CountryName Country 3 const 250 Using index condition
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 4025 AND 4035;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 4028 AND 4032;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 5 Using where
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 3500 AND 3800;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 300 Using where
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 4000 AND 4300;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 80 Using where
+EXPLAIN
+SELECT * FROM City WHERE ID BETWEEN 250 and 260 ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 102000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 38 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE (Population > 101000 AND Population < 103000);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Population Population 4 NULL 80 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City WHERE Name LIKE 'Pa%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range Name Name 35 NULL 71 Using index condition; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryPopulation,PRIMARY 7,4 NULL 13 Using sort_union(CountryPopulation,PRIMARY); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 103000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4028 AND 4032);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryName,PRIMARY 38,4 NULL 10 Using sort_union(CountryName,PRIMARY); Using where
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 110000) OR
+ID BETWEEN 3500 AND 3800) AND Country='FIN'
+ AND (Name BETWEEN 'P' AND 'T' OR ID BETWEEN 4000 AND 4300);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City ref PRIMARY,Population,Country,Name,CountryPopulation,CountryName Country 3 const 7 Using index condition; Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4028 AND 4032);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4028 AND 4032);
+ID Name Country Population
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='FIN'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='FIN'
+ AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
+ID Name Country Population
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 and Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ OR (Name LIKE 'Pa%' OR ID BETWEEN 250 AND 260) AND Country='BRA';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryPopulation,CountryName,PRIMARY 7,38,4 NULL 35 Using sort_union(CountryPopulation,CountryName,PRIMARY); Using where
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 and Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ OR (Name LIKE 'Pa%' OR ID BETWEEN 250 AND 260) AND Country='BRA';
+ID Name Country Population
+250 Mauá BRA 375055
+251 Carapicuíba BRA 357552
+252 Olinda BRA 354732
+253 Campina Grande BRA 352497
+254 São José do Rio Preto BRA 351944
+255 Caxias do Sul BRA 349581
+256 Moji das Cruzes BRA 339194
+257 Diadema BRA 335078
+258 Aparecida de Goiânia BRA 324662
+259 Piracicaba BRA 319104
+260 Cariacica BRA 319033
+285 Paulista BRA 248473
+339 Passo Fundo BRA 166343
+364 Parnaíba BRA 129756
+372 Paranaguá BRA 126076
+379 Palmas BRA 121919
+386 Patos de Minas BRA 119262
+424 Passos BRA 98570
+430 Paulo Afonso BRA 97291
+435 Parnamirim BRA 96210
+448 Patos BRA 90519
+451 Palhoça BRA 89465
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE ((Population > 101000 and Population < 102000) OR
+ID BETWEEN 3790 AND 3800) AND Country='USA'
+ OR (Name LIKE 'Pa%' OR ID BETWEEN 250 AND 260) AND Country='BRA';
+ID Name Country Population
+285 Paulista BRA 248473
+339 Passo Fundo BRA 166343
+364 Parnaíba BRA 129756
+372 Paranaguá BRA 126076
+379 Palmas BRA 121919
+386 Patos de Minas BRA 119262
+424 Passos BRA 98570
+430 Paulo Afonso BRA 97291
+435 Parnamirim BRA 96210
+448 Patos BRA 90519
+451 Palhoça BRA 89465
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+250 Mauá BRA 375055
+251 Carapicuíba BRA 357552
+252 Olinda BRA 354732
+253 Campina Grande BRA 352497
+254 São José do Rio Preto BRA 351944
+255 Caxias do Sul BRA 349581
+256 Moji das Cruzes BRA 339194
+257 Diadema BRA 335078
+258 Aparecida de Goiânia BRA 324662
+259 Piracicaba BRA 319104
+260 Cariacica BRA 319033
+3793 New York USA 8008278
+3794 Los Angeles USA 3694820
+3795 Chicago USA 2896016
+3796 Houston USA 1953631
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+3799 San Diego USA 1223400
+3800 Dallas USA 1188580
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'P%' OR ID BETWEEN 4000 AND 4300);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country,Name,CountryPopulation,CountryName CountryName 38 NULL 18 Using index condition; Using where; Using MRR
+EXPLAIN
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pho%' OR ID BETWEEN 4000 AND 4300);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City range PRIMARY,Population,Country,Name,CountryPopulation,CountryName Name 35 NULL 1 Using index condition; Using where; Using MRR
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'P%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'P%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3797 Philadelphia USA 1517550
+3798 Phoenix USA 1321045
+SELECT * FROM City USE INDEX ()
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pho%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3798 Phoenix USA 1321045
+SELECT * FROM City
+WHERE ((Population > 101000 AND Population < 11000) OR
+ID BETWEEN 3500 AND 3800) AND Country='USA'
+ AND (Name LIKE 'Pho%' OR ID BETWEEN 4000 AND 4300);
+ID Name Country Population
+3798 Phoenix USA 1321045
+DROP INDEX Population ON City;
+DROP INDEX Name ON City;
+EXPLAIN
+SELECT * FROM City
+WHERE Country='USA' AND Population BETWEEN 101000 AND 102000 OR
+Country='USA' AND Name LIKE 'Pa%';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Country,CountryPopulation,CountryName CountryPopulation,CountryName 7,38 NULL 8 Using sort_union(CountryPopulation,CountryName); Using where
+SELECT * FROM City USE INDEX()
+WHERE Country='USA' AND Population BETWEEN 101000 AND 102000 OR
+Country='USA' AND Name LIKE 'Pa%';
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE Country='USA' AND Population BETWEEN 101000 AND 102000 OR
+Country='USA' AND Name LIKE 'Pa%';
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+EXPLAIN
+SELECT * FROM City
+WHERE Country='USA' AND
+(Population BETWEEN 101000 AND 102000 OR Name LIKE 'Pa%');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE City index_merge Country,CountryPopulation,CountryName CountryPopulation,CountryName 7,38 NULL 8 Using sort_union(CountryPopulation,CountryName); Using where
+SELECT * FROM City
+WHERE Country='USA' AND
+(Population BETWEEN 101000 AND 102000 OR Name LIKE 'Pa%');
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+SELECT * FROM City
+WHERE Country='USA' AND
+(Population BETWEEN 101000 AND 102000 OR Name LIKE 'Pa%');
+ID Name Country Population
+3932 Paterson USA 149222
+3943 Pasadena USA 141674
+3953 Pasadena USA 133936
+3967 Paradise USA 124682
+3986 Palmdale USA 116670
+4030 Sandy USA 101853
+4031 Athens-Clarke County USA 101489
+4032 Cambridge USA 101355
+DROP DATABASE world;
+use test;
+CREATE TABLE t1 (
+id int(10) unsigned NOT NULL auto_increment,
+account_id int(10) unsigned NOT NULL,
+first_name varchar(50) default NULL,
+middle_name varchar(50) default NULL,
+last_name varchar(100) default NULL,
+home_address_1 varchar(150) default NULL,
+home_city varchar(75) default NULL,
+home_state char(2) default NULL,
+home_postal_code varchar(50) default NULL,
+home_county varchar(75) default NULL,
+home_country char(3) default NULL,
+work_address_1 varchar(150) default NULL,
+work_city varchar(75) default NULL,
+work_state char(2) default NULL,
+work_postal_code varchar(50) default NULL,
+work_county varchar(75) default NULL,
+work_country char(3) default NULL,
+login varchar(50) NOT NULL,
+PRIMARY KEY (id),
+KEY login (login,account_id),
+KEY account_id (account_id),
+KEY user_home_country_indx (home_country),
+KEY user_work_country_indx (work_country),
+KEY user_home_state_indx (home_state),
+KEY user_work_state_indx (work_state),
+KEY user_home_city_indx (home_city),
+KEY user_work_city_indx (work_city),
+KEY user_first_name_indx (first_name),
+KEY user_last_name_indx (last_name)
+);
+insert into t1(account_id, login, home_state, work_state) values
+(1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia'),
+(1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia'), (1, 'pw', 'ia', 'ia');
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+insert into t1(account_id, login, home_state, work_state)
+select 1, 'pw', 'ak', 'ak' from t1;
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+select count(*) from t1 where account_id = 1;
+count(*)
+3072
+select * from t1
+where (home_state = 'ia' or work_state='ia') and account_id = 1;
+id account_id first_name middle_name last_name home_address_1 home_city home_state home_postal_code home_county home_country work_address_1 work_city work_state work_postal_code work_county work_country login
+1 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+2 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+3 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+4 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+5 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+6 1 NULL NULL NULL NULL NULL ia NULL NULL NULL NULL NULL ia NULL NULL NULL pw
+explain
+select * from t1
+where (home_state = 'ia' or work_state='ia') and account_id = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge account_id,user_home_state_indx,user_work_state_indx user_home_state_indx,user_work_state_indx 3,3 NULL 10 Using union(user_home_state_indx,user_work_state_indx); Using where
+drop table t1;
+CREATE TABLE t1 (
+c1 int(11) NOT NULL auto_increment,
+c2 decimal(10,0) default NULL,
+c3 decimal(10,0) default NULL,
+c4 decimal(10,0) default NULL,
+c5 decimal(10,0) default NULL,
+cp decimal(1,0) default NULL,
+ce decimal(10,0) default NULL,
+cdata char(20),
+PRIMARY KEY (c1),
+KEY k1 (c2,c3,cp,ce),
+KEY k2 (c4,c5,cp,ce)
+);
+insert into t1 (c2, c3, c4, c5, cp) values(1,1,1,1,1);
+insert into t1 (c2, c3, c4, c5, cp) values(2,1,1,1,4);
+insert into t1 (c2, c3, c4, c5, cp) values(2,1,2,1,1);
+insert into t1 (c2, c3, c4, c5, cp) values(2,1,3,1,4);
+insert into t1 (c2, c3, c4, c5, cp) values(3,1,4,1,4);
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+insert into t1 (c2, c3, c4, c5, cp)
+select c2, c3, c4, c5, cp from t1 where cp = 4;
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+explain
+select * from t1 where (c2=1 and c3=1) or (c4=2 and c5=1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 12,12 NULL 2 Using sort_union(k1,k2); Using where
+explain
+select * from t1
+where (c2=1 and c3=1 and cp=1) or (c4=2 and c5=1 and cp=1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 14,14 NULL 2 Using sort_union(k1,k2); Using where
+explain
+select * from t1
+where ((c2=1 and c3=1) or (c4=2 and c5=1)) and cp=1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 14,14 NULL 2 Using sort_union(k1,k2); Using where
+select * from t1
+where (c2=1 and c3=1 and cp=1) or (c4=2 and c5=1 and cp=1);
+c1 c2 c3 c4 c5 cp ce cdata
+1 1 1 1 1 1 NULL NULL
+3 2 1 2 1 1 NULL NULL
+select * from t1
+where ((c2=1 and c3=1) or (c4=2 and c5=1)) and cp=1;
+c1 c2 c3 c4 c5 cp ce cdata
+1 1 1 1 1 1 NULL NULL
+3 2 1 2 1 1 NULL NULL
+drop table t1;
+create table t1 (
+c1 int auto_increment primary key,
+c2 char(20),
+c3 char (20),
+c4 int
+);
+alter table t1 add key k1 (c2);
+alter table t1 add key k2 (c3);
+alter table t1 add key k3 (c4);
+insert into t1 values(null, 'a', 'b', 0);
+insert into t1 values(null, 'c', 'b', 0);
+insert into t1 values(null, 'a', 'd', 0);
+insert into t1 values(null, 'ccc', 'qqq', 0);
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3) select c2,c3 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,1 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,2 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,3 from t1 where c2 != 'a';
+insert into t1 (c2,c3,c4) select c2,c3,4 from t1 where c2 != 'a';
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+select count(*) from t1 where (c2='e' OR c3='q');
+count(*)
+0
+select count(*) from t1 where c4 != 0;
+count(*)
+3840
+explain
+select distinct c1 from t1 where (c2='e' OR c3='q');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2 k1,k2 21,21 NULL 2 Using union(k1,k2); Using where
+explain
+select distinct c1 from t1 where (c4!= 0) AND (c2='e' OR c3='q');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge k1,k2,k3 k1,k2 21,21 NULL 2 Using union(k1,k2); Using where
+drop table t1;
+create table t1 (
+id int unsigned auto_increment primary key,
+c1 char(12),
+c2 char(15),
+c3 char(1)
+);
+insert into t1 (c3) values ('1'), ('2');
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+insert into t1 (c3) select c3 from t1;
+update t1 set c1=lpad(id+1000, 12, ' '), c2=lpad(id+10000, 15, ' ');
+alter table t1 add unique index (c1), add unique index (c2), add index (c3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+explain
+select * from t1 where (c1=' 100000' or c2=' 2000000');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge c1,c2 c1,c2 13,16 NULL 2 Using union(c1,c2); Using where
+explain
+select * from t1 where (c1=' 100000' or c2=' 2000000') and c3='2';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge c1,c2,c3 c1,c2 13,16 NULL 2 Using union(c1,c2); Using where
+select * from t1 where (c1=' 100000' or c2=' 2000000');
+id c1 c2 c3
+select * from t1 where (c1=' 100000' or c2=' 2000000') and c3='2';
+id c1 c2 c3
+drop table t1;
+CREATE TABLE t1 (
+a smallint DEFAULT NULL,
+pk int NOT NULL AUTO_INCREMENT PRIMARY KEY,
+b varchar(10) DEFAULT NULL,
+c varchar(64) DEFAULT NULL,
+INDEX idx1 (a),
+INDEX idx2 (b),
+INDEX idx3 (c)
+);
+SELECT COUNT(*) FROM t1 IGNORE INDEX (idx2,idx3)
+WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
+(pk BETWEEN 120 AND 79 + 255 OR a IN ( 4 , 179 , 1 ) ) AND a > 8 ;
+COUNT(*)
+5
+SELECT COUNT(*) FROM t1
+WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
+(pk BETWEEN 120 AND 79 + 255 OR a IN ( 4 , 179 , 1 ) ) AND a > 8 ;
+COUNT(*)
+5
+EXPLAIN
+SELECT COUNT(*) FROM t1
+WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
+(pk BETWEEN 120 AND 79 + 255 OR a IN ( 4 , 179 , 1 ) ) AND a > 8 ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge PRIMARY,idx1,idx2,idx3 idx3,idx2,idx1,PRIMARY 67,13,3,4 NULL 9 Using sort_union(idx3,idx2,idx1,PRIMARY); Using where
+DROP TABLE t1;
+CREATE TABLE t1 (
+f1 int, f2 int, f3 int, f4 int, f5 int,
+PRIMARY KEY (f4), KEY (f1), KEY (f2), KEY (f3)
+) ;
+INSERT INTO t1 VALUES (0,0,NULL,9,5), (0,0,1,9425,NULL);
+SELECT f5 FROM t1
+WHERE f2 != 1 OR f1 IS NULL OR f4 = 4 OR
+f2 AND (f4 BETWEEN 6 AND 255 OR f3 IS NULL);
+f5
+5
+NULL
+DROP TABLE t1;
+CREATE TABLE t1 (
+f1 int, f2 int, f3 int, f4 int,
+PRIMARY KEY (f1), KEY (f3), KEY (f4)
+);
+INSERT INTO t1 VALUES (9,0,2,6), (9930,0,0,NULL);
+SET SESSION optimizer_switch='index_merge_intersection=off';
+SET SESSION optimizer_switch='index_merge_sort_union=off';
+SET SESSION optimizer_switch='index_merge_union=off';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL PRIMARY,f3,f4 NULL NULL NULL 2 Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+SET SESSION optimizer_switch='index_merge_union=on';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge PRIMARY,f3,f4 PRIMARY,f3 4,5 NULL 2 Using union(PRIMARY,f3); Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+INSERT INTO t1 VALUES
+(93,0,3,6), (9933,0,3,3), (94,0,4,6), (9934,0,4,4),
+(95,0,5,6), (9935,0,5,5), (96,0,6,6), (9936,0,6,6),
+(97,0,7,6), (9937,0,7,7), (98,0,8,6), (9938,0,8,8),
+(99,0,9,6), (9939,0,9,9);
+SET SESSION optimizer_switch='index_merge_union=off';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL PRIMARY,f3,f4 NULL NULL NULL 16 Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+SET SESSION optimizer_switch='index_merge_union=on';
+EXPLAIN
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index_merge PRIMARY,f3,f4 PRIMARY,f3 4,5 NULL 2 Using union(PRIMARY,f3); Using where
+SELECT * FROM t1 FORCE KEY (PRIMARY,f3,f4)
+WHERE ( f3 = 1 OR f1 = 7 ) AND f1 < 10
+OR f3 BETWEEN 2 AND 2 AND ( f3 = 1 OR f4 != 1 );
+f1 f2 f3 f4
+9 0 2 6
+SET SESSION optimizer_switch=DEFAULT;
+DROP TABLE t1;
+set session optimizer_switch='index_merge_sort_intersection=default';
+SET SESSION STORAGE_ENGINE=DEFAULT;
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 74049298981..930a0d6d8d5 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -3658,8 +3658,6 @@ insert into t1 select RAND()*1000, A.a + 10*(B.a+10*(C.a+10*D.a))
from t3 A, t3 B, t3 C, t3 D where D.a<3;
insert into t2(y,z) select t1.b, RAND()*1000 from t1, t3;
SET SESSION sort_buffer_size = 32 * 1024;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '32768'
SELECT SQL_NO_CACHE COUNT(*)
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
FROM t1) t;
@@ -4095,8 +4093,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
INSERT INTO `t2` VALUES ('abcdefghijk');
INSERT INTO `t2` VALUES ('asdf');
SET session sort_buffer_size=8192;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
d1
1
diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result
index 46e99151fb7..c6fd3e8efed 100644
--- a/mysql-test/r/subselect_no_mat.result
+++ b/mysql-test/r/subselect_no_mat.result
@@ -3661,8 +3661,6 @@ insert into t1 select RAND()*1000, A.a + 10*(B.a+10*(C.a+10*D.a))
from t3 A, t3 B, t3 C, t3 D where D.a<3;
insert into t2(y,z) select t1.b, RAND()*1000 from t1, t3;
SET SESSION sort_buffer_size = 32 * 1024;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '32768'
SELECT SQL_NO_CACHE COUNT(*)
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
FROM t1) t;
@@ -4098,8 +4096,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
INSERT INTO `t2` VALUES ('abcdefghijk');
INSERT INTO `t2` VALUES ('asdf');
SET session sort_buffer_size=8192;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
d1
1
diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result
index d697e2dbbc8..24770798209 100644
--- a/mysql-test/r/subselect_no_opts.result
+++ b/mysql-test/r/subselect_no_opts.result
@@ -3658,8 +3658,6 @@ insert into t1 select RAND()*1000, A.a + 10*(B.a+10*(C.a+10*D.a))
from t3 A, t3 B, t3 C, t3 D where D.a<3;
insert into t2(y,z) select t1.b, RAND()*1000 from t1, t3;
SET SESSION sort_buffer_size = 32 * 1024;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '32768'
SELECT SQL_NO_CACHE COUNT(*)
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
FROM t1) t;
@@ -4095,8 +4093,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
INSERT INTO `t2` VALUES ('abcdefghijk');
INSERT INTO `t2` VALUES ('asdf');
SET session sort_buffer_size=8192;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
d1
1
diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result
index 1eae8184dfd..e4b88c81158 100644
--- a/mysql-test/r/subselect_no_semijoin.result
+++ b/mysql-test/r/subselect_no_semijoin.result
@@ -3658,8 +3658,6 @@ insert into t1 select RAND()*1000, A.a + 10*(B.a+10*(C.a+10*D.a))
from t3 A, t3 B, t3 C, t3 D where D.a<3;
insert into t2(y,z) select t1.b, RAND()*1000 from t1, t3;
SET SESSION sort_buffer_size = 32 * 1024;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '32768'
SELECT SQL_NO_CACHE COUNT(*)
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
FROM t1) t;
@@ -4095,8 +4093,6 @@ INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
INSERT INTO `t2` VALUES ('abcdefghijk');
INSERT INTO `t2` VALUES ('asdf');
SET session sort_buffer_size=8192;
-Warnings:
-Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
d1
1
diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result
index 832c679f8d5..f1133b7fb4d 100644
--- a/mysql-test/r/variables.result
+++ b/mysql-test/r/variables.result
@@ -971,6 +971,7 @@ tmpdir #
select * from information_schema.session_variables where variable_name like 'tmpdir';
VARIABLE_NAME VARIABLE_VALUE
TMPDIR #
+set sort_buffer_size=1024*8;
select @@ssl_ca, @@ssl_capath, @@ssl_cert, @@ssl_cipher, @@ssl_key;
@@ssl_ca @@ssl_capath @@ssl_cert @@ssl_cipher @@ssl_key
# # # # #