diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index c75bce6580f..4468991c0ef 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -4821,6 +4821,17 @@ begin declare x int; select id from t1 order by x; 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) select id from t1 order by x| call bug16474_1()| diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index fe306126e45..29e657004ed 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5672,6 +5672,21 @@ begin select id from t1 order by x; 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. create procedure bug16474_2(x int) select id from t1 order by x| diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 181b91781d7..804270992e5 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -916,8 +916,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) DBUG_RETURN(TRUE); } if (!ha_check_storage_engine_flag(ha_resolve_by_legacy_type(thd, table_type), - HTON_CAN_RECREATE) - || thd->lex->sphead) + HTON_CAN_RECREATE)) goto trunc_by_del; if (lock_and_wait_for_table_name(thd, table_list)) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c33257ff602..51d3cbbd41d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3387,7 +3387,7 @@ end_with_restore_list: Don't allow this within a transaction because we want to use 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, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));