Commit 6318e449 authored by unknown's avatar unknown

Bug#11816 - Truncate table doesn't work with temporary innodb tables

Handle temporary tables like permanent tables: If the storage engine
cannot truncate, delete instead.


mysql-test/r/innodb.result:
  Bug#11816 - Truncate table doesn't work with temporary innodb tables
  The test result.
mysql-test/t/innodb.test:
  Bug#11816 - Truncate table doesn't work with temporary innodb tables
  The test case.
sql/sql_delete.cc:
  Bug#11816 - Truncate table doesn't work with temporary innodb tables
  Handle temporary tables like permanent tables: If the storage engine
  cannot truncate, delete instead.
  Replaced a numeric literal by its symbolic name.
parent 0f7161b0
...@@ -1658,3 +1658,19 @@ a_id b_list ...@@ -1658,3 +1658,19 @@ a_id b_list
3 NULL 3 NULL
DROP TABLE t2; DROP TABLE t2;
DROP TABLE t1; DROP TABLE t1;
create temporary table t1 (a int) engine=innodb;
insert into t1 values (4711);
truncate t1;
insert into t1 values (42);
select * from t1;
a
42
drop table t1;
create table t1 (a int) engine=innodb;
insert into t1 values (4711);
truncate t1;
insert into t1 values (42);
select * from t1;
a
42
drop table t1;
...@@ -1202,4 +1202,22 @@ SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t ...@@ -1202,4 +1202,22 @@ SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t
DROP TABLE t2; DROP TABLE t2;
DROP TABLE t1; DROP TABLE t1;
#
# Bug#11816 - Truncate table doesn't work with temporary innodb tables
# This is not an innodb bug, but we test it using innodb.
#
create temporary table t1 (a int) engine=innodb;
insert into t1 values (4711);
truncate t1;
insert into t1 values (42);
select * from t1;
drop table t1;
# Show that it works with permanent tables too.
create table t1 (a int) engine=innodb;
insert into t1 values (4711);
truncate t1;
insert into t1 values (42);
select * from t1;
drop table t1;
# End of 4.1 tests # End of 4.1 tests
...@@ -617,6 +617,8 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -617,6 +617,8 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
TABLE *table= *table_ptr; TABLE *table= *table_ptr;
table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK); table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
db_type table_type=table->db_type; db_type table_type=table->db_type;
if (!ha_supports_generate(table_type))
goto trunc_by_del;
strmov(path,table->path); strmov(path,table->path);
*table_ptr= table->next; // Unlink table from list *table_ptr= table->next; // Unlink table from list
close_temporary(table,0); close_temporary(table,0);
...@@ -635,7 +637,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -635,7 +637,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
(void) sprintf(path,"%s/%s/%s%s",mysql_data_home,table_list->db, (void) sprintf(path,"%s/%s/%s%s",mysql_data_home,table_list->db,
table_list->real_name,reg_ext); table_list->real_name,reg_ext);
fn_format(path,path,"","",4); fn_format(path, path, "", "", MY_UNPACK_FILENAME);
if (!dont_send_ok) if (!dont_send_ok)
{ {
...@@ -647,18 +649,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -647,18 +649,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
if (!ha_supports_generate(table_type)) if (!ha_supports_generate(table_type))
{ goto trunc_by_del;
/* Probably InnoDB table */
ulong save_options= thd->options;
table_list->lock_type= TL_WRITE;
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
ha_enable_transaction(thd, FALSE);
error= mysql_delete(thd, table_list, (COND*) 0, (SQL_LIST*) 0,
HA_POS_ERROR, 0);
ha_enable_transaction(thd, TRUE);
thd->options= save_options;
DBUG_RETURN(error);
}
if (lock_and_wait_for_table_name(thd, table_list)) if (lock_and_wait_for_table_name(thd, table_list))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -693,4 +684,16 @@ end: ...@@ -693,4 +684,16 @@ end:
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
} }
DBUG_RETURN(error ? -1 : 0); DBUG_RETURN(error ? -1 : 0);
trunc_by_del:
/* Probably InnoDB table */
ulong save_options= thd->options;
table_list->lock_type= TL_WRITE;
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
ha_enable_transaction(thd, FALSE);
error= mysql_delete(thd, table_list, (COND*) 0, (SQL_LIST*) 0,
HA_POS_ERROR, 0);
ha_enable_transaction(thd, TRUE);
thd->options= save_options;
DBUG_RETURN(error);
} }
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