~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

  • Committer: Brian Aker
  • Date: 2010-10-08 20:13:50 UTC
  • mfrom: (1823.1.3 trunk-drizzle)
  • Revision ID: brian@tangent.org-20101008201350-bmjpgakk12zmyw10
Overall merge of Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "drizzled/internal/my_sys.h"
31
31
#include "drizzled/internal/iocache.h"
32
32
 
 
33
#include <boost/dynamic_bitset.hpp>
33
34
#include <list>
34
35
 
35
36
using namespace std;
51
52
 
52
53
static void prepare_record_for_error_message(int error, Table *table)
53
54
{
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)];
 
55
  Field **field_p= NULL;
 
56
  Field *field= NULL;
 
57
  uint32_t keynr= 0;
59
58
 
60
59
  /*
61
60
    Only duplicate key errors print the key value.
62
61
    If storage engine does always read all columns, we have the value alraedy.
63
62
  */
64
63
  if ((error != HA_ERR_FOUND_DUPP_KEY) ||
65
 
      !(table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ)))
 
64
      ! (table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ)))
66
65
    return;
67
66
 
68
67
  /*
73
72
    return;
74
73
 
75
74
  /* Create unique_map with all fields used by that index. */
76
 
  unique_map.init(unique_map_buf, table->getMutableShare()->sizeFields());
77
 
  table->mark_columns_used_by_index_no_reset(keynr, &unique_map);
 
75
  boost::dynamic_bitset<> unique_map(table->getMutableShare()->sizeFields()); /* Fields in offended unique. */
 
76
  table->mark_columns_used_by_index_no_reset(keynr, unique_map);
78
77
 
79
78
  /* Subtract read_set and write_set. */
80
 
  bitmap_subtract(&unique_map, table->read_set);
81
 
  bitmap_subtract(&unique_map, table->write_set);
 
79
  unique_map-= *table->read_set;
 
80
  unique_map-= *table->write_set;
82
81
 
83
82
  /*
84
83
    If the unique index uses columns that are neither in read_set
85
84
    nor in write_set, we must re-read the record.
86
85
    Otherwise no need to do anything.
87
86
  */
88
 
  if (unique_map.isClearAll())
 
87
  if (unique_map.none())
89
88
    return;
90
89
 
91
90
  /* Get identifier of last read record into table->cursor->ref. */
92
91
  table->cursor->position(table->getInsertRecord());
93
92
  /* Add all fields used by unique index to read_set. */
94
 
  bitmap_union(table->read_set, &unique_map);
 
93
  *table->read_set|= unique_map;
95
94
  /* Read record that is identified by table->cursor->ref. */
96
95
  (void) table->cursor->rnd_pos(table->getUpdateRecord(), table->cursor->ref);
97
96
  /* Copy the newly read columns into the new record. */
98
97
  for (field_p= table->getFields(); (field= *field_p); field_p++)
99
98
  {
100
 
    if (unique_map.isBitSet(field->field_index))
 
99
    if (unique_map.test(field->field_index))
101
100
    {
102
101
      field->copy_from_tmp(table->getShare()->rec_buff_length);
103
102
    }
104
103
  }
105
104
 
106
 
 
107
105
  return;
108
106
}
109
107
 
219
217
      (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
220
218
       table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
221
219
  {
222
 
    bitmap_union(table->read_set, table->write_set);
 
220
    *table->read_set|= *table->write_set;
223
221
  }
224
222
  // Don't count on usage of 'only index' when calculating which key to use
225
223
  table->covering_keys.reset();
263
261
  {
264
262
    used_index= select->quick->index;
265
263
    used_key_is_modified= (!select->quick->unique_key_range() &&
266
 
                          select->quick->is_keys_used(table->write_set));
 
264
                          select->quick->is_keys_used(*table->write_set));
267
265
  }
268
266
  else
269
267
  {
271
269
    if (used_index == MAX_KEY)                  // no index for sort order
272
270
      used_index= table->cursor->key_used_on_scan;
273
271
    if (used_index != MAX_KEY)
274
 
      used_key_is_modified= is_key_used(table, used_index, table->write_set);
 
272
      used_key_is_modified= is_key_used(table, used_index, *table->write_set);
275
273
  }
276
274
 
277
275
 
451
449
    the table handler is returning all columns OR if
452
450
    if all updated columns are read
453
451
  */
454
 
  can_compare_record= (!(table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ)) ||
455
 
                       bitmap_is_subset(table->write_set, table->read_set));
 
452
  can_compare_record= (! (table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ)) ||
 
453
                       table->write_set->is_subset_of(*table->read_set));
456
454
 
457
 
  while (!(error=info.read_record(&info)) && !session->killed)
 
455
  while (! (error=info.read_record(&info)) && !session->killed)
458
456
  {
459
 
    if (!(select && select->skip_record()))
 
457
    if (! (select && select->skip_record()))
460
458
    {
461
459
      if (table->cursor->was_semi_consistent_read())
462
460
        continue;  /* repeat the read of the same row if it still exists */