Skip to content

Commit

Permalink
MDEV-18266 Changing an index comment unnecessarily rebuilds index
Browse files Browse the repository at this point in the history
ALTER_CHANGE_INDEX_COMMENT: new handler flag added

Compare_keys::EqualButComment: new outcome of compare_keys_but_name()
  • Loading branch information
kevgs committed Jul 10, 2019
1 parent 70c2bde commit a0230bc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
14 changes: 14 additions & 0 deletions mysql-test/suite/innodb/r/instant_alter.result
Expand Up @@ -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;
10 changes: 10 additions & 0 deletions mysql-test/suite/innodb/t/instant_alter.test
Expand Up @@ -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;
1 change: 1 addition & 0 deletions sql/handler.h
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions sql/lex_string.h
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions sql/sql_table.cc
Expand Up @@ -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
};

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion storage/innobase/handler/handler0alter.cc
Expand Up @@ -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
Expand Down

0 comments on commit a0230bc

Please sign in to comment.