~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_update.cc

  • Committer: Brian Aker
  • Date: 2009-04-13 16:22:40 UTC
  • mfrom: (971.1.78 mordred)
  • Revision ID: brian@gaz-20090413162240-ugi3gvhofmcuglzl
Merge 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
 
 
30
using namespace std;
 
31
 
28
32
/*
29
33
  check that all fields are real fields
30
34
 
61
65
  return false;
62
66
}
63
67
 
64
 
 
65
68
/**
66
69
  Re-read record if more columns are needed for error message.
67
70
 
79
82
  Field **field_p;
80
83
  Field *field;
81
84
  uint32_t keynr;
82
 
  MY_BITMAP unique_map; /* Fields in offended unique. */
83
 
  my_bitmap_map unique_map_buf[bitmap_buffer_size(MAX_FIELDS)];
 
85
  bitset<MAX_FIELDS> unique_map; /* Fields in offended unique */
84
86
 
85
87
  /*
86
88
    Only duplicate key errors print the key value.
98
100
    return;
99
101
 
100
102
  /* Create unique_map with all fields used by that index. */
101
 
  bitmap_init(&unique_map, unique_map_buf, table->s->fields, false);
102
103
  table->mark_columns_used_by_index_no_reset(keynr, &unique_map);
103
104
 
104
105
  /* Subtract read_set and write_set. */
105
 
  bitmap_subtract(&unique_map, table->read_set);
106
 
  bitmap_subtract(&unique_map, table->write_set);
 
106
  unique_map &= table->read_set->flip();
 
107
  unique_map &= table->write_set->flip();
 
108
  table->read_set->flip();
 
109
  table->write_set->flip();
107
110
 
108
111
  /*
109
112
    If the unique index uses columns that are neither in read_set
110
113
    nor in write_set, we must re-read the record.
111
114
    Otherwise no need to do anything.
112
115
  */
113
 
  if (bitmap_is_clear_all(&unique_map))
 
116
  if (unique_map.none())
114
117
    return;
115
118
 
116
119
  /* Get identifier of last read record into table->file->ref. */
117
120
  table->file->position(table->record[0]);
118
121
  /* Add all fields used by unique index to read_set. */
119
 
  bitmap_union(table->read_set, &unique_map);
 
122
  *(table->read_set) |= unique_map;
120
123
  /* Tell the engine about the new set. */
121
124
  table->file->column_bitmaps_signal();
122
125
  /* Read record that is identified by table->file->ref. */
123
126
  (void) table->file->rnd_pos(table->record[1], table->file->ref);
124
127
  /* Copy the newly read columns into the new record. */
125
128
  for (field_p= table->field; (field= *field_p); field_p++)
126
 
    if (bitmap_is_set(&unique_map, field->field_index))
 
129
    if (unique_map.test(field->field_index))
127
130
      field->copy_from_tmp(table->s->rec_buff_length);
128
131
 
129
132
  return;
209
212
  if (table->timestamp_field)
210
213
  {
211
214
    // Don't set timestamp column if this is modified
212
 
    if (bitmap_is_set(table->write_set,
213
 
                      table->timestamp_field->field_index))
 
215
    if (table->write_set->test(table->timestamp_field->field_index))
214
216
      table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
215
217
    else
216
218
    {
217
219
      if (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
218
220
          table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH)
219
 
        bitmap_set_bit(table->write_set,
220
 
                       table->timestamp_field->field_index);
 
221
        table->write_set->set(table->timestamp_field->field_index);
221
222
    }
222
223
  }
223
224
 
251
252
      table->timestamp_field &&
252
253
      (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
253
254
       table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
254
 
    bitmap_union(table->read_set, table->write_set);
 
255
    *(table->read_set) |= *(table->write_set);
255
256
  // Don't count on usage of 'only index' when calculating which key to use
256
257
  table->covering_keys.clear_all();
257
258
 
482
483
  */
483
484
  can_compare_record= (!(table->file->ha_table_flags() &
484
485
                         HA_PARTIAL_COLUMN_READ) ||
485
 
                       bitmap_is_subset(table->write_set, table->read_set));
 
486
                       ((*table->read_set & *table->write_set) == *table->write_set));
486
487
 
487
488
  while (!(error=info.read_record(&info)) && !session->killed)
488
489
  {
848
849
    Table *table= tl->table;
849
850
    /* Only set timestamp column if this is not modified */
850
851
    if (table->timestamp_field &&
851
 
        bitmap_is_set(table->write_set,
852
 
                      table->timestamp_field->field_index))
 
852
        table->write_set->test(table->timestamp_field->field_index))
853
853
      table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
854
854
 
855
855
    /* if table will be updated then check that it is unique */
1322
1322
      bool can_compare_record;
1323
1323
      can_compare_record= (!(table->file->ha_table_flags() &
1324
1324
                             HA_PARTIAL_COLUMN_READ) ||
1325
 
                           bitmap_is_subset(table->write_set,
1326
 
                                            table->read_set));
 
1325
                           ((*table->read_set & *table->write_set) == *table->write_set));
1327
1326
      table->status|= STATUS_UPDATED;
1328
1327
      store_record(table,record[1]);
1329
1328
      if (fill_record(session, *fields_for_table[offset],
1522
1521
 
1523
1522
    can_compare_record= (!(table->file->ha_table_flags() &
1524
1523
                           HA_PARTIAL_COLUMN_READ) ||
1525
 
                         bitmap_is_subset(table->write_set,
1526
 
                                          table->read_set));
 
1524
                         ((*table->read_set & *table->write_set) == *table->write_set));
1527
1525
 
1528
1526
    for (;;)
1529
1527
    {