summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varunraiko1803@gmail.com>2018-01-19 13:29:31 +0530
committerVarun Gupta <varunraiko1803@gmail.com>2018-01-19 13:29:31 +0530
commita7a4519a40c58947796c6d9b2e4e58acc18aeef8 (patch)
tree992ba023da35908c9d5bd275cb8e2bbba59e56ea
parent4f96b401d9dd9f876c2d3e6e266e8670d30ca2c8 (diff)
downloadmariadb-git-a7a4519a40c58947796c6d9b2e4e58acc18aeef8.tar.gz
MDEV-14241: Server crash in key_copy / get_matching_chain_by_join_key or valgrind warnings
In this case we were using the optimization derived_with_keys but we could not create a key because the length of the key was greater than the max allowed(MI_MAX_KEY_LENGTH). To do the join we needed to create a hash join key instead, but in the explain output it showed that we were still referring to derived keys which were created but not used.
-rw-r--r--mysql-test/r/derived.result25
-rw-r--r--mysql-test/t/derived.test23
-rw-r--r--sql/sql_select.cc2
3 files changed, 49 insertions, 1 deletions
diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result
index 33af7c61613..763dbe264fb 100644
--- a/mysql-test/r/derived.result
+++ b/mysql-test/r/derived.result
@@ -1011,4 +1011,29 @@ id id data
2 2 yes
1 NULL NULL
drop table t1;
+#
+# MDEV-14241: Server crash in key_copy / get_matching_chain_by_join_key
+# or valgrind warnings
+#
+CREATE TABLE t1 (a VARCHAR(10)) ENGINE=MyISAM;
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES ('foo'),('bar');
+CREATE TABLE t2 (b integer auto_increment primary key) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (NULL),(NULL);
+CREATE TABLE t3 (c VARCHAR(1024) CHARACTER SET utf8, d INT) ENGINE=MyISAM;
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3;
+INSERT INTO t3 VALUES ('abc',NULL),('def',4);
+SET join_cache_level= 8;
+explain
+SELECT * FROM v1, t2, v3 WHERE a = c AND b = d;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
+1 PRIMARY <derived3> hash_ALL NULL #hash#$hj 3075 func 2 Using where; Using join buffer (flat, BNLH join)
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 v3.d 1 Using index
+3 DERIVED t3 ALL NULL NULL NULL NULL 2
+2 DERIVED t1 ALL NULL NULL NULL NULL 2
+SELECT * FROM v1, t2, v3 WHERE a = c AND b = d;
+a b c d
+DROP VIEW v1, v3;
+DROP TABLE t1, t2, t3;
# end of 5.5
diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test
index f8ba87ac1f5..eb6e502b029 100644
--- a/mysql-test/t/derived.test
+++ b/mysql-test/t/derived.test
@@ -864,5 +864,28 @@ select distinct t1.id, tt.id, tt.data
drop table t1;
+--echo #
+--echo # MDEV-14241: Server crash in key_copy / get_matching_chain_by_join_key
+--echo # or valgrind warnings
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(10)) ENGINE=MyISAM;
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES ('foo'),('bar');
+
+CREATE TABLE t2 (b integer auto_increment primary key) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (NULL),(NULL);
+
+CREATE TABLE t3 (c VARCHAR(1024) CHARACTER SET utf8, d INT) ENGINE=MyISAM;
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3;
+INSERT INTO t3 VALUES ('abc',NULL),('def',4);
+
+SET join_cache_level= 8;
+explain
+SELECT * FROM v1, t2, v3 WHERE a = c AND b = d;
+SELECT * FROM v1, t2, v3 WHERE a = c AND b = d;
+
+DROP VIEW v1, v3;
+DROP TABLE t1, t2, t3;
--echo # end of 5.5
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 42b3420a9b6..d35a5a8094c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -9513,7 +9513,7 @@ void JOIN::drop_unused_derived_keys()
table->use_index(tab->ref.key);
if (table->s->keys)
{
- if (tab->ref.key >= 0)
+ if (tab->ref.key >= 0 && tab->ref.key < MAX_KEY)
tab->ref.key= 0;
else
table->s->keys= 0;