Commit 3bf6e7ba authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #684117.

A crash may happenin the cases when the range optimizer tried to OR
two index merge such that the second one contained less range trees
than the first one.
The bug was introduced by the patch of MWL#24: 
"index_merge: fair choice between index_merge union and range access".
parent ae8a6d03
...@@ -1314,4 +1314,16 @@ WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR ...@@ -1314,4 +1314,16 @@ WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
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 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 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; 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;
set session optimizer_switch='index_merge_sort_intersection=default'; set session optimizer_switch='index_merge_sort_intersection=default';
...@@ -1315,5 +1315,17 @@ WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR ...@@ -1315,5 +1315,17 @@ WHERE c = 'i' OR b IN ( 'Arkansas' , 'd' , 'pdib' , 'can' ) OR
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 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 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; 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;
set session optimizer_switch='index_merge_sort_intersection=default'; set session optimizer_switch='index_merge_sort_intersection=default';
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -925,6 +925,22 @@ SELECT COUNT(*) FROM t1 ...@@ -925,6 +925,22 @@ SELECT COUNT(*) FROM t1
DROP TABLE t1; DROP TABLE t1;
#
# Bug #637978: ORing of two index merge that caused a crash
#
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);
DROP TABLE t1;
#the following command must be the last one in the file #the following command must be the last one in the file
set session optimizer_switch='index_merge_sort_intersection=default'; set session optimizer_switch='index_merge_sort_intersection=default';
...@@ -1195,7 +1195,8 @@ int SEL_IMERGE::or_sel_imerge_with_checks(RANGE_OPT_PARAM *param, ...@@ -1195,7 +1195,8 @@ int SEL_IMERGE::or_sel_imerge_with_checks(RANGE_OPT_PARAM *param,
{ {
*is_last_check_pass= TRUE; *is_last_check_pass= TRUE;
SEL_TREE** tree= imerge->trees; SEL_TREE** tree= imerge->trees;
for (uint i= 0; i < n_trees; i++, tree++) SEL_TREE** tree_end= imerge->trees_next;
for ( ; tree < tree_end; tree++)
{ {
uint rc; uint rc;
bool is_last= TRUE; bool is_last= TRUE;
......
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