| 19543 | */ |
| 19544 | |
| 19545 | static void update_const_equal_items(THD *thd, COND *cond, JOIN_TAB *tab, |
| 19546 | bool const_key) |
| 19547 | { |
| 19548 | if (!(cond->used_tables() & tab->table->map)) |
| 19549 | return; |
| 19550 | |
| 19551 | if (cond->type() == Item::COND_ITEM) |
| 19552 | { |
| 19553 | List<Item> *cond_list= ((Item_cond*) cond)->argument_list(); |
| 19554 | List_iterator_fast<Item> li(*cond_list); |
| 19555 | Item *item; |
| 19556 | while ((item= li++)) |
| 19557 | update_const_equal_items(thd, item, tab, |
| 19558 | cond->is_top_level_item() && |
| 19559 | ((Item_cond*) cond)->functype() == |
| 19560 | Item_func::COND_AND_FUNC); |
| 19561 | } |
| 19562 | else if (cond->type() == Item::FUNC_ITEM && |
| 19563 | ((Item_func*) cond)->functype() == Item_func::MULT_EQUAL_FUNC) |
| 19564 | { |
| 19565 | Item_equal *item_equal= (Item_equal *) cond; |
| 19566 | bool contained_const= item_equal->get_const() != NULL; |
| 19567 | item_equal->update_const(thd); |
| 19568 | if (!contained_const && item_equal->get_const()) |
| 19569 | { |
| 19570 | /* Update keys for range analysis */ |
| 19571 | Item_equal_fields_iterator it(*item_equal); |
| 19572 | while (it++) |
| 19573 | { |
| 19574 | Field *field= it.get_curr_field(); |
| 19575 | JOIN_TAB *stat= field->table->reginfo.join_tab; |
| 19576 | key_map possible_keys= field->key_start; |
| 19577 | possible_keys.intersect(field->table->keys_in_use_for_query); |
| 19578 | stat[0].const_keys.merge(possible_keys); |
| 19579 | |
| 19580 | /* |
| 19581 | For each field in the multiple equality (for which we know that it |
| 19582 | is a constant) we have to find its corresponding key part, and set |
| 19583 | that key part in const_key_parts. |
| 19584 | */ |
| 19585 | if (!possible_keys.is_clear_all()) |
| 19586 | { |
| 19587 | TABLE *field_tab= field->table; |
| 19588 | KEYUSE *use; |
| 19589 | for (use= stat->keyuse; use && use->table == field_tab; use++) |
| 19590 | if (const_key && |
| 19591 | !use->is_for_hash_join() && possible_keys.is_set(use->key) && |
| 19592 | field_tab->key_info[use->key].key_part[use->keypart].field == |
| 19593 | field) |
| 19594 | field_tab->const_key_parts[use->key]|= use->keypart_map; |
| 19595 | } |
| 19596 | } |
| 19597 | } |
| 19598 | } |
| 19599 | } |
| 19600 | |
| 19601 | |
| 19602 | /** |
no test coverage detected