Skip to content

Commit 90b292c

Browse files
committed
Follow-up to MDEV-16328: ALTER TABLE…page_compression_level should not rebuild table
Allow combination of non-instant, non-rebuilding operations with changes of table options that do not require a rebuild. For example, DROP INDEX or ADD INDEX can be performed with ALGORITHM=NOCOPY together with changing such table options. Changing the table options alone would be allowed with ALGORITHM=INSTANT. INNOBASE_ALTER_NOCREATE: A new set of flags, for operations that are refused for ALGORITHM=INSTANT and do not involve creating index trees. Move ALTER_RENAME_INDEX to the proper place (INNOBASE_ALTER_INSTANT). innobase_need_rebuild(): Do not require a rebuild if INNOBASE_ALTER_NOREBUILD operations are combined with ALTER_OPTIONS. ha_innobase::prepare_inplace_alter_table(), ha_innobase::inplace_alter_table(): Use the fast path if ALTER_OPTIONS is combined with INNOBASE_ALTER_NOCREATE. In this case, the actual changes would be deferred to ha_innobase::commit_inplace_alter_table().
1 parent 28ae796 commit 90b292c

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

mysql-test/suite/innodb/include/alter_nocopy.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ SELECT @@alter_algorithm;
1414

1515
--enable_info
1616
--error $error_code
17-
--eval ALTER TABLE t1 ADD INDEX idx1(f4)
17+
--eval ALTER TABLE t1 ADD INDEX idx1(f4), page_compressed=1
1818

1919
--error $error_code
20-
--eval ALTER TABLE t1 DROP INDEX idx
20+
--eval ALTER TABLE t1 DROP INDEX idx, page_compression_level=5
2121

2222
--error $error_code
2323
--eval ALTER TABLE t1 ADD UNIQUE INDEX u1(f2)
2424

2525
--error $error_code
26-
--eval ALTER TABLE t1 DROP INDEX f4
26+
--eval ALTER TABLE t1 DROP INDEX f4, page_compression_level=9
2727

2828
SET foreign_key_checks = 0;
2929
--error $error_code

mysql-test/suite/innodb/r/alter_algorithm,INPLACE.rdiff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
@@alter_algorithm
7171
-COPY
7272
+INPLACE
73-
ALTER TABLE t1 ADD INDEX idx1(f4);
73+
ALTER TABLE t1 ADD INDEX idx1(f4), page_compressed=1;
7474
-affected rows: 1
7575
-info: Records: 1 Duplicates: 0 Warnings: 0
7676
+affected rows: 0
7777
+info: Records: 0 Duplicates: 0 Warnings: 0
78-
ALTER TABLE t1 DROP INDEX idx;
78+
ALTER TABLE t1 DROP INDEX idx, page_compression_level=5;
7979
-affected rows: 1
8080
-info: Records: 1 Duplicates: 0 Warnings: 0
8181
+affected rows: 0
@@ -85,7 +85,7 @@
8585
-info: Records: 1 Duplicates: 0 Warnings: 0
8686
+affected rows: 0
8787
+info: Records: 0 Duplicates: 0 Warnings: 0
88-
ALTER TABLE t1 DROP INDEX f4;
88+
ALTER TABLE t1 DROP INDEX f4, page_compression_level=9;
8989
-affected rows: 1
9090
-info: Records: 1 Duplicates: 0 Warnings: 0
9191
+affected rows: 0

mysql-test/suite/innodb/r/alter_algorithm,INSTANT.rdiff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@
6161
@@alter_algorithm
6262
-COPY
6363
+INSTANT
64-
ALTER TABLE t1 ADD INDEX idx1(f4);
64+
ALTER TABLE t1 ADD INDEX idx1(f4), page_compressed=1;
6565
-affected rows: 1
6666
-info: Records: 1 Duplicates: 0 Warnings: 0
6767
+ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: ADD INDEX. Try ALGORITHM=NOCOPY
68-
ALTER TABLE t1 DROP INDEX idx;
68+
ALTER TABLE t1 DROP INDEX idx, page_compression_level=5;
6969
-affected rows: 1
7070
-info: Records: 1 Duplicates: 0 Warnings: 0
7171
+ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: DROP INDEX. Try ALGORITHM=NOCOPY
7272
ALTER TABLE t1 ADD UNIQUE INDEX u1(f2);
7373
-affected rows: 1
7474
-info: Records: 1 Duplicates: 0 Warnings: 0
7575
+ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: ADD INDEX. Try ALGORITHM=NOCOPY
76-
ALTER TABLE t1 DROP INDEX f4;
76+
ALTER TABLE t1 DROP INDEX f4, page_compression_level=9;
7777
-affected rows: 1
7878
-info: Records: 1 Duplicates: 0 Warnings: 0
7979
+ERROR 0A000: ALGORITHM=INSTANT is not supported. Reason: DROP INDEX. Try ALGORITHM=NOCOPY

mysql-test/suite/innodb/r/alter_algorithm,NOCOPY.rdiff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@
6161
@@alter_algorithm
6262
-COPY
6363
+NOCOPY
64-
ALTER TABLE t1 ADD INDEX idx1(f4);
64+
ALTER TABLE t1 ADD INDEX idx1(f4), page_compressed=1;
6565
-affected rows: 1
6666
-info: Records: 1 Duplicates: 0 Warnings: 0
6767
+affected rows: 0
6868
+info: Records: 0 Duplicates: 0 Warnings: 0
69-
ALTER TABLE t1 DROP INDEX idx;
69+
ALTER TABLE t1 DROP INDEX idx, page_compression_level=5;
7070
-affected rows: 1
7171
-info: Records: 1 Duplicates: 0 Warnings: 0
7272
+affected rows: 0
@@ -76,7 +76,7 @@
7676
-info: Records: 1 Duplicates: 0 Warnings: 0
7777
+affected rows: 0
7878
+info: Records: 0 Duplicates: 0 Warnings: 0
79-
ALTER TABLE t1 DROP INDEX f4;
79+
ALTER TABLE t1 DROP INDEX f4, page_compression_level=9;
8080
-affected rows: 1
8181
-info: Records: 1 Duplicates: 0 Warnings: 0
8282
+affected rows: 0

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4);
5959
SELECT @@alter_algorithm;
6060
@@alter_algorithm
6161
COPY
62-
ALTER TABLE t1 ADD INDEX idx1(f4);
62+
ALTER TABLE t1 ADD INDEX idx1(f4), page_compressed=1;
6363
affected rows: 1
6464
info: Records: 1 Duplicates: 0 Warnings: 0
65-
ALTER TABLE t1 DROP INDEX idx;
65+
ALTER TABLE t1 DROP INDEX idx, page_compression_level=5;
6666
affected rows: 1
6767
info: Records: 1 Duplicates: 0 Warnings: 0
6868
ALTER TABLE t1 ADD UNIQUE INDEX u1(f2);
6969
affected rows: 1
7070
info: Records: 1 Duplicates: 0 Warnings: 0
71-
ALTER TABLE t1 DROP INDEX f4;
71+
ALTER TABLE t1 DROP INDEX f4, page_compression_level=9;
7272
affected rows: 1
7373
info: Records: 1 Duplicates: 0 Warnings: 0
7474
SET foreign_key_checks = 0;

storage/innobase/handler/handler0alter.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,23 @@ static const alter_table_operations INNOBASE_FOREIGN_OPERATIONS
110110
= ALTER_DROP_FOREIGN_KEY
111111
| ALTER_ADD_FOREIGN_KEY;
112112

113+
/** Operations that InnoDB cares about and can perform without creating data */
114+
static const alter_table_operations INNOBASE_ALTER_NOCREATE
115+
= ALTER_DROP_NON_UNIQUE_NON_PRIM_INDEX
116+
| ALTER_DROP_UNIQUE_INDEX;
117+
113118
/** Operations that InnoDB cares about and can perform without rebuild */
114119
static const alter_table_operations INNOBASE_ALTER_NOREBUILD
115120
= INNOBASE_ONLINE_CREATE
116-
| ALTER_DROP_NON_UNIQUE_NON_PRIM_INDEX
117-
| ALTER_DROP_UNIQUE_INDEX
118-
#ifdef MYSQL_RENAME_INDEX
119-
| ALTER_RENAME_INDEX
120-
#endif
121-
;
121+
| INNOBASE_ALTER_NOCREATE;
122122

123123
/** Operations that can be performed instantly, without inplace_alter_table() */
124124
static const alter_table_operations INNOBASE_ALTER_INSTANT
125125
= ALTER_VIRTUAL_COLUMN_ORDER
126126
| ALTER_COLUMN_NAME
127+
#ifdef MYSQL_RENAME_INDEX
128+
| ALTER_RENAME_INDEX
129+
#endif
127130
| ALTER_ADD_VIRTUAL_COLUMN
128131
| INNOBASE_FOREIGN_OPERATIONS
129132
| ALTER_COLUMN_EQUAL_PACK_LENGTH
@@ -550,6 +553,7 @@ innobase_need_rebuild(
550553
const TABLE* table)
551554
{
552555
if ((ha_alter_info->handler_flags & ~(INNOBASE_INPLACE_IGNORE
556+
| INNOBASE_ALTER_NOREBUILD
553557
| INNOBASE_ALTER_INSTANT))
554558
== ALTER_OPTIONS) {
555559
return alter_options_need_rebuild(ha_alter_info, table);
@@ -6836,6 +6840,7 @@ ha_innobase::prepare_inplace_alter_table(
68366840

68376841
if (!(ha_alter_info->handler_flags & INNOBASE_ALTER_DATA)
68386842
|| ((ha_alter_info->handler_flags & ~(INNOBASE_INPLACE_IGNORE
6843+
| INNOBASE_ALTER_NOCREATE
68396844
| INNOBASE_ALTER_INSTANT))
68406845
== ALTER_OPTIONS
68416846
&& !alter_options_need_rebuild(ha_alter_info, table))) {
@@ -7121,6 +7126,7 @@ ha_innobase::inplace_alter_table(
71217126
}
71227127

71237128
if ((ha_alter_info->handler_flags & ~(INNOBASE_INPLACE_IGNORE
7129+
| INNOBASE_ALTER_NOCREATE
71247130
| INNOBASE_ALTER_INSTANT))
71257131
== ALTER_OPTIONS
71267132
&& !alter_options_need_rebuild(ha_alter_info, table)) {

0 commit comments

Comments
 (0)