summaryrefslogtreecommitdiff
path: root/sql/sql_delete.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r--sql/sql_delete.cc68
1 files changed, 39 insertions, 29 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 3e9df1cfd29..fc98cfb90c5 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -78,7 +78,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
select=make_select(table,0,0,conds,&error);
if (error)
DBUG_RETURN(-1);
- if ((select && select->check_quick(test(thd->options & SQL_SAFE_UPDATES),
+ if ((select && select->check_quick(test(thd->options & OPTION_SAFE_UPDATES),
limit)) ||
!limit)
{
@@ -167,7 +167,8 @@ cleanup:
mysql_update_log.write(thd,thd->query, thd->query_length);
if (mysql_bin_log.is_open())
{
- Query_log_event qinfo(thd, thd->query, using_transactions);
+ Query_log_event qinfo(thd, thd->query, thd->query_length,
+ using_transactions);
if (mysql_bin_log.write(&qinfo) && using_transactions)
error=1;
}
@@ -198,10 +199,10 @@ cleanup:
/***************************************************************************
-** delete multiple tables from join
+ Delete multiple tables from join
***************************************************************************/
-#define MEM_STRIP_BUF_SIZE sortbuff_size
+#define MEM_STRIP_BUF_SIZE current_thd->variables.sortbuff_size
int refposcmp2(void* arg, const void *a,const void *b)
{
@@ -215,21 +216,8 @@ multi_delete::multi_delete(THD *thd_arg, TABLE_LIST *dt,
num_of_tables(num_of_tables_arg), error(0), lock_option(lock_option_arg),
do_delete(false)
{
- uint counter=0;
not_trans_safe=false;
tempfiles = (Unique **) sql_calloc(sizeof(Unique *) * (num_of_tables-1));
-
- /* Don't use key read with MULTI-TABLE-DELETE */
- dt->table->used_keys=0;
- for (dt=dt->next ; dt ; dt=dt->next,counter++)
- {
- TABLE *table=dt->table;
- table->used_keys=0;
- tempfiles[counter] = new Unique (refposcmp2,
- (void *) &table->file->ref_length,
- table->file->ref_length,
- MEM_STRIP_BUF_SIZE);
- }
}
@@ -261,6 +249,7 @@ multi_delete::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
void
multi_delete::initialize_tables(JOIN *join)
{
+ int counter=0;
TABLE_LIST *walk;
table_map tables_to_delete_from=0;
for (walk= delete_tables ; walk ; walk=walk->next)
@@ -274,14 +263,27 @@ multi_delete::initialize_tables(JOIN *join)
if (tab->table->map & tables_to_delete_from)
{
/* We are going to delete from this table */
- walk->table=tab->table;
+ TABLE *tbl=walk->table=tab->table;
+ /* Don't use KEYREAD optimization on this table */
+ tbl->no_keyread=1;
walk=walk->next;
- if (tab == join->join_tab)
- tab->table->no_keyread=1;
- if (!not_trans_safe && !tab->table->file->has_transactions())
+ if (!not_trans_safe && !tbl->file->has_transactions())
not_trans_safe=true;
}
}
+ walk= delete_tables;
+ walk->table->used_keys=0;
+ for (walk=walk->next ; walk ; walk=walk->next, counter++)
+ {
+ tables_to_delete_from|= walk->table->map;
+ TABLE *table=walk->table;
+ /* Don't use key read with MULTI-TABLE-DELETE */
+ table->used_keys=0;
+ tempfiles[counter] = new Unique (refposcmp2,
+ (void *) &table->file->ref_length,
+ table->file->ref_length,
+ MEM_STRIP_BUF_SIZE);
+ }
init_ftfuncs(thd,1);
}
@@ -358,7 +360,7 @@ void multi_delete::send_error(uint errcode,const char *err)
if (!deleted)
DBUG_VOID_RETURN;
- /* Somthing alredy deleted consequently we have to invalidate cache */
+ /* Something already deleted so we have to invalidate cache */
query_cache_invalidate3(thd, delete_tables, 1);
/* Below can happen when thread is killed early ... */
@@ -437,6 +439,8 @@ int multi_delete::do_deletes(bool from_send_error)
/*
+ Send ok to the client
+
return: 0 sucess
1 error
*/
@@ -467,7 +471,7 @@ bool multi_delete::send_eof()
mysql_update_log.write(thd,thd->query,thd->query_length);
if (mysql_bin_log.is_open())
{
- Query_log_event qinfo(thd, thd->query);
+ Query_log_event qinfo(thd, thd->query, thd->query_length);
if (mysql_bin_log.write(&qinfo) &&
!not_trans_safe)
error=1; // Log write failed: roll back the SQL statement
@@ -485,7 +489,7 @@ bool multi_delete::send_eof()
/***************************************************************************
-* TRUNCATE TABLE
+ TRUNCATE TABLE
****************************************************************************/
/*
@@ -530,9 +534,8 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
table_list->real_name, 1))))
(void) rm_temporary_table(table_type, path);
/*
- If we return here we will not have binloged the truncation and
- we will not send_ok() to the client. Yes, we do need better coverage
- testing, this bug has been here for a few months :-).
+ If we return here we will not have logged the truncation to the bin log
+ and we will not send_ok() to the client.
*/
goto end;
}
@@ -546,7 +549,8 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
db_type table_type;
if ((table_type=get_table_type(path)) == DB_TYPE_UNKNOWN)
{
- my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->real_name);
+ my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db,
+ table_list->real_name);
DBUG_RETURN(-1);
}
if (!ha_supports_generate(table_type))
@@ -573,14 +577,20 @@ end:
mysql_update_log.write(thd,thd->query,thd->query_length);
if (mysql_bin_log.is_open())
{
- Query_log_event qinfo(thd, thd->query);
+ Query_log_event qinfo(thd, thd->query, thd->query_length);
mysql_bin_log.write(&qinfo);
}
send_ok(&thd->net); // This should return record count
}
+ VOID(pthread_mutex_lock(&LOCK_open));
unlock_table_name(thd, table_list);
+ VOID(pthread_mutex_unlock(&LOCK_open));
}
else if (error)
+ {
+ VOID(pthread_mutex_lock(&LOCK_open));
unlock_table_name(thd, table_list);
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ }
DBUG_RETURN(error ? -1 : 0);
}