~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

Merge of Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/sql_base.h>
26
26
#include <drizzled/field/timestamp.h>
27
27
 
28
 
#include <bitset>
29
28
#include <list>
30
29
 
31
30
using namespace std;
66
65
  return false;
67
66
}
68
67
 
 
68
 
69
69
/**
70
70
  Re-read record if more columns are needed for error message.
71
71
 
83
83
  Field **field_p;
84
84
  Field *field;
85
85
  uint32_t keynr;
86
 
  bitset<MAX_FIELDS> unique_map; /* Fields in offended unique */
 
86
  MY_BITMAP unique_map; /* Fields in offended unique. */
 
87
  my_bitmap_map unique_map_buf[bitmap_buffer_size(MAX_FIELDS)];
87
88
 
88
89
  /*
89
90
    Only duplicate key errors print the key value.
101
102
    return;
102
103
 
103
104
  /* Create unique_map with all fields used by that index. */
 
105
  bitmap_init(&unique_map, unique_map_buf, table->s->fields, false);
104
106
  table->mark_columns_used_by_index_no_reset(keynr, &unique_map);
105
107
 
106
108
  /* Subtract read_set and write_set. */
107
 
  unique_map&= table->read_set->flip();
108
 
  unique_map&= table->write_set->flip();
109
 
  table->read_set->flip();
110
 
  table->write_set->flip();
 
109
  bitmap_subtract(&unique_map, table->read_set);
 
110
  bitmap_subtract(&unique_map, table->write_set);
111
111
 
112
112
  /*
113
113
    If the unique index uses columns that are neither in read_set
114
114
    nor in write_set, we must re-read the record.
115
115
    Otherwise no need to do anything.
116
116
  */
117
 
  if (unique_map.none())
 
117
  if (bitmap_is_clear_all(&unique_map))
118
118
    return;
119
119
 
120
120
  /* Get identifier of last read record into table->file->ref. */
121
121
  table->file->position(table->record[0]);
122
122
  /* Add all fields used by unique index to read_set. */
123
 
  *(table->read_set) |= unique_map;
 
123
  bitmap_union(table->read_set, &unique_map);
124
124
  /* Read record that is identified by table->file->ref. */
125
125
  (void) table->file->rnd_pos(table->record[1], table->file->ref);
126
126
  /* Copy the newly read columns into the new record. */
127
127
  for (field_p= table->field; (field= *field_p); field_p++)
128
 
    if (unique_map.test(field->field_index))
 
128
    if (bitmap_is_set(&unique_map, field->field_index))
129
129
      field->copy_from_tmp(table->s->rec_buff_length);
130
130
 
131
131
  return;
211
211
  if (table->timestamp_field)
212
212
  {
213
213
    // Don't set timestamp column if this is modified
214
 
    if (table->write_set->test(table->timestamp_field->field_index))
 
214
    if (table->timestamp_field->isWriteSet())
215
215
      table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
216
216
    else
217
217
    {
218
218
      if (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
219
219
          table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH)
220
 
        table->write_set->set(table->timestamp_field->field_index);
 
220
        table->setWriteSet(table->timestamp_field->field_index);
221
221
    }
222
222
  }
223
223
 
251
251
      table->timestamp_field &&
252
252
      (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
253
253
       table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
254
 
    *(table->read_set) |= *(table->write_set);
 
254
    bitmap_union(table->read_set, table->write_set);
255
255
  // Don't count on usage of 'only index' when calculating which key to use
256
256
  table->covering_keys.reset();
257
257
 
482
482
  */
483
483
  can_compare_record= (!(table->file->ha_table_flags() &
484
484
                         HA_PARTIAL_COLUMN_READ) ||
485
 
                       ((*table->read_set & *table->write_set) == *table->write_set));
 
485
                       bitmap_is_subset(table->write_set, table->read_set));
486
486
 
487
487
  while (!(error=info.read_record(&info)) && !session->killed)
488
488
  {
847
847
  {
848
848
    Table *table= tl->table;
849
849
    /* Only set timestamp column if this is not modified */
850
 
    if (table->timestamp_field &&
851
 
        table->write_set->test(table->timestamp_field->field_index))
 
850
    if (table->timestamp_field && table->timestamp_field->isWriteSet())
852
851
      table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
853
852
 
854
853
    /* if table will be updated then check that it is unique */
1320
1319
      bool can_compare_record;
1321
1320
      can_compare_record= (!(table->file->ha_table_flags() &
1322
1321
                             HA_PARTIAL_COLUMN_READ) ||
1323
 
                           ((*table->read_set & *table->write_set) == *table->write_set));
 
1322
                           bitmap_is_subset(table->write_set,
 
1323
                                            table->read_set));
1324
1324
      table->status|= STATUS_UPDATED;
1325
1325
      table->storeRecord();
1326
1326
      if (fill_record(session, *fields_for_table[offset],
1522
1522
 
1523
1523
    can_compare_record= (!(table->file->ha_table_flags() &
1524
1524
                           HA_PARTIAL_COLUMN_READ) ||
1525
 
                         ((*table->read_set & *table->write_set) == *table->write_set));
 
1525
                         bitmap_is_subset(table->write_set,
 
1526
                                          table->read_set));
1526
1527
 
1527
1528
    for (;;)
1528
1529
    {