Commit 6f2db629 authored by Igor Babaev's avatar Igor Babaev

Post-review fixes.

parent 65af63b0
This diff is collapsed.
......@@ -84,98 +84,77 @@ id select_type table type possible_keys key key_len ref rows Extra
SELECT * FROM City USE INDEX ()
WHERE Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population
71 Córdoba ARG 1157507
151 Chittagong BGD 1392860
212 Curitiba BRA 1584232
608 Cairo EGY 6789479
712 Cape Town ZAF 2352121
926 Conakry GIN 1090610
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
SELECT * FROM City
WHERE Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population
71 Córdoba ARG 1157507
151 Chittagong BGD 1392860
212 Curitiba BRA 1584232
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
131 Melbourne AUS 2865329
653 Madrid ESP 2879052
766 Manila PHL 1581082
942 Medan IDN 1843919
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
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
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
SELECT * FROM City USE INDEX ()
WHERE Name LIKE 'M%' AND Population > 300000;
ID Name Country Population
77 Mar del Plata ARG 512880
80 Merlo ARG 463846
83 Moreno ARG 356993
87 Morón ARG 349246
131 Melbourne AUS 2865329
215 Manaus BRA 1255049
223 Maceió BRA 786288
250 Mauá BRA 375055
256 Moji das Cruzes BRA 339194
462 Manchester GBR 430000
653 Madrid ESP 2879052
658 Málaga ESP 530553
661 Murcia ESP 353504
766 Manila PHL 1581082
778 Makati PHL 444867
781 Marikina PHL 391170
783 Muntinlupa PHL 379310
786 Malabon PHL 338855
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 > 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
......@@ -188,6 +167,8 @@ ID Name Country Population
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
......@@ -196,12 +177,14 @@ ID Name Country Population
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
......@@ -236,37 +219,33 @@ ID Name Country Population
3834 Mesa USA 396375
3837 Minneapolis USA 382618
3839 Miami USA 362470
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 300000;
ID Name Country Population
77 Mar del Plata ARG 512880
80 Merlo ARG 463846
83 Moreno ARG 356993
87 Morón ARG 349246
131 Melbourne AUS 2865329
215 Manaus BRA 1255049
223 Maceió BRA 786288
250 Mauá BRA 375055
256 Moji das Cruzes BRA 339194
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
......@@ -279,6 +258,8 @@ ID Name Country Population
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
......@@ -287,12 +268,14 @@ ID Name Country Population
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
......@@ -327,6 +310,23 @@ ID Name Country Population
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 > 5000000;
ID Name Country Population
......@@ -487,30 +487,30 @@ 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
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 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
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 'L%';
ID Name Country Population
......@@ -752,23 +752,23 @@ id select_type table type possible_keys key key_len ref rows Extra
SELECT * FROM City WHERE
Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population
71 Córdoba ARG 1157507
151 Chittagong BGD 1392860
212 Curitiba BRA 1584232
608 Cairo EGY 6789479
712 Cape Town ZAF 2352121
926 Conakry GIN 1090610
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
......@@ -918,10 +918,9 @@ ID Name Country Population
2698 Maputo MOZ 1018938
2710 Rangoon (Yangon) MMR 3361700
SELECT * FROM City
WHERE Country LIKE 'M%' AND Population > 700000;
WHERE Country LIKE 'M%' AND Population > 1000000;
ID Name Country Population
2464 Kuala Lumpur MYS 1297526
2482 Bamako MLI 809552
2485 Casablanca MAR 2940623
2515 Ciudad de México MEX 8591309
2516 Guadalajara MEX 1647720
......@@ -933,17 +932,8 @@ ID Name Country Population
2522 León MEX 1133576
2523 Monterrey MEX 1108499
2524 Zapopan MEX 1002239
2525 Naucalpan de Juárez MEX 857511
2526 Mexicali MEX 764902
2527 Culiacán MEX 744859
2528 Acapulco de Juárez MEX 721011
2529 Tlalnepantla de Baz MEX 720755
2530 Mérida MEX 703324
2690 Chisinau MDA 719900
2696 Ulan Bator MNG 773700
2698 Maputo MOZ 1018938
2710 Rangoon (Yangon) MMR 3361700
2711 Mandalay MMR 885300
SELECT * FROM City USE INDEX ()
WHERE Country='CHN' AND Population > 1500000;
ID Name Country Population
......
......@@ -1506,7 +1506,7 @@ index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_inter
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_merge_sort_intersection=on
index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_merge_sort_intersection=off
set optimizer_switch=4;
ERROR 42000: Variable 'optimizer_switch' can't be set to the value of '4'
set optimizer_switch=NULL;
......@@ -1533,21 +1533,21 @@ 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_merge_sort_intersection=on
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
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_merge_sort_intersection=on
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
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_merge_sort_intersection=on
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
#
# 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_merge_sort_intersection=on
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int, b int, c int, filler char(100),
......@@ -1657,6 +1657,6 @@ id select_type table type possible_keys key key_len ref rows Extra
set optimizer_switch=default;
show variables like 'optimizer_switch';
Variable_name Value
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=on
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off
drop table t0, t1;
set optimizer_switch= @optimizer_switch_save;
......@@ -75,24 +75,24 @@ SELECT * FROM City
# the previous 4 plans are valid and return
# the correct results when executed
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE Name LIKE 'C%' AND Population > 1000000;
--sorted_result
SELECT * FROM City
WHERE Name LIKE 'C%' AND Population > 1000000;
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE Name LIKE 'M%' AND Population > 1500000;
--sorted_result
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 1500000;
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE Name LIKE 'M%' AND Population > 300000;
--sorted_result
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 300000;
......@@ -223,10 +223,10 @@ SELECT * FROM City USE INDEX ()
SELECT * FROM City
WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
--sorted_result
SELECT * FROM City
WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
......@@ -237,20 +237,20 @@ SELECT * FROM City USE INDEX ()
SELECT * FROM City
WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'L%';
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE ID BETWEEN 3701 AND 4000 AND Population > 700000
AND Country BETWEEN 'S' AND 'Z';
--sorted_result
SELECT * FROM City
WHERE ID BETWEEN 3701 AND 4000 AND Population > 700000
AND Country BETWEEN 'S' AND 'Z';
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
AND Country BETWEEN 'S' AND 'Z' ;
--sorted_result
SELECT * FROM City
WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
AND Country BETWEEN 'S' AND 'Z' ;
......@@ -293,7 +293,7 @@ SELECT * FROM City
#Yet the query themselves return the correct results in this case as well
--sorted_result
SELECT * FROM City WHERE
Name LIKE 'C%' AND Population > 1000000;
......@@ -310,7 +310,7 @@ SELECT * FROM City
SELECT * FROM City
WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%';
--sorted_result
SELECT * FROM City
WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
AND Country BETWEEN 'S' AND 'Z';
......@@ -353,17 +353,17 @@ SELECT * FROM City
# Check that the previous 3 plans return the right results when executed
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE Country LIKE 'M%' AND Population > 1000000;
--sorted_result
SELECT * FROM City
WHERE Country LIKE 'M%' AND Population > 700000;
WHERE Country LIKE 'M%' AND Population > 1000000;
--sorted_result
SELECT * FROM City USE INDEX ()
WHERE Country='CHN' AND Population > 1500000;
--sorted_result
SELECT * FROM City
WHERE Country='CHN' AND Population > 1500000;
......
......@@ -559,14 +559,12 @@ class Default_object_creation_ctx : public Object_creation_ctx
# define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \
OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \
OPTIMIZER_SWITCH_INDEX_MERGE_SORT_INTERSECT)
OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT)
#else
# define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \
OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \
OPTIMIZER_SWITCH_INDEX_MERGE_SORT_INTERSECT | \
OPTIMIZER_SWITCH_TABLE_ELIMINATION)
#endif
......
......@@ -433,7 +433,7 @@ static const char *sql_mode_str= "OFF";
static const char *optimizer_switch_str="index_merge=on,index_merge_union=on,"
"index_merge_sort_union=on,"
"index_merge_intersection=on,"
"index_merge_sort_intersection=on"
"index_merge_sort_intersection=off"
#ifndef DBUG_OFF
",table_elimination=on";
#else
......
......@@ -4863,6 +4863,17 @@ ha_rows records_in_index_intersect_extension(PARTIAL_INDEX_INTERSECT_INFO *curr,
when searching for the best intersection plan. It also allocates
memory to store the most cheap index intersection.
NOTES
When selecting candidates for index intersection we always take only
one representative out of any set of indexes that share the same range
conditions. These indexes always have the same prefixes and the
components of this prefixes are exactly those used in these range
conditions.
Range conditions over clustered primary key (cpk) is always used only
as the condition that filters out some rowids retrieved by the scans
for secondary indexes. The cpk index will be handled in special way by
the function that search for the best index intersection.
RETURN
FALSE in the case of success
TRUE otherwise
......@@ -4935,7 +4946,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
if (*index_scan == cpk_scan)
continue;
if (cpk_scan && cpk_scan->used_key_parts == used_key_parts &&
if (cpk_scan && cpk_scan->used_key_parts >= used_key_parts &&
same_index_prefix(cpk_scan->key_info, key_info, used_key_parts))
continue;
......@@ -5012,7 +5023,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
curr.intersect_fields= &cpk_scan->used_fields;
curr.records= cpk_scan->records;
curr.length= 1;
for (scan_ptr=selected_index_scans, i= 0; *scan_ptr; scan_ptr++, i++)
for (scan_ptr=selected_index_scans; *scan_ptr; scan_ptr++)
{
ha_rows scan_records= (*scan_ptr)->records;
ha_rows records= records_in_index_intersect_extension(&curr, *scan_ptr);
......@@ -5022,7 +5033,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
}
else
{
for (scan_ptr=selected_index_scans, i= 0; *scan_ptr; scan_ptr++, i++)
for (scan_ptr=selected_index_scans; *scan_ptr; scan_ptr++)
(*scan_ptr)->filtered_out= 0;
}
......@@ -5250,6 +5261,13 @@ ha_rows records_in_index_intersect_extension(PARTIAL_INDEX_INTERSECT_INFO *curr,
}
/*
Estimate the cost a binary search within disjoint cpk range intervals
Number of comparisons to check whether a cpk value satisfies
the cpk range condition = log2(cpk_scan->range_count).
*/
static inline
double get_cpk_filter_cost(ha_rows filtered_records,
INDEX_SCAN_INFO *cpk_scan,
......@@ -5412,6 +5430,7 @@ void find_index_intersect_best_extension(PARTIAL_INDEX_INTERSECT_INFO *curr)
common_info->best_length= curr->length;
common_info->best_records= curr->records;
common_info->filtered_scans= curr->filtered_scans;
/* common_info->best_uses_cpk <=> at least one scan uses a cpk filter */
common_info->best_uses_cpk= !curr->filtered_scans.is_clear_all();
uint sz= sizeof(INDEX_SCAN_INFO *) * curr->length;
memcpy(common_info->best_intersect, common_info->search_scans, sz);
......
......@@ -6376,8 +6376,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (tab->type == JT_REF && tab->quick &&
(((uint) tab->ref.key == tab->quick->index &&
tab->ref.key_length < tab->quick->max_used_key_length) ||
(!tab->table->intersect_keys.is_clear_all() &&
tab->table->intersect_keys.is_set(tab->ref.key))))
tab->table->intersect_keys.is_set(tab->ref.key)))
{
/* Range uses longer key; Use this instead of ref on key */
tab->type=JT_ALL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment