~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

  • Committer: Brian Aker
  • Date: 2009-12-05 01:48:28 UTC
  • mfrom: (1237.2.12 push)
  • Revision ID: brian@gaz-20091205014828-xd4e29ujttx2xe2j
MergeĀ forĀ staging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
                 bool ignore)
124
124
{
125
125
  bool          using_limit= limit != HA_POS_ERROR;
126
 
  bool          safe_update= test(session->options & OPTION_SAFE_UPDATES);
127
 
  bool          used_key_is_modified, transactional_table, will_batch;
 
126
  bool          used_key_is_modified;
 
127
  bool          transactional_table;
128
128
  bool          can_compare_record;
129
 
  int           error, loc_error;
 
129
  int           error;
130
130
  uint          used_index= MAX_KEY, dup_key_found;
131
131
  bool          need_sort= true;
132
132
  ha_rows       updated, found;
212
212
 
213
213
  select= make_select(table, 0, 0, conds, 0, &error);
214
214
  if (error || !limit ||
215
 
      (select && select->check_quick(session, safe_update, limit)))
 
215
      (select && select->check_quick(session, false, limit)))
216
216
  {
217
217
    delete select;
218
218
    /**
236
236
  if (table->quick_keys.none())
237
237
  {
238
238
    session->server_status|=SERVER_QUERY_NO_INDEX_USED;
239
 
    if (safe_update && !using_limit)
240
 
    {
241
 
      my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
242
 
                 ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
243
 
      goto err;
244
 
    }
245
239
  }
246
240
 
247
241
  table->mark_columns_needed_for_update();
423
417
 
424
418
  transactional_table= table->cursor->has_transactions();
425
419
  session->abort_on_warning= test(!ignore);
426
 
  will_batch= !table->cursor->start_bulk_update();
427
420
 
428
421
  /*
429
422
    Assure that we can use position()
448
441
        continue;  /* repeat the read of the same row if it still exists */
449
442
 
450
443
      table->storeRecord();
451
 
      if (fill_record(session, fields, values, 0))
 
444
      if (fill_record(session, fields, values))
452
445
        break;
453
446
 
454
447
      found++;
455
448
 
456
449
      if (!can_compare_record || table->compare_record())
457
450
      {
458
 
        if (will_batch)
459
 
        {
460
 
          /*
461
 
            Typically a batched handler can execute the batched jobs when:
462
 
            1) When specifically told to do so
463
 
            2) When it is not a good idea to batch anymore
464
 
            3) When it is necessary to send batch for other reasons
465
 
               (One such reason is when READ's must be performed)
466
 
 
467
 
            1) is covered by exec_bulk_update calls.
468
 
            2) and 3) is handled by the bulk_update_row method.
469
 
 
470
 
            bulk_update_row can execute the updates including the one
471
 
            defined in the bulk_update_row or not including the row
472
 
            in the call. This is up to the handler implementation and can
473
 
            vary from call to call.
474
 
 
475
 
            The dup_key_found reports the number of duplicate keys found
476
 
            in those updates actually executed. It only reports those if
477
 
            the extra call with HA_EXTRA_IGNORE_DUP_KEY have been issued.
478
 
            If this hasn't been issued it returns an error code and can
479
 
            ignore this number. Thus any handler that implements batching
480
 
            for UPDATE IGNORE must also handle this extra call properly.
481
 
 
482
 
            If a duplicate key is found on the record included in this
483
 
            call then it should be included in the count of dup_key_found
484
 
            and error should be set to 0 (only if these errors are ignored).
485
 
          */
486
 
          error= table->cursor->ha_bulk_update_row(table->record[1],
487
 
                                                 table->record[0],
488
 
                                                 &dup_key_found);
489
 
          limit+= dup_key_found;
490
 
          updated-= dup_key_found;
491
 
        }
492
 
        else
493
 
        {
494
 
          /* Non-batched update */
495
 
          error= table->cursor->ha_update_row(table->record[1],
 
451
        /* Non-batched update */
 
452
        error= table->cursor->ha_update_row(table->record[1],
496
453
                                            table->record[0]);
497
 
        }
498
454
        if (!error || error == HA_ERR_RECORD_IS_THE_SAME)
499
455
        {
500
456
          if (error != HA_ERR_RECORD_IS_THE_SAME)
502
458
          else
503
459
            error= 0;
504
460
        }
505
 
        else if (!ignore ||
 
461
        else if (! ignore ||
506
462
                 table->cursor->is_fatal_error(error, HA_CHECK_DUP_KEY))
507
463
        {
508
464
          /*
523
479
 
524
480
      if (!--limit && using_limit)
525
481
      {
526
 
        /*
527
 
          We have reached end-of-cursor in most common situations where no
528
 
          batching has occurred and if batching was supposed to occur but
529
 
          no updates were made and finally when the batch execution was
530
 
          performed without error and without finding any duplicate keys.
531
 
          If the batched updates were performed with errors we need to
532
 
          check and if no error but duplicate key's found we need to
533
 
          continue since those are not counted for in limit.
534
 
        */
535
 
        if (will_batch &&
536
 
            ((error= table->cursor->exec_bulk_update(&dup_key_found)) ||
537
 
             dup_key_found))
538
 
        {
539
 
          if (error)
540
 
          {
541
 
            /*
542
 
              The handler should not report error of duplicate keys if they
543
 
              are ignored. This is a requirement on batching handlers.
544
 
            */
545
 
            prepare_record_for_error_message(error, table);
546
 
            table->print_error(error,MYF(0));
547
 
            error= 1;
548
 
            break;
549
 
          }
550
 
          /*
551
 
            Either an error was found and we are ignoring errors or there
552
 
            were duplicate keys found. In both cases we need to correct
553
 
            the counters and continue the loop.
554
 
          */
555
 
          limit= dup_key_found; //limit is 0 when we get here so need to +
556
 
          updated-= dup_key_found;
557
 
        }
558
 
        else
559
 
        {
560
 
          error= -1;                            // Simulate end of cursor
561
 
          break;
562
 
        }
 
482
        error= -1;                              // Simulate end of cursor
 
483
        break;
563
484
      }
564
485
    }
565
486
    else
579
500
  // simulated killing after the loop must be ineffective for binlogging
580
501
  error= (killed_status == Session::NOT_KILLED)?  error : 1;
581
502
 
582
 
  if (error &&
583
 
      will_batch &&
584
 
      (loc_error= table->cursor->exec_bulk_update(&dup_key_found)))
585
 
    /*
586
 
      An error has occurred when a batched update was performed and returned
587
 
      an error indication. It cannot be an allowed duplicate key error since
588
 
      we require the batching handler to treat this as a normal behavior.
589
 
 
590
 
      Otherwise we simply remove the number of duplicate keys records found
591
 
      in the batched update.
592
 
    */
593
 
  {
594
 
    prepare_record_for_error_message(loc_error, table);
595
 
    table->print_error(loc_error,MYF(ME_FATALERROR));
596
 
    error= 1;
597
 
  }
598
 
  else
599
 
    updated-= dup_key_found;
600
 
  if (will_batch)
601
 
    table->cursor->end_bulk_update();
 
503
  updated-= dup_key_found;
602
504
  table->cursor->try_semi_consistent_read(0);
603
505
 
604
506
  if (!transactional_table && updated > 0)