summaryrefslogtreecommitdiff
path: root/sql/sql_delete.cc
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2002-11-21 15:56:48 +0200
committerunknown <monty@mashka.mysql.fi>2002-11-21 15:56:48 +0200
commit33fc0d53b543032accea2476a4eed0522cead2bb (patch)
treed3df5d3fc1abf364dcbcc8eb2305a1cf62540192 /sql/sql_delete.cc
parent2723dbdb5e2c60162ca464f65f68fdd13b7c9cef (diff)
parent70a17cd5a7aab52697b494cd8379fb78db15eeea (diff)
downloadmariadb-git-33fc0d53b543032accea2476a4eed0522cead2bb.tar.gz
Merge with 4.0
BitKeeper/etc/gone: auto-union BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union BitKeeper/deleted/.del-.my_sys.h.swp~f6a4a7f8dae03f18: Auto merged BitKeeper/etc/config: Auto merged acconfig.h: Auto merged acinclude.m4: Auto merged Docs/manual.texi: Auto merged client/mysqlcheck.c: Auto merged client/mysqlshow.c: Auto merged include/myisam.h: Auto merged include/violite.h: Auto merged isam/pack_isam.c: Auto merged libmysql/libmysql.c: Auto merged libmysqld/lib_sql.cc: Auto merged myisam/Makefile.am: Auto merged myisam/ft_nlq_search.c: Auto merged myisam/mi_open.c: Auto merged myisam/mi_write.c: Auto merged myisam/sort.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/fulltext.result: Auto merged mysql-test/r/func_test.result: Auto merged mysql-test/r/isam.result: Auto merged mysql-test/r/rpl_replicate_do.result: Auto merged mysql-test/r/variables.result: Auto merged mysql-test/t/func_test.test: Auto merged mysql-test/t/myisam.test: Auto merged mysql-test/t/rpl_rotate_logs.test: Auto merged mysql-test/t/variables.test: Auto merged mysys/hash.c: Auto merged mysys/tree.c: Auto merged scripts/Makefile.am: Auto merged sql/Makefile.am: Auto merged sql/filesort.cc: Auto merged sql/gen_lex_hash.cc: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/hash_filo.h: Auto merged sql/hostname.cc: Auto merged sql/item_func.cc: Auto merged sql/item_func.h: Auto merged sql/item_timefunc.cc: Auto merged sql/lex.h: Auto merged sql/lock.cc: Auto merged sql/log.cc: Auto merged sql/log_event.h: Auto merged sql/mini_client.cc: Auto merged sql/opt_range.cc: Auto merged sql/opt_sum.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/set_var.h: Auto merged sql/slave.h: Auto merged sql/sql_acl.cc: Auto merged sql/sql_analyse.cc: Auto merged sql/sql_cache.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_load.cc: Auto merged sql/sql_rename.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_udf.cc: Auto merged sql/share/czech/errmsg.txt: Auto merged sql/share/danish/errmsg.txt: Auto merged sql/share/dutch/errmsg.txt: Auto merged sql/share/english/errmsg.txt: Auto merged sql/share/estonian/errmsg.txt: Auto merged sql/share/french/errmsg.txt: Auto merged sql/share/german/errmsg.txt: Auto merged sql/share/greek/errmsg.txt: Auto merged sql/share/hungarian/errmsg.txt: Auto merged sql/share/italian/errmsg.txt: Auto merged sql/share/japanese/errmsg.txt: Auto merged sql/share/korean/errmsg.txt: Auto merged sql/share/norwegian/errmsg.txt: Auto merged sql/table.h: Auto merged sql/unireg.cc: Auto merged sql-bench/server-cfg.sh: Auto merged sql/share/norwegian-ny/errmsg.txt: Auto merged sql/share/polish/errmsg.txt: Auto merged sql/share/portuguese/errmsg.txt: Auto merged sql/share/romanian/errmsg.txt: Auto merged sql/share/russian/errmsg.txt: Auto merged sql/share/slovak/errmsg.txt: Auto merged sql/share/spanish/errmsg.txt: Auto merged sql/share/swedish/errmsg.txt: Auto merged sql/share/ukrainian/errmsg.txt: Auto merged sql/ha_myisam.cc: Merge with 4.0 Removed some commented code sql/sql_db.cc: Merge with 4.0 Optimized the logging of the drop db call a bit sql/sql_update.cc: Added comment
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r--sql/sql_delete.cc108
1 files changed, 59 insertions, 49 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 811cc7c5f5e..cc60ebfb58d 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -28,20 +28,18 @@
#include "sql_select.h"
int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
- ha_rows limit, thr_lock_type lock_type, ulong options)
+ ha_rows limit, ulong options)
{
int error;
TABLE *table;
SQL_SELECT *select=0;
READ_RECORD info;
bool using_limit=limit != HA_POS_ERROR;
- bool using_transactions, safe_update, const_cond;
+ bool using_transactions, log_delayed, safe_update, const_cond;
ha_rows deleted;
DBUG_ENTER("mysql_delete");
- if (!table_list->db)
- table_list->db=thd->db;
- if (!(table = open_ltable(thd,table_list, lock_type)))
+ if (!(table = open_ltable(thd, table_list, table_list->lock_type)))
DBUG_RETURN(-1);
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
thd->proc_info="init";
@@ -162,23 +160,34 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
(void) table->file->extra(HA_EXTRA_NORMAL);
cleanup:
- using_transactions=table->file->has_transactions();
- if (deleted && (error <= 0 || !using_transactions))
+ transactional_table= table->file->has_transactions();
+ log_delayed= (transactional_table || table->tmp_table);
+ if (deleted && (error <= 0 || !transactional_table))
{
mysql_update_log.write(thd,thd->query, thd->query_length);
if (mysql_bin_log.is_open())
{
Query_log_event qinfo(thd, thd->query, thd->query_length,
- using_transactions);
- if (mysql_bin_log.write(&qinfo) && using_transactions)
+ log_delayed);
+ if (mysql_bin_log.write(&qinfo) && transactional_table)
error=1;
}
- if (!using_transactions)
+ if (!log_delayed)
thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
}
- if (using_transactions && ha_autocommit_or_rollback(thd,error >= 0))
- error=1;
- if (deleted)
+ if (transactional_table)
+ {
+ if (ha_autocommit_or_rollback(thd,error >= 0))
+ error=1;
+ }
+ /*
+ Only invalidate the query cache if something changed or if we
+ didn't commit the transacion (query cache is automaticly
+ invalidated on commit)
+ */
+ if (deleted &&
+ (!transactional_table ||
+ thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
{
query_cache_invalidate3(thd, table_list, 1);
}
@@ -205,19 +214,17 @@ cleanup:
#define MEM_STRIP_BUF_SIZE current_thd->variables.sortbuff_size
-int refposcmp2(void* arg, const void *a,const void *b)
+extern "C" int refposcmp2(void* arg, const void *a,const void *b)
{
return memcmp(a,b, *(int*) arg);
}
multi_delete::multi_delete(THD *thd_arg, TABLE_LIST *dt,
- thr_lock_type lock_option_arg,
uint num_of_tables_arg)
: delete_tables (dt), thd(thd_arg), deleted(0),
- num_of_tables(num_of_tables_arg), error(0), lock_option(lock_option_arg),
- do_delete(false)
+ num_of_tables(num_of_tables_arg), error(0),
+ do_delete(0), transactional_tables(0), log_delayed(0), normal_tables(0)
{
- not_trans_safe=false;
tempfiles = (Unique **) sql_calloc(sizeof(Unique *) * (num_of_tables-1));
}
@@ -268,8 +275,12 @@ multi_delete::initialize_tables(JOIN *join)
/* Don't use KEYREAD optimization on this table */
tbl->no_keyread=1;
walk=walk->next;
- if (!not_trans_safe && !tbl->file->has_transactions())
- not_trans_safe=true;
+ if (tbl->file->has_transactions())
+ log_delayed= transactional_tables= 1;
+ else if (tbl->tmp_table != NO_TMP_TABLE)
+ log_delayed= 1;
+ else
+ normal_tables= 1;
}
}
walk= delete_tables;
@@ -375,7 +386,7 @@ void multi_delete::send_error(uint errcode,const char *err)
In all other cases do attempt deletes ...
*/
if ((table_being_deleted->table->file->has_transactions() &&
- table_being_deleted == delete_tables) || !not_trans_safe)
+ table_being_deleted == delete_tables) || !normal_tables)
ha_rollback_stmt(thd);
else if (do_delete)
{
@@ -394,7 +405,7 @@ void multi_delete::send_error(uint errcode,const char *err)
int multi_delete::do_deletes(bool from_send_error)
{
- int error = 0, counter = 0;
+ int local_error= 0, counter= 0;
if (from_send_error)
{
@@ -415,27 +426,26 @@ int multi_delete::do_deletes(bool from_send_error)
TABLE *table = table_being_deleted->table;
if (tempfiles[counter]->get(table))
{
- error=1;
+ local_error=1;
break;
}
READ_RECORD info;
init_read_record(&info,thd,table,NULL,0,0);
- while (!(error=info.read_record(&info)) &&
- (!thd->killed || from_send_error || not_trans_safe))
+ while (!(local_error=info.read_record(&info)) && !thd->killed)
{
- if ((error=table->file->delete_row(table->record[0])))
+ if ((local_error=table->file->delete_row(table->record[0])))
{
- table->file->print_error(error,MYF(0));
+ table->file->print_error(local_error,MYF(0));
break;
}
deleted++;
}
end_read_record(&info);
- if (error == -1) // End of file
- error = 0;
+ if (local_error == -1) // End of file
+ local_error = 0;
}
- return error;
+ return local_error;
}
@@ -451,15 +461,11 @@ bool multi_delete::send_eof()
thd->proc_info="deleting from reference tables";
/* Does deletes for the last n - 1 tables, returns 0 if ok */
- int error = do_deletes(0); // returns 0 if success
+ int local_error= do_deletes(0); // returns 0 if success
/* reset used flags */
thd->proc_info="end";
- if (error)
- {
- ::send_error(thd);
- return 1;
- }
+
/*
Write the SQL statement to the binlog if we deleted
@@ -467,24 +473,25 @@ bool multi_delete::send_eof()
was a non-transaction-safe table involved, since
modifications in it cannot be rolled back.
*/
- if (deleted || not_trans_safe)
+ if (deleted)
{
mysql_update_log.write(thd,thd->query,thd->query_length);
if (mysql_bin_log.is_open())
{
- 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
+ Query_log_event qinfo(thd, thd->query, thd->query_length,
+ log_delayed);
+ if (mysql_bin_log.write(&qinfo) && !normal_tables)
+ local_error=1; // Log write failed: roll back the SQL statement
}
/* Commit or rollback the current SQL statement */
- VOID(ha_autocommit_or_rollback(thd,error > 0));
- }
- if (deleted)
- {
+ VOID(ha_autocommit_or_rollback(thd,local_error > 0));
+
query_cache_invalidate3(thd, delete_tables, 1);
}
- ::send_ok(thd,deleted);
+ if (local_error)
+ ::send_error(thd);
+ else
+ ::send_ok(thd, deleted);
return 0;
}
@@ -557,8 +564,9 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
if (!ha_supports_generate(table_type))
{
/* Probably InnoDB table */
- DBUG_RETURN(mysql_delete(thd,table_list, (COND*) 0, (ORDER*) 0,
- HA_POS_ERROR, TL_WRITE, 0));
+ table_list->lock_type= TL_WRITE;
+ DBUG_RETURN(mysql_delete(thd, table_list, (COND*) 0, (ORDER*) 0,
+ HA_POS_ERROR, 0));
}
if (lock_and_wait_for_table_name(thd, table_list))
DBUG_RETURN(-1);
@@ -570,6 +578,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
*fn_ext(path)=0; // Remove the .frm extension
error= ha_create_table(path,&create_info,1) ? -1 : 0;
query_cache_invalidate3(thd, table_list, 0);
+
end:
if (!dont_send_ok)
{
@@ -578,7 +587,8 @@ end:
mysql_update_log.write(thd,thd->query,thd->query_length);
if (mysql_bin_log.is_open())
{
- Query_log_event qinfo(thd, thd->query, thd->query_length);
+ Query_log_event qinfo(thd, thd->query, thd->query_length,
+ thd->tmp_table);
mysql_bin_log.write(&qinfo);
}
send_ok(thd); // This should return record count