16 #include "sql_parse.h"                        
   17 #include "sql_table.h"                        
   20 #include "sql_alter.h" 
   24   :drop_list(rhs.drop_list, mem_root),
 
   25   alter_list(rhs.alter_list, mem_root),
 
   26   key_list(rhs.key_list, mem_root),
 
   27   create_list(rhs.create_list, mem_root),
 
   29   keys_onoff(rhs.keys_onoff),
 
   30   partition_names(rhs.partition_names, mem_root),
 
   31   num_parts(rhs.num_parts),
 
   32   requested_algorithm(rhs.requested_algorithm),
 
   33   requested_lock(rhs.requested_lock)
 
   44   list_copy_and_replace_each_value(drop_list, mem_root);
 
   45   list_copy_and_replace_each_value(alter_list, mem_root);
 
   46   list_copy_and_replace_each_value(key_list, mem_root);
 
   47   list_copy_and_replace_each_value(create_list, mem_root);
 
   55   if (!my_strcasecmp(system_charset_info, str->str, 
"INPLACE"))
 
   56     requested_algorithm= ALTER_TABLE_ALGORITHM_INPLACE;
 
   57   else if (!my_strcasecmp(system_charset_info, str->str, 
"COPY"))
 
   58     requested_algorithm= ALTER_TABLE_ALGORITHM_COPY;
 
   59   else if (!my_strcasecmp(system_charset_info, str->str, 
"DEFAULT"))
 
   60     requested_algorithm= ALTER_TABLE_ALGORITHM_DEFAULT;
 
   70   if (!my_strcasecmp(system_charset_info, str->str, 
"NONE"))
 
   71     requested_lock= ALTER_TABLE_LOCK_NONE;
 
   72   else if (!my_strcasecmp(system_charset_info, str->str, 
"SHARED"))
 
   73     requested_lock= ALTER_TABLE_LOCK_SHARED;
 
   74   else if (!my_strcasecmp(system_charset_info, str->str, 
"EXCLUSIVE"))
 
   75     requested_lock= ALTER_TABLE_LOCK_EXCLUSIVE;
 
   76   else if (!my_strcasecmp(system_charset_info, str->str, 
"DEFAULT"))
 
   77     requested_lock= ALTER_TABLE_LOCK_DEFAULT;
 
   84 Alter_table_ctx::Alter_table_ctx()
 
   85   : datetime_field(NULL), error_if_not_empty(false),
 
   88     new_db(NULL), new_name(NULL), new_alias(NULL),
 
   89     fk_error_if_delete_row(false), fk_error_id(NULL),
 
   98 Alter_table_ctx::Alter_table_ctx(THD *thd, 
TABLE_LIST *table_list,
 
   99                                  uint tables_opened_arg,
 
  100                                  char *new_db_arg, 
char *new_name_arg)
 
  101   : datetime_field(NULL), error_if_not_empty(false),
 
  102     tables_opened(tables_opened_arg),
 
  103     new_db(new_db_arg), new_name(new_name_arg),
 
  104     fk_error_if_delete_row(false), fk_error_id(NULL),
 
  117   alias= (lower_case_table_names == 2) ? table_list->alias : 
table_name;
 
  119   if (!new_db || !my_strcasecmp(table_alias_charset, new_db, db))
 
  124     DBUG_PRINT(
"info", (
"new_db.new_name: '%s'.'%s'", new_db, new_name));
 
  126     if (lower_case_table_names == 1) 
 
  128       my_casedn_str(files_charset_info, new_name);
 
  131     else if (lower_case_table_names == 2) 
 
  133       strmov(new_alias= new_alias_buff, new_name);
 
  134       my_casedn_str(files_charset_info, new_name);
 
  139     if (!is_database_changed() &&
 
  140         !my_strcasecmp(table_alias_charset, new_name, 
table_name))
 
  157               current_pid, thd->thread_id);
 
  159   if (lower_case_table_names)
 
  160     my_casedn_str(files_charset_info, tmp_name);
 
  162   if (table_list->table->s->tmp_table == NO_TMP_TABLE)
 
  164     build_table_filename(path, 
sizeof(path) - 1, db, 
table_name, 
"", 0);
 
  166     build_table_filename(new_path, 
sizeof(new_path) - 1, new_db, new_name, 
"", 0);
 
  168     build_table_filename(new_filename, 
sizeof(new_filename) - 1,
 
  169                          new_db, new_name, reg_ext, 0);
 
  171     build_table_filename(tmp_path, 
sizeof(tmp_path) - 1, new_db, tmp_name, 
"",
 
  181     build_tmptable_filename(thd, tmp_path, 
sizeof(tmp_path));
 
  193   SELECT_LEX *select_lex= &lex->select_lex;
 
  204   Alter_info alter_info(lex->alter_info, thd->mem_root);
 
  206   ulong priv_needed= ALTER_ACL;
 
  209   DBUG_ENTER(
"Sql_cmd_alter_table::execute");
 
  211   if (thd->is_fatal_error) 
 
  217   if (alter_info.flags & (Alter_info::ALTER_DROP_PARTITION |
 
  218                           Alter_info::ALTER_RENAME))
 
  219     priv_needed|= DROP_ACL;
 
  222   DBUG_ASSERT(select_lex->db);
 
  223   DBUG_ASSERT(!(alter_info.flags & Alter_info::ALTER_EXCHANGE_PARTITION));
 
  224   DBUG_ASSERT(!(alter_info.flags & Alter_info::ALTER_ADMIN_PARTITION));
 
  229       check_access(thd, INSERT_ACL | CREATE_ACL, select_lex->db,
 
  236   if (create_info.merge_list.first)
 
  274                            create_info.merge_list.first, FALSE, UINT_MAX, FALSE))
 
  278   if (check_grant(thd, priv_needed, first_table, FALSE, UINT_MAX, FALSE))
 
  281   if (lex->name.str && !test_all_bits(priv, INSERT_ACL | CREATE_ACL))
 
  285     memset(&tmp_table, 0, 
sizeof(tmp_table));
 
  286     tmp_table.table_name= lex->name.str;
 
  287     tmp_table.db= select_lex->db;
 
  289     if (check_grant(thd, INSERT_ACL | CREATE_ACL, &tmp_table, FALSE,
 
  295   if (create_info.data_file_name)
 
  296     push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
 
  297                         WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
 
  299   if (create_info.index_file_name)
 
  300     push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
 
  301                         WARN_OPTION_IGNORED, ER(WARN_OPTION_IGNORED),
 
  303   create_info.data_file_name= create_info.index_file_name= NULL;
 
  305   thd->enable_slow_log= opt_log_slow_admin_statements;
 
  307   result= mysql_alter_table(thd, select_lex->db, lex->name.str,
 
  311                             select_lex->order_list.elements,
 
  312                             select_lex->order_list.first,
 
  322   SELECT_LEX *select_lex= &thd->lex->select_lex;
 
  332   if (check_grant(thd, ALTER_ACL, table_list, 
false, UINT_MAX, 
false))
 
  335   thd->enable_slow_log= opt_log_slow_admin_statements;
 
  343   int table_kind= check_if_log_table(table_list->db_length, table_list->db,
 
  344                                      table_list->table_name_length,
 
  345                                      table_list->table_name, 
false);
 
  350     if (logger.is_log_table_enabled(table_kind))
 
  352       my_error(ER_BAD_LOG_STATEMENT, MYF(0), 
"ALTER");
 
  361   thd->add_to_binlog_accessed_dbs(table_list->db);
 
  364     mysql_discard_or_import_tablespace(thd, table_list,
 
  365                                        m_tablespace_op == DISCARD_TABLESPACE);