Commit 9355e3e9 authored by kevg's avatar kevg Committed by Aleksey Midenkov

SQL: CREATE TABLE LIKE for versioned tables [fixes #146]

parent 17745222
......@@ -225,4 +225,15 @@ A int
ERROR HY000: Wrong parameters for `t1`: Versioning specified more than once for the same table
create or replace table t1 (a int) with system versioning;
create temporary table tmp with system versioning select * from t1;
create or replace table t1 (a int) with system versioning;
create table tt1 like t1;
show create table tt1;
Table Create Table
tt1 CREATE TABLE `tt1` (
`a` int(11) DEFAULT NULL,
`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`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
drop table tt1;
drop table t1;
......@@ -207,4 +207,9 @@ create or replace table t1 (
create or replace table t1 (a int) with system versioning;
create temporary table tmp with system versioning select * from t1;
create or replace table t1 (a int) with system versioning;
create table tt1 like t1;
show create table tt1;
drop table tt1;
drop table t1;
......@@ -6850,6 +6850,33 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
check_generated_type(table_name, alter_info, integer_fields)));
}
bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
HA_CREATE_INFO *create_info)
{
List_iterator<Create_field> it(alter_info->create_list);
Create_field *f= NULL;
DBUG_ASSERT(alter_info->create_list.elements > 2);
for (uint i= 0; i < alter_info->create_list.elements - 1; ++i)
f= it++;
DBUG_ASSERT(f->flags & VERS_SYS_START_FLAG);
if (create_string(thd->mem_root, &generated_as_row.start, f->field_name) ||
create_string(thd->mem_root, &period_for_system_time.start,
f->field_name))
return true;
f= it++;
DBUG_ASSERT(f->flags & VERS_SYS_END_FLAG);
if (create_string(thd->mem_root, &generated_as_row.end, f->field_name) ||
create_string(thd->mem_root, &period_for_system_time.end, f->field_name))
return true;
create_info->options|= HA_VERSIONED_TABLE;
return false;
}
bool Vers_parse_info::check_with_conditions(const char *table_name) const
{
if (!generated_as_row.start)
......
......@@ -1723,6 +1723,8 @@ struct Vers_parse_info
bool integer_fields, const char *table_name);
bool check_and_fix_alter(THD *thd, Alter_info *alter_info,
HA_CREATE_INFO *create_info, TABLE_SHARE *share);
bool fix_create_like(THD *thd, Alter_info *alter_info,
HA_CREATE_INFO *create_info);
/** User has added 'WITH SYSTEM VERSIONING' to table definition */
bool declared_with_system_versioning : 1;
......
......@@ -3877,10 +3877,11 @@ mysql_execute_command(THD *thd)
create_info.use_default_db_type(thd);
DBUG_ASSERT(create_info.db_type);
if (create_info.vers_info.check_and_fix_implicit(thd,
&alter_info,
create_info.db_type->flags & HTON_SUPPORTS_SYS_VERSIONING,
create_table->table_name))
if (!create_info.like() &&
create_info.vers_info.check_and_fix_implicit(
thd, &alter_info,
create_info.db_type->flags & HTON_SUPPORTS_SYS_VERSIONING,
create_table->table_name))
{
goto end_with_restore_list;
}
......
......@@ -5378,6 +5378,13 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
thd->work_part_info= src_table->table->part_info->get_clone(thd);
#endif
if (src_table->table->versioned() &&
local_create_info.vers_info.fix_create_like(thd, &local_alter_info,
&local_create_info))
{
goto err;
}
/*
Adjust description of source table before using it for creation of
target table.
......
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