~ubuntu-branches/ubuntu/maverick/drizzle/maverick

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2006 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
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
 
 
17
/*
 
18
  Single table and multi table updates of tables.
 
19
  Multi-table updates were introduced by Sinisa & Monty
 
20
*/
 
21
#include "config.h"
 
22
#include "drizzled/sql_select.h"
 
23
#include "drizzled/error.h"
 
24
#include "drizzled/probes.h"
 
25
#include "drizzled/sql_base.h"
 
26
#include "drizzled/field/timestamp.h"
 
27
#include "drizzled/sql_parse.h"
 
28
#include "drizzled/optimizer/range.h"
 
29
#include "drizzled/records.h"
 
30
#include "drizzled/internal/my_sys.h"
 
31
#include "drizzled/internal/iocache.h"
 
32
 
 
33
#include <list>
 
34
 
 
35
using namespace std;
 
36
 
 
37
namespace drizzled
 
38
{
 
39
 
 
40
/**
 
41
  Re-read record if more columns are needed for error message.
 
42
 
 
43
  If we got a duplicate key error, we want to write an error
 
44
  message containing the value of the duplicate key. If we do not have
 
45
  all fields of the key value in record[0], we need to re-read the
 
46
  record with a proper read_set.
 
47
 
 
48
  @param[in] error   error number
 
49
  @param[in] table   table
 
50
*/
 
51
 
 
52
static void prepare_record_for_error_message(int error, Table *table)
 
53
{
 
54
  Field **field_p;
 
55
  Field *field;
 
56
  uint32_t keynr;
 
57
  MyBitmap unique_map; /* Fields in offended unique. */
 
58
  my_bitmap_map unique_map_buf[bitmap_buffer_size(MAX_FIELDS)];
 
59
 
 
60
  /*
 
61
    Only duplicate key errors print the key value.
 
62
    If storage engine does always read all columns, we have the value alraedy.
 
63
  */
 
64
  if ((error != HA_ERR_FOUND_DUPP_KEY) ||
 
65
      !(table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ)))
 
66
    return;
 
67
 
 
68
  /*
 
69
    Get the number of the offended index.
 
70
    We will see MAX_KEY if the engine cannot determine the affected index.
 
71
  */
 
72
  if ((keynr= table->get_dup_key(error)) >= MAX_KEY)
 
73
    return;
 
74
 
 
75
  /* Create unique_map with all fields used by that index. */
 
76
  unique_map.init(unique_map_buf, table->s->fields);
 
77
  table->mark_columns_used_by_index_no_reset(keynr, &unique_map);
 
78
 
 
79
  /* Subtract read_set and write_set. */
 
80
  bitmap_subtract(&unique_map, table->read_set);
 
81
  bitmap_subtract(&unique_map, table->write_set);
 
82
 
 
83
  /*
 
84
    If the unique index uses columns that are neither in read_set
 
85
    nor in write_set, we must re-read the record.
 
86
    Otherwise no need to do anything.
 
87
  */
 
88
  if (unique_map.isClearAll())
 
89
    return;
 
90
 
 
91
  /* Get identifier of last read record into table->cursor->ref. */
 
92
  table->cursor->position(table->record[0]);
 
93
  /* Add all fields used by unique index to read_set. */
 
94
  bitmap_union(table->read_set, &unique_map);
 
95
  /* Read record that is identified by table->cursor->ref. */
 
96
  (void) table->cursor->rnd_pos(table->record[1], table->cursor->ref);
 
97
  /* Copy the newly read columns into the new record. */
 
98
  for (field_p= table->field; (field= *field_p); field_p++)
 
99
    if (unique_map.isBitSet(field->field_index))
 
100
      field->copy_from_tmp(table->s->rec_buff_length);
 
101
 
 
102
  return;
 
103
}
 
104
 
 
105
 
 
106
/*
 
107
  Process usual UPDATE
 
108
 
 
109
  SYNOPSIS
 
110
    mysql_update()
 
111
    session                     thread handler
 
112
    fields              fields for update
 
113
    values              values of fields for update
 
114
    conds               WHERE clause expression
 
115
    order_num           number of elemen in ORDER BY clause
 
116
    order               order_st BY clause list
 
117
    limit               limit clause
 
118
    handle_duplicates   how to handle duplicates
 
119
 
 
120
  RETURN
 
121
    0  - OK
 
122
    1  - error
 
123
*/
 
124
 
 
125
int mysql_update(Session *session, TableList *table_list,
 
126
                 List<Item> &fields, List<Item> &values, COND *conds,
 
127
                 uint32_t order_num, order_st *order,
 
128
                 ha_rows limit, enum enum_duplicates,
 
129
                 bool ignore)
 
130
{
 
131
  bool          using_limit= limit != HA_POS_ERROR;
 
132
  bool          used_key_is_modified;
 
133
  bool          transactional_table;
 
134
  bool          can_compare_record;
 
135
  int           error;
 
136
  uint          used_index= MAX_KEY, dup_key_found;
 
137
  bool          need_sort= true;
 
138
  ha_rows       updated, found;
 
139
  key_map       old_covering_keys;
 
140
  Table         *table;
 
141
  optimizer::SqlSelect *select= NULL;
 
142
  READ_RECORD   info;
 
143
  Select_Lex    *select_lex= &session->lex->select_lex;
 
144
  uint64_t     id;
 
145
  List<Item> all_fields;
 
146
  Session::killed_state killed_status= Session::NOT_KILLED;
 
147
 
 
148
  DRIZZLE_UPDATE_START(session->query.c_str());
 
149
  if (session->openTablesLock(table_list))
 
150
  {
 
151
    DRIZZLE_UPDATE_DONE(1, 0, 0);
 
152
    return 1;
 
153
  }
 
154
 
 
155
  session->set_proc_info("init");
 
156
  table= table_list->table;
 
157
 
 
158
  /* Calculate "table->covering_keys" based on the WHERE */
 
159
  table->covering_keys= table->s->keys_in_use;
 
160
  table->quick_keys.reset();
 
161
 
 
162
  if (mysql_prepare_update(session, table_list, &conds, order_num, order))
 
163
    goto abort;
 
164
 
 
165
  old_covering_keys= table->covering_keys;              // Keys used in WHERE
 
166
  /* Check the fields we are going to modify */
 
167
  if (setup_fields_with_no_wrap(session, 0, fields, MARK_COLUMNS_WRITE, 0, 0))
 
168
    goto abort;
 
169
  if (table->timestamp_field)
 
170
  {
 
171
    // Don't set timestamp column if this is modified
 
172
    if (table->timestamp_field->isWriteSet())
 
173
      table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
 
174
    else
 
175
    {
 
176
      if (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
 
177
          table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH)
 
178
        table->setWriteSet(table->timestamp_field->field_index);
 
179
    }
 
180
  }
 
181
 
 
182
  if (setup_fields(session, 0, values, MARK_COLUMNS_READ, 0, 0))
 
183
  {
 
184
    free_underlaid_joins(session, select_lex);
 
185
    goto abort;
 
186
  }
 
187
 
 
188
  if (select_lex->inner_refs_list.elements &&
 
189
    fix_inner_refs(session, all_fields, select_lex, select_lex->ref_pointer_array))
 
190
  {
 
191
    DRIZZLE_UPDATE_DONE(1, 0, 0);
 
192
    return -1;
 
193
  }
 
194
 
 
195
  if (conds)
 
196
  {
 
197
    Item::cond_result cond_value;
 
198
    conds= remove_eq_conds(session, conds, &cond_value);
 
199
    if (cond_value == Item::COND_FALSE)
 
200
      limit= 0;                                   // Impossible WHERE
 
201
  }
 
202
 
 
203
  /*
 
204
    If a timestamp field settable on UPDATE is present then to avoid wrong
 
205
    update force the table handler to retrieve write-only fields to be able
 
206
    to compare records and detect data change.
 
207
  */
 
208
  if (table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) &&
 
209
      table->timestamp_field &&
 
210
      (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
 
211
       table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
 
212
    bitmap_union(table->read_set, table->write_set);
 
213
  // Don't count on usage of 'only index' when calculating which key to use
 
214
  table->covering_keys.reset();
 
215
 
 
216
  /* Update the table->cursor->stats.records number */
 
217
  table->cursor->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
 
218
 
 
219
  select= optimizer::make_select(table, 0, 0, conds, 0, &error);
 
220
  if (error || !limit ||
 
221
      (select && select->check_quick(session, false, limit)))
 
222
  {
 
223
    delete select;
 
224
    /**
 
225
     * Resetting the Diagnostic area to prevent
 
226
     * lp bug# 439719
 
227
     */
 
228
    session->main_da.reset_diagnostics_area();
 
229
    free_underlaid_joins(session, select_lex);
 
230
    if (error)
 
231
      goto abort;                               // Error in where
 
232
    DRIZZLE_UPDATE_DONE(0, 0, 0);
 
233
    session->my_ok();                           // No matching records
 
234
    return 0;
 
235
  }
 
236
  if (!select && limit != HA_POS_ERROR)
 
237
  {
 
238
    if ((used_index= optimizer::get_index_for_order(table, order, limit)) != MAX_KEY)
 
239
      need_sort= false;
 
240
  }
 
241
  /* If running in safe sql mode, don't allow updates without keys */
 
242
  if (table->quick_keys.none())
 
243
  {
 
244
    session->server_status|=SERVER_QUERY_NO_INDEX_USED;
 
245
  }
 
246
 
 
247
  table->mark_columns_needed_for_update();
 
248
 
 
249
  /* Check if we are modifying a key that we are used to search with */
 
250
 
 
251
  if (select && select->quick)
 
252
  {
 
253
    used_index= select->quick->index;
 
254
    used_key_is_modified= (!select->quick->unique_key_range() &&
 
255
                          select->quick->is_keys_used(table->write_set));
 
256
  }
 
257
  else
 
258
  {
 
259
    used_key_is_modified= 0;
 
260
    if (used_index == MAX_KEY)                  // no index for sort order
 
261
      used_index= table->cursor->key_used_on_scan;
 
262
    if (used_index != MAX_KEY)
 
263
      used_key_is_modified= is_key_used(table, used_index, table->write_set);
 
264
  }
 
265
 
 
266
 
 
267
  if (used_key_is_modified || order)
 
268
  {
 
269
    /*
 
270
      We can't update table directly;  We must first search after all
 
271
      matching rows before updating the table!
 
272
    */
 
273
    if (used_index < MAX_KEY && old_covering_keys.test(used_index))
 
274
    {
 
275
      table->key_read=1;
 
276
      table->mark_columns_used_by_index(used_index);
 
277
    }
 
278
    else
 
279
    {
 
280
      table->use_all_columns();
 
281
    }
 
282
 
 
283
    /* note: We avoid sorting avoid if we sort on the used index */
 
284
    if (order && (need_sort || used_key_is_modified))
 
285
    {
 
286
      /*
 
287
        Doing an order_st BY;  Let filesort find and sort the rows we are going
 
288
        to update
 
289
        NOTE: filesort will call table->prepare_for_position()
 
290
      */
 
291
      uint32_t         length= 0;
 
292
      SORT_FIELD  *sortorder;
 
293
      ha_rows examined_rows;
 
294
 
 
295
      table->sort.io_cache = new internal::IO_CACHE;
 
296
      memset(table->sort.io_cache, 0, sizeof(internal::IO_CACHE));
 
297
 
 
298
      if (!(sortorder=make_unireg_sortorder(order, &length, NULL)) ||
 
299
          (table->sort.found_records= filesort(session, table, sortorder, length,
 
300
                                               select, limit, 1,
 
301
                                               &examined_rows))
 
302
          == HA_POS_ERROR)
 
303
      {
 
304
        goto err;
 
305
      }
 
306
      /*
 
307
        Filesort has already found and selected the rows we want to update,
 
308
        so we don't need the where clause
 
309
      */
 
310
      delete select;
 
311
      select= 0;
 
312
    }
 
313
    else
 
314
    {
 
315
      /*
 
316
        We are doing a search on a key that is updated. In this case
 
317
        we go trough the matching rows, save a pointer to them and
 
318
        update these in a separate loop based on the pointer.
 
319
      */
 
320
 
 
321
      internal::IO_CACHE tempfile;
 
322
      if (open_cached_file(&tempfile, drizzle_tmpdir,TEMP_PREFIX,
 
323
                           DISK_BUFFER_SIZE, MYF(MY_WME)))
 
324
        goto err;
 
325
 
 
326
      /* If quick select is used, initialize it before retrieving rows. */
 
327
      if (select && select->quick && select->quick->reset())
 
328
        goto err;
 
329
      table->cursor->try_semi_consistent_read(1);
 
330
 
 
331
      /*
 
332
        When we get here, we have one of the following options:
 
333
        A. used_index == MAX_KEY
 
334
           This means we should use full table scan, and start it with
 
335
           init_read_record call
 
336
        B. used_index != MAX_KEY
 
337
           B.1 quick select is used, start the scan with init_read_record
 
338
           B.2 quick select is not used, this is full index scan (with LIMIT)
 
339
               Full index scan must be started with init_read_record_idx
 
340
      */
 
341
 
 
342
      if (used_index == MAX_KEY || (select && select->quick))
 
343
        init_read_record(&info,session,table,select,0,1);
 
344
      else
 
345
        init_read_record_idx(&info, session, table, 1, used_index);
 
346
 
 
347
      session->set_proc_info("Searching rows for update");
 
348
      ha_rows tmp_limit= limit;
 
349
 
 
350
      while (!(error=info.read_record(&info)) && !session->killed)
 
351
      {
 
352
        if (!(select && select->skip_record()))
 
353
        {
 
354
          if (table->cursor->was_semi_consistent_read())
 
355
            continue;  /* repeat the read of the same row if it still exists */
 
356
 
 
357
          table->cursor->position(table->record[0]);
 
358
          if (my_b_write(&tempfile,table->cursor->ref,
 
359
                         table->cursor->ref_length))
 
360
          {
 
361
            error=1;
 
362
            break;
 
363
          }
 
364
          if (!--limit && using_limit)
 
365
          {
 
366
            error= -1;
 
367
            break;
 
368
          }
 
369
        }
 
370
        else
 
371
          table->cursor->unlock_row();
 
372
      }
 
373
      if (session->killed && !error)
 
374
        error= 1;                               // Aborted
 
375
      limit= tmp_limit;
 
376
      table->cursor->try_semi_consistent_read(0);
 
377
      end_read_record(&info);
 
378
 
 
379
      /* Change select to use tempfile */
 
380
      if (select)
 
381
      {
 
382
        delete select->quick;
 
383
        if (select->free_cond)
 
384
          delete select->cond;
 
385
        select->quick=0;
 
386
        select->cond=0;
 
387
      }
 
388
      else
 
389
      {
 
390
        select= new optimizer::SqlSelect;
 
391
        select->head=table;
 
392
      }
 
393
      if (reinit_io_cache(&tempfile,internal::READ_CACHE,0L,0,0))
 
394
        error=1;
 
395
      // Read row ptrs from this cursor
 
396
      memcpy(select->file, &tempfile, sizeof(tempfile));
 
397
      if (error >= 0)
 
398
        goto err;
 
399
    }
 
400
    if (table->key_read)
 
401
      table->restore_column_maps_after_mark_index();
 
402
  }
 
403
 
 
404
  if (ignore)
 
405
    table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
 
406
 
 
407
  if (select && select->quick && select->quick->reset())
 
408
    goto err;
 
409
  table->cursor->try_semi_consistent_read(1);
 
410
  init_read_record(&info,session,table,select,0,1);
 
411
 
 
412
  updated= found= 0;
 
413
  /*
 
414
   * Per the SQL standard, inserting NULL into a NOT NULL
 
415
   * field requires an error to be thrown.
 
416
   *
 
417
   * @NOTE
 
418
   *
 
419
   * NULL check and handling occurs in field_conv.cc
 
420
   */
 
421
  session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
 
422
  session->cuted_fields= 0L;
 
423
  session->set_proc_info("Updating");
 
424
 
 
425
  transactional_table= table->cursor->has_transactions();
 
426
  session->abort_on_warning= test(!ignore);
 
427
 
 
428
  /*
 
429
    Assure that we can use position()
 
430
    if we need to create an error message.
 
431
  */
 
432
  if (table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ))
 
433
    table->prepare_for_position();
 
434
 
 
435
  /*
 
436
    We can use compare_record() to optimize away updates if
 
437
    the table handler is returning all columns OR if
 
438
    if all updated columns are read
 
439
  */
 
440
  can_compare_record= (!(table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ)) ||
 
441
                       bitmap_is_subset(table->write_set, table->read_set));
 
442
 
 
443
  while (!(error=info.read_record(&info)) && !session->killed)
 
444
  {
 
445
    if (!(select && select->skip_record()))
 
446
    {
 
447
      if (table->cursor->was_semi_consistent_read())
 
448
        continue;  /* repeat the read of the same row if it still exists */
 
449
 
 
450
      table->storeRecord();
 
451
      if (fill_record(session, fields, values))
 
452
        break;
 
453
 
 
454
      found++;
 
455
 
 
456
      if (!can_compare_record || table->compare_record())
 
457
      {
 
458
        /* Non-batched update */
 
459
        error= table->cursor->ha_update_row(table->record[1],
 
460
                                            table->record[0]);
 
461
        if (!error || error == HA_ERR_RECORD_IS_THE_SAME)
 
462
        {
 
463
          if (error != HA_ERR_RECORD_IS_THE_SAME)
 
464
            updated++;
 
465
          else
 
466
            error= 0;
 
467
        }
 
468
        else if (! ignore ||
 
469
                 table->cursor->is_fatal_error(error, HA_CHECK_DUP_KEY))
 
470
        {
 
471
          /*
 
472
            If (ignore && error is ignorable) we don't have to
 
473
            do anything; otherwise...
 
474
          */
 
475
          myf flags= 0;
 
476
 
 
477
          if (table->cursor->is_fatal_error(error, HA_CHECK_DUP_KEY))
 
478
            flags|= ME_FATALERROR; /* Other handler errors are fatal */
 
479
 
 
480
          prepare_record_for_error_message(error, table);
 
481
          table->print_error(error,MYF(flags));
 
482
          error= 1;
 
483
          break;
 
484
        }
 
485
      }
 
486
 
 
487
      if (!--limit && using_limit)
 
488
      {
 
489
        error= -1;                              // Simulate end of cursor
 
490
        break;
 
491
      }
 
492
    }
 
493
    else
 
494
      table->cursor->unlock_row();
 
495
    session->row_count++;
 
496
  }
 
497
  dup_key_found= 0;
 
498
  /*
 
499
    Caching the killed status to pass as the arg to query event constuctor;
 
500
    The cached value can not change whereas the killed status can
 
501
    (externally) since this point and change of the latter won't affect
 
502
    binlogging.
 
503
    It's assumed that if an error was set in combination with an effective
 
504
    killed status then the error is due to killing.
 
505
  */
 
506
  killed_status= session->killed; // get the status of the volatile
 
507
  // simulated killing after the loop must be ineffective for binlogging
 
508
  error= (killed_status == Session::NOT_KILLED)?  error : 1;
 
509
 
 
510
  updated-= dup_key_found;
 
511
  table->cursor->try_semi_consistent_read(0);
 
512
 
 
513
  if (!transactional_table && updated > 0)
 
514
    session->transaction.stmt.markModifiedNonTransData();
 
515
 
 
516
  end_read_record(&info);
 
517
  delete select;
 
518
  session->set_proc_info("end");
 
519
  table->cursor->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
 
520
 
 
521
  /*
 
522
    error < 0 means really no error at all: we processed all rows until the
 
523
    last one without error. error > 0 means an error (e.g. unique key
 
524
    violation and no IGNORE or REPLACE). error == 0 is also an error (if
 
525
    preparing the record or invoking before triggers fails). See
 
526
    ha_autocommit_or_rollback(error>=0) and return(error>=0) below.
 
527
    Sometimes we want to binlog even if we updated no rows, in case user used
 
528
    it to be sure master and slave are in same state.
 
529
  */
 
530
  if ((error < 0) || session->transaction.stmt.hasModifiedNonTransData())
 
531
  {
 
532
    if (session->transaction.stmt.hasModifiedNonTransData())
 
533
      session->transaction.all.markModifiedNonTransData();
 
534
  }
 
535
  assert(transactional_table || !updated || session->transaction.stmt.hasModifiedNonTransData());
 
536
  free_underlaid_joins(session, select_lex);
 
537
 
 
538
  /* If LAST_INSERT_ID(X) was used, report X */
 
539
  id= session->arg_of_last_insert_id_function ?
 
540
    session->first_successful_insert_id_in_prev_stmt : 0;
 
541
 
 
542
  if (error < 0)
 
543
  {
 
544
    char buff[STRING_BUFFER_USUAL_SIZE];
 
545
    sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
 
546
            (ulong) session->cuted_fields);
 
547
    session->row_count_func= updated;
 
548
    /**
 
549
     * Resetting the Diagnostic area to prevent
 
550
     * lp bug# 439719
 
551
     */
 
552
    session->main_da.reset_diagnostics_area();
 
553
    session->my_ok((ulong) session->row_count_func, found, id, buff);
 
554
  }
 
555
  session->count_cuted_fields= CHECK_FIELD_IGNORE;              /* calc cuted fields */
 
556
  session->abort_on_warning= 0;
 
557
  DRIZZLE_UPDATE_DONE((error >= 0 || session->is_error()), found, updated);
 
558
  return ((error >= 0 || session->is_error()) ? 1 : 0);
 
559
 
 
560
err:
 
561
  delete select;
 
562
  free_underlaid_joins(session, select_lex);
 
563
  if (table->key_read)
 
564
  {
 
565
    table->key_read=0;
 
566
    table->cursor->extra(HA_EXTRA_NO_KEYREAD);
 
567
  }
 
568
  session->abort_on_warning= 0;
 
569
 
 
570
abort:
 
571
  DRIZZLE_UPDATE_DONE(1, 0, 0);
 
572
  return 1;
 
573
}
 
574
 
 
575
/*
 
576
  Prepare items in UPDATE statement
 
577
 
 
578
  SYNOPSIS
 
579
    mysql_prepare_update()
 
580
    session                     - thread handler
 
581
    table_list          - global/local table list
 
582
    conds               - conditions
 
583
    order_num           - number of ORDER BY list entries
 
584
    order               - ORDER BY clause list
 
585
 
 
586
  RETURN VALUE
 
587
    false OK
 
588
    true  error
 
589
*/
 
590
bool mysql_prepare_update(Session *session, TableList *table_list,
 
591
                         Item **conds, uint32_t order_num, order_st *order)
 
592
{
 
593
  List<Item> all_fields;
 
594
  Select_Lex *select_lex= &session->lex->select_lex;
 
595
 
 
596
  session->lex->allow_sum_func= 0;
 
597
 
 
598
  if (setup_tables_and_check_access(session, &select_lex->context,
 
599
                                    &select_lex->top_join_list,
 
600
                                    table_list,
 
601
                                    &select_lex->leaf_tables,
 
602
                                    false) ||
 
603
      session->setup_conds(table_list, conds) ||
 
604
      select_lex->setup_ref_array(session, order_num) ||
 
605
      setup_order(session, select_lex->ref_pointer_array,
 
606
                  table_list, all_fields, all_fields, order))
 
607
    return true;
 
608
 
 
609
  /* Check that we are not using table that we are updating in a sub select */
 
610
  {
 
611
    TableList *duplicate;
 
612
    if ((duplicate= unique_table(table_list, table_list->next_global)))
 
613
    {
 
614
      my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
 
615
      return true;
 
616
    }
 
617
  }
 
618
 
 
619
  return false;
 
620
}
 
621
 
 
622
} /* namespace drizzled */