Skip to content

Commit 75f6067

Browse files
committed
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
Do not try to create index where ref is for hash join.
1 parent 5a0fff5 commit 75f6067

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

mysql-test/r/subselect_innodb.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,18 @@ HAVING SQ2_alias1 . col_int_key >= 7
454454
1
455455
drop table t1;
456456
set optimizer_switch=@subselect_innodb_tmp;
457+
#
458+
# MDEV-9635:Server crashes in part_of_refkey or assertion
459+
# `!created && key_to_save < (int)s->keys' failed in
460+
# TABLE::use_index(int) or with join_cache_level>2
461+
#
462+
SET join_cache_level=3;
463+
CREATE TABLE t1 (f1 VARCHAR(1024)) ENGINE=InnoDB;
464+
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
465+
CREATE TABLE t2 (f2 VARCHAR(4)) ENGINE=InnoDB;
466+
INSERT INTO t2 VALUES ('foo'),('bar');
467+
SELECT * FROM v1, t2 WHERE ( f1, f2 ) IN ( SELECT f1, f1 FROM t1 );
468+
f1 f2
469+
set join_cache_level = default;
470+
drop view v1;
471+
drop table t1,t2;

mysql-test/t/subselect_innodb.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,23 @@ drop table t1;
433433

434434

435435
set optimizer_switch=@subselect_innodb_tmp;
436+
437+
--echo #
438+
--echo # MDEV-9635:Server crashes in part_of_refkey or assertion
439+
--echo # `!created && key_to_save < (int)s->keys' failed in
440+
--echo # TABLE::use_index(int) or with join_cache_level>2
441+
--echo #
442+
443+
SET join_cache_level=3;
444+
445+
CREATE TABLE t1 (f1 VARCHAR(1024)) ENGINE=InnoDB;
446+
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
447+
448+
CREATE TABLE t2 (f2 VARCHAR(4)) ENGINE=InnoDB;
449+
INSERT INTO t2 VALUES ('foo'),('bar');
450+
451+
SELECT * FROM v1, t2 WHERE ( f1, f2 ) IN ( SELECT f1, f1 FROM t1 );
452+
453+
set join_cache_level = default;
454+
drop view v1;
455+
drop table t1,t2;

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9422,7 +9422,7 @@ void JOIN::drop_unused_derived_keys()
94229422
continue;
94239423
if (!table->pos_in_table_list->is_materialized_derived())
94249424
continue;
9425-
if (table->max_keys > 1)
9425+
if (table->max_keys > 1 && !tab->is_ref_for_hash_join())
94269426
table->use_index(tab->ref.key);
94279427
if (table->s->keys)
94289428
{

0 commit comments

Comments
 (0)