MCPcopy Create free account
hub / github.com/MariaDB/server / create_ref_for_key

Function create_ref_for_key

sql/sql_select.cc:13692–13920  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13690}
13691
13692static 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 }

Callers 3

make_join_statisticsFunction · 0.85
get_best_combinationMethod · 0.85
test_if_skip_sort_orderFunction · 0.85

Calls 13

is_hash_join_key_noFunction · 0.85
create_hj_key_for_tableFunction · 0.85
are_tables_localFunction · 0.85
get_store_keyFunction · 0.85
key_itemMethod · 0.80
actual_key_flagsMethod · 0.80
used_tablesMethod · 0.45
maybe_nullMethod · 0.45
real_itemMethod · 0.45
typeMethod · 0.45
is_errorMethod · 0.45

Tested by 1

test_if_skip_sort_orderFunction · 0.68