Commit 229c5281 authored by Eugene Kosov's avatar Eugene Kosov Committed by Aleksey Midenkov

SQL: hide system fields instead of drop [closes #210]

parent 46d572dd
......@@ -130,10 +130,33 @@ t CREATE TABLE `t` (
`c` int(11) DEFAULT NULL,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
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 for system_time all;
a sys_trx_start sys_trx_end
alter table t drop column sys_trx_start;
alter table t drop column sys_trx_end;
select * from t for system_time all;
a
alter table t drop column sys_trx_start;
ERROR HY000: Wrong parameters for `t`: Can not drop system versioning field
ERROR 42000: Can't DROP COLUMN `sys_trx_start`; check that it exists
alter table t drop column sys_trx_end;
ERROR HY000: Wrong parameters for `t`: Can not drop system versioning field
ERROR 42000: Can't DROP COLUMN `sys_trx_end`; check that it exists
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 for system_time all;
a sys_trx_start sys_trx_end
alter table t drop column sys_trx_start, drop column sys_trx_end;
select * from t for system_time all;
a
create or replace table t(
a int
);
......
......@@ -62,10 +62,33 @@ show create table t;
alter table t drop column a;
show create table t;
--error ER_VERS_WRONG_PARAMS
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 for system_time all;
alter table t drop column sys_trx_start;
--error ER_VERS_WRONG_PARAMS
alter table t drop column sys_trx_end;
select * from t for system_time all;
--error ER_CANT_DROP_FIELD_OR_KEY
alter table t drop column sys_trx_start;
--error ER_CANT_DROP_FIELD_OR_KEY
alter table t drop column sys_trx_end;
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 for system_time all;
alter table t drop column sys_trx_start, drop column sys_trx_end;
select * from t for system_time all;
create or replace table t(
a int
......
......@@ -6630,6 +6630,7 @@ static bool vers_create_sys_field(THD *thd, const char *field_name,
return true;
alter_info->create_list.push_back(f);
alter_info->flags|= Alter_info::ALTER_ADD_COLUMN;
return false;
}
......@@ -6885,15 +6886,41 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
if (alter_info->drop_list.elements)
{
bool done_start= false;
bool done_end= false;
List_iterator<Alter_drop> it(alter_info->drop_list);
while (Alter_drop* d= it++)
while (Alter_drop *d= it++)
{
if (is_trx_start(d->name) || is_trx_end(d->name))
const char *name= d->name;
Field *f= NULL;
if (!done_start && is_trx_start(name))
{
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
"Can not drop system versioning field");
f= share->vers_start_field();
done_start= true;
}
else if (!done_end && is_trx_end(name))
{
f= share->vers_end_field();
done_end= true;
}
else
continue;
if (f->flags & HIDDEN_FLAG)
{
my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), d->type_name(), name);
return true;
}
if (vers_create_sys_field(thd, name, alter_info,
f->flags &
(VERS_SYS_START_FLAG | VERS_SYS_END_FLAG),
integer_fields))
{
return true;
}
if (done_start && done_end)
break;
}
}
......
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