MySQL  8.0.16
Source Code Documentation
sql_base.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2019, 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, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef SQL_BASE_INCLUDED
24 #define SQL_BASE_INCLUDED
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 #include <memory>
29 #include <string>
30 
31 #include "lex_string.h"
32 #include "map_helpers.h"
33 #include "my_base.h" // ha_extra_function
34 #include "my_inttypes.h"
36 #include "prealloced_array.h" // Prealloced_array
37 #include "sql/mdl.h" // MDL_savepoint
38 #include "sql/sql_array.h" // Bounds_checked_array
39 #include "sql/sql_const.h" // enum_resolution_type
40 #include "sql/trigger_def.h" // enum_trigger_event_type
41 #include "thr_lock.h" // thr_lock_type
42 
43 class COPY_INFO;
44 class Field;
45 class Item;
46 class Item_ident;
47 class Open_table_context;
48 class Open_tables_backup;
50 class Query_tables_list;
51 class SELECT_LEX;
53 class THD;
54 class sp_head;
55 struct LEX;
56 struct MY_BITMAP;
58 struct OPEN_TABLE_LIST;
59 struct TABLE;
60 struct TABLE_LIST;
61 struct TABLE_SHARE;
62 struct handlerton;
63 template <class T>
64 class List;
65 template <class T>
67 
69 namespace dd {
70 class Table;
71 } // namespace dd
72 
73 #define TEMP_PREFIX "MY"
74 
75 /* Defines for use with openfrm, openprt and openfrd */
76 
77 #define READ_ALL 1 /* openfrm: Read all parameters */
78 #define EXTRA_RECORD 8 /* Reservera plats f|r extra record */
79 #define DELAYED_OPEN 4096 /* Open table later */
80 /**
81  If set, open_table_from_share() will skip calling get_new_handler() to
82  create a new handler object for the table. Designed to be used when
83  opening a table from inside storage engines.
84 */
85 #define SKIP_NEW_HANDLER 32768
86 
93 };
94 
100 };
101 
102 extern mysql_mutex_t LOCK_open;
103 bool table_def_init(void);
104 void table_def_free(void);
105 void table_def_start_shutdown(void);
106 void assign_new_table_id(TABLE_SHARE *share);
108 size_t get_table_def_key(const TABLE_LIST *table_list, const char **key);
109 TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name,
110  const char *key, size_t key_length, bool open_view,
111  bool open_secondary = false);
112 void release_table_share(TABLE_SHARE *share);
113 
114 TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
115  uint lock_flags);
116 
117 /* mysql_lock_tables() and open_table() flags bits */
118 #define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001
119 #define MYSQL_OPEN_IGNORE_FLUSH 0x0002
120 /* MYSQL_OPEN_TEMPORARY_ONLY (0x0004) is not used anymore. */
121 #define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
122 #define MYSQL_LOCK_LOG_TABLE 0x0010
123 /**
124  Do not try to acquire a metadata lock on the table: we
125  already have one.
126 */
127 #define MYSQL_OPEN_HAS_MDL_LOCK 0x0020
128 /**
129  If in locked tables mode, ignore the locked tables and get
130  a new instance of the table.
131 */
132 #define MYSQL_OPEN_GET_NEW_TABLE 0x0040
133 /* 0x0080 used to be MYSQL_OPEN_SKIP_TEMPORARY */
134 /** Fail instead of waiting when conficting metadata lock is discovered. */
135 #define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0100
136 /** Open tables using MDL_SHARED lock instead of one specified in parser. */
137 #define MYSQL_OPEN_FORCE_SHARED_MDL 0x0200
138 /**
139  Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified
140  in parser.
141 */
142 #define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0400
143 /**
144  When opening or locking the table, use the maximum timeout
145  (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value.
146 */
147 #define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800
148 /**
149  When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to
150  be open do not acquire global, tablespace-scope and schema-scope IX locks.
151 */
152 #define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000
153 /**
154  When opening or locking a replication table through an internal
155  operation rather than explicitly through an user thread.
156 */
157 #define MYSQL_LOCK_RPL_INFO_TABLE 0x2000
158 /**
159  Only check THD::killed if waits happen (e.g. wait on MDL, wait on
160  table flush, wait on thr_lock.c locks) while opening and locking table.
161 */
162 #define MYSQL_OPEN_IGNORE_KILLED 0x4000
163 /**
164  For new TABLE instances constructed do not open table in the storage
165  engine. Existing TABLE instances for which there is a handler object
166  which represents table open in storage engines can still be used.
167 */
168 #define MYSQL_OPEN_NO_NEW_TABLE_IN_SE 0x8000
169 /** Open a shadow copy of a table from a secondary storage engine. */
170 #define MYSQL_OPEN_SECONDARY_ENGINE 0x10000
171 
172 /** Please refer to the internals manual. */
173 #define MYSQL_OPEN_REOPEN \
174  (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | \
175  MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_LOCK_IGNORE_TIMEOUT | \
176  MYSQL_OPEN_IGNORE_KILLED | MYSQL_OPEN_GET_NEW_TABLE | \
177  MYSQL_OPEN_HAS_MDL_LOCK)
178 
179 bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx);
180 
181 TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
182  const char *table_name,
183  bool add_to_temporary_tables_list,
184  bool open_in_engine, const dd::Table &table_def);
185 TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
187  Query_tables_list *prelocking_ctx,
188  TABLE_LIST *table_list,
189  bool routine_modifies_data);
190 
191 bool mysql_rm_tmp_tables(void);
192 bool rm_temporary_table(THD *thd, handlerton *base, const char *path,
193  const dd::Table *table_def);
194 void close_tables_for_reopen(THD *thd, TABLE_LIST **tables,
195  const MDL_savepoint &start_of_statement_svp);
196 TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
197 TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
198 void close_thread_tables(THD *thd);
199 bool fill_record_n_invoke_before_triggers(THD *thd, COPY_INFO *optype_info,
200  List<Item> &fields,
201  List<Item> &values, TABLE *table,
202  enum enum_trigger_event_type event,
203  int num_fields);
205  List<Item> &values, TABLE *table,
206  enum enum_trigger_event_type event,
207  int num_fields);
208 bool resolve_var_assignments(THD *thd, LEX *lex);
209 bool insert_fields(THD *thd, Name_resolution_context *context,
210  const char *db_name, const char *table_name,
211  List_iterator<Item> *it, bool any_privileges);
212 bool setup_fields(THD *thd, Ref_item_array ref_item_array, List<Item> &item,
213  ulong privilege, List<Item> *sum_func_list,
214  bool allow_sum_func, bool column_update);
215 bool fill_record(THD *thd, TABLE *table, List<Item> &fields, List<Item> &values,
216  MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap);
217 bool fill_record(THD *thd, TABLE *table, Field **field, List<Item> &values,
218  MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap);
219 
220 bool check_record(THD *thd, Field **ptr);
221 
222 /**
223  Invoke check constraints defined on the table.
224 
225  @param thd Thread handle.
226  @param table Instance of TABLE.
227 
228  @retval false If all enforced check constraints are satisfied.
229  @retval true Otherwise. THD::is_error() may be "true" in this case.
230 */
231 bool invoke_table_check_constraints(THD *thd, const TABLE *table);
232 
233 Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *first_table,
234  TABLE_LIST *last_table, Item **ref,
236  ulong want_privilege, bool register_tree_change);
237 Field *find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
238  const char *name, size_t length,
239  const char *item_name, const char *db_name,
240  const char *table_name, Item **ref,
241  ulong want_privilege, bool allow_rowid,
242  uint *cached_field_index_ptr,
243  bool register_tree_change,
244  TABLE_LIST **actual_table);
245 Field *find_field_in_table(TABLE *table, const char *name, size_t length,
246  bool allow_rowid, uint *cached_field_index_ptr);
247 Field *find_field_in_table_sef(TABLE *table, const char *name);
250  enum_resolution_type *resolution);
251 bool setup_natural_join_row_types(THD *thd, List<TABLE_LIST> *from_clause,
252  Name_resolution_context *context);
253 bool wait_while_table_is_used(THD *thd, TABLE *table,
254  enum ha_extra_function function);
255 
256 void update_non_unique_table_error(TABLE_LIST *update, const char *operation,
257  TABLE_LIST *duplicate);
258 int setup_ftfuncs(const THD *thd, SELECT_LEX *select);
259 bool init_ftfuncs(THD *thd, SELECT_LEX *select);
260 int run_before_dml_hook(THD *thd);
261 bool get_and_lock_tablespace_names(THD *thd, TABLE_LIST *tables_start,
262  TABLE_LIST *tables_end,
263  ulong lock_wait_timeout, uint flags);
264 bool lock_table_names(
265  THD *thd, TABLE_LIST *table_list, TABLE_LIST *table_list_end,
266  ulong lock_wait_timeout, uint flags,
267  Prealloced_array<MDL_request *, 1> *schema_reqs = nullptr);
268 bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags,
269  Prelocking_strategy *prelocking_strategy);
270 /* open_and_lock_tables */
271 bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, uint flags,
272  Prelocking_strategy *prelocking_strategy);
273 /* simple open_and_lock_tables for single table */
275  thr_lock_type lock_type, uint flags,
276  Prelocking_strategy *prelocking_strategy);
277 bool open_tables_for_query(THD *thd, TABLE_LIST *tables, uint flags);
278 bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags);
279 void free_io_cache(TABLE *entry);
281 void close_thread_table(THD *thd, TABLE **table_ptr);
282 bool close_temporary_tables(THD *thd);
283 TABLE_LIST *unique_table(const TABLE_LIST *table, TABLE_LIST *table_list,
284  bool check_alias);
285 void drop_temporary_table(THD *thd, TABLE_LIST *table_list);
286 void close_temporary_table(THD *thd, TABLE *table, bool free_share,
287  bool delete_table);
288 void close_temporary(THD *thd, TABLE *table, bool free_share,
289  bool delete_table);
290 bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db,
291  const char *table_name);
292 bool open_temporary_tables(THD *thd, TABLE_LIST *tl_list);
293 bool open_temporary_table(THD *thd, TABLE_LIST *tl);
294 bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
295 
296 /* Functions to work with system tables. */
297 bool open_trans_system_tables_for_read(THD *thd, TABLE_LIST *table_list);
298 void close_trans_system_tables(THD *thd);
299 void close_mysql_tables(THD *thd);
300 TABLE *open_log_table(THD *thd, TABLE_LIST *one_table,
303 
304 bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool wait_for_refresh,
305  ulong timeout);
306 
307 /**
308  Close all open instances of the table but keep the MDL lock.
309 
310  Works both under LOCK TABLES and in the normal mode.
311  Removes all closed instances of the table from the table cache.
312 
313  @param thd Thread context.
314  @param share Table share, but is just a handy way to
315  access the table cache key.
316  @param remove_from_locked_tables
317  True if the table is being dropped.
318  In that case the documented behaviour is to
319  implicitly remove the table from LOCK TABLES list.
320  @param skip_table TABLE instance that should be kept open.
321 
322  @pre Must be called with an X MDL lock on the table.
323 */
324 void close_all_tables_for_name(THD *thd, TABLE_SHARE *share,
325  bool remove_from_locked_tables,
326  TABLE *skip_table);
327 
328 /**
329  Close all open instances of the table but keep the MDL lock.
330 
331  Works both under LOCK TABLES and in the normal mode.
332  Removes all closed instances of the table from the table cache.
333 
334  @param thd Thread context.
335  @param db Database name.
336  @param table_name Table name.
337  @param remove_from_locked_tables
338  True if the table is being dropped.
339  In that case the documented behaviour is to
340  implicitly remove the table from LOCK TABLES list.
341 
342  @pre Must be called with an X MDL lock on the table.
343 */
344 void close_all_tables_for_name(THD *thd, const char *db, const char *table_name,
345  bool remove_from_locked_tables);
346 
347 OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
348 void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
349  const char *db, const char *table_name, bool has_lock);
351 TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
352  const char *table_name, bool no_error);
353 void mark_tmp_table_for_reuse(TABLE *table);
354 
355 extern Item **not_found_item;
356 extern Field *not_found_field;
357 extern Field *view_ref_found;
358 
360  void operator()(TABLE_SHARE *share) const;
361 };
362 extern malloc_unordered_map<std::string,
363  std::unique_ptr<TABLE_SHARE, Table_share_deleter>>
365 
367  const char *table_name);
368 
369 /**
370  An abstract class for a strategy specifying how the prelocking
371  algorithm should extend the prelocking set while processing
372  already existing elements in the set.
373 */
374 
376  public:
377  virtual ~Prelocking_strategy() {}
378 
379  virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
380  Sroutine_hash_entry *rt, sp_head *sp,
381  bool *need_prelocking) = 0;
382  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
383  TABLE_LIST *table_list, bool *need_prelocking) = 0;
384  virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
385  TABLE_LIST *table_list, bool *need_prelocking) = 0;
386 };
387 
388 /**
389  A Strategy for prelocking algorithm suitable for DML statements.
390 
391  Ensures that all tables used by all statement's SF/SP/triggers and
392  required for foreign key checks are prelocked and SF/SPs used are
393  cached.
394 */
395 
397  public:
398  virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
399  Sroutine_hash_entry *rt, sp_head *sp,
400  bool *need_prelocking);
401  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
402  TABLE_LIST *table_list, bool *need_prelocking);
403  virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
404  TABLE_LIST *table_list, bool *need_prelocking);
405 };
406 
407 /**
408  A strategy for prelocking algorithm to be used for LOCK TABLES
409  statement.
410 */
411 
413  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
414  TABLE_LIST *table_list, bool *need_prelocking);
415 };
416 
417 /**
418  Strategy for prelocking algorithm to be used for ALTER TABLE statements.
419 
420  Unlike DML or LOCK TABLES strategy, it doesn't
421  prelock triggers, views or stored routines, since they are not
422  used during ALTER.
423 */
424 
426  public:
427  virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
428  Sroutine_hash_entry *rt, sp_head *sp,
429  bool *need_prelocking);
430  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
431  TABLE_LIST *table_list, bool *need_prelocking);
432  virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
433  TABLE_LIST *table_list, bool *need_prelocking);
434 };
435 
436 inline bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter,
437  uint flags) {
438  DML_prelocking_strategy prelocking_strategy;
439 
440  return open_tables(thd, tables, counter, flags, &prelocking_strategy);
441 }
442 
444  thr_lock_type lock_type, uint flags) {
445  DML_prelocking_strategy prelocking_strategy;
446 
447  return open_n_lock_single_table(thd, table_l, lock_type, flags,
448  &prelocking_strategy);
449 }
450 
451 // open_and_lock_tables with default prelocking strategy
452 inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, uint flags) {
453  DML_prelocking_strategy prelocking_strategy;
454 
455  return open_and_lock_tables(thd, tables, flags, &prelocking_strategy);
456 }
457 
458 /**
459  A context of open_tables() function, used to recover
460  from a failed open_table() or open_routine() attempt.
461 */
462 
464  public:
472  };
474 
477  TABLE_LIST *table);
478 
480 
481  /**
482  When doing a back-off, we close all tables acquired by this
483  statement. Return an MDL savepoint taken at the beginning of
484  the statement, so that we can rollback to it before waiting on
485  locks.
486  */
489  }
490 
491  inline ulong get_timeout() const { return m_timeout; }
492 
493  uint get_flags() const { return m_flags; }
494 
495  /**
496  Set flag indicating that we have already acquired metadata lock
497  protecting this statement against GRL while opening tables.
498  */
500 
503  }
504 
505  bool can_back_off() const { return !m_has_locks; }
506 
507  private:
508  /* THD for which tables are opened. */
510  /**
511  For OT_DISCOVER, OT_REPAIR and OT_FIX_ROW_TYPE actions, the table list
512  element for the table which definition should be re-discovered/updated
513  or which should be repaired.
514  */
517  /**
518  Lock timeout in seconds. Initialized to LONG_TIMEOUT when opening system
519  tables or to the "lock_wait_timeout" system variable for regular tables.
520  */
522  /* open_table() flags. */
524  /** Back off action. */
526  /**
527  Whether we had any locks when this context was created.
528  If we did, they are from the previous statement of a transaction,
529  and we can't safely do back-off (and release them).
530  */
532  /**
533  Indicates that in the process of opening tables we have acquired
534  protection against global read lock.
535  */
537 };
538 
539 #endif /* SQL_BASE_INCLUDED */
void assign_new_table_id(TABLE_SHARE *share)
Definition: sql_base.cc:3567
TABLE * open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup)
Open a log table.
Definition: sql_base.cc:9885
void tdc_flush_unused_tables()
Definition: sql_base.cc:9586
This file defines all base public constants related to triggers in MySQL.
void close_thread_tables(THD *thd)
Definition: sql_base.cc:1537
Definition: item.h:3072
Definition: sql_base.h:99
Item ** not_found_item
Definition: sql_base.cc:7801
const char * db_name
Definition: rules_table_service.cc:54
bool can_back_off() const
Definition: sql_base.h:505
Definition: mysql_lex_string.h:34
uint cached_table_definitions(void)
Definition: sql_base.cc:499
Definition: sql_lex.h:3635
const string name("\ame\)
Definition: sql_lex.h:2514
bool fill_record(THD *thd, TABLE *table, List< Item > &fields, List< Item > &values, MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap)
Definition: sql_base.cc:9017
bool request_backoff_action(enum_open_table_action action_arg, TABLE_LIST *table)
Check if we can back-off and set back off action if we can.
Definition: sql_base.cc:4026
Definition: sql_base.h:97
This structure is shared between different table objects.
Definition: table.h:646
uint get_flags() const
Definition: sql_base.h:493
File containing constants that can be used throughout the server.
void close_thread_table(THD *thd, TABLE **table_ptr)
Definition: sql_base.cc:1720
Strategy for prelocking algorithm to be used for ALTER TABLE statements.
Definition: sql_base.h:425
void table_def_free(void)
Definition: sql_base.cc:486
Some integer typedefs for easier portability.
TABLE * open_table_uncached(THD *thd, const char *path, const char *db, const char *table_name, bool add_to_temporary_tables_list, bool open_in_engine, const dd::Table &table_def)
Open a single table without table caching and don&#39;t add it to THD::open_tables.
Definition: sql_base.cc:6808
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables, const MDL_savepoint &start_of_statement_svp)
Prepare statement for reopening of tables and recalculation of set of prelocked tables.
Definition: sql_base.cc:6752
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
Defines how prelocking algorithm for LOCK TABLES statement should handle table list elements...
Definition: sql_base.cc:6056
Field * find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, const char *name, size_t length, const char *item_name, const char *db_name, const char *table_name, Item **ref, ulong want_privilege, bool allow_rowid, uint *cached_field_index_ptr, bool register_tree_change, TABLE_LIST **actual_table)
Definition: sql_base.cc:7397
bool is_equal(const LEX_STRING *a, const LEX_STRING *b)
Definition: sql_base.cc:9742
bool m_has_locks
Whether we had any locks when this context was created.
Definition: sql_base.h:531
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
Defines how prelocking algorithm for DML statements should handle table list elements: ...
Definition: sql_base.cc:5954
void close_all_tables_for_name(THD *thd, TABLE_SHARE *share, bool remove_from_locked_tables, TABLE *skip_table)
Close all open instances of the table but keep the MDL lock.
Definition: sql_base.cc:1458
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:922
Definition: field.h:707
A strategy for prelocking algorithm to be used for LOCK TABLES statement.
Definition: sql_base.h:412
TABLE * open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update, uint lock_flags)
Definition: sql_base.cc:6264
Definition: sql_base.h:471
bool setup_natural_join_row_types(THD *thd, List< TABLE_LIST > *from_clause, Name_resolution_context *context)
Definition: sql_base.cc:8556
bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy)
Open all tables in list.
Definition: sql_base.cc:5551
bool get_and_lock_tablespace_names(THD *thd, TABLE_LIST *tables_start, TABLE_LIST *tables_end, ulong lock_wait_timeout, uint flags)
Acquire IX metadata locks on tablespace names used by LOCK TABLES or by a DDL statement.
Definition: sql_base.cc:5198
bool init_ftfuncs(THD *thd, SELECT_LEX *select)
Definition: sql_base.cc:9728
bool open_temporary_tables(THD *thd, TABLE_LIST *tl_list)
Pre-open temporary tables corresponding to table list elements.
Definition: sql_base.cc:7078
Definition: sql_base.h:90
ulong get_timeout() const
Definition: sql_base.h:491
class udf_list * list
Storage for backup of Open_tables_state.
Definition: sql_class.h:563
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)=0
Definition: sql_base.h:88
const MDL_savepoint & start_of_statement_svp() const
When doing a back-off, we close all tables acquired by this statement.
Definition: sql_base.h:487
Structure that represents element in the set of stored routines used by statement or routine...
Definition: sp.h:225
Definition: sql_base.h:89
bool invoke_table_check_constraints(THD *thd, const TABLE *table)
Invoke check constraints defined on the table.
Definition: sql_base.cc:9147
malloc_unordered_map< std::string, std::unique_ptr< TABLE_SHARE, Table_share_deleter > > * table_def_cache
Definition: sql_base.cc:304
TABLE_SHARE * get_table_share(THD *thd, const char *db, const char *table_name, const char *key, size_t key_length, bool open_view, bool open_secondary=false)
Get the TABLE_SHARE for a table.
Definition: sql_base.cc:647
enum_resolution_type
Definition: sql_const.h:426
static bool report_error(THD *thd, int error_code, Sql_condition::enum_severity_level level, Args... args)
Definition: error_handler.cc:281
TABLE * open_n_lock_single_table(THD *thd, TABLE_LIST *table_l, thr_lock_type lock_type, uint flags, Prelocking_strategy *prelocking_strategy)
Open and lock one table.
Definition: sql_base.cc:6214
bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, uint flags, Prelocking_strategy *prelocking_strategy)
Open all tables in list, locks them and optionally process derived tables.
Definition: sql_base.cc:6357
bool wait_while_table_is_used(THD *thd, TABLE *table, enum ha_extra_function function)
Force all other threads to stop using the table by upgrading metadata lock on it and remove unused TA...
Definition: sql_base.cc:2448
TABLE * find_locked_table(TABLE *list, const char *db, const char *table_name)
Find table in the list of open tables.
Definition: sql_base.cc:3472
Definition: sql_base.h:91
TABLE * find_temporary_table(THD *thd, const char *db, const char *table_name)
Find temporary table specified by database and table names in the THD::temporary_tables list...
Definition: sql_base.cc:2253
void drop_temporary_table(THD *thd, TABLE_LIST *table_list)
Drop a temporary table.
Definition: sql_base.cc:2317
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)=0
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
Defines how prelocking algorithm for DML statements should handle view - all view routines should be ...
Definition: sql_base.cc:6019
static bool backup
Definition: myisampack.cc:194
Definition: table.h:1294
bool check_record(THD *thd, Field **ptr)
Check the NOT NULL constraint on all the fields of the current record.
Definition: sql_base.cc:9106
void mark_tmp_table_for_reuse(TABLE *table)
Reset a single temporary table.
Definition: sql_base.cc:1319
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool wait_for_refresh, ulong timeout)
Definition: sql_base.cc:1137
A Strategy for prelocking algorithm suitable for DML statements.
Definition: sql_base.h:396
Definition: table.h:3605
bool insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, const char *table_name, List_iterator< Item > *it, bool any_privileges)
Definition: sql_base.cc:8825
bool open_trans_system_tables_for_read(THD *thd, TABLE_LIST *table_list)
Open and lock transactional system tables for read.
Definition: sql_base.cc:9776
Definition: sql_base.h:92
void close_mysql_tables(THD *thd)
A helper function to close a mysql.
Definition: sql_base.cc:9867
This file includes constants used by all storage engines.
void intern_close_table(TABLE *entry)
Definition: sql_base.cc:1091
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:66
void release_table_share(TABLE_SHARE *share)
Mark that we are not using table share anymore.
Definition: sql_base.cc:942
Field * not_found_field
Definition: sql_base.cc:6965
bool resolve_var_assignments(THD *thd, LEX *lex)
Resolve variable assignments from LEX object.
Definition: sql_base.cc:8630
void set_has_protection_against_grl()
Set flag indicating that we have already acquired metadata lock protecting this statement against GRL...
Definition: sql_base.h:499
TABLE_LIST * m_failed_table
For OT_DISCOVER, OT_REPAIR and OT_FIX_ROW_TYPE actions, the table list element for the table which de...
Definition: sql_base.h:515
bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
Open a base table.
Definition: sql_base.cc:2772
thr_lock_type
Definition: thr_lock.h:50
Field * find_field_in_table(TABLE *table, const char *name, size_t length, bool allow_rowid, uint *cached_field_index_ptr)
Definition: sql_base.cc:7307
void close_trans_system_tables(THD *thd)
Close transactional system tables, opened with open_trans_system_tables_for_read().
Definition: sql_base.cc:9842
Savepoint for MDL context.
Definition: mdl.h:1294
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys...
Definition: map_helpers.h:175
enum enum_open_table_action m_action
Back off action.
Definition: sql_base.h:525
int setup_ftfuncs(const THD *thd, SELECT_LEX *select)
Definition: sql_base.cc:9704
TABLE_LIST * find_table_in_global_list(TABLE_LIST *table, const char *db_name, const char *table_name)
Find table in global list.
Definition: sql_base.cc:2052
TABLE * find_table_for_mdl_upgrade(THD *thd, const char *db, const char *table_name, bool no_error)
Find instance of TABLE with upgradable or exclusive metadata lock from the list of open tables...
Definition: sql_base.cc:3505
Definition: aggregate_check.h:523
Definition: my_bitmap.h:42
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking)=0
bool rm_temporary_table(THD *thd, handlerton *base, const char *path, const dd::Table *table_def)
Delete a temporary table.
Definition: sql_base.cc:6933
bool m_has_protection_against_grl
Indicates that in the process of opening tables we have acquired protection against global read lock...
Definition: sql_base.h:536
bool lock_table_names(THD *thd, TABLE_LIST *table_list, TABLE_LIST *table_list_end, ulong lock_wait_timeout, uint flags, Prealloced_array< MDL_request *, 1 > *schema_reqs=nullptr)
Acquire "strong" (SRO, SNW, SNRW) metadata locks on tables used by LOCK TABLES or by a DDL statement...
Definition: sql_base.cc:5312
Definition: sql_base.h:470
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
Defines how prelocking algorithm for ALTER TABLE statement should handle table list elements...
Definition: sql_base.cc:6091
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool *need_prelocking)
Defines how prelocking algorithm for ALTER TABLE statement should handle view - do nothing...
Definition: sql_base.cc:6103
static char * path
Definition: mysqldump.cc:122
bool fill_record_n_invoke_before_triggers(THD *thd, COPY_INFO *optype_info, List< Item > &fields, List< Item > &values, TABLE *table, enum enum_trigger_event_type event, int num_fields)
Definition: sql_base.cc:9270
Definition: item.h:666
unsigned int uint
Definition: uca-dump.cc:29
bool setup_fields(THD *thd, Ref_item_array ref_item_array, List< Item > &item, ulong privilege, List< Item > *sum_func_list, bool allow_sum_func, bool column_update)
Resolve a list of expressions and setup appropriate data.
Definition: sql_base.cc:8669
A context of open_tables() function, used to recover from a failed open_table() or open_routine() att...
Definition: sql_base.h:463
uint m_flags
Definition: sql_base.h:523
void table_def_start_shutdown(void)
Notify table definition cache that process of shutting down server has started so it has to keep numb...
Definition: sql_base.cc:470
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2219
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking)
Defines how prelocking algorithm for DML statements should handle routines:
Definition: sql_base.cc:5905
void close_log_table(THD *thd, Open_tables_backup *backup)
Close a log table.
Definition: sql_base.cc:9918
static uint update
Definition: myisamlog.cc:88
Definition: sql_base.h:359
Definition: sql_base.h:466
sp_head represents one instance of a stored program.
Definition: sp_head.h:405
bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags)
Lock all tables in a list.
Definition: sql_base.cc:6587
bool can_recover_from_failed_open() const
Definition: sql_base.h:479
OPEN_TABLE_LIST * list_open_tables(THD *thd, const char *db, const char *wild)
Definition: sql_base.cc:1017
static const char * key
Definition: suite_stubs.c:14
MDL_savepoint m_start_of_statement_svp
Definition: sql_base.h:516
Open_table_context(THD *thd, uint flags)
Open_table_context.
Definition: sql_base.cc:4006
thr_lock_type read_lock_type_for_table(THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list, bool routine_modifies_data)
Definition: sql_base.cc:4300
Field * find_field_in_table_sef(TABLE *table, const char *name)
Definition: sql_base.cc:7537
bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db, const char *table_name)
Definition: sql_base.cc:2414
Definition: sql_base.h:96
enum_tdc_remove_table_type
Definition: sql_base.h:95
Definition: item.h:390
void free_io_cache(TABLE *entry)
Definition: sql_base.cc:1108
bool recover_from_failed_open()
Recover from failed attempt of open table by performing requested action.
Definition: sql_base.cc:4140
This class encapsulates a data change operation.
Definition: sql_data_change.h:71
uint counter
Definition: mysqlimport.cc:52
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
An abstract class for a strategy specifying how the prelocking algorithm should extend the prelocking...
Definition: sql_base.h:375
size_t get_table_def_key(const TABLE_LIST *table_list, const char **key)
Get table cache key for a table list element.
Definition: sql_base.cc:412
Field * view_ref_found
Definition: sql_base.cc:6966
bool has_protection_against_grl() const
Definition: sql_base.h:501
bool table_def_init(void)
Definition: sql_base.cc:445
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking)
Defines how prelocking algorithm for ALTER TABLE statement should handle routines - do nothing as thi...
Definition: sql_base.cc:6078
int run_before_dml_hook(THD *thd)
Run the server hook called "before_dml".
Definition: sql_base.cc:5152
void update_non_unique_table_error(TABLE_LIST *update, const char *operation, TABLE_LIST *duplicate)
Issue correct error message in case we found 2 duplicate tables which prevent some update operation...
Definition: sql_base.cc:2208
ABI for instrumented mutexes.
void operator()(TABLE_SHARE *share) const
Definition: sql_base.cc:433
static void free_share(st_blackhole_share *share)
Definition: ha_blackhole.cc:282
bool mysql_rm_tmp_tables(void)
Drop all temporary tables which have been left from previous server run.
Definition: sql_base.cc:9506
bool close_temporary_tables(THD *thd)
Definition: sql_base.cc:1773
void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, const char *db, const char *table_name, bool has_lock)
Remove all or some (depending on parameter) instances of TABLE and TABLE_SHARE from the table definit...
Definition: sql_base.cc:9631
Item ** find_item_in_list(THD *thd, Item *item, List< Item > &items, uint *counter, find_item_error_report_type report_error, enum_resolution_type *resolution)
Definition: sql_base.cc:7803
Definition: test_sql_stmt.cc:148
virtual ~Prelocking_strategy()
Definition: sql_base.h:377
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
Bounds_checked_array< Item * > Ref_item_array
Definition: sql_base.h:66
A table definition from the master.
Definition: rpl_utility.h:245
Definition: sql_base.h:468
Definition: item.h:78
Definition: sql_base.h:98
THD * m_thd
Definition: sql_base.h:509
Definition: table.h:2439
static int flags[50]
Definition: hp_test1.cc:39
enum_trigger_event_type
Constants to enumerate possible event types on which triggers can be fired.
Definition: trigger_def.h:41
mysql_mutex_t LOCK_open
LOCK_open protects the following variables/objects:
Definition: sql_base.cc:243
Field * find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *first_table, TABLE_LIST *last_table, Item **ref, find_item_error_report_type report_error, ulong want_privilege, bool register_tree_change)
Definition: sql_base.cc:7595
bool open_tables_for_query(THD *thd, TABLE_LIST *tables, uint flags)
Open all tables for a query or statement, in list started by "tables".
Definition: sql_base.cc:6505
find_item_error_report_type
Definition: sql_base.h:87
void close_temporary(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2383
bool open_temporary_table(THD *thd, TABLE_LIST *tl)
Find a temporary table specified by TABLE_LIST instance in the cache and prepare its TABLE instance f...
Definition: sql_base.cc:6995
Definition: table.h:43
Definition: sql_base.h:469
unsigned long ulong
Definition: my_inttypes.h:46
Definition: completion_hash.h:34
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
ulong m_timeout
Lock timeout in seconds.
Definition: sql_base.h:521
static uint key_length
Definition: mi_test1.cc:42
void close_temporary_table(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2343
Definition: items.h:34
enum_open_table_action
Definition: sql_base.h:465
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776
ha_extra_function
Definition: my_base.h:183
const char * table_name
Definition: rules_table_service.cc:55
TABLE_LIST * unique_table(const TABLE_LIST *table, TABLE_LIST *table_list, bool check_alias)
Test that the subject table of INSERT/UPDATE/DELETE/CREATE or (in case of MyISAMMRG) one of its child...
Definition: sql_base.cc:2179