16 #ifndef SQL_BASE_INCLUDED
17 #define SQL_BASE_INCLUDED
20 #include "sql_trigger.h"
21 #include "sql_class.h"
27 class Open_tables_state;
34 typedef class st_select_lex SELECT_LEX;
50 enum enum_resolution_type {
52 RESOLVED_IGNORING_ALIAS,
53 RESOLVED_BEHIND_ALIAS,
54 RESOLVED_WITH_NO_ALIAS,
55 RESOLVED_AGAINST_ALIAS
58 enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
59 IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
60 IGNORE_EXCEPT_NON_UNIQUE};
62 enum enum_tdc_remove_table_type {TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN,
64 TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE};
67 #define RTFC_NO_FLAG 0x0000
68 #define RTFC_OWNED_BY_THD_FLAG 0x0001
69 #define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
70 #define RTFC_CHECK_KILLED_FLAG 0x0004
72 bool check_dup(
const char *db,
const char *
name,
TABLE_LIST *tables);
74 bool table_cache_init(
void);
75 void table_cache_free(
void);
76 bool table_def_init(
void);
77 void table_def_free(
void);
80 uint cached_table_definitions(
void);
83 const char *key, uint key_length,
84 uint db_flags,
int *error,
85 my_hash_value_type hash_value);
89 TABLE *open_ltable(THD *thd,
TABLE_LIST *table_list, thr_lock_type update,
93 #define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001
94 #define MYSQL_OPEN_IGNORE_FLUSH 0x0002
96 #define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
97 #define MYSQL_LOCK_LOG_TABLE 0x0010
102 #define MYSQL_OPEN_HAS_MDL_LOCK 0x0020
107 #define MYSQL_OPEN_GET_NEW_TABLE 0x0040
110 #define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0100
112 #define MYSQL_OPEN_FORCE_SHARED_MDL 0x0200
117 #define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0400
122 #define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800
127 #define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000
132 #define MYSQL_LOCK_RPL_INFO_TABLE 0x2000
137 #define MYSQL_OPEN_IGNORE_KILLED 0x4000
140 #define MYSQL_OPEN_REOPEN (MYSQL_OPEN_IGNORE_FLUSH |\
141 MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK |\
142 MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |\
143 MYSQL_LOCK_IGNORE_TIMEOUT |\
144 MYSQL_OPEN_IGNORE_KILLED |\
145 MYSQL_OPEN_GET_NEW_TABLE |\
146 MYSQL_OPEN_HAS_MDL_LOCK)
154 bool add_to_temporary_tables_list,
155 bool open_in_engine);
157 thr_lock_type read_lock_type_for_table(THD *thd,
158 Query_tables_list *prelocking_ctx,
160 bool routine_modifies_data);
162 my_bool mysql_rm_tmp_tables(
void);
173 uint table_key_length);
174 void close_thread_tables(THD *thd);
175 bool fill_record_n_invoke_before_triggers(THD *thd,
List<Item> &fields,
179 enum trg_event_type
event);
180 bool fill_record_n_invoke_before_triggers(THD *thd,
Field **field,
184 enum trg_event_type
event);
191 List<Item> &item, enum_mark_columns mark_used_columns,
192 List<Item> *sum_func_list,
bool allow_sum_func);
199 find_field_in_tables(THD *thd,
Item_ident *item,
201 Item **ref, find_item_error_report_type report_error,
202 bool check_privileges,
bool register_tree_change);
204 find_field_in_table_ref(THD *thd,
TABLE_LIST *table_list,
205 const char *
name, uint length,
206 const char *item_name,
const char *db_name,
208 bool check_privileges,
bool allow_rowid,
209 uint *cached_field_index_ptr,
210 bool register_tree_change,
TABLE_LIST **actual_table);
212 find_field_in_table(THD *thd,
TABLE *
table,
const char *
name, uint length,
213 bool allow_rowid, uint *cached_field_index_ptr);
217 find_item_error_report_type report_error,
218 enum_resolution_type *resolution);
228 ulong want_access_first,
231 enum ha_extra_function
function);
235 void update_non_unique_table_error(
TABLE_LIST *update,
236 const char *operation,
240 int setup_ftfuncs(SELECT_LEX* select);
241 int init_ftfuncs(THD *thd, SELECT_LEX* select,
bool no_order);
243 TABLE_LIST *table_list_end, ulong lock_wait_timeout,
249 bool derived, uint
flags,
253 thr_lock_type lock_type, uint
flags,
259 void close_thread_table(THD *thd,
TABLE **table_ptr);
260 bool close_temporary_tables(THD *thd);
264 void close_temporary_table(THD *thd,
TABLE *
table,
bool free_share,
266 void close_temporary(
TABLE *
table,
bool free_share,
bool delete_table);
267 bool rename_temporary_table(THD* thd,
TABLE *
table,
const char *new_db,
274 bool open_system_tables_for_read(THD *thd,
TABLE_LIST *table_list,
275 Open_tables_backup *backup);
276 void close_system_tables(THD *thd, Open_tables_backup *backup);
283 Open_tables_state *backup);
284 void close_performance_schema_table(THD *thd, Open_tables_state *backup);
286 bool close_cached_tables(THD *thd,
TABLE_LIST *tables,
287 bool wait_for_refresh, ulong timeout);
290 bool remove_from_locked_tables,
292 OPEN_TABLE_LIST *list_open_tables(THD *thd,
const char *db,
const char *wild);
297 const char *cache_key, uint cache_key_length, uint
flags);
298 void tdc_flush_unused_tables();
305 extern Item **not_found_item;
306 extern Field *not_found_field;
307 extern Field *view_ref_found;
308 extern HASH table_def_cache;
321 table->used_fields= 0;
322 table->const_table= 0;
324 table->status= STATUS_GARBAGE | STATUS_NOT_FOUND;
325 table->maybe_null= table_list->outer_join;
327 while (!table->maybe_null && embedding)
329 table->maybe_null= embedding->outer_join;
330 embedding= embedding->embedding;
332 table->tablenr= tablenr;
333 table->map= (table_map) 1 << tablenr;
334 table->force_index= table_list->force_index;
336 table->covering_keys= table->s->keys_for_keyread;
337 table->merge_keys.clear_all();
344 return find_table_in_list(table, &TABLE_LIST::next_global,
345 db_name, table_name);
352 return find_table_in_list(table, &TABLE_LIST::next_local,
353 db_name, table_name);
357 inline bool setup_fields_with_no_wrap(THD *thd,
Ref_ptr_array ref_pointer_array,
359 enum_mark_columns mark_used_columns,
364 thd->lex->select_lex.no_wrap_view_item= TRUE;
365 res= setup_fields(thd, ref_pointer_array, item, mark_used_columns,
366 sum_func_list, allow_sum_func);
367 thd->lex->select_lex.no_wrap_view_item= FALSE;
382 virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
384 bool *need_prelocking) = 0;
385 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
386 TABLE_LIST *table_list,
bool *need_prelocking) = 0;
387 virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
388 TABLE_LIST *table_list,
bool *need_prelocking)= 0;
403 virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
405 bool *need_prelocking);
406 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
407 TABLE_LIST *table_list,
bool *need_prelocking);
408 virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
409 TABLE_LIST *table_list,
bool *need_prelocking);
420 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
421 TABLE_LIST *table_list,
bool *need_prelocking);
436 virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
438 bool *need_prelocking);
439 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
440 TABLE_LIST *table_list,
bool *need_prelocking);
441 virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
442 TABLE_LIST *table_list,
bool *need_prelocking);
451 return open_tables(thd, tables, counter, flags, &prelocking_strategy);
456 thr_lock_type lock_type, uint
flags)
461 &prelocking_strategy);
467 bool derived, uint
flags)
472 &prelocking_strategy);
484 enum enum_open_table_action
487 OT_BACKOFF_AND_RETRY,
498 bool can_recover_from_failed_open()
const
499 {
return m_action != OT_NO_ACTION; }
509 return m_start_of_statement_svp;
512 inline ulong get_timeout()
const
517 uint get_flags()
const {
return m_flags; }
525 m_has_protection_against_grl= TRUE;
528 bool has_protection_against_grl()
const
530 return m_has_protection_against_grl;
551 enum enum_open_table_action m_action;
562 bool m_has_protection_against_grl;
570 inline bool is_temporary_table(
TABLE_LIST *tl)
572 if (tl->view || tl->schema_table)
586 return tl->table->s->tmp_table != NO_TMP_TABLE;
598 : m_handled_errors(0), m_unhandled_errors(0)
601 bool handle_condition(THD *thd,
603 const char* sqlstate,
604 Sql_condition::enum_warning_level
level,
615 int m_handled_errors;
616 int m_unhandled_errors;