summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/handler.cc2
-rw-r--r--sql/handler.h17
-rw-r--r--sql/opt_range.cc6
-rw-r--r--sql/opt_sum.cc2
-rw-r--r--sql/sql_base.cc2
-rw-r--r--sql/sql_select.cc38
-rw-r--r--sql/sql_statistics.cc3
-rw-r--r--sql/table.cc11
-rw-r--r--sql/table.h2
9 files changed, 39 insertions, 44 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 8781db30889..fb5d1699419 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -5909,7 +5909,7 @@ int handler::ha_reset()
table->s->column_bitmap_size ==
(uchar*) table->def_write_set.bitmap);
DBUG_ASSERT(bitmap_is_set_all(&table->s->all_set));
- DBUG_ASSERT(table->file->key_read == 0);
+ DBUG_ASSERT(!table->file->keyread_enabled());
/* ensure that ha_index_end / ha_rnd_end has been called */
DBUG_ASSERT(inited == NONE);
/* reset the bitmaps to point to defaults */
diff --git a/sql/handler.h b/sql/handler.h
index 017d045cdbc..3e04cf7f7b5 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -2653,8 +2653,7 @@ public:
uint errkey; /* Last dup key */
uint key_used_on_scan;
- uint active_index;
- bool key_read;
+ uint active_index, keyread;
/** Length of ref (1-8 or the clustered key length) */
uint ref_length;
@@ -2750,8 +2749,7 @@ public:
check_table_binlog_row_based_result(0),
in_range_check_pushed_down(FALSE),
key_used_on_scan(MAX_KEY),
- active_index(MAX_KEY),
- key_read(false),
+ active_index(MAX_KEY), keyread(MAX_KEY),
ref_length(sizeof(my_off_t)),
ft_handler(0), inited(NONE),
pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0),
@@ -2856,18 +2854,19 @@ public:
int ha_delete_row(const uchar * buf);
void ha_release_auto_increment();
- int ha_start_keyread()
+ bool keyread_enabled() { return keyread < MAX_KEY; }
+ int ha_start_keyread(uint idx)
{
- if (key_read)
+ if (keyread_enabled())
return 0;
- key_read= 1;
+ keyread= idx;
return extra(HA_EXTRA_KEYREAD);
}
int ha_end_keyread()
{
- if (!key_read)
+ if (!keyread_enabled())
return 0;
- key_read= 0;
+ keyread= MAX_KEY;
return extra(HA_EXTRA_NO_KEYREAD);
}
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index f013f6ae254..61fe64c3930 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -10617,7 +10617,7 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table,
/* Call multi_range_read_info() to get the MRR flags and buffer size */
quick->mrr_flags= HA_MRR_NO_ASSOCIATION |
- (table->file->key_read ? HA_MRR_INDEX_ONLY : 0);
+ (table->file->keyread_enabled() ? HA_MRR_INDEX_ONLY : 0);
if (thd->lex->sql_command != SQLCOM_SELECT)
quick->mrr_flags |= HA_MRR_USE_DEFAULT_IMPL;
@@ -10670,7 +10670,7 @@ int read_keys_and_merge_scans(THD *thd,
DBUG_ENTER("read_keys_and_merge");
/* We're going to just read rowids. */
- head->file->ha_start_keyread();
+ head->file->ha_start_keyread(head->s->primary_key);
head->prepare_for_position();
cur_quick_it.rewind();
@@ -13649,7 +13649,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::reset(void)
DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::reset");
seen_first_key= FALSE;
- head->file->ha_start_keyread(); /* We need only the key attributes */
+ head->file->ha_start_keyread(index); /* We need only the key attributes */
if ((result= file->ha_index_init(index,1)))
{
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 9d229f6aeef..e7bf4658d5c 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -968,7 +968,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
converted (for example to upper case)
*/
if (field->part_of_key.is_set(idx))
- table->file->ha_start_keyread();
+ table->file->ha_start_keyread(idx);
DBUG_RETURN(TRUE);
}
}
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index cdd70280eaf..99c67186dbd 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -859,7 +859,7 @@ void close_thread_table(THD *thd, TABLE **table_ptr)
DBUG_ENTER("close_thread_table");
DBUG_PRINT("tcache", ("table: '%s'.'%s' 0x%lx", table->s->db.str,
table->s->table_name.str, (long) table));
- DBUG_ASSERT(table->file->key_read == 0);
+ DBUG_ASSERT(!table->file->keyread_enabled());
DBUG_ASSERT(!table->file || table->file->inited == handler::NONE);
/*
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 7e642b519c6..a981e3adc60 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -11257,20 +11257,18 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
case JT_SYSTEM: // Only happens with left join
case JT_CONST: // Only happens with left join
/* Only happens with outer joins */
- tab->read_first_record= tab->type == JT_SYSTEM ?
- join_read_system :join_read_const;
- if (table->covering_keys.is_set(tab->ref.key) &&
- !table->no_keyread)
- table->file->ha_start_keyread();
+ tab->read_first_record= tab->type == JT_SYSTEM ? join_read_system
+ : join_read_const;
+ if (table->covering_keys.is_set(tab->ref.key) && !table->no_keyread)
+ table->file->ha_start_keyread(tab->ref.key);
else if ((!jcl || jcl > 4) && !tab->ref.is_access_triggered())
push_index_cond(tab, tab->ref.key);
break;
case JT_EQ_REF:
tab->read_record.unlock_row= join_read_key_unlock_row;
/* fall through */
- if (table->covering_keys.is_set(tab->ref.key) &&
- !table->no_keyread)
- table->file->ha_start_keyread();
+ if (table->covering_keys.is_set(tab->ref.key) && !table->no_keyread)
+ table->file->ha_start_keyread(tab->ref.key);
else if ((!jcl || jcl > 4) && !tab->ref.is_access_triggered())
push_index_cond(tab, tab->ref.key);
break;
@@ -11283,9 +11281,8 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
}
delete tab->quick;
tab->quick=0;
- if (table->covering_keys.is_set(tab->ref.key) &&
- !table->no_keyread)
- table->file->ha_start_keyread();
+ if (table->covering_keys.is_set(tab->ref.key) && !table->no_keyread)
+ table->file->ha_start_keyread(tab->ref.key);
else if ((!jcl || jcl > 4) && !tab->ref.is_access_triggered())
push_index_cond(tab, tab->ref.key);
break;
@@ -11348,7 +11345,7 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
if (tab->select && tab->select->quick &&
tab->select->quick->index != MAX_KEY && //not index_merge
table->covering_keys.is_set(tab->select->quick->index))
- table->file->ha_start_keyread();
+ table->file->ha_start_keyread(tab->select->quick->index);
else if (!table->covering_keys.is_clear_all() &&
!(tab->select && tab->select->quick))
{ // Only read index tree
@@ -11377,7 +11374,8 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
}
}
if (tab->select && tab->select->quick &&
- tab->select->quick->index != MAX_KEY && !tab->table->file->key_read)
+ tab->select->quick->index != MAX_KEY &&
+ !tab->table->file->keyread_enabled())
push_index_cond(tab, tab->select->quick->index);
}
break;
@@ -18830,7 +18828,7 @@ join_read_const_table(THD *thd, JOIN_TAB *tab, POSITION *pos)
table->covering_keys.is_set(tab->ref.key) && !table->no_keyread &&
(int) table->reginfo.lock_type <= (int) TL_READ_HIGH_PRIORITY)
{
- table->file->ha_start_keyread();
+ table->file->ha_start_keyread(tab->ref.key);
tab->index= tab->ref.key;
}
error=join_read_const(tab);
@@ -19350,7 +19348,7 @@ join_read_first(JOIN_TAB *tab)
DBUG_ENTER("join_read_first");
if (table->covering_keys.is_set(tab->index) && !table->no_keyread)
- table->file->ha_start_keyread();
+ table->file->ha_start_keyread(tab->index);
tab->table->status=0;
tab->read_record.read_record=join_read_next;
tab->read_record.table=table;
@@ -19389,7 +19387,7 @@ join_read_last(JOIN_TAB *tab)
DBUG_ENTER("join_read_first");
if (table->covering_keys.is_set(tab->index) && !table->no_keyread)
- table->file->ha_start_keyread();
+ table->file->ha_start_keyread(tab->index);
tab->table->status=0;
tab->read_record.read_record=join_read_prev;
tab->read_record.table=table;
@@ -21254,10 +21252,10 @@ check_reverse_order:
If ref_key used index tree reading only ('Using index' in EXPLAIN),
and best_key doesn't, then revert the decision.
*/
- if (!table->covering_keys.is_set(best_key))
- table->file->ha_end_keyread();
+ if (table->covering_keys.is_set(best_key))
+ table->file->ha_start_keyread(best_key);
else
- table->file->ha_start_keyread();
+ table->file->ha_end_keyread();
if (!quick_created)
{
@@ -24209,7 +24207,7 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta,
}
/* Build "Extra" field and save it */
- key_read=table->file->key_read;
+ key_read= table->file->keyread_enabled();
if ((tab_type == JT_NEXT || tab_type == JT_CONST) &&
table->covering_keys.is_set(index))
key_read=1;
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index 63e8b7bcec7..979852e2f6b 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -2633,8 +2633,7 @@ int collect_statistics_for_index(THD *thd, TABLE *table, uint index)
DBUG_RETURN(rc);
}
- table->file->ha_start_keyread();
-
+ table->file->ha_start_keyread(index);
table->file->ha_index_init(index, TRUE);
rc= table->file->ha_index_first(table->record[0]);
while (rc != HA_ERR_END_OF_FILE)
diff --git a/sql/table.cc b/sql/table.cc
index 093adf339b4..33317234c85 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -4436,7 +4436,7 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)
(*f_ptr)->cond_selectivity= 1.0;
}
- DBUG_ASSERT(file->key_read == 0);
+ DBUG_ASSERT(!file->keyread_enabled());
/* mark the record[0] uninitialized */
TRASH_ALLOC(record[0], s->reclength);
@@ -6075,7 +6075,7 @@ MY_BITMAP *TABLE::prepare_for_keyread(uint index, MY_BITMAP *map)
MY_BITMAP *backup= read_set;
DBUG_ENTER("TABLE::prepare_for_keyread");
if (!no_keyread)
- file->ha_start_keyread();
+ file->ha_start_keyread(index);
mark_columns_used_by_index(index, map);
column_bitmaps_set(map);
DBUG_RETURN(backup);
@@ -7310,7 +7310,7 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode)
bool handler_pushed= 0;
DBUG_ASSERT(vfield);
- if (h->key_read)
+ if (h->keyread_enabled())
DBUG_RETURN(0);
error= 0;
@@ -7364,9 +7364,8 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode)
case VCOL_UPDATE_INDEXED:
case VCOL_UPDATE_INDEXED_FOR_UPDATE:
/* Read indexed fields that was not updated in VCOL_UPDATE_FOR_READ */
- update= (!vcol_info->stored_in_db && (vf->flags & PART_KEY_FLAG) &&
- bitmap_is_set(vcol_set, vf->field_index) &&
- (h->key_read && vf->part_of_key.is_set(h->active_index)));
+ update= !vcol_info->stored_in_db && (vf->flags & PART_KEY_FLAG) &&
+ bitmap_is_set(vcol_set, vf->field_index);
swap_values= 1;
break;
}
diff --git a/sql/table.h b/sql/table.h
index adfefba3234..ec33188b688 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1402,7 +1402,7 @@ public:
{
if (created)
return;
- if (file->key_read)
+ if (file->keyread_enabled())
file->extra(HA_EXTRA_KEYREAD);
created= true;
}