Skip to content

Commit

Permalink
MDEV-9635: Server crashes in part_of_refkey or assertion `!created &&…
Browse files Browse the repository at this point in the history
… key_to_save < (int)s->keys' failed in TABLE::use_index(int) or with join_cache_level>2

Do not try to create index where ref is for hash join.
  • Loading branch information
sanja-byelkin committed Feb 28, 2017
1 parent 5a0fff5 commit 75f6067
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mysql-test/r/subselect_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,18 @@ HAVING SQ2_alias1 . col_int_key >= 7
1
drop table t1;
set optimizer_switch=@subselect_innodb_tmp;
#
# MDEV-9635:Server crashes in part_of_refkey or assertion
# `!created && key_to_save < (int)s->keys' failed in
# TABLE::use_index(int) or with join_cache_level>2
#
SET join_cache_level=3;
CREATE TABLE t1 (f1 VARCHAR(1024)) ENGINE=InnoDB;
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
CREATE TABLE t2 (f2 VARCHAR(4)) ENGINE=InnoDB;
INSERT INTO t2 VALUES ('foo'),('bar');
SELECT * FROM v1, t2 WHERE ( f1, f2 ) IN ( SELECT f1, f1 FROM t1 );
f1 f2
set join_cache_level = default;
drop view v1;
drop table t1,t2;
20 changes: 20 additions & 0 deletions mysql-test/t/subselect_innodb.test
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,23 @@ drop table t1;


set optimizer_switch=@subselect_innodb_tmp;

--echo #
--echo # MDEV-9635:Server crashes in part_of_refkey or assertion
--echo # `!created && key_to_save < (int)s->keys' failed in
--echo # TABLE::use_index(int) or with join_cache_level>2
--echo #

SET join_cache_level=3;

CREATE TABLE t1 (f1 VARCHAR(1024)) ENGINE=InnoDB;
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;

CREATE TABLE t2 (f2 VARCHAR(4)) ENGINE=InnoDB;
INSERT INTO t2 VALUES ('foo'),('bar');

SELECT * FROM v1, t2 WHERE ( f1, f2 ) IN ( SELECT f1, f1 FROM t1 );

set join_cache_level = default;
drop view v1;
drop table t1,t2;
2 changes: 1 addition & 1 deletion sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9422,7 +9422,7 @@ void JOIN::drop_unused_derived_keys()
continue;
if (!table->pos_in_table_list->is_materialized_derived())
continue;
if (table->max_keys > 1)
if (table->max_keys > 1 && !tab->is_ref_for_hash_join())
table->use_index(tab->ref.key);
if (table->s->keys)
{
Expand Down

0 comments on commit 75f6067

Please sign in to comment.