MySQL  8.0.17
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 
295 /* Functions to work with system tables. */
296 bool open_trans_system_tables_for_read(THD *thd, TABLE_LIST *table_list);
297 void close_trans_system_tables(THD *thd);
298 void close_mysql_tables(THD *thd);
299 TABLE *open_log_table(THD *thd, TABLE_LIST *one_table,
302 
303 bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool wait_for_refresh,
304  ulong timeout);
305 
306 /**
307  Close all open instances of the table but keep the MDL lock.
308 
309  Works both under LOCK TABLES and in the normal mode.
310  Removes all closed instances of the table from the table cache.
311 
312  @param thd Thread context.
313  @param share Table share, but is just a handy way to
314  access the table cache key.
315  @param remove_from_locked_tables
316  True if the table is being dropped.
317  In that case the documented behaviour is to
318  implicitly remove the table from LOCK TABLES list.
319  @param skip_table TABLE instance that should be kept open.
320 
321  @pre Must be called with an X MDL lock on the table.
322 */
323 void close_all_tables_for_name(THD *thd, TABLE_SHARE *share,
324  bool remove_from_locked_tables,
325  TABLE *skip_table);
326 
327 /**
328  Close all open instances of the table but keep the MDL lock.
329 
330  Works both under LOCK TABLES and in the normal mode.
331  Removes all closed instances of the table from the table cache.
332 
333  @param thd Thread context.
334  @param db Database name.
335  @param table_name Table name.
336  @param remove_from_locked_tables
337  True if the table is being dropped.
338  In that case the documented behaviour is to
339  implicitly remove the table from LOCK TABLES list.
340 
341  @pre Must be called with an X MDL lock on the table.
342 */
343 void close_all_tables_for_name(THD *thd, const char *db, const char *table_name,
344  bool remove_from_locked_tables);
345 
346 OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
347 void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
348  const char *db, const char *table_name, bool has_lock);
350 TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
351  const char *table_name, bool no_error);
352 void mark_tmp_table_for_reuse(TABLE *table);
353 
354 extern Item **not_found_item;
355 extern Field *not_found_field;
356 extern Field *view_ref_found;
357 
359  void operator()(TABLE_SHARE *share) const;
360 };
361 extern malloc_unordered_map<std::string,
362  std::unique_ptr<TABLE_SHARE, Table_share_deleter>>
364 
366  const char *table_name);
367 
368 /**
369  An abstract class for a strategy specifying how the prelocking
370  algorithm should extend the prelocking set while processing
371  already existing elements in the set.
372 */
373 
375  public:
376  virtual ~Prelocking_strategy() {}
377 
378  virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
379  Sroutine_hash_entry *rt, sp_head *sp,
380  bool *need_prelocking) = 0;
381  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
382  TABLE_LIST *table_list, bool *need_prelocking) = 0;
383  virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
384  TABLE_LIST *table_list, bool *need_prelocking) = 0;
385 };
386 
387 /**
388  A Strategy for prelocking algorithm suitable for DML statements.
389 
390  Ensures that all tables used by all statement's SF/SP/triggers and
391  required for foreign key checks are prelocked and SF/SPs used are
392  cached.
393 */
394 
396  public:
397  virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
398  Sroutine_hash_entry *rt, sp_head *sp,
399  bool *need_prelocking);
400  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
401  TABLE_LIST *table_list, bool *need_prelocking);
402  virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
403  TABLE_LIST *table_list, bool *need_prelocking);
404 };
405 
406 /**
407  A strategy for prelocking algorithm to be used for LOCK TABLES
408  statement.
409 */
410 
412  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
413  TABLE_LIST *table_list, bool *need_prelocking);
414 };
415 
416 /**
417  Strategy for prelocking algorithm to be used for ALTER TABLE statements.
418 
419  Unlike DML or LOCK TABLES strategy, it doesn't
420  prelock triggers, views or stored routines, since they are not
421  used during ALTER.
422 */
423 
425  public:
426  virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
427  Sroutine_hash_entry *rt, sp_head *sp,
428  bool *need_prelocking);
429  virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
430  TABLE_LIST *table_list, bool *need_prelocking);
431  virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
432  TABLE_LIST *table_list, bool *need_prelocking);
433 };
434 
435 inline bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter,
436  uint flags) {
437  DML_prelocking_strategy prelocking_strategy;
438 
439  return open_tables(thd, tables, counter, flags, &prelocking_strategy);
440 }
441 
443  thr_lock_type lock_type, uint flags) {
444  DML_prelocking_strategy prelocking_strategy;
445 
446  return open_n_lock_single_table(thd, table_l, lock_type, flags,
447  &prelocking_strategy);
448 }
449 
450 // open_and_lock_tables with default prelocking strategy
451 inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, uint flags) {
452  DML_prelocking_strategy prelocking_strategy;
453 
454  return open_and_lock_tables(thd, tables, flags, &prelocking_strategy);
455 }
456 
457 /**
458  A context of open_tables() function, used to recover
459  from a failed open_table() or open_routine() attempt.
460 */
461 
463  public:
471  };
473 
476  TABLE_LIST *table);
477 
479 
480  /**
481  When doing a back-off, we close all tables acquired by this
482  statement. Return an MDL savepoint taken at the beginning of
483  the statement, so that we can rollback to it before waiting on
484  locks.
485  */
488  }
489 
490  inline ulong get_timeout() const { return m_timeout; }
491 
492  uint get_flags() const { return m_flags; }
493 
494  /**
495  Set flag indicating that we have already acquired metadata lock
496  protecting this statement against GRL while opening tables.
497  */
499 
502  }
503 
504  bool can_back_off() const { return !m_has_locks; }
505 
506  private:
507  /* THD for which tables are opened. */
509  /**
510  For OT_DISCOVER, OT_REPAIR and OT_FIX_ROW_TYPE actions, the table list
511  element for the table which definition should be re-discovered/updated
512  or which should be repaired.
513  */
516  /**
517  Lock timeout in seconds. Initialized to LONG_TIMEOUT when opening system
518  tables or to the "lock_wait_timeout" system variable for regular tables.
519  */
521  /* open_table() flags. */
523  /** Back off action. */
525  /**
526  Whether we had any locks when this context was created.
527  If we did, they are from the previous statement of a transaction,
528  and we can't safely do back-off (and release them).
529  */
531  /**
532  Indicates that in the process of opening tables we have acquired
533  protection against global read lock.
534  */
536 };
537 
538 #endif /* SQL_BASE_INCLUDED */
void assign_new_table_id(TABLE_SHARE *share)
Definition: sql_base.cc:3568
TABLE * open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup)
Open a log table.
Definition: sql_base.cc:9891
void tdc_flush_unused_tables()
Definition: sql_base.cc:9596
This file defines all base public constants related to triggers in MySQL.
void close_thread_tables(THD *thd)
Definition: sql_base.cc:1538
Definition: item.h:3134
Definition: sql_base.h:99
Item ** not_found_item
Definition: sql_base.cc:7817
const char * db_name
Definition: rules_table_service.cc:54
bool can_back_off() const
Definition: sql_base.h:504
uint cached_table_definitions(void)
Definition: sql_base.cc:499
Definition: sql_lex.h:3063
const string name("\ame\)
Definition: sql_lex.h:1933
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:9033
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:4029
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:492
File containing constants that can be used throughout the server.
void close_thread_table(THD *thd, TABLE **table_ptr)
Definition: sql_base.cc:1721
Strategy for prelocking algorithm to be used for ALTER TABLE statements.
Definition: sql_base.h:424
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:6824
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:6768
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:6046
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:7413
bool m_has_locks
Whether we had any locks when this context was created.
Definition: sql_base.h:530
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:5944
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:1459
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:847
Definition: field.h:709
A strategy for prelocking algorithm to be used for LOCK TABLES statement.
Definition: sql_base.h:411
TABLE * open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update, uint lock_flags)
Definition: sql_base.cc:6254
Definition: sql_base.h:470
bool setup_natural_join_row_types(THD *thd, List< TABLE_LIST > *from_clause, Name_resolution_context *context)
Definition: sql_base.cc:8572
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:5554
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:5201
bool init_ftfuncs(THD *thd, SELECT_LEX *select)
Definition: sql_base.cc:9738
bool open_temporary_tables(THD *thd, TABLE_LIST *tl_list)
Pre-open temporary tables corresponding to table list elements.
Definition: sql_base.cc:7094
Definition: sql_base.h:90
ulong get_timeout() const
Definition: sql_base.h:490
class udf_list * list
Storage for backup of Open_tables_state.
Definition: sql_class.h:564
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:486
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:9163
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:425
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:6204
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:6347
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:2449
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:3473
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:2254
void drop_temporary_table(THD *thd, TABLE_LIST *table_list)
Drop a temporary table.
Definition: sql_base.cc:2318
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:6009
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:9122
void mark_tmp_table_for_reuse(TABLE *table)
Reset a single temporary table.
Definition: sql_base.cc:1320
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool wait_for_refresh, ulong timeout)
Definition: sql_base.cc:1138
A Strategy for prelocking algorithm suitable for DML statements.
Definition: sql_base.h:395
Definition: table.h:3634
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:8841
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:9782
Definition: sql_base.h:92
void close_mysql_tables(THD *thd)
A helper function to close a mysql.
Definition: sql_base.cc:9873
This file includes constants used by all storage engines.
void intern_close_table(TABLE *entry)
Definition: sql_base.cc:1092
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:6981
bool resolve_var_assignments(THD *thd, LEX *lex)
Resolve variable assignments from LEX object.
Definition: sql_base.cc:8646
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:498
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:514
bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
Open a base table.
Definition: sql_base.cc:2773
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:7323
void close_trans_system_tables(THD *thd)
Close transactional system tables, opened with open_trans_system_tables_for_read().
Definition: sql_base.cc:9848
Savepoint for MDL context.
Definition: mdl.h:1295
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:524
int setup_ftfuncs(const THD *thd, SELECT_LEX *select)
Definition: sql_base.cc:9714
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:2053
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:3506
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:6949
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:535
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:5315
Definition: sql_base.h:469
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:6081
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:6093
static char * path
Definition: mysqldump.cc:123
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:9280
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:8685
A context of open_tables() function, used to recover from a failed open_table() or open_routine() att...
Definition: sql_base.h:462
uint m_flags
Definition: sql_base.h:522
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:2275
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:5895
void close_log_table(THD *thd, Open_tables_backup *backup)
Close a log table.
Definition: sql_base.cc:9924
static uint update
Definition: myisamlog.cc:88
Definition: sql_base.h:358
Definition: sql_base.h:465
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:6577
bool can_recover_from_failed_open() const
Definition: sql_base.h:478
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:515
Open_table_context(THD *thd, uint flags)
Open_table_context.
Definition: sql_base.cc:4009
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:4303
Field * find_field_in_table_sef(TABLE *table, const char *name)
Definition: sql_base.cc:7553
bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db, const char *table_name)
Definition: sql_base.cc:2415
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:1109
bool recover_from_failed_open()
Recover from failed attempt of open table by performing requested action.
Definition: sql_base.cc:4143
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:374
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:6982
bool has_protection_against_grl() const
Definition: sql_base.h:500
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:6068
int run_before_dml_hook(THD *thd)
Run the server hook called "before_dml".
Definition: sql_base.cc:5155
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:2209
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:9516
bool close_temporary_tables(THD *thd)
Definition: sql_base.cc:1774
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:9641
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:7819
Definition: test_sql_stmt.cc:150
virtual ~Prelocking_strategy()
Definition: sql_base.h:376
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:467
Definition: item.h:78
Definition: sql_base.h:98
THD * m_thd
Definition: sql_base.h:508
Definition: table.h:2442
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:7611
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:6495
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:2384
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:7011
Definition: table.h:43
Definition: sql_base.h:468
unsigned long ulong
Definition: my_inttypes.h:48
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:520
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:2344
Definition: items.h:34
enum_open_table_action
Definition: sql_base.h:464
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777
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:2180