MySQL 9.6.0
Source Code Documentation
sql_base.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2025, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_BASE_INCLUDED
25#define SQL_BASE_INCLUDED
26
27#include <stddef.h>
28#include <sys/types.h>
29#include <memory>
30#include <string>
31
32#include "lex_string.h"
33#include "map_helpers.h"
34#include "mem_root_deque.h"
35#include "my_base.h" // ha_extra_function
36#include "my_inttypes.h"
38#include "prealloced_array.h" // Prealloced_array
39#include "sql/auth/auth_acls.h" // Access_bitmask
40#include "sql/key.h" // KEY
41#include "sql/locked_tables_list.h" // enum_locked_tables_mode
42#include "sql/mdl.h" // MDL_savepoint
43#include "sql/sql_array.h" // Bounds_checked_array
44#include "sql/sql_const.h" // enum_resolution_type
45#include "sql/trigger_def.h" // enum_trigger_event_type
46#include "thr_lock.h" // thr_lock_type
47
48class COPY_INFO;
49class Field;
50class Item;
51class Item_ident;
56class Query_block;
58class THD;
59class sp_head;
60struct LEX;
61struct MY_BITMAP;
63struct OPEN_TABLE_LIST;
64struct TABLE;
65class Table_ref;
66struct TABLE_SHARE;
67struct handlerton;
68template <class T>
69class List;
70template <class T>
71class List_iterator;
72template <class T>
73class Mem_root_array;
74
76namespace dd {
77class Table;
78} // namespace dd
79
80#define TEMP_PREFIX "MY"
81
82/* Defines for use with openfrm, openprt and openfrd */
83
84#define READ_ALL 1 /* openfrm: Read all parameters */
85#define EXTRA_RECORD 8 /* Reservera plats f|r extra record */
86#define DELAYED_OPEN 4096 /* Open table later */
87/**
88 If set, open_table_from_share() will skip calling get_new_handler() to
89 create a new handler object for the table. Designed to be used when
90 opening a table from inside storage engines.
91*/
92#define SKIP_NEW_HANDLER 32768
93
94constexpr int REPORT_NO_ERRORS = 0x00;
95constexpr int REPORT_NON_UNIQUE = 0x01;
96constexpr int REPORT_UNKNOWN_TABLE = 0x02;
97constexpr int REPORT_BAD_FIELD = 0x04;
98constexpr int REPORT_ALL_ERRORS =
100
102
111
113bool table_def_init(void);
114void table_def_free(void);
115void table_def_start_shutdown(void);
117uint cached_table_definitions(void);
118size_t get_table_def_key(const Table_ref *table_list, const char **key);
119TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name,
120 const char *key, size_t key_length, bool open_view,
121 bool open_secondary = false);
123
125 uint lock_flags);
126
127/* mysql_lock_tables() and open_table() flags bits */
128#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001
129#define MYSQL_OPEN_IGNORE_FLUSH 0x0002
130/* MYSQL_OPEN_TEMPORARY_ONLY (0x0004) is not used anymore. */
131#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
132#define MYSQL_LOCK_LOG_TABLE 0x0010
133/**
134 Do not try to acquire a metadata lock on the table: we
135 already have one.
136*/
137#define MYSQL_OPEN_HAS_MDL_LOCK 0x0020
138/**
139 If in locked tables mode, ignore the locked tables and get
140 a new instance of the table.
141*/
142#define MYSQL_OPEN_GET_NEW_TABLE 0x0040
143/* 0x0080 used to be MYSQL_OPEN_SKIP_TEMPORARY */
144/** Fail instead of waiting when conficting metadata lock is discovered. */
145#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0100
146/** Open tables using MDL_SHARED lock instead of one specified in parser. */
147#define MYSQL_OPEN_FORCE_SHARED_MDL 0x0200
148/**
149 Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified
150 in parser.
151*/
152#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0400
153/**
154 When opening or locking the table, use the maximum timeout
155 (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value.
156*/
157#define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800
158/**
159 When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to
160 be open do not acquire global, tablespace-scope and schema-scope IX locks.
161*/
162#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000
163/**
164 When opening or locking a replication table through an internal
165 operation rather than explicitly through an user thread.
166*/
167#define MYSQL_LOCK_RPL_INFO_TABLE 0x2000
168/**
169 Only check THD::killed if waits happen (e.g. wait on MDL, wait on
170 table flush, wait on thr_lock.c locks) while opening and locking table.
171*/
172#define MYSQL_OPEN_IGNORE_KILLED 0x4000
173/**
174 For new TABLE instances constructed do not open table in the storage
175 engine. Existing TABLE instances for which there is a handler object
176 which represents table open in storage engines can still be used.
177*/
178#define MYSQL_OPEN_NO_NEW_TABLE_IN_SE 0x8000
179/** Open a shadow copy of a table from a secondary storage engine. */
180#define MYSQL_OPEN_SECONDARY_ENGINE 0x10000
181
182/** Please refer to the internals manual. */
183#define MYSQL_OPEN_REOPEN \
184 (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | \
185 MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_LOCK_IGNORE_TIMEOUT | \
186 MYSQL_OPEN_IGNORE_KILLED | MYSQL_OPEN_GET_NEW_TABLE | \
187 MYSQL_OPEN_HAS_MDL_LOCK)
188
189bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx);
190
191TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
192 const char *table_name,
193 bool add_to_temporary_tables_list,
194 bool open_in_engine, const dd::Table &table_def);
195TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
197 Query_tables_list *prelocking_ctx,
198 Table_ref *table_list,
199 bool routine_modifies_data);
200
201bool mysql_rm_tmp_tables(void);
202bool rm_temporary_table(THD *thd, handlerton *base, const char *path,
203 const dd::Table *table_def);
204void close_tables_for_reopen(THD *thd, Table_ref **tables,
205 const MDL_savepoint &start_of_statement_svp);
206TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
207TABLE *find_temporary_table(THD *thd, const Table_ref *tl);
208void close_thread_tables(THD *thd);
210 THD *thd, COPY_INFO *optype_info, const mem_root_deque<Item *> &fields,
211 const mem_root_deque<Item *> &values, TABLE *table,
212 enum enum_trigger_event_type event, int num_fields,
213 bool raise_autoinc_has_expl_non_null_val, bool *is_row_changed);
215 const mem_root_deque<Item *> &values,
216 TABLE *table,
218 int num_fields);
219bool resolve_var_assignments(THD *thd, LEX *lex);
220bool insert_fields(THD *thd, Query_block *query_block, const char *db_name,
221 const char *table_name, mem_root_deque<Item *> *fields,
222 mem_root_deque<Item *>::iterator *it, bool any_privileges);
223bool setup_fields(THD *thd, Access_bitmask want_privilege, bool allow_sum_func,
224 bool split_sum_funcs, bool column_update,
225 const mem_root_deque<Item *> *typed_items,
227 Ref_item_array ref_item_array);
228bool fill_record(THD *thd, TABLE *table, const mem_root_deque<Item *> &fields,
229 const mem_root_deque<Item *> &values, MY_BITMAP *bitmap,
230 MY_BITMAP *insert_into_fields_bitmap,
231 bool raise_autoinc_has_expl_non_null_val);
232bool fill_record(THD *thd, TABLE *table, Field **field,
233 const mem_root_deque<Item *> &values, MY_BITMAP *bitmap,
234 MY_BITMAP *insert_into_fields_bitmap,
235 bool raise_autoinc_has_expl_non_null_val);
236
237bool check_record(THD *thd, Field **ptr);
238
239/**
240 Invoke check constraints defined on the table.
241
242 @param thd Thread handle.
243 @param table Instance of TABLE.
244
245 @retval false If all enforced check constraints are satisfied.
246 @retval true Otherwise. THD::is_error() may be "true" in this case.
247*/
249
250bool find_field_in_tables(THD *thd, Item_ident *item, Table_ref *first_table,
251 Table_ref *last_table, int report_error,
252 Access_bitmask want_privilege,
253 Find_field_result *result, Field **base_field,
254 Item_ident **ref_field);
255bool find_field_in_table_ref(THD *thd, Table_ref *tr, const char *field_name,
256 size_t length, const char *alias,
257 const char *db_name, const char *table_name,
258 Access_bitmask want_privilege, bool allow_rowid,
259 Find_field_result *result, Field **base_field,
260 Item_ident **ref_field);
261Field *find_field_in_table(TABLE *table, const char *field_name,
262 bool allow_rowid, uint *field_index);
263Field *find_field_in_table_sef(TABLE *table, const char *field_name);
264
265bool find_item_in_list(THD *thd, Item *item, mem_root_deque<Item *> *items,
266 Item ***found, uint *counter,
267 enum_resolution_type *resolution);
269 mem_root_deque<Table_ref *> *from_clause,
270 Name_resolution_context *context);
272 enum ha_extra_function function);
273
274void update_non_unique_table_error(Table_ref *update, const char *operation,
275 Table_ref *duplicate);
276int setup_ftfuncs(const THD *thd, Query_block *select);
277bool init_ftfuncs(THD *thd, Query_block *select);
278int run_before_dml_hook(THD *thd);
279bool get_and_lock_tablespace_names(THD *thd, Table_ref *tables_start,
280 Table_ref *tables_end,
281 ulong lock_wait_timeout, uint flags);
283 THD *thd, Table_ref *table_list, Table_ref *table_list_end,
284 ulong lock_wait_timeout, uint flags,
285 Prealloced_array<MDL_request *, 1> *schema_reqs = nullptr);
286bool open_tables(THD *thd, Table_ref **tables, uint *counter, uint flags,
287 Prelocking_strategy *prelocking_strategy);
288/* open_and_lock_tables */
289bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags,
290 Prelocking_strategy *prelocking_strategy);
291/* simple open_and_lock_tables for single table */
293 thr_lock_type lock_type, uint flags,
294 Prelocking_strategy *prelocking_strategy);
295bool open_tables_for_query(THD *thd, Table_ref *tables, uint flags);
296bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags);
297bool lock_dictionary_tables(THD *thd, Table_ref *tables, uint count,
298 uint flags);
301void close_thread_table(THD *thd, TABLE **table_ptr);
302bool close_temporary_tables(THD *thd);
303Table_ref *unique_table(const Table_ref *table, Table_ref *table_list,
304 bool check_alias);
305void drop_temporary_table(THD *thd, Table_ref *table_list);
307 bool delete_table);
308void close_temporary(THD *thd, TABLE *table, bool free_share,
309 bool delete_table);
310bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db,
311 const char *table_name);
312bool open_temporary_tables(THD *thd, Table_ref *tl_list);
313bool open_temporary_table(THD *thd, Table_ref *tl);
314
315/* Functions to work with system tables. */
316bool open_trans_system_tables_for_read(THD *thd, Table_ref *table_list);
318void close_mysql_tables(THD *thd);
319TABLE *open_log_table(THD *thd, Table_ref *one_table,
322
323bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh,
324 ulong timeout);
325
326/**
327 Close all open instances of the table but keep the MDL lock.
328
329 Works both under LOCK TABLES and in the normal mode.
330 Removes all closed instances of the table from the table cache.
331
332 @param thd Thread context.
333 @param share Table share, but is just a handy way to
334 access the table cache key.
335 @param remove_from_locked_tables
336 True if the table is being dropped.
337 In that case the documented behaviour is to
338 implicitly remove the table from LOCK TABLES list.
339 @param skip_table TABLE instance that should be kept open.
340
341 @pre Must be called with an X MDL lock on the table.
342*/
344 bool remove_from_locked_tables,
345 TABLE *skip_table);
346
347/**
348 Close all open instances of the table but keep the MDL lock.
349
350 Works both under LOCK TABLES and in the normal mode.
351 Removes all closed instances of the table from the table cache.
352
353 @param thd Thread context.
354 @param db Database name.
355 @param table_name Table name.
356 @param remove_from_locked_tables
357 True if the table is being dropped.
358 In that case the documented behaviour is to
359 implicitly remove the table from LOCK TABLES list.
360
361 @pre Must be called with an X MDL lock on the table.
362*/
363void close_all_tables_for_name(THD *thd, const char *db, const char *table_name,
364 bool remove_from_locked_tables);
365
366OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
367void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
368 const char *db, const char *table_name, bool has_lock);
370TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
371 const char *table_name, bool no_error);
373
374extern Field *not_found_field;
375extern Field *view_ref_found;
376
378 void operator()(TABLE_SHARE *share) const;
379};
380extern malloc_unordered_map<std::string,
381 std::unique_ptr<TABLE_SHARE, Table_share_deleter>>
383
385 const char *table_name);
386
387/**
388 The maximum length of a key in the table definition cache.
389
390 The key consists of the schema name, a '\0' character, the table
391 name and a '\0' character. Hence NAME_LEN * 2 + 1 + 1.
392
393 Additionally, the key can be suffixed with either 4 + 4 extra bytes
394 for slave tmp tables, or with a single extra byte for tables in a
395 secondary storage engine. Add 4 + 4 to account for either of these
396 suffixes.
397*/
398constexpr const size_t MAX_DBKEY_LENGTH{NAME_LEN * 2 + 1 + 1 + 4 + 4};
399
400/**
401 Create a table cache/table definition cache key for a table. The
402 table is neither a temporary table nor a table in a secondary
403 storage engine.
404
405 @note
406 The table cache_key is created from:
407
408 db_name + \0
409 table_name + \0
410
411 @param[in] db_name the database name
412 @param[in] table_name the table name
413 @param[out] key buffer for the key to be created (must be of
414 size MAX_DBKEY_LENGTH)
415 @return the length of the key
416*/
417size_t create_table_def_key(const char *db_name, const char *table_name,
418 char *key);
419
420/**
421 An abstract class for a strategy specifying how the prelocking
422 algorithm should extend the prelocking set while processing
423 already existing elements in the set.
424*/
425
427 public:
428 virtual ~Prelocking_strategy() = default;
429
430 virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
432 bool *need_prelocking) = 0;
433 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
434 Table_ref *table_list, bool *need_prelocking) = 0;
435 virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
436 Table_ref *table_list, bool *need_prelocking) = 0;
437};
438
439/**
440 A Strategy for prelocking algorithm suitable for DML statements.
441
442 Ensures that all tables used by all statement's SF/SP/triggers and
443 required for foreign key checks are prelocked and SF/SPs used are
444 cached.
445*/
446
448 public:
449 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
451 bool *need_prelocking) override;
452 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
453 Table_ref *table_list, bool *need_prelocking) override;
454 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
455 Table_ref *table_list, bool *need_prelocking) override;
456};
457
458/**
459 A strategy for prelocking algorithm to be used for LOCK TABLES
460 statement.
461*/
462
464 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
465 Table_ref *table_list, bool *need_prelocking) override;
466};
467
468/**
469 Strategy for prelocking algorithm to be used for ALTER TABLE statements.
470
471 Unlike DML or LOCK TABLES strategy, it doesn't
472 prelock triggers, views or stored routines, since they are not
473 used during ALTER.
474*/
475
477 public:
478 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
480 bool *need_prelocking) override;
481 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
482 Table_ref *table_list, bool *need_prelocking) override;
483 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
484 Table_ref *table_list, bool *need_prelocking) override;
485};
486
487inline bool open_tables(THD *thd, Table_ref **tables, uint *counter,
488 uint flags) {
489 DML_prelocking_strategy prelocking_strategy;
490
491 return open_tables(thd, tables, counter, flags, &prelocking_strategy);
492}
493
495 thr_lock_type lock_type, uint flags) {
496 DML_prelocking_strategy prelocking_strategy;
497
498 return open_n_lock_single_table(thd, table_l, lock_type, flags,
499 &prelocking_strategy);
500}
501
502// open_and_lock_tables with default prelocking strategy
503inline bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags) {
504 DML_prelocking_strategy prelocking_strategy;
505
506 return open_and_lock_tables(thd, tables, flags, &prelocking_strategy);
507}
508
509/**
510 Get an existing table definition from the table definition cache.
511
512 Search the table definition cache for a share with the given key.
513 If the share exists or if it is in the process of being opened
514 by another thread (m_open_in_progress flag is true) return share.
515 Do not wait for share opening to finish.
516
517 @param db database name.
518 @param table_name table name.
519
520 @retval nulltpr a share for the table does not exist in the cache
521 @retval != nulltpr pointer to existing share in the cache
522*/
523
524TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
525
526/**
527 A context of open_tables() function, used to recover
528 from a failed open_table() or open_routine() attempt.
529*/
530
532 public:
540 };
541 Open_table_context(THD *thd, uint flags);
542
546
548
549 /**
550 When doing a back-off, we close all tables acquired by this
551 statement. Return an MDL savepoint taken at the beginning of
552 the statement, so that we can rollback to it before waiting on
553 locks.
554 */
557 }
558
559 inline ulong get_timeout() const { return m_timeout; }
560
561 uint get_flags() const { return m_flags; }
562
563 /**
564 Set flag indicating that we have already acquired metadata lock
565 protecting this statement against GRL while opening tables.
566 */
568
571 }
572
573 bool can_back_off() const { return !m_has_locks; }
574
575 private:
576 /* THD for which tables are opened. */
578 /**
579 For OT_DISCOVER, OT_REPAIR and OT_FIX_ROW_TYPE actions, the table list
580 element for the table which definition should be re-discovered/updated
581 or which should be repaired.
582 */
585 /**
586 Lock timeout in seconds. Initialized to LONG_TIMEOUT when opening system
587 tables or to the "lock_wait_timeout" system variable for regular tables.
588 */
590 /* open_table() flags. */
592 /** Back off action. */
594 /**
595 Whether we had any locks when this context was created.
596 If we did, they are from the previous statement of a transaction,
597 and we can't safely do back-off (and release them).
598 */
600 /**
601 Indicates that in the process of opening tables we have acquired
602 protection against global read lock.
603 */
605};
606
607/**
608 Check if given Table_ref is a acl table and is being read and not
609 in LOCK TABLE mode.
610
611 @param tl Table_ref pointing to the table.
612 @param ltm THD->locked_tables_mode enum.
613
614 @return true if acl table is being read, otherwise false.
615*/
617 enum enum_locked_tables_mode ltm);
618
619/**
620 Create a table cache/table definition cache key for a table in a
621 secondary storage engine.
622
623 The key is constructed by appending a single byte with the value 1
624 to the key generated by #create_table_def_key().
625
626 @param db_name the database name
627 @param table_name the table name
628 @return the key
629*/
630std::string create_table_def_key_secondary(const char *db_name,
631 const char *table_name);
632#endif /* SQL_BASE_INCLUDED */
uint32_t Access_bitmask
Definition: auth_acls.h:34
Strategy for prelocking algorithm to be used for ALTER TABLE statements.
Definition: sql_base.h:476
This class encapsulates a data change operation.
Definition: sql_data_change.h:74
A Strategy for prelocking algorithm suitable for DML statements.
Definition: sql_base.h:447
Definition: field.h:570
Definition: item.h:4196
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:928
Definition: sql_list.h:633
Definition: sql_list.h:494
A strategy for prelocking algorithm to be used for LOCK TABLES statement.
Definition: sql_base.h:463
Savepoint for MDL context.
Definition: mdl.h:1320
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
A context of open_tables() function, used to recover from a failed open_table() or open_routine() att...
Definition: sql_base.h:531
uint m_flags
Definition: sql_base.h:591
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:583
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:567
enum enum_open_table_action m_action
Back off action.
Definition: sql_base.h:593
enum_open_table_action
Definition: sql_base.h:533
@ OT_FIX_ROW_TYPE
Definition: sql_base.h:539
@ OT_DISCOVER
Definition: sql_base.h:537
@ OT_BACKOFF_AND_RETRY
Definition: sql_base.h:535
@ OT_REOPEN_TABLES
Definition: sql_base.h:536
@ OT_NO_ACTION
Definition: sql_base.h:534
@ OT_REPAIR
Definition: sql_base.h:538
ulong get_timeout() const
Definition: sql_base.h:559
uint get_flags() const
Definition: sql_base.h:561
bool has_protection_against_grl() const
Definition: sql_base.h:569
ulong m_timeout
Lock timeout in seconds.
Definition: sql_base.h:589
THD * m_thd
Definition: sql_base.h:577
bool m_has_locks
Whether we had any locks when this context was created.
Definition: sql_base.h:599
bool can_back_off() const
Definition: sql_base.h:573
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:555
bool can_recover_from_failed_open() const
Definition: sql_base.h:547
MDL_savepoint m_start_of_statement_svp
Definition: sql_base.h:584
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:604
Storage for backup of Open_tables_state.
Definition: sql_class.h:697
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
An abstract class for a strategy specifying how the prelocking algorithm should extend the prelocking...
Definition: sql_base.h:426
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:1179
Definition: sql_lex.h:2758
Structure that represents element in the set of stored routines used by statement or routine.
Definition: sp.h:227
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2952
Definition: table.h:47
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:157
Definition: mem_root_deque.h:289
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
sp_head represents one instance of a stored program.
Definition: sp_head.h:389
A table definition from the master.
Definition: rpl_utility.h:249
static bool report_error(THD *thd, int error_code, Sql_condition::enum_severity_level level, Args... args)
Definition: error_handler.cc:291
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:3597
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:9865
void free_io_cache(TABLE *entry)
Definition: sql_base.cc:1173
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:4154
void assign_new_table_id(TABLE_SHARE *share)
Definition: sql_base.cc:3692
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:2274
void release_table_share(TABLE_SHARE *share)
Mark that we are not using table share anymore.
Definition: sql_base.cc:1017
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:389
bool find_field_in_table_ref(THD *thd, Table_ref *tr, const char *field_name, size_t length, const char *alias, const char *db_name, const char *table_name, Access_bitmask want_privilege, bool allow_rowid, Find_field_result *result, Field **base_field, Item_ident **ref_field)
Given a table reference and the name of a field, attempt to find the field in the referenced table.
Definition: sql_base.cc:8154
bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db, const char *table_name)
Definition: sql_base.cc:2475
Field * find_field_in_table(TABLE *table, const char *field_name, bool allow_rowid, uint *field_index)
Find field by name in a base table.
Definition: sql_base.cc:8075
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:1051
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:6723
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:9646
bool mysql_rm_tmp_tables(void)
Drop all temporary tables which have been left from previous server run.
Definition: sql_base.cc:10453
TABLE * open_log_table(THD *thd, Table_ref *one_table, Open_tables_backup *backup)
Open a log table.
Definition: sql_base.cc:10851
void close_temporary(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2445
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:1591
malloc_unordered_map< std::string, std::unique_ptr< TABLE_SHARE, Table_share_deleter > > * table_def_cache
Definition: sql_base.cc:328
bool check_record(THD *thd, Field **ptr)
Check the NOT NULL constraint on all the fields of the current record.
Definition: sql_base.cc:9970
bool rm_temporary_table(THD *thd, handlerton *base, const char *path, const dd::Table *table_def)
Delete a temporary table.
Definition: sql_base.cc:7743
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:5904
bool init_ftfuncs(THD *thd, Query_block *select)
Definition: sql_base.cc:10685
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:723
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:8480
OPEN_TABLE_LIST * list_open_tables(THD *thd, const char *db, const char *wild)
Definition: sql_base.cc:1078
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:2318
TABLE * open_ltable(THD *thd, Table_ref *table_list, thr_lock_type update, uint lock_flags)
Definition: sql_base.cc:6773
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:419
void close_temporary_table(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2406
void operator()(TABLE_SHARE *share) const
Definition: sql_base.cc:440
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:6462
Field * find_field_in_table_sef(TABLE *table, const char *field_name)
Find field in table, no side effects, only purpose is to check for field in table object and get refe...
Definition: sql_base.cc:8288
bool setup_natural_join_row_types(THD *thd, mem_root_deque< Table_ref * > *from_clause, Name_resolution_context *context)
Definition: sql_base.cc:9205
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:2245
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:1522
void table_def_free(void)
Definition: sql_base.cc:492
Open_table_context(THD *thd, uint flags)
Open_table_context.
Definition: sql_base.cc:4134
void close_log_table(THD *thd, Open_tables_backup *backup)
Close a log table.
Definition: sql_base.cc:10882
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:10581
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:10146
void close_mysql_tables(THD *thd)
A helper function to close a mysql.
Definition: sql_base.cc:10833
void close_trans_system_tables(THD *thd)
Close transactional system tables, opened with open_trans_system_tables_for_read().
Definition: sql_base.cc:10808
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:7799
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:6567
mysql_mutex_t LOCK_open
LOCK_open protects the following variables/objects:
Definition: sql_base.cc:267
bool setup_fields(THD *thd, Access_bitmask 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:9326
bool close_temporary_tables(THD *thd)
Definition: sql_base.cc:1832
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:7494
bool find_field_in_tables(THD *thd, Item_ident *item, Table_ref *first_table, Table_ref *last_table, int report_error, Access_bitmask want_privilege, Find_field_result *result, Field **base_field, Item_ident **ref_field)
Find field in list of tables inside one query block.
Definition: sql_base.cc:8331
void tdc_flush_unused_tables()
Definition: sql_base.cc:10533
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:6530
bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh, ulong timeout)
Definition: sql_base.cc:1201
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:6589
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:7604
bool open_temporary_tables(THD *thd, Table_ref *tl_list)
Pre-open temporary tables corresponding to table list elements.
Definition: sql_base.cc:7895
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:7172
uint cached_table_definitions(void)
Definition: sql_base.cc:504
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:476
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:10742
void drop_temporary_table(THD *thd, Table_ref *table_list)
Drop a temporary table.
Definition: sql_base.cc:2382
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:6866
bool resolve_var_assignments(THD *thd, LEX *lex)
Resolve variable assignments from LEX object.
Definition: sql_base.cc:9282
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:2509
void close_thread_table(THD *thd, TABLE **table_ptr)
Definition: sql_base.cc:1771
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:2117
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:6413
bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags)
Lock all tables in a list.
Definition: sql_base.cc:7271
int setup_ftfuncs(const THD *thd, Query_block *select)
Definition: sql_base.cc:10661
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:4430
bool table_def_init(void)
Definition: sql_base.cc:451
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:3630
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:7548
bool recover_from_failed_open()
Recover from failed attempt of open table by performing requested action.
Definition: sql_base.cc:4268
bool invoke_table_check_constraints(THD *thd, const TABLE *table)
Invoke check constraints defined on the table.
Definition: sql_base.cc:10011
bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx)
Open a base table.
Definition: sql_base.cc:2852
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:5507
void mark_tmp_table_for_reuse(TABLE *table)
Reset a single temporary table.
Definition: sql_base.cc:1383
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:6614
size_t create_table_def_key(const char *db_name, const char *table_name, char *key)
Create a table cache/table definition cache key for a table.
Definition: sql_base.cc:342
int run_before_dml_hook(THD *thd)
Run the server hook called "before_dml".
Definition: sql_base.cc:5434
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:5636
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:6011
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:6602
void intern_close_table(TABLE *entry)
Definition: sql_base.cc:1153
static void free_share(st_blackhole_share *share)
Definition: ha_blackhole.cc:308
static int flags[50]
Definition: hp_test1.cc:40
enum_locked_tables_mode
Type of locked tables mode.
Definition: locked_tables_list.h:47
This file includes constants used by all storage engines.
ha_extra_function
Definition: my_base.h:185
Some integer typedefs for easier portability.
static int count
Definition: myisam_ftdump.cc:45
static uint update
Definition: myisamlog.cc:94
static bool backup
Definition: myisampack.cc:198
#define NAME_LEN
Definition: mysql_com.h:67
ABI for instrumented mutexes.
static char * path
Definition: mysqldump.cc:150
uint counter
Definition: mysqlimport.cc:58
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
static PFS_engine_table_share_proxy share
Definition: connection_control_pfs_table.cc:92
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:44
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:76
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
entry::Table Table
Definition: select.h:51
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2884
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required string event
Definition: replication_group_member_actions.proto:32
Find_field_result
Definition: sql_base.h:101
@ FIELD_NOT_FOUND
Definition: sql_base.h:101
@ VIEW_FIELD_FOUND
Definition: sql_base.h:101
@ BASE_FIELD_FOUND
Definition: sql_base.h:101
constexpr int REPORT_ALL_ERRORS
Definition: sql_base.h:98
constexpr int REPORT_NO_ERRORS
Definition: sql_base.h:94
constexpr int REPORT_NON_UNIQUE
Definition: sql_base.h:95
Bounds_checked_array< Item * > Ref_item_array
Definition: sql_base.h:73
enum_tdc_remove_table_type
Definition: sql_base.h:103
@ TDC_RT_REMOVE_UNUSED
Definition: sql_base.h:106
@ TDC_RT_MARK_FOR_REOPEN_AND_INVALIDATE_SHARE
Definition: sql_base.h:109
@ TDC_RT_REMOVE_NOT_OWN
Definition: sql_base.h:105
@ TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE
Definition: sql_base.h:107
@ TDC_RT_REMOVE_ALL
Definition: sql_base.h:104
@ TDC_RT_MARK_FOR_REOPEN
Definition: sql_base.h:108
constexpr int REPORT_BAD_FIELD
Definition: sql_base.h:97
constexpr const size_t MAX_DBKEY_LENGTH
The maximum length of a key in the table definition cache.
Definition: sql_base.h:398
constexpr int REPORT_UNKNOWN_TABLE
Definition: sql_base.h:96
Field * not_found_field
Field * view_ref_found
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:280
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3995
Definition: my_bitmap.h:43
Instances of Name_resolution_context store the information necessary for name resolution of Items and...
Definition: item.h:413
Definition: table.h:4346
This structure is shared between different table objects.
Definition: table.h:731
Definition: table.h:1450
Definition: sql_base.h:377
Definition: completion_hash.h:35
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2856
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: result.h:30
thr_lock_type
Definition: thr_lock.h:51
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:42