MySQL 8.4.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/locked_tables_list.h" // enum_locked_tables_mode
40#include "sql/mdl.h" // MDL_savepoint
41#include "sql/sql_array.h" // Bounds_checked_array
42#include "sql/sql_const.h" // enum_resolution_type
43#include "sql/trigger_def.h" // enum_trigger_event_type
44#include "thr_lock.h" // thr_lock_type
45
46class COPY_INFO;
47class Field;
48class Item;
49class Item_ident;
54class Query_block;
56class THD;
57class sp_head;
58struct LEX;
59struct MY_BITMAP;
61struct OPEN_TABLE_LIST;
62struct TABLE;
63class Table_ref;
64struct TABLE_SHARE;
65struct handlerton;
66template <class T>
67class List;
68template <class T>
69class List_iterator;
70template <class T>
71class Mem_root_array;
72
74namespace dd {
75class Table;
76} // namespace dd
77
78#define TEMP_PREFIX "MY"
79
80/* Defines for use with openfrm, openprt and openfrd */
81
82#define READ_ALL 1 /* openfrm: Read all parameters */
83#define EXTRA_RECORD 8 /* Reservera plats f|r extra record */
84#define DELAYED_OPEN 4096 /* Open table later */
85/**
86 If set, open_table_from_share() will skip calling get_new_handler() to
87 create a new handler object for the table. Designed to be used when
88 opening a table from inside storage engines.
89*/
90#define SKIP_NEW_HANDLER 32768
91
98};
99
107
109bool table_def_init(void);
110void table_def_free(void);
111void table_def_start_shutdown(void);
113uint cached_table_definitions(void);
114size_t get_table_def_key(const Table_ref *table_list, const char **key);
115TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name,
116 const char *key, size_t key_length, bool open_view,
117 bool open_secondary = false);
119
121 uint lock_flags);
122
123/* mysql_lock_tables() and open_table() flags bits */
124#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001
125#define MYSQL_OPEN_IGNORE_FLUSH 0x0002
126/* MYSQL_OPEN_TEMPORARY_ONLY (0x0004) is not used anymore. */
127#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
128#define MYSQL_LOCK_LOG_TABLE 0x0010
129/**
130 Do not try to acquire a metadata lock on the table: we
131 already have one.
132*/
133#define MYSQL_OPEN_HAS_MDL_LOCK 0x0020
134/**
135 If in locked tables mode, ignore the locked tables and get
136 a new instance of the table.
137*/
138#define MYSQL_OPEN_GET_NEW_TABLE 0x0040
139/* 0x0080 used to be MYSQL_OPEN_SKIP_TEMPORARY */
140/** Fail instead of waiting when conficting metadata lock is discovered. */
141#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0100
142/** Open tables using MDL_SHARED lock instead of one specified in parser. */
143#define MYSQL_OPEN_FORCE_SHARED_MDL 0x0200
144/**
145 Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified
146 in parser.
147*/
148#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0400
149/**
150 When opening or locking the table, use the maximum timeout
151 (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value.
152*/
153#define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800
154/**
155 When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to
156 be open do not acquire global, tablespace-scope and schema-scope IX locks.
157*/
158#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000
159/**
160 When opening or locking a replication table through an internal
161 operation rather than explicitly through an user thread.
162*/
163#define MYSQL_LOCK_RPL_INFO_TABLE 0x2000
164/**
165 Only check THD::killed if waits happen (e.g. wait on MDL, wait on
166 table flush, wait on thr_lock.c locks) while opening and locking table.
167*/
168#define MYSQL_OPEN_IGNORE_KILLED 0x4000
169/**
170 For new TABLE instances constructed do not open table in the storage
171 engine. Existing TABLE instances for which there is a handler object
172 which represents table open in storage engines can still be used.
173*/
174#define MYSQL_OPEN_NO_NEW_TABLE_IN_SE 0x8000
175/** Open a shadow copy of a table from a secondary storage engine. */
176#define MYSQL_OPEN_SECONDARY_ENGINE 0x10000
177
178/** Please refer to the internals manual. */
179#define MYSQL_OPEN_REOPEN \
180 (MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | \
181 MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_LOCK_IGNORE_TIMEOUT | \
182 MYSQL_OPEN_IGNORE_KILLED | MYSQL_OPEN_GET_NEW_TABLE | \
183 MYSQL_OPEN_HAS_MDL_LOCK)
184
185bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx);
186
187TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
188 const char *table_name,
189 bool add_to_temporary_tables_list,
190 bool open_in_engine, const dd::Table &table_def);
191TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
193 Query_tables_list *prelocking_ctx,
194 Table_ref *table_list,
195 bool routine_modifies_data);
196
197bool mysql_rm_tmp_tables(void);
198bool rm_temporary_table(THD *thd, handlerton *base, const char *path,
199 const dd::Table *table_def);
200void close_tables_for_reopen(THD *thd, Table_ref **tables,
201 const MDL_savepoint &start_of_statement_svp);
202TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
203TABLE *find_temporary_table(THD *thd, const Table_ref *tl);
204void close_thread_tables(THD *thd);
206 THD *thd, COPY_INFO *optype_info, const mem_root_deque<Item *> &fields,
207 const mem_root_deque<Item *> &values, TABLE *table,
208 enum enum_trigger_event_type event, int num_fields,
209 bool raise_autoinc_has_expl_non_null_val, bool *is_row_changed);
211 const mem_root_deque<Item *> &values,
212 TABLE *table,
214 int num_fields);
215bool resolve_var_assignments(THD *thd, LEX *lex);
216bool insert_fields(THD *thd, Query_block *query_block, const char *db_name,
217 const char *table_name, mem_root_deque<Item *> *fields,
218 mem_root_deque<Item *>::iterator *it, bool any_privileges);
219bool setup_fields(THD *thd, ulong want_privilege, bool allow_sum_func,
220 bool split_sum_funcs, bool column_update,
221 const mem_root_deque<Item *> *typed_items,
223 Ref_item_array ref_item_array);
224bool fill_record(THD *thd, TABLE *table, const mem_root_deque<Item *> &fields,
225 const mem_root_deque<Item *> &values, MY_BITMAP *bitmap,
226 MY_BITMAP *insert_into_fields_bitmap,
227 bool raise_autoinc_has_expl_non_null_val);
228bool fill_record(THD *thd, TABLE *table, Field **field,
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);
232
233bool check_record(THD *thd, Field **ptr);
234
235/**
236 Invoke check constraints defined on the table.
237
238 @param thd Thread handle.
239 @param table Instance of TABLE.
240
241 @retval false If all enforced check constraints are satisfied.
242 @retval true Otherwise. THD::is_error() may be "true" in this case.
243*/
245
246Field *find_field_in_tables(THD *thd, Item_ident *item, Table_ref *first_table,
247 Table_ref *last_table, Item **ref,
249 ulong want_privilege, bool register_tree_change);
250Field *find_field_in_table_ref(THD *thd, Table_ref *table_list,
251 const char *name, size_t length,
252 const char *item_name, const char *db_name,
253 const char *table_name, Item **ref,
254 ulong want_privilege, bool allow_rowid,
255 uint *cached_field_index_ptr,
256 bool register_tree_change,
257 Table_ref **actual_table);
258Field *find_field_in_table(TABLE *table, const char *name, bool allow_rowid,
259 uint *cached_field_index_ptr);
261bool find_item_in_list(THD *thd, Item *item, mem_root_deque<Item *> *items,
262 Item ***found, uint *counter,
263 enum_resolution_type *resolution);
265 mem_root_deque<Table_ref *> *from_clause,
266 Name_resolution_context *context);
268 enum ha_extra_function function);
269
270void update_non_unique_table_error(Table_ref *update, const char *operation,
271 Table_ref *duplicate);
272int setup_ftfuncs(const THD *thd, Query_block *select);
273bool init_ftfuncs(THD *thd, Query_block *select);
274int run_before_dml_hook(THD *thd);
275bool get_and_lock_tablespace_names(THD *thd, Table_ref *tables_start,
276 Table_ref *tables_end,
277 ulong lock_wait_timeout, uint flags);
279 THD *thd, Table_ref *table_list, Table_ref *table_list_end,
280 ulong lock_wait_timeout, uint flags,
281 Prealloced_array<MDL_request *, 1> *schema_reqs = nullptr);
282bool open_tables(THD *thd, Table_ref **tables, uint *counter, uint flags,
283 Prelocking_strategy *prelocking_strategy);
284/* open_and_lock_tables */
285bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags,
286 Prelocking_strategy *prelocking_strategy);
287/* simple open_and_lock_tables for single table */
289 thr_lock_type lock_type, uint flags,
290 Prelocking_strategy *prelocking_strategy);
291bool open_tables_for_query(THD *thd, Table_ref *tables, uint flags);
292bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags);
293bool lock_dictionary_tables(THD *thd, Table_ref *tables, uint count,
294 uint flags);
297void close_thread_table(THD *thd, TABLE **table_ptr);
298bool close_temporary_tables(THD *thd);
299Table_ref *unique_table(const Table_ref *table, Table_ref *table_list,
300 bool check_alias);
301void drop_temporary_table(THD *thd, Table_ref *table_list);
303 bool delete_table);
304void close_temporary(THD *thd, TABLE *table, bool free_share,
305 bool delete_table);
306bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db,
307 const char *table_name);
308bool open_temporary_tables(THD *thd, Table_ref *tl_list);
309bool open_temporary_table(THD *thd, Table_ref *tl);
310
311/* Functions to work with system tables. */
312bool open_trans_system_tables_for_read(THD *thd, Table_ref *table_list);
314void close_mysql_tables(THD *thd);
315TABLE *open_log_table(THD *thd, Table_ref *one_table,
318
319bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh,
320 ulong timeout);
321
322/**
323 Close all open instances of the table but keep the MDL lock.
324
325 Works both under LOCK TABLES and in the normal mode.
326 Removes all closed instances of the table from the table cache.
327
328 @param thd Thread context.
329 @param share Table share, but is just a handy way to
330 access the table cache key.
331 @param remove_from_locked_tables
332 True if the table is being dropped.
333 In that case the documented behaviour is to
334 implicitly remove the table from LOCK TABLES list.
335 @param skip_table TABLE instance that should be kept open.
336
337 @pre Must be called with an X MDL lock on the table.
338*/
340 bool remove_from_locked_tables,
341 TABLE *skip_table);
342
343/**
344 Close all open instances of the table but keep the MDL lock.
345
346 Works both under LOCK TABLES and in the normal mode.
347 Removes all closed instances of the table from the table cache.
348
349 @param thd Thread context.
350 @param db Database name.
351 @param table_name Table name.
352 @param remove_from_locked_tables
353 True if the table is being dropped.
354 In that case the documented behaviour is to
355 implicitly remove the table from LOCK TABLES list.
356
357 @pre Must be called with an X MDL lock on the table.
358*/
359void close_all_tables_for_name(THD *thd, const char *db, const char *table_name,
360 bool remove_from_locked_tables);
361
362OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
363void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
364 const char *db, const char *table_name, bool has_lock);
366TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
367 const char *table_name, bool no_error);
369
370extern Field *not_found_field;
371extern Field *view_ref_found;
372
374 void operator()(TABLE_SHARE *share) const;
375};
376extern malloc_unordered_map<std::string,
377 std::unique_ptr<TABLE_SHARE, Table_share_deleter>>
379
381 const char *table_name);
382
383/**
384 An abstract class for a strategy specifying how the prelocking
385 algorithm should extend the prelocking set while processing
386 already existing elements in the set.
387*/
388
390 public:
391 virtual ~Prelocking_strategy() = default;
392
393 virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
395 bool *need_prelocking) = 0;
396 virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
397 Table_ref *table_list, bool *need_prelocking) = 0;
398 virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
399 Table_ref *table_list, bool *need_prelocking) = 0;
400};
401
402/**
403 A Strategy for prelocking algorithm suitable for DML statements.
404
405 Ensures that all tables used by all statement's SF/SP/triggers and
406 required for foreign key checks are prelocked and SF/SPs used are
407 cached.
408*/
409
411 public:
412 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
414 bool *need_prelocking) override;
415 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
416 Table_ref *table_list, bool *need_prelocking) override;
417 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
418 Table_ref *table_list, bool *need_prelocking) override;
419};
420
421/**
422 A strategy for prelocking algorithm to be used for LOCK TABLES
423 statement.
424*/
425
427 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
428 Table_ref *table_list, bool *need_prelocking) override;
429};
430
431/**
432 Strategy for prelocking algorithm to be used for ALTER TABLE statements.
433
434 Unlike DML or LOCK TABLES strategy, it doesn't
435 prelock triggers, views or stored routines, since they are not
436 used during ALTER.
437*/
438
440 public:
441 bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
443 bool *need_prelocking) override;
444 bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
445 Table_ref *table_list, bool *need_prelocking) override;
446 bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
447 Table_ref *table_list, bool *need_prelocking) override;
448};
449
450inline bool open_tables(THD *thd, Table_ref **tables, uint *counter,
451 uint flags) {
452 DML_prelocking_strategy prelocking_strategy;
453
454 return open_tables(thd, tables, counter, flags, &prelocking_strategy);
455}
456
458 thr_lock_type lock_type, uint flags) {
459 DML_prelocking_strategy prelocking_strategy;
460
461 return open_n_lock_single_table(thd, table_l, lock_type, flags,
462 &prelocking_strategy);
463}
464
465// open_and_lock_tables with default prelocking strategy
466inline bool open_and_lock_tables(THD *thd, Table_ref *tables, uint flags) {
467 DML_prelocking_strategy prelocking_strategy;
468
469 return open_and_lock_tables(thd, tables, flags, &prelocking_strategy);
470}
471
472/**
473 Get an existing table definition from the table definition cache.
474
475 Search the table definition cache for a share with the given key.
476 If the share exists or if it is in the process of being opened
477 by another thread (m_open_in_progress flag is true) return share.
478 Do not wait for share opening to finish.
479
480 @param db database name.
481 @param table_name table name.
482
483 @retval nulltpr a share for the table does not exist in the cache
484 @retval != nulltpr pointer to existing share in the cache
485*/
486
487TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
488
489/**
490 A context of open_tables() function, used to recover
491 from a failed open_table() or open_routine() attempt.
492*/
493
495 public:
503 };
504 Open_table_context(THD *thd, uint flags);
505
509
511
512 /**
513 When doing a back-off, we close all tables acquired by this
514 statement. Return an MDL savepoint taken at the beginning of
515 the statement, so that we can rollback to it before waiting on
516 locks.
517 */
520 }
521
522 inline ulong get_timeout() const { return m_timeout; }
523
524 uint get_flags() const { return m_flags; }
525
526 /**
527 Set flag indicating that we have already acquired metadata lock
528 protecting this statement against GRL while opening tables.
529 */
531
534 }
535
536 bool can_back_off() const { return !m_has_locks; }
537
538 private:
539 /* THD for which tables are opened. */
541 /**
542 For OT_DISCOVER, OT_REPAIR and OT_FIX_ROW_TYPE actions, the table list
543 element for the table which definition should be re-discovered/updated
544 or which should be repaired.
545 */
548 /**
549 Lock timeout in seconds. Initialized to LONG_TIMEOUT when opening system
550 tables or to the "lock_wait_timeout" system variable for regular tables.
551 */
553 /* open_table() flags. */
555 /** Back off action. */
557 /**
558 Whether we had any locks when this context was created.
559 If we did, they are from the previous statement of a transaction,
560 and we can't safely do back-off (and release them).
561 */
563 /**
564 Indicates that in the process of opening tables we have acquired
565 protection against global read lock.
566 */
568};
569
570/**
571 Check if given Table_ref is a acl table and is being read and not
572 in LOCK TABLE mode.
573
574 @param tl Table_ref pointing to the table.
575 @param ltm THD->locked_tables_mode enum.
576
577 @return true if acl table is being read, otherwise false.
578*/
580 enum enum_locked_tables_mode ltm);
581
582/**
583 Create a table cache/table definition cache key for a table in a
584 secondary storage engine.
585
586 The key is constructed by appending a single byte with the value 1
587 to the key generated by #create_table_def_key().
588
589 @param db_name the database name
590 @param table_name the table name
591 @return the key
592*/
593std::string create_table_def_key_secondary(const char *db_name,
594 const char *table_name);
595#endif /* SQL_BASE_INCLUDED */
Strategy for prelocking algorithm to be used for ALTER TABLE statements.
Definition: sql_base.h:439
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:410
Definition: field.h:575
Definition: item.h:4077
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:934
Definition: sql_list.h:606
Definition: sql_list.h:467
A strategy for prelocking algorithm to be used for LOCK TABLES statement.
Definition: sql_base.h:426
Savepoint for MDL context.
Definition: mdl.h:1317
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:494
uint m_flags
Definition: sql_base.h:554
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:546
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:530
enum enum_open_table_action m_action
Back off action.
Definition: sql_base.h:556
enum_open_table_action
Definition: sql_base.h:496
@ OT_FIX_ROW_TYPE
Definition: sql_base.h:502
@ OT_DISCOVER
Definition: sql_base.h:500
@ OT_BACKOFF_AND_RETRY
Definition: sql_base.h:498
@ OT_REOPEN_TABLES
Definition: sql_base.h:499
@ OT_NO_ACTION
Definition: sql_base.h:497
@ OT_REPAIR
Definition: sql_base.h:501
ulong get_timeout() const
Definition: sql_base.h:522
uint get_flags() const
Definition: sql_base.h:524
bool has_protection_against_grl() const
Definition: sql_base.h:532
ulong m_timeout
Lock timeout in seconds.
Definition: sql_base.h:552
THD * m_thd
Definition: sql_base.h:540
bool m_has_locks
Whether we had any locks when this context was created.
Definition: sql_base.h:562
bool can_back_off() const
Definition: sql_base.h:536
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:518
bool can_recover_from_failed_open() const
Definition: sql_base.h:510
MDL_savepoint m_start_of_statement_svp
Definition: sql_base.h:547
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:567
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:389
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:1163
Definition: sql_lex.h:2596
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:2863
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:248
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:9695
void free_io_cache(TABLE *entry)
Definition: sql_base.cc:1211
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:4167
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:2306
void release_table_share(TABLE_SHARE *share)
Mark that we are not using table share anymore.
Definition: sql_base.cc:1055
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:416
bool rename_temporary_table(THD *thd, TABLE *table, const char *new_db, const char *table_name)
Definition: sql_base.cc:2507
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:1089
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:6539
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:9476
bool mysql_rm_tmp_tables(void)
Drop all temporary tables which have been left from previous server run.
Definition: sql_base.cc:10281
TABLE * open_log_table(THD *thd, Table_ref *one_table, Open_tables_backup *backup)
Open a log table.
Definition: sql_base.cc:10675
void close_temporary(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2477
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:1629
malloc_unordered_map< std::string, std::unique_ptr< TABLE_SHARE, Table_share_deleter > > * table_def_cache
Definition: sql_base.cc:337
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:8100
bool check_record(THD *thd, Field **ptr)
Check the NOT NULL constraint on all the fields of the current record.
Definition: sql_base.cc:9800
bool rm_temporary_table(THD *thd, handlerton *base, const char *path, const dd::Table *table_def)
Delete a temporary table.
Definition: sql_base.cc:7462
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:5766
bool init_ftfuncs(THD *thd, Query_block *select)
Definition: sql_base.cc:10509
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:748
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:9159
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:8298
OPEN_TABLE_LIST * list_open_tables(THD *thd, const char *db, const char *wild)
Definition: sql_base.cc:1116
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:2350
TABLE * open_ltable(THD *thd, Table_ref *table_list, thr_lock_type update, uint lock_flags)
Definition: sql_base.cc:6589
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:446
void close_temporary_table(THD *thd, TABLE *table, bool free_share, bool delete_table)
Definition: sql_base.cc:2438
void operator()(TABLE_SHARE *share) const
Definition: sql_base.cc:467
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:6281
bool setup_natural_join_row_types(THD *thd, mem_root_deque< Table_ref * > *from_clause, Name_resolution_context *context)
Definition: sql_base.cc:9038
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:2277
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:1560
void table_def_free(void)
Definition: sql_base.cc:519
Open_table_context(THD *thd, uint flags)
Open_table_context.
Definition: sql_base.cc:4147
void close_log_table(THD *thd, Open_tables_backup *backup)
Close a log table.
Definition: sql_base.cc:10706
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:7915
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:10409
Field * not_found_field
Definition: sql_base.cc:7494
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:9976
void close_mysql_tables(THD *thd)
A helper function to close a mysql.
Definition: sql_base.cc:10657
void close_trans_system_tables(THD *thd)
Close transactional system tables, opened with open_trans_system_tables_for_read().
Definition: sql_base.cc:10632
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:7524
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:6383
mysql_mutex_t LOCK_open
LOCK_open protects the following variables/objects:
Definition: sql_base.cc:276
bool close_temporary_tables(THD *thd)
Definition: sql_base.cc:1869
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:7227
void tdc_flush_unused_tables()
Definition: sql_base.cc:10361
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:7839
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:6346
bool close_cached_tables(THD *thd, Table_ref *tables, bool wait_for_refresh, ulong timeout)
Definition: sql_base.cc:1239
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:6405
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:7337
bool open_temporary_tables(THD *thd, Table_ref *tl_list)
Pre-open temporary tables corresponding to table list elements.
Definition: sql_base.cc:7616
Field * view_ref_found
Definition: sql_base.cc:7495
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:6909
uint cached_table_definitions(void)
Definition: sql_base.cc:531
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:503
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:10566
void drop_temporary_table(THD *thd, Table_ref *table_list)
Drop a temporary table.
Definition: sql_base.cc:2414
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:6682
bool resolve_var_assignments(THD *thd, LEX *lex)
Resolve variable assignments from LEX object.
Definition: sql_base.cc:9115
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:2541
void close_thread_table(THD *thd, TABLE **table_ptr)
Definition: sql_base.cc:1809
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:2149
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:6232
bool lock_tables(THD *thd, Table_ref *tables, uint counter, uint flags)
Lock all tables in a list.
Definition: sql_base.cc:7004
int setup_ftfuncs(const THD *thd, Query_block *select)
Definition: sql_base.cc:10485
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:4443
bool table_def_init(void)
Definition: sql_base.cc:478
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:7281
bool recover_from_failed_open()
Recover from failed attempt of open table by performing requested action.
Definition: sql_base.cc:4281
bool invoke_table_check_constraints(THD *thd, const TABLE *table)
Invoke check constraints defined on the table.
Definition: sql_base.cc:9841
bool open_table(THD *thd, Table_ref *table_list, Open_table_context *ot_ctx)
Open a base table.
Definition: sql_base.cc:2884
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:5369
void mark_tmp_table_for_reuse(TABLE *table)
Reset a single temporary table.
Definition: sql_base.cc:1421
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:6430
int run_before_dml_hook(THD *thd)
Run the server hook called "before_dml".
Definition: sql_base.cc:5296
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:5498
Field * find_field_in_table_sef(TABLE *table, const char *name)
Definition: sql_base.cc:8051
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:5873
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:6418
void intern_close_table(TABLE *entry)
Definition: sql_base.cc:1191
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
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
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:2878
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required string event
Definition: replication_group_member_actions.proto:32
Bounds_checked_array< Item * > Ref_item_array
Definition: sql_base.h:71
find_item_error_report_type
Definition: sql_base.h:92
@ REPORT_EXCEPT_NOT_FOUND
Definition: sql_base.h:94
@ IGNORE_EXCEPT_NON_UNIQUE
Definition: sql_base.h:97
@ IGNORE_ERRORS
Definition: sql_base.h:95
@ REPORT_ALL_ERRORS
Definition: sql_base.h:93
@ REPORT_EXCEPT_NON_UNIQUE
Definition: sql_base.h:96
enum_tdc_remove_table_type
Definition: sql_base.h:100
@ TDC_RT_REMOVE_UNUSED
Definition: sql_base.h:103
@ TDC_RT_REMOVE_NOT_OWN
Definition: sql_base.h:102
@ TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE
Definition: sql_base.h:104
@ TDC_RT_REMOVE_ALL
Definition: sql_base.h:101
@ TDC_RT_MARK_FOR_REOPEN
Definition: sql_base.h:105
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:279
case opt name
Definition: sslopt-case.h:29
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3822
Definition: my_bitmap.h:43
Definition: item.h:401
Definition: table.h:4166
This structure is shared between different table objects.
Definition: table.h:700
Definition: table.h:1405
Definition: sql_base.h:373
Definition: completion_hash.h:35
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2733
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
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