| 2313 | */ |
| 2314 | |
| 2315 | static bool check_prepared_statement(Prepared_statement *stmt) |
| 2316 | { |
| 2317 | THD *thd= stmt->thd; |
| 2318 | LEX *lex= stmt->lex; |
| 2319 | SELECT_LEX *select_lex= lex->first_select_lex(); |
| 2320 | TABLE_LIST *tables; |
| 2321 | enum enum_sql_command sql_command= lex->sql_command; |
| 2322 | int res= 0; |
| 2323 | DBUG_ENTER("check_prepared_statement"); |
| 2324 | DBUG_PRINT("enter",("command: %d param_count: %u", |
| 2325 | sql_command, stmt->param_count)); |
| 2326 | |
| 2327 | lex->first_lists_tables_same(); |
| 2328 | lex->fix_first_select_number(); |
| 2329 | tables= lex->query_tables; |
| 2330 | |
| 2331 | /* set context for commands which do not use setup_tables */ |
| 2332 | lex->first_select_lex()->context.resolve_in_table_list_only(select_lex-> |
| 2333 | get_table_list()); |
| 2334 | |
| 2335 | /* |
| 2336 | For the optimizer trace, this is the symmetric, for statement preparation, |
| 2337 | of what is done at statement execution (in mysql_execute_command()). |
| 2338 | */ |
| 2339 | Opt_trace_start ots(thd); |
| 2340 | ots.init(thd, tables, lex->sql_command, &lex->var_list, thd->query(), |
| 2341 | thd->query_length(), thd->variables.character_set_client); |
| 2342 | |
| 2343 | Json_writer_object trace_command(thd); |
| 2344 | Json_writer_array trace_command_steps(thd, "steps"); |
| 2345 | |
| 2346 | /* Reset warning count for each query that uses tables */ |
| 2347 | if (tables) |
| 2348 | thd->get_stmt_da()->opt_clear_warning_info(thd->query_id); |
| 2349 | |
| 2350 | if (sql_command_flags[sql_command] & CF_HA_CLOSE) |
| 2351 | mysql_ha_rm_tables(thd, tables); |
| 2352 | |
| 2353 | /* |
| 2354 | Open temporary tables that are known now. Temporary tables added by |
| 2355 | prelocking will be opened afterwards (during open_tables()). |
| 2356 | */ |
| 2357 | if (sql_command_flags[sql_command] & CF_PREOPEN_TMP_TABLES) |
| 2358 | { |
| 2359 | if (thd->open_temporary_tables(tables)) |
| 2360 | goto error; |
| 2361 | } |
| 2362 | |
| 2363 | #ifdef WITH_WSREP |
| 2364 | if (wsrep_sync_wait(thd, sql_command)) |
| 2365 | goto error; |
| 2366 | #endif |
| 2367 | switch (sql_command) { |
| 2368 | case SQLCOM_REPLACE: |
| 2369 | case SQLCOM_INSERT: |
| 2370 | res= mysql_test_insert(stmt, tables, lex->field_list, |
| 2371 | lex->many_values, |
| 2372 | lex->update_list, lex->value_list, |
no test coverage detected