Commit bd62c823 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #803410.

Due to this bug in the function generate_derived_keys_for_table some
key definitions to access materialized derived tables or materialized
views were constructed with invalid info for their key parts.
This could make the server crash when it optimized queries using 
materialized derived tables or materialized views. 
parent a853c7dd
......@@ -703,3 +703,25 @@ a
NULL
DROP VIEW v1;
DROP TABLE t1,t2,t3;
#
# LP bug #803410: materialized view/dt accessed by two-component key
#
CREATE TABLE t1 (a varchar(1));
INSERT INTO t1 VALUES ('c');
CREATE TABLE t2 (a varchar(1) , KEY (a)) ;
INSERT INTO t2 VALUES ('c'), (NULL), ('r');
CREATE TABLE t3 (a varchar(1), b varchar(1));
INSERT INTO t3 VALUES ('e', 'c'), ('c', 'c'), ('c', 'r');
CREATE VIEW v1 AS SELECT a, MIN(b) AS b FROM t3 GROUP BY a;
EXPLAIN
SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 ref a a 4 const 1 Using index
1 PRIMARY <derived2> ref key1 key1 10 test.t1.a,test.t1.a 2 Using where
2 DERIVED t3 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort
SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b;
a a a b
c c c c
DROP VIEW v1;
DROP TABLE t1,t2,t3;
......@@ -322,3 +322,24 @@ SELECT t.a FROM t1 LEFT JOIN
DROP VIEW v1;
DROP TABLE t1,t2,t3;
--echo #
--echo # LP bug #803410: materialized view/dt accessed by two-component key
--echo #
CREATE TABLE t1 (a varchar(1));
INSERT INTO t1 VALUES ('c');
CREATE TABLE t2 (a varchar(1) , KEY (a)) ;
INSERT INTO t2 VALUES ('c'), (NULL), ('r');
CREATE TABLE t3 (a varchar(1), b varchar(1));
INSERT INTO t3 VALUES ('e', 'c'), ('c', 'c'), ('c', 'r');
CREATE VIEW v1 AS SELECT a, MIN(b) AS b FROM t3 GROUP BY a;
EXPLAIN
SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b;
SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b;
DROP VIEW v1;
DROP TABLE t1,t2,t3;
......@@ -8293,6 +8293,7 @@ bool generate_derived_keys_for_table(KEYUSE *keyuse, uint count, uint keys)
first_keyuse= keyuse;
keyno++;
parts= 0;
prev_part= (uint) (-1);
}
else if (keyuse->keypart != prev_part)
{
......
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