MySQL 8.3.0
Source Code Documentation
sql_base.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2023, Oracle and/or its affiliates.
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 "mem_root_deque.h"
34#include "my_base.h" // ha_extra_function
35#include "my_inttypes.h"
37#include "prealloced_array.h" // Prealloced_array
38#include "sql/locked_tables_list.h" // enum_locked_tables_mode
39#include "sql/mdl.h" // MDL_savepoint
40#include "sql/sql_array.h" // Bounds_checked_array
41#include "sql/sql_const.h" // enum_resolution_type
42#include "sql/trigger_def.h" // enum_trigger_event_type
43#include "thr_lock.h" // thr_lock_type
44
45class COPY_INFO;
46class Field;
47class Item;
48class Item_ident;
53class Query_block;
55class THD;
56class sp_head;
57struct LEX;
58struct MY_BITMAP;
60struct OPEN_TABLE_LIST;
61struct TABLE;
62class Table_ref;
63struct TABLE_SHARE;
64struct handlerton;
65template <class T>
66class List;
67template <class T>
68class List_iterator;
69template <class T>
70class Mem_root_array;
71
73namespace dd {
74class Table;
75} // namespace dd
76
77#define TEMP_PREFIX "MY"
78
79/* Defines for use with openfrm, openprt and openfrd */
80
81#define READ_ALL 1 /* openfrm: Read all parameters */
82#define EXTRA_RECORD 8 /* Reservera plats f|r extra record */
83#define DELAYED_OPEN 4096 /* Open table later */
84/**
85 If set, open_table_from_share() will skip calling get_new_handler() to
86 create a new handler object for the table. Designed to be used when
87 opening a table from inside storage engines.
88*/
89#define SKIP_NEW_HANDLER 32768
90
97};
98
106
108bool table_def_init(void);
109void table_def_free(void);
110void table_def_start_shutdown(void);
112uint cached_table_definitions(void);
113size_t get_table_def_key(const Table_ref *table_list, const char **key);
114TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name,
115 const char *key, size_t key_length, bool open_view,
116 bool open_secondary = false);
118
120 uint lock_flags);
121
122/* mysql_lock_tables() and open_table() flags bits */
123#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001
124#define MYSQL_OPEN_IGNORE_FLUSH 0x0002
125/* MYSQL_OPEN_TEMPORARY_ONLY (0x0004) is not used anymore. */
126#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
127#define MYSQL_LOCK_LOG_TABLE 0x0010
128/**
129 Do not try to acquire a metadata lock on the table: we
130 already have one.
131*/
132#define MYSQL_OPEN_HAS_MDL_LOCK 0x0020
133/**
134 If in locked tables mode, ignore the locked tables and get
135 a new instance of the table.
136*/
137#define MYSQL_OPEN_GET_NEW_TABLE 0x0040
138/* 0x0080 used to be MYSQL_OPEN_SKIP_TEMPORARY */
139/** Fail instead of waiting when conficting metadata lock is discovered. */
140#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0100
141/** Open tables using MDL_SHARED lock instead of one specified in parser. */
142#define MYSQL_OPEN_FORCE_SHARED_MDL 0x0200
143/**
144 Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified
145 in parser.
146*/
147#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0400
148/**
149 When opening or locking the table, use the maximum timeout
150 (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value.
151*/
152#define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800
153/**
154 When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to
155 be open do not acquire global, tablespace-scope and schema-scope IX locks.
156*/
157#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000
158/**
159 When opening or locking a replication table through an internal
160 operation rather than explicitly through an user thread.
161*/
162#define MYSQL_LOCK_RPL_INFO_TABLE 0x2000
163/**
164 Only check THD::killed if waits happen (e.g. wait on MDL, wait on
165 table flush, wait on thr_lock.c locks) while opening and locking table.
166*/
167#define MYSQL_OPEN_IGNORE_KILLED 0x4000
168/**
169 For new TABLE instances constructed do not open table in the storage
170 engine. Existing TABLE instances for which there is a handler object
171 which represents table open in storage engines can still be used.
172*/
173#define MYSQL_OPEN_NO_NEW_TABLE_IN_SE 0x8000
174/** Open a shadow copy of a table from a secondary storage engine. */
175#define MYSQL_OPEN_SECONDARY_ENGINE 0x10000
176
177/** Please refer to the internals manual. */
178#define MYSQL_OPEN_REOPEN \
179 (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | \
180 MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_LOCK_IGNORE_TIMEOUT | \
181 MYSQL_OPEN_IGNORE_KILLED | MYSQL_OPEN_GET_NEW_TABLE | \
182 MYSQL_OPEN_HAS_MDL_LOCK)
183
184bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx);
185
186TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
187 const char *table_name,
188 bool add_to_temporary_tables_list,
189 bool open_in_engine, const dd::Table &table_def);
190TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
192 Query_tables_list *prelocking_ctx,
193 Table_ref *table_list,
194 bool routine_modifies_data);
195
196bool mysql_rm_tmp_tables(void);
197bool rm_temporary_table(THD *thd, handlerton *base, const char *path,
198 const dd::Table *table_def);
199void close_tables_for_reopen(THD *thd, Table_ref **tables,
200 const MDL_savepoint &start_of_statement_svp);
201TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
202TABLE *find_temporary_table(THD *thd, const Table_ref *tl);
203void close_thread_tables(THD *thd);
205 THD *thd, COPY_INFO *optype_info, const mem_root_deque<Item *> &fields,
206 const mem_root_deque<Item *> &values, TABLE *table,
207 enum enum_trigger_event_type event, int num_fields,
208 bool raise_autoinc_has_expl_non_null_val, bool *is_row_changed);
210 const mem_root_deque<Item *> &values,
211 TABLE *table,
213 int num_fields);
214bool resolve_var_assignments(THD *thd, LEX *lex);
215bool insert_fields(THD *thd, Query_block *query_block, const char *db_name,
216 const char *table_name, mem_root_deque<Item *> *fields,
217 mem_root_deque<Item *>::iterator *it, bool any_privileges);
218bool setup_fields(THD *thd, ulong want_privilege, bool allow_sum_func,
219 bool split_sum_funcs, bool column_update,
220 const mem_root_deque<Item *> *typed_items,
222 Ref_item_array ref_item_array);
223bool fill_record(THD *thd, TABLE *table, const mem_root_deque<Item *> &fields,
224 const mem_root_deque<Item *> &values, MY_BITMAP *bitmap,
225 MY_BITMAP *insert_into_fields_bitmap,
226 bool raise_autoinc_has_expl_non_null_val);
227bool fill_record(THD *thd, TABLE *table, Field **field,
228 const mem_root_deque<Item *> &values, MY_BITMAP *bitmap,
229 MY_BITMAP *insert_into_fields_bitmap,
230 bool raise_autoinc_has_expl_non_null_val);
231
232bool check_record(THD *thd, Field **ptr);
233
234/**
235 Invoke check constraints defined on the table.
236
237 @param thd Thread handle.
238 @param table Instance of TABLE.
239
240 @retval false If all enforced check constraints are satisfied.
241 @retval true Otherwise. THD::is_error() may be "true" in this case.
242*/
244
245Field *find_field_in_tables(THD *thd, Item_ident *item, Table_ref *first_table,
246 Table_ref *last_table, Item **ref,
248 ulong want_privilege, bool register_tree_change);
249Field *find_field_in_table_ref(THD *thd, Table_ref *table_list,
250 const char *name, size_t length,
251 const char *item_name, const char *db_name,
252 const char *table_name, Item **ref,
253 ulong want_privilege, bool allow_rowid,
254 uint *cached_field_index_ptr,
255 bool register_tree_change,
256 Table_ref **actual_table);
257Field *find_field_in_table(TABLE *table, const char *name, bool allow_rowid,
258 uint *cached_field_index_ptr);
260bool find_item_in_list(THD *thd, Item *item, mem_root_deque<Item *> *items,
261 Item ***found, uint *counter,
262 enum_resolution_type *resolution);
264 mem_root_deque<Table_ref *> *from_clause,
265 Name_resolution_context *context);
267 enum ha_extra_function function);
268
269void update_non_unique_table_error(Table_ref *update, const char *operation,
270 Table_ref *duplicate);
271int setup_ftfuncs(const THD *thd, Query_block *select);
272bool init_ftfuncs(THD *thd, Query_block *select);
273int run_before_dml_hook(THD *thd);
274bool get_and_lock_tablespace_names(THD *thd, Table_ref *tables_start,
275 Table_ref *tables_end,
276 ulong lock_wait_timeout, uint flags);
278 THD *thd, Table_ref *table_list, Table_ref *table_list_end,
279 ulong lock_wait_timeout, uint flags,
280 Prealloced_array<MDL_request *, 1> *schema_reqs = nullptr);
281bool open_tables(THD *thd, Table_ref **tables, uint *counter, uint flags,
282 Prelocking_strategy *prelocking_strategy);
283/* open_and_lock_tables */
284bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags,
285 Prelocking_strategy *prelocking_strategy);
286/* simple open_and_lock_tables for single table */
288 thr_lock_type lock_type, uint flags,
289 Prelocking_strategy *prelocking_strategy);
290bool open_tables_for_query(THD *thd, Table_ref *tables, uint flags);
291bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags);
292bool lock_dictionary_tables(THD *thd, Table_ref *tables, uint count,
293 uint flags);
296void close_thread_table(THD *thd, TABLE **table_ptr);
297bool close_temporary_tables(THD *thd);
298Table_ref *unique_table(const Table_ref *table, Table_ref *table_list,
299 bool check_alias);
300void drop_temporary_table(THD *thd, Table_ref *table_list);
302 bool delete_table);
303void close_temporary(THD *thd, TABLE *table, bool free_share,
304 bool delete_table);
305bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db,
306 const char *table_name);
307bool open_temporary_tables(THD *thd, Table_ref *tl_list);
308bool open_temporary_table(THD *thd, Table_ref *tl);
309
310/* Functions to work with system tables. */
311bool open_trans_system_tables_for_read(THD *thd, Table_ref *table_list);
313void close_mysql_tables(THD *thd);
314TABLE *open_log_table(THD *thd, Table_ref *one_table,
317
318bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh,
319 ulong timeout);
320
321/**
322 Close all open instances of the table but keep the MDL lock.
323
324 Works both under LOCK TABLES and in the normal mode.
325 Removes all closed instances of the table from the table cache.
326
327 @param thd Thread context.
328 @param share Table share, but is just a handy way to
329 access the table cache key.
330 @param remove_from_locked_tables
331 True if the table is being dropped.
332 In that case the documented behaviour is to
333 implicitly remove the table from LOCK TABLES list.
334 @param skip_table TABLE instance that should be kept open.
335
336 @pre Must be called with an X MDL lock on the table.
337*/
339 bool remove_from_locked_tables,
340 TABLE *skip_table);
341
342/**
343 Close all open instances of the table but keep the MDL lock.
344
345 Works both under LOCK TABLES and in the normal mode.
346 Removes all closed instances of the table from the table cache.
347
348 @param thd Thread context.
349 @param db Database name.
350 @param table_name Table name.
351 @param remove_from_locked_tables
352 True if the table is being dropped.
353 In that case the documented behaviour is to
354 implicitly remove the table from LOCK TABLES list.
355
356 @pre Must be called with an X MDL lock on the table.
357*/
358void close_all_tables_for_name(THD *thd, const char *db, const char *table_name,
359 bool remove_from_locked_tables);
360
361OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
362void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
363 const char *db, const char *table_name, bool has_lock);
365TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
366 const char *table_name, bool no_error);
368
369extern Field *not_found_field;
370extern Field *view_ref_found;
371
373 void operator()(TABLE_SHARE *share) const;
374};
375extern malloc_unordered_map<std::string,
376 std::unique_ptr<TABLE_SHARE, Table_share_deleter>>
378
380 const char *table_name);
381
382/**
383 An abstract class for a strategy specifying how the prelocking
384 algorithm should extend the prelocking set while processing
385 already existing elements in the set.
386*/
387
389 public:
390 virtual ~Prelocking_strategy() = default;
391
392 virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
394 bool *need_prelocking) = 0;
395 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
396 Table_ref *table_list, bool *need_prelocking) = 0;
397 virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
398 Table_ref *table_list, bool *need_prelocking) = 0;
399};
400
401/**
402 A Strategy for prelocking algorithm suitable for DML statements.
403
404 Ensures that all tables used by all statement's SF/SP/triggers and
405 required for foreign key checks are prelocked and SF/SPs used are
406 cached.
407*/
408
410 public:
411 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
413 bool *need_prelocking) override;
414 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
415 Table_ref *table_list, bool *need_prelocking) override;
416 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
417 Table_ref *table_list, bool *need_prelocking) override;
418};
419
420/**
421 A strategy for prelocking algorithm to be used for LOCK TABLES
422 statement.
423*/
424
426 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
427 Table_ref *table_list, bool *need_prelocking) override;
428};
429
430/**
431 Strategy for prelocking algorithm to be used for ALTER TABLE statements.
432
433 Unlike DML or LOCK TABLES strategy, it doesn't
434 prelock triggers, views or stored routines, since they are not
435 used during ALTER.
436*/
437
439 public:
440 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
442 bool *need_prelocking) override;
443 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
444 Table_ref *table_list, bool *need_prelocking) override;
445 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
446 Table_ref *table_list, bool *need_prelocking) override;
447};
448
449inline bool open_tables(THD *thd, Table_ref **tables, uint *counter,
450 uint flags) {
451 DML_prelocking_strategy prelocking_strategy;
452
453 return open_tables(thd, tables, counter, flags, &prelocking_strategy);
454}
455
457 thr_lock_type lock_type, uint flags) {
458 DML_prelocking_strategy prelocking_strategy;
459
460 return open_n_lock_single_table(thd, table_l, lock_type, flags,
461 &prelocking_strategy);
462}
463
464// open_and_lock_tables with default prelocking strategy
465inline bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags) {
466 DML_prelocking_strategy prelocking_strategy;
467
468 return open_and_lock_tables(thd, tables, flags, &prelocking_strategy);
469}
470
471/**
472 Get an existing table definition from the table definition cache.
473
474 Search the table definition cache for a share with the given key.
475 If the share exists or if it is in the process of being opened
476 by another thread (m_open_in_progress flag is true) return share.
477 Do not wait for share opening to finish.
478
479 @param db database name.
480 @param table_name table name.
481
482 @retval nulltpr a share for the table does not exist in the cache
483 @retval != nulltpr pointer to existing share in the cache
484*/
485
486TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
487
488/**
489 A context of open_tables() function, used to recover
490 from a failed open_table() or open_routine() attempt.
491*/
492
494 public:
502 };
503 Open_table_context(THD *thd, uint flags);
504
508
510
511 /**
512 When doing a back-off, we close all tables acquired by this
513 statement. Return an MDL savepoint taken at the beginning of
514 the statement, so that we can rollback to it before waiting on
515 locks.
516 */
519 }
520
521 inline ulong get_timeout() const { return m_timeout; }
522
523 uint get_flags() const { return m_flags; }
524
525 /**
526 Set flag indicating that we have already acquired metadata lock
527 protecting this statement against GRL while opening tables.
528 */
530
533 }
534
535 bool can_back_off() const { return !m_has_locks; }
536
537 private:
538 /* THD for which tables are opened. */
540 /**
541 For OT_DISCOVER, OT_REPAIR and OT_FIX_ROW_TYPE actions, the table list
542 element for the table which definition should be re-discovered/updated
543 or which should be repaired.
544 */
547 /**
548 Lock timeout in seconds. Initialized to LONG_TIMEOUT when opening system
549 tables or to the "lock_wait_timeout" system variable for regular tables.
550 */
552 /* open_table() flags. */
554 /** Back off action. */
556 /**
557 Whether we had any locks when this context was created.
558 If we did, they are from the previous statement of a transaction,
559 and we can't safely do back-off (and release them).
560 */
562 /**
563 Indicates that in the process of opening tables we have acquired
564 protection against global read lock.
565 */
567};
568
569/**
570 Check if given Table_ref is a acl table and is being read and not
571 in LOCK TABLE mode.
572
573 @param tl Table_ref pointing to the table.
574 @param ltm THD->locked_tables_mode enum.
575
576 @return true if acl table is being read, otherwise false.
577*/
579 enum enum_locked_tables_mode ltm);
580
581/**
582 Create a table cache/table definition cache key for a table in a
583 secondary storage engine.
584
585 The key is constructed by appending a single byte with the value 1
586 to the key generated by #create_table_def_key().
587
588 @param db_name the database name
589 @param table_name the table name
590 @return the key
591*/
592std::string create_table_def_key_secondary(const char *db_name,
593 const char *table_name);
594#endif /* SQL_BASE_INCLUDED */
Strategy for prelocking algorithm to be used for ALTER TABLE statements.
Definition: sql_base.h:438
This class encapsulates a data change operation.
Definition: sql_data_change.h:73
A Strategy for prelocking algorithm suitable for DML statements.
Definition: sql_base.h:409
Definition: field.h:574
Definition: item.h:4068
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
Definition: sql_list.h:573
Definition: sql_list.h:434
A strategy for prelocking algorithm to be used for LOCK TABLES statement.
Definition: sql_base.h:425
Savepoint for MDL context.
Definition: mdl.h:1316
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
A context of open_tables() function, used to recover from a failed open_table() or open_routine() att...
Definition: sql_base.h:493
uint m_flags
Definition: sql_base.h:553
Table_ref * 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:545
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:529
enum enum_open_table_action m_action
Back off action.
Definition: sql_base.h:555
enum_open_table_action
Definition: sql_base.h:495
@ OT_FIX_ROW_TYPE
Definition: sql_base.h:501
@ OT_DISCOVER
Definition: sql_base.h:499
@ OT_BACKOFF_AND_RETRY
Definition: sql_base.h:497
@ OT_REOPEN_TABLES
Definition: sql_base.h:498
@ OT_NO_ACTION
Definition: sql_base.h:496
@ OT_REPAIR
Definition: sql_base.h:500
ulong get_timeout() const
Definition: sql_base.h:521
uint get_flags() const
Definition: sql_base.h:523
bool has_protection_against_grl() const
Definition: sql_base.h:531
ulong m_timeout
Lock timeout in seconds.
Definition: sql_base.h:551
THD * m_thd
Definition: sql_base.h:539
bool m_has_locks
Whether we had any locks when this context was created.
Definition: sql_base.h:561
bool can_back_off() const
Definition: sql_base.h:535
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:517
bool can_recover_from_failed_open() const
Definition: sql_base.h:509
MDL_savepoint m_start_of_statement_svp
Definition: sql_base.h:546
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:566
Storage for backup of Open_tables_state.
Definition: sql_class.h:692
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:70
An abstract class for a strategy specifying how the prelocking algorithm should extend the prelocking...
Definition: sql_base.h:388
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking)=0
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking)=0
virtual ~Prelocking_strategy()=default
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking)=0
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1161
Definition: sql_lex.h:2565
Structure that represents element in the set of stored routines used by statement or routine.
Definition: sp.h:224
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: table.h:2853
Definition: table.h:46
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:156
Definition: mem_root_deque.h:287
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:110
sp_head represents one instance of a stored program.
Definition: sp_head.h:382
A table definition from the master.
Definition: rpl_utility.h:247
static bool report_error(THD *thd, int error_code, Sql_condition::enum_severity_level level, Args... args)
Definition: error_handler.cc:290
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:3545
bool fill_record(THD *thd, TABLE *table, const mem_root_deque< Item * > &fields, const mem_root_deque< 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:9630
void free_io_cache(TABLE *entry)
Definition: sql_base.cc:1159
bool request_backoff_action(enum_open_table_action action_arg, Table_ref *table)
Check if we can back-off and set back off action if we can.
Definition: sql_base.cc:4115
void assign_new_table_id(TABLE_SHARE *share)
Definition: sql_base.cc:3640
void update_non_unique_table_error(Table_ref *update, const char *operation, Table_ref *duplicate)
Issue correct error message in case we found 2 duplicate tables which prevent some update operation.
Definition: sql_base.cc:2254
void release_table_share(TABLE_SHARE *share)
Mark that we are not using table share anymore.
Definition: sql_base.cc:1003
std::string create_table_def_key_secondary(const char *db_name, const char *table_name)
Create a table cache/table definition cache key for a table in a secondary storage engine.
Definition: sql_base.cc:415
bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db, const char *table_name)
Definition: sql_base.cc:2455
TABLE_SHARE * get_cached_table_share(const char *db, const char *table_name)
Get an existing table definition from the table definition cache.
Definition: sql_base.cc:1037
TABLE * open_n_lock_single_table(THD *thd, Table_ref *table_l, thr_lock_type lock_type, uint flags, Prelocking_strategy *prelocking_strategy)
Open and lock one table.
Definition: sql_base.cc:6487
bool insert_fields(THD *thd, Query_block *query_block, const char *db_name, const char *table_name, mem_root_deque< Item * > *fields, mem_root_deque< Item * >::iterator *it, bool any_privileges)
Definition: sql_base.cc:9411
bool mysql_rm_tmp_tables(void)
Drop all temporary tables which have been left from previous server run.
Definition: sql_base.cc:10216
TABLE * open_log_table(THD *thd, Table_ref *one_table, Open_tables_backup *backup)
Open a log table.
Definition: sql_base.cc:10609
void close_temporary(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2425
void close_thread_tables(THD *thd)
Close all tables used by the current substatement, or all tables used by this thread if we are on the...
Definition: sql_base.cc:1577
malloc_unordered_map< std::string, std::unique_ptr< TABLE_SHARE, Table_share_deleter > > * table_def_cache
Definition: sql_base.cc:336
Field * find_field_in_tables(THD *thd, Item_ident *item, Table_ref *first_table, Table_ref *last_table, Item **ref, find_item_error_report_type report_error, ulong want_privilege, bool register_tree_change)
Definition: sql_base.cc:8035
bool check_record(THD *thd, Field **ptr)
Check the NOT NULL constraint on all the fields of the current record.
Definition: sql_base.cc:9735
bool rm_temporary_table(THD *thd, handlerton *base, const char *path, const dd::Table *table_def)
Delete a temporary table.
Definition: sql_base.cc:7397
bool is_acl_table_in_non_LTM(const Table_ref *tl, enum enum_locked_tables_mode ltm)
Check if given Table_ref is a acl table and is being read and not in LOCK TABLE mode.
Definition: sql_base.cc:5714
bool init_ftfuncs(THD *thd, Query_block *select)
Definition: sql_base.cc:10443
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:697
bool setup_fields(THD *thd, ulong want_privilege, bool allow_sum_func, bool split_sum_funcs, bool column_update, const mem_root_deque< Item * > *typed_items, mem_root_deque< Item * > *fields, Ref_item_array ref_item_array)
Resolve a list of expressions and setup appropriate data.
Definition: sql_base.cc:9094
bool find_item_in_list(THD *thd, Item *item, mem_root_deque< Item * > *items, Item ***found, uint *counter, enum_resolution_type *resolution)
Find Item in list of items (find_field_in_tables analog)
Definition: sql_base.cc:8233
OPEN_TABLE_LIST * list_open_tables(THD *thd, const char *db, const char *wild)
Definition: sql_base.cc:1064
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:2298
TABLE * open_ltable(THD *thd, Table_ref *table_list, thr_lock_type update, uint lock_flags)
Definition: sql_base.cc:6537
size_t get_table_def_key(const Table_ref *table_list, const char **key)
Get table cache key for a table list element.
Definition: sql_base.cc:445
void close_temporary_table(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2386
void operator()(TABLE_SHARE *share) const
Definition: sql_base.cc:466
bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
Defines how prelocking algorithm for DML statements should handle table list elements:
Definition: sql_base.cc:6229
bool setup_natural_join_row_types(THD *thd, mem_root_deque< Table_ref * > *from_clause, Name_resolution_context *context)
Definition: sql_base.cc:8973
Table_ref * unique_table(const Table_ref *table, Table_ref *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:2225
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:1508
void table_def_free(void)
Definition: sql_base.cc:518
Open_table_context(THD *thd, uint flags)
Open_table_context.
Definition: sql_base.cc:4095
void close_log_table(THD *thd, Open_tables_backup *backup)
Close a log table.
Definition: sql_base.cc:10640
Field * find_field_in_table_ref(THD *thd, Table_ref *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_ref **actual_table)
Find field in a table reference.
Definition: sql_base.cc:7850
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:10344
Field * not_found_field
Definition: sql_base.cc:7429
bool fill_record_n_invoke_before_triggers(THD *thd, COPY_INFO *optype_info, const mem_root_deque< Item * > &fields, const mem_root_deque< 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:9911
void close_mysql_tables(THD *thd)
A helper function to close a mysql.
Definition: sql_base.cc:10591
void close_trans_system_tables(THD *thd)
Close transactional system tables, opened with open_trans_system_tables_for_read().
Definition: sql_base.cc:10566
bool open_temporary_table(THD *thd, Table_ref *tl)
Find a temporary table specified by Table_ref instance in the cache and prepare its TABLE instance fo...
Definition: sql_base.cc:7459
bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
Defines how prelocking algorithm for LOCK TABLES statement should handle table list elements.
Definition: sql_base.cc:6331
mysql_mutex_t LOCK_open
LOCK_open protects the following variables/objects:
Definition: sql_base.cc:275
bool close_temporary_tables(THD *thd)
Definition: sql_base.cc:1817
bool lock_dictionary_tables(THD *thd, Table_ref *tables, uint count, uint flags)
Simplified version of lock_tables() call to be used for locking data-dictionary tables when reading o...
Definition: sql_base.cc:7162
void tdc_flush_unused_tables()
Definition: sql_base.cc:10296
Field * find_field_in_table(TABLE *table, const char *name, bool allow_rowid, uint *cached_field_index_ptr)
Find field by name in a base table.
Definition: sql_base.cc:7774
bool handle_view(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
Defines how prelocking algorithm for DML statements should handle view - all view routines should be ...
Definition: sql_base.cc:6294
bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh, ulong timeout)
Definition: sql_base.cc:1187
bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking) override
Defines how prelocking algorithm for ALTER TABLE statement should handle routines - do nothing as thi...
Definition: sql_base.cc:6353
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't add it to THD::open_tables.
Definition: sql_base.cc:7272
bool open_temporary_tables(THD *thd, Table_ref *tl_list)
Pre-open temporary tables corresponding to table list elements.
Definition: sql_base.cc:7551
Field * view_ref_found
Definition: sql_base.cc:7430
bool open_tables_for_query(THD *thd, Table_ref *tables, uint flags)
Open all tables for a query or statement, in list started by "tables".
Definition: sql_base.cc:6857
uint cached_table_definitions(void)
Definition: sql_base.cc:530
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:502
bool open_trans_system_tables_for_read(THD *thd, Table_ref *table_list)
Open and lock transactional system tables for read.
Definition: sql_base.cc:10500
void drop_temporary_table(THD *thd, Table_ref *table_list)
Drop a temporary table.
Definition: sql_base.cc:2362
bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags, Prelocking_strategy *prelocking_strategy)
Open all tables in list, locks them and optionally process derived tables.
Definition: sql_base.cc:6630
bool resolve_var_assignments(THD *thd, LEX *lex)
Resolve variable assignments from LEX object.
Definition: sql_base.cc:9050
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:2489
void close_thread_table(THD *thd, TABLE **table_ptr)
Definition: sql_base.cc:1757
Table_ref * find_table_in_global_list(Table_ref *table, const char *db_name, const char *table_name)
Find table in global list.
Definition: sql_base.cc:2097
bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx, Sroutine_hash_entry *rt, sp_head *sp, bool *need_prelocking) override
Defines how prelocking algorithm for DML statements should handle routines:
Definition: sql_base.cc:6180
bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags)
Lock all tables in a list.
Definition: sql_base.cc:6939
int setup_ftfuncs(const THD *thd, Query_block *select)
Definition: sql_base.cc:10419
thr_lock_type read_lock_type_for_table(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool routine_modifies_data)
Definition: sql_base.cc:4391
bool table_def_init(void)
Definition: sql_base.cc:477
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:3578
void close_tables_for_reopen(THD *thd, Table_ref **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:7216
bool recover_from_failed_open()
Recover from failed attempt of open table by performing requested action.
Definition: sql_base.cc:4229
bool invoke_table_check_constraints(THD *thd, const TABLE *table)
Invoke check constraints defined on the table.
Definition: sql_base.cc:9776
bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx)
Open a base table.
Definition: sql_base.cc:2832
bool get_and_lock_tablespace_names(THD *thd, Table_ref *tables_start, Table_ref *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:5317
void mark_tmp_table_for_reuse(TABLE *table)
Reset a single temporary table.
Definition: sql_base.cc:1369
bool handle_view(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
Defines how prelocking algorithm for ALTER TABLE statement should handle view - do nothing.
Definition: sql_base.cc:6378
int run_before_dml_hook(THD *thd)
Run the server hook called "before_dml".
Definition: sql_base.cc:5244
bool lock_table_names(THD *thd, Table_ref *table_list, Table_ref *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:5446
Field * find_field_in_table_sef(TABLE *table, const char *name)
Definition: sql_base.cc:7986
bool open_tables(THD *thd, Table_ref **tables, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy)
Open all tables in list.
Definition: sql_base.cc:5821
bool handle_table(THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list, bool *need_prelocking) override
Defines how prelocking algorithm for ALTER TABLE statement should handle table list elements.
Definition: sql_base.cc:6366
void intern_close_table(TABLE *entry)
Definition: sql_base.cc:1139
static void free_share(st_blackhole_share *share)
Definition: ha_blackhole.cc:307
static int flags[50]
Definition: hp_test1.cc:39
enum_locked_tables_mode
Type of locked tables mode.
Definition: locked_tables_list.h:46
This file includes constants used by all storage engines.
ha_extra_function
Definition: my_base.h:184
Some integer typedefs for easier portability.
static int count
Definition: myisam_ftdump.cc:44
static uint update
Definition: myisamlog.cc:93
static bool backup
Definition: myisampack.cc:197
ABI for instrumented mutexes.
static char * path
Definition: mysqldump.cc:148
uint counter
Definition: mysqlimport.cc:57
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
PT & ref(PT *tp)
Definition: tablespace_impl.cc:358
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
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
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:497
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2877
required string key
Definition: replication_asynchronous_connection_failover.proto:59
required string event
Definition: replication_group_member_actions.proto:31
Bounds_checked_array< Item * > Ref_item_array
Definition: sql_base.h:70
find_item_error_report_type
Definition: sql_base.h:91
@ REPORT_EXCEPT_NOT_FOUND
Definition: sql_base.h:93
@ IGNORE_EXCEPT_NON_UNIQUE
Definition: sql_base.h:96
@ IGNORE_ERRORS
Definition: sql_base.h:94
@ REPORT_ALL_ERRORS
Definition: sql_base.h:92
@ REPORT_EXCEPT_NON_UNIQUE
Definition: sql_base.h:95
enum_tdc_remove_table_type
Definition: sql_base.h:99
@ TDC_RT_REMOVE_UNUSED
Definition: sql_base.h:102
@ TDC_RT_REMOVE_NOT_OWN
Definition: sql_base.h:101
@ TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE
Definition: sql_base.h:103
@ TDC_RT_REMOVE_ALL
Definition: sql_base.h:100
@ TDC_RT_MARK_FOR_REOPEN
Definition: sql_base.h:104
File containing constants that can be used throughout the server.
enum_resolution_type
This enumeration type is used only by the function find_item_in_list to return the info on how an ite...
Definition: sql_const.h:278
case opt name
Definition: sslopt-case.h:32
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3787
Definition: my_bitmap.h:42
Definition: item.h:400
Definition: table.h:4131
This structure is shared between different table objects.
Definition: table.h:698
Definition: table.h:1403
Definition: sql_base.h:372
Definition: completion_hash.h:34
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2718
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
thr_lock_type
Definition: thr_lock.h:50
This file defines all base public constants related to triggers in MySQL.
enum_trigger_event_type
Constants to enumerate possible event types on which triggers can be fired.
Definition: trigger_def.h:41