52
53
static void prepare_record_for_error_message(int error, Table *table)
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;
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.
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)))
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);
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;
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.
88
if (unique_map.isClearAll())
87
if (unique_map.none())
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++)
100
if (unique_map.isBitSet(field->field_index))
99
if (unique_map.test(field->field_index))
102
101
field->copy_from_tmp(table->getShare()->rec_buff_length);
219
217
(table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_UPDATE ||
220
218
table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
222
bitmap_union(table->read_set, table->write_set);
220
*table->read_set|= *table->write_set;
224
222
// Don't count on usage of 'only index' when calculating which key to use
225
223
table->covering_keys.reset();
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);
451
449
the table handler is returning all columns OR if
452
450
if all updated columns are read
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));
457
while (!(error=info.read_record(&info)) && !session->killed)
455
while (! (error=info.read_record(&info)) && !session->killed)
459
if (!(select && select->skip_record()))
457
if (! (select && select->skip_record()))
461
459
if (table->cursor->was_semi_consistent_read())
462
460
continue; /* repeat the read of the same row if it still exists */