Skip to content

Commit d46b3c9

Browse files
midenokdr-m
authored andcommitted
MDEV-17697 Broken versioning info after instant drop column
Closes #986
1 parent cb2f36d commit d46b3c9

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

mysql-test/suite/versioning/r/online.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,16 @@ alter table t add index idx(a), lock=none;
124124
alter table t drop column s, drop column e;
125125
alter table t drop system versioning, lock=none;
126126
ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned operations. Try LOCK=SHARED
127+
#
128+
# MDEV-17697 Broken versioning info after instant drop column
129+
#
130+
set @@system_versioning_alter_history= keep;
131+
create or replace table t1 (a int, b int) with system versioning;
132+
insert into t1 values (1, 1);
133+
alter table t1 drop column b, algorithm=instant;
134+
alter table t1 drop system versioning;
135+
create or replace table t1 (a int, b int) with system versioning;
136+
insert into t1 values (1, 1);
137+
alter table t1 drop system versioning;
127138
drop database test;
128139
create database test;

mysql-test/suite/versioning/t/online.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,29 @@ alter table t drop column s, drop column e;
148148
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
149149
alter table t drop system versioning, lock=none;
150150

151+
--echo #
152+
--echo # MDEV-17697 Broken versioning info after instant drop column
153+
--echo #
154+
set @@system_versioning_alter_history= keep;
155+
create or replace table t1 (a int, b int) with system versioning;
156+
insert into t1 values (1, 1);
157+
alter table t1 drop column b, algorithm=instant;
158+
alter table t1 drop system versioning;
159+
160+
create or replace table t1 (a int, b int) with system versioning;
161+
insert into t1 values (1, 1);
162+
163+
if ($have_debug) {
164+
--disable_query_log
165+
--disable_result_log
166+
set debug_dbug='+d,ib_commit_inplace_fail_1';
167+
--error ER_INTERNAL_ERROR
168+
alter table t1 drop column b, algorithm=instant;
169+
set debug_dbug= default;
170+
--enable_query_log
171+
--enable_result_log
172+
}
173+
alter table t1 drop system versioning;
174+
151175
drop database test;
152176
create database test;

storage/innobase/handler/handler0alter.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,14 @@ inline bool dict_table_t::instant_column(const dict_table_t& table,
538538
& ~(DATA_NOT_NULL | DATA_VERSIONED)));
539539
DBUG_ASSERT(c.mtype == o->mtype);
540540
DBUG_ASSERT(c.len >= o->len);
541+
542+
if (o->vers_sys_start()) {
543+
ut_ad(o->ind == vers_start);
544+
vers_start = i;
545+
} else if (o->vers_sys_end()) {
546+
ut_ad(o->ind == vers_end);
547+
vers_end = i;
548+
}
541549
continue;
542550
}
543551

@@ -786,6 +794,16 @@ inline void dict_table_t::rollback_instant(
786794
n_v_def = n_v_cols = old_n_v_cols;
787795
n_t_def = n_t_cols = n_cols + n_v_cols;
788796

797+
if (versioned()) {
798+
for (unsigned i = 0; i < n_cols; ++i) {
799+
if (cols[i].vers_sys_start()) {
800+
vers_start = i;
801+
} else if (cols[i].vers_sys_end()) {
802+
vers_end = i;
803+
}
804+
}
805+
}
806+
789807
index->fields = old_fields;
790808
mtr.commit();
791809

@@ -4116,7 +4134,7 @@ innobase_build_col_map(
41164134
Alter_inplace_info* ha_alter_info,
41174135
const TABLE* altered_table,
41184136
const TABLE* table,
4119-
const dict_table_t* new_table,
4137+
dict_table_t* new_table,
41204138
const dict_table_t* old_table,
41214139
dtuple_t* defaults,
41224140
mem_heap_t* heap)
@@ -4190,6 +4208,13 @@ innobase_build_col_map(
41904208
}
41914209

41924210
col_map[old_i - num_old_v] = i;
4211+
if (old_table->versioned()) {
4212+
if (old_i == old_table->vers_start) {
4213+
new_table->vers_start = i;
4214+
} else if (old_i == old_table->vers_end) {
4215+
new_table->vers_end = i;
4216+
}
4217+
}
41934218
goto found_col;
41944219
}
41954220
}

storage/innobase/include/dict0mem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ struct dict_col_t{
618618
ut_ad(mtype == DATA_INT || mtype == DATA_FIXBINARY);
619619
return mtype == DATA_INT;
620620
}
621-
/** @return whether this is system versioned */
621+
/** @return whether this user column (not row_start, row_end)
622+
has System Versioning property */
622623
bool is_versioned() const { return !(~prtype & DATA_VERSIONED); }
623624
/** @return whether this is the system version start */
624625
bool vers_sys_start() const

0 commit comments

Comments
 (0)