[Commits] 4ca016237f1: MDEV-20001 Potential dangerous regression: INSERT INTO >=100 rows fail for myisam table with HASH indexes

sachin.setiya at mariadb.com sachin.setiya at mariadb.com
Mon Jul 29 17:04:33 EEST 2019


revision-id: 4ca016237f1a1813c9e1ce9e4227c056c53896bb (mariadb-10.4.5-152-g4ca016237f1)
parent(s): 4a5cd4072894864c9f1f59675c2b8b8cd2ae40a4
author: Sachin
committer: Sachin
timestamp: 2019-07-29 19:33:05 +0530
message:

MDEV-20001 Potential dangerous regression: INSERT INTO >=100 rows fail for myisam table with HASH indexes

Dont deactivate the long unique keys on bulk insert.

---
 mysql-test/main/long_unique_bugs.result |  3 +++
 mysql-test/main/long_unique_bugs.test   | 17 +++++++++++++++++
 storage/myisam/ha_myisam.cc             | 11 ++++++++++-
 storage/myisam/mi_check.c               |  5 +++--
 storage/myisam/myisamdef.h              |  2 +-
 5 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result
index 33496c4e20d..910e5e592e1 100644
--- a/mysql-test/main/long_unique_bugs.result
+++ b/mysql-test/main/long_unique_bugs.result
@@ -265,3 +265,6 @@ ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
 disconnect con1;
 connection default;
 DROP TABLE t1, t2;
+create table t1(a int, unique(a) using hash);
+#BULK insert > 100 rows (MI_MIN_ROWS_TO_DISABLE_INDEXES)
+drop table t1;
diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test
index dc78f6c7067..da054e59f34 100644
--- a/mysql-test/main/long_unique_bugs.test
+++ b/mysql-test/main/long_unique_bugs.test
@@ -317,3 +317,20 @@ INSERT IGNORE INTO t1 VALUES (4, 1)/*4*/;
 --disconnect con1
 --connection default
 DROP TABLE t1, t2;
+
+#
+# MDEV-20001 Potential dangerous regression: INSERT INTO >=100 rows fail for myisam table with HASH indexes
+#
+create table t1(a int, unique(a) using hash);
+--let $count=150
+--let insert_stmt= insert into t1 values(200)
+while ($count)
+{
+  --let $insert_stmt=$insert_stmt,($count)
+  --dec $count
+}
+--disable_query_log
+--echo #BULK insert > 100 rows (MI_MIN_ROWS_TO_DISABLE_INDEXES)
+--eval $insert_stmt
+--enable_query_log
+drop table t1;
diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc
index f478e01e441..c1169737911 100644
--- a/storage/myisam/ha_myisam.cc
+++ b/storage/myisam/ha_myisam.cc
@@ -1749,7 +1749,16 @@ void ha_myisam::start_bulk_insert(ha_rows rows, uint flags)
     else
     {
       my_bool all_keys= MY_TEST(flags & HA_CREATE_UNIQUE_INDEX_BY_SORT);
-      mi_disable_indexes_for_rebuild(file, rows, all_keys);
+      if (table->s->long_unique_table)
+      {
+        ulonglong hash_key_map= 0ULL;
+        for(uint i= 0; i < table->s->keys; i++)
+          if (table->key_info[i].algorithm == HA_KEY_ALG_LONG_HASH)
+            mi_set_key_active(hash_key_map, i);
+        mi_disable_indexes_for_rebuild(file, rows, all_keys, hash_key_map);
+      }
+      else
+        mi_disable_indexes_for_rebuild(file, rows, all_keys, 0ULL);
     }
   }
   else
diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c
index 869e86b7495..d3205b89d90 100644
--- a/storage/myisam/mi_check.c
+++ b/storage/myisam/mi_check.c
@@ -4694,7 +4694,7 @@ static my_bool mi_too_big_key_for_sort(MI_KEYDEF *key, ha_rows rows)
  */
 
 void mi_disable_indexes_for_rebuild(MI_INFO *info, ha_rows rows,
-                                    my_bool all_keys)
+                                    my_bool all_keys, ulonglong hash_key_map)
 {
   MYISAM_SHARE *share=info->s;
   MI_KEYDEF    *key=share->keyinfo;
@@ -4706,7 +4706,8 @@ void mi_disable_indexes_for_rebuild(MI_INFO *info, ha_rows rows,
   {
     if (!(key->flag & (HA_SPATIAL | HA_AUTO_KEY)) &&
         ! mi_too_big_key_for_sort(key,rows) && info->s->base.auto_key != i+1 &&
-        (all_keys || !(key->flag & HA_NOSAME))) 
+        (all_keys || !(key->flag & HA_NOSAME)) &&
+        !mi_is_key_active(hash_key_map, i))
     {
       mi_clear_key_active(share->state.key_map, i);
       info->update|= HA_STATE_CHANGED;
diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h
index 7fc8a8eba4f..a8794f76fbd 100644
--- a/storage/myisam/myisamdef.h
+++ b/storage/myisam/myisamdef.h
@@ -716,7 +716,7 @@ void mi_copy_status(void *to, void *from);
 my_bool mi_check_status(void *param);
 void mi_fix_status(MI_INFO *org_table, MI_INFO *new_table);
 void mi_disable_indexes_for_rebuild(MI_INFO *info, ha_rows rows,
-                                    my_bool all_keys);
+                                    my_bool all_keys, ulonglong hash_key_map);
 extern MI_INFO *test_if_reopen(char *filename);
 my_bool check_table_is_closed(const char *name, const char *where);
 int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share);


More information about the commits mailing list