1--source suite/versioning/innodb.inc
2--source suite/versioning/common.inc
3--source include/maybe_debug.inc
4
5set system_versioning_alter_history=keep;
6
7create or replace table t (a int);
8--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
9alter table t add system versioning, lock=none;
10--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
11alter table t add system versioning, algorithm=inplace;
12alter table t add system versioning, lock=shared;
13
14alter table t add column b int, change column a a int without system versioning, lock=none;
15--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
16alter table t drop system versioning, lock=none;
17alter table t drop system versioning, algorithm=inplace;
18
19--replace_result $sys_datatype_expl SYS_DATATYPE
20eval create or replace table t (
21  a int, b int,
22  row_start $sys_datatype_expl as row start invisible,
23  row_end $sys_datatype_expl as row end invisible,
24  period for system_time (row_start, row_end)
25) with system versioning;
26insert into t values (1, 0);
27insert into t values (2, 0);
28delete from t where a = 2;
29alter table t drop column b, lock=none;
30alter table t add index idx(a), lock=none;
31
32select a, check_row(row_start, row_end) from t for system_time all order by a;
33
34--echo # MDEV-17038 ALTER TABLE CHANGE COLUMN c1 c1 bigint NOT NULL -
35--echo # generates error if table uses SYSTEM VERSIONING [tempesta-tech/mariadb#540]
36create or replace table t1 (a int, key(a)) with system versioning;
37create or replace table t2 like t;
38alter table t2 add foreign key(a) references t1(a);
39alter table t2 modify column a int not null, lock=none;
40
41drop table t2;
42drop table t1;
43
44--echo # MDEV-16330 Allow instant change of WITH SYSTEM VERSIONING column attribute
45--replace_result $sys_datatype_expl SYS_DATATYPE
46eval create or replace table t1 (
47  a int,
48  b int,
49  row_start $sys_datatype_expl as row start invisible,
50  row_end $sys_datatype_expl as row end invisible,
51  period for system_time(row_start, row_end)
52) with system versioning;
53
54--replace_result $sys_datatype_expl SYS_DATATYPE
55eval create or replace table t2 (
56  a int without system versioning,
57  b int,
58  row_start $sys_datatype_expl as row start invisible,
59  row_end $sys_datatype_expl as row end invisible,
60  period for system_time(row_start, row_end)
61) with system versioning;
62
63insert into t1 values (1,1);
64insert into t2 values (1,1);
65
66set @@system_versioning_alter_history=keep;
67
68--enable_info
69--echo # without rebuild
70alter table t1
71  change a a int without system versioning,
72  algorithm=instant;
73
74--error ER_ALTER_OPERATION_NOT_SUPPORTED
75alter table t2
76  change a a int with system versioning,
77  add primary key pk (a),
78  algorithm=instant;
79
80--echo # with rebuild
81alter table t2
82  change a a int with system versioning,
83  add primary key pk (a);
84--disable_info
85
86--source include/restart_mysqld.inc
87
88update t1 set a=2;
89select count(*) from t1 for system_time all;
90
91update t2 set a=2;
92select count(*) from t2 for system_time all;
93
94drop table t1, t2;
95
96--echo # rollback ALTER TABLE: nothing should change
97--replace_result $sys_datatype_expl SYS_DATATYPE
98eval create or replace table t (
99  a int,
100  b int,
101  row_start $sys_datatype_expl as row start invisible,
102  row_end $sys_datatype_expl as row end invisible,
103  period for system_time(row_start, row_end)
104) with system versioning;
105
106insert into t values (1, 1);
107
108select c.prtype from information_schema.innodb_sys_columns as c
109  join information_schema.innodb_sys_tables as t on c.table_id=t.table_id
110  where t.name='test/t' and c.name='b';
111
112set @@system_versioning_alter_history=keep;
113
114if ($have_debug) {
115--disable_query_log
116--disable_result_log
117set debug_dbug='+d,ib_commit_inplace_fail_1';
118--error ER_INTERNAL_ERROR
119alter table t
120  change b b int without system versioning;
121set debug_dbug= default;
122--enable_query_log
123--enable_result_log
124}
125
126select c.prtype from information_schema.innodb_sys_columns as c
127  join information_schema.innodb_sys_tables as t on c.table_id=t.table_id
128  where t.name='test/t' and c.name='b';
129
130--replace_result $sys_datatype_expl SYS_DATATYPE
131show create table t;
132
133select count(*) from t for system_time all;
134update t set b=11;
135select count(*) from t for system_time all;
136drop table t;
137
138--echo # Start of 10.4 tests
139
140create or replace table t (a int, b int) engine=innodb;
141alter table t
142  add s bigint unsigned as row start,
143  add e bigint unsigned as row end,
144  add period for system_time(s, e),
145  add system versioning;
146alter table t drop column b, algorithm=instant;
147alter table t add index idx(a), lock=none;
148alter table t drop column s, drop column e;
149--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
150alter table t drop system versioning, lock=none;
151
152--echo #
153--echo # MDEV-17697 Broken versioning info after instant drop column
154--echo #
155set @@system_versioning_alter_history= keep;
156create or replace table t1 (a int, b int) with system versioning;
157insert into t1 values (1, 1);
158alter table t1 drop column b, algorithm=instant;
159alter table t1 drop system versioning;
160
161create or replace table t1 (a int, b int) with system versioning;
162insert into t1 values (1, 1);
163
164if ($have_debug) {
165--disable_query_log
166--disable_result_log
167set debug_dbug='+d,ib_commit_inplace_fail_1';
168--error ER_INTERNAL_ERROR
169alter table t1 drop column b, algorithm=instant;
170set debug_dbug= default;
171--enable_query_log
172--enable_result_log
173}
174alter table t1 drop system versioning;
175
176--echo #
177--echo # MDEV-18173 Assertion `o->ind == vers_end' or `o->ind == vers_start' failed in dict_table_t::instant_column
178--echo #
179set @@system_versioning_alter_history= keep;
180create or replace table t1 (pk integer primary key, a int, b int, v int as (a))
181with system versioning;
182
183alter table t1 force;
184alter table t1 drop column b;
185
186--echo #
187--echo # MDEV-18122 Assertion `table->versioned() == m_prebuilt->table->versioned()' failed in ha_innobase::open
188--echo #
189create or replace table t1 (
190  x int,
191  v int as (x) virtual,
192  y int
193) with system versioning;
194alter table t1 drop system versioning;
195
196drop tables t, t1;
197
198--source suite/versioning/common_finish.inc
199