Commit 3cae225b authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: remove TABLE::add_read_columns_used_by_index

TABLE::add_read_columns_used_by_index() is conceptually wrong,
it *adds* columns used by index to the bitmap, without clearing
it first. But it also enables keyread, meaning that *only* columns
from the index will be read. It is supposed to be used to
add columns used by an index to a bitmap that already has columns
of a primary key - for engines where a primary key is part of every
index.

The correct fix is to change mark_columns_used_by_index() to
take into account extended keys.

this reverts 1d0acc77 and cf97cbd1
parent 9fa6589f
......@@ -467,17 +467,7 @@ bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields)
{
bitmap_clear_all(&table->tmp_set);
table->mark_columns_used_by_index_no_reset(idx, &table->tmp_set);
if (bitmap_is_overlapping(&table->tmp_set, fields))
return 1;
/*
If table handler has primary key as part of the index, check that primary
key is not updated
*/
if (idx != table->s->primary_key && table->s->primary_key < MAX_KEY &&
(table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX))
return is_key_used(table, table->s->primary_key, fields);
return 0;
return bitmap_is_overlapping(&table->tmp_set, fields);
}
......
......@@ -539,7 +539,7 @@ int mysql_update(THD *thd,
MY_BITMAP *save_write_set= table->write_set;
if (query_plan.index < MAX_KEY && old_covering_keys.is_set(query_plan.index))
table->add_read_columns_used_by_index(query_plan.index);
table->mark_columns_used_by_index(query_plan.index);
else
table->use_all_columns();
......
......@@ -6093,28 +6093,6 @@ MY_BITMAP *TABLE::mark_columns_used_by_index_in_bitmap(uint index,
DBUG_RETURN(backup);
}
/*
Add fields used by a specified index to the table's read_set.
NOTE:
The original state can be restored with
restore_column_maps_after_mark_index().
*/
void TABLE::add_read_columns_used_by_index(uint index)
{
MY_BITMAP *bitmap= &tmp_set;
DBUG_ENTER("TABLE::add_read_columns_used_by_index");
file->ha_start_keyread();
bitmap_copy(bitmap, read_set);
mark_columns_used_by_index_no_reset(index, bitmap);
column_bitmaps_set(bitmap, write_set);
DBUG_VOID_RETURN;
}
/*
Restore to use normal column maps after key read
......@@ -6143,10 +6121,12 @@ void TABLE::restore_column_maps_after_mark_index(MY_BITMAP *backup)
void TABLE::mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *bitmap)
{
KEY_PART_INFO *key_part= key_info[index].key_part;
KEY_PART_INFO *key_part_end= (key_part +
key_info[index].user_defined_key_parts);
KEY_PART_INFO *key_part_end= (key_part + key_info[index].user_defined_key_parts);
for (;key_part != key_part_end; key_part++)
bitmap_set_bit(bitmap, key_part->fieldnr-1);
if (file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX &&
s->primary_key != MAX_KEY && s->primary_key != index)
mark_columns_used_by_index_no_reset(s->primary_key, bitmap);
}
......
......@@ -1310,7 +1310,6 @@ struct TABLE
MY_BITMAP *mark_columns_used_by_index_in_bitmap(uint index, MY_BITMAP *map);
MY_BITMAP *mark_columns_used_by_index(uint index)
{ return mark_columns_used_by_index_in_bitmap(index, &tmp_set); }
void add_read_columns_used_by_index(uint index);
void restore_column_maps_after_mark_index(MY_BITMAP *backup);
void mark_auto_increment_column(void);
void mark_columns_needed_for_update(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment