Commit 5ce6044b authored by Eugene Kosov's avatar Eugene Kosov Committed by Aleksey Midenkov

SQL: remove versioning only when hidden system fields

[closes #211]
parent c2c8808a
...@@ -57,6 +57,7 @@ t CREATE TABLE `t` ( ...@@ -57,6 +57,7 @@ t CREATE TABLE `t` (
`trx_end` timestamp(6) GENERATED ALWAYS AS ROW END, `trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`trx_start`, `trx_end`) PERIOD FOR SYSTEM_TIME (`trx_start`, `trx_end`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
alter table t drop column trx_start, drop column trx_end;
alter table t without system versioning; alter table t without system versioning;
show create table t; show create table t;
Table Create Table Table Create Table
...@@ -338,6 +339,7 @@ t CREATE TABLE `t` ( ...@@ -338,6 +339,7 @@ t CREATE TABLE `t` (
`trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END, `trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`trx_start`, `trx_end`) PERIOD FOR SYSTEM_TIME (`trx_start`, `trx_end`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING ) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
alter table t drop column trx_start, drop column trx_end;
alter table t without system versioning; alter table t without system versioning;
alter table t with system versioning, algorithm=copy; alter table t with system versioning, algorithm=copy;
show create table t; show create table t;
...@@ -511,6 +513,30 @@ period for system_time(sys_trx_start, sys_trx_end) ...@@ -511,6 +513,30 @@ period for system_time(sys_trx_start, sys_trx_end)
) with system versioning engine myisam; ) with system versioning engine myisam;
alter table t change column sys_trx_start asdf timestamp(6); alter table t change column sys_trx_start asdf timestamp(6);
ERROR HY000: Can not change system versioning field 'sys_trx_start' 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;
select * from t;
a sys_trx_start sys_trx_end
alter table t without system versioning;
ERROR HY000: System versioning field 'sys_trx_start' is not hidden
alter table t drop column sys_trx_start;
select * from t;
a sys_trx_end
alter table t without system versioning;
ERROR HY000: System versioning field 'sys_trx_end' is not hidden
alter table t drop column sys_trx_end;
select * from t;
a
alter table t without system versioning;
show create table t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
call verify_vtq; call verify_vtq;
No A B C D No A B C D
1 1 1 1 1 1 1 1 1 1
......
...@@ -41,6 +41,7 @@ alter table t ...@@ -41,6 +41,7 @@ alter table t
with system versioning; with system versioning;
show create table t; show create table t;
alter table t drop column trx_start, drop column trx_end;
alter table t without system versioning; alter table t without system versioning;
show create table t; show create table t;
...@@ -150,6 +151,7 @@ alter table t ...@@ -150,6 +151,7 @@ alter table t
add period for system_time(trx_start, trx_end), add period for system_time(trx_start, trx_end),
with system versioning; with system versioning;
show create table t; show create table t;
alter table t drop column trx_start, drop column trx_end;
alter table t without system versioning; alter table t without system versioning;
alter table t with system versioning, algorithm=copy; alter table t with system versioning, algorithm=copy;
...@@ -238,6 +240,27 @@ create or replace table t ( ...@@ -238,6 +240,27 @@ create or replace table t (
--error ER_VERS_ALTER_SYSTEM_FIELD --error ER_VERS_ALTER_SYSTEM_FIELD
alter table t change column sys_trx_start asdf timestamp(6); alter table t change column sys_trx_start asdf timestamp(6);
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;
select * from t;
--error ER_VERS_SYS_FIELD_NOT_HIDDEN
alter table t without system versioning;
alter table t drop column sys_trx_start;
select * from t;
--error ER_VERS_SYS_FIELD_NOT_HIDDEN
alter table t without system versioning;
alter table t drop column sys_trx_end;
select * from t;
alter table t without system versioning;
show create table t;
call verify_vtq; call verify_vtq;
drop table t; drop table t;
......
...@@ -6603,15 +6603,12 @@ bool Vers_parse_info::is_trx_end(const Create_field &f) const ...@@ -6603,15 +6603,12 @@ bool Vers_parse_info::is_trx_end(const Create_field &f) const
return f.flags & VERS_SYS_END_FLAG; return f.flags & VERS_SYS_END_FLAG;
} }
static Create_field *vers_init_sys_field(THD *thd, const char *field_name,
static bool vers_create_sys_field(THD *thd, const char *field_name, int flags, bool integer_fields)
Alter_info *alter_info,
int flags,
bool integer_fields)
{ {
Create_field *f= new (thd->mem_root) Create_field(); Create_field *f= new (thd->mem_root) Create_field();
if (!f) if (!f)
return true; return NULL;
memset(f, 0, sizeof(*f)); memset(f, 0, sizeof(*f));
f->field_name= field_name; f->field_name= field_name;
...@@ -6630,10 +6627,38 @@ static bool vers_create_sys_field(THD *thd, const char *field_name, ...@@ -6630,10 +6627,38 @@ static bool vers_create_sys_field(THD *thd, const char *field_name,
} }
if (f->check(thd)) if (f->check(thd))
return NULL;
return f;
}
static bool vers_create_sys_field(THD *thd, const char *field_name,
Alter_info *alter_info, int flags,
bool integer_fields)
{
Create_field *f= vers_init_sys_field(thd, field_name, flags, integer_fields);
if (!f)
return true; return true;
alter_info->create_list.push_back(f);
alter_info->flags|= Alter_info::ALTER_ADD_COLUMN; alter_info->flags|= Alter_info::ALTER_ADD_COLUMN;
alter_info->create_list.push_back(f);
return false;
}
static bool vers_change_sys_field(THD *thd, const char *field_name,
Alter_info *alter_info, int flags,
bool integer_fields, const char *change)
{
Create_field *f= vers_init_sys_field(thd, field_name, flags, integer_fields);
if (!f)
return true;
f->change= change;
alter_info->flags|= Alter_info::ALTER_CHANGE_COLUMN;
alter_info->create_list.push_back(f);
return false; return false;
} }
...@@ -6814,6 +6839,7 @@ static bool add_field_to_drop_list(THD *thd, Alter_info *alter_info, ...@@ -6814,6 +6839,7 @@ static bool add_field_to_drop_list(THD *thd, Alter_info *alter_info,
{ {
DBUG_ASSERT(field); DBUG_ASSERT(field);
DBUG_ASSERT(field->field_name); DBUG_ASSERT(field->field_name);
alter_info->flags|= Alter_info::ALTER_DROP_COLUMN;
Alter_drop *ad= new (thd->mem_root) Alter_drop *ad= new (thd->mem_root)
Alter_drop(Alter_drop::COLUMN, field->field_name, false); Alter_drop(Alter_drop::COLUMN, field->field_name, false);
return !ad || alter_info->drop_list.push_back(ad, thd->mem_root); return !ad || alter_info->drop_list.push_back(ad, thd->mem_root);
...@@ -6838,11 +6864,23 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info, ...@@ -6838,11 +6864,23 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
return true; return true;
} }
if (!(share->vers_start_field()->flags & HIDDEN_FLAG))
{
my_error(ER_VERS_SYS_FIELD_NOT_HIDDEN, MYF(0),
share->vers_start_field()->field_name);
return true;
}
if (!(share->vers_end_field()->flags & HIDDEN_FLAG))
{
my_error(ER_VERS_SYS_FIELD_NOT_HIDDEN, MYF(0),
share->vers_end_field()->field_name);
return true;
}
if (add_field_to_drop_list(thd, alter_info, share->vers_start_field()) || if (add_field_to_drop_list(thd, alter_info, share->vers_start_field()) ||
add_field_to_drop_list(thd, alter_info, share->vers_end_field())) add_field_to_drop_list(thd, alter_info, share->vers_end_field()))
return true; return true;
alter_info->flags|= Alter_info::ALTER_DROP_COLUMN;
return false; return false;
} }
...@@ -6908,14 +6946,16 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info, ...@@ -6908,14 +6946,16 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
return true; return true;
} }
if (vers_create_sys_field(thd, name, alter_info, if (vers_change_sys_field(thd, name, alter_info,
f->flags & f->flags &
(VERS_SYS_START_FLAG | VERS_SYS_END_FLAG), (VERS_SYS_START_FLAG | VERS_SYS_END_FLAG),
integer_fields)) integer_fields, name))
{ {
return true; return true;
} }
it.remove();
if (done_start && done_end) if (done_start && done_end)
break; break;
} }
......
...@@ -7597,3 +7597,6 @@ ER_WRONG_TABLESPACE_NAME 42000 ...@@ -7597,3 +7597,6 @@ ER_WRONG_TABLESPACE_NAME 42000
ER_VERS_ALTER_SYSTEM_FIELD ER_VERS_ALTER_SYSTEM_FIELD
eng "Can not change system versioning field '%s'" eng "Can not change system versioning field '%s'"
ER_VERS_SYS_FIELD_NOT_HIDDEN
eng "System versioning field '%s' is not hidden"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment