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

Function update_ref_and_keys

sql/sql_select.cc:7714–7842  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7712*/
7713
7714static bool
7715update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
7716 uint tables, COND *cond, table_map normal_tables,
7717 SELECT_LEX *select_lex, SARGABLE_PARAM **sargables)
7718{
7719 uint and_level,i;
7720 KEY_FIELD *key_fields, *end, *field;
7721 size_t sz;
7722 uint m= MY_MAX(select_lex->max_equal_elems,1);
7723 DBUG_ENTER("update_ref_and_keys");
7724 DBUG_PRINT("enter", ("normal_tables: %llx", normal_tables));
7725
7726 SELECT_LEX *sel=thd->lex->current_select;
7727 sel->cond_count= 0;
7728 sel->between_count= 0;
7729 if (cond)
7730 cond->walk(&Item::count_sargable_conds, sel, 0);
7731 for (i=0 ; i < tables ; i++)
7732 {
7733 if (*join_tab[i].on_expr_ref)
7734 (*join_tab[i].on_expr_ref)->walk(&Item::count_sargable_conds, sel, 0);
7735 }
7736 {
7737 List_iterator<TABLE_LIST> li(*join_tab->join->join_list);
7738 TABLE_LIST *table;
7739 while ((table= li++))
7740 {
7741 if (table->nested_join)
7742 count_cond_for_nj(sel, table);
7743 }
7744 }
7745
7746 /*
7747 We use the same piece of memory to store both KEY_FIELD
7748 and SARGABLE_PARAM structure.
7749 KEY_FIELD values are placed at the beginning this memory
7750 while SARGABLE_PARAM values are put at the end.
7751 All predicates that are used to fill arrays of KEY_FIELD
7752 and SARGABLE_PARAM structures have at most 2 arguments
7753 except BETWEEN predicates that have 3 arguments and
7754 IN predicates.
7755 This any predicate if it's not BETWEEN/IN can be used
7756 directly to fill at most 2 array elements, either of KEY_FIELD
7757 or SARGABLE_PARAM type. For a BETWEEN predicate 3 elements
7758 can be filled as this predicate is considered as
7759 sargable with respect to each of its argument.
7760 An IN predicate can require at most 1 element as currently
7761 it is considered as sargable only for its first argument.
7762 Multiple equality can add elements that are filled after
7763 substitution of field arguments by equal fields. There
7764 can be not more than select_lex->max_equal_elems such
7765 substitutions.
7766 */
7767 sz= MY_MAX(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
7768 ((sel->cond_count*2 + sel->between_count)*m+1);
7769 if (!(key_fields=(KEY_FIELD*) thd->alloc(sz)))
7770 DBUG_RETURN(TRUE); /* purecov: inspected */
7771 and_level= 0;

Callers 2

make_join_statisticsFunction · 0.85
reoptimizeMethod · 0.85

Calls 9

count_cond_for_njFunction · 0.85
add_key_fields_for_njFunction · 0.85
add_key_partFunction · 0.85
add_ft_keysFunction · 0.85
real_maybe_nullMethod · 0.80
walkMethod · 0.45
allocMethod · 0.45
add_key_fieldsMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected