mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Merge zim.(none):/home/brian/mysql/mysql-5.0
into zim.(none):/home/brian/mysql/mysql-5.1 Resolved to minor issues.
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user