Commit a0230bc7 authored by Eugene Kosov's avatar Eugene Kosov

MDEV-18266 Changing an index comment unnecessarily rebuilds index

ALTER_CHANGE_INDEX_COMMENT: new handler flag added

Compare_keys::EqualButComment: new outcome of compare_keys_but_name()
parent 70c2bde9
...@@ -2533,3 +2533,17 @@ WHERE variable_name = 'innodb_instant_alter_column'; ...@@ -2533,3 +2533,17 @@ WHERE variable_name = 'innodb_instant_alter_column';
instants instants
181 181
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency; 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;
...@@ -752,3 +752,13 @@ SELECT variable_value-@old_instant instants ...@@ -752,3 +752,13 @@ SELECT variable_value-@old_instant instants
FROM information_schema.global_status FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column'; WHERE variable_name = 'innodb_instant_alter_column';
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency; 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;
...@@ -643,6 +643,7 @@ typedef ulonglong alter_table_operations; ...@@ -643,6 +643,7 @@ typedef ulonglong alter_table_operations;
#define ALTER_ADD_FOREIGN_KEY (1ULL << 21) #define ALTER_ADD_FOREIGN_KEY (1ULL << 21)
// Set for DROP FOREIGN KEY // Set for DROP FOREIGN KEY
#define ALTER_DROP_FOREIGN_KEY (1ULL << 22) #define ALTER_DROP_FOREIGN_KEY (1ULL << 22)
#define ALTER_CHANGE_INDEX_COMMENT (1ULL << 23)
// Set for ADD [COLUMN] FIRST | AFTER // Set for ADD [COLUMN] FIRST | AFTER
#define ALTER_COLUMN_ORDER (1ULL << 25) #define ALTER_COLUMN_ORDER (1ULL << 25)
#define ALTER_ADD_CHECK_CONSTRAINT (1ULL << 27) #define ALTER_ADD_CHECK_CONSTRAINT (1ULL << 27)
......
...@@ -37,6 +37,10 @@ static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b) ...@@ -37,6 +37,10 @@ static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
return (a->length != b->length || return (a->length != b->length ||
memcmp(a->str, b->str, a->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 Compare if two LEX_CSTRING are equal. Assumption is that
......
...@@ -6521,10 +6521,11 @@ static int compare_uint(const uint *s, const uint *t) ...@@ -6521,10 +6521,11 @@ static int compare_uint(const uint *s, const uint *t)
return (*s < *t) ? -1 : ((*s > *t) ? 1 : 0); return (*s < *t) ? -1 : ((*s > *t) ? 1 : 0);
} }
enum class Compare_keys enum class Compare_keys : uint32_t
{ {
Equal, Equal,
EqualButKeyPartLength, EqualButKeyPartLength,
EqualButComment,
NotEqual NotEqual
}; };
...@@ -6608,11 +6609,12 @@ Compare_keys compare_keys_but_name(const KEY *table_key, const KEY *new_key, ...@@ -6608,11 +6609,12 @@ Compare_keys compare_keys_but_name(const KEY *table_key, const KEY *new_key,
return Compare_keys::NotEqual; return Compare_keys::NotEqual;
/* Check that key comment is not changed. */ /* Check that key comment is not changed. */
if (table_key->comment.length != new_key->comment.length || if (cmp(table_key->comment, new_key->comment) != 0)
(table_key->comment.length && {
memcmp(table_key->comment.str, new_key->comment.str, if (result != Compare_keys::Equal)
table_key->comment.length) != 0)) return Compare_keys::NotEqual;
return Compare_keys::NotEqual; result= Compare_keys::EqualButComment;
}
return result; return result;
} }
...@@ -7002,6 +7004,9 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar, ...@@ -7002,6 +7004,9 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
case Compare_keys::EqualButKeyPartLength: case Compare_keys::EqualButKeyPartLength:
ha_alter_info->handler_flags|= ALTER_COLUMN_INDEX_LENGTH; ha_alter_info->handler_flags|= ALTER_COLUMN_INDEX_LENGTH;
continue; continue;
case Compare_keys::EqualButComment:
ha_alter_info->handler_flags|= ALTER_CHANGE_INDEX_COMMENT;
continue;
case Compare_keys::NotEqual: case Compare_keys::NotEqual:
break; break;
} }
......
...@@ -108,7 +108,8 @@ static const alter_table_operations INNOBASE_INPLACE_IGNORE ...@@ -108,7 +108,8 @@ static const alter_table_operations INNOBASE_INPLACE_IGNORE
| ALTER_VIRTUAL_GCOL_EXPR | ALTER_VIRTUAL_GCOL_EXPR
| ALTER_DROP_CHECK_CONSTRAINT | ALTER_DROP_CHECK_CONSTRAINT
| ALTER_RENAME | ALTER_RENAME
| ALTER_COLUMN_INDEX_LENGTH; | ALTER_COLUMN_INDEX_LENGTH
| ALTER_CHANGE_INDEX_COMMENT;
/** Operations on foreign key definitions (changing the schema only) */ /** Operations on foreign key definitions (changing the schema only) */
static const alter_table_operations INNOBASE_FOREIGN_OPERATIONS static const alter_table_operations INNOBASE_FOREIGN_OPERATIONS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment