1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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

This commit is contained in:
kevg
2017-03-06 15:53:53 +03:00
committed by Aleksey Midenkov
parent 17745222a1
commit 9355e3e966
6 changed files with 57 additions and 4 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -1723,6 +1723,8 @@ public:
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;

View File

@ -3877,8 +3877,9 @@ 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,
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))
{

View File

@ -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.