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

Fixed LP bug #891953.

Due to this bug the function SEL_IMERGE::or_sel_tree_with_checks()
could build an inconsistent merge tree if one of the SEL_TREEs in the
resulting index merge happened to contain a full key range.
This could trigger an assertion failure.


parent fbb22ca4
...@@ -1427,4 +1427,17 @@ WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND ...@@ -1427,4 +1427,17 @@ WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND
(t1.c=0 OR t1.a=500); (t1.c=0 OR t1.a=500);
a b c a b c
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX idx(b));
INSERT INTO t1 VALUES (167,9999), (168,10000);
EXPLAIN
SELECT * FROM t1
WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY,idx NULL NULL NULL 2 Using where
SELECT * FROM t1
WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
a b
167 9999
168 10000
DROP TABLE t1;
set session optimizer_switch='index_merge_sort_intersection=default'; set session optimizer_switch='index_merge_sort_intersection=default';
...@@ -1428,5 +1428,18 @@ WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND ...@@ -1428,5 +1428,18 @@ WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND
(t1.c=0 OR t1.a=500); (t1.c=0 OR t1.a=500);
a b c a b c
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX idx(b));
INSERT INTO t1 VALUES (167,9999), (168,10000);
EXPLAIN
SELECT * FROM t1
WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,idx PRIMARY 0 NULL 1 Using where
SELECT * FROM t1
WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
a b
167 9999
168 10000
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;
...@@ -1074,6 +1074,21 @@ SELECT * FROM t1 ...@@ -1074,6 +1074,21 @@ SELECT * FROM t1
DROP TABLE t1; DROP TABLE t1;
#
# LP bug #891953: always true OR
#
CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX idx(b));
INSERT INTO t1 VALUES (167,9999), (168,10000);
EXPLAIN
SELECT * FROM t1
WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
SELECT * FROM t1
WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
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';
...@@ -1208,13 +1208,13 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param, ...@@ -1208,13 +1208,13 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param,
if (result) if (result)
{ {
result->keys_map= result_keys;
if (result_keys.is_clear_all()) if (result_keys.is_clear_all())
result->type= SEL_TREE::ALWAYS; result->type= SEL_TREE::ALWAYS;
if ((result->type == SEL_TREE::MAYBE) || if ((result->type == SEL_TREE::MAYBE) ||
(result->type == SEL_TREE::ALWAYS)) (result->type == SEL_TREE::ALWAYS))
return 1; return 1;
/* SEL_TREE::IMPOSSIBLE is impossible here */ /* SEL_TREE::IMPOSSIBLE is impossible here */
result->keys_map= result_keys;
*or_tree= result; *or_tree= result;
was_ored= TRUE; was_ored= 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