From a4885dde4ccec68bbb0268796f62e68e08ba4837 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 16 Aug 2017 18:44:17 +0200 Subject: [PATCH] MDEV-13535 Query on MyISAM table corrupts the table don't assume that the table always has a primary key, head->s->primary_key might be MAX_KEY, which won't start keyread. --- mysql-test/include/index_merge1.inc | 2 ++ mysql-test/r/index_merge_myisam.result | 3 +++ sql/opt_range.cc | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mysql-test/include/index_merge1.inc b/mysql-test/include/index_merge1.inc index 88dd4c31910..b63b2db78da 100644 --- a/mysql-test/include/index_merge1.inc +++ b/mysql-test/include/index_merge1.inc @@ -64,6 +64,8 @@ explain select * from t0 where key1 < 3 or key2 > 1020; select * from t0 where key1 < 3 or key2 > 1020; +select * from t0 where key1=1022; # MDEV-13535 no-key-read select after keyread + explain select * from t0 where key1 < 3 or key2 <4; explain diff --git a/mysql-test/r/index_merge_myisam.result b/mysql-test/r/index_merge_myisam.result index 21387f67893..992e1d831b5 100644 --- a/mysql-test/r/index_merge_myisam.result +++ b/mysql-test/r/index_merge_myisam.result @@ -34,6 +34,9 @@ key1 key2 key3 key4 key5 key6 key7 key8 1022 1022 1022 1022 1022 1022 1022 2 1023 1023 1023 1023 1023 1023 1023 1 1024 1024 1024 1024 1024 1024 1024 0 +select * from t0 where key1=1022; +key1 key2 key3 key4 key5 key6 key7 key8 +1022 1022 1022 1022 1022 1022 1022 2 explain select * from t0 where key1 < 3 or key2 <4; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t0 index_merge i1,i2 i1,i2 4,4 NULL 7 Using sort_union(i1,i2); Using where diff --git a/sql/opt_range.cc b/sql/opt_range.cc index ec59c0acf86..c15810ba686 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -10889,13 +10889,13 @@ int read_keys_and_merge_scans(THD *thd, DBUG_ENTER("read_keys_and_merge"); /* We're going to just read rowids. */ - head->file->ha_start_keyread(head->s->primary_key); head->prepare_for_position(); cur_quick_it.rewind(); cur_quick= cur_quick_it++; bool first_quick= TRUE; DBUG_ASSERT(cur_quick != 0); + head->file->ha_start_keyread(cur_quick->index); /* We reuse the same instance of handler so we need to call both init and