| 8358 | */ |
| 8359 | |
| 8360 | TABLE_LIST *st_select_lex::nest_last_join(THD *thd) |
| 8361 | { |
| 8362 | TABLE_LIST *ptr; |
| 8363 | NESTED_JOIN *nested_join; |
| 8364 | List<TABLE_LIST> *embedded_list; |
| 8365 | DBUG_ENTER("nest_last_join"); |
| 8366 | |
| 8367 | TABLE_LIST *head= join_list->head(); |
| 8368 | if (head->nested_join && (head->nested_join->nest_type & REBALANCED_NEST)) |
| 8369 | { |
| 8370 | head= join_list->pop(); |
| 8371 | DBUG_RETURN(head); |
| 8372 | } |
| 8373 | |
| 8374 | if (unlikely(!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+ |
| 8375 | sizeof(NESTED_JOIN))))) |
| 8376 | DBUG_RETURN(0); |
| 8377 | nested_join= ptr->nested_join= |
| 8378 | ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST)))); |
| 8379 | |
| 8380 | ptr->embedding= embedding; |
| 8381 | ptr->join_list= join_list; |
| 8382 | ptr->alias.str= "(nest_last_join)"; |
| 8383 | ptr->alias.length= sizeof("(nest_last_join)")-1; |
| 8384 | embedded_list= &nested_join->join_list; |
| 8385 | embedded_list->empty(); |
| 8386 | nested_join->nest_type= JOIN_OP_NEST; |
| 8387 | |
| 8388 | for (uint i=0; i < 2; i++) |
| 8389 | { |
| 8390 | TABLE_LIST *table= join_list->pop(); |
| 8391 | if (unlikely(!table)) |
| 8392 | DBUG_RETURN(NULL); |
| 8393 | table->join_list= embedded_list; |
| 8394 | table->embedding= ptr; |
| 8395 | embedded_list->push_back(table); |
| 8396 | if (table->natural_join) |
| 8397 | { |
| 8398 | ptr->is_natural_join= TRUE; |
| 8399 | /* |
| 8400 | If this is a JOIN ... USING, move the list of joined fields to the |
| 8401 | table reference that describes the join. |
| 8402 | */ |
| 8403 | if (prev_join_using) |
| 8404 | ptr->join_using_fields= prev_join_using; |
| 8405 | } |
| 8406 | } |
| 8407 | nested_join->used_tables= nested_join->not_null_tables= (table_map) 0; |
| 8408 | DBUG_RETURN(ptr); |
| 8409 | } |
| 8410 | |
| 8411 | |
| 8412 | /** |