~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to sql/sql_delete.cc

  • Committer: monty at mysql
  • Date: 2002-12-05 17:38:42 UTC
  • mfrom: (1346.7.103)
  • mto: (1388.1.1)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: sp1r-monty@mashka.mysql.fi-20021205173842-56440
Merge with 4.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
226
226
 
227
227
extern "C" int refposcmp2(void* arg, const void *a,const void *b)
228
228
{
 
229
  /* arg is a pointer to file->ref_length */
229
230
  return memcmp(a,b, *(int*) arg);
230
231
}
231
232
 
232
233
multi_delete::multi_delete(THD *thd_arg, TABLE_LIST *dt,
233
234
                           uint num_of_tables_arg)
234
 
  : delete_tables (dt), thd(thd_arg), deleted(0),
 
235
  : delete_tables(dt), thd(thd_arg), deleted(0),
235
236
    num_of_tables(num_of_tables_arg), error(0),
236
237
    do_delete(0), transactional_tables(0), log_delayed(0), normal_tables(0)
237
238
{
244
245
{
245
246
  DBUG_ENTER("multi_delete::prepare");
246
247
  unit= u;
247
 
  do_delete = true;   
 
248
  do_delete= 1;
248
249
  thd->proc_info="deleting from main table";
249
 
 
250
 
  if (thd->options & OPTION_SAFE_UPDATES)
251
 
  {
252
 
    TABLE_LIST *table_ref;
253
 
    for (table_ref=delete_tables;  table_ref; table_ref=table_ref->next)
254
 
    {
255
 
      TABLE *table=table_ref->table;
256
 
      if ((thd->options & OPTION_SAFE_UPDATES) && !table->quick_keys)
257
 
      {
258
 
        my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,MYF(0));
259
 
        DBUG_RETURN(1);
260
 
      }
261
 
    }
262
 
  }
263
250
  DBUG_RETURN(0);
264
251
}
265
252
 
266
253
 
267
 
void
 
254
bool
268
255
multi_delete::initialize_tables(JOIN *join)
269
256
{
270
 
  int counter=0;
271
257
  TABLE_LIST *walk;
 
258
  Unique **tempfiles_ptr;
 
259
  DBUG_ENTER("initialize_tables");
 
260
 
 
261
  if ((thd->options & OPTION_SAFE_UPDATES) && error_if_full_join(join))
 
262
    DBUG_RETURN(1);
 
263
 
272
264
  table_map tables_to_delete_from=0;
273
265
  for (walk= delete_tables ; walk ; walk=walk->next)
274
266
    tables_to_delete_from|= walk->table->map;
282
274
    {
283
275
      /* We are going to delete from this table */
284
276
      TABLE *tbl=walk->table=tab->table;
 
277
      walk=walk->next;
285
278
      /* Don't use KEYREAD optimization on this table */
286
279
      tbl->no_keyread=1;
287
 
      walk=walk->next;
 
280
      tbl->used_keys= 0;
288
281
      if (tbl->file->has_transactions())
289
282
        log_delayed= transactional_tables= 1;
290
283
      else if (tbl->tmp_table != NO_TMP_TABLE)
294
287
    }
295
288
  }
296
289
  walk= delete_tables;
297
 
  walk->table->used_keys=0;
298
 
  for (walk=walk->next ; walk ; walk=walk->next, counter++)
 
290
  tempfiles_ptr= tempfiles;
 
291
  for (walk=walk->next ; walk ; walk=walk->next)
299
292
  {
300
 
    tables_to_delete_from|= walk->table->map;
301
293
    TABLE *table=walk->table;
302
 
  /* Don't use key read with MULTI-TABLE-DELETE */
303
 
    table->used_keys=0;
304
 
    tempfiles[counter] = new Unique (refposcmp2,
305
 
                                     (void *) &table->file->ref_length,
306
 
                                     table->file->ref_length,
307
 
                                     MEM_STRIP_BUF_SIZE);
 
294
    *tempfiles_ptr++= new Unique (refposcmp2,
 
295
                                  (void *) &table->file->ref_length,
 
296
                                  table->file->ref_length,
 
297
                                  MEM_STRIP_BUF_SIZE);
308
298
  }
309
299
  init_ftfuncs(thd, thd->lex.current_select->select_lex(), 1);
 
300
  DBUG_RETURN(thd->fatal_error != 0);
310
301
}
311
302
 
312
303
 
321
312
    t->no_keyread=0;
322
313
  }
323
314
 
324
 
  for (uint counter = 0; counter < num_of_tables-1; counter++)
 
315
  for (uint counter= 0; counter < num_of_tables-1; counter++)
325
316
  {
326
317
    if (tempfiles[counter])
327
318
      delete tempfiles[counter];
428
419
  else
429
420
    table_being_deleted = delete_tables;
430
421
 
431
 
  do_delete = false;
 
422
  do_delete= 0;
432
423
  for (table_being_deleted=table_being_deleted->next;
433
424
       table_being_deleted ;
434
425
       table_being_deleted=table_being_deleted->next, counter++)
483
474
    was a non-transaction-safe table involved, since
484
475
    modifications in it cannot be rolled back.
485
476
  */
486
 
  if (deleted)
 
477
  if (deleted && (error <= 0 || normal_tables))
487
478
  {
488
479
    mysql_update_log.write(thd,thd->query,thd->query_length);
489
480
    if (mysql_bin_log.is_open())
493
484
      if (mysql_bin_log.write(&qinfo) && !normal_tables)
494
485
        local_error=1;  // Log write failed: roll back the SQL statement
495
486
    }
496
 
    /* Commit or rollback the current SQL statement */ 
497
 
    VOID(ha_autocommit_or_rollback(thd,local_error > 0));
498
 
 
 
487
    if (!log_delayed)
 
488
      thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
 
489
  }
 
490
  /* Commit or rollback the current SQL statement */ 
 
491
  if (transactional_tables)
 
492
    if (ha_autocommit_or_rollback(thd,local_error > 0))
 
493
      local_error=1;
 
494
  
 
495
  if (deleted)
499
496
    query_cache_invalidate3(thd, delete_tables, 1);
500
 
  }
 
497
 
501
498
  if (local_error)
502
499
    ::send_error(thd);
503
500
  else