~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_delete.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "drizzled/records.h"
31
31
#include "drizzled/internal/iocache.h"
32
32
#include "drizzled/transaction_services.h"
33
 
#include "drizzled/filesort.h"
34
33
 
35
34
namespace drizzled
36
35
{
43
42
  end of dispatch_command().
44
43
*/
45
44
 
46
 
bool delete_query(Session *session, TableList *table_list, COND *conds,
 
45
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
47
46
                  SQL_LIST *order, ha_rows limit, uint64_t,
48
47
                  bool reset_auto_increment)
49
48
{
57
56
  ha_rows       deleted= 0;
58
57
  uint32_t usable_index= MAX_KEY;
59
58
  Select_Lex   *select_lex= &session->lex->select_lex;
60
 
  Session::killed_state_t killed_status= Session::NOT_KILLED;
 
59
  Session::killed_state killed_status= Session::NOT_KILLED;
61
60
 
62
61
  if (session->openTablesLock(table_list))
63
62
  {
71
70
  session->set_proc_info("init");
72
71
  table->map=1;
73
72
 
74
 
  if (prepare_delete(session, table_list, &conds))
 
73
  if (mysql_prepare_delete(session, table_list, &conds))
75
74
  {
76
75
    DRIZZLE_DELETE_DONE(1, 0);
77
76
    return true;
89
88
 
90
89
      if (select_lex->setup_ref_array(session, order->elements) ||
91
90
          setup_order(session, select_lex->ref_pointer_array, &tables,
92
 
                    fields, all_fields, (Order*) order->first))
 
91
                    fields, all_fields, (order_st*) order->first))
93
92
      {
94
93
        delete select;
95
94
        free_underlaid_joins(session, &session->lex->select_lex);
173
172
    delete select;
174
173
    free_underlaid_joins(session, select_lex);
175
174
    session->row_count_func= 0;
176
 
    if (session->is_error())
177
 
      return true;
178
175
    DRIZZLE_DELETE_DONE(0, 0);
179
176
    /**
180
177
     * Resetting the Diagnostic area to prevent
181
178
     * lp bug# 439719
182
179
     */
183
180
    session->main_da.reset_diagnostics_area();
184
 
    session->my_ok((ha_rows) session->rowCount());
 
181
    session->my_ok((ha_rows) session->row_count_func);
185
182
    /*
186
183
      We don't need to call reset_auto_increment in this case, because
187
184
      mysql_truncate always gives a NULL conds argument, hence we never
203
200
    ha_rows examined_rows;
204
201
 
205
202
    if ((!select || table->quick_keys.none()) && limit != HA_POS_ERROR)
206
 
      usable_index= optimizer::get_index_for_order(table, (Order*)(order->first), limit);
 
203
      usable_index= optimizer::get_index_for_order(table, (order_st*)(order->first), limit);
207
204
 
208
205
    if (usable_index == MAX_KEY)
209
206
    {
210
 
      FileSort filesort(*session);
211
207
      table->sort.io_cache= new internal::IO_CACHE;
212
208
 
213
209
 
214
 
      if (not (sortorder= make_unireg_sortorder((Order*) order->first, &length, NULL)) ||
215
 
          (table->sort.found_records = filesort.run(table, sortorder, length,
216
 
                                                    select, HA_POS_ERROR, 1,
217
 
                                                    examined_rows)) == HA_POS_ERROR)
 
210
      if (!(sortorder= make_unireg_sortorder((order_st*) order->first,
 
211
                                             &length, NULL)) ||
 
212
          (table->sort.found_records = filesort(session, table, sortorder, length,
 
213
                                                select, HA_POS_ERROR, 1,
 
214
                                                &examined_rows))
 
215
          == HA_POS_ERROR)
218
216
      {
219
217
        delete select;
220
218
        free_underlaid_joins(session, &session->lex->select_lex);
243
241
 
244
242
  if (usable_index==MAX_KEY)
245
243
  {
246
 
    if ((error= info.init_read_record(session,table,select,1,1)))
247
 
    {
248
 
      table->print_error(error, MYF(0));
249
 
      delete select;
250
 
      free_underlaid_joins(session, select_lex);
251
 
      return true;
252
 
    }
 
244
    info.init_read_record(session,table,select,1,1);
253
245
  }
254
246
  else
255
247
  {
256
 
    if ((error= info.init_read_record_idx(session, table, 1, usable_index)))
257
 
    {
258
 
      table->print_error(error, MYF(0));
259
 
      delete select;
260
 
      free_underlaid_joins(session, select_lex);
261
 
      return true;
262
 
    }
 
248
    info.init_read_record_idx(session, table, 1, usable_index);
263
249
  }
264
250
 
265
251
  session->set_proc_info("updating");
266
252
 
267
253
  table->mark_columns_needed_for_delete();
268
254
 
269
 
  while (!(error=info.read_record(&info)) && !session->getKilled() &&
 
255
  while (!(error=info.read_record(&info)) && !session->killed &&
270
256
         ! session->is_error())
271
257
  {
272
258
    // session->is_error() is tested to disallow delete row on error
299
285
    else
300
286
      table->cursor->unlock_row();  // Row failed selection, release lock on it
301
287
  }
302
 
  killed_status= session->getKilled();
 
288
  killed_status= session->killed;
303
289
  if (killed_status != Session::NOT_KILLED || session->is_error())
304
290
    error= 1;                                   // Aborted
305
291
 
347
333
     * lp bug# 439719
348
334
     */
349
335
    session->main_da.reset_diagnostics_area();    
350
 
    session->my_ok((ha_rows) session->rowCount());
 
336
    session->my_ok((ha_rows) session->row_count_func);
351
337
  }
352
338
  session->status_var.deleted_row_count+= deleted;
353
339
 
359
345
  Prepare items in DELETE statement
360
346
 
361
347
  SYNOPSIS
362
 
    prepare_delete()
 
348
    mysql_prepare_delete()
363
349
    session                     - thread handler
364
350
    table_list          - global/local table list
365
351
    conds               - conditions
368
354
    false OK
369
355
    true  error
370
356
*/
371
 
int prepare_delete(Session *session, TableList *table_list, Item **conds)
 
357
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds)
372
358
{
373
359
  Select_Lex *select_lex= &session->lex->select_lex;
374
360
 
392
378
 
393
379
  if (select_lex->inner_refs_list.elements &&
394
380
    fix_inner_refs(session, all_fields, select_lex, select_lex->ref_pointer_array))
395
 
    return(true);
 
381
    return(-1);
396
382
 
397
383
  return(false);
398
384
}
407
393
  This will work even if the .ISM and .ISD tables are destroyed
408
394
*/
409
395
 
410
 
bool truncate(Session& session, TableList *table_list)
 
396
bool mysql_truncate(Session& session, TableList *table_list)
411
397
{
412
398
  bool error;
413
399
  TransactionServices &transaction_services= TransactionServices::singleton();
415
401
  uint64_t save_options= session.options;
416
402
  table_list->lock_type= TL_WRITE;
417
403
  session.options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
418
 
  init_select(session.lex);
419
 
  error= delete_query(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
 
404
  mysql_init_select(session.lex);
 
405
  error= mysql_delete(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
420
406
                      HA_POS_ERROR, 0L, true);
421
407
  /*
422
408
    Safety, in case the engine ignored ha_enable_transaction(false)
423
409
    above. Also clears session->transaction.*.
424
410
  */
425
 
  error= transaction_services.autocommitOrRollback(session, error);
 
411
  error= transaction_services.autocommitOrRollback(&session, error);
426
412
  session.options= save_options;
427
413
 
428
414
  return error;