Skip to content

Commit d3ec326

Browse files
1 parent 593abb7 commit d3ec326

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,16 @@ ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col1 % col2)
198198
VIRTUAL, ADD UNIQUE index idx (col1), algorithm=inplace;
199199
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY.
200200
DROP TABLE t1;
201+
#
202+
# Bug 27122803 - BACKPORT FIX FOR BUG 25899959 TO MYSQL-5.7
203+
#
204+
CREATE TABLE t1 (col1 int(10)) DEFAULT CHARSET=utf8mb4;
205+
ALTER TABLE t1 ADD col2 char(21) AS (col1 * col1), ADD INDEX n (col2);
206+
SHOW CREATE TABLE t1;
207+
Table Create Table
208+
t1 CREATE TABLE `t1` (
209+
`col1` int(10) DEFAULT NULL,
210+
`col2` char(21) GENERATED ALWAYS AS ((`col1` * `col1`)) VIRTUAL,
211+
KEY `n` (`col2`)
212+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
213+
DROP TABLE t1;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,13 @@ ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col1 % col2)
218218
VIRTUAL, ADD UNIQUE index idx (col1), algorithm=inplace;
219219

220220
DROP TABLE t1;
221+
222+
--echo #
223+
--echo # Bug 27122803 - BACKPORT FIX FOR BUG 25899959 TO MYSQL-5.7
224+
--echo #
225+
226+
CREATE TABLE t1 (col1 int(10)) DEFAULT CHARSET=utf8mb4;
227+
ALTER TABLE t1 ADD col2 char(21) AS (col1 * col1), ADD INDEX n (col2);
228+
SHOW CREATE TABLE t1;
229+
230+
DROP TABLE t1;

storage/innobase/handler/handler0alter.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4251,6 +4251,19 @@ prepare_inplace_alter_table_dict(
42514251
for create index */
42524252
if (ha_alter_info->handler_flags
42534253
& Alter_inplace_info::ADD_INDEX) {
4254+
for (ulint i = 0;
4255+
i < ctx->num_to_add_vcol;
4256+
i++) {
4257+
/* Set mbminmax for newly added column */
4258+
ulint i_mbminlen, i_mbmaxlen;
4259+
dtype_get_mblen(ctx->add_vcol[i].m_col.mtype,
4260+
ctx->add_vcol[i].m_col.prtype,
4261+
&i_mbminlen, &i_mbmaxlen);
4262+
4263+
dtype_set_mbminmaxlen(
4264+
(dtype_t*) &ctx->add_vcol[i].m_col,
4265+
i_mbminlen, i_mbmaxlen);
4266+
}
42544267
add_v = static_cast<dict_add_v_col_t*>(
42554268
mem_heap_alloc(ctx->heap, sizeof *add_v));
42564269
add_v->n_v_col = ctx->num_to_add_vcol;

0 commit comments

Comments
 (0)