MySQL  8.0.18
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);
200  THD *thd, COPY_INFO *optype_info, List<Item> &fields, List<Item> &values,
201  TABLE *table, enum enum_trigger_event_type event, int num_fields,
202  bool raise_autoinc_has_expl_non_null_val, bool *is_row_changed);
204  List<Item> &values, TABLE *table,
205  enum enum_trigger_event_type event,
206  int num_fields);
207 bool resolve_var_assignments(THD *thd, LEX *lex);
208 bool insert_fields(THD *thd, Name_resolution_context *context,
209  const char *db_name, const char *table_name,
210  List_iterator<Item> *it, bool any_privileges);
211 bool setup_fields(THD *thd, Ref_item_array ref_item_array, List<Item> &item,
212  ulong privilege, List<Item> *sum_func_list,
213  bool allow_sum_func, bool column_update);
214 bool fill_record(THD *thd, TABLE *table, List<Item> &fields, List<Item> &values,
215  MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap,
216  bool raise_autoinc_has_expl_non_null_val);
217 bool fill_record(THD *thd, TABLE *table, Field **field, List<Item> &values,
218  MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap,
219  bool raise_autoinc_has_expl_non_null_val);
220 
221 bool check_record(THD *thd, Field **ptr);
222 
223 /**
224  Invoke check constraints defined on the table.
225 
226  @param thd Thread handle.
227  @param table Instance of TABLE.
228 
229  @retval false If all enforced check constraints are satisfied.
230  @retval true Otherwise. THD::is_error() may be "true" in this case.
231 */
232 bool invoke_table_check_constraints(THD *thd, const TABLE *table);
233 
234 Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *first_table,
235  TABLE_LIST *last_table, Item **ref,
237  ulong want_privilege, bool register_tree_change);
238 Field *find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
239  const char *name, size_t length,
240  const char *item_name, const char *db_name,
241  const char *table_name, Item **ref,
242  ulong want_privilege, bool allow_rowid,
243  uint *cached_field_index_ptr,
244  bool register_tree_change,
245  TABLE_LIST **actual_table);
246 Field *find_field_in_table(TABLE *table, const char *name, size_t length,
247  bool allow_rowid, uint *cached_field_index_ptr);
248 Field *find_field_in_table_sef(TABLE *table, const char *name);
251  enum_resolution_type *resolution);
252 bool setup_natural_join_row_types(THD *thd, List<TABLE_LIST> *from_clause,
253  Name_resolution_context *context);
254 bool wait_while_table_is_used(THD *thd, TABLE *table,
255  enum ha_extra_function function);
256 
257 void update_non_unique_table_error(TABLE_LIST *update, const char *operation,
258  TABLE_LIST *duplicate);
259 int setup_ftfuncs(const THD *thd, SELECT_LEX *select);
260 bool init_ftfuncs(THD *thd, SELECT_LEX *select);
261 int run_before_dml_hook(THD *thd);
262 bool get_and_lock_tablespace_names(THD *thd, TABLE_LIST *tables_start,
263  TABLE_LIST *tables_end,
264  ulong lock_wait_timeout, uint flags);
265 bool lock_table_names(
266  THD *thd, TABLE_LIST *table_list, TABLE_LIST *table_list_end,
267  ulong lock_wait_timeout, uint flags,
268  Prealloced_array<MDL_request *, 1> *schema_reqs = nullptr);
269 bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags,
270  Prelocking_strategy *prelocking_strategy);
271 /* open_and_lock_tables */
272 bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, uint flags,
273  Prelocking_strategy *prelocking_strategy);
274 /* simple open_and_lock_tables for single table */
276  thr_lock_type lock_type, uint flags,
277  Prelocking_strategy *prelocking_strategy);
278 bool open_tables_for_query(THD *thd, TABLE_LIST *tables, uint flags);
279 bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags);
280 void free_io_cache(TABLE *entry);
282 void close_thread_table(THD *thd, TABLE **table_ptr);
283 bool close_temporary_tables(THD *thd);
284 TABLE_LIST *unique_table(const TABLE_LIST *table, TABLE_LIST *table_list,
285  bool check_alias);
286 void drop_temporary_table(THD *thd, TABLE_LIST *table_list);
287 void close_temporary_table(THD *thd, TABLE *table, bool free_share,
288  bool delete_table);
289 void close_temporary(THD *thd, TABLE *table, bool free_share,
290  bool delete_table);
291 bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db,
292  const char *table_name);
293 bool open_temporary_tables(THD *thd, TABLE_LIST *tl_list);
294 bool open_temporary_table(THD *thd, TABLE_LIST *tl);
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:3553
TABLE * open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup)
Open a log table.
Definition: sql_base.cc:9969
void tdc_flush_unused_tables()
Definition: sql_base.cc:9674
This file defines all base public constants related to triggers in MySQL.
void close_thread_tables(THD *thd)
Definition: sql_base.cc:1532
Definition: item.h:3126
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
uint cached_table_definitions(void)
Definition: sql_base.cc:497
Definition: sql_lex.h:3192
const string name("\ame\)
Definition: sql_lex.h:2062
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:4012
Definition: sql_base.h:97
This structure is shared between different table objects.
Definition: table.h:653
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:1713
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:485
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:6030
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 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:5928
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:1453
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:971
Definition: field.h:700
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:6238
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:8555
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:5538
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:5185
bool init_ftfuncs(THD *thd, SELECT_LEX *select)
Definition: sql_base.cc:9816
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:565
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:9179
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:645
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:6188
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:6331
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:2435
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:3458
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:2244
void drop_temporary_table(THD *thd, TABLE_LIST *table_list)
Drop a temporary table.
Definition: sql_base.cc:2308
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:5993
static bool backup
Definition: myisampack.cc:194
Definition: table.h:1301
bool check_record(THD *thd, Field **ptr)
Check the NOT NULL constraint on all the fields of the current record.
Definition: sql_base.cc:9138
void mark_tmp_table_for_reuse(TABLE *table)
Reset a single temporary table.
Definition: sql_base.cc:1314
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool wait_for_refresh, ulong timeout)
Definition: sql_base.cc:1132
A Strategy for prelocking algorithm suitable for DML statements.
Definition: sql_base.h:396
Definition: table.h:3647
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:8824
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:9860
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, bool raise_autoinc_has_expl_non_null_val, bool *is_row_changed)
Fill fields in list with values from the list of items and invoke before triggers.
Definition: sql_base.cc:9312
Definition: sql_base.h:92
void close_mysql_tables(THD *thd)
A helper function to close a mysql.
Definition: sql_base.cc:9951
This file includes constants used by all storage engines.
void intern_close_table(TABLE *entry)
Definition: sql_base.cc:1088
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:940
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:8629
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:2759
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:9926
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:525
int setup_ftfuncs(const THD *thd, SELECT_LEX *select)
Definition: sql_base.cc:9792
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:2043
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:3491
bool fill_record(THD *thd, TABLE *table, List< Item > &fields, List< Item > &values, MY_BITMAP *bitmap, MY_BITMAP *insert_into_fields_bitmap, bool raise_autoinc_has_expl_non_null_val)
Fill fields with given items.
Definition: sql_base.cc:9030
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:5299
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:6065
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:6077
static char * path
Definition: mysqldump.cc:125
Definition: item.h:668
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:8668
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:469
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2272
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:5879
void close_log_table(THD *thd, Open_tables_backup *backup)
Close a log table.
Definition: sql_base.cc:10002
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:6561
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:1013
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:3992
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:4288
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:2401
Definition: sql_base.h:96
enum_tdc_remove_table_type
Definition: sql_base.h:95
Definition: item.h:392
void free_io_cache(TABLE *entry)
Definition: sql_base.cc:1104
bool recover_from_failed_open()
Recover from failed attempt of open table by performing requested action.
Definition: sql_base.cc:4126
This class encapsulates a data change operation.
Definition: sql_data_change.h:71
uint counter
Definition: mysqlimport.cc:53
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:444
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:6052
int run_before_dml_hook(THD *thd)
Run the server hook called "before_dml".
Definition: sql_base.cc:5139
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:2199
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:281
bool mysql_rm_tmp_tables(void)
Drop all temporary tables which have been left from previous server run.
Definition: sql_base.cc:9594
bool close_temporary_tables(THD *thd)
Definition: sql_base.cc:1764
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:9719
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:150
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:79
Definition: sql_base.h:98
THD * m_thd
Definition: sql_base.h:509
Definition: table.h:2468
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:6479
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:2371
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: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: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:2332
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:778
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:2170