Skip to content

Commit

Permalink
SQL: disallow ALTER CHANGE of system fields [fixes #213]
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgs committed Jul 19, 2017
1 parent 909867d commit f8b6256
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mysql-test/suite/versioning/r/alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,22 @@ alter table t without system versioning, algorithm=inplace;
select * from t;
a b
2 NULL
create or replace table t (
a int,
sys_trx_start bigint(20) unsigned generated always as row start,
sys_trx_end bigint(20) unsigned generated always as row end,
period for system_time(sys_trx_start, sys_trx_end)
) with system versioning engine innodb;
alter table t change column sys_trx_start asdf bigint unsigned;
ERROR HY000: Can not change system versioning field 'sys_trx_start'
create or replace table t (
a int,
sys_trx_start timestamp(6) generated always as row start,
sys_trx_end timestamp(6) generated always as row end,
period for system_time(sys_trx_start, sys_trx_end)
) with system versioning engine myisam;
alter table t change column sys_trx_start asdf timestamp(6);
ERROR HY000: Can not change system versioning field 'sys_trx_start'
call verify_vtq;
No A B C D
1 1 1 1 1
Expand Down
18 changes: 18 additions & 0 deletions mysql-test/suite/versioning/t/alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ select * from t for system_time all;
alter table t without system versioning, algorithm=inplace;
select * from t;

create or replace table t (
a int,
sys_trx_start bigint(20) unsigned generated always as row start,
sys_trx_end bigint(20) unsigned generated always as row end,
period for system_time(sys_trx_start, sys_trx_end)
) with system versioning engine innodb;
--error ER_VERS_ALTER_SYSTEM_FIELD
alter table t change column sys_trx_start asdf bigint unsigned;

create or replace table t (
a int,
sys_trx_start timestamp(6) generated always as row start,
sys_trx_end timestamp(6) generated always as row end,
period for system_time(sys_trx_start, sys_trx_end)
) with system versioning engine myisam;
--error ER_VERS_ALTER_SYSTEM_FIELD
alter table t change column sys_trx_start asdf timestamp(6);

call verify_vtq;
drop table t;

Expand Down
6 changes: 6 additions & 0 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6869,6 +6869,12 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
{
if (f->versioning == Column_definition::WITHOUT_VERSIONING)
f->flags|= VERS_OPTIMIZED_UPDATE_FLAG;

if (f->change && (!strcmp(f->change, start) || !strcmp(f->change, end)))
{
my_error(ER_VERS_ALTER_SYSTEM_FIELD, MYF(0), f->change);
return true;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions sql/share/errmsg-utf8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7591,3 +7591,6 @@ ER_VERS_HISTORY_LOCK

ER_WRONG_TABLESPACE_NAME 42000
eng "Incorrect tablespace name `%-.192s`"

ER_VERS_ALTER_SYSTEM_FIELD
eng "Can not change system versioning field '%s'"

0 comments on commit f8b6256

Please sign in to comment.