Test if a field or an item is equal to a constant value in WHERE @param cond WHERE clause expression @param comp_item Item to find in WHERE expression (if comp_field != NULL) @param comp_field Field to find in WHERE expression (if comp_item != NULL) @param[out] const_item inte
| 21530 | comp_item and comp_field parameters are mutually exclusive. |
| 21531 | */ |
| 21532 | bool |
| 21533 | const_expression_in_where(COND *cond, Item *comp_item, Field *comp_field, |
| 21534 | Item **const_item) |
| 21535 | { |
| 21536 | DBUG_ASSERT((comp_item == NULL) ^ (comp_field == NULL)); |
| 21537 | |
| 21538 | Item *intermediate= NULL; |
| 21539 | if (const_item == NULL) |
| 21540 | const_item= &intermediate; |
| 21541 | |
| 21542 | if (cond->type() == Item::COND_ITEM) |
| 21543 | { |
| 21544 | bool and_level= (((Item_cond*) cond)->functype() |
| 21545 | == Item_func::COND_AND_FUNC); |
| 21546 | List_iterator_fast<Item> li(*((Item_cond*) cond)->argument_list()); |
| 21547 | Item *item; |
| 21548 | while ((item=li++)) |
| 21549 | { |
| 21550 | bool res=const_expression_in_where(item, comp_item, comp_field, |
| 21551 | const_item); |
| 21552 | if (res) // Is a const value |
| 21553 | { |
| 21554 | if (and_level) |
| 21555 | return 1; |
| 21556 | } |
| 21557 | else if (!and_level) |
| 21558 | return 0; |
| 21559 | } |
| 21560 | return and_level ? 0 : 1; |
| 21561 | } |
| 21562 | else if (cond->eq_cmp_result() != Item::COND_OK) |
| 21563 | { // boolean compare function |
| 21564 | Item_func* func= (Item_func*) cond; |
| 21565 | if (func->functype() != Item_func::EQUAL_FUNC && |
| 21566 | func->functype() != Item_func::EQ_FUNC) |
| 21567 | return 0; |
| 21568 | Item *left_item= ((Item_func*) cond)->arguments()[0]; |
| 21569 | Item *right_item= ((Item_func*) cond)->arguments()[1]; |
| 21570 | if (equal(left_item, comp_item, comp_field)) |
| 21571 | { |
| 21572 | if (test_if_equality_guarantees_uniqueness (left_item, right_item)) |
| 21573 | { |
| 21574 | if (*const_item) |
| 21575 | return right_item->eq(*const_item, 1); |
| 21576 | *const_item=right_item; |
| 21577 | return 1; |
| 21578 | } |
| 21579 | } |
| 21580 | else if (equal(right_item, comp_item, comp_field)) |
| 21581 | { |
| 21582 | if (test_if_equality_guarantees_uniqueness (right_item, left_item)) |
| 21583 | { |
| 21584 | if (*const_item) |
| 21585 | return left_item->eq(*const_item, 1); |
| 21586 | *const_item=left_item; |
| 21587 | return 1; |
| 21588 | } |
| 21589 | } |
no test coverage detected