~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/*
17
  Delete of records and truncate of tables.
18
19
  Multi-table deletes were introduced by Monty and Sinisa
20
*/
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
22
#include <drizzled/sql_select.h>
23
#include <drizzled/error.h>
24
#include <drizzled/probes.h>
25
#include <drizzled/sql_parse.h>
26
#include <drizzled/sql_base.h>
27
#include <drizzled/lock.h>
28
#include <drizzled/probes.h>
29
#include <drizzled/optimizer/range.h>
30
#include <drizzled/records.h>
31
#include <drizzled/internal/iocache.h>
32
#include <drizzled/transaction_services.h>
33
#include <drizzled/filesort.h>
2234.1.4 by Olaf van der Spek
Refactor includes
34
#include <drizzled/sql_lex.h>
2239.1.5 by Olaf van der Spek
Refactor includes
35
#include <drizzled/diagnostics_area.h>
2241.3.1 by Olaf van der Spek
Refactor Session::status_var
36
#include <drizzled/statistics_variables.h>
2241.3.4 by Olaf van der Spek
Refactor Session::transaction
37
#include <drizzled/session/transactions.h>
1 by brian
clean slate
38
2239.1.5 by Olaf van der Spek
Refactor includes
39
namespace drizzled {
1130.1.4 by Monty Taylor
Moved StorageEngine into plugin namespace.
40
1 by brian
clean slate
41
/**
42
  Implement DELETE SQL word.
43
44
  @note Like implementations of other DDL/DML in MySQL, this function
45
  relies on the caller to close the thread tables. This is done in the
46
  end of dispatch_command().
47
*/
48
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
49
bool delete_query(Session *session, TableList *table_list, COND *conds,
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
50
                  SQL_LIST *order, ha_rows limit, uint64_t,
1 by brian
clean slate
51
                  bool reset_auto_increment)
52
{
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
53
  int		error;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
54
  Table		*table;
1237.13.3 by Padraig O'Sullivan
Performed numerous style cleanups in range.[cc,h].
55
  optimizer::SqlSelect *select= NULL;
1538 by Brian Aker
Code shuffle on ReadRecord
56
  ReadRecord	info;
1 by brian
clean slate
57
  bool          using_limit=limit != HA_POS_ERROR;
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
58
  bool		transactional_table, const_cond;
1 by brian
clean slate
59
  bool          const_cond_result;
60
  ha_rows	deleted= 0;
482 by Brian Aker
Remove uint.
61
  uint32_t usable_index= MAX_KEY;
2227.4.8 by Olaf van der Spek
Session::lex()
62
  Select_Lex   *select_lex= &session->lex().select_lex;
1910.2.8 by Brian Aker
Enapsulate Kill.
63
  Session::killed_state_t killed_status= Session::NOT_KILLED;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
64
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
65
  if (session->openTablesLock(table_list))
1126.10.7 by Padraig O'Sullivan
Added calls to the dtrace delete begin/end probes.
66
  {
67
    DRIZZLE_DELETE_DONE(1, 0);
1109.1.2 by Brian Aker
More from the table patch
68
    return true;
1126.10.7 by Padraig O'Sullivan
Added calls to the dtrace delete begin/end probes.
69
  }
737 by Brian Aker
Updates for dead code removal (and forced assert() in delete).
70
71
  table= table_list->table;
72
  assert(table);
73
520.1.22 by Brian Aker
Second pass of thd cleanup
74
  session->set_proc_info("init");
1 by brian
clean slate
75
  table->map=1;
76
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
77
  if (prepare_delete(session, table_list, &conds))
1864.3.21 by Brian Aker
sql_delete removal of goto
78
  {
79
    DRIZZLE_DELETE_DONE(1, 0);
80
    return true;
81
  }
1 by brian
clean slate
82
83
  /* check ORDER BY even if it can be ignored */
84
  if (order && order->elements)
85
  {
327.2.4 by Brian Aker
Refactoring table.h
86
    TableList   tables;
1 by brian
clean slate
87
    List<Item>   fields;
88
    List<Item>   all_fields;
89
90
    tables.table = table;
91
    tables.alias = table_list->alias;
92
520.1.22 by Brian Aker
Second pass of thd cleanup
93
      if (select_lex->setup_ref_array(session, order->elements) ||
94
	  setup_order(session, select_lex->ref_pointer_array, &tables,
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
95
                    fields, all_fields, (Order*) order->first))
1864.3.21 by Brian Aker
sql_delete removal of goto
96
      {
97
        delete select;
2227.4.8 by Olaf van der Spek
Session::lex()
98
        free_underlaid_joins(session, &session->lex().select_lex);
1864.3.21 by Brian Aker
sql_delete removal of goto
99
        DRIZZLE_DELETE_DONE(1, 0);
100
101
        return true;
102
      }
1 by brian
clean slate
103
  }
104
105
  const_cond= (!conds || conds->const_item());
106
2227.4.8 by Olaf van der Spek
Session::lex()
107
  select_lex->no_error= session->lex().ignore;
1 by brian
clean slate
108
109
  const_cond_result= const_cond && (!conds || conds->val_int());
520.1.22 by Brian Aker
Second pass of thd cleanup
110
  if (session->is_error())
1 by brian
clean slate
111
  {
112
    /* Error evaluating val_int(). */
163 by Brian Aker
Merge Monty's code.
113
    return(true);
1 by brian
clean slate
114
  }
115
116
  /*
117
    Test if the user wants to delete all rows and deletion doesn't have
118
    any side-effects (because of triggers), so we can use optimized
119
    handler::delete_all_rows() method.
120
121
    We implement fast TRUNCATE for InnoDB even if triggers are
122
    present.  TRUNCATE ignores triggers.
123
124
    We can use delete_all_rows() if and only if:
125
    - We allow new functions (not using option --skip-new), and are
126
      not in safe mode (not using option --safe-mode)
127
    - There is no limit clause
128
    - The condition is constant
129
    - If there is a condition, then it it produces a non-zero value
130
    - If the current command is DELETE FROM with no where clause
131
      (i.e., not TRUNCATE) then:
132
      - We should not be binlogging this statement row-based, and
133
      - there should be no delete triggers associated with the table.
134
  */
581 by Brian Aker
Second pass through on replication row patch
135
  if (!using_limit && const_cond_result)
1 by brian
clean slate
136
  {
1208.3.2 by brian
Update for Cursor renaming.
137
    /* Update the table->cursor->stats.records number */
138
    table->cursor->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
139
    ha_rows const maybe_deleted= table->cursor->stats.records;
140
    if (!(error=table->cursor->ha_delete_all_rows()))
1 by brian
clean slate
141
    {
142
      error= -1;				// ok
143
      deleted= maybe_deleted;
144
      goto cleanup;
145
    }
146
    if (error != HA_ERR_WRONG_COMMAND)
147
    {
1216.1.1 by Brian Aker
Move print_error up to Engine.
148
      table->print_error(error,MYF(0));
1 by brian
clean slate
149
      error=0;
150
      goto cleanup;
151
    }
152
    /* Handler didn't support fast delete; Delete rows one by one */
153
  }
154
  if (conds)
155
  {
156
    Item::cond_result result;
520.1.22 by Brian Aker
Second pass of thd cleanup
157
    conds= remove_eq_conds(session, conds, &result);
1 by brian
clean slate
158
    if (result == Item::COND_FALSE)             // Impossible where
159
      limit= 0;
160
  }
161
1208.3.2 by brian
Update for Cursor renaming.
162
  /* Update the table->cursor->stats.records number */
163
  table->cursor->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
1 by brian
clean slate
164
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
165
  table->covering_keys.reset();
166
  table->quick_keys.reset();		// Can't use 'only index'
1237.9.2 by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to
167
  select= optimizer::make_select(table, 0, 0, conds, 0, &error);
1 by brian
clean slate
168
  if (error)
1864.3.21 by Brian Aker
sql_delete removal of goto
169
  {
170
    DRIZZLE_DELETE_DONE(1, 0);
171
    return true;
172
  }
173
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
174
  if ((select && select->check_quick(session, false, limit)) || !limit)
1 by brian
clean slate
175
  {
176
    delete select;
520.1.22 by Brian Aker
Second pass of thd cleanup
177
    free_underlaid_joins(session, select_lex);
178
    session->row_count_func= 0;
2062.4.1 by Andrew Hutchings
Backport http://bugs.mysql.com/bug.php?id=40113
179
    if (session->is_error())
180
      return true;
1126.10.18 by Padraig O'Sullivan
Various small build fixes for when dtrace is enabled.
181
    DRIZZLE_DELETE_DONE(0, 0);
1124.2.14 by Diego Medina
* On certain UPDATE and DELETE statements, drizzled failed an assert() in
182
    /**
183
     * Resetting the Diagnostic area to prevent
184
     * lp bug# 439719
185
     */
2239.1.4 by Olaf van der Spek
Refactor includes
186
    session->main_da().reset_diagnostics_area();
2148.5.2 by Brian Aker
Additional remove of current_session.
187
    session->my_ok((ha_rows) session->rowCount());
1 by brian
clean slate
188
    /*
189
      We don't need to call reset_auto_increment in this case, because
190
      mysql_truncate always gives a NULL conds argument, hence we never
191
      get here.
192
    */
1126.10.7 by Padraig O'Sullivan
Added calls to the dtrace delete begin/end probes.
193
    return 0; // Nothing to delete
1 by brian
clean slate
194
  }
195
196
  /* If running in safe sql mode, don't allow updates without keys */
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
197
  if (table->quick_keys.none())
1 by brian
clean slate
198
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
199
    session->server_status|=SERVER_QUERY_NO_INDEX_USED;
1 by brian
clean slate
200
  }
201
202
  if (order && order->elements)
203
  {
482 by Brian Aker
Remove uint.
204
    uint32_t         length= 0;
1711.6.1 by Brian Aker
Style on structure cleanup
205
    SortField  *sortorder;
1 by brian
clean slate
206
    ha_rows examined_rows;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
207
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
208
    if ((!select || table->quick_keys.none()) && limit != HA_POS_ERROR)
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
209
      usable_index= optimizer::get_index_for_order(table, (Order*)(order->first), limit);
1 by brian
clean slate
210
211
    if (usable_index == MAX_KEY)
212
    {
1905.1.1 by Brian Aker
Adding FileSort class.
213
      FileSort filesort(*session);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
214
      table->sort.io_cache= new internal::IO_CACHE;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
215
216
1905.1.1 by Brian Aker
Adding FileSort class.
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,
1908.1.1 by Brian Aker
Merge in encapsulations in filesort.
220
						    examined_rows)) == HA_POS_ERROR)
1 by brian
clean slate
221
      {
222
        delete select;
2227.4.8 by Olaf van der Spek
Session::lex()
223
        free_underlaid_joins(session, &session->lex().select_lex);
1864.3.21 by Brian Aker
sql_delete removal of goto
224
225
        DRIZZLE_DELETE_DONE(1, 0);
226
        return true;
1 by brian
clean slate
227
      }
228
      /*
229
        Filesort has already found and selected the rows we want to delete,
230
        so we don't need the where clause
231
      */
232
      delete select;
520.1.22 by Brian Aker
Second pass of thd cleanup
233
      free_underlaid_joins(session, select_lex);
1 by brian
clean slate
234
      select= 0;
235
    }
236
  }
237
238
  /* If quick select is used, initialize it before retrieving rows. */
239
  if (select && select->quick && select->quick->reset())
240
  {
241
    delete select;
520.1.22 by Brian Aker
Second pass of thd cleanup
242
    free_underlaid_joins(session, select_lex);
1864.3.21 by Brian Aker
sql_delete removal of goto
243
    DRIZZLE_DELETE_DONE(1, 0);
244
    return true;
1 by brian
clean slate
245
  }
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
246
1 by brian
clean slate
247
  if (usable_index==MAX_KEY)
1538 by Brian Aker
Code shuffle on ReadRecord
248
  {
2049.2.1 by Stewart Smith
doStartTableScan() result not checked.
249
    if ((error= info.init_read_record(session,table,select,1,1)))
250
    {
251
      table->print_error(error, MYF(0));
252
      delete select;
253
      free_underlaid_joins(session, select_lex);
254
      return true;
255
    }
1538 by Brian Aker
Code shuffle on ReadRecord
256
  }
1 by brian
clean slate
257
  else
1538 by Brian Aker
Code shuffle on ReadRecord
258
  {
2049.2.7 by Stewart Smith
init_read_record_idx return result should be checked now that it checks startIndexScan result.
259
    if ((error= info.init_read_record_idx(session, table, 1, usable_index)))
260
    {
261
      table->print_error(error, MYF(0));
262
      delete select;
263
      free_underlaid_joins(session, select_lex);
264
      return true;
265
    }
1538 by Brian Aker
Code shuffle on ReadRecord
266
  }
1 by brian
clean slate
267
520.1.22 by Brian Aker
Second pass of thd cleanup
268
  session->set_proc_info("updating");
1 by brian
clean slate
269
270
  table->mark_columns_needed_for_delete();
271
1910.2.8 by Brian Aker
Enapsulate Kill.
272
  while (!(error=info.read_record(&info)) && !session->getKilled() &&
520.1.22 by Brian Aker
Second pass of thd cleanup
273
	 ! session->is_error())
1 by brian
clean slate
274
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
275
    // session->is_error() is tested to disallow delete row on error
276
    if (!(select && select->skip_record())&& ! session->is_error() )
1 by brian
clean slate
277
    {
1672.3.6 by Brian Aker
First pass in encapsulating row
278
      if (!(error= table->cursor->deleteRecord(table->getInsertRecord())))
1 by brian
clean slate
279
      {
280
	deleted++;
281
	if (!--limit && using_limit)
282
	{
283
	  error= -1;
284
	  break;
285
	}
286
      }
287
      else
288
      {
1216.1.1 by Brian Aker
Move print_error up to Engine.
289
	table->print_error(error,MYF(0));
1 by brian
clean slate
290
	/*
291
	  In < 4.0.14 we set the error number to 0 here, but that
292
	  was not sensible, because then MySQL would not roll back the
293
	  failed DELETE, and also wrote it to the binlog. For MyISAM
294
	  tables a DELETE probably never should fail (?), but for
295
	  InnoDB it can fail in a FOREIGN KEY error or an
296
	  out-of-tablespace error.
297
	*/
298
 	error= 1;
299
	break;
300
      }
301
    }
302
    else
1208.3.2 by brian
Update for Cursor renaming.
303
      table->cursor->unlock_row();  // Row failed selection, release lock on it
1 by brian
clean slate
304
  }
1910.2.8 by Brian Aker
Enapsulate Kill.
305
  killed_status= session->getKilled();
520.1.22 by Brian Aker
Second pass of thd cleanup
306
  if (killed_status != Session::NOT_KILLED || session->is_error())
1 by brian
clean slate
307
    error= 1;					// Aborted
1237.6.1 by Brian Aker
Remove dead bits in parser/whitespace/etc.
308
520.1.22 by Brian Aker
Second pass of thd cleanup
309
  session->set_proc_info("end");
1538 by Brian Aker
Code shuffle on ReadRecord
310
  info.end_read_record();
1 by brian
clean slate
311
1208.2.2 by Brian Aker
Merge Truncate patch. This fixes all of the "half setup" of Truncate. Still
312
cleanup:
313
1 by brian
clean slate
314
  if (reset_auto_increment && (error < 0))
315
  {
316
    /*
317
      We're really doing a truncate and need to reset the table's
318
      auto-increment counter.
319
    */
1208.3.2 by brian
Update for Cursor renaming.
320
    int error2= table->cursor->ha_reset_auto_increment(0);
1 by brian
clean slate
321
322
    if (error2 && (error2 != HA_ERR_WRONG_COMMAND))
323
    {
1216.1.1 by Brian Aker
Move print_error up to Engine.
324
      table->print_error(error2, MYF(0));
1 by brian
clean slate
325
      error= 1;
326
    }
327
  }
328
329
  delete select;
1208.3.2 by brian
Update for Cursor renaming.
330
  transactional_table= table->cursor->has_transactions();
1 by brian
clean slate
331
332
  if (!transactional_table && deleted > 0)
1273.1.13 by Jay Pipes
Style cleanup around TransactionContext::modified_non_trans_table and dead code removal
333
    session->transaction.stmt.markModifiedNonTransData();
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
334
1 by brian
clean slate
335
  /* See similar binlogging code in sql_update.cc, for comments */
1273.1.13 by Jay Pipes
Style cleanup around TransactionContext::modified_non_trans_table and dead code removal
336
  if ((error < 0) || session->transaction.stmt.hasModifiedNonTransData())
1 by brian
clean slate
337
  {
1273.1.13 by Jay Pipes
Style cleanup around TransactionContext::modified_non_trans_table and dead code removal
338
    if (session->transaction.stmt.hasModifiedNonTransData())
339
      session->transaction.all.markModifiedNonTransData();
1 by brian
clean slate
340
  }
1273.1.13 by Jay Pipes
Style cleanup around TransactionContext::modified_non_trans_table and dead code removal
341
  assert(transactional_table || !deleted || session->transaction.stmt.hasModifiedNonTransData());
520.1.22 by Brian Aker
Second pass of thd cleanup
342
  free_underlaid_joins(session, select_lex);
1 by brian
clean slate
343
1126.10.25 by Padraig O'Sullivan
Updated calls to some dtrace probes to cast the parameter to const char *
344
  DRIZZLE_DELETE_DONE((error >= 0 || session->is_error()), deleted);
2227.4.8 by Olaf van der Spek
Session::lex()
345
  if (error < 0 || (session->lex().ignore && !session->is_fatal_error))
1 by brian
clean slate
346
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
347
    session->row_count_func= deleted;
1124.2.14 by Diego Medina
* On certain UPDATE and DELETE statements, drizzled failed an assert() in
348
    /**
349
     * Resetting the Diagnostic area to prevent
350
     * lp bug# 439719
351
     */
2239.1.4 by Olaf van der Spek
Refactor includes
352
    session->main_da().reset_diagnostics_area();
2148.5.2 by Brian Aker
Additional remove of current_session.
353
    session->my_ok((ha_rows) session->rowCount());
1 by brian
clean slate
354
  }
1625.2.2 by Joe Daly
add counter logic for rows sent/received/inserted/updated
355
  session->status_var.deleted_row_count+= deleted;
1864.3.21 by Brian Aker
sql_delete removal of goto
356
1126.10.7 by Padraig O'Sullivan
Added calls to the dtrace delete begin/end probes.
357
  return (error >= 0 || session->is_error());
1 by brian
clean slate
358
}
359
360
361
/*
362
  Prepare items in DELETE statement
363
364
  SYNOPSIS
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
365
    prepare_delete()
520.1.22 by Brian Aker
Second pass of thd cleanup
366
    session			- thread handler
1 by brian
clean slate
367
    table_list		- global/local table list
368
    conds		- conditions
369
370
  RETURN VALUE
163 by Brian Aker
Merge Monty's code.
371
    false OK
372
    true  error
1 by brian
clean slate
373
*/
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
374
int prepare_delete(Session *session, TableList *table_list, Item **conds)
1 by brian
clean slate
375
{
2227.4.8 by Olaf van der Spek
Session::lex()
376
  Select_Lex *select_lex= &session->lex().select_lex;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
377
1 by brian
clean slate
378
  List<Item> all_fields;
379
2227.4.8 by Olaf van der Spek
Session::lex()
380
  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,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
383
                                    table_list,
1 by brian
clean slate
384
                                    &select_lex->leaf_tables, false) ||
1109.1.5 by Brian Aker
More extraction from sql_base
385
      session->setup_conds(table_list, conds))
163 by Brian Aker
Merge Monty's code.
386
    return(true);
1 by brian
clean slate
387
  {
327.2.4 by Brian Aker
Refactoring table.h
388
    TableList *duplicate;
1220.1.13 by Brian Aker
Remove mysql_lock_have_duplicate() (we don't have merge, and our partition
389
    if ((duplicate= unique_table(table_list, table_list->next_global)))
1 by brian
clean slate
390
    {
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
391
      my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->alias);
163 by Brian Aker
Merge Monty's code.
392
      return(true);
1 by brian
clean slate
393
    }
394
  }
395
2183.2.19 by Olaf van der Spek
Use List::size()
396
  if (select_lex->inner_refs_list.size() &&
520.1.22 by Brian Aker
Second pass of thd cleanup
397
    fix_inner_refs(session, all_fields, select_lex, select_lex->ref_pointer_array))
2062.4.1 by Andrew Hutchings
Backport http://bugs.mysql.com/bug.php?id=40113
398
    return(true);
1 by brian
clean slate
399
163 by Brian Aker
Merge Monty's code.
400
  return(false);
1 by brian
clean slate
401
}
402
403
404
/***************************************************************************
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
405
  TRUNCATE Table
1 by brian
clean slate
406
****************************************************************************/
407
408
/*
409
  Optimize delete of all rows by doing a full generate of the table
410
  This will work even if the .ISM and .ISD tables are destroyed
411
*/
412
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
413
bool truncate(Session& session, TableList *table_list)
1 by brian
clean slate
414
{
415
  bool error;
1273.1.2 by Jay Pipes
This patch does not change any algorithms or code paths,
416
  TransactionServices &transaction_services= TransactionServices::singleton();
1208.2.2 by Brian Aker
Merge Truncate patch. This fixes all of the "half setup" of Truncate. Still
417
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
418
  uint64_t save_options= session.options;
1 by brian
clean slate
419
  table_list->lock_type= TL_WRITE;
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
420
  session.options&= ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
2227.4.10 by Olaf van der Spek
Session::lex()
421
  init_select(&session.lex());
2026.2.1 by Monty Taylor
Renamed things prefixed mysql_ or mysqld_
422
  error= delete_query(&session, table_list, (COND*) 0, (SQL_LIST*) 0,
398.1.8 by Monty Taylor
Enabled -Wlong-long.
423
                      HA_POS_ERROR, 0L, true);
1 by brian
clean slate
424
  /*
163 by Brian Aker
Merge Monty's code.
425
    Safety, in case the engine ignored ha_enable_transaction(false)
520.1.22 by Brian Aker
Second pass of thd cleanup
426
    above. Also clears session->transaction.*.
1 by brian
clean slate
427
  */
2096.2.1 by David Shrewsbury
Initial change to use references to Session in TransactionServices methods rather than pointers.
428
  error= transaction_services.autocommitOrRollback(session, error);
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
429
  session.options= save_options;
430
1208.2.2 by Brian Aker
Merge Truncate patch. This fixes all of the "half setup" of Truncate. Still
431
  return error;
1 by brian
clean slate
432
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
433
434
} /* namespace drizzled */