Commit d72462a2 authored by Eugene Kosov's avatar Eugene Kosov

SQL: TRX_ID to TIMESTAMP versioning switch [fixes #428]

parent d1e4c5d1
......@@ -79,6 +79,18 @@ algorithm=copy;
select check_result(count(*) = @tmp) from mysql.transaction_registry;
check_result(count(*) = @tmp)
[CORRECT]
# TRX_ID to TIMESTAMP versioning switch
create or replace table t1 (
x int,
sys_start bigint unsigned as row start invisible,
sys_end bigint unsigned as row end invisible,
period for system_time (sys_start, sys_end)
) engine innodb with system versioning;
insert into t1 values (1);
alter table t1 drop column sys_start, drop column sys_end;
select sys_end = 18446744073709551615 as transaction_based from t1 for system_time all;
transaction_based
1
drop table t1;
set global system_versioning_transaction_registry=off;
drop function check_result;
......@@ -81,6 +81,17 @@ alter table t1
select check_result(count(*) = @tmp) from mysql.transaction_registry;
--echo # TRX_ID to TIMESTAMP versioning switch
create or replace table t1 (
x int,
sys_start bigint unsigned as row start invisible,
sys_end bigint unsigned as row end invisible,
period for system_time (sys_start, sys_end)
) engine innodb with system versioning;
insert into t1 values (1);
alter table t1 drop column sys_start, drop column sys_end;
select sys_end = 18446744073709551615 as transaction_based from t1 for system_time all;
drop table t1;
set global system_versioning_transaction_registry=off;
drop function check_result;
......@@ -6852,8 +6852,7 @@ bool Vers_parse_info::is_end(const Create_field &f) const
return f.flags & VERS_SYS_END_FLAG;
}
static Create_field *vers_init_sys_field(THD *thd, const char *field_name,
int flags)
static Create_field *vers_init_sys_field(THD *thd, const char *field_name, int flags, bool integer)
{
Create_field *f= new (thd->mem_root) Create_field();
if (!f)
......@@ -6864,8 +6863,17 @@ static Create_field *vers_init_sys_field(THD *thd, const char *field_name,
f->field_name.length= strlen(field_name);
f->charset= system_charset_info;
f->flags= flags;
f->set_handler(&type_handler_timestamp2);
f->length= MAX_DATETIME_PRECISION;
if (integer)
{
f->set_handler(&type_handler_longlong);
f->length= MY_INT64_NUM_DECIMAL_DIGITS - 1;
f->flags|= UNSIGNED_FLAG;
}
else
{
f->set_handler(&type_handler_timestamp2);
f->length= MAX_DATETIME_PRECISION;
}
f->invisible= INVISIBLE_SYSTEM;
if (f->check(thd))
......@@ -6877,7 +6885,7 @@ 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,
Alter_info *alter_info, int flags)
{
Create_field *f= vers_init_sys_field(thd, field_name, flags);
Create_field *f= vers_init_sys_field(thd, field_name, flags, false);
if (!f)
return true;
......@@ -6887,23 +6895,6 @@ static bool vers_create_sys_field(THD *thd, const char *field_name,
return false;
}
static bool vers_change_sys_field(THD *thd, const char *field_name,
Alter_info *alter_info, int flags,
const char *change)
{
Create_field *f= vers_init_sys_field(thd, field_name, flags);
if (!f)
return true;
f->change.str= change;
f->change.length= strlen(change);
alter_info->flags|= Alter_info::ALTER_CHANGE_COLUMN;
alter_info->create_list.push_back(f);
return false;
}
const LString Vers_parse_info::default_start= "sys_trx_start";
const LString Vers_parse_info::default_end= "sys_trx_end";
......@@ -7330,11 +7321,15 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
return true;
}
if (vers_change_sys_field(thd, name, alter_info,
f->flags & VERS_SYSTEM_FIELD, name))
{
bool integer= table->vers_start_field()->type() == MYSQL_TYPE_LONGLONG;
Create_field *field= vers_init_sys_field(thd, name, f->flags & VERS_SYSTEM_FIELD, integer);
if (!field)
return true;
}
field->change= f->field_name;
alter_info->flags|= Alter_info::ALTER_CHANGE_COLUMN;
alter_info->create_list.push_back(field);
it.remove();
......
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