Skip to content

Commit 5c820a7

Browse files
committed
SQL: create_like_table strip versioning for tmp tables [#365 bug 6]
Tests affected (forced versioning): rpl.rpl_row_merge_engine
1 parent b9225bb commit 5c820a7

File tree

5 files changed

+49
-16
lines changed

5 files changed

+49
-16
lines changed

mysql-test/suite/versioning/r/create.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ tt1 CREATE TABLE `tt1` (
281281
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
282282
) ENGINE=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
283283
drop table tt1;
284+
create temporary table tt1 like t1;
285+
Warnings:
286+
Warning 1105 System versioning is stripped from temporary `test.tt1`
287+
# Temporary is stripped from versioning
288+
show create table tt1;
289+
Table Create Table
290+
tt1 CREATE TEMPORARY TABLE `tt1` (
291+
`a` int(11) DEFAULT NULL
292+
) ENGINE=INNODB_OR_MYISAM DEFAULT CHARSET=latin1
284293
create or replace table t1 (x int) with system versioning;
285294
create or replace table t0(
286295
y int,

mysql-test/suite/versioning/t/create.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ create table tt1 like t1;
198198
--replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM "bigint(20) unsigned" SYS_TRX_TYPE timestamp(6) SYS_TRX_TYPE
199199
show create table tt1;
200200
drop table tt1;
201+
create temporary table tt1 like t1;
202+
--echo # Temporary is stripped from versioning
203+
--replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM
204+
show create table tt1;
201205

202206
# CREATE TABLE ... SELECT
203207
create or replace table t1 (x int) with system versioning;

sql/handler.cc

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7138,13 +7138,34 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
71387138
check_generated_type(table_name, alter_info, integer_fields)));
71397139
}
71407140

7141-
bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
7142-
HA_CREATE_INFO *create_info, TABLE_LIST *table)
7141+
bool
7142+
Vers_parse_info::fix_create_like(Alter_info &alter_info, HA_CREATE_INFO &create_info,
7143+
TABLE_LIST &src_table, TABLE_LIST &table)
71437144
{
7144-
List_iterator<Create_field> it(alter_info->create_list);
7145+
List_iterator<Create_field> it(alter_info.create_list);
71457146
Create_field *f, *f_start=NULL, *f_end= NULL;
71467147

7147-
DBUG_ASSERT(alter_info->create_list.elements > 2);
7148+
DBUG_ASSERT(alter_info.create_list.elements > 2);
7149+
7150+
if (create_info.tmp_table())
7151+
{
7152+
int remove= 2;
7153+
while (remove && (f= it++))
7154+
{
7155+
if (f->flags & (VERS_SYS_START_FLAG|VERS_SYS_END_FLAG))
7156+
{
7157+
it.remove();
7158+
remove--;
7159+
}
7160+
}
7161+
DBUG_ASSERT(remove == 0);
7162+
push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
7163+
ER_UNKNOWN_ERROR,
7164+
"System versioning is stripped from temporary `%s.%s`",
7165+
table.db, table.table_name);
7166+
return false;
7167+
}
7168+
71487169
while ((f= it++))
71497170
{
71507171
if (f->flags & VERS_SYS_START_FLAG)
@@ -7163,15 +7184,15 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
71637184

71647185
if (!f_start || !f_end)
71657186
{
7166-
my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), table->table_name,
7187+
my_error_as(ER_VERS_WRONG_PARAMS, ER_MISSING, MYF(0), src_table.table_name,
71677188
f_start ? "AS ROW END" : "AS ROW START");
71687189
return true;
71697190
}
71707191

71717192
as_row= start_end_t(f_start->field_name, f_end->field_name);
71727193
system_time= as_row;
71737194

7174-
create_info->options|= HA_VERSIONED_TABLE;
7195+
create_info.options|= HA_VERSIONED_TABLE;
71757196
return false;
71767197
}
71777198

sql/handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ struct Vers_parse_info
17471747
const char *table_name);
17481748
bool check_and_fix_alter(THD *thd, Alter_info *alter_info,
17491749
HA_CREATE_INFO *create_info, TABLE *table);
1750-
bool fix_create_like(THD *thd, Alter_info *alter_info,
1751-
HA_CREATE_INFO *create_info, TABLE_LIST *table);
1750+
bool fix_create_like(Alter_info &alter_info, HA_CREATE_INFO &create_info,
1751+
TABLE_LIST &src_table, TABLE_LIST &table);
17521752

17531753
/** User has added 'WITH SYSTEM VERSIONING' to table definition */
17541754
bool with_system_versioning : 1;

sql/sql_table.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,13 +5502,6 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
55025502
thd->work_part_info= src_table->table->part_info->get_clone(thd);
55035503
#endif
55045504

5505-
if (src_table->table->versioned() &&
5506-
local_create_info.vers_info.fix_create_like(thd, &local_alter_info,
5507-
&local_create_info, src_table))
5508-
{
5509-
goto err;
5510-
}
5511-
55125505
/*
55135506
Adjust description of source table before using it for creation of
55145507
target table.
@@ -5520,7 +5513,6 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
55205513
local_create_info.max_rows= 0;
55215514
/* Replace type of source table with one specified in the statement. */
55225515
local_create_info.options&= ~HA_LEX_CREATE_TMP_TABLE;
5523-
local_create_info.options|= create_info->tmp_table();
55245516
local_create_info.options|= create_info->options;
55255517
/* Reset auto-increment counter for the new table. */
55265518
local_create_info.auto_increment_value= 0;
@@ -5530,6 +5522,13 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
55305522
*/
55315523
local_create_info.data_file_name= local_create_info.index_file_name= NULL;
55325524

5525+
if (src_table->table->versioned() &&
5526+
local_create_info.vers_info.fix_create_like(local_alter_info, local_create_info,
5527+
*src_table, *table))
5528+
{
5529+
goto err;
5530+
}
5531+
55335532
/* The following is needed only in case of lock tables */
55345533
if ((local_create_info.table= thd->lex->query_tables->table))
55355534
pos_in_locked_tables= local_create_info.table->pos_in_locked_tables;

0 commit comments

Comments
 (0)