diff options
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index cb620495897..494e87aa489 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3380,11 +3380,13 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, The effect of this is that we don't do const substitution for such tables. */ - if (eq_part.is_prefix(table->key_info[key].key_parts) && + KEY *keyinfo= table->key_info+key; + uint key_parts= table->actual_n_key_parts(keyinfo); + if (eq_part.is_prefix(key_parts) && !table->fulltext_searched && (!embedding || (embedding->sj_on_expr && !embedding->embedding))) { - if (table->key_info[key].flags & HA_NOSAME) + if (table->actual_key_flags(keyinfo) & HA_NOSAME) { if (const_ref == eq_part && !has_expensive_keyparts && @@ -4410,7 +4412,8 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array, KEY_FIELD *key_field) if (form->key_info[key].flags & (HA_FULLTEXT | HA_SPATIAL)) continue; // ToDo: ft-keys in non-ft queries. SerG - uint key_parts= (uint) form->key_info[key].key_parts; + KEY *keyinfo= form->key_info+key; + uint key_parts= form->actual_n_key_parts(keyinfo); for (uint part=0 ; part < key_parts ; part++) { if (field->eq(form->key_info[key].key_part[part].field)) @@ -4713,7 +4716,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, /* fill keyuse with found key parts */ for ( ; field != end ; field++) { - if (add_key_part(keyuse,field)) + if (add_key_part(keyuse, field)) return TRUE; } @@ -5042,6 +5045,8 @@ best_access_path(JOIN *join, for (keyuse=s->keyuse ; keyuse->table == table ;) { KEY *keyinfo; + ulong key_flags; + uint key_parts; key_part_map found_part= 0; table_map found_ref= 0; uint key= keyuse->key; @@ -5068,6 +5073,8 @@ best_access_path(JOIN *join, } keyinfo= table->key_info+key; + key_parts= table->actual_n_key_parts(keyinfo); + key_flags= table->actual_key_flags(keyinfo); /* Calculate how many key segments of the current key we can use */ start_key= keyuse; @@ -5146,11 +5153,11 @@ best_access_path(JOIN *join, loose_scan_opt.check_ref_access_part1(s, key, start_key, found_part); /* Check if we found full key */ - if (found_part == PREV_BITS(uint,keyinfo->key_parts) && + if (found_part == PREV_BITS(uint, key_parts) && !ref_or_null_part) { /* use eq key */ max_key_part= (uint) ~0; - if ((keyinfo->flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME) + if ((key_flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME) { tmp = prev_record_reads(join->positions, idx, found_ref); records=1.0; @@ -7262,6 +7269,7 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab, key_parts))) DBUG_RETURN(TRUE); keyinfo->usable_key_parts= keyinfo->key_parts = key_parts; + keyinfo->ext_key_parts= keyinfo->key_parts; keyinfo->key_part= key_part_info; keyinfo->key_length=0; keyinfo->algorithm= HA_KEY_ALG_UNDEF; @@ -7495,8 +7503,11 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, DBUG_RETURN(0); if (j->type == JT_CONST) j->table->const_table= 1; - else if (((keyinfo->flags & (HA_NOSAME | HA_NULL_PART_KEY)) != HA_NOSAME) || - keyparts != keyinfo->key_parts || null_ref_key) + else if (((j->table->actual_key_flags(keyinfo) & + (HA_NOSAME | HA_NULL_PART_KEY)) + != HA_NOSAME) || + keyparts != j->table->actual_n_key_parts(keyinfo) || + null_ref_key) { /* Must read with repeat */ j->type= null_ref_key ? JT_REF_OR_NULL : JT_REF; |