MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_table.h
1 /* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef SQL_TABLE_INCLUDED
17 #define SQL_TABLE_INCLUDED
18 
19 #include "my_global.h" /* my_bool */
20 #include "my_pthread.h"
21 #include "m_ctype.h" /* CHARSET_INFO */
22 #include "mysql_com.h" /* enum_field_types */
23 
24 class Alter_info;
25 class Alter_table_ctx;
26 class Create_field;
27 struct TABLE_LIST;
28 class THD;
29 struct TABLE;
30 struct handlerton;
31 typedef struct st_ha_check_opt HA_CHECK_OPT;
33 typedef struct st_key KEY;
34 typedef struct st_key_cache KEY_CACHE;
36 typedef struct st_mysql_lex_string LEX_STRING;
37 typedef struct st_order ORDER;
38 
39 enum ddl_log_entry_code
40 {
41  /*
42  DDL_LOG_EXECUTE_CODE:
43  This is a code that indicates that this is a log entry to
44  be executed, from this entry a linked list of log entries
45  can be found and executed.
46  DDL_LOG_ENTRY_CODE:
47  An entry to be executed in a linked list from an execute log
48  entry.
49  DDL_IGNORE_LOG_ENTRY_CODE:
50  An entry that is to be ignored
51  */
52  DDL_LOG_EXECUTE_CODE = 'e',
53  DDL_LOG_ENTRY_CODE = 'l',
54  DDL_IGNORE_LOG_ENTRY_CODE = 'i'
55 };
56 
57 enum ddl_log_action_code
58 {
59  /*
60  The type of action that a DDL_LOG_ENTRY_CODE entry is to
61  perform.
62  DDL_LOG_DELETE_ACTION:
63  Delete an entity
64  DDL_LOG_RENAME_ACTION:
65  Rename an entity
66  DDL_LOG_REPLACE_ACTION:
67  Rename an entity after removing the previous entry with the
68  new name, that is replace this entry.
69  DDL_LOG_EXCHANGE_ACTION:
70  Exchange two entities by renaming them a -> tmp, b -> a, tmp -> b.
71  */
72  DDL_LOG_DELETE_ACTION = 'd',
73  DDL_LOG_RENAME_ACTION = 'r',
74  DDL_LOG_REPLACE_ACTION = 's',
75  DDL_LOG_EXCHANGE_ACTION = 'e'
76 };
77 
78 enum enum_ddl_log_exchange_phase {
79  EXCH_PHASE_NAME_TO_TEMP= 0,
80  EXCH_PHASE_FROM_TO_NAME= 1,
81  EXCH_PHASE_TEMP_TO_FROM= 2
82 };
83 
84 
85 typedef struct st_ddl_log_entry
86 {
87  const char *name;
88  const char *from_name;
89  const char *handler_name;
90  const char *tmp_name;
91  uint next_entry;
92  uint entry_pos;
93  enum ddl_log_entry_code entry_type;
94  enum ddl_log_action_code action_type;
95  /*
96  Most actions have only one phase. REPLACE does however have two
97  phases. The first phase removes the file with the new name if
98  there was one there before and the second phase renames the
99  old name to the new name. EXCHANGE have three phases.
100  */
101  char phase;
102 } DDL_LOG_ENTRY;
103 
105 {
106  uint entry_pos;
107  struct st_ddl_log_memory_entry *next_log_entry;
108  struct st_ddl_log_memory_entry *prev_log_entry;
109  struct st_ddl_log_memory_entry *next_active_log_entry;
111 
112 
113 enum enum_explain_filename_mode
114 {
115  EXPLAIN_ALL_VERBOSE= 0,
116  EXPLAIN_PARTITIONS_VERBOSE,
117  EXPLAIN_PARTITIONS_AS_COMMENT
118 };
119 
120 /* depends on errmsg.txt Database `db`, Table `t` ... */
121 #define EXPLAIN_FILENAME_MAX_EXTRA_LENGTH 63
122 
123 #define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
124 #define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9
125 
126 #define WFRM_WRITE_SHADOW 1
127 #define WFRM_INSTALL_SHADOW 2
128 #define WFRM_PACK_FRM 4
129 #define WFRM_KEEP_SHARE 8
130 
131 /* Flags for conversion functions. */
132 static const uint FN_FROM_IS_TMP= 1 << 0;
133 static const uint FN_TO_IS_TMP= 1 << 1;
134 static const uint FN_IS_TMP= FN_FROM_IS_TMP | FN_TO_IS_TMP;
135 static const uint NO_FRM_RENAME= 1 << 2;
136 static const uint FRM_ONLY= 1 << 3;
138 static const uint NO_HA_TABLE= 1 << 4;
140 static const uint SKIP_SYMDIR_ACCESS= 1 << 5;
142 static const uint NO_FK_CHECKS= 1 << 6;
143 
144 uint filename_to_tablename(const char *from, char *to, uint to_length
145 #ifndef DBUG_OFF
146  , bool stay_quiet = false
147 #endif /* DBUG_OFF */
148  );
149 uint tablename_to_filename(const char *from, char *to, uint to_length);
150 uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length);
151 bool check_mysql50_prefix(const char *name);
152 uint build_table_filename(char *buff, size_t bufflen, const char *db,
153  const char *table, const char *ext,
154  uint flags, bool *was_truncated);
155 // For caller's who are mostly sure that path do not truncate
156 uint inline build_table_filename(char *buff, size_t bufflen, const char *db,
157  const char *table, const char *ext, uint flags)
158 {
159  bool truncated_not_used;
160  return build_table_filename(buff, bufflen, db, table, ext, flags,
161  &truncated_not_used);
162 }
163 uint build_table_shadow_filename(char *buff, size_t bufflen,
165 uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen);
166 bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
167  HA_CREATE_INFO *create_info,
168  Alter_info *alter_info);
169 bool mysql_create_table_no_lock(THD *thd, const char *db,
170  const char *table_name,
171  HA_CREATE_INFO *create_info,
172  Alter_info *alter_info,
173  uint select_field_count,
174  bool *is_trans);
175 int mysql_discard_or_import_tablespace(THD *thd,
176  TABLE_LIST *table_list,
177  bool discard);
178 bool mysql_prepare_alter_table(THD *thd, TABLE *table,
179  HA_CREATE_INFO *create_info,
180  Alter_info *alter_info,
181  Alter_table_ctx *alter_ctx);
182 bool mysql_trans_prepare_alter_copy_data(THD *thd);
183 bool mysql_trans_commit_alter_copy_data(THD *thd);
184 bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
185  HA_CREATE_INFO *create_info,
186  TABLE_LIST *table_list,
187  Alter_info *alter_info,
188  uint order_num, ORDER *order, bool ignore);
189 bool mysql_compare_tables(TABLE *table,
190  Alter_info *alter_info,
191  HA_CREATE_INFO *create_info,
192  bool *metadata_equal);
193 bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
194 bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
195  TABLE_LIST *src_table,
196  HA_CREATE_INFO *create_info);
197 bool mysql_rename_table(handlerton *base, const char *old_db,
198  const char * old_name, const char *new_db,
199  const char * new_name, uint flags);
200 
201 bool mysql_backup_table(THD* thd, TABLE_LIST* table_list);
202 bool mysql_restore_table(THD* thd, TABLE_LIST* table_list);
203 
204 bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
205  HA_CHECK_OPT* check_opt);
206 bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
207  my_bool drop_temporary);
208 int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
209  bool drop_temporary, bool drop_view,
210  bool log_query);
211 bool quick_rm_table(THD *thd, handlerton *base, const char *db,
212  const char *table_name, uint flags);
213 void close_cached_table(THD *thd, TABLE *table);
214 bool fill_field_definition(THD *thd,
215  class sp_head *sp,
216  enum enum_field_types field_type,
217  Create_field *field_def);
218 int prepare_create_field(Create_field *sql_field,
219  uint *blob_columns,
220  longlong table_flags);
221 const CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
222  HA_CREATE_INFO *create_info);
223 bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
224 int write_bin_log(THD *thd, bool clear_error,
225  char const *query, ulong query_length,
226  bool is_trans= FALSE);
227 bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry,
228  DDL_LOG_MEMORY_ENTRY **active_entry);
229 bool write_execute_ddl_log_entry(uint first_entry,
230  bool complete,
231  DDL_LOG_MEMORY_ENTRY **active_entry);
232 bool deactivate_ddl_log_entry(uint entry_no);
233 void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry);
234 bool sync_ddl_log();
235 void release_ddl_log();
236 void execute_ddl_log_recovery();
237 bool execute_ddl_log_entry(THD *thd, uint first_entry);
238 bool validate_comment_length(THD *thd, const char *comment_str,
239  size_t *comment_len, uint max_len,
240  uint err_code, const char *comment_name);
241 
242 template<typename T> class List;
243 void promote_first_timestamp_column(List<Create_field> *column_definitions);
244 
245 /*
246  These prototypes where under INNODB_COMPATIBILITY_HOOKS.
247 */
248 uint explain_filename(THD* thd, const char *from, char *to, uint to_length,
249  enum_explain_filename_mode explain_mode);
250 
251 
252 extern MYSQL_PLUGIN_IMPORT const char *primary_key_name;
253 extern mysql_mutex_t LOCK_gdl;
254 
255 #endif /* SQL_TABLE_INCLUDED */