Skip to content

Commit a0230bc

Browse files
committed
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()
1 parent 70c2bde commit a0230bc

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

mysql-test/suite/innodb/r/instant_alter.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,3 +2533,17 @@ WHERE variable_name = 'innodb_instant_alter_column';
25332533
instants
25342534
181
25352535
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency;
2536+
#
2537+
# MDEV-18266: Changing an index comment unnecessarily rebuilds index
2538+
#
2539+
CREATE TABLE t1(a INT, b INT) ENGINE=INNODB;
2540+
CREATE INDEX i1 ON t1(a) COMMENT 'comment1';
2541+
ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2', ALGORITHM=INSTANT;
2542+
SHOW CREATE TABLE t1;
2543+
Table Create Table
2544+
t1 CREATE TABLE `t1` (
2545+
`a` int(11) DEFAULT NULL,
2546+
`b` int(11) DEFAULT NULL,
2547+
KEY `i1` (`a`) COMMENT 'comment2'
2548+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
2549+
DROP TABLE t1;

mysql-test/suite/innodb/t/instant_alter.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,3 +752,13 @@ SELECT variable_value-@old_instant instants
752752
FROM information_schema.global_status
753753
WHERE variable_name = 'innodb_instant_alter_column';
754754
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency;
755+
756+
--echo #
757+
--echo # MDEV-18266: Changing an index comment unnecessarily rebuilds index
758+
--echo #
759+
760+
CREATE TABLE t1(a INT, b INT) ENGINE=INNODB;
761+
CREATE INDEX i1 ON t1(a) COMMENT 'comment1';
762+
ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2', ALGORITHM=INSTANT;
763+
SHOW CREATE TABLE t1;
764+
DROP TABLE t1;

sql/handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ typedef ulonglong alter_table_operations;
643643
#define ALTER_ADD_FOREIGN_KEY (1ULL << 21)
644644
// Set for DROP FOREIGN KEY
645645
#define ALTER_DROP_FOREIGN_KEY (1ULL << 22)
646+
#define ALTER_CHANGE_INDEX_COMMENT (1ULL << 23)
646647
// Set for ADD [COLUMN] FIRST | AFTER
647648
#define ALTER_COLUMN_ORDER (1ULL << 25)
648649
#define ALTER_ADD_CHECK_CONSTRAINT (1ULL << 27)

sql/lex_string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
3737
return (a->length != b->length ||
3838
memcmp(a->str, b->str, a->length));
3939
}
40+
static inline bool cmp(const LEX_CSTRING a, const LEX_CSTRING b)
41+
{
42+
return a.length != b.length || memcmp(a.str, b.str, a.length);
43+
}
4044

4145
/*
4246
Compare if two LEX_CSTRING are equal. Assumption is that

sql/sql_table.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6521,10 +6521,11 @@ static int compare_uint(const uint *s, const uint *t)
65216521
return (*s < *t) ? -1 : ((*s > *t) ? 1 : 0);
65226522
}
65236523

6524-
enum class Compare_keys
6524+
enum class Compare_keys : uint32_t
65256525
{
65266526
Equal,
65276527
EqualButKeyPartLength,
6528+
EqualButComment,
65286529
NotEqual
65296530
};
65306531

@@ -6608,11 +6609,12 @@ Compare_keys compare_keys_but_name(const KEY *table_key, const KEY *new_key,
66086609
return Compare_keys::NotEqual;
66096610

66106611
/* Check that key comment is not changed. */
6611-
if (table_key->comment.length != new_key->comment.length ||
6612-
(table_key->comment.length &&
6613-
memcmp(table_key->comment.str, new_key->comment.str,
6614-
table_key->comment.length) != 0))
6615-
return Compare_keys::NotEqual;
6612+
if (cmp(table_key->comment, new_key->comment) != 0)
6613+
{
6614+
if (result != Compare_keys::Equal)
6615+
return Compare_keys::NotEqual;
6616+
result= Compare_keys::EqualButComment;
6617+
}
66166618

66176619
return result;
66186620
}
@@ -7002,6 +7004,9 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
70027004
case Compare_keys::EqualButKeyPartLength:
70037005
ha_alter_info->handler_flags|= ALTER_COLUMN_INDEX_LENGTH;
70047006
continue;
7007+
case Compare_keys::EqualButComment:
7008+
ha_alter_info->handler_flags|= ALTER_CHANGE_INDEX_COMMENT;
7009+
continue;
70057010
case Compare_keys::NotEqual:
70067011
break;
70077012
}

storage/innobase/handler/handler0alter.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ static const alter_table_operations INNOBASE_INPLACE_IGNORE
108108
| ALTER_VIRTUAL_GCOL_EXPR
109109
| ALTER_DROP_CHECK_CONSTRAINT
110110
| ALTER_RENAME
111-
| ALTER_COLUMN_INDEX_LENGTH;
111+
| ALTER_COLUMN_INDEX_LENGTH
112+
| ALTER_CHANGE_INDEX_COMMENT;
112113

113114
/** Operations on foreign key definitions (changing the schema only) */
114115
static const alter_table_operations INNOBASE_FOREIGN_OPERATIONS

0 commit comments

Comments
 (0)