summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kosov <claprix@yandex.ru>2019-07-10 21:15:12 +0300
committerEugene Kosov <claprix@yandex.ru>2019-07-10 21:36:29 +0300
commita0230bc76d78202178f43d2f4f6a7e3322c19a16 (patch)
tree47d1bafa6345c7516cab8ae48a53ceca1ecd735c
parent70c2bde931246ea4966d82fa56773b8ef1e0074f (diff)
downloadmariadb-git-bb-10.4-MDEV-18266-index-comment.tar.gz
MDEV-18266 Changing an index comment unnecessarily rebuilds indexbb-10.4-MDEV-18266-index-comment
ALTER_CHANGE_INDEX_COMMENT: new handler flag added Compare_keys::EqualButComment: new outcome of compare_keys_but_name()
-rw-r--r--mysql-test/suite/innodb/r/instant_alter.result14
-rw-r--r--mysql-test/suite/innodb/t/instant_alter.test10
-rw-r--r--sql/handler.h1
-rw-r--r--sql/lex_string.h4
-rw-r--r--sql/sql_table.cc17
-rw-r--r--storage/innobase/handler/handler0alter.cc3
6 files changed, 42 insertions, 7 deletions
diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result
index 30eddd51bfb..0723559fd10 100644
--- a/mysql-test/suite/innodb/r/instant_alter.result
+++ b/mysql-test/suite/innodb/r/instant_alter.result
@@ -2533,3 +2533,17 @@ WHERE variable_name = 'innodb_instant_alter_column';
instants
181
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency;
+#
+# MDEV-18266: Changing an index comment unnecessarily rebuilds index
+#
+CREATE TABLE t1(a INT, b INT) ENGINE=INNODB;
+CREATE INDEX i1 ON t1(a) COMMENT 'comment1';
+ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2', ALGORITHM=INSTANT;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ KEY `i1` (`a`) COMMENT 'comment2'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
diff --git a/mysql-test/suite/innodb/t/instant_alter.test b/mysql-test/suite/innodb/t/instant_alter.test
index b6be9137532..71c4e22de2f 100644
--- a/mysql-test/suite/innodb/t/instant_alter.test
+++ b/mysql-test/suite/innodb/t/instant_alter.test
@@ -752,3 +752,13 @@ SELECT variable_value-@old_instant instants
FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency;
+
+--echo #
+--echo # MDEV-18266: Changing an index comment unnecessarily rebuilds index
+--echo #
+
+CREATE TABLE t1(a INT, b INT) ENGINE=INNODB;
+CREATE INDEX i1 ON t1(a) COMMENT 'comment1';
+ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2', ALGORITHM=INSTANT;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
diff --git a/sql/handler.h b/sql/handler.h
index 7bdcb637485..f3a95022b4f 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -643,6 +643,7 @@ typedef ulonglong alter_table_operations;
#define ALTER_ADD_FOREIGN_KEY (1ULL << 21)
// Set for DROP FOREIGN KEY
#define ALTER_DROP_FOREIGN_KEY (1ULL << 22)
+#define ALTER_CHANGE_INDEX_COMMENT (1ULL << 23)
// Set for ADD [COLUMN] FIRST | AFTER
#define ALTER_COLUMN_ORDER (1ULL << 25)
#define ALTER_ADD_CHECK_CONSTRAINT (1ULL << 27)
diff --git a/sql/lex_string.h b/sql/lex_string.h
index a5209165be0..88a7154b064 100644
--- a/sql/lex_string.h
+++ b/sql/lex_string.h
@@ -37,6 +37,10 @@ static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
return (a->length != b->length ||
memcmp(a->str, b->str, a->length));
}
+static inline bool cmp(const LEX_CSTRING a, const LEX_CSTRING b)
+{
+ return a.length != b.length || memcmp(a.str, b.str, a.length);
+}
/*
Compare if two LEX_CSTRING are equal. Assumption is that
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 67f17b893d0..efccd2226c3 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -6521,10 +6521,11 @@ static int compare_uint(const uint *s, const uint *t)
return (*s < *t) ? -1 : ((*s > *t) ? 1 : 0);
}
-enum class Compare_keys
+enum class Compare_keys : uint32_t
{
Equal,
EqualButKeyPartLength,
+ EqualButComment,
NotEqual
};
@@ -6608,11 +6609,12 @@ Compare_keys compare_keys_but_name(const KEY *table_key, const KEY *new_key,
return Compare_keys::NotEqual;
/* Check that key comment is not changed. */
- if (table_key->comment.length != new_key->comment.length ||
- (table_key->comment.length &&
- memcmp(table_key->comment.str, new_key->comment.str,
- table_key->comment.length) != 0))
- return Compare_keys::NotEqual;
+ if (cmp(table_key->comment, new_key->comment) != 0)
+ {
+ if (result != Compare_keys::Equal)
+ return Compare_keys::NotEqual;
+ result= Compare_keys::EqualButComment;
+ }
return result;
}
@@ -7002,6 +7004,9 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
case Compare_keys::EqualButKeyPartLength:
ha_alter_info->handler_flags|= ALTER_COLUMN_INDEX_LENGTH;
continue;
+ case Compare_keys::EqualButComment:
+ ha_alter_info->handler_flags|= ALTER_CHANGE_INDEX_COMMENT;
+ continue;
case Compare_keys::NotEqual:
break;
}
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 08e549629fd..73260da824f 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -108,7 +108,8 @@ static const alter_table_operations INNOBASE_INPLACE_IGNORE
| ALTER_VIRTUAL_GCOL_EXPR
| ALTER_DROP_CHECK_CONSTRAINT
| ALTER_RENAME
- | ALTER_COLUMN_INDEX_LENGTH;
+ | ALTER_COLUMN_INDEX_LENGTH
+ | ALTER_CHANGE_INDEX_COMMENT;
/** Operations on foreign key definitions (changing the schema only) */
static const alter_table_operations INNOBASE_FOREIGN_OPERATIONS