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:
@ -225,4 +225,15 @@ A int
|
|||||||
ERROR HY000: Wrong parameters for `t1`: Versioning specified more than once for the same table
|
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 or replace table t1 (a int) with system versioning;
|
||||||
create temporary table tmp with system versioning select * from t1;
|
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;
|
drop table t1;
|
||||||
|
@ -207,4 +207,9 @@ create or replace table t1 (
|
|||||||
create or replace table t1 (a int) with system versioning;
|
create or replace table t1 (a int) with system versioning;
|
||||||
create temporary table tmp with system versioning select * from t1;
|
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;
|
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)));
|
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
|
bool Vers_parse_info::check_with_conditions(const char *table_name) const
|
||||||
{
|
{
|
||||||
if (!generated_as_row.start)
|
if (!generated_as_row.start)
|
||||||
|
@ -1723,6 +1723,8 @@ public:
|
|||||||
bool integer_fields, const char *table_name);
|
bool integer_fields, const char *table_name);
|
||||||
bool check_and_fix_alter(THD *thd, Alter_info *alter_info,
|
bool check_and_fix_alter(THD *thd, Alter_info *alter_info,
|
||||||
HA_CREATE_INFO *create_info, TABLE_SHARE *share);
|
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 */
|
/** User has added 'WITH SYSTEM VERSIONING' to table definition */
|
||||||
bool declared_with_system_versioning : 1;
|
bool declared_with_system_versioning : 1;
|
||||||
|
@ -3877,10 +3877,11 @@ mysql_execute_command(THD *thd)
|
|||||||
create_info.use_default_db_type(thd);
|
create_info.use_default_db_type(thd);
|
||||||
|
|
||||||
DBUG_ASSERT(create_info.db_type);
|
DBUG_ASSERT(create_info.db_type);
|
||||||
if (create_info.vers_info.check_and_fix_implicit(thd,
|
if (!create_info.like() &&
|
||||||
&alter_info,
|
create_info.vers_info.check_and_fix_implicit(
|
||||||
create_info.db_type->flags & HTON_SUPPORTS_SYS_VERSIONING,
|
thd, &alter_info,
|
||||||
create_table->table_name))
|
create_info.db_type->flags & HTON_SUPPORTS_SYS_VERSIONING,
|
||||||
|
create_table->table_name))
|
||||||
{
|
{
|
||||||
goto end_with_restore_list;
|
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);
|
thd->work_part_info= src_table->table->part_info->get_clone(thd);
|
||||||
#endif
|
#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
|
Adjust description of source table before using it for creation of
|
||||||
target table.
|
target table.
|
||||||
|
Reference in New Issue
Block a user