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

Function test_if_ref

sql/sql_select.cc:26691–26737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26689*/
26690
26691bool test_if_ref(Item *root_cond, Item_field *left_item,Item *right_item)
26692{
26693 Field *field=left_item->field;
26694 JOIN_TAB *join_tab= field->table->reginfo.join_tab;
26695 // No need to change const test
26696 if (!field->table->const_table && join_tab &&
26697 !join_tab->is_ref_for_hash_join() &&
26698 (!join_tab->first_inner ||
26699 *join_tab->first_inner->on_expr_ref == root_cond))
26700 {
26701 /*
26702 If ref access uses "Full scan on NULL key" (i.e. it actually alternates
26703 between ref access and full table scan), then no equality can be
26704 guaranteed to be true.
26705 */
26706 if (join_tab->ref.is_access_triggered())
26707 return FALSE;
26708
26709 Item *ref_item=part_of_refkey(field->table,field);
26710 if (ref_item && (ref_item->eq(right_item,1) ||
26711 ref_item->real_item()->eq(right_item,1)))
26712 {
26713 right_item= right_item->real_item();
26714 if (right_item->type() == Item::FIELD_ITEM)
26715 return (field->eq_def(((Item_field *) right_item)->field));
26716 /* remove equalities injected by IN->EXISTS transformation */
26717 else if (right_item->type() == Item::CACHE_ITEM)
26718 return ((Item_cache *)right_item)->eq_def (field);
26719 if (right_item->const_item() && !(right_item->is_null()))
26720 {
26721 /*
26722 We can remove binary fields and numerical fields except float,
26723 as float comparison isn't 100 % safe
26724 We have to keep normal strings to be able to check for end spaces
26725 */
26726 if (field->binary() &&
26727 field->real_type() != MYSQL_TYPE_STRING &&
26728 field->real_type() != MYSQL_TYPE_VARCHAR &&
26729 (field->type() != MYSQL_TYPE_FLOAT || field->decimals() == 0))
26730 {
26731 return !right_item->save_in_field_no_warnings(field, 1);
26732 }
26733 }
26734 }
26735 }
26736 return 0; // keep test
26737}
26738
26739
26740/**

Callers 3

make_cond_after_sjmFunction · 0.85

Calls 13

part_of_refkeyFunction · 0.85
is_ref_for_hash_joinMethod · 0.80
is_access_triggeredMethod · 0.80
eqMethod · 0.45
real_itemMethod · 0.45
typeMethod · 0.45
eq_defMethod · 0.45
const_itemMethod · 0.45
is_nullMethod · 0.45
binaryMethod · 0.45
real_typeMethod · 0.45

Tested by

no test coverage detected