From 357331af8a450dfc975575e99c640b8f6893360b Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 20 Mar 2012 17:03:28 -0700 Subject: [PATCH] Fixed LP bug #954262. This bug in the constructor SEL_IMERGE::SEL_IMERGE could cause huge excessive memory requests. --- mysql-test/r/range_vs_index_merge.result | 176 ++++++++++++++++++ .../r/range_vs_index_merge_innodb.result | 176 ++++++++++++++++++ mysql-test/t/range_vs_index_merge.test | 56 ++++++ sql/opt_range.cc | 2 +- 4 files changed, 409 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/range_vs_index_merge.result b/mysql-test/r/range_vs_index_merge.result index f8738457dd9..faaa6d2429e 100644 --- a/mysql-test/r/range_vs_index_merge.result +++ b/mysql-test/r/range_vs_index_merge.result @@ -1045,6 +1045,182 @@ ID Name Country Population 4030 Sandy USA 101853 4031 Athens-Clarke County USA 101489 4032 Cambridge USA 101355 +set @save_optimizer_switch=@@optimizer_switch; +CREATE INDEX CityName on City(Name); +EXPLAIN SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE City index_merge Country,CountryPopulation,CountryName,CityName CountryName,CityName 38,35 NULL 28 Using sort_union(CountryName,CityName); Using where +SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +Name Country Population +Addis Abeba ETH 2495000 +Manila PHL 1581082 +Jakarta IDN 9604900 +Delhi IND 7206704 +Bangalore IND 2660088 +Teheran IRN 6758845 +Roma ITA 2643581 +Venezia ITA 277305 +Tokyo JPN 7980230 +Toronto CAN 688275 +Vancouver CAN 514008 +Peking CHN 7472000 +Seoul KOR 9981619 +Kaunas LTU 412639 +Rabat MAR 623457 +Tijuana MEX 1212232 +Lagos NGA 1518000 +Paris FRA 2125246 +Dresden DEU 476668 +Dakar SEN 785071 +Basel CHE 166700 +Praha CZE 1181126 +Ankara TUR 3038159 +Lugansk UKR 469000 +Caracas VEN 1975294 +Samara RUS 1156100 +Seattle USA 563374 +set optimizer_switch='index_merge=off'; +EXPLAIN SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CountryName 38 NULL 29 Using index condition; Using where +SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +Name Country Population +Toronto CAN 688275 +Vancouver CAN 514008 +Basel CHE 166700 +Peking CHN 7472000 +Praha CZE 1181126 +Dresden DEU 476668 +Addis Abeba ETH 2495000 +Paris FRA 2125246 +Jakarta IDN 9604900 +Bangalore IND 2660088 +Delhi IND 7206704 +Teheran IRN 6758845 +Roma ITA 2643581 +Venezia ITA 277305 +Tokyo JPN 7980230 +Seoul KOR 9981619 +Kaunas LTU 412639 +Rabat MAR 623457 +Tijuana MEX 1212232 +Lagos NGA 1518000 +Manila PHL 1581082 +Samara RUS 1156100 +Dakar SEN 785071 +Ankara TUR 3038159 +Lugansk UKR 469000 +Seattle USA 563374 +Caracas VEN 1975294 +set optimizer_switch=@save_optimizer_switch; DROP DATABASE world; use test; CREATE TABLE t1 ( diff --git a/mysql-test/r/range_vs_index_merge_innodb.result b/mysql-test/r/range_vs_index_merge_innodb.result index c42f80f0e85..df3a2af0753 100644 --- a/mysql-test/r/range_vs_index_merge_innodb.result +++ b/mysql-test/r/range_vs_index_merge_innodb.result @@ -1046,6 +1046,182 @@ ID Name Country Population 4030 Sandy USA 101853 4031 Athens-Clarke County USA 101489 4032 Cambridge USA 101355 +set @save_optimizer_switch=@@optimizer_switch; +CREATE INDEX CityName on City(Name); +EXPLAIN SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CountryName 38 NULL 27 Using index condition; Using where +SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +Name Country Population +Toronto CAN 688275 +Vancouver CAN 514008 +Basel CHE 166700 +Peking CHN 7472000 +Praha CZE 1181126 +Dresden DEU 476668 +Addis Abeba ETH 2495000 +Paris FRA 2125246 +Jakarta IDN 9604900 +Bangalore IND 2660088 +Delhi IND 7206704 +Teheran IRN 6758845 +Roma ITA 2643581 +Venezia ITA 277305 +Tokyo JPN 7980230 +Seoul KOR 9981619 +Kaunas LTU 412639 +Rabat MAR 623457 +Tijuana MEX 1212232 +Lagos NGA 1518000 +Manila PHL 1581082 +Samara RUS 1156100 +Dakar SEN 785071 +Ankara TUR 3038159 +Lugansk UKR 469000 +Seattle USA 563374 +Caracas VEN 1975294 +set optimizer_switch='index_merge=off'; +EXPLAIN SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CountryName 38 NULL 27 Using index condition; Using where +SELECT Name, Country, Population FROM City WHERE +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); +Name Country Population +Toronto CAN 688275 +Vancouver CAN 514008 +Basel CHE 166700 +Peking CHN 7472000 +Praha CZE 1181126 +Dresden DEU 476668 +Addis Abeba ETH 2495000 +Paris FRA 2125246 +Jakarta IDN 9604900 +Bangalore IND 2660088 +Delhi IND 7206704 +Teheran IRN 6758845 +Roma ITA 2643581 +Venezia ITA 277305 +Tokyo JPN 7980230 +Seoul KOR 9981619 +Kaunas LTU 412639 +Rabat MAR 623457 +Tijuana MEX 1212232 +Lagos NGA 1518000 +Manila PHL 1581082 +Samara RUS 1156100 +Dakar SEN 785071 +Ankara TUR 3038159 +Lugansk UKR 469000 +Seattle USA 563374 +Caracas VEN 1975294 +set optimizer_switch=@save_optimizer_switch; DROP DATABASE world; use test; CREATE TABLE t1 ( diff --git a/mysql-test/t/range_vs_index_merge.test b/mysql-test/t/range_vs_index_merge.test index de7e6a0838c..613a7cf5760 100755 --- a/mysql-test/t/range_vs_index_merge.test +++ b/mysql-test/t/range_vs_index_merge.test @@ -621,6 +621,62 @@ SELECT * FROM City (Population BETWEEN 101000 AND 102000 OR Name LIKE 'Pa%'); +# +# LP bug #954262: index merge oover long disjunction in WHERE +# + +set @save_optimizer_switch=@@optimizer_switch; + +CREATE INDEX CityName on City(Name); + +let $cond = +(Name='Manila' AND Country='PHL') OR +(Name='Addis Abeba' AND Country='ETH') OR +(Name='Jakarta' AND Country='IDN') OR +(Name='Bangalore' AND Country='IND') OR +(Name='Teheran' AND Country='IRN') OR +(Name='Roma' AND Country='ITA') OR +(Name='Delhi' AND Country='IND') OR +(Name='Venezia' AND Country='ITA') OR +(Name='Tokyo' AND Country='JPN') OR +(Name='Toronto' AND Country='CAN') OR +(Name='Peking' AND Country='CHN') OR +(Name='Lagos' AND Country='NGA') OR +(Name='Tijuana' AND Country='MEX') OR +(Name='Rabat' AND Country='MAR') OR +(Name='Seoul' AND Country='KOR') OR +(Name='Vancouver' AND Country='CAN') OR +(Name='Kaunas' AND Country='LTU') OR +(Name='Paris' AND Country='FRA') OR +(Name='Dakar' AND Country='SEN') OR +(Name='Basel' AND Country='CHE') OR +(Name='Praha' AND Country='CZE') OR +(Name='Ankara' AND Country='TUR') OR +(Name='Dresden' AND Country='DEU') OR +(Name='Lugansk' AND Country='UKR') OR +(Name='Caracas' AND Country='VEN') OR +(Name='Samara' AND Country='RUS') OR +(Name='Seattle' AND Country='USA'); + +eval +EXPLAIN SELECT Name, Country, Population FROM City WHERE +$cond; +eval +SELECT Name, Country, Population FROM City WHERE +$cond; + +set optimizer_switch='index_merge=off'; + +eval +EXPLAIN SELECT Name, Country, Population FROM City WHERE +$cond; +eval +SELECT Name, Country, Population FROM City WHERE +$cond; + +set optimizer_switch=@save_optimizer_switch; + + DROP DATABASE world; use test; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index e0841d3a696..4b973b8500e 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1369,7 +1369,7 @@ SEL_IMERGE::SEL_IMERGE(SEL_IMERGE *arg, uint cnt, for (SEL_TREE **tree = trees, **arg_tree= arg->trees; tree < trees_next; tree++, arg_tree++) { - if (!(*tree= new SEL_TREE(*arg_tree, FALSE, param))) + if (!(*tree= new SEL_TREE(*arg_tree, TRUE, param))) goto mem_err; }