mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 04:22:27 +01:00
Fixed LP bug #878199.
The function JOIN::drop_unused_derived_keys could erroneously set the value of REF::key to 0 for a joined materialized view/derived table in the case when no REF access to the table was used by the query execution plan. This could cause a crash of the server.
This commit is contained in:
parent
0e4d88f1b2
commit
e7a7e2a036
3 changed files with 46 additions and 1 deletions
|
@ -1534,4 +1534,26 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1,t2;
|
||||
#
|
||||
# LP bug #878199: join of two materialized views
|
||||
#
|
||||
CREATE TABLE t1 (a int, b varchar(1)) ;
|
||||
INSERT INTO t1 VALUES (7,'c'), (3,'h'), (7,'c');
|
||||
CREATE TABLE t2 (b varchar(1)) ;
|
||||
INSERT INTO t2 VALUES ('p'), ('c'), ('j'), ('c'), ('p');
|
||||
CREATE VIEW v1 AS SELECT * FROM t1 GROUP BY a,b;
|
||||
CREATE VIEW v2 AS SELECT * FROM t2 GROUP BY b;
|
||||
SET SESSION optimizer_switch = 'derived_with_keys=on';
|
||||
SELECT v1.a FROM v1,v2 WHERE v2.b = v1.b ORDER BY 1;
|
||||
a
|
||||
7
|
||||
EXPLAIN
|
||||
SELECT v1.a FROM v1,v2 WHERE v2.b = v1.b ORDER BY 1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> ALL key0 NULL NULL NULL 3 Using where; Using filesort
|
||||
1 PRIMARY <derived3> ref key0 key0 5 v1.b 2
|
||||
3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
|
||||
2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort
|
||||
DROP VIEW v1,v2;
|
||||
DROP TABLE t1,t2;
|
||||
set optimizer_switch=@exit_optimizer_switch;
|
||||
|
|
|
@ -973,5 +973,28 @@ SELECT v1.a FROM v1
|
|||
DROP VIEW v1;
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
--echo #
|
||||
--echo # LP bug #878199: join of two materialized views
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (a int, b varchar(1)) ;
|
||||
INSERT INTO t1 VALUES (7,'c'), (3,'h'), (7,'c');
|
||||
|
||||
CREATE TABLE t2 (b varchar(1)) ;
|
||||
INSERT INTO t2 VALUES ('p'), ('c'), ('j'), ('c'), ('p');
|
||||
|
||||
CREATE VIEW v1 AS SELECT * FROM t1 GROUP BY a,b;
|
||||
|
||||
CREATE VIEW v2 AS SELECT * FROM t2 GROUP BY b;
|
||||
|
||||
SET SESSION optimizer_switch = 'derived_with_keys=on';
|
||||
|
||||
SELECT v1.a FROM v1,v2 WHERE v2.b = v1.b ORDER BY 1;
|
||||
EXPLAIN
|
||||
SELECT v1.a FROM v1,v2 WHERE v2.b = v1.b ORDER BY 1;
|
||||
|
||||
DROP VIEW v1,v2;
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
# The following command must be the last one the file
|
||||
set optimizer_switch=@exit_optimizer_switch;
|
||||
|
|
|
@ -8541,7 +8541,7 @@ void JOIN::drop_unused_derived_keys()
|
|||
continue;
|
||||
if (table->max_keys > 1)
|
||||
table->use_index(tab->ref.key);
|
||||
if (table->s->keys)
|
||||
if (table->s->keys && tab->ref.key >= 0)
|
||||
tab->ref.key= 0;
|
||||
tab->keys= (key_map) (table->s->keys ? 1 : 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue