summaryrefslogtreecommitdiff
path: root/sql/sql_delete.cc
diff options
context:
space:
mode:
authorunknown <brian@zim.(none)>2005-08-30 14:40:02 -0700
committerunknown <brian@zim.(none)>2005-08-30 14:40:02 -0700
commit9ea1d5e293a0a12b1be1d305d1a88e2aae18a4ba (patch)
treefb387d75c6bc8131e0d735a74cc6ab053e56c186 /sql/sql_delete.cc
parent172392f272b65ce630e3c56790ed76e666af3903 (diff)
parent8d17360181f9b27295fe18e6f4137b8af1fc2d06 (diff)
downloadmariadb-git-9ea1d5e293a0a12b1be1d305d1a88e2aae18a4ba.tar.gz
Merge zim.(none):/home/brian/mysql/mysql-5.0
into zim.(none):/home/brian/mysql/mysql-5.1 Resolved to minor issues. BitKeeper/etc/config: Auto merged Makefile.am: Auto merged VC++Files/sql/mysqld.vcproj: Auto merged extra/perror.c: Auto merged include/my_global.h: Auto merged mysql-test/mysql-test-run.pl: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/t/alter_table.test: Auto merged mysql-test/t/disabled.def: Auto merged mysys/Makefile.am: Auto merged scripts/mysql_fix_privilege_tables.sql: Auto merged sql/Makefile.am: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_innodb.h: Auto merged sql/handler.h: Auto merged sql/item.cc: Auto merged sql/lex.h: Auto merged sql/log.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/opt_range.cc: Auto merged sql/set_var.cc: Auto merged sql/sp.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_update.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/examples/ha_tina.cc: Auto merged sql/table.h: Auto merged sql/unireg.h: Auto merged storage/innobase/lock/lock0lock.c: Auto merged storage/myisam/mi_check.c: Auto merged storage/myisam/mi_search.c: Auto merged storage/myisam/myisamchk.c: Auto merged storage/myisam/myisamlog.c: Auto merged storage/myisam/myisampack.c: Auto merged storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Auto merged configure.in: Fixed the resolve of versions. mysql-test/r/alter_table.result: Fixed results.
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r--sql/sql_delete.cc59
1 files changed, 41 insertions, 18 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 5c339d7d64d..5accc9607fe 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -14,15 +14,12 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
/*
Delete of records and truncate of tables.
Multi-table deletes were introduced by Monty and Sinisa
*/
-
-
#include "mysql_priv.h"
#include "ha_innodb.h"
#include "sql_select.h"
@@ -30,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)
{
bool will_batch;
int error, loc_error;
@@ -104,6 +102,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
}
@@ -234,6 +239,21 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (options & OPTION_QUICK)
(void) table->file->extra(HA_EXTRA_NORMAL);
+ 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(0);
+
+ 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
@@ -789,6 +809,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
TABLE *table= *table_ptr;
table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
db_type table_type= table->s->db_type;
+ if (!ha_supports_generate(table_type))
+ goto trunc_by_del;
strmov(path, table->s->path);
*table_ptr= table->next; // Unlink table from list
close_temporary(table,0);
@@ -807,7 +829,7 @@ bool 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,
table_list->table_name,reg_ext);
- fn_format(path,path,"","",4);
+ fn_format(path, path, "", "", MY_UNPACK_FILENAME);
if (!dont_send_ok)
{
@@ -819,19 +841,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
DBUG_RETURN(TRUE);
}
if (!ha_supports_generate(table_type) || thd->lex->sphead)
- {
- /* 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);
- mysql_init_select(thd->lex);
- error= mysql_delete(thd, table_list, (COND*) 0, (SQL_LIST*) 0,
- HA_POS_ERROR, LL(0));
- ha_enable_transaction(thd, TRUE);
- thd->options= save_options;
- DBUG_RETURN(error);
- }
+ goto trunc_by_del;
if (lock_and_wait_for_table_name(thd, table_list))
DBUG_RETURN(TRUE);
}
@@ -865,4 +875,17 @@ end:
VOID(pthread_mutex_unlock(&LOCK_open));
}
DBUG_RETURN(error);
+
+ 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);
+ mysql_init_select(thd->lex);
+ error= mysql_delete(thd, table_list, (COND*) 0, (SQL_LIST*) 0,
+ HA_POS_ERROR, LL(0), TRUE);
+ ha_enable_transaction(thd, TRUE);
+ thd->options= save_options;
+ DBUG_RETURN(error);
}