1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

SQL: VTMD for OR REPLACE [fixes #270]

This commit is contained in:
Aleksey Midenkov
2017-09-20 13:07:15 +03:00
parent 9ba635fda3
commit 6c9b71d734
5 changed files with 52 additions and 31 deletions

View File

@@ -37,7 +37,7 @@ set @start= null;
select start from tmp_vtmd for system_time all order by start limit 1 into @start; select start from tmp_vtmd for system_time all order by start limit 1 into @start;
select @start > 0 and @start < @inf; select @start > 0 and @start < @inf;
select select
start + 0 = @start as A_start, start >= @start as A_start,
(@start:= end) and end = @inf as B_end, (@start:= end) and end = @inf as B_end,
name, name,
substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name
@@ -45,12 +45,12 @@ from tmp_vtmd for system_time all;
drop table tmp_vtmd; drop table tmp_vtmd;
end~~ end~~
set versioning_alter_history= keep; set versioning_alter_history= keep;
create or replace table t0 (x int) with system versioning; create table t0 (z int) with system versioning;
show tables; show tables;
Tables_in_test Tables_in_test
t0 t0
set versioning_alter_history= survive; set versioning_alter_history= survive;
create or replace table t0 (x int) with system versioning; create or replace table t0 (y int) with system versioning;
show tables; show tables;
Tables_in_test Tables_in_test
t0 t0
@@ -75,14 +75,18 @@ A_start B_end name C_archive_name
set versioning_alter_history= keep; set versioning_alter_history= keep;
drop table t0; drop table t0;
set versioning_alter_history= survive; set versioning_alter_history= survive;
create or replace table t0 (x int) with system versioning; create table t0 (x int) with system versioning;
ERROR HY000: VTMD error: `test.t0_vtmd` exists and not empty! ERROR HY000: VTMD error: `test.t0_vtmd` exists and not empty!
drop table t0_vtmd;
create table t0 (y int) with system versioning;
create or replace table t0 (x int) with system versioning;
alter table t0 add column (y int); alter table t0 add column (y int);
call check_vtmd('t0_vtmd'); call check_vtmd('t0_vtmd');
@start > 0 and @start < @inf @start > 0 and @start < @inf
1 1
A_start B_end name C_archive_name A_start B_end name C_archive_name
1 0 t0 t0_ 1 0 t0 t0_
1 0 t0 t0_
1 1 t0 NULL 1 1 t0 NULL
call drop_archives('t0_vtmd'); call drop_archives('t0_vtmd');
drop table t0_vtmd; drop table t0_vtmd;

View File

@@ -46,7 +46,7 @@ begin
select start from tmp_vtmd for system_time all order by start limit 1 into @start; select start from tmp_vtmd for system_time all order by start limit 1 into @start;
select @start > 0 and @start < @inf; select @start > 0 and @start < @inf;
select select
start + 0 = @start as A_start, start >= @start as A_start,
(@start:= end) and end = @inf as B_end, (@start:= end) and end = @inf as B_end,
name, name,
substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name
@@ -58,10 +58,10 @@ delimiter ;~~
# create # create
set versioning_alter_history= keep; set versioning_alter_history= keep;
create or replace table t0 (x int) with system versioning; create table t0 (z int) with system versioning;
show tables; show tables;
set versioning_alter_history= survive; set versioning_alter_history= survive;
create or replace table t0 (x int) with system versioning; create or replace table t0 (y int) with system versioning;
show tables; show tables;
show create table t0_vtmd; show create table t0_vtmd;
call check_vtmd('t0_vtmd'); call check_vtmd('t0_vtmd');
@@ -70,6 +70,10 @@ set versioning_alter_history= keep;
drop table t0; drop table t0;
set versioning_alter_history= survive; set versioning_alter_history= survive;
--error ER_VERS_VTMD_ERROR --error ER_VERS_VTMD_ERROR
create table t0 (x int) with system versioning;
drop table t0_vtmd;
create table t0 (y int) with system versioning;
create or replace table t0 (x int) with system versioning; create or replace table t0 (x int) with system versioning;
# alter # alter

View File

@@ -211,7 +211,7 @@ enum vers_hide_enum
enum vers_alter_history_enum enum vers_alter_history_enum
{ {
VERS_ALTER_HISTORY_KEEP, VERS_ALTER_HISTORY_KEEP= 0,
VERS_ALTER_HISTORY_SURVIVE, VERS_ALTER_HISTORY_SURVIVE,
VERS_ALTER_HISTORY_DROP VERS_ALTER_HISTORY_DROP
}; };

View File

@@ -2438,6 +2438,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
else else
{ {
char *end; char *end;
int frm_delete_error= 0;
/* /*
It could happen that table's share in the table definition cache It could happen that table's share in the table definition cache
is the only thing that keeps the engine plugin loaded is the only thing that keeps the engine plugin loaded
@@ -2476,7 +2477,8 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
// Remove extension for delete // Remove extension for delete
*(end= path + path_length - reg_ext_length)= '\0'; *(end= path + path_length - reg_ext_length)= '\0';
if (thd->lex->sql_command == SQLCOM_DROP_TABLE && if ((thd->lex->sql_command == SQLCOM_DROP_TABLE ||
thd->lex->sql_command == SQLCOM_CREATE_TABLE) &&
thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE && thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE &&
table_type && table_type != view_pseudo_hton) table_type && table_type != view_pseudo_hton)
{ {
@@ -2493,29 +2495,33 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
drop_table: drop_table:
error= ha_delete_table(thd, table_type, path, db, table->table_name, error= ha_delete_table(thd, table_type, path, db, table->table_name,
!dont_log_query); !dont_log_query);
if (!error)
{
/* Delete the table definition file */
strmov(end,reg_ext);
if (table_type && table_type != view_pseudo_hton &&
table_type->discover_table)
{
/*
Table type is using discovery and may not need a .frm file.
Delete it silently if it exists
*/
(void) mysql_file_delete(key_file_frm, path, MYF(0));
}
else if (mysql_file_delete(key_file_frm, path,
MYF(MY_WME)))
{
frm_delete_error= my_errno;
DBUG_ASSERT(frm_delete_error);
}
}
} }
if (!error) if (!error)
{ {
int frm_delete_error, trigger_drop_error= 0; int trigger_drop_error= 0;
/* Delete the table definition file */
strmov(end,reg_ext); if (!frm_delete_error)
if (table_type && table_type != view_pseudo_hton &&
table_type->discover_table)
{
/*
Table type is using discovery and may not need a .frm file.
Delete it silently if it exists
*/
(void) mysql_file_delete(key_file_frm, path, MYF(0));
frm_delete_error= 0;
}
else
frm_delete_error= mysql_file_delete(key_file_frm, path,
MYF(MY_WME));
if (frm_delete_error)
frm_delete_error= my_errno;
else
{ {
non_tmp_table_deleted= TRUE; non_tmp_table_deleted= TRUE;
trigger_drop_error= trigger_drop_error=
@@ -2534,7 +2540,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
if (!error && vtmd.exists) if (!error && vtmd.exists)
{ {
enum_sql_command sql_command= thd->lex->sql_command;
thd->lex->sql_command= SQLCOM_DROP_TABLE;
error= vtmd.update(thd); error= vtmd.update(thd);
thd->lex->sql_command= sql_command;
if (error) if (error)
mysql_rename_table(table_type, table->db, vtmd.archive_name(), mysql_rename_table(table_type, table->db, vtmd.archive_name(),
table->db, table->table_name, NO_FK_CHECKS); table->db, table->table_name, NO_FK_CHECKS);
@@ -5081,6 +5090,9 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
VTMD_table vtmd(*create_table); VTMD_table vtmd(*create_table);
if (vtmd.update(thd)) if (vtmd.update(thd))
{ {
thd->variables.vers_alter_history = VERS_ALTER_HISTORY_KEEP;
mysql_rm_table_no_locks(thd, create_table, 0, 0, 0, 0, 1, 1);
thd->variables.vers_alter_history = VERS_ALTER_HISTORY_SURVIVE;
result= 1; result= 1;
goto err; goto err;
} }

View File

@@ -237,10 +237,9 @@ VTMD_table::update(THD *thd, const char* archive_name)
{ {
err: err:
vtmd->file->print_error(error, MYF(0)); vtmd->file->print_error(error, MYF(0));
goto quit;
} }
else
result= false; result= local_da.is_error();
} }
quit: quit:
@@ -436,6 +435,8 @@ VTMD_rename::try_rename(THD *thd, LString new_db, LString new_alias, const char
if (lock_table_names(thd, &vtmd_tl, 0, thd->variables.lock_wait_timeout, 0)) if (lock_table_names(thd, &vtmd_tl, 0, thd->variables.lock_wait_timeout, 0))
return true; return true;
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, about.db, vtmd_name, false); tdc_remove_table(thd, TDC_RT_REMOVE_ALL, about.db, vtmd_name, false);
if (local_da.is_error()) // just safety check
return true;
bool rc= mysql_rename_table(hton, bool rc= mysql_rename_table(hton,
about.db, vtmd_name, about.db, vtmd_name,
new_db, vtmd_new_name, new_db, vtmd_new_name,