| 13532 | |
| 13533 | |
| 13534 | bool Sql_cmd_create_table_like::execute(THD *thd) |
| 13535 | { |
| 13536 | DBUG_ENTER("Sql_cmd_create_table::execute"); |
| 13537 | LEX *lex= thd->lex; |
| 13538 | SELECT_LEX *select_lex= lex->first_select_lex(); |
| 13539 | TABLE_LIST *first_table= select_lex->table_list.first; |
| 13540 | DBUG_ASSERT(first_table == lex->query_tables); |
| 13541 | DBUG_ASSERT(first_table != 0); |
| 13542 | bool link_to_local; |
| 13543 | TABLE_LIST *create_table= first_table; |
| 13544 | TABLE_LIST *select_tables= lex->create_last_non_select_table->next_global; |
| 13545 | /* most outer SELECT_LEX_UNIT of query */ |
| 13546 | SELECT_LEX_UNIT *unit= &lex->unit; |
| 13547 | int res= 0; |
| 13548 | |
| 13549 | const bool used_engine= lex->create_info.used_fields & HA_CREATE_USED_ENGINE; |
| 13550 | ulong binlog_format= thd->wsrep_binlog_format(thd->variables.binlog_format); |
| 13551 | DBUG_ASSERT((m_storage_engine_name.str != NULL) == used_engine); |
| 13552 | |
| 13553 | if (lex->create_info.resolve_to_charset_collation_context(thd, |
| 13554 | thd->charset_collation_context_create_table_in_db(first_table->db.str))) |
| 13555 | DBUG_RETURN(true); |
| 13556 | |
| 13557 | if (used_engine) |
| 13558 | { |
| 13559 | if (resolve_storage_engine_with_error(thd, &lex->create_info.db_type, |
| 13560 | lex->create_info.tmp_table())) |
| 13561 | DBUG_RETURN(true); // Engine not found, substitution is not allowed |
| 13562 | |
| 13563 | if (!lex->create_info.db_type) // Not found, but substitution is allowed |
| 13564 | { |
| 13565 | lex->create_info.use_default_db_type(thd); |
| 13566 | push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, |
| 13567 | ER_WARN_USING_OTHER_HANDLER, |
| 13568 | ER_THD(thd, ER_WARN_USING_OTHER_HANDLER), |
| 13569 | hton_name(lex->create_info.db_type)->str, |
| 13570 | create_table->table_name.str); |
| 13571 | } |
| 13572 | } |
| 13573 | |
| 13574 | if (lex->tmp_table()) |
| 13575 | { |
| 13576 | status_var_decrement(thd->status_var.com_stat[SQLCOM_CREATE_TABLE]); |
| 13577 | status_var_increment(thd->status_var.com_create_tmp_table); |
| 13578 | } |
| 13579 | |
| 13580 | /* |
| 13581 | Code below (especially in mysql_create_table() and select_create |
| 13582 | methods) may modify HA_CREATE_INFO structure in LEX, so we have to |
| 13583 | use a copy of this structure to make execution prepared statement- |
| 13584 | safe. A shallow copy is enough as this code won't modify any memory |
| 13585 | referenced from this structure. |
| 13586 | */ |
| 13587 | Table_specification_st create_info(lex->create_info); |
| 13588 | /* |
| 13589 | We need to copy alter_info for the same reasons of re-execution |
| 13590 | safety, only in case of Alter_info we have to do (almost) a deep |
| 13591 | copy. |
nothing calls this directly
no test coverage detected