summaryrefslogtreecommitdiff
path: root/sql/sql_delete.cc
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2002-11-29 16:40:18 +0200
committerunknown <monty@mashka.mysql.fi>2002-11-29 16:40:18 +0200
commit4653621909f900200c1e3238a4f5d2f58f6edf29 (patch)
tree9914e2306a30c63d173b56a8ac8f100ee49823d7 /sql/sql_delete.cc
parent7d2d7e3fea4c46857af1e930e04c0d012a084e25 (diff)
downloadmariadb-git-4653621909f900200c1e3238a4f5d2f58f6edf29.tar.gz
New multi-table-update code
New (simpler) internal timestamp handling. More debuging to heap tables. Small cleanups to multi-table-delete false -> 0 and true -> 1 (We should use TRUE and FALSE) heap/_check.c: Added checking of rows heap/hp_delete.c: Extra debugging heap/hp_scan.c: Extra debugging heap/hp_update.c: Extra debugging heap/hp_write.c: Extra debugging include/my_base.h: Added option to disable row cache when using updates isam/extra.c: Added option to disable row cache when using updates myisam/mi_check.c: Comment cleanup myisam/mi_extra.c: Added option to disable row cache when using updates myisam/sort.c: Indentaion cleanups myisammrg/myrg_extra.c: Added option to disable row cache when using updates mysql-test/r/multi_update.result: Updated results mysql-test/t/multi_update.test: Cleanup up to only use table names t1, t2,... mysys/mf_iocache.c: Safety fix sql/item_cmpfunc.cc: change true-> 1 and false -> 0 sql/mysql_priv.h: Cleaned up SQL_LIST handling sql/sql_base.cc: Fixed grant checking if SELECT tablename.* sql/sql_class.h: Cleaned up multi-table-update sql/sql_delete.cc: Fixed OPTION_SAFE_UPDATE checking in multi-table-delete. Fixed query-cache invalidation in multi-table-delete sql/sql_insert.cc: cleaned up timestamp handling sql/sql_olap.cc: false -> 0 sql/sql_parse.cc: Optimized some list handling. Moved multi-table-update to sql_update.cc sql/sql_select.cc: More comments Fixed create_tmp_table for multi-table-update sql/sql_select.h: New prototypes sql/sql_union.cc: false -> 0 Cleaned up timestamp handling sql/sql_update.cc: New multi-update-table code sql/sql_yacc.yy: false -> 0, true -> 1 Optimized some list handling sql/table.h: Added union for temporary values. Made shared int to be able to store counters. sql/uniques.cc: Indentation cleanup
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r--sql/sql_delete.cc67
1 files changed, 32 insertions, 35 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 1361ff39388..4997305de6b 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -213,12 +213,13 @@ cleanup:
extern "C" int refposcmp2(void* arg, const void *a,const void *b)
{
+ /* arg is a pointer to file->ref_length */
return memcmp(a,b, *(int*) arg);
}
multi_delete::multi_delete(THD *thd_arg, TABLE_LIST *dt,
uint num_of_tables_arg)
- : delete_tables (dt), thd(thd_arg), deleted(0),
+ : delete_tables(dt), thd(thd_arg), deleted(0),
num_of_tables(num_of_tables_arg), error(0),
do_delete(0), transactional_tables(0), log_delayed(0), normal_tables(0)
{
@@ -230,31 +231,22 @@ int
multi_delete::prepare(List<Item> &values)
{
DBUG_ENTER("multi_delete::prepare");
- do_delete = true;
+ do_delete= 1;
thd->proc_info="deleting from main table";
-
- if (thd->options & OPTION_SAFE_UPDATES)
- {
- TABLE_LIST *table_ref;
- for (table_ref=delete_tables; table_ref; table_ref=table_ref->next)
- {
- TABLE *table=table_ref->table;
- if ((thd->options & OPTION_SAFE_UPDATES) && !table->quick_keys)
- {
- my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,MYF(0));
- DBUG_RETURN(1);
- }
- }
- }
DBUG_RETURN(0);
}
-void
+bool
multi_delete::initialize_tables(JOIN *join)
{
- int counter=0;
TABLE_LIST *walk;
+ Unique **tempfiles_ptr;
+ DBUG_ENTER("initialize_tables");
+
+ if ((thd->options & OPTION_SAFE_UPDATES) && error_if_full_join(join))
+ DBUG_RETURN(1);
+
table_map tables_to_delete_from=0;
for (walk= delete_tables ; walk ; walk=walk->next)
tables_to_delete_from|= walk->table->map;
@@ -268,9 +260,10 @@ multi_delete::initialize_tables(JOIN *join)
{
/* We are going to delete from this table */
TABLE *tbl=walk->table=tab->table;
+ walk=walk->next;
/* Don't use KEYREAD optimization on this table */
tbl->no_keyread=1;
- walk=walk->next;
+ tbl->used_keys= 0;
if (tbl->file->has_transactions())
log_delayed= transactional_tables= 1;
else if (tbl->tmp_table != NO_TMP_TABLE)
@@ -280,19 +273,17 @@ multi_delete::initialize_tables(JOIN *join)
}
}
walk= delete_tables;
- walk->table->used_keys=0;
- for (walk=walk->next ; walk ; walk=walk->next, counter++)
+ tempfiles_ptr= tempfiles;
+ for (walk=walk->next ; walk ; walk=walk->next)
{
- 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);
+ *tempfiles_ptr++= new Unique (refposcmp2,
+ (void *) &table->file->ref_length,
+ table->file->ref_length,
+ MEM_STRIP_BUF_SIZE);
}
init_ftfuncs(thd,1);
+ DBUG_RETURN(thd->fatal_error != 0);
}
@@ -307,7 +298,7 @@ multi_delete::~multi_delete()
t->no_keyread=0;
}
- for (uint counter = 0; counter < num_of_tables-1; counter++)
+ for (uint counter= 0; counter < num_of_tables-1; counter++)
{
if (tempfiles[counter])
delete tempfiles[counter];
@@ -414,7 +405,7 @@ int multi_delete::do_deletes(bool from_send_error)
else
table_being_deleted = delete_tables;
- do_delete = false;
+ do_delete= 0;
for (table_being_deleted=table_being_deleted->next;
table_being_deleted ;
table_being_deleted=table_being_deleted->next, counter++)
@@ -468,7 +459,7 @@ bool multi_delete::send_eof()
was a non-transaction-safe table involved, since
modifications in it cannot be rolled back.
*/
- if (deleted)
+ if (deleted && (error <= 0 || normal_tables))
{
mysql_update_log.write(thd,thd->query,thd->query_length);
if (mysql_bin_log.is_open())
@@ -478,11 +469,17 @@ bool multi_delete::send_eof()
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,local_error > 0));
-
- query_cache_invalidate3(thd, delete_tables, 1);
+ if (!log_delayed)
+ thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
}
+ /* Commit or rollback the current SQL statement */
+ if (transactional_tables)
+ if (ha_autocommit_or_rollback(thd,local_error > 0))
+ local_error=1;
+
+ if (deleted)
+ query_cache_invalidate3(thd, delete_tables, 1);
+
if (local_error)
::send_error(&thd->net);
else