diff options
author | Sergei Golubchik <serg@mariadb.org> | 2017-02-01 18:00:16 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2017-02-13 18:12:05 +0100 |
commit | 3cae225b0ff8751a5708bfe4ab0cf52b1badc37e (patch) | |
tree | d2ce0640322a1f3e64c2d0c5ca258fdd20b08694 | |
parent | 9fa6589f64654642543c88a53dfba8c4ef5a215e (diff) | |
download | mariadb-git-3cae225b0ff8751a5708bfe4ab0cf52b1badc37e.tar.gz |
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 1d0acc7754a44613d2ad and cf97cbd1db762c443aa3
-rw-r--r-- | sql/key.cc | 12 | ||||
-rw-r--r-- | sql/sql_update.cc | 2 | ||||
-rw-r--r-- | sql/table.cc | 28 | ||||
-rw-r--r-- | sql/table.h | 1 |
4 files changed, 6 insertions, 37 deletions
diff --git a/sql/key.cc b/sql/key.cc index 31b65adabe9..3bb009fcac9 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -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); } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 4aa68c51b3e..a74a4c2b761 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -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(); diff --git a/sql/table.cc b/sql/table.cc index 078ba5b075b..5b491e3e892 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -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); } diff --git a/sql/table.h b/sql/table.h index 845c94b11c4..61efea0c5b3 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1310,7 +1310,6 @@ public: 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); |