diff options
author | unknown <osku@127.(none)> | 2005-08-17 11:00:20 +0300 |
---|---|---|
committer | unknown <osku@127.(none)> | 2005-08-17 11:00:20 +0300 |
commit | fa31a9950babd887086c20419669b484d813f501 (patch) | |
tree | 11d5cb3571d6cc02c145f145c4e8f190b0477cf1 /sql/sql_delete.cc | |
parent | c78623fa10bfb8d0716c2a77a85be651fdd33996 (diff) | |
download | mariadb-git-fa31a9950babd887086c20419669b484d813f501.tar.gz |
Fix bug #11946, truncate not always resetting the auto-increment counter
in InnoDB tables.
mysql-test/r/innodb.result:
New tests.
mysql-test/t/innodb.test:
New tests.
sql/ha_innodb.cc:
Add reset_auto_increment.
sql/ha_innodb.h:
Add reset_auto_increment.
sql/handler.h:
Add reset_auto_increment.
sql/sql_delete.cc:
Call handler->reset_auto_increment when needed.
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r-- | sql/sql_delete.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 35183fc959b..f6fb5f2cf53 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -103,6 +103,13 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, free_underlaid_joins(thd, select_lex); thd->row_count_func= 0; send_ok(thd,0L); + + /* + We don't need to call reset_auto_increment in this case, because + mysql_truncate always gives a NULL conds argument, hence we never + get here. + */ + DBUG_RETURN(0); // Nothing to delete } @@ -226,6 +233,21 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (options & OPTION_QUICK) (void) table->file->extra(HA_EXTRA_NORMAL); + if ((error < 0) && (thd->lex->sql_command == SQLCOM_TRUNCATE)) + { + /* + We're really doing a truncate and need to reset the table's + auto-increment counter. + */ + int error2 = table->file->reset_auto_increment(); + + if (error2 && (error2 != HA_ERR_WRONG_COMMAND)) + { + table->file->print_error(error2, MYF(0)); + error = 1; + } + } + cleanup: /* Invalidate the table in the query cache if something changed. This must |