Commit ab411f8f authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #794909.

The function generate_derived_keys did not take into account the fact
that the last element in the array of keyuses could be just a barrier
element. In some cases it could lead to a crash of the server.

Also fixed a couple of other bugs in generate_derived_keys: the inner 
loop in the body of if this function did not change the cycle variables
properly.
parent 7f345153
......@@ -568,3 +568,24 @@ TODO: Add test with 64 tables mergeable view to test fall back to
materialization on tables > MAX_TABLES merge
drop table t1,t2;
drop view v1,v2,v3,v4,v6,v7;
#
# LP bug #794909: crash when defining possible keys for
# a materialized view/derived_table
#
CREATE TABLE t1 (f1 int) ;
INSERT INTO t1 VALUES (149), (150), (224), (29);
CREATE TABLE t2 (f1 int, KEY (f1));
INSERT INTO t2 VALUES (149), (NULL), (224);
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
EXPLAIN
SELECT * FROM v1 JOIN t2 ON v1.f1 = t2.f1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 index f1 f1 5 NULL 3 Using where; Using index
1 PRIMARY <derived2> ref key0 key0 5 test.t2.f1 2
2 DERIVED t1 ALL NULL NULL NULL NULL 4
SELECT * FROM v1 JOIN t2 ON v1.f1 = t2.f1;
f1 f1
149 149
224 224
DROP VIEW v1;
DROP TABLE t1,t2;
......@@ -215,3 +215,23 @@ select * from t1 join (select * from t2 group by f2) tt on t1.f1=tt.f2 join t1 x
--echo materialization on tables > MAX_TABLES merge
drop table t1,t2;
drop view v1,v2,v3,v4,v6,v7;
--echo #
--echo # LP bug #794909: crash when defining possible keys for
--echo # a materialized view/derived_table
--echo #
CREATE TABLE t1 (f1 int) ;
INSERT INTO t1 VALUES (149), (150), (224), (29);
CREATE TABLE t2 (f1 int, KEY (f1));
INSERT INTO t2 VALUES (149), (NULL), (224);
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
EXPLAIN
SELECT * FROM v1 JOIN t2 ON v1.f1 = t2.f1;
SELECT * FROM v1 JOIN t2 ON v1.f1 = t2.f1;
DROP VIEW v1;
DROP TABLE t1,t2;
......@@ -8328,6 +8328,8 @@ bool generate_derived_keys(DYNAMIC_ARRAY *keyuse_array)
TABLE *prev_table= 0;
for (uint i= 0; i < elements; i++, keyuse++)
{
if (!keyuse->table)
break;
KEYUSE *first_table_keyuse= NULL;
table_map last_used_tables= 0;
uint count= 0;
......@@ -8353,11 +8355,13 @@ bool generate_derived_keys(DYNAMIC_ARRAY *keyuse_array)
}
count++;
keyuse++;
if (keyuse->table != prev_table &&
generate_derived_keys_for_table(first_table_keyuse, count, ++keys))
return TRUE;
if (++i == elements)
break;
if (keyuse->table != prev_table)
{
if (generate_derived_keys_for_table(first_table_keyuse, count, ++keys))
return TRUE;
keyuse--;
derived= NULL;
}
}
}
return FALSE;
......
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