Prepare of whole select (including sub queries in future). @todo Add check of calculation of GROUP functions and fields: SELECT COUNT(*)+table.col1 from table1; @retval -1 on error @retval 0 on success */
| 1423 | 0 on success |
| 1424 | */ |
| 1425 | int |
| 1426 | JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num, |
| 1427 | ORDER *order_init, bool skip_order_by, |
| 1428 | ORDER *group_init, Item *having_init, |
| 1429 | ORDER *proc_param_init, SELECT_LEX *select_lex_arg, |
| 1430 | SELECT_LEX_UNIT *unit_arg) |
| 1431 | { |
| 1432 | DBUG_ENTER("JOIN::prepare"); |
| 1433 | |
| 1434 | // to prevent double initialization on EXPLAIN |
| 1435 | if (optimization_state != JOIN::NOT_OPTIMIZED) |
| 1436 | DBUG_RETURN(0); |
| 1437 | |
| 1438 | conds= conds_init; |
| 1439 | order= order_init; |
| 1440 | group_list= group_init; |
| 1441 | having= having_init; |
| 1442 | proc_param= proc_param_init; |
| 1443 | tables_list= tables_init; |
| 1444 | select_lex= select_lex_arg; |
| 1445 | DBUG_PRINT("info", ("select %p (%u) = JOIN %p", |
| 1446 | select_lex, select_lex->select_number, this)); |
| 1447 | select_lex->join= this; |
| 1448 | join_list= &select_lex->top_join_list; |
| 1449 | union_part= unit_arg->is_unit_op(); |
| 1450 | |
| 1451 | Json_writer_object trace_wrapper(thd); |
| 1452 | Json_writer_object trace_prepare(thd, "join_preparation"); |
| 1453 | trace_prepare.add_select_number(select_lex->select_number); |
| 1454 | Json_writer_array trace_steps(thd, "steps"); |
| 1455 | |
| 1456 | // simple check that we got usable conds |
| 1457 | dbug_print_item(conds); |
| 1458 | |
| 1459 | /* Fix items that requires the join structure to exist */ |
| 1460 | fix_items_after_optimize(thd, select_lex); |
| 1461 | |
| 1462 | /* |
| 1463 | It is hack which force creating EXPLAIN object always on runt-time arena |
| 1464 | (because very top JOIN::prepare executes always with runtime arena, but |
| 1465 | constant subquery like (SELECT 'x') can be called with statement arena |
| 1466 | during prepare phase of top SELECT). |
| 1467 | */ |
| 1468 | if (!(thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_PREPARE)) |
| 1469 | create_explain_query_if_not_exists(thd->lex, thd->mem_root); |
| 1470 | |
| 1471 | if (select_lex->handle_derived(thd->lex, DT_PREPARE)) |
| 1472 | DBUG_RETURN(-1); |
| 1473 | |
| 1474 | thd->lex->current_select->context_analysis_place= NO_MATTER; |
| 1475 | thd->lex->current_select->is_item_list_lookup= 1; |
| 1476 | /* |
| 1477 | If we have already executed SELECT, then it have not sense to prevent |
| 1478 | its table from update (see unique_table()) |
| 1479 | Affects only materialized derived tables. |
| 1480 | */ |
| 1481 | /* Check that all tables, fields, conds and order are ok */ |
| 1482 | if (!(select_options & OPTION_SETUP_TABLES_DONE) && |
no test coverage detected