Skip to content

Commit

Permalink
MDEV-15235: Assertion `length > 0' failed in create_ref_for_key
Browse files Browse the repository at this point in the history
The issue is that we are creating a materialised table with key of length 0 which is incorrect, we should
disable materialisation for such a case.
  • Loading branch information
varunraiko committed Mar 11, 2018
1 parent ac3fd5a commit 926edd4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mysql-test/r/subselect_mat.result
Original file line number Diff line number Diff line change
Expand Up @@ -2642,3 +2642,18 @@ a b sq
4 4 1
4 2 1
drop table t1, t2;
#
# MDEV-15235: Assertion `length > 0' failed in create_ref_for_key
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (f CHAR(1));
INSERT INTO t2 VALUES ('a'),('b');
explain
SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 );
f
DROP TABLE t1, t2;
13 changes: 13 additions & 0 deletions mysql-test/t/subselect_mat.test
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,16 @@ SELECT a, b, (a, b) NOT IN (SELECT a, b FROM t2) as sq
FROM t1;

drop table t1, t2;

--echo #
--echo # MDEV-15235: Assertion `length > 0' failed in create_ref_for_key
--echo #

CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (f CHAR(1));
INSERT INTO t2 VALUES ('a'),('b');
explain
SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 );
SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 );
DROP TABLE t1, t2;
4 changes: 3 additions & 1 deletion sql/opt_subselect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,10 @@ bool subquery_types_allow_materialization(Item_in_subselect *in_subs)
Make sure that create_tmp_table will not fail due to too long keys.
See MDEV-7122. This check is performed inside create_tmp_table also and
we must do it so that we know the table has keys created.
Make sure that the length of the key for the temp_table is atleast
greater than 0.
*/
if (total_key_length > tmp_table_max_key_length() ||
if (!total_key_length || total_key_length > tmp_table_max_key_length() ||
elements > tmp_table_max_key_parts())
DBUG_RETURN(FALSE);

Expand Down

0 comments on commit 926edd4

Please sign in to comment.