~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

  • Committer: Monty Taylor
  • Date: 2009-05-08 19:27:21 UTC
  • mto: This revision was merged to the branch mainline in revision 1009.
  • Revision ID: mordred@inaugust.com-20090508192721-glbsg850k7wqp1rd
Further reversion of P.

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
  /* Tell the engine about the new set. */
125
125
  table->file->column_bitmaps_signal();
126
126
  /* Read record that is identified by table->file->ref. */
127
127
  (void) table->file->rnd_pos(table->record[1], table->file->ref);
128
128
  /* Copy the newly read columns into the new record. */
129
129
  for (field_p= table->field; (field= *field_p); field_p++)
130
 
    if (unique_map.test(field->field_index))
 
130
    if (bitmap_is_set(&unique_map, field->field_index))
131
131
      field->copy_from_tmp(table->s->rec_buff_length);
132
132
 
133
133
  return;
213
213
  if (table->timestamp_field)
214
214
  {
215
215
    // Don't set timestamp column if this is modified
216
 
    if (table->write_set->test(table->timestamp_field->field_index))
 
216
    if (bitmap_is_set(table->write_set,
 
217
                      table->timestamp_field->field_index))
217
218
      table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
218
219
    else
219
220
    {
220
221
      if (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
221
222
          table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH)
222
 
        table->write_set->set(table->timestamp_field->field_index);
 
223
        bitmap_set_bit(table->write_set,
 
224
                       table->timestamp_field->field_index);
223
225
    }
224
226
  }
225
227
 
253
255
      table->timestamp_field &&
254
256
      (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
255
257
       table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
256
 
    *(table->read_set) |= *(table->write_set);
 
258
    bitmap_union(table->read_set, table->write_set);
257
259
  // Don't count on usage of 'only index' when calculating which key to use
258
260
  table->covering_keys.clear_all();
259
261
 
484
486
  */
485
487
  can_compare_record= (!(table->file->ha_table_flags() &
486
488
                         HA_PARTIAL_COLUMN_READ) ||
487
 
                       isBitmapSubset(table->write_set, table->read_set));
 
489
                       bitmap_is_subset(table->write_set, table->read_set));
488
490
 
489
491
  while (!(error=info.read_record(&info)) && !session->killed)
490
492
  {
850
852
    Table *table= tl->table;
851
853
    /* Only set timestamp column if this is not modified */
852
854
    if (table->timestamp_field &&
853
 
        table->write_set->test(table->timestamp_field->field_index))
 
855
        bitmap_is_set(table->write_set,
 
856
                      table->timestamp_field->field_index))
854
857
      table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
855
858
 
856
859
    /* if table will be updated then check that it is unique */
1322
1325
      bool can_compare_record;
1323
1326
      can_compare_record= (!(table->file->ha_table_flags() &
1324
1327
                             HA_PARTIAL_COLUMN_READ) ||
1325
 
                           isBitmapSubset(table->write_set,
1326
 
                                          table->write_set));
 
1328
                           bitmap_is_subset(table->write_set,
 
1329
                                            table->read_set));
1327
1330
      table->status|= STATUS_UPDATED;
1328
1331
      table->storeRecord();
1329
1332
      if (fill_record(session, *fields_for_table[offset],
1525
1528
 
1526
1529
    can_compare_record= (!(table->file->ha_table_flags() &
1527
1530
                           HA_PARTIAL_COLUMN_READ) ||
1528
 
                         isBitmapSubset(table->write_set,
1529
 
                                        table->read_set));
 
1531
                         bitmap_is_subset(table->write_set,
 
1532
                                          table->read_set));
1530
1533
 
1531
1534
    for (;;)
1532
1535
    {