summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc19
1 files changed, 11 insertions, 8 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2d6a843f7ad..7dcbafd4a88 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8512,6 +8512,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
KEYUSE *keyuse= pos->key;
KEYUSE *prev_ref_keyuse= keyuse;
uint key= keyuse->key;
+ bool used_range_selectivity= false;
/*
Check if we have a prefix of key=const that matches a quick select.
@@ -8537,6 +8538,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
keyparts++;
}
sel /= (double)table->quick_rows[key] / (double) table->stat_records();
+ used_range_selectivity= true;
}
}
@@ -8572,13 +8574,14 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
if (keyparts > keyuse->keypart)
{
/* Ok this is the keyuse that will be used for ref access */
- uint fldno;
- if (is_hash_join_key_no(key))
- fldno= keyuse->keypart;
- else
- fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1;
- if (keyuse->val->const_item())
+ if (!used_range_selectivity && keyuse->val->const_item())
{
+ uint fldno;
+ if (is_hash_join_key_no(key))
+ fldno= keyuse->keypart;
+ else
+ fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1;
+
if (table->field[fldno]->cond_selectivity > 0)
{
sel /= table->field[fldno]->cond_selectivity;
@@ -16937,9 +16940,9 @@ static void create_tmp_field_from_item_finalize(THD *thd,
static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
Item ***copy_func, bool modify_item)
{
- Field *UNINIT_VAR(new_field);
DBUG_ASSERT(thd == table->in_use);
- if ((new_field= item->create_tmp_field(false, table)))
+ Field* new_field= item->create_tmp_field(false, table);
+ if (new_field)
create_tmp_field_from_item_finalize(thd, new_field, item,
copy_func, modify_item);
return new_field;