Commit ee3cf23b authored by unknown's avatar unknown

Fix for bug#14945 "Truncate table doesn't reset the auto_increment

counter".

When TRUNCATE TABLE was called within an stored procedure the
auto_increment counter was not reset to 0 even if straight
TRUNCATE for this table did this.

This fix makes TRUNCATE in stored procedures to be handled exactly
in the same way as straight TRUNCATE. We achieve this by rolling
back the fix for bug 8850, which is no longer needed since stored
procedures don't require prelocked mode anymore (and TRUNCATE is
not allowed in stored functions or triggers).


mysql-test/r/sp.result:
  Test case for BUG#14945.
mysql-test/t/sp.test:
  Test case for BUG#14945.
sql/sql_delete.cc:
  Handle TRUNCATE in stored procedures exactly in the same way as straight
  TRUNCATE (i.e. without falling back to DELETE if possible). We achieve
  this by rolling back the fix for bug 8850, which is no longer relevant
  since stored procedures don't require prelocked mode anymore
  (and TRUNCATE is not allowed in stored functions or triggers).
sql/sql_parse.cc:
  Handle TRUNCATE in stored procedures exactly in the same way as straight
  TRUNCATE (i.e. without falling back to DELETE if possible). We achieve
  this by rolling back the fix for bug 8850, which is no longer relevant
  since stored procedures don't require prelocked mode anymore
  (and TRUNCATE is not allowed in stored functions or triggers).
parent 66ac19e2
...@@ -4811,6 +4811,17 @@ begin ...@@ -4811,6 +4811,17 @@ begin
declare x int; declare x int;
select id from t1 order by x; select id from t1 order by x;
end| end|
drop procedure if exists bug14945|
create table t3 (id int not null auto_increment primary key)|
create procedure bug14945() deterministic truncate t3|
insert into t3 values (null)|
call bug14945()|
insert into t3 values (null)|
select * from t3|
id
1
drop table t3|
drop procedure bug14945|
create procedure bug16474_2(x int) create procedure bug16474_2(x int)
select id from t1 order by x| select id from t1 order by x|
call bug16474_1()| call bug16474_1()|
......
...@@ -5666,6 +5666,21 @@ begin ...@@ -5666,6 +5666,21 @@ begin
select id from t1 order by x; select id from t1 order by x;
end| end|
#
# BUG#14945: Truncate table doesn't reset the auto_increment counter
#
--disable_warnings
drop procedure if exists bug14945|
--enable_warnings
create table t3 (id int not null auto_increment primary key)|
create procedure bug14945() deterministic truncate t3|
insert into t3 values (null)|
call bug14945()|
insert into t3 values (null)|
select * from t3|
drop table t3|
drop procedure bug14945|
# This does NOT order by column index; variable is an expression. # This does NOT order by column index; variable is an expression.
create procedure bug16474_2(x int) create procedure bug16474_2(x int)
select id from t1 order by x| select id from t1 order by x|
......
...@@ -842,8 +842,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -842,8 +842,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
table_list->db, table_list->table_name); table_list->db, table_list->table_name);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE) if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
|| thd->lex->sphead)
goto trunc_by_del; goto trunc_by_del;
if (lock_and_wait_for_table_name(thd, table_list)) if (lock_and_wait_for_table_name(thd, table_list))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
......
...@@ -3350,7 +3350,7 @@ mysql_execute_command(THD *thd) ...@@ -3350,7 +3350,7 @@ mysql_execute_command(THD *thd)
Don't allow this within a transaction because we want to use Don't allow this within a transaction because we want to use
re-generate table re-generate table
*/ */
if ((thd->locked_tables && !lex->sphead) || thd->active_transaction()) if (thd->locked_tables || thd->active_transaction())
{ {
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
......
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