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

Function merge_key_fields

sql/sql_select.cc:6606–6716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6604*/
6605
6606static KEY_FIELD *
6607merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end,
6608 uint and_level)
6609{
6610 if (start == new_fields)
6611 return start; // Impossible or
6612 if (new_fields == end)
6613 return start; // No new fields, skip all
6614
6615 KEY_FIELD *first_free=new_fields;
6616
6617 /* Mark all found fields in old array */
6618 for (; new_fields != end ; new_fields++)
6619 {
6620 for (KEY_FIELD *old=start ; old != first_free ; old++)
6621 {
6622 if (old->field == new_fields->field)
6623 {
6624 /*
6625 NOTE: below const_item() call really works as "!used_tables()", i.e.
6626 it can return FALSE where it is feasible to make it return TRUE.
6627
6628 The cause is as follows: Some of the tables are already known to be
6629 const tables (the detection code is in make_join_statistics(),
6630 above the update_ref_and_keys() call), but we didn't propagate
6631 information about this: TABLE::const_table is not set to TRUE, and
6632 Item::update_used_tables() hasn't been called for each item.
6633 The result of this is that we're missing some 'ref' accesses.
6634 TODO: OptimizerTeam: Fix this
6635 */
6636 if (!new_fields->val->const_item())
6637 {
6638 /*
6639 If the value matches, we can use the key reference.
6640 If not, we keep it until we have examined all new values
6641 */
6642 if (old->val->eq(new_fields->val, old->field->binary()))
6643 {
6644 old->level= and_level;
6645 old->optimize= ((old->optimize & new_fields->optimize &
6646 KEY_OPTIMIZE_EXISTS) |
6647 ((old->optimize | new_fields->optimize) &
6648 KEY_OPTIMIZE_REF_OR_NULL));
6649 old->null_rejecting= (old->null_rejecting &&
6650 new_fields->null_rejecting);
6651 }
6652 }
6653 else if (old->eq_func && new_fields->eq_func &&
6654 old->val->eq_by_collation(new_fields->val,
6655 old->field->binary(),
6656 old->field->charset()))
6657
6658 {
6659 old->level= and_level;
6660 old->optimize= ((old->optimize & new_fields->optimize &
6661 KEY_OPTIMIZE_EXISTS) |
6662 ((old->optimize | new_fields->optimize) &
6663 KEY_OPTIMIZE_REF_OR_NULL));

Callers 1

add_key_fieldsMethod · 0.85

Calls 10

eq_by_collationMethod · 0.80
can_eval_in_optimizeMethod · 0.80
const_itemMethod · 0.45
eqMethod · 0.45
binaryMethod · 0.45
charsetMethod · 0.45
is_nullMethod · 0.45
is_expensiveMethod · 0.45
maybe_nullMethod · 0.45
used_tablesMethod · 0.45

Tested by

no test coverage detected