Commit 065a0044 authored by Igor Babaev's avatar Igor Babaev

Addemdum for bug #685952.

Also:
Changed the value of TIME_FOR_COMPARE_ROWID to make it the same as for MWL 21.
Changed some queries in range_vs_index_merge.test to make them generate
the same plans as earlier.
parent 99a938b1
...@@ -194,7 +194,7 @@ alter table t2 add index i321(key3, key2, key1); ...@@ -194,7 +194,7 @@ alter table t2 add index i321(key3, key2, key1);
explain select key3 from t2 where key1 = 100 or key2 = 100; explain select key3 from t2 where key1 = 100 or key2 = 100;
# index_merge vs 'index', 'index' is better. # index_merge vs 'index', 'index' is better.
explain select key3 from t2 where key1 <100 or key2 < 100; explain select key3 from t2 where key1 < 500 or key2 < 500;
# index_merge vs 'all', index_merge is better. # index_merge vs 'all', index_merge is better.
explain select key7 from t2 where key1 <100 or key2 < 100; explain select key7 from t2 where key1 <100 or key2 < 100;
......
...@@ -203,12 +203,12 @@ alter table t2 add index i321(key3, key2, key1); ...@@ -203,12 +203,12 @@ alter table t2 add index i321(key3, key2, key1);
explain select key3 from t2 where key1 = 100 or key2 = 100; explain select key3 from t2 where key1 = 100 or key2 = 100;
id select_type table type possible_keys key key_len ref rows Extra 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 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 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 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; explain select key7 from t2 where key1 <100 or key2 < 100;
id select_type table type possible_keys key key_len ref rows Extra 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 ( create table t4 (
key1a int not null, key1a int not null,
key1b int not null, key1b int not null,
......
This diff is collapsed.
...@@ -68,7 +68,7 @@ SELECT * FROM City ...@@ -68,7 +68,7 @@ SELECT * FROM City
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE (Population > 101000 AND Population < 103000); WHERE (Population > 101000 AND Population < 102000);
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
...@@ -88,7 +88,7 @@ SELECT * FROM City ...@@ -88,7 +88,7 @@ SELECT * FROM City
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F')) WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
AND (Population > 101000 AND Population < 103000); AND (Population > 101000 AND Population < 102000);
# The following 4 queries check that the plans # The following 4 queries check that the plans
# for the previous 2 plans are valid # for the previous 2 plans are valid
...@@ -103,11 +103,11 @@ SELECT * FROM City ...@@ -103,11 +103,11 @@ SELECT * FROM City
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F')) WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
AND (Population > 101000 AND Population < 103000); AND (Population > 101000 AND Population < 102000);
SELECT * FROM City SELECT * FROM City
WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F')) WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'F'))
AND (Population > 101000 AND Population < 103000); AND (Population > 101000 AND Population < 102000);
# The output of the next 7 commands tells us about selectivities # The output of the next 7 commands tells us about selectivities
# of the conditions utilized in 4 queries following after them # of the conditions utilized in 4 queries following after them
...@@ -197,11 +197,11 @@ SELECT * FROM City ...@@ -197,11 +197,11 @@ SELECT * FROM City
# of the conditions utilized in 3 queries following after them # of the conditions utilized in 3 queries following after them
EXPLAIN EXPLAIN
SELECT * FROM City WHERE (ID < 50) OR (ID BETWEEN 100 AND 110); SELECT * FROM City WHERE (ID < 10) OR (ID BETWEEN 100 AND 110);
EXPLAIN EXPLAIN
SELECT * FROM City WHERE (ID < 200) OR (ID BETWEEN 300 AND 600); SELECT * FROM City WHERE (ID < 200) OR (ID BETWEEN 100 AND 200);
EXPLAIN EXPLAIN
SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1800); SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1500);
EXPLAIN EXPLAIN
SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG'; SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG';
EXPLAIN EXPLAIN
...@@ -219,20 +219,20 @@ SELECT * FROM City WHERE Name LIKE 'Ha%' OR Name LIKE 'Pa%' ; ...@@ -219,20 +219,20 @@ SELECT * FROM City WHERE Name LIKE 'Ha%' OR Name LIKE 'Pa%' ;
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ((ID < 50) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 100 AND 110) AND OR ((ID BETWEEN 100 AND 110) AND
(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 900 AND 1800) AND OR ((ID BETWEEN 900 AND 1500) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ((ID < 600) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 300 AND 600) AND OR ((ID BETWEEN 100 AND 200) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
...@@ -240,33 +240,33 @@ SELECT * FROM City ...@@ -240,33 +240,33 @@ SELECT * FROM City
# for the previous 3 plans are valid # for the previous 3 plans are valid
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE ((ID < 50) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 100 AND 110) AND OR ((ID BETWEEN 100 AND 110) AND
(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
SELECT * FROM City SELECT * FROM City
WHERE ((ID < 50) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 100 AND 110) AND OR ((ID BETWEEN 100 AND 110) AND
(Name LIKE 'P%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'P%' OR (Population > 103000 AND Population < 104000)));
SELECT * FROM City USE INDEX() SELECT * FROM City USE INDEX()
WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 900 AND 1800) AND OR ((ID BETWEEN 900 AND 1500) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
SELECT * FROM City SELECT * FROM City
WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 900 AND 1800) AND OR ((ID BETWEEN 900 AND 1500) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 300 AND 600) AND OR ((ID BETWEEN 100 AND 200) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
SELECT * FROM City SELECT * FROM City
WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 300 AND 600) AND OR ((ID BETWEEN 100 AND 200) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
...@@ -353,7 +353,7 @@ ANALYZE TABLE City; ...@@ -353,7 +353,7 @@ ANALYZE TABLE City;
--enable_result_log --enable_result_log
--enable_query_log --enable_query_log
# The output of the next 4 commands tells us about selectivities # The output of the next 5 commands tells us about selectivities
# of the conditions utilized in 2 queries following after them # of the conditions utilized in 2 queries following after them
EXPLAIN EXPLAIN
...@@ -364,6 +364,8 @@ EXPLAIN ...@@ -364,6 +364,8 @@ EXPLAIN
SELECT * FROM City WHERE (Population > 101000 AND Population < 103000); SELECT * FROM City WHERE (Population > 101000 AND Population < 103000);
EXPLAIN EXPLAIN
SELECT * FROM City WHERE Country='USA'; SELECT * FROM City WHERE Country='USA';
EXPLAIN
SELECT * FROM City WHERE Country='FIN';
# The pattern of the WHERE condition used in the following 3 queries is # The pattern of the WHERE condition used in the following 3 queries is
# (range(key1_p2) OR (range(key2)) AND key1_p1=c # (range(key1_p2) OR (range(key2)) AND key1_p1=c
...@@ -380,7 +382,7 @@ SELECT * FROM City ...@@ -380,7 +382,7 @@ SELECT * FROM City
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%') WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
AND Country='USA'; AND Country='FIN';
# The following 4 queries check that the plans # The following 4 queries check that the plans
# for the previous 2 plans are valid # for the previous 2 plans are valid
...@@ -395,11 +397,11 @@ SELECT * FROM City USE INDEX () ...@@ -395,11 +397,11 @@ SELECT * FROM City USE INDEX ()
SELECT * FROM City SELECT * FROM City
WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%') WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
AND Country='USA'; AND Country='FIN';
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%') WHERE ((Population > 101000 AND Population < 103000) OR Name LIKE 'P%')
AND Country='USA'; AND Country='FIN';
CREATE INDEX CountryName ON City(Country,Name); CREATE INDEX CountryName ON City(Country,Name);
...@@ -412,12 +414,14 @@ ANALYZE TABLE City; ...@@ -412,12 +414,14 @@ ANALYZE TABLE City;
--enable_result_log --enable_result_log
--enable_query_log --enable_query_log
# The output of the next 11 commands tells us about selectivities # The output of the next 12 commands tells us about selectivities
# of the conditions utilized in 3 queries following after them # of the conditions utilized in 3 queries following after them
EXPLAIN EXPLAIN
SELECT * FROM City WHERE Country='USA'; SELECT * FROM City WHERE Country='USA';
EXPLAIN EXPLAIN
SELECT * FROM City WHERE Country='FIN';
EXPLAIN
SELECT * FROM City WHERE Country='BRA'; SELECT * FROM City WHERE Country='BRA';
EXPLAIN EXPLAIN
SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800; SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800;
...@@ -464,7 +468,7 @@ SELECT * FROM City ...@@ -464,7 +468,7 @@ SELECT * FROM City
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ((Population > 101000 AND Population < 110000) OR WHERE ((Population > 101000 AND Population < 110000) OR
ID BETWEEN 3500 AND 3800) AND Country='USA' ID BETWEEN 3500 AND 3800) AND Country='FIN'
AND (Name BETWEEN 'P' AND 'T' OR ID BETWEEN 4000 AND 4300); AND (Name BETWEEN 'P' AND 'T' OR ID BETWEEN 4000 AND 4300);
# The following 6 queries check that the plans # The following 6 queries check that the plans
...@@ -492,12 +496,12 @@ SELECT * FROM City ...@@ -492,12 +496,12 @@ SELECT * FROM City
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE ((Population > 101000 AND Population < 102000) OR WHERE ((Population > 101000 AND Population < 102000) OR
ID BETWEEN 3790 AND 3800) AND Country='USA' ID BETWEEN 3790 AND 3800) AND Country='FIN'
AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035); AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
SELECT * FROM City SELECT * FROM City
WHERE ((Population > 101000 AND Population < 102000) OR WHERE ((Population > 101000 AND Population < 102000) OR
ID BETWEEN 3790 AND 3800) AND Country='USA' ID BETWEEN 3790 AND 3800) AND Country='FIN'
AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035); AND (Name LIKE 'Pa%' OR ID BETWEEN 4025 AND 4035);
......
...@@ -338,7 +338,7 @@ class Default_object_creation_ctx : public Object_creation_ctx ...@@ -338,7 +338,7 @@ class Default_object_creation_ctx : public Object_creation_ctx
Number of comparisons of table rowids equivalent to reading one row from a Number of comparisons of table rowids equivalent to reading one row from a
table. table.
*/ */
#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2) #define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*100)
/* /*
For sequential disk seeks the cost formula is: For sequential disk seeks the cost formula is:
......
...@@ -1093,7 +1093,7 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param, ...@@ -1093,7 +1093,7 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param,
{ {
bool must_be_ored= sel_trees_must_be_ored(param, *or_tree, tree, bool must_be_ored= sel_trees_must_be_ored(param, *or_tree, tree,
ored_keys); ored_keys);
if (must_be_ored == is_first_check_pass) if (must_be_ored || !is_first_check_pass)
{ {
result_keys.clear_all(); result_keys.clear_all();
result= *or_tree; result= *or_tree;
...@@ -1138,8 +1138,7 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param, ...@@ -1138,8 +1138,7 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param,
*or_tree= result; *or_tree= result;
if (is_first_check_pass) if (is_first_check_pass)
return 0; return 0;
else was_ored= TRUE;
was_ored= TRUE;
} }
} }
if (was_ored) if (was_ored)
......
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