My Project
|
00001 /* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights 00002 reserved. 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; version 2 of the License. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00016 00017 #ifndef SQL_TABLE_INCLUDED 00018 #define SQL_TABLE_INCLUDED 00019 00020 #include "my_global.h" /* my_bool */ 00021 #include "my_pthread.h" 00022 #include "m_ctype.h" /* CHARSET_INFO */ 00023 #include "mysql_com.h" /* enum_field_types */ 00024 00025 class Alter_info; 00026 class Alter_table_ctx; 00027 class Create_field; 00028 struct TABLE_LIST; 00029 class THD; 00030 struct TABLE; 00031 struct handlerton; 00032 typedef struct st_ha_check_opt HA_CHECK_OPT; 00033 typedef struct st_ha_create_information HA_CREATE_INFO; 00034 typedef struct st_key KEY; 00035 typedef struct st_key_cache KEY_CACHE; 00036 typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE; 00037 typedef struct st_mysql_lex_string LEX_STRING; 00038 typedef struct st_order ORDER; 00039 00040 enum ddl_log_entry_code 00041 { 00042 /* 00043 DDL_LOG_EXECUTE_CODE: 00044 This is a code that indicates that this is a log entry to 00045 be executed, from this entry a linked list of log entries 00046 can be found and executed. 00047 DDL_LOG_ENTRY_CODE: 00048 An entry to be executed in a linked list from an execute log 00049 entry. 00050 DDL_IGNORE_LOG_ENTRY_CODE: 00051 An entry that is to be ignored 00052 */ 00053 DDL_LOG_EXECUTE_CODE = 'e', 00054 DDL_LOG_ENTRY_CODE = 'l', 00055 DDL_IGNORE_LOG_ENTRY_CODE = 'i' 00056 }; 00057 00058 enum ddl_log_action_code 00059 { 00060 /* 00061 The type of action that a DDL_LOG_ENTRY_CODE entry is to 00062 perform. 00063 DDL_LOG_DELETE_ACTION: 00064 Delete an entity 00065 DDL_LOG_RENAME_ACTION: 00066 Rename an entity 00067 DDL_LOG_REPLACE_ACTION: 00068 Rename an entity after removing the previous entry with the 00069 new name, that is replace this entry. 00070 DDL_LOG_EXCHANGE_ACTION: 00071 Exchange two entities by renaming them a -> tmp, b -> a, tmp -> b. 00072 */ 00073 DDL_LOG_DELETE_ACTION = 'd', 00074 DDL_LOG_RENAME_ACTION = 'r', 00075 DDL_LOG_REPLACE_ACTION = 's', 00076 DDL_LOG_EXCHANGE_ACTION = 'e' 00077 }; 00078 00079 enum enum_ddl_log_exchange_phase { 00080 EXCH_PHASE_NAME_TO_TEMP= 0, 00081 EXCH_PHASE_FROM_TO_NAME= 1, 00082 EXCH_PHASE_TEMP_TO_FROM= 2 00083 }; 00084 00085 00086 typedef struct st_ddl_log_entry 00087 { 00088 const char *name; 00089 const char *from_name; 00090 const char *handler_name; 00091 const char *tmp_name; 00092 uint next_entry; 00093 uint entry_pos; 00094 enum ddl_log_entry_code entry_type; 00095 enum ddl_log_action_code action_type; 00096 /* 00097 Most actions have only one phase. REPLACE does however have two 00098 phases. The first phase removes the file with the new name if 00099 there was one there before and the second phase renames the 00100 old name to the new name. EXCHANGE have three phases. 00101 */ 00102 char phase; 00103 } DDL_LOG_ENTRY; 00104 00105 typedef struct st_ddl_log_memory_entry 00106 { 00107 uint entry_pos; 00108 struct st_ddl_log_memory_entry *next_log_entry; 00109 struct st_ddl_log_memory_entry *prev_log_entry; 00110 struct st_ddl_log_memory_entry *next_active_log_entry; 00111 } DDL_LOG_MEMORY_ENTRY; 00112 00113 00114 enum enum_explain_filename_mode 00115 { 00116 EXPLAIN_ALL_VERBOSE= 0, 00117 EXPLAIN_PARTITIONS_VERBOSE, 00118 EXPLAIN_PARTITIONS_AS_COMMENT 00119 }; 00120 00121 /* Maximum length of GEOM_POINT Field */ 00122 #define MAX_LEN_GEOM_POINT_FIELD 25 00123 00124 /* depends on errmsg.txt Database `db`, Table `t` ... */ 00125 #define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63 00126 00127 #define MYSQL50_TABLE_NAME_PREFIX "#mysql50#" 00128 #define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9 00129 00130 #define WFRM_WRITE_SHADOW 1 00131 #define WFRM_INSTALL_SHADOW 2 00132 #define WFRM_PACK_FRM 4 00133 #define WFRM_KEEP_SHARE 8 00134 00135 /* Flags for conversion functions. */ 00136 static const uint FN_FROM_IS_TMP= 1 << 0; 00137 static const uint FN_TO_IS_TMP= 1 << 1; 00138 static const uint FN_IS_TMP= FN_FROM_IS_TMP | FN_TO_IS_TMP; 00139 static const uint NO_FRM_RENAME= 1 << 2; 00140 static const uint FRM_ONLY= 1 << 3; 00142 static const uint NO_HA_TABLE= 1 << 4; 00144 static const uint SKIP_SYMDIR_ACCESS= 1 << 5; 00146 static const uint NO_FK_CHECKS= 1 << 6; 00147 00148 uint filename_to_tablename(const char *from, char *to, uint to_length 00149 #ifndef DBUG_OFF 00150 , bool stay_quiet = false 00151 #endif /* DBUG_OFF */ 00152 ); 00153 uint tablename_to_filename(const char *from, char *to, uint to_length); 00154 uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length); 00155 bool check_mysql50_prefix(const char *name); 00156 uint build_table_filename(char *buff, size_t bufflen, const char *db, 00157 const char *table, const char *ext, 00158 uint flags, bool *was_truncated); 00159 // For caller's who are mostly sure that path do not truncate 00160 uint inline build_table_filename(char *buff, size_t bufflen, const char *db, 00161 const char *table, const char *ext, uint flags) 00162 { 00163 bool truncated_not_used; 00164 return build_table_filename(buff, bufflen, db, table, ext, flags, 00165 &truncated_not_used); 00166 } 00167 uint build_table_shadow_filename(char *buff, size_t bufflen, 00168 ALTER_PARTITION_PARAM_TYPE *lpt); 00169 uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen); 00170 bool mysql_create_table(THD *thd, TABLE_LIST *create_table, 00171 HA_CREATE_INFO *create_info, 00172 Alter_info *alter_info); 00173 bool mysql_create_table_no_lock(THD *thd, const char *db, 00174 const char *table_name, 00175 HA_CREATE_INFO *create_info, 00176 Alter_info *alter_info, 00177 uint select_field_count, 00178 bool *is_trans); 00179 int mysql_discard_or_import_tablespace(THD *thd, 00180 TABLE_LIST *table_list, 00181 bool discard); 00182 bool mysql_prepare_alter_table(THD *thd, TABLE *table, 00183 HA_CREATE_INFO *create_info, 00184 Alter_info *alter_info, 00185 Alter_table_ctx *alter_ctx); 00186 bool mysql_trans_prepare_alter_copy_data(THD *thd); 00187 bool mysql_trans_commit_alter_copy_data(THD *thd); 00188 bool mysql_alter_table(THD *thd, char *new_db, char *new_name, 00189 HA_CREATE_INFO *create_info, 00190 TABLE_LIST *table_list, 00191 Alter_info *alter_info, 00192 uint order_num, ORDER *order, bool ignore); 00193 bool mysql_compare_tables(TABLE *table, 00194 Alter_info *alter_info, 00195 HA_CREATE_INFO *create_info, 00196 bool *metadata_equal); 00197 bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy); 00198 bool mysql_create_like_table(THD *thd, TABLE_LIST *table, 00199 TABLE_LIST *src_table, 00200 HA_CREATE_INFO *create_info); 00201 bool mysql_rename_table(handlerton *base, const char *old_db, 00202 const char * old_name, const char *new_db, 00203 const char * new_name, uint flags); 00204 00205 bool mysql_backup_table(THD* thd, TABLE_LIST* table_list); 00206 bool mysql_restore_table(THD* thd, TABLE_LIST* table_list); 00207 00208 bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list, 00209 HA_CHECK_OPT* check_opt); 00210 bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, 00211 my_bool drop_temporary); 00212 int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, 00213 bool drop_temporary, bool drop_view, 00214 bool log_query); 00215 bool quick_rm_table(THD *thd, handlerton *base, const char *db, 00216 const char *table_name, uint flags); 00217 void close_cached_table(THD *thd, TABLE *table); 00218 bool fill_field_definition(THD *thd, 00219 class sp_head *sp, 00220 enum enum_field_types field_type, 00221 Create_field *field_def); 00222 int prepare_create_field(Create_field *sql_field, 00223 uint *blob_columns, 00224 longlong table_flags); 00225 const CHARSET_INFO* get_sql_field_charset(Create_field *sql_field, 00226 HA_CREATE_INFO *create_info); 00227 bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags); 00228 int write_bin_log(THD *thd, bool clear_error, 00229 char const *query, ulong query_length, 00230 bool is_trans= FALSE); 00231 bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry, 00232 DDL_LOG_MEMORY_ENTRY **active_entry); 00233 bool write_execute_ddl_log_entry(uint first_entry, 00234 bool complete, 00235 DDL_LOG_MEMORY_ENTRY **active_entry); 00236 bool deactivate_ddl_log_entry(uint entry_no); 00237 void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry); 00238 bool sync_ddl_log(); 00239 void release_ddl_log(); 00240 void execute_ddl_log_recovery(); 00241 bool execute_ddl_log_entry(THD *thd, uint first_entry); 00242 bool validate_comment_length(THD *thd, const char *comment_str, 00243 size_t *comment_len, uint max_len, 00244 uint err_code, const char *comment_name); 00245 00246 template<typename T> class List; 00247 void promote_first_timestamp_column(List<Create_field> *column_definitions); 00248 00249 /* 00250 These prototypes where under INNODB_COMPATIBILITY_HOOKS. 00251 */ 00252 uint explain_filename(THD* thd, const char *from, char *to, uint to_length, 00253 enum_explain_filename_mode explain_mode); 00254 00255 00256 extern MYSQL_PLUGIN_IMPORT const char *primary_key_name; 00257 extern mysql_mutex_t LOCK_gdl; 00258 00259 #endif /* SQL_TABLE_INCLUDED */