Skip to content

Commit 414651c

Browse files
kevgsmidenok
authored andcommitted
SQL: ALTER ADD COLUMN order fix
1 parent 3bdf5b6 commit 414651c

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ show create table t;
7777
Table Create Table
7878
t CREATE TABLE `t` (
7979
`a` int(11) DEFAULT NULL,
80-
`b` int(11) DEFAULT NULL,
8180
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
8281
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
82+
`b` int(11) DEFAULT NULL,
8383
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
8484
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
8585
alter table t add column c int;
8686
show create table t;
8787
Table Create Table
8888
t CREATE TABLE `t` (
8989
`a` int(11) DEFAULT NULL,
90-
`b` int(11) DEFAULT NULL,
91-
`c` int(11) DEFAULT NULL,
9290
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
9391
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
92+
`b` int(11) DEFAULT NULL,
93+
`c` int(11) DEFAULT NULL,
9494
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
9595
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
9696
alter table t add column d int first;
@@ -99,10 +99,10 @@ Table Create Table
9999
t CREATE TABLE `t` (
100100
`d` int(11) DEFAULT NULL,
101101
`a` int(11) DEFAULT NULL,
102-
`b` int(11) DEFAULT NULL,
103-
`c` int(11) DEFAULT NULL,
104102
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
105103
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
104+
`b` int(11) DEFAULT NULL,
105+
`c` int(11) DEFAULT NULL,
106106
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
107107
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
108108
alter table t add column e int after d;
@@ -112,26 +112,22 @@ t CREATE TABLE `t` (
112112
`d` int(11) DEFAULT NULL,
113113
`e` int(11) DEFAULT NULL,
114114
`a` int(11) DEFAULT NULL,
115-
`b` int(11) DEFAULT NULL,
116-
`c` int(11) DEFAULT NULL,
117115
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
118116
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
117+
`b` int(11) DEFAULT NULL,
118+
`c` int(11) DEFAULT NULL,
119119
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
120120
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
121-
alter table t add column f int after sys_trx_start;
122-
ERROR HY000: Wrong parameters for `t`: Can not put new field after system versioning field
123-
alter table t add column f int after sys_trx_end;
124-
ERROR HY000: Wrong parameters for `t`: Can not put new field after system versioning field
125121
alter table t drop column a;
126122
show create table t;
127123
Table Create Table
128124
t CREATE TABLE `t` (
129125
`d` int(11) DEFAULT NULL,
130126
`e` int(11) DEFAULT NULL,
131-
`b` int(11) DEFAULT NULL,
132-
`c` int(11) DEFAULT NULL,
133127
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
134128
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
129+
`b` int(11) DEFAULT NULL,
130+
`c` int(11) DEFAULT NULL,
135131
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
136132
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
137133
alter table t drop column sys_trx_start;
@@ -179,9 +175,9 @@ show create table t;
179175
Table Create Table
180176
t CREATE TABLE `t` (
181177
`a` int(11) DEFAULT NULL,
182-
`b` int(11) DEFAULT NULL,
183178
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
184179
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
180+
`b` int(11) DEFAULT NULL,
185181
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
186182
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
187183
select * from t;
@@ -339,9 +335,9 @@ show create table t;
339335
Table Create Table
340336
t CREATE TABLE `t` (
341337
`a` int(11) DEFAULT NULL,
342-
`b` int(11) DEFAULT NULL,
343338
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
344339
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
340+
`b` int(11) DEFAULT NULL,
345341
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
346342
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
347343
select * from t;
@@ -366,9 +362,9 @@ show create table t;
366362
Table Create Table
367363
t CREATE TABLE `t` (
368364
`a` int(11) DEFAULT NULL,
369-
`b` int(11) DEFAULT NULL,
370365
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
371366
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
367+
`b` int(11) DEFAULT NULL,
372368
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
373369
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
374370
select * from t;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ show create table t;
5959
alter table t add column e int after d;
6060
show create table t;
6161

62-
--error ER_VERS_WRONG_PARAMS
63-
alter table t add column f int after sys_trx_start;
64-
--error ER_VERS_WRONG_PARAMS
65-
alter table t add column f int after sys_trx_end;
66-
6762
alter table t drop column a;
6863
show create table t;
6964

sql/handler.cc

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6874,31 +6874,11 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
68746874

68756875
if (alter_info->create_list.elements)
68766876
{
6877-
DBUG_ASSERT(share->fields > 2);
6878-
const char *after_this= share->field[share->fields - 3]->field_name;
6879-
List_iterator<Create_field> it(alter_info->create_list);
6877+
List_iterator_fast<Create_field> it(alter_info->create_list);
68806878
while (Create_field *f= it++)
68816879
{
68826880
if (f->versioning == Column_definition::WITHOUT_VERSIONING)
68836881
f->flags|= VERS_OPTIMIZED_UPDATE_FLAG;
6884-
6885-
if (f->change)
6886-
continue;
6887-
6888-
if (f->after)
6889-
{
6890-
if (is_trx_start(f->after) || is_trx_end(f->after))
6891-
{
6892-
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
6893-
"Can not put new field after system versioning field");
6894-
return true;
6895-
}
6896-
6897-
continue;
6898-
}
6899-
6900-
// TODO: ALTER_COLUMN_ORDER?
6901-
f->after= after_this;
69026882
}
69036883
}
69046884

0 commit comments

Comments
 (0)