| 21671 | */ |
| 21672 | |
| 21673 | Field * |
| 21674 | Item_field::create_tmp_field_from_item_field(MEM_ROOT *root, TABLE *new_table, |
| 21675 | Item_ref *orig_item, |
| 21676 | const Tmp_field_param *param) |
| 21677 | { |
| 21678 | DBUG_ASSERT(!is_result_field()); |
| 21679 | Field *result; |
| 21680 | const Lex_ident_column *new_name= (orig_item ? &orig_item->name : |
| 21681 | !param->modify_item() ? &name : |
| 21682 | &field->field_name); |
| 21683 | |
| 21684 | /* |
| 21685 | If item have to be able to store NULLs but underlaid field can't do it, |
| 21686 | create_tmp_field_from_field() can't be used for tmp field creation. |
| 21687 | */ |
| 21688 | if (((maybe_null() && in_rollup()) || |
| 21689 | (new_table->in_use->create_tmp_table_for_derived && /* for mat. view/dt */ |
| 21690 | orig_item && orig_item->maybe_null())) && |
| 21691 | !field->maybe_null()) |
| 21692 | { |
| 21693 | /* |
| 21694 | The item the ref points to may have maybe_null flag set while |
| 21695 | the ref doesn't have it. This may happen for outer fields |
| 21696 | when the outer query decided at some point after name resolution phase |
| 21697 | that this field might be null. Take this into account here. |
| 21698 | */ |
| 21699 | Record_addr rec(orig_item ? orig_item->maybe_null() : maybe_null()); |
| 21700 | const Type_handler *handler= type_handler()-> |
| 21701 | type_handler_for_tmp_table(this); |
| 21702 | result= handler->make_and_init_table_field(root, new_name, |
| 21703 | rec, *this, new_table); |
| 21704 | } |
| 21705 | else if (param->table_cant_handle_bit_fields() && |
| 21706 | field->type() == MYSQL_TYPE_BIT) |
| 21707 | { |
| 21708 | const Type_handler *handler= |
| 21709 | Type_handler::type_handler_long_or_longlong(max_char_length(), true); |
| 21710 | result= handler->make_and_init_table_field(root, new_name, |
| 21711 | Record_addr(maybe_null()), |
| 21712 | *this, new_table); |
| 21713 | } |
| 21714 | else |
| 21715 | { |
| 21716 | bool tmp_maybe_null= param->modify_item() ? maybe_null() : |
| 21717 | field->maybe_null(); |
| 21718 | result= field->create_tmp_field(root, new_table, tmp_maybe_null); |
| 21719 | if (result && ! param->modify_item()) |
| 21720 | result->field_name= *new_name; |
| 21721 | } |
| 21722 | if (result && param->modify_item()) |
| 21723 | result_field= result; |
| 21724 | return result; |
| 21725 | } |
| 21726 | |
| 21727 | |
| 21728 | Field *Item_field::create_tmp_field_ex(MEM_ROOT *root, TABLE *table, |
no test coverage detected