| 6586 | } |
| 6587 | |
| 6588 | SELECT_LEX * |
| 6589 | LEX::wrap_unit_into_derived(SELECT_LEX_UNIT *unit) |
| 6590 | { |
| 6591 | SELECT_LEX *wrapping_sel; |
| 6592 | Table_ident *ti; |
| 6593 | DBUG_ENTER("LEX::wrap_unit_into_derived"); |
| 6594 | |
| 6595 | if (!(wrapping_sel= alloc_select(TRUE))) |
| 6596 | DBUG_RETURN(NULL); |
| 6597 | Name_resolution_context *context= &wrapping_sel->context; |
| 6598 | context->init(); |
| 6599 | wrapping_sel->automatic_brackets= FALSE; |
| 6600 | wrapping_sel->mark_as_unit_nest(); |
| 6601 | wrapping_sel->register_unit(unit, context); |
| 6602 | |
| 6603 | /* stuff dummy SELECT * FROM (...) */ |
| 6604 | |
| 6605 | if (push_select(wrapping_sel)) // for Items & TABLE_LIST |
| 6606 | DBUG_RETURN(NULL); |
| 6607 | |
| 6608 | /* add SELECT list*/ |
| 6609 | { |
| 6610 | Item *item= new (thd->mem_root) Item_field(thd, context, star_clex_str); |
| 6611 | if (item == NULL) |
| 6612 | goto err; |
| 6613 | if (add_item_to_list(thd, item)) |
| 6614 | goto err; |
| 6615 | (wrapping_sel->with_wild)++; |
| 6616 | } |
| 6617 | |
| 6618 | unit->first_select()->set_linkage(DERIVED_TABLE_TYPE); |
| 6619 | |
| 6620 | ti= new (thd->mem_root) Table_ident(unit); |
| 6621 | if (ti == NULL) |
| 6622 | goto err; |
| 6623 | { |
| 6624 | TABLE_LIST *table_list; |
| 6625 | LEX_CSTRING alias; |
| 6626 | if (wrapping_sel->make_unique_derived_name(thd, &alias)) |
| 6627 | goto err; |
| 6628 | |
| 6629 | if (!(table_list= wrapping_sel->add_table_to_list(thd, ti, &alias, |
| 6630 | 0, TL_READ, |
| 6631 | MDL_SHARED_READ))) |
| 6632 | goto err; |
| 6633 | |
| 6634 | context->resolve_in_table_list_only(table_list); |
| 6635 | wrapping_sel->add_joined_table(table_list); |
| 6636 | } |
| 6637 | |
| 6638 | pop_select(); |
| 6639 | |
| 6640 | derived_tables|= DERIVED_SUBQUERY; |
| 6641 | |
| 6642 | DBUG_RETURN(wrapping_sel); |
| 6643 | |
| 6644 | err: |
| 6645 | pop_select(); |
nothing calls this directly
no test coverage detected