From c12a760ce9e0c99a2b943bf2de4d7278fb8fa21e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Aug 2005 12:39:20 +0300 Subject: [PATCH] Bug #11946: Review fixes. sql/ha_innodb.cc: Add 'value' parameter to reset_auto_increment. sql/ha_innodb.h: Add 'value' parameter to reset_auto_increment. sql/handler.h: Add 'value' parameter to reset_auto_increment. sql/mysql_priv.h: Add 'reset_auto_increment' parameter to mysql_delete. sql/sql_delete.cc: Add 'reset_auto_increment' parameter to mysql_delete, and use it instead of checking for SQLCOM_TRUNCATE. mysql_truncate: Adapt to changes in mysql_delete. sql/sql_parse.cc: mysql_execute_command: Adapt to changes in mysql_delete. --- sql/ha_innodb.cc | 4 ++-- sql/ha_innodb.h | 2 +- sql/handler.h | 13 +++++++------ sql/mysql_priv.h | 5 +++-- sql/sql_delete.cc | 11 ++++++----- sql/sql_parse.cc | 3 ++- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 736d2d58a57..9a9e5bdaf92 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -6890,7 +6890,7 @@ ha_innobase::get_auto_increment() /* See comment in handler.h */ int -ha_innobase::reset_auto_increment() +ha_innobase::reset_auto_increment(ulonglong value) { DBUG_ENTER("ha_innobase::reset_auto_increment"); @@ -6905,7 +6905,7 @@ ha_innobase::reset_auto_increment() DBUG_RETURN(error); } - dict_table_autoinc_initialize(prebuilt->table, 0); + dict_table_autoinc_initialize(prebuilt->table, value); DBUG_RETURN(0); } diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index ec823487b30..672e48d9817 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -173,7 +173,7 @@ class ha_innobase: public handler enum thr_lock_type lock_type); void init_table_handle_for_HANDLER(); ulonglong get_auto_increment(); - int reset_auto_increment(); + int reset_auto_increment(ulonglong value); uint8 table_cache_type() { return HA_CACHE_TBL_ASKTRANSACT; } /* diff --git a/sql/handler.h b/sql/handler.h index c28554618a6..860f34f15ce 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -651,12 +651,13 @@ public: virtual ulonglong get_auto_increment(); virtual void restore_auto_increment(); - /* This is called after TRUNCATE is emulated by doing a 'DELETE FROM t', - in which case we need a separate operation for resetting the table's - auto-increment counter. HA_ERR_WRONG_COMMAND is returned by storage - engines that have no need for this, i.e. those that can always do a - fast TRUNCATE. */ - virtual int reset_auto_increment() + /* + Reset the auto-increment counter to the given value, i.e. the next row + inserted will get the given value. This is called e.g. after TRUNCATE + is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is + returned by storage engines that don't support this operation. + */ + virtual int reset_auto_increment(ulonglong value) { return HA_ERR_WRONG_COMMAND; } virtual void update_create_info(HA_CREATE_INFO *create_info) {} diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 7d2a53a5e3e..7e21a19bd66 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -740,8 +740,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table,List &fields, int check_that_all_fields_are_given_values(THD *thd, TABLE *entry, TABLE_LIST *table_list); bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds); -bool mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, SQL_LIST *order, - ha_rows rows, ulonglong options); +bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, + SQL_LIST *order, ha_rows rows, ulonglong options, + bool reset_auto_increment); bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok); bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create); TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 3e50b806897..c7fabdaf18e 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -27,7 +27,8 @@ #include "sql_trigger.h" bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, - SQL_LIST *order, ha_rows limit, ulonglong options) + SQL_LIST *order, ha_rows limit, ulonglong options, + bool reset_auto_increment) { int error; TABLE *table; @@ -230,18 +231,18 @@ 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)) + if (reset_auto_increment && (error < 0)) { /* We're really doing a truncate and need to reset the table's auto-increment counter. */ - int error2 = table->file->reset_auto_increment(); + int error2= table->file->reset_auto_increment(0); if (error2 && (error2 != HA_ERR_WRONG_COMMAND)) { table->file->print_error(error2, MYF(0)); - error = 1; + error= 1; } } @@ -828,7 +829,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ha_enable_transaction(thd, FALSE); mysql_init_select(thd->lex); error= mysql_delete(thd, table_list, (COND*) 0, (SQL_LIST*) 0, - HA_POS_ERROR, LL(0)); + HA_POS_ERROR, LL(0), TRUE); ha_enable_transaction(thd, TRUE); thd->options= save_options; DBUG_RETURN(error); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index c023c525079..c4f0552242d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3321,7 +3321,8 @@ end_with_restore_list: unit->set_limit(select_lex); res = mysql_delete(thd, all_tables, select_lex->where, &select_lex->order_list, - unit->select_limit_cnt, select_lex->options); + unit->select_limit_cnt, select_lex->options, + FALSE); break; } case SQLCOM_DELETE_MULTI: