~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_delete.cc

  • Committer: Mark Atwood
  • Date: 2011-06-22 20:04:22 UTC
  • mfrom: (2318.6.39 rf)
  • Revision ID: me@mark.atwood.name-20110622200422-609npl456o0e5p32
mergeĀ lp:~olafvdspek/drizzle/refactor13

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
  optimizer::SqlSelect *select= NULL;
56
56
  ReadRecord    info;
57
57
  bool          using_limit=limit != HA_POS_ERROR;
58
 
  bool          transactional_table, const_cond;
59
 
  bool          const_cond_result;
60
58
  ha_rows       deleted= 0;
61
59
  uint32_t usable_index= MAX_KEY;
62
60
  Select_Lex   *select_lex= &session->lex().select_lex;
90
88
    tables.table = table;
91
89
    tables.alias = table_list->alias;
92
90
 
93
 
      if (select_lex->setup_ref_array(session, order->elements) ||
94
 
          setup_order(session, select_lex->ref_pointer_array, &tables,
95
 
                    fields, all_fields, (Order*) order->first))
96
 
      {
97
 
        delete select;
98
 
        free_underlaid_joins(session, &session->lex().select_lex);
99
 
        DRIZZLE_DELETE_DONE(1, 0);
 
91
    select_lex->setup_ref_array(session, order->elements);
 
92
    if (setup_order(session, select_lex->ref_pointer_array, &tables, fields, all_fields, (Order*) order->first))
 
93
    {
 
94
      delete select;
 
95
      free_underlaid_joins(session, &session->lex().select_lex);
 
96
      DRIZZLE_DELETE_DONE(1, 0);
100
97
 
101
 
        return true;
102
 
      }
 
98
      return true;
 
99
    }
103
100
  }
104
101
 
105
 
  const_cond= (!conds || conds->const_item());
 
102
  bool const_cond= not conds || conds->const_item();
106
103
 
107
104
  select_lex->no_error= session->lex().ignore;
108
105
 
109
 
  const_cond_result= const_cond && (!conds || conds->val_int());
 
106
  bool const_cond_result= const_cond && (!conds || conds->val_int());
110
107
  if (session->is_error())
111
108
  {
112
109
    /* Error evaluating val_int(). */
201
198
 
202
199
  if (order && order->elements)
203
200
  {
204
 
    uint32_t         length= 0;
205
 
    SortField  *sortorder;
206
 
    ha_rows examined_rows;
207
 
 
208
201
    if ((!select || table->quick_keys.none()) && limit != HA_POS_ERROR)
209
202
      usable_index= optimizer::get_index_for_order(table, (Order*)(order->first), limit);
210
203
 
212
205
    {
213
206
      FileSort filesort(*session);
214
207
      table->sort.io_cache= new internal::io_cache_st;
215
 
 
216
 
 
217
 
      if (not (sortorder= make_unireg_sortorder((Order*) order->first, &length, NULL)) ||
218
 
          (table->sort.found_records = filesort.run(table, sortorder, length,
219
 
                                                    select, HA_POS_ERROR, 1,
220
 
                                                    examined_rows)) == HA_POS_ERROR)
 
208
      uint32_t length= 0;
 
209
      SortField* sortorder= make_unireg_sortorder((Order*) order->first, &length, NULL);
 
210
      ha_rows examined_rows;
 
211
      if ((table->sort.found_records= filesort.run(table, sortorder, length, select, HA_POS_ERROR, 1, examined_rows)) == HA_POS_ERROR)
221
212
      {
222
213
        delete select;
223
214
        free_underlaid_joins(session, &session->lex().select_lex);
327
318
  }
328
319
 
329
320
  delete select;
330
 
  transactional_table= table->cursor->has_transactions();
 
321
  bool transactional_table= table->cursor->has_transactions();
331
322
 
332
323
  if (!transactional_table && deleted > 0)
333
324
    session->transaction.stmt.markModifiedNonTransData();
374
365
int prepare_delete(Session *session, TableList *table_list, Item **conds)
375
366
{
376
367
  Select_Lex *select_lex= &session->lex().select_lex;
377
 
 
378
 
  List<Item> all_fields;
379
 
 
380
368
  session->lex().allow_sum_func= 0;
381
 
  if (setup_tables_and_check_access(session, &session->lex().select_lex.context,
382
 
                                    &session->lex().select_lex.top_join_list,
383
 
                                    table_list,
384
 
                                    &select_lex->leaf_tables, false) ||
 
369
  if (setup_tables_and_check_access(session, &session->lex().select_lex.context, &select_lex->top_join_list, 
 
370
    table_list, &select_lex->leaf_tables, false) ||
385
371
      session->setup_conds(table_list, conds))
386
372
    return(true);
 
373
 
 
374
  if (unique_table(table_list, table_list->next_global))
387
375
  {
388
 
    TableList *duplicate;
389
 
    if ((duplicate= unique_table(table_list, table_list->next_global)))
390
 
    {
391
 
      my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->alias);
392
 
      return(true);
393
 
    }
 
376
    my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->alias);
 
377
    return(true);
394
378
  }
395
 
 
396
 
  if (select_lex->inner_refs_list.size() &&
397
 
    fix_inner_refs(session, all_fields, select_lex, select_lex->ref_pointer_array))
 
379
  List<Item> all_fields;
 
380
  if (select_lex->inner_refs_list.size() && fix_inner_refs(session, all_fields, select_lex, select_lex->ref_pointer_array))
398
381
    return(true);
399
 
 
400
382
  return(false);
401
383
}
402
384
 
412
394
 
413
395
bool truncate(Session& session, TableList *table_list)
414
396
{
415
 
  bool error;
416
 
  TransactionServices &transaction_services= TransactionServices::singleton();
417
 
 
418
397
  uint64_t save_options= session.options;
419
398
  table_list->lock_type= TL_WRITE;
420
399
  session.options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
421
400
  init_select(&session.lex());
422
 
  error= delete_query(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
423
 
                      HA_POS_ERROR, 0L, true);
 
401
  int error= delete_query(&session, table_list, (COND*) 0, (SQL_LIST*) 0, HA_POS_ERROR, 0L, true);
424
402
  /*
425
403
    Safety, in case the engine ignored ha_enable_transaction(false)
426
404
    above. Also clears session->transaction.*.
427
405
  */
428
 
  error= transaction_services.autocommitOrRollback(session, error);
 
406
  error= TransactionServices::singleton().autocommitOrRollback(session, error);
429
407
  session.options= save_options;
430
 
 
431
408
  return error;
432
409
}
433
410