MySQL 9.1.0
Source Code Documentation
sql_base.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2024, 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/locked_tables_list.h" // enum_locked_tables_mode
41#include "sql/mdl.h" // MDL_savepoint
42#include "sql/sql_array.h" // Bounds_checked_array
43#include "sql/sql_const.h" // enum_resolution_type
44#include "sql/trigger_def.h" // enum_trigger_event_type
45#include "thr_lock.h" // thr_lock_type
46
47class COPY_INFO;
48class Field;
49class Item;
50class Item_ident;
55class Query_block;
57class THD;
58class sp_head;
59struct LEX;
60struct MY_BITMAP;
62struct OPEN_TABLE_LIST;
63struct TABLE;
64class Table_ref;
65struct TABLE_SHARE;
66struct handlerton;
67template <class T>
68class List;
69template <class T>
70class List_iterator;
71template <class T>
72class Mem_root_array;
73
75namespace dd {
76class Table;
77} // namespace dd
78
79#define TEMP_PREFIX "MY"
80
81/* Defines for use with openfrm, openprt and openfrd */
82
83#define READ_ALL 1 /* openfrm: Read all parameters */
84#define EXTRA_RECORD 8 /* Reservera plats f|r extra record */
85#define DELAYED_OPEN 4096 /* Open table later */
86/**
87 If set, open_table_from_share() will skip calling get_new_handler() to
88 create a new handler object for the table. Designed to be used when
89 opening a table from inside storage engines.
90*/
91#define SKIP_NEW_HANDLER 32768
92
93constexpr int REPORT_NO_ERRORS = 0x00;
94constexpr int REPORT_NON_UNIQUE = 0x01;
95constexpr int REPORT_UNKNOWN_TABLE = 0x02;
96constexpr int REPORT_BAD_FIELD = 0x04;
97constexpr int REPORT_ALL_ERRORS =
99
101
109
111bool table_def_init(void);
112void table_def_free(void);
113void table_def_start_shutdown(void);
115uint cached_table_definitions(void);
116size_t get_table_def_key(const Table_ref *table_list, const char **key);
117TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name,
118 const char *key, size_t key_length, bool open_view,
119 bool open_secondary = false);
121
123 uint lock_flags);
124
125/* mysql_lock_tables() and open_table() flags bits */
126#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001
127#define MYSQL_OPEN_IGNORE_FLUSH 0x0002
128/* MYSQL_OPEN_TEMPORARY_ONLY (0x0004) is not used anymore. */
129#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
130#define MYSQL_LOCK_LOG_TABLE 0x0010
131/**
132 Do not try to acquire a metadata lock on the table: we
133 already have one.
134*/
135#define MYSQL_OPEN_HAS_MDL_LOCK 0x0020
136/**
137 If in locked tables mode, ignore the locked tables and get
138 a new instance of the table.
139*/
140#define MYSQL_OPEN_GET_NEW_TABLE 0x0040
141/* 0x0080 used to be MYSQL_OPEN_SKIP_TEMPORARY */
142/** Fail instead of waiting when conficting metadata lock is discovered. */
143#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0100
144/** Open tables using MDL_SHARED lock instead of one specified in parser. */
145#define MYSQL_OPEN_FORCE_SHARED_MDL 0x0200
146/**
147 Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified
148 in parser.
149*/
150#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0400
151/**
152 When opening or locking the table, use the maximum timeout
153 (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value.
154*/
155#define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800
156/**
157 When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to
158 be open do not acquire global, tablespace-scope and schema-scope IX locks.
159*/
160#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000
161/**
162 When opening or locking a replication table through an internal
163 operation rather than explicitly through an user thread.
164*/
165#define MYSQL_LOCK_RPL_INFO_TABLE 0x2000
166/**
167 Only check THD::killed if waits happen (e.g. wait on MDL, wait on
168 table flush, wait on thr_lock.c locks) while opening and locking table.
169*/
170#define MYSQL_OPEN_IGNORE_KILLED 0x4000
171/**
172 For new TABLE instances constructed do not open table in the storage
173 engine. Existing TABLE instances for which there is a handler object
174 which represents table open in storage engines can still be used.
175*/
176#define MYSQL_OPEN_NO_NEW_TABLE_IN_SE 0x8000
177/** Open a shadow copy of a table from a secondary storage engine. */
178#define MYSQL_OPEN_SECONDARY_ENGINE 0x10000
179
180/** Please refer to the internals manual. */
181#define MYSQL_OPEN_REOPEN \
182 (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | \
183 MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_LOCK_IGNORE_TIMEOUT | \
184 MYSQL_OPEN_IGNORE_KILLED | MYSQL_OPEN_GET_NEW_TABLE | \
185 MYSQL_OPEN_HAS_MDL_LOCK)
186
187bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx);
188
189TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
190 const char *table_name,
191 bool add_to_temporary_tables_list,
192 bool open_in_engine, const dd::Table &table_def);
193TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
195 Query_tables_list *prelocking_ctx,
196 Table_ref *table_list,
197 bool routine_modifies_data);
198
199bool mysql_rm_tmp_tables(void);
200bool rm_temporary_table(THD *thd, handlerton *base, const char *path,
201 const dd::Table *table_def);
202void close_tables_for_reopen(THD *thd, Table_ref **tables,
203 const MDL_savepoint &start_of_statement_svp);
204TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
205TABLE *find_temporary_table(THD *thd, const Table_ref *tl);
206void close_thread_tables(THD *thd);
208 THD *thd, COPY_INFO *optype_info, const mem_root_deque<Item *> &fields,
209 const mem_root_deque<Item *> &values, TABLE *table,
210 enum enum_trigger_event_type event, int num_fields,
211 bool raise_autoinc_has_expl_non_null_val, bool *is_row_changed);
213 const mem_root_deque<Item *> &values,
214 TABLE *table,
216 int num_fields);
217bool resolve_var_assignments(THD *thd, LEX *lex);
218bool insert_fields(THD *thd, Query_block *query_block, const char *db_name,
219 const char *table_name, mem_root_deque<Item *> *fields,
220 mem_root_deque<Item *>::iterator *it, bool any_privileges);
221bool setup_fields(THD *thd, Access_bitmask want_privilege, bool allow_sum_func,
222 bool split_sum_funcs, bool column_update,
223 const mem_root_deque<Item *> *typed_items,
225 Ref_item_array ref_item_array);
226bool fill_record(THD *thd, TABLE *table, const mem_root_deque<Item *> &fields,
227 const mem_root_deque<Item *> &values, MY_BITMAP *bitmap,
228 MY_BITMAP *insert_into_fields_bitmap,
229 bool raise_autoinc_has_expl_non_null_val);
230bool fill_record(THD *thd, TABLE *table, Field **field,
231 const mem_root_deque<Item *> &values, MY_BITMAP *bitmap,
232 MY_BITMAP *insert_into_fields_bitmap,
233 bool raise_autoinc_has_expl_non_null_val);
234
235bool check_record(THD *thd, Field **ptr);
236
237/**
238 Invoke check constraints defined on the table.
239
240 @param thd Thread handle.
241 @param table Instance of TABLE.
242
243 @retval false If all enforced check constraints are satisfied.
244 @retval true Otherwise. THD::is_error() may be "true" in this case.
245*/
247
248bool find_field_in_tables(THD *thd, Item_ident *item, Table_ref *first_table,
249 Table_ref *last_table, int report_error,
250 Access_bitmask want_privilege,
251 Find_field_result *result, Field **base_field,
252 Item_ident **ref_field);
253bool find_field_in_table_ref(THD *thd, Table_ref *tr, const char *field_name,
254 size_t length, const char *alias,
255 const char *db_name, const char *table_name,
256 Access_bitmask want_privilege, bool allow_rowid,
257 Find_field_result *result, Field **base_field,
258 Item_ident **ref_field);
259Field *find_field_in_table(TABLE *table, const char *field_name,
260 bool allow_rowid, uint *field_index);
261Field *find_field_in_table_sef(TABLE *table, const char *field_name);
262bool find_item_in_list(THD *thd, Item *item, mem_root_deque<Item *> *items,
263 Item ***found, uint *counter,
264 enum_resolution_type *resolution);
266 mem_root_deque<Table_ref *> *from_clause,
267 Name_resolution_context *context);
269 enum ha_extra_function function);
270
271void update_non_unique_table_error(Table_ref *update, const char *operation,
272 Table_ref *duplicate);
273int setup_ftfuncs(const THD *thd, Query_block *select);
274bool init_ftfuncs(THD *thd, Query_block *select);
275int run_before_dml_hook(THD *thd);
276bool get_and_lock_tablespace_names(THD *thd, Table_ref *tables_start,
277 Table_ref *tables_end,
278 ulong lock_wait_timeout, uint flags);
280 THD *thd, Table_ref *table_list, Table_ref *table_list_end,
281 ulong lock_wait_timeout, uint flags,
282 Prealloced_array<MDL_request *, 1> *schema_reqs = nullptr);
283bool open_tables(THD *thd, Table_ref **tables, uint *counter, uint flags,
284 Prelocking_strategy *prelocking_strategy);
285/* open_and_lock_tables */
286bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags,
287 Prelocking_strategy *prelocking_strategy);
288/* simple open_and_lock_tables for single table */
290 thr_lock_type lock_type, uint flags,
291 Prelocking_strategy *prelocking_strategy);
292bool open_tables_for_query(THD *thd, Table_ref *tables, uint flags);
293bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags);
294bool lock_dictionary_tables(THD *thd, Table_ref *tables, uint count,
295 uint flags);
298void close_thread_table(THD *thd, TABLE **table_ptr);
299bool close_temporary_tables(THD *thd);
300Table_ref *unique_table(const Table_ref *table, Table_ref *table_list,
301 bool check_alias);
302void drop_temporary_table(THD *thd, Table_ref *table_list);
304 bool delete_table);
305void close_temporary(THD *thd, TABLE *table, bool free_share,
306 bool delete_table);
307bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db,
308 const char *table_name);
309bool open_temporary_tables(THD *thd, Table_ref *tl_list);
310bool open_temporary_table(THD *thd, Table_ref *tl);
311
312/* Functions to work with system tables. */
313bool open_trans_system_tables_for_read(THD *thd, Table_ref *table_list);
315void close_mysql_tables(THD *thd);
316TABLE *open_log_table(THD *thd, Table_ref *one_table,
319
320bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh,
321 ulong timeout);
322
323/**
324 Close all open instances of the table but keep the MDL lock.
325
326 Works both under LOCK TABLES and in the normal mode.
327 Removes all closed instances of the table from the table cache.
328
329 @param thd Thread context.
330 @param share Table share, but is just a handy way to
331 access the table cache key.
332 @param remove_from_locked_tables
333 True if the table is being dropped.
334 In that case the documented behaviour is to
335 implicitly remove the table from LOCK TABLES list.
336 @param skip_table TABLE instance that should be kept open.
337
338 @pre Must be called with an X MDL lock on the table.
339*/
341 bool remove_from_locked_tables,
342 TABLE *skip_table);
343
344/**
345 Close all open instances of the table but keep the MDL lock.
346
347 Works both under LOCK TABLES and in the normal mode.
348 Removes all closed instances of the table from the table cache.
349
350 @param thd Thread context.
351 @param db Database name.
352 @param table_name Table name.
353 @param remove_from_locked_tables
354 True if the table is being dropped.
355 In that case the documented behaviour is to
356 implicitly remove the table from LOCK TABLES list.
357
358 @pre Must be called with an X MDL lock on the table.
359*/
360void close_all_tables_for_name(THD *thd, const char *db, const char *table_name,
361 bool remove_from_locked_tables);
362
363OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
364void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
365 const char *db, const char *table_name, bool has_lock);
367TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
368 const char *table_name, bool no_error);
370
371extern Field *not_found_field;
372extern Field *view_ref_found;
373
375 void operator()(TABLE_SHARE *share) const;
376};
377extern malloc_unordered_map<std::string,
378 std::unique_ptr<TABLE_SHARE, Table_share_deleter>>
380
382 const char *table_name);
383
384/**
385 An abstract class for a strategy specifying how the prelocking
386 algorithm should extend the prelocking set while processing
387 already existing elements in the set.
388*/
389
391 public:
392 virtual ~Prelocking_strategy() = default;
393
394 virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
396 bool *need_prelocking) = 0;
397 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
398 Table_ref *table_list, bool *need_prelocking) = 0;
399 virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
400 Table_ref *table_list, bool *need_prelocking) = 0;
401};
402
403/**
404 A Strategy for prelocking algorithm suitable for DML statements.
405
406 Ensures that all tables used by all statement's SF/SP/triggers and
407 required for foreign key checks are prelocked and SF/SPs used are
408 cached.
409*/
410
412 public:
413 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
415 bool *need_prelocking) override;
416 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
417 Table_ref *table_list, bool *need_prelocking) override;
418 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
419 Table_ref *table_list, bool *need_prelocking) override;
420};
421
422/**
423 A strategy for prelocking algorithm to be used for LOCK TABLES
424 statement.
425*/
426
428 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
429 Table_ref *table_list, bool *need_prelocking) override;
430};
431
432/**
433 Strategy for prelocking algorithm to be used for ALTER TABLE statements.
434
435 Unlike DML or LOCK TABLES strategy, it doesn't
436 prelock triggers, views or stored routines, since they are not
437 used during ALTER.
438*/
439
441 public:
442 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
444 bool *need_prelocking) override;
445 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
446 Table_ref *table_list, bool *need_prelocking) override;
447 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
448 Table_ref *table_list, bool *need_prelocking) override;
449};
450
451inline bool open_tables(THD *thd, Table_ref **tables, uint *counter,
452 uint flags) {
453 DML_prelocking_strategy prelocking_strategy;
454
455 return open_tables(thd, tables, counter, flags, &prelocking_strategy);
456}
457
459 thr_lock_type lock_type, uint flags) {
460 DML_prelocking_strategy prelocking_strategy;
461
462 return open_n_lock_single_table(thd, table_l, lock_type, flags,
463 &prelocking_strategy);
464}
465
466// open_and_lock_tables with default prelocking strategy
467inline bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags) {
468 DML_prelocking_strategy prelocking_strategy;
469
470 return open_and_lock_tables(thd, tables, flags, &prelocking_strategy);
471}
472
473/**
474 Get an existing table definition from the table definition cache.
475
476 Search the table definition cache for a share with the given key.
477 If the share exists or if it is in the process of being opened
478 by another thread (m_open_in_progress flag is true) return share.
479 Do not wait for share opening to finish.
480
481 @param db database name.
482 @param table_name table name.
483
484 @retval nulltpr a share for the table does not exist in the cache
485 @retval != nulltpr pointer to existing share in the cache
486*/
487
488TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
489
490/**
491 A context of open_tables() function, used to recover
492 from a failed open_table() or open_routine() attempt.
493*/
494
496 public:
504 };
505 Open_table_context(THD *thd, uint flags);
506
510
512
513 /**
514 When doing a back-off, we close all tables acquired by this
515 statement. Return an MDL savepoint taken at the beginning of
516 the statement, so that we can rollback to it before waiting on
517 locks.
518 */
521 }
522
523 inline ulong get_timeout() const { return m_timeout; }
524
525 uint get_flags() const { return m_flags; }
526
527 /**
528 Set flag indicating that we have already acquired metadata lock
529 protecting this statement against GRL while opening tables.
530 */
532
535 }
536
537 bool can_back_off() const { return !m_has_locks; }
538
539 private:
540 /* THD for which tables are opened. */
542 /**
543 For OT_DISCOVER, OT_REPAIR and OT_FIX_ROW_TYPE actions, the table list
544 element for the table which definition should be re-discovered/updated
545 or which should be repaired.
546 */
549 /**
550 Lock timeout in seconds. Initialized to LONG_TIMEOUT when opening system
551 tables or to the "lock_wait_timeout" system variable for regular tables.
552 */
554 /* open_table() flags. */
556 /** Back off action. */
558 /**
559 Whether we had any locks when this context was created.
560 If we did, they are from the previous statement of a transaction,
561 and we can't safely do back-off (and release them).
562 */
564 /**
565 Indicates that in the process of opening tables we have acquired
566 protection against global read lock.
567 */
569};
570
571/**
572 Check if given Table_ref is a acl table and is being read and not
573 in LOCK TABLE mode.
574
575 @param tl Table_ref pointing to the table.
576 @param ltm THD->locked_tables_mode enum.
577
578 @return true if acl table is being read, otherwise false.
579*/
581 enum enum_locked_tables_mode ltm);
582
583/**
584 Create a table cache/table definition cache key for a table in a
585 secondary storage engine.
586
587 The key is constructed by appending a single byte with the value 1
588 to the key generated by #create_table_def_key().
589
590 @param db_name the database name
591 @param table_name the table name
592 @return the key
593*/
594std::string create_table_def_key_secondary(const char *db_name,
595 const char *table_name);
596#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:440
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:411
Definition: field.h:577
Definition: item.h:4123
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
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:427
Savepoint for MDL context.
Definition: mdl.h:1318
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
A context of open_tables() function, used to recover from a failed open_table() or open_routine() att...
Definition: sql_base.h:495
uint m_flags
Definition: sql_base.h:555
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:547
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:531
enum enum_open_table_action m_action
Back off action.
Definition: sql_base.h:557
enum_open_table_action
Definition: sql_base.h:497
@ OT_FIX_ROW_TYPE
Definition: sql_base.h:503
@ OT_DISCOVER
Definition: sql_base.h:501
@ OT_BACKOFF_AND_RETRY
Definition: sql_base.h:499
@ OT_REOPEN_TABLES
Definition: sql_base.h:500
@ OT_NO_ACTION
Definition: sql_base.h:498
@ OT_REPAIR
Definition: sql_base.h:502
ulong get_timeout() const
Definition: sql_base.h:523
uint get_flags() const
Definition: sql_base.h:525
bool has_protection_against_grl() const
Definition: sql_base.h:533
ulong m_timeout
Lock timeout in seconds.
Definition: sql_base.h:553
THD * m_thd
Definition: sql_base.h:541
bool m_has_locks
Whether we had any locks when this context was created.
Definition: sql_base.h:563
bool can_back_off() const
Definition: sql_base.h:537
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:519
bool can_recover_from_failed_open() const
Definition: sql_base.h:511
MDL_savepoint m_start_of_statement_svp
Definition: sql_base.h:548
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:568
Storage for backup of Open_tables_state.
Definition: sql_class.h:693
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:390
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:1159
Definition: sql_lex.h:2618
Structure that represents element in the set of stored routines used by statement or routine.
Definition: sp.h:225
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:2900
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:288
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:383
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: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:3623
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:9618
void free_io_cache(TABLE *entry)
Definition: sql_base.cc:1209
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:4180
void assign_new_table_id(TABLE_SHARE *share)
Definition: sql_base.cc:3718
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:2304
void release_table_share(TABLE_SHARE *share)
Mark that we are not using table share anymore.
Definition: sql_base.cc:1053
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:414
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:7908
bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db, const char *table_name)
Definition: sql_base.cc:2505
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:7829
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:1087
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:6567
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:9399
bool mysql_rm_tmp_tables(void)
Drop all temporary tables which have been left from previous server run.
Definition: sql_base.cc:10204
TABLE * open_log_table(THD *thd, Table_ref *one_table, Open_tables_backup *backup)
Open a log table.
Definition: sql_base.cc:10598
void close_temporary(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2475
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:1627
malloc_unordered_map< std::string, std::unique_ptr< TABLE_SHARE, Table_share_deleter > > * table_def_cache
Definition: sql_base.cc:336
bool check_record(THD *thd, Field **ptr)
Check the NOT NULL constraint on all the fields of the current record.
Definition: sql_base.cc:9723
bool rm_temporary_table(THD *thd, handlerton *base, const char *path, const dd::Table *table_def)
Delete a temporary table.
Definition: sql_base.cc:7501
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:5784
bool init_ftfuncs(THD *thd, Query_block *select)
Definition: sql_base.cc:10432
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:746
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:8234
OPEN_TABLE_LIST * list_open_tables(THD *thd, const char *db, const char *wild)
Definition: sql_base.cc:1114
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:2348
TABLE * open_ltable(THD *thd, Table_ref *table_list, thr_lock_type update, uint lock_flags)
Definition: sql_base.cc:6617
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:444
void close_temporary_table(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2436
void operator()(TABLE_SHARE *share) const
Definition: sql_base.cc:465
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:6309
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:8042
bool setup_natural_join_row_types(THD *thd, mem_root_deque< Table_ref * > *from_clause, Name_resolution_context *context)
Definition: sql_base.cc:8959
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:2275
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:1558
void table_def_free(void)
Definition: sql_base.cc:517
Open_table_context(THD *thd, uint flags)
Open_table_context.
Definition: sql_base.cc:4160
void close_log_table(THD *thd, Open_tables_backup *backup)
Close a log table.
Definition: sql_base.cc:10629
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:10332
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:9899
void close_mysql_tables(THD *thd)
A helper function to close a mysql.
Definition: sql_base.cc:10580
void close_trans_system_tables(THD *thd)
Close transactional system tables, opened with open_trans_system_tables_for_read().
Definition: sql_base.cc:10555
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:7557
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:6411
mysql_mutex_t LOCK_open
LOCK_open protects the following variables/objects:
Definition: sql_base.cc:275
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:9080
bool close_temporary_tables(THD *thd)
Definition: sql_base.cc:1867
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:7266
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:8085
void tdc_flush_unused_tables()
Definition: sql_base.cc:10284
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:6374
bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh, ulong timeout)
Definition: sql_base.cc:1237
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:6433
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:7376
bool open_temporary_tables(THD *thd, Table_ref *tl_list)
Pre-open temporary tables corresponding to table list elements.
Definition: sql_base.cc:7649
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:6948
uint cached_table_definitions(void)
Definition: sql_base.cc:529
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:501
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:10489
void drop_temporary_table(THD *thd, Table_ref *table_list)
Drop a temporary table.
Definition: sql_base.cc:2412
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:6710
bool resolve_var_assignments(THD *thd, LEX *lex)
Resolve variable assignments from LEX object.
Definition: sql_base.cc:9036
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:2539
void close_thread_table(THD *thd, TABLE **table_ptr)
Definition: sql_base.cc:1807
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:2147
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:6260
bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags)
Lock all tables in a list.
Definition: sql_base.cc:7043
int setup_ftfuncs(const THD *thd, Query_block *select)
Definition: sql_base.cc:10408
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:4456
bool table_def_init(void)
Definition: sql_base.cc:476
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:3656
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:7320
bool recover_from_failed_open()
Recover from failed attempt of open table by performing requested action.
Definition: sql_base.cc:4294
bool invoke_table_check_constraints(THD *thd, const TABLE *table)
Invoke check constraints defined on the table.
Definition: sql_base.cc:9764
bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx)
Open a base table.
Definition: sql_base.cc:2882
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:5387
void mark_tmp_table_for_reuse(TABLE *table)
Reset a single temporary table.
Definition: sql_base.cc:1419
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:6458
int run_before_dml_hook(THD *thd)
Run the server hook called "before_dml".
Definition: sql_base.cc:5314
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:5516
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:5891
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:6446
void intern_close_table(TABLE *entry)
Definition: sql_base.cc:1189
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
ABI for instrumented mutexes.
static char * path
Definition: mysqldump.cc:149
uint counter
Definition: mysqlimport.cc:58
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
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
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:2880
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:100
@ FIELD_NOT_FOUND
Definition: sql_base.h:100
@ VIEW_FIELD_FOUND
Definition: sql_base.h:100
@ BASE_FIELD_FOUND
Definition: sql_base.h:100
constexpr int REPORT_ALL_ERRORS
Definition: sql_base.h:97
constexpr int REPORT_NO_ERRORS
Definition: sql_base.h:93
constexpr int REPORT_NON_UNIQUE
Definition: sql_base.h:94
Bounds_checked_array< Item * > Ref_item_array
Definition: sql_base.h:72
enum_tdc_remove_table_type
Definition: sql_base.h:102
@ TDC_RT_REMOVE_UNUSED
Definition: sql_base.h:105
@ TDC_RT_REMOVE_NOT_OWN
Definition: sql_base.h:104
@ TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE
Definition: sql_base.h:106
@ TDC_RT_REMOVE_ALL
Definition: sql_base.h:103
@ TDC_RT_MARK_FOR_REOPEN
Definition: sql_base.h:107
constexpr int REPORT_BAD_FIELD
Definition: sql_base.h:96
constexpr int REPORT_UNKNOWN_TABLE
Definition: sql_base.h:95
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:3844
Definition: my_bitmap.h:43
Instances of Name_resolution_context store the information necessary for name resolution of Items and...
Definition: item.h:415
Definition: table.h:4225
This structure is shared between different table objects.
Definition: table.h:704
Definition: table.h:1421
Definition: sql_base.h:374
Definition: completion_hash.h:35
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2740
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