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".
This commit is contained in:
Igor Babaev 2010-12-04 19:19:55 -08:00
parent 25704af0b2
commit bfb7727526
4 changed files with 42 additions and 1 deletions

View file

@ -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
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;
set session optimizer_switch='index_merge_sort_intersection=default';

View file

@ -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
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;
set session optimizer_switch='index_merge_sort_intersection=default';
SET SESSION STORAGE_ENGINE=DEFAULT;

View file

@ -925,6 +925,22 @@ SELECT COUNT(*) FROM 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
set session optimizer_switch='index_merge_sort_intersection=default';

View file

@ -1195,7 +1195,8 @@ int SEL_IMERGE::or_sel_imerge_with_checks(RANGE_OPT_PARAM *param,
{
*is_last_check_pass= TRUE;
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;
bool is_last= TRUE;