| 13690 | } |
| 13691 | |
| 13692 | static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, |
| 13693 | KEYUSE *org_keyuse, bool allow_full_scan, |
| 13694 | table_map used_tables) |
| 13695 | { |
| 13696 | uint keyparts, length, key; |
| 13697 | TABLE *table; |
| 13698 | KEY *keyinfo; |
| 13699 | KEYUSE *keyuse= org_keyuse; |
| 13700 | bool ftkey= (keyuse->keypart == FT_KEYPART); |
| 13701 | THD *thd= join->thd; |
| 13702 | DBUG_ENTER("create_ref_for_key"); |
| 13703 | |
| 13704 | /* Use best key from find_best */ |
| 13705 | table= j->table; |
| 13706 | key= keyuse->key; |
| 13707 | if (!is_hash_join_key_no(key)) |
| 13708 | keyinfo= table->key_info+key; |
| 13709 | else |
| 13710 | { |
| 13711 | if (create_hj_key_for_table(join, j, org_keyuse, used_tables)) |
| 13712 | DBUG_RETURN(TRUE); |
| 13713 | keyinfo= j->hj_key; |
| 13714 | } |
| 13715 | |
| 13716 | if (ftkey) |
| 13717 | { |
| 13718 | Item_func_match *ifm=(Item_func_match *)keyuse->val; |
| 13719 | |
| 13720 | length=0; |
| 13721 | keyparts=1; |
| 13722 | ifm->join_key=1; |
| 13723 | } |
| 13724 | else |
| 13725 | { |
| 13726 | keyparts=length=0; |
| 13727 | uint found_part_ref_or_null= 0; |
| 13728 | /* |
| 13729 | Calculate length for the used key |
| 13730 | Stop if there is a missing key part or when we find second key_part |
| 13731 | with KEY_OPTIMIZE_REF_OR_NULL |
| 13732 | */ |
| 13733 | do |
| 13734 | { |
| 13735 | if (!(~used_tables & keyuse->used_tables) && |
| 13736 | (!keyuse->validity_ref || *keyuse->validity_ref) && |
| 13737 | j->keyuse_is_valid_for_access_in_chosen_plan(join, keyuse)) |
| 13738 | { |
| 13739 | if (are_tables_local(j, keyuse->val->used_tables())) |
| 13740 | { |
| 13741 | if ((is_hash_join_key_no(key) && keyuse->keypart != NO_KEYPART) || |
| 13742 | (!is_hash_join_key_no(key) && keyparts == keyuse->keypart && |
| 13743 | !(found_part_ref_or_null & keyuse->optimize))) |
| 13744 | { |
| 13745 | length+= keyinfo->key_part[keyparts].store_length; |
| 13746 | keyparts++; |
| 13747 | found_part_ref_or_null|= keyuse->optimize & ~KEY_OPTIMIZE_EQ; |
| 13748 | } |
| 13749 | } |