MySQL 8.3.0
Source Code Documentation
table.h
Go to the documentation of this file.
1#ifndef TABLE_INCLUDED
2#define TABLE_INCLUDED
3
4/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26#include <assert.h>
27#include <string.h>
28#include <sys/types.h>
29#include <string>
30
31#include "field_types.h"
32#include "lex_string.h"
33#include "map_helpers.h"
34#include "mem_root_deque.h"
35#include "my_alloc.h"
36#include "my_base.h"
37#include "my_bitmap.h"
38#include "my_compiler.h"
39#include "mysql/binlog/event/table_id.h" // Table_id
40
41#include "my_inttypes.h"
42#include "my_sys.h"
43#include "my_table_map.h"
47#include "sql/dd/types/foreign_key.h" // dd::Foreign_key::enum_rule
48#include "sql/enum_query_type.h" // enum_query_type
49#include "sql/key.h"
50#include "sql/key_spec.h"
51#include "sql/mdl.h" // MDL_wait_for_subgraph
52#include "sql/mem_root_array.h"
53#include "sql/mysqld_cs.h"
54#include "sql/opt_costmodel.h" // Cost_model_table
55#include "sql/partition_info.h"
56#include "sql/record_buffer.h" // Record_buffer
57#include "sql/sql_bitmap.h" // Bitmap
58#include "sql/sql_const.h"
59#include "sql/sql_list.h"
60#include "sql/sql_plist.h"
61#include "sql/sql_plugin_ref.h"
62#include "sql/sql_sort.h" // Sort_result
63#include "thr_lock.h"
64#include "typelib.h"
65
66class Field;
67class Field_longlong;
68
69namespace histograms {
70class Histogram;
71} // namespace histograms
72
75class COND_EQUAL;
76class Field_json;
77/* Structs that defines the TABLE */
78class File_parser;
79class Value_generator;
80class GRANT_TABLE;
81class Handler_share;
82class Index_hint;
83class Item;
84class Item_field;
87class Json_wrapper;
88class Opt_hints_qb;
89class Opt_hints_table;
91class Query_block;
94class SortingIterator;
95class String;
96class THD;
100class Table_ref;
102class Temp_table_param;
103class handler;
104class partition_info;
105enum enum_stats_auto_recalc : int;
106enum Value_generator_source : short;
107enum row_type : int;
108struct AccessPath;
109struct HA_CREATE_INFO;
110struct LEX;
111struct NESTED_JOIN;
113struct TABLE;
114struct TABLE_SHARE;
115struct handlerton;
117using plan_idx = int;
118
119namespace dd {
120class Table;
121class View;
122
123enum class enum_table_type;
124} // namespace dd
126
130
134
136
138
139enum class enum_json_diff_operation;
140
142
144
146
147#define store_record(A, B) \
148 memcpy((A)->B, (A)->record[0], (size_t)(A)->s->reclength)
149#define restore_record(A, B) \
150 memcpy((A)->record[0], (A)->B, (size_t)(A)->s->reclength)
151#define cmp_record(A, B) \
152 memcmp((A)->record[0], (A)->B, (size_t)(A)->s->reclength)
153
154#define tmp_file_prefix "#sql" /**< Prefix for tmp tables */
155#define tmp_file_prefix_length 4
156#define TMP_TABLE_KEY_EXTRA 8
157#define PLACEHOLDER_TABLE_ROW_ESTIMATE 2
158
159/**
160 Enumerate possible types of a table from re-execution
161 standpoint.
162 Table_ref class has a member of this type.
163 At prepared statement prepare, this member is assigned a value
164 as of the current state of the database. Before (re-)execution
165 of a prepared statement, we check that the value recorded at
166 prepare matches the type of the object we obtained from the
167 table definition cache.
168
169 @sa check_and_update_table_version()
170 @sa Execute_observer
171 @sa Prepared_statement::reprepare()
172*/
173
175 /** Initial value set by the parser */
182
183/**
184 Enumerate possible status of a identifier name while determining
185 its validity
186*/
188
189/*************************************************************************/
190
191/**
192 Object_creation_ctx -- interface for creation context of database objects
193 (views, stored routines, events, triggers). Creation context -- is a set
194 of attributes, that should be fixed at the creation time and then be used
195 each time the object is parsed or executed.
196*/
197
199 public:
201
202 void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
203
204 protected:
206 virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
207 virtual void delete_backup_ctx() = 0;
208
209 virtual void change_env(THD *thd) const = 0;
210
211 public:
212 virtual ~Object_creation_ctx() = default;
213};
214
215/*************************************************************************/
216
217/**
218 Default_object_creation_ctx -- default implementation of
219 Object_creation_ctx.
220*/
221
223 public:
225
227
228 protected:
230
232 const CHARSET_INFO *connection_cl);
233
234 protected:
235 Object_creation_ctx *create_backup_ctx(THD *thd) const override;
236 void delete_backup_ctx() override;
237
238 void change_env(THD *thd) const override;
239
240 protected:
241 /**
242 client_cs stores the value of character_set_client session variable.
243 The only character set attribute is used.
244
245 Client character set is included into query context, because we save
246 query in the original character set, which is client character set. So,
247 in order to parse the query properly we have to switch client character
248 set on parsing.
249 */
251
252 /**
253 connection_cl stores the value of collation_connection session
254 variable. Both character set and collation attributes are used.
255
256 Connection collation is included into query context, because it defines
257 the character set and collation of text literals in internal
258 representation of query (item-objects).
259 */
261};
262
263/**
264 View_creation_ctx -- creation context of view objects.
265*/
266
268 public:
269 static View_creation_ctx *create(THD *thd);
270
271 static View_creation_ctx *create(THD *thd, Table_ref *view);
272
273 private:
275};
276
277/*************************************************************************/
278
279/** Order clause list element */
280
282
283struct ORDER {
284 /// @returns true if item pointer is same as original
285 bool is_item_original() const { return item[0] == item_initial; }
286
287 ORDER *next{nullptr};
288
289 /**
290 If the query block includes non-primitive grouping, then these modifiers are
291 represented as grouping sets. The variable 'grouping_set_info' functions as
292 a bitvector, containing the grouping set details. If the 'ith' bit of the
293 variable is set, then the corresponding element is included in the 'ith'
294 grouping set. */
296 /**
297 The initial ordering expression. Usually substituted during resolving
298 and must not be used during optimization and execution.
299 */
300 Item *item_initial{nullptr}; /* Storage for initial item */
301
302 public:
303 /**
304 Points at the item in the select fields. Note that this means that
305 after resolving, it points into a slice (see JOIN::ref_items),
306 even though the item is not of type Item_ref!
307 */
309
311
313 ORDER_NOT_RELEVANT}; /* Requested direction of ordering */
314 bool in_field_list{false}; /* true if in select field list */
315 /**
316 Tells whether this ORDER element was referenced with an alias or with an
317 expression in the query, and what the alias was:
318 SELECT a AS foo GROUP BY foo: "foo".
319 SELECT a AS foo GROUP BY a: nullptr.
320 */
321 const char *used_alias{nullptr};
322 /**
323 When GROUP BY is implemented with a temporary table (i.e. the table takes
324 care to store only unique group rows, table->group != nullptr), each GROUP
325 BY expression is stored in a column of the table, which is
326 'field_in_tmp_table'.
327 Such field may point into table->record[0] (if we only use it to get its
328 value from a tmp table's row), or into 'buff' (if we use it to do index
329 lookup into the tmp table).
330 */
332 char *buff{nullptr}; /* If tmp-table group */
334 bool is_explicit{false}; /* Whether ASC/DESC is explicitly specified */
335};
336
337/**
338 State information for internal tables grants.
339 This structure is part of the Table_ref, and is updated
340 during the ACL check process.
341 @sa GRANT_INFO
342*/
344 /** True if the internal lookup by schema name was done. */
346 /** Cached internal schema access. */
348 /** True if the internal lookup by table name was done. */
350 /** Cached internal table access. */
352};
353
354/**
355 @brief The current state of the privilege checking process for the current
356 user, SQL statement and SQL object.
357
358 @details The privilege checking process is divided into phases depending on
359 the level of the privilege to be checked and the type of object to be
360 accessed. Due to the mentioned scattering of privilege checking
361 functionality, it is necessary to keep track of the state of the process.
362
363 A GRANT_INFO also serves as a cache of the privilege hash tables. Relevant
364 members are grant_table and version.
365 */
367 GRANT_INFO();
368 /**
369 @brief A copy of the privilege information regarding the current host,
370 database, object and user.
371
372 @details The version of this copy is found in GRANT_INFO::version.
373 */
375 /**
376 @brief Used for cache invalidation when caching privilege information.
377
378 @details The privilege information is stored on disk, with dedicated
379 caches residing in memory: table-level and column-level privileges,
380 respectively, have their own dedicated caches.
381
382 The GRANT_INFO works as a level 1 cache with this member updated to the
383 current value of the global variable @c grant_version (@c static variable
384 in sql_acl.cc). It is updated Whenever the GRANT_INFO is refreshed from
385 the level 2 cache. The level 2 cache is the @c column_priv_hash structure
386 (@c static variable in sql_acl.cc)
387
388 @see grant_version
389 */
390 uint version{0};
391 /**
392 @brief The set of privileges that the current user has fulfilled for a
393 certain host, database, and object.
394
395 @details This field is continually updated throughout the access checking
396 process. In each step the "wanted privilege" is checked against the
397 fulfilled privileges. When/if the intersection of these sets is empty,
398 access is granted.
399
400 The set is implemented as a bitmap, with the bits defined in sql_acl.h.
401 */
402 ulong privilege{0};
403 /** The grant state for internal tables. */
405};
406
414
415/**
416 Category of table found in the table share.
417*/
419 /**
420 Unknown value.
421 */
423
424 /**
425 Temporary table.
426 The table is visible only in the session.
427 Therefore,
428 - FLUSH TABLES WITH READ LOCK
429 - SET GLOBAL READ_ONLY = ON
430 do not apply to this table.
431 Note that LOCK TABLE t FOR READ/WRITE
432 can be used on temporary tables.
433 Temporary tables are not part of the table cache.
434
435 2016-06-14 Contrary to what's written in these comments, the truth is:
436 - tables created by CREATE TEMPORARY TABLE have TABLE_CATEGORY_USER
437 - tables created by create_tmp_table() (internal ones) have
438 TABLE_CATEGORY_TEMPORARY.
439 ha_innodb.cc relies on this observation (so: grep it). If you clean this
440 up, you may also want to look at 'no_tmp_table'; its enum values' meanings
441 have degraded over time: INTERNAL_TMP_TABLE is not used for some internal
442 tmp tables (derived tables). Unification of both enums would be
443 great. Whatever the result, we need to be able to distinguish the two
444 types of temporary tables above, as usage patterns are more restricted for
445 the second type, and allow more optimizations.
446 */
448
449 /**
450 User table.
451 These tables do honor:
452 - LOCK TABLE t FOR READ/WRITE
453 - FLUSH TABLES WITH READ LOCK
454 - SET GLOBAL READ_ONLY = ON
455 User tables are cached in the table cache.
456 */
458
459 /**
460 System table, maintained by the server.
461 These tables do honor:
462 - LOCK TABLE t FOR READ/WRITE
463 - FLUSH TABLES WITH READ LOCK
464 - SET GLOBAL READ_ONLY = ON
465 Typically, writes to system tables are performed by
466 the server implementation, not explicitly be a user.
467 System tables are cached in the table cache.
468 */
470
471 /**
472 Information schema tables.
473 These tables are an interface provided by the system
474 to inspect the system metadata.
475 These tables do *not* honor:
476 - LOCK TABLE t FOR READ/WRITE
477 - FLUSH TABLES WITH READ LOCK
478 - SET GLOBAL READ_ONLY = ON
479 as there is no point in locking explicitly
480 an INFORMATION_SCHEMA table.
481 Nothing is directly written to information schema tables.
482 Note that this value is not used currently,
483 since information schema tables are not shared,
484 but implemented as session specific temporary tables.
485 */
486 /*
487 TODO: Fixing the performance issues of I_S will lead
488 to I_S tables in the table cache, which should use
489 this table type.
490 */
492
493 /**
494 Log tables.
495 These tables are an interface provided by the system
496 to inspect the system logs.
497 These tables do *not* honor:
498 - LOCK TABLE t FOR READ/WRITE
499 - FLUSH TABLES WITH READ LOCK
500 - SET GLOBAL READ_ONLY = ON
501 as there is no point in locking explicitly
502 a LOG table.
503 An example of LOG tables are:
504 - mysql.slow_log
505 - mysql.general_log,
506 which *are* updated even when there is either
507 a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
508 User queries do not write directly to these tables
509 (there are exceptions for log tables).
510 The server implementation perform writes.
511 Log tables are cached in the table cache.
512 */
514
515 /**
516 Performance schema tables.
517 These tables are an interface provided by the system
518 to inspect the system performance data.
519 These tables do *not* honor:
520 - LOCK TABLE t FOR READ/WRITE
521 - FLUSH TABLES WITH READ LOCK
522 - SET GLOBAL READ_ONLY = ON
523 as there is no point in locking explicitly
524 a PERFORMANCE_SCHEMA table.
525 An example of PERFORMANCE_SCHEMA tables are:
526 - performance_schema.*
527 which *are* updated (but not using the handler interface)
528 even when there is either
529 a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
530 User queries do not write directly to these tables
531 (there are exceptions for SETUP_* tables).
532 The server implementation perform writes.
533 Performance tables are cached in the table cache.
534 */
536
537 /**
538 Replication Information Tables.
539 These tables are used to store replication information.
540 These tables do *not* honor:
541 - LOCK TABLE t FOR READ/WRITE
542 - FLUSH TABLES WITH READ LOCK
543 - SET GLOBAL READ_ONLY = ON
544 as there is no point in locking explicitly
545 a Replication Information table.
546 An example of replication tables are:
547 - mysql.slave_master_info
548 - mysql.slave_relay_log_info,
549 which *are* updated even when there is either
550 a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
551 User queries do not write directly to these tables.
552 Replication tables are cached in the table cache.
553 */
555
556 /**
557 Gtid Table.
558 The table is used to store gtids.
559 The table does *not* honor:
560 - LOCK TABLE t FOR READ/WRITE
561 - FLUSH TABLES WITH READ LOCK
562 - SET GLOBAL READ_ONLY = ON
563 as there is no point in locking explicitly
564 a Gtid table.
565 An example of gtid_executed table is:
566 - mysql.gtid_executed,
567 which is updated even when there is either
568 a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect.
569 Gtid table is cached in the table cache.
570 */
572
573 /**
574 A data dictionary table.
575 Table's with this category will skip checking the
576 TABLE_SHARE versions because these table structures
577 are fixed upon server bootstrap.
578 */
580
581 /**
582 A ACL metadata table.
583 For table in this category we will skip row locks when SQL statement
584 reads them.
585 */
589
590extern ulong refresh_version;
591
596};
597
599 uint count;
601};
602
604 protected:
606 virtual void report_error(uint code, const char *fmt, ...) = 0;
607
608 public:
610 virtual ~Table_check_intact() = default;
611
612 /**
613 Checks whether a table is intact. Should be done *just* after the table has
614 been opened.
615
616 @param[in] thd Thread handle
617 @param[in] table The table to check
618 @param[in] table_def Expected structure of the table (column name
619 and type)
620
621 @retval false OK
622 @retval true There was an error.
623 */
624 bool check(THD *thd, TABLE *table, const TABLE_FIELD_DEF *table_def);
625};
626
627/**
628 Class representing the fact that some thread waits for table
629 share to be flushed. Is used to represent information about
630 such waits in MDL deadlock detector.
631*/
632
637
638 public:
640 uint deadlock_weight_arg)
641 : m_ctx(ctx_arg),
642 m_share(share_arg),
643 m_deadlock_weight(deadlock_weight_arg) {}
644
645 MDL_context *get_ctx() const { return m_ctx; }
646
647 bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor) override;
648
649 uint get_deadlock_weight() const override;
650
651 /**
652 Pointers for participating in the list of waiters for table share.
653 */
656};
657
658typedef I_P_List<
663
667 /**
668 Name of unique key matching FK in parent table, "" if there is no
669 unique key.
670 */
674 /**
675 Arrays with names of referencing columns of the FK.
676 */
679
685
686/**
687 Definition of name for generated keys, owned by TABLE_SHARE
688*/
689struct Key_name {
691};
692
693/**
694 This structure is shared between different table objects. There is one
695 instance of table share per one table in the database.
696*/
697
699 TABLE_SHARE() = default;
700
701 /**
702 Create a new TABLE_SHARE with the given version number.
703 @param version the version of the TABLE_SHARE
704 @param secondary set to true if the TABLE_SHARE represents a table
705 in a secondary storage engine
706 */
707 TABLE_SHARE(unsigned long version, bool secondary)
708 : m_version(version), m_secondary_engine(secondary) {}
709
710 /*
711 Managed collection of refererence-counted snapshots of histograms statistics
712 for the table. TABLE objects acquire/release pointers to histogram
713 statistics from this collection. A new statistics snapshot is inserted when
714 the share is initialized and when histograms are updated/dropped.
715
716 For temporary tables m_histograms should be nullptr since we do not support
717 histograms on temporary tables.
718 */
720
721 /** Category of this table. */
723
725 /**
726 Used to allocate new handler for internal temporary table when the
727 size limitation of the primary storage engine is exceeded.
728 */
730
731 TYPELIB keynames; /* Pointers to keynames */
732 TYPELIB *intervals{nullptr}; /* pointer to interval info */
733 mysql_mutex_t LOCK_ha_data; /* To protect access to ha_data */
734 TABLE_SHARE *next{nullptr}, **prev{nullptr}; /* Link to unused shares */
735 /**
736 Array of table_cache_instances pointers to elements of table caches
737 respresenting this table in each of Table_cache instances.
738 Allocated along with the share itself in alloc_table_share().
739 Each element of the array is protected by Table_cache::m_lock in the
740 corresponding Table_cache. False sharing should not be a problem in
741 this case as elements of this array are supposed to be updated rarely.
742 */
744
745 /* The following is copied to each TABLE on OPEN */
746 Field **field{nullptr};
748 KEY *key_info{nullptr}; /* data of keys defined for the table */
749 uint *blob_field{nullptr}; /* Index to blobs in Field array */
750
751 uchar *default_values{nullptr}; /* row with default values */
752 LEX_STRING comment{nullptr, 0}; /* Comment about table */
753 LEX_STRING compress{nullptr, 0}; /* Compression algorithm */
754 LEX_STRING encrypt_type{nullptr, 0}; /* encryption algorithm */
755
756 /** Secondary storage engine. */
758 /** Secondary engine load status */
759 bool secondary_load{false};
760
762 nullptr}; /* Default charset of string fields */
763
765 /*
766 Key which is used for looking-up table in table cache and in the list
767 of thread's temporary tables. Has the form of:
768 "database_name\0table_name\0" + optional part for temporary tables.
769
770 Note that all three 'table_cache_key', 'db' and 'table_name' members
771 must be set (and be non-zero) for tables in table cache. They also
772 should correspond to each other.
773 To ensure this one can use set_table_cache() methods.
774 */
776 LEX_CSTRING db{nullptr, 0}; /* Pointer to db */
777 LEX_CSTRING table_name{nullptr, 0}; /* Table name (for open) */
778 LEX_STRING path{nullptr, 0}; /* Path to .frm file (from datadir) */
779 LEX_CSTRING normalized_path{nullptr, 0}; /* unpack_filename(path) */
781
784
785 /**
786 The set of indexes that are not disabled for this table. I.e. it excludes
787 indexes disabled by `ALTER TABLE ... DISABLE KEYS`, however it does
788 include invisible indexes. The data dictionary populates this bitmap.
789 */
791
792 /// The set of visible and enabled indexes for this table.
795 ha_rows min_rows{0}, max_rows{0}; /* create information */
796 ulong avg_row_length{0}; /* create information */
797 ulong mysql_version{0}; /* 0 if .frm is created before 5.0 */
798 ulong reclength{0}; /* Recordlength */
799 ulong stored_rec_length{0}; /* Stored record length
800 (no generated-only generated fields) */
802
803 plugin_ref db_plugin{nullptr}; /* storage engine plugin */
804 inline handlerton *db_type() const /* table_type for handler */
805 {
806 // assert(db_plugin);
807 return db_plugin ? plugin_data<handlerton *>(db_plugin) : nullptr;
808 }
809 /**
810 Value of ROW_FORMAT option for the table as provided by user.
811 Can be different from the real row format used by the storage
812 engine. ROW_TYPE_DEFAULT value indicates that no explicit
813 ROW_FORMAT was specified for the table. @sa real_row_type.
814 */
815 enum row_type row_type = {}; // Zero-initialized to ROW_TYPE_DEFAULT
816 /** Real row format used for the table by the storage engine. */
817 enum row_type real_row_type = {}; // Zero-initialized to ROW_TYPE_DEFAULT
819
820 /**
821 Only for internal temporary tables.
822 Count of TABLEs (having this TABLE_SHARE) which have a "handler"
823 (table->file!=nullptr) which is open (ha_open() has been called).
824 */
826
827 /**
828 Only for internal temporary tables.
829 Count of TABLEs (having this TABLE_SHARE) which have opened this table.
830 */
832
833 // Can only be 1,2,4,8 or 16, but use uint32_t since that how it is
834 // represented in InnoDB
835 std::uint32_t key_block_size{0}; /* create key_block_size, if used */
836 uint stats_sample_pages{0}; /* number of pages to sample during
837 stats estimation, if used, otherwise 0. */
839 stats_auto_recalc{}; /* Automatic recalc of stats.
840 Zero-initialized to HA_STATS_AUTO_RECALC_DEFAULT
841 */
843 uint fields{0}; /* Number of fields */
844 uint rec_buff_length{0}; /* Size of table->record[] buffer */
845 uint keys{0}; /* Number of keys defined for the table*/
846 uint key_parts{0}; /* Number of key parts of all keys
847 defined for the table
848 */
849 uint max_key_length{0}; /* Length of the longest key */
850 uint max_unique_length{0}; /* Length of the longest unique key */
852 /**
853 Whether this is a temporary table that already has a UNIQUE index (removing
854 duplicate rows on insert), so that the optimizer does not need to run
855 DISTINCT itself. Also used for INTERSECT and EXCEPT as a fall-back if
856 hashing fails (secondary overflow of in-memory hash table, in which case
857 we revert to de-duplication using the unique key in the output table).
858 */
859 bool is_distinct{false};
860
861 uint null_fields{0}; /* number of null fields */
862 uint blob_fields{0}; /* number of blob fields */
863 uint varchar_fields{0}; /* number of varchar fields */
864 /**
865 For materialized derived tables; @see add_derived_key().
866 'first' means: having the lowest position in key_info.
867 */
869 /**
870 For materialized derived tables: allocated size of key_info array.
871 */
873 /**
874 For materialized derived tables: allocated size of base_key_parts array of
875 all TABLE objects. Used for generated keys.
876 */
878 /**
879 Array of names for generated keys, used for materialized derived tables.
880 Shared among all TABLE objects referring to this table share.
881 */
883 /**
884 Records per key array, used for materialized derived tables.
885 This is a contiguous array, with size given by max_tmp_key_parts.
886 The array is shared with all TABLE objects referring to this table share.
887 */
888 ulong *base_rec_per_key{nullptr};
889 /**
890 Records per key array, float rep., used for materialized derived tables.
891 This is a contiguous array, with size given by max_tmp_key_parts.
892 The array is shared with all TABLE objects referring to this table share.
893 */
895 /**
896 Bitmap with flags representing some of table options/attributes.
897
898 @sa HA_OPTION_PACK_RECORD, HA_OPTION_PACK_KEYS, ...
899
900 @note This is basically copy of HA_CREATE_INFO::table_options bitmap
901 at the time of table opening/usage.
902 */
904 /**
905 Bitmap with flags representing some of table options/attributes which
906 are in use by storage engine.
907
908 @note db_options_in_use is normally copy of db_create_options but can
909 be overridden by SE. E.g. MyISAM does this at handler::open() and
910 handler::info() time.
911 */
913 uint rowid_field_offset{0}; /* Field_nr +1 to rowid field */
914 /* Primary key index number, used in TABLE::key_info[] */
915 uint primary_key{0};
916 uint next_number_index{0}; /* autoincrement key number */
917 uint next_number_key_offset{0}; /* autoinc keypart offset in a key */
918 uint next_number_keypart{0}; /* autoinc keypart number in a key */
919 bool error{false}; /* error during open_table_def() */
921 /// Number of generated fields
922 uint vfields{0};
923 /// Number of fields having the default value generated
925 bool system{false}; /* Set if system table (one record) */
926 bool db_low_byte_first{false}; /* Portable row format */
927 bool crashed{false};
928 bool is_view{false};
929 bool m_open_in_progress{false}; /* True: alloc'ed, false: def opened */
930 mysql::binlog::event::Table_id table_map_id; /* for row-based replication */
931
932 /*
933 Cache for row-based replication table share checks that does not
934 need to be repeated. Possible values are: -1 when cache value is
935 not calculated yet, 0 when table *shall not* be replicated, 1 when
936 table *may* be replicated.
937 */
939
940 /*
941 Storage media to use for this table (unless another storage
942 media has been specified on an individual column - in versions
943 where that is supported)
944 */
946
947 /* Name of the tablespace used for this table */
948 const char *tablespace{nullptr};
949
950 /**
951 Partition meta data. Allocated from TABLE_SHARE::mem_root,
952 created when reading from the dd tables,
953 used as template for each TABLE instance.
954 The reason for having it on the TABLE_SHARE is to be able to reuse the
955 partition_elements containing partition names, values etc. instead of
956 allocating them for each TABLE instance.
957 TODO: Currently it is filled in and then only used for generating
958 the partition_info_str. The plan is to clone/copy/reference each
959 TABLE::part_info instance from it.
960 What is missing before it can be completed:
961 1) The partition expression, currently created only during parsing which
962 also needs the current TABLE instance as context for name resolution etc.
963 2) The partition values, currently the DD stores them as text so it needs
964 to be converted to field images (which is now done by first parsing the
965 value text into an Item, then saving the Item result/value into a field
966 and then finally copy the field image).
967 */
969 // TODO: Remove these four variables:
970 /**
971 Filled in when reading from frm.
972 This can simply be removed when removing the .frm support,
973 since it is already stored in the new DD.
974 */
975 bool auto_partitioned{false};
976 /**
977 Storing the full partitioning clause (PARTITION BY ...) which is used
978 when creating new partition_info object for each new TABLE object by
979 parsing this string.
980 These two will be needed until the missing parts above is fixed.
981 */
982 char *partition_info_str{nullptr};
984
985 /**
986 Cache the checked structure of this table.
987
988 The pointer data is used to describe the structure that
989 a instance of the table must have. Each element of the
990 array specifies a field that must exist on the table.
991
992 The pointer is cached in order to perform the check only
993 once -- when the table is loaded from the disk.
994 */
996
997 /** Main handler's share */
999
1000 /** Instrumentation for this table share. */
1002
1003 /**
1004 List of tickets representing threads waiting for the share to be flushed.
1005 */
1007
1008 /**
1009 View object holding view definition read from DD. This object is not
1010 cached, and is owned by the table share. We are not able to read it
1011 on demand since we may then get a cache miss while holding LOCK_OPEN.
1012 */
1013 const dd::View *view_object{nullptr};
1014
1015 /**
1016 Data-dictionary object describing explicit temporary table represented
1017 by this share. NULL for other table types (non-temporary tables, internal
1018 temporary tables). This object is owned by TABLE_SHARE and should be
1019 deleted along with it.
1020 */
1022
1023 /// For materialized derived tables; @see add_derived_key().
1025
1026 /**
1027 Arrays with descriptions of foreign keys in which this table participates
1028 as child or parent. We only cache in them information from dd::Table object
1029 which is sufficient for use by prelocking algorithm/to check if table is
1030 referenced by a foreign key.
1031 */
1036
1037 // List of check constraint share instances.
1039
1040 /**
1041 Schema's read only mode - ON (true) or OFF (false). This is filled in
1042 when the share is initialized with meta data from DD. If the schema is
1043 altered, the tables and share are removed. This can be done since
1044 ALTER SCHEMA acquires exclusive meta data locks on the tables in the
1045 schema. We set this only for non-temporary tables. Otherwise, the value
1046 of the member below is 'NOT_SET'.
1047 */
1050
1051 /**
1052 Set share's table cache key and update its db and table name appropriately.
1053
1054 @param key_buff Buffer with already built table cache key to be
1055 referenced from share.
1056 @param key_length Key length.
1057
1058 @note
1059 Since 'key_buff' buffer will be referenced from share it should has same
1060 life-time as share itself.
1061 This method automatically ensures that TABLE_SHARE::table_name/db have
1062 appropriate values by using table cache key as their source.
1063 */
1064
1065 void set_table_cache_key(char *key_buff, size_t key_length) {
1066 table_cache_key.str = key_buff;
1067 table_cache_key.length = key_length;
1068 /*
1069 Let us use the fact that the key is "db/0/table_name/0" + optional
1070 part for temporary tables.
1071 */
1073 db.length = strlen(db.str);
1074 table_name.str = db.str + db.length + 1;
1075 table_name.length = strlen(table_name.str);
1076 }
1077
1078 /**
1079 Set share's table cache key and update its db and table name appropriately.
1080
1081 @param key_buff Buffer to be used as storage for table cache key
1082 (should be at least key_length bytes).
1083 @param key Value for table cache key.
1084 @param key_length Key length.
1085
1086 NOTE
1087 Since 'key_buff' buffer will be used as storage for table cache key
1088 it should has same life-time as share itself.
1089 */
1090
1091 void set_table_cache_key(char *key_buff, const char *key, size_t key_length) {
1092 memcpy(key_buff, key, key_length);
1093 set_table_cache_key(key_buff, key_length);
1094 }
1095
1097
1098 /** Returns the version of this TABLE_SHARE. */
1099 unsigned long version() const { return m_version; }
1100
1101 /**
1102 Set the version of this TABLE_SHARE to zero. This marks the
1103 TABLE_SHARE for automatic removal from the table definition cache
1104 once it is no longer referenced.
1105 */
1106 void clear_version();
1107
1108 /** Is this table share being expelled from the table definition cache? */
1109 bool has_old_version() const { return version() != refresh_version; }
1110
1111 /**
1112 Convert unrelated members of TABLE_SHARE to one enum
1113 representing its type.
1114
1115 @todo perhaps we need to have a member instead of a function.
1116 */
1118 if (is_view) return TABLE_REF_VIEW;
1119 switch (tmp_table) {
1120 case NO_TMP_TABLE:
1121 return TABLE_REF_BASE_TABLE;
1122 case SYSTEM_TMP_TABLE:
1123 return TABLE_REF_I_S_TABLE;
1124 default:
1125 return TABLE_REF_TMP_TABLE;
1126 }
1127 }
1128 /**
1129 Return a table metadata version.
1130 * for base tables and views, we return table_map_id.
1131 It is assigned from a global counter incremented for each
1132 new table loaded into the table definition cache (TDC).
1133 * for temporary tables it's table_map_id again. But for
1134 temporary tables table_map_id is assigned from
1135 thd->query_id. The latter is assigned from a thread local
1136 counter incremented for every new SQL statement. Since
1137 temporary tables are thread-local, each temporary table
1138 gets a unique id.
1139 * for everything else (e.g. information schema tables),
1140 the version id is zero.
1141
1142 This choice of version id is a large compromise
1143 to have a working prepared statement validation in 5.1. In
1144 future version ids will be persistent, as described in WL#4180.
1145
1146 Let's try to explain why and how this limited solution allows
1147 to validate prepared statements.
1148
1149 Firstly, sets (in mathematical sense) of version numbers
1150 never intersect for different table types. Therefore,
1151 version id of a temporary table is never compared with
1152 a version id of a view, and vice versa.
1153
1154 Secondly, for base tables and views, we know that each DDL flushes
1155 the respective share from the TDC. This ensures that whenever
1156 a table is altered or dropped and recreated, it gets a new
1157 version id.
1158 Unfortunately, since elements of the TDC are also flushed on
1159 LRU basis, this choice of version ids leads to false positives.
1160 E.g. when the TDC size is too small, we may have a SELECT
1161 * FROM INFORMATION_SCHEMA.TABLES flush all its elements, which
1162 in turn will lead to a validation error and a subsequent
1163 reprepare of all prepared statements. This is
1164 considered acceptable, since as long as prepared statements are
1165 automatically reprepared, spurious invalidation is only
1166 a performance hit. Besides, no better simple solution exists.
1167
1168 For temporary tables, using thd->query_id ensures that if
1169 a temporary table was altered or recreated, a new version id is
1170 assigned. This suits validation needs very well and will perhaps
1171 never change.
1172
1173 Metadata of information schema tables never changes.
1174 Thus we can safely assume 0 for a good enough version id.
1175
1176 Finally, by taking into account table type, we always
1177 track that a change has taken place when a view is replaced
1178 with a base table, a base table is replaced with a temporary
1179 table and so on.
1180
1181 @retval 0 For schema tables, DD tables and system views.
1182 non-0 For bases tables, views and temporary tables.
1183
1184 @sa Table_ref::is_table_ref_id_equal()
1185 */
1187
1188 /** Determine if the table is missing a PRIMARY KEY. */
1190 assert(primary_key <= MAX_KEY);
1191 return primary_key == MAX_KEY;
1192 }
1193
1194 uint find_first_unused_tmp_key(const Key_map &k);
1195
1196 bool visit_subgraph(Wait_for_flush *waiting_ticket,
1197 MDL_wait_for_graph_visitor *gvisitor);
1198
1199 bool wait_for_old_version(THD *thd, struct timespec *abstime,
1200 uint deadlock_weight);
1201
1202 /**
1203 The set of indexes that the optimizer may use when creating an execution
1204 plan.
1205 */
1206 Key_map usable_indexes(const THD *thd) const;
1207
1208 /** Release resources and free memory occupied by the table share. */
1209 void destroy();
1210
1211 /**
1212 How many TABLE objects use this TABLE_SHARE.
1213 @return the reference count
1214 */
1215 unsigned int ref_count() const {
1216 assert(assert_ref_count_is_locked(this));
1217 return m_ref_count;
1218 }
1219
1220 /**
1221 Increment the reference count by one.
1222 @return the new reference count
1223 */
1224 unsigned int increment_ref_count() {
1225 assert(assert_ref_count_is_locked(this));
1226 assert(!m_open_in_progress);
1227 return ++m_ref_count;
1228 }
1229
1230 /**
1231 Decrement the reference count by one.
1232 @return the new reference count
1233 */
1234 unsigned int decrement_ref_count() {
1235 assert(assert_ref_count_is_locked(this));
1236 assert(!m_open_in_progress);
1237 assert(m_ref_count > 0);
1238 return --m_ref_count;
1239 }
1240
1241 /// Does this TABLE_SHARE represent a table in a primary storage engine?
1242 bool is_primary_engine() const { return !m_secondary_engine; }
1243
1244 /// Does this TABLE_SHARE represent a table in a secondary storage engine?
1246
1247 /**
1248 Does this TABLE_SHARE represent a primary table that has a shadow
1249 copy in a secondary storage engine?
1250 */
1252 return is_primary_engine() && secondary_engine.str != nullptr;
1253 }
1254
1255 /** Returns whether this table is referenced by a foreign key. */
1257
1258 private:
1259 /// How many TABLE objects use this TABLE_SHARE.
1260 unsigned int m_ref_count{0};
1261
1262 /**
1263 TABLE_SHARE version, if changed the TABLE_SHARE must be reopened.
1264 NOTE: The TABLE_SHARE will not be reopened during LOCK TABLES in
1265 close_thread_tables!!!
1266 */
1267 unsigned long m_version{0};
1268
1269 protected: // To allow access from unit tests.
1270 /// Does this TABLE_SHARE represent a table in a secondary storage engine?
1272};
1273
1274/**
1275 Class is used as a BLOB field value storage for
1276 intermediate GROUP_CONCAT results. Used only for
1277 GROUP_CONCAT with DISTINCT or ORDER BY options.
1278 */
1279
1281 private:
1283 /**
1284 Sign that some values were cut
1285 during saving into the storage.
1286 */
1288
1289 public:
1292
1293 void reset() {
1295 truncated_value = false;
1296 }
1297 /**
1298 Function creates duplicate of 'from'
1299 string in 'storage' MEM_ROOT.
1300
1301 @param from string to copy
1302 @param length string length
1303
1304 @retval Pointer to the copied string.
1305 @retval 0 if an error occurred.
1306 */
1307 char *store(const char *from, size_t length) {
1308 return (char *)memdup_root(&storage, from, length);
1309 }
1312 }
1313 bool is_truncated_value() const { return truncated_value; }
1314};
1315
1316/**
1317 Class that represents a single change to a column value in partial
1318 update of a JSON column.
1319*/
1320class Binary_diff final {
1321 /// The offset of the start of the change.
1322 size_t m_offset;
1323
1324 /// The size of the portion that is to be replaced.
1325 size_t m_length;
1326
1327 public:
1328 /**
1329 Create a new Binary_diff object.
1330
1331 @param offset the offset of the beginning of the change
1332 @param length the length of the section that is to be replaced
1333 */
1334 Binary_diff(size_t offset, size_t length)
1336
1337 /// @return the offset of the changed data
1338 size_t offset() const { return m_offset; }
1339
1340 /// @return the length of the changed data
1341 size_t length() const { return m_length; }
1342
1343 /**
1344 Get a pointer to the start of the replacement data.
1345
1346 @param field the column that is updated
1347 @return a pointer to the start of the replacement data
1348 */
1349 const char *new_data(const Field *field) const;
1350
1351 /**
1352 Get a pointer to the start of the old data to be replaced.
1353
1354 @param field the column that is updated
1355 @return a pointer to the start of old data to be replaced.
1356 */
1357 const char *old_data(const Field *field) const;
1358};
1359
1360/**
1361 Vector of Binary_diff objects.
1362
1363 The Binary_diff objects in the vector should be ordered on offset, and none
1364 of the diffs should be overlapping or adjacent.
1365*/
1367
1368/**
1369 Flags for TABLE::m_status (maximum 8 bits).
1370 The flags define the state of the row buffer in TABLE::record[0].
1371*/
1372/**
1373 STATUS_NOT_STARTED is set when table is not accessed yet.
1374 Neither STATUS_NOT_FOUND nor STATUS_NULL_ROW can be set when this flag is set.
1375*/
1376#define STATUS_NOT_STARTED 1
1377/**
1378 Means we were searching for a row and didn't find it. This is used by
1379 storage engines (@see handler::index_read_map()) and the executor, both
1380 when doing an exact row lookup and advancing a scan (no more rows in range).
1381*/
1382#define STATUS_NOT_FOUND 2
1383/// Reserved for use by multi-table update. Means the row has been updated.
1384#define STATUS_UPDATED 16
1385/**
1386 Means that table->null_row is set. This is an artificial NULL-filled row
1387 (one example: in outer join, if no match has been found in inner table).
1388*/
1389#define STATUS_NULL_ROW 32
1390/// Reserved for use by multi-table delete. Means the row has been deleted.
1391#define STATUS_DELETED 64
1392
1393/* Information for one open table */
1395
1396/* Bitmap of table's fields */
1398
1399/*
1400 NOTE: Despite being a struct (for historical reasons), TABLE has
1401 a nontrivial destructor.
1402*/
1403struct TABLE {
1404 TABLE_SHARE *s{nullptr};
1405 handler *file{nullptr};
1406 TABLE *next{nullptr}, *prev{nullptr};
1407
1408 private:
1409 /**
1410 Links for the lists of used/unused TABLE objects for the particular
1411 table in the specific instance of Table_cache (in other words for
1412 specific Table_cache_element object).
1413 Declared as private to avoid direct manipulation with those objects.
1414 One should use methods of I_P_List template instead.
1415 */
1416 TABLE *cache_next{nullptr}, **cache_prev{nullptr};
1417
1418 /*
1419 Give Table_cache_element access to the above two members to allow
1420 using them for linking TABLE objects in a list.
1421 */
1423
1424 public:
1425 // Pointer to the histograms available on the table.
1426 // Protected in the same way as the pointer to the share.
1428
1429 /**
1430 A bitmap marking the hidden generated columns that exists for functional
1431 indexes.
1432 */
1434 /**
1435 The current session using this table object.
1436 Should be NULL when object is not in use.
1437 For an internal temporary table, it is NULL when the table is closed.
1438 Used for two purposes:
1439 - Signal that the object is in use, and by which session.
1440 - Pass the thread handler to storage handlers.
1441 The field should NOT be used as a general THD reference, instead use
1442 a passed THD reference, or, if there is no such, current_thd.
1443 The reason for this is that we cannot guarantee the field is not NULL.
1444 */
1445 THD *in_use{nullptr};
1446 Field **field{nullptr}; /* Pointer to fields */
1447 /// Count of hidden fields, if internal temporary table; 0 otherwise.
1449
1450 uchar *record[2]{nullptr, nullptr}; /* Pointer to records */
1451 uchar *write_row_record{nullptr}; /* Used as optimisation in
1452 THD::write_row */
1453 uchar *insert_values{nullptr}; /* used by INSERT ... UPDATE */
1454
1455 /// Buffer for use in multi-row reads. Initially empty.
1457
1458 /*
1459 Map of keys that can be used to retrieve all data from this table
1460 needed by the query without reading the row.
1461 */
1464
1465 /* Merge keys are all keys that had a column referred to in the query */
1467
1468 /*
1469 possible_quick_keys is a superset of quick_keys to use with EXPLAIN of
1470 JOIN-less commands (single-table UPDATE and DELETE).
1471
1472 When explaining regular JOINs, we use JOIN_TAB::keys to output the
1473 "possible_keys" column value. However, it is not available for
1474 single-table UPDATE and DELETE commands, since they don't use JOIN
1475 optimizer at the top level. OTOH they directly use the range optimizer,
1476 that collects all keys usable for range access here.
1477 */
1479
1480 /*
1481 A set of keys that can be used in the query that references this
1482 table.
1483
1484 All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be
1485 subtracted from this set upon instantiation. Thus for any TABLE t it holds
1486 that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
1487 must not introduce any new keys here (see setup_tables).
1488
1489 The set is implemented as a bitmap.
1490 */
1492 /* Map of keys that can be used to calculate GROUP BY without sorting */
1494 /* Map of keys that can be used to calculate ORDER BY without sorting */
1496 KEY *key_info{nullptr}; /* data of keys defined for the table */
1497 /**
1498 Key part array for generated keys, used for materialized derived tables.
1499 This is a contiguous array, with size given by s->max_tmp_key_parts.
1500 */
1502
1503 Field *next_number_field{nullptr}; /* Set if next_number is activated */
1504 Field *found_next_number_field{nullptr}; /* Set on open */
1505 /// Pointer to generated columns
1506 Field **vfield{nullptr};
1507 /// Pointer to fields having the default value generated
1509 /// Field used by unique constraint
1511 // ----------------------------------------------------------------------
1512 // The next few members are used if this (temporary) file is used solely for
1513 // the materialization/computation of an INTERSECT or EXCEPT set operation
1514 // (in addition to hash_field above used to detect duplicate rows). For
1515 // INTERSECT and EXCEPT, we always use the hash field and compute the shape
1516 // of the result set using m_set_counter. The latter is a hidden field
1517 // located between the hash field and the row proper, only present for
1518 // INTERSECT or EXCEPT materialized in a temporary result table. The
1519 // materialized table has no duplicate rows, relying instead of the embedded
1520 // counter to produce the correct number of duplicates with ALL semantics. If
1521 // we have distinct semantics, we squash duplicates. This all happens in the
1522 // reading step of the tmp table (TableScanIterator::Read),
1523 // cf. m_last_operation_is_distinct. For explanation if the logic of the set
1524 // counter, see MaterializeIterator<Profiler>::MaterializeOperand.
1525 //
1526
1527 /// A priori unlimited. We pass this on to TableScanIterator at construction
1528 /// time, q.v., to limit the number of rows out of an EXCEPT or INTERSECT.
1529 /// For these set operations, we do not know enough to enforce the limit at
1530 /// materialize time (as for UNION): only when reading the rows with
1531 /// TableScanIterator do we check the counters.
1532 /// @todo: Ideally, this limit should be communicated to TableScanIterator in
1533 /// some other way.
1535
1536 private:
1537 /// The set counter. It points to the field in the materialized table
1538 /// holding the counter used to compute INTERSECT and EXCEPT, in record[0].
1539 /// For EXCEPT [DISTINCT | ALL] and INTERSECT DISTINCT this is a simple 64
1540 /// bits counter. For INTERSECT ALL, it is subdivided into two sub counters
1541 /// cf. class HalfCounter, cf. MaterializeOperand. See set_counter().
1543
1544 /// If m_set_counter is set: true if last block has DISTINCT semantics,
1545 /// either because it is marked as such, or because we have computed this
1546 /// to give an equivalent answer. If false, we have ALL semantics.
1547 /// It will be true if any DISTINCT is given in the merged N-ary set
1548 /// operation. See is_distinct().
1550 /// If false, de-duplication happens via an index on this table, if
1551 /// true, via an in-memory hash table, in which case we do not need to use
1552 /// any index.
1554
1555 public:
1565
1566 private:
1567 /// Holds the set operation type
1569
1570 public:
1571 /// Test if this tmp table stores the result of a UNION set operation or
1572 /// a single table.
1573 /// @return true if so, else false.
1574 bool is_union_or_table() const { return m_set_counter == nullptr; }
1575
1576 void set_hashing(bool use_hashing) {
1577 m_deduplicate_with_hashing = use_hashing;
1578 }
1579
1581
1582 /// Returns the set operation type
1584 if (m_set_op_type == SOT_NONE) {
1585 assert(is_union_or_table()); // EXCEPT and INTERSECT are already set up
1587 }
1588 return m_set_op_type;
1589 }
1590
1591 bool is_intersect() const {
1592 return m_set_op_type == SOT_INTERSECT_ALL ||
1594 }
1595
1596 bool is_except() const {
1597 return m_set_op_type == SOT_EXCEPT_ALL ||
1599 }
1600
1602 /**
1603 Initialize the set counter field pointer and the type of set operation
1604 *other than UNION*.
1605 @param set_counter the field in the materialized table that holds the
1606 counter we use to compute intersect or except
1607 @param except if true, EXCEPT, else INTERSECT
1608 @param distinct if true, the set operation is DISTINCT, else ALL
1609 */
1610 void set_set_op(Field_longlong *set_counter, bool except, bool distinct) {
1613 assert(m_set_op_type == SOT_NONE);
1614 m_set_op_type = except
1615 ? (distinct ? SOT_EXCEPT_DISTINCT : SOT_EXCEPT_ALL)
1617 }
1618
1620 //
1621 // end of INTERSECT and EXCEPT specific members
1622 // ----------------------------------------------------------------------
1623
1624 Field *fts_doc_id_field{nullptr}; /* Set if FTS_DOC_ID field is present */
1625
1626 /* Table's triggers, 0 if there are no of them */
1628 Table_ref *pos_in_table_list{nullptr}; /* Element referring to this table */
1629 /* Position in thd->locked_table_list under LOCK TABLES */
1631 ORDER *group{nullptr};
1632 const char *alias{nullptr}; ///< alias or table name
1633 uchar *null_flags{nullptr}; ///< Pointer to the null flags of record[0]
1635 nullptr}; ///< Saved null_flags while null_row is true
1636
1637 /* containers */
1639 /*
1640 Bitmap of fields that one or more query condition refers to. Only
1641 used if optimizer_condition_fanout_filter is turned 'on'.
1642 Currently, only the WHERE clause and ON clause of inner joins is
1643 taken into account but not ON conditions of outer joins.
1644 Furthermore, HAVING conditions apply to groups and are therefore
1645 not useful as table condition filters.
1646 */
1648
1649 /**
1650 Bitmap of table fields (columns), which are explicitly set in the
1651 INSERT INTO statement. It is declared here to avoid memory allocation
1652 on MEM_ROOT).
1653
1654 @sa fields_set_during_insert.
1655 */
1657
1658 /**
1659 The read set contains the set of columns that the execution engine needs to
1660 process the query. In particular, it is used to tell the storage engine
1661 which columns are needed. For virtual generated columns, the underlying base
1662 columns are also added, since they are required in order to calculate the
1663 virtual generated columns.
1664
1665 Internal operations in the execution engine that need to move rows between
1666 buffers, such as aggregation, sorting, hash join and set operations, should
1667 rather use read_set_internal, since the virtual generated columns have
1668 already been calculated when the row was read from the storage engine.
1669
1670 Set during resolving; every field that gets resolved, sets its own bit
1671 in the read set. In some cases, we switch the read set around during
1672 various phases; note that it is a pointer.
1673
1674 In addition, for binary logging purposes, the bitmaps are set according
1675 to the settings of @@binlog_row_image. Therefore, for logging purposes,
1676 some additional fields, to those specified by the optimizer, may be
1677 flagged in the read and write sets.
1678 @c TABLE::mark_columns_per_binlog_row_image for additional details.
1679 */
1681
1683
1684 /**
1685 A bitmap of fields that are explicitly referenced by the query. This is
1686 mostly the same as read_set, but it does not include base columns of
1687 referenced virtual generated columns unless the base columns are referenced
1688 explicitly in the query.
1689
1690 This is the read set that should be used for determining which columns to
1691 store in join buffers, aggregation buffers, sort buffers, or similar
1692 operations internal to the execution engine. Both because it is unnecessary
1693 to store the implicitly read base columns in the buffer, since they won't
1694 ever be read out of the buffer anyways, and because the base columns may not
1695 even be possible to read, if a covering index scan is used and the index
1696 only contains the virtual column and not all its base columns.
1697 */
1699
1700 /**
1701 A pointer to the bitmap of table fields (columns), which are explicitly set
1702 in the INSERT INTO statement.
1703
1704 fields_set_during_insert points to def_fields_set_during_insert
1705 for base (non-temporary) tables. In other cases, it is NULL.
1706 Triggers can not be defined for temporary tables, so this bitmap does not
1707 matter for temporary tables.
1708
1709 @sa def_fields_set_during_insert.
1710 */
1712
1713 /*
1714 The ID of the query that opened and is using this table. Has different
1715 meanings depending on the table type.
1716
1717 Temporary tables:
1718
1719 table->query_id is set to thd->query_id for the duration of a statement
1720 and is reset to 0 once it is closed by the same statement. A non-zero
1721 table->query_id means that a statement is using the table even if it's
1722 not the current statement (table is in use by some outer statement).
1723
1724 Non-temporary tables:
1725
1726 Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
1727 for the duration of a statement and is reset to 0 once it is closed by
1728 the same statement. A non-zero query_id is used to control which tables
1729 in the list of pre-opened and locked tables are actually being used.
1730 */
1732
1733 /*
1734 For each key that has quick_keys.is_set(key) == true: estimate of #records
1735 and max #key parts that range access would use.
1736 */
1738
1739 /* Bitmaps of key parts that =const for the entire join. */
1741
1744
1745 /*
1746 Estimate of number of records that satisfy SARGable part of the table
1747 condition, or table->file->records if no SARGable condition could be
1748 constructed.
1749 This value is used by join optimizer as an estimate of number of records
1750 that will pass the table condition (condition that depends on fields of
1751 this table and constants)
1752 */
1754
1755 uint lock_position{0}; /* Position in MYSQL_LOCK.table */
1756 uint lock_data_start{0}; /* Start pos. in MYSQL_LOCK.locks */
1757 uint lock_count{0}; /* Number of locks */
1758 uint db_stat{0}; /* mode of file as in handler.h */
1759 int current_lock{0}; /* Type of lock on table */
1760
1761 // List of table check constraints.
1763
1764 private:
1765 /**
1766 If true, this table is inner w.r.t. some outer join operation, all columns
1767 are nullable (in the query), and null_row may be true.
1768 */
1769 bool nullable{false};
1770
1771 uint8 m_status{0}; /* What's in record[0] */
1772 public:
1773 /*
1774 If true, the current table row is considered to have all columns set to
1775 NULL, including columns declared as "not null" (see nullable).
1776 @todo make it private, currently join buffering changes it through a pointer
1777 */
1778 bool null_row{false};
1779
1780 bool copy_blobs{false}; /* copy_blobs when storing */
1781
1782 /*
1783 TODO: Each of the following flags take up 8 bits. They can just as easily
1784 be put into one single unsigned long and instead of taking up 18
1785 bytes, it would take up 4.
1786 */
1787 bool force_index{false};
1788
1789 /**
1790 Flag set when the statement contains FORCE INDEX FOR ORDER BY
1791 See Table_ref::process_index_hints().
1792 */
1794
1795 /**
1796 Flag set when the statement contains FORCE INDEX FOR GROUP BY
1797 See Table_ref::process_index_hints().
1798 */
1800 bool const_table{false};
1801 /// True if writes to this table should not write rows and just write keys.
1802 bool no_rows{false};
1803
1804 /**
1805 If set, the optimizer has found that row retrieval should access index
1806 tree only.
1807 */
1808 bool key_read{false};
1809 /**
1810 Certain statements which need the full row, set this to ban index-only
1811 access.
1812 */
1813 bool no_keyread{false};
1814 /**
1815 If set, indicate that the table is not replicated by the server.
1816 */
1817 bool no_replicate{false};
1818 /* To signal that the table is associated with a HANDLER statement */
1819 bool open_by_handler{false};
1820 /**
1821 To indicate that value of the auto_increment field was provided
1822 explicitly by the user or from some other source (e.g. in case of
1823 INSERT ... SELECT, ALTER TABLE or LOAD DATA) and not as default
1824 or result of conversion from NULL value.
1825
1826 @note Since auto_increment fields are always non-NULL we can't find
1827 out using methods of Field class if 0 value stored in such field
1828 was provided explicitly or is result of applying default/conversion
1829 from NULL value. In the former case no new auto_increment value
1830 needs to be generated in MODE_NO_AUTO_VALUE_ON_ZERO mode, while
1831 the latter cases require new value generation. Hence the need
1832 for this flag.
1833 @note Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode and only
1834 by handler::write_row().
1835 */
1837 bool alias_name_used{false}; /* true if table_name is alias */
1838 bool get_fields_in_item_tree{false}; /* Signal to fix_field */
1839
1840 private:
1841 /**
1842 This TABLE object is invalid and cannot be reused. TABLE object might have
1843 inconsistent info or handler might not allow some operations.
1844
1845 For example, TABLE might have inconsistent info about partitioning.
1846 We also use this flag to avoid calling handler::reset() for partitioned
1847 InnoDB tables after in-place ALTER TABLE API commit phase and to force
1848 closing table after REPAIR TABLE has failed during its prepare phase as
1849 well.
1850
1851 @note This member can be set only by thread that owns/has opened the
1852 table and while holding its THD::LOCK_thd_data lock.
1853 It can be read without locking by this owner thread, or by some other
1854 thread concurrently after acquiring owner's THD::LOCK_thd_data.
1855
1856 @note The TABLE will not be reopened under LOCK TABLES in
1857 close_thread_tables().
1858 */
1859 bool m_invalid_dict{false};
1860
1861 /**
1862 This TABLE object is invalid and cannot be reused as it has outdated
1863 rec_per_key and handler stats.
1864
1865 @note This member is protected from concurrent access to it by lock of
1866 Table Cache's partition to which this TABLE object belongs,
1867 */
1868 bool m_invalid_stats{false};
1869
1870 /**
1871 For tmp tables. true <=> tmp table has been instantiated.
1872 Also indicates that table was successfully opened since
1873 we immediately delete tmp tables which we fail to open.
1874 */
1875 bool created{false};
1876
1877 public:
1878 /// For a materializable derived or SJ table: true if has been materialized
1879 bool materialized{false};
1880 struct /* field connections */
1881 {
1882 class JOIN_TAB *join_tab{nullptr};
1883 class QEP_TAB *qep_tab{nullptr};
1884 thr_lock_type lock_type{TL_UNLOCK}; /* How table is used */
1886 /*
1887 true <=> range optimizer found that there is no rows satisfying
1888 table conditions.
1889 */
1890 bool impossible_range{false};
1892
1893 /**
1894 @todo This member should not be declared in-line. That makes it
1895 impossible for any function that does memory allocation to take a const
1896 reference to a TABLE object.
1897 */
1899 /**
1900 Initialized in Item_func_group_concat::setup for appropriate
1901 temporary table if GROUP_CONCAT is used with ORDER BY | DISTINCT
1902 and BLOB field count > 0.
1903 */
1905
1906 /**
1907 Not owned by the TABLE; used only from filesort_free_buffers().
1908 See comments on SortingIterator::CleanupAfterQuery().
1909 */
1912
1913 /**
1914 The result of applying a unique operation (by row ID) to the table, if done.
1915 In particular, this is done in some forms of index merge.
1916 */
1918 partition_info *part_info{nullptr}; /* Partition related information */
1919 /* If true, all partitions have been pruned away */
1922
1923 private:
1924 /// Cost model object for operations on this table
1926#ifndef NDEBUG
1927 /**
1928 Internal tmp table sequential number. Increased in the order of
1929 creation. Used for debugging purposes when many tmp tables are used
1930 during execution (e.g several windows with window functions)
1931 */
1933#endif
1934 public:
1935 void reset();
1936 void init(THD *thd, Table_ref *tl);
1937 bool init_tmp_table(THD *thd, TABLE_SHARE *share, MEM_ROOT *m_root,
1938 CHARSET_INFO *charset, const char *alias, Field **fld,
1939 uint *blob_fld, bool is_virtual);
1940 bool fill_item_list(mem_root_deque<Item *> *item_list) const;
1941 void clear_column_bitmaps(void);
1942 void prepare_for_position(void);
1943
1946 uint key_parts = 0) const;
1948 void mark_auto_increment_column(void);
1949 void mark_columns_needed_for_update(THD *thd, bool mark_binlog_columns);
1953 void mark_generated_columns(bool is_update);
1954 void mark_gcol_in_maps(const Field *field);
1955 void mark_check_constraint_columns(bool is_update);
1956 void column_bitmaps_set(MY_BITMAP *read_set_arg, MY_BITMAP *write_set_arg);
1957 inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
1958 MY_BITMAP *write_set_arg) {
1959 read_set = read_set_arg;
1960 write_set = write_set_arg;
1961 }
1962 inline void use_all_columns() {
1964 }
1968 }
1969 void invalidate_dict();
1970 void invalidate_stats();
1971 /**
1972 @note Can be called by thread owning table without additional locking, and
1973 by any other thread which has acquired owner's THD::LOCK_thd_data lock.
1974 */
1975 inline bool has_invalid_dict() const {
1976 assert(assert_invalid_dict_is_locked(this));
1977 return !db_stat || m_invalid_dict;
1978 }
1979 /// @note Can be called by thread owning Table_cache::m_lock
1980 inline bool has_invalid_stats() {
1981 assert(assert_invalid_stats_is_locked(this));
1982 return m_invalid_stats;
1983 }
1984 /// @returns first non-hidden column
1986 /// @returns count of visible fields
1988 bool alloc_tmp_keys(uint new_key_count, uint new_key_part_count,
1989 bool modify_share);
1990 bool add_tmp_key(Field_map *key_parts, bool invisible, bool modify_share);
1991 void move_tmp_key(int old_idx, bool modify_share);
1992 void drop_unused_tmp_keys(bool modify_share);
1993
1994 void set_keyread(bool flag);
1995
1996 /**
1997 Check whether the given index has a virtual generated columns.
1998
1999 @param index_no the given index to check
2000
2001 @returns true if if index is defined over at least one virtual generated
2002 column
2003 */
2004 inline bool index_contains_some_virtual_gcol(uint index_no) const {
2005 assert(index_no < s->keys);
2006 return key_info[index_no].flags & HA_VIRTUAL_GEN_KEY;
2007 }
2008 void update_const_key_parts(Item *conds);
2009
2010 bool check_read_removal(uint index);
2011
2012 ptrdiff_t default_values_offset() const {
2013 return (ptrdiff_t)(s->default_values - record[0]);
2014 }
2015
2016 /// @returns true if a storage engine handler object is assigned to table
2017 bool has_storage_handler() const { return file != nullptr; }
2018
2019 /// Set storage handler for temporary table
2021 // Ensure consistent call order
2022 assert((file == nullptr && file_arg != nullptr) ||
2023 (file != nullptr && file_arg == nullptr));
2024 assert(!is_created());
2025 assert(file_arg->inited == handler::NONE);
2026 file = file_arg;
2027 }
2028 /// Return true if table is instantiated, and false otherwise.
2029 bool is_created() const { return created; }
2030
2031 /**
2032 Set the table as "created", and enable flags in storage engine
2033 that could not be enabled without an instantiated table.
2034 */
2035 void set_created();
2036 /**
2037 Set the contents of table to be "deleted", ie "not created", after having
2038 deleted the contents.
2039 */
2040 void set_deleted() { created = materialized = false; }
2041 /// Set table as nullable, ie it is inner wrt some outer join
2042 void set_nullable() { nullable = true; }
2043
2044 /// Return whether table is nullable
2045 bool is_nullable() const { return nullable; }
2046
2047 /// @return true if table contains one or more generated columns
2048 bool has_gcol() const { return vfield; }
2049
2050 /**
2051 Life cycle of the row buffer is as follows:
2052 - The initial state is "not started".
2053 - When reading a row through the storage engine handler, the status is set
2054 as "has row" or "no row", depending on whether a row was found or not.
2055 The "not started" state is cleared, as well as the "null row" state,
2056 the updated state and the deleted state.
2057 - When making a row available in record[0], make sure to update row status
2058 similarly to how the storage engine handler does it.
2059 - If a NULL-extended row is needed in join execution, the "null row" state
2060 is set. Note that this can be combined with "has row" if a row was read
2061 but condition on it was evaluated to false (happens for single-row
2062 lookup), or "no row" if no more rows could be read.
2063 Note also that for the "null row" state, the NULL bits inside the
2064 row are set to one, so the row inside the row buffer is no longer usable,
2065 unless the NULL bits are saved in a separate buffer.
2066 - The "is updated" and "is deleted" states are set when row is updated or
2067 deleted, respectively.
2068 */
2069 /// Set status for row buffer as "not started"
2072 null_row = false;
2073 }
2074
2075 /// @return true if a row operation has been done
2076 bool is_started() const { return !(m_status & STATUS_NOT_STARTED); }
2077
2078 /// Set status for row buffer: contains row
2080 m_status = 0;
2081 null_row = false;
2082 }
2083
2084 /**
2085 Set status for row buffer: contains no row. This is set when
2086 - A lookup operation finds no row
2087 - A scan operation scans past the last row of the range.
2088 - An error in generating key values before calling storage engine.
2089 */
2090 void set_no_row() {
2092 null_row = false;
2093 }
2094
2095 /**
2096 Set "row found" status from handler result
2097
2098 @param status 0 if row was found, <> 0 if row was not found
2099 */
2102 null_row = false;
2103 }
2104
2105 /**
2106 Set current row as "null row", for use in null-complemented outer join.
2107 The row buffer may or may not contain a valid row.
2108 set_null_row() and reset_null_row() are used by the join executor to
2109 signal the presence or absence of a NULL-extended row for an outer joined
2110 table. Null rows may also be used to specify rows that are all NULL in
2111 grouing operations.
2112 @note this is a destructive operation since the NULL value bit vector
2113 is overwritten. Caching operations must be aware of this.
2114 */
2116 null_row = true;
2118 if (s->null_bytes > 0) memset(null_flags, 255, s->null_bytes);
2119 }
2120
2121 /// Clear "null row" status for the current row
2123 null_row = false;
2124 m_status &= ~STATUS_NULL_ROW;
2125 }
2126
2127 /// Set "updated" property for the current row
2129 assert(is_started() && has_row());
2131 }
2132
2133 /// Set "deleted" property for the current row
2135 assert(is_started() && has_row());
2137 }
2138
2139 /// @return true if there is a row in row buffer
2140 bool has_row() const { return !(m_status & STATUS_NOT_FOUND); }
2141
2142 /// @return true if current row is null-extended
2143 bool has_null_row() const { return null_row; }
2144
2145 /// @return true if current row has been updated (multi-table update)
2146 bool has_updated_row() const { return m_status & STATUS_UPDATED; }
2147
2148 /// @return true if current row has been deleted (multi-table delete)
2149 bool has_deleted_row() const { return m_status & STATUS_DELETED; }
2150
2151 /// Save the NULL flags of the current row into the designated buffer.
2152 /// This should be done before null-complementing a table accessed
2153 /// with EQRefIterator or a const table, as they need to be able to
2154 /// restore the original contents of the record buffer before
2155 /// reading the next row. This is necessary because of their special
2156 /// code for avoiding table access if the same row should be
2157 /// accessed by the next read.
2159 if (s->null_bytes > 0) memcpy(null_flags_saved, null_flags, s->null_bytes);
2160 }
2161
2162 /// Restore the NULL flags of the current row from the designated buffer
2164 if (s->null_bytes > 0) memcpy(null_flags, null_flags_saved, s->null_bytes);
2165 }
2166
2167 /// Empties internal temporary table (deletes rows, closes scan)
2168 bool empty_result_table();
2169
2170 /**
2171 Initialize the optimizer cost model.
2172
2173 This function should be called each time a new query is started.
2174
2175 @param cost_model_server the main cost model object for the query
2176 */
2177 void init_cost_model(const Cost_model_server *cost_model_server) {
2178 m_cost_model.init(cost_model_server, this);
2179 }
2180
2181 /**
2182 Return the cost model object for this table.
2183 */
2184 const Cost_model_table *cost_model() const { return &m_cost_model; }
2185
2186 /**
2187 Bind all the table's value generator columns in all the forms:
2188 stored/virtual GC, default expressions and checked constraints.
2189
2190 @details When a table is opened from the dictionary, the Value Generator
2191 expressions are bound during opening (see fix_value_generator_fields()).
2192 After query execution, Item::cleanup() is called on them
2193 (see cleanup_value_generator_items()). When the table is opened from the
2194 table cache, the Value Generetor(s) need to be bound again and this
2195 function does that.
2196 */
2198
2199 /**
2200 Clean any state in items associated with generated columns to be ready for
2201 the next statement.
2202 */
2204
2205#ifndef NDEBUG
2206 void set_tmp_table_seq_id(uint arg) { tmp_table_seq_id = arg; }
2207#endif
2208 /**
2209 Update covering keys depending on max read key length.
2210
2211 Update available covering keys for the table, based on a constrained field
2212 and the identified covering prefix keys: If the matched part of field is
2213 longer than the index prefix,
2214 the prefix index cannot be used as a covering index.
2215
2216 @param[in] field Pointer to field object
2217 @param[in] key_read_length Max read key length
2218 @param[in] covering_prefix_keys Covering prefix keys
2219 */
2220 void update_covering_prefix_keys(Field *field, uint16 key_read_length,
2221 Key_map *covering_prefix_keys);
2222
2223 /**
2224 Returns the primary engine handler for the table.
2225 If none exist, nullptr is returned.
2226 */
2228
2229 private:
2230 /**
2231 Bitmap that tells which columns are eligible for partial update in an
2232 update statement.
2233
2234 The bitmap is lazily allocated in the TABLE's mem_root when
2235 #mark_column_for_partial_update() is called.
2236 */
2238
2239 /**
2240 Object which contains execution time state used for partial update
2241 of JSON columns.
2242
2243 It is allocated in the execution mem_root by #setup_partial_update() if
2244 there are columns that have been marked as eligible for partial update.
2245 */
2247
2248 /**
2249 This flag decides whether or not we should log the drop temporary table
2250 command.
2251 */
2253
2254 public:
2255 /**
2256 Does this table have any columns that can be updated using partial update
2257 in the current row?
2258
2259 @return whether any columns in the current row can be updated using partial
2260 update
2261 */
2262 bool has_binary_diff_columns() const;
2263
2264 /**
2265 Get the list of binary diffs that have been collected for a given column in
2266 the current row, or `nullptr` if partial update cannot be used for that
2267 column.
2268
2269 @param field the column to get binary diffs for
2270 @return the list of binary diffs for the column, or `nullptr` if the column
2271 cannot be updated using partial update
2272 */
2273 const Binary_diff_vector *get_binary_diffs(const Field *field) const;
2274
2275 /**
2276 Mark a given column as one that can potentially be updated using
2277 partial update during execution of an update statement.
2278
2279 Whether it is actually updated using partial update, is not
2280 determined until execution time, since that depends both on the
2281 data that is in the column and the new data that is written to the
2282 column.
2283
2284 This function should be called during preparation of an update
2285 statement.
2286
2287 @param field a column which is eligible for partial update
2288 @retval false on success
2289 @retval true on out-of-memory
2290 */
2292
2293 /**
2294 Has this column been marked for partial update?
2295
2296 Note that this only tells if the column satisfies the syntactical
2297 requirements for being partially updated. Use #is_binary_diff_enabled() or
2298 #is_logical_diff_enabled() instead to see if partial update should be used
2299 on the column.
2300
2301 @param field the column to check
2302 @return whether the column has been marked for partial update
2303 */
2304 bool is_marked_for_partial_update(const Field *field) const;
2305
2306 /**
2307 Does this table have any columns that were marked with
2308 #mark_column_for_partial_update()?
2309
2310 Note that this only tells if any of the columns satisfy the syntactical
2311 requirements for being partially updated. Use
2312 #has_binary_diff_columns(), #is_binary_diff_enabled() or
2313 #is_logical_diff_enabled() instead to see if partial update should be used
2314 on a column.
2315 */
2317
2318 /**
2319 Enable partial update of JSON columns in this table. It is only
2320 enabled for the columns that have previously been marked for
2321 partial update using #mark_column_for_partial_update().
2322
2323 @param logical_diffs should logical JSON diffs be collected in addition
2324 to the physical binary diffs?
2325
2326 This function should be called once per statement execution, when
2327 the update statement is optimized.
2328
2329 @retval false on success
2330 @retval true on out-of-memory
2331 */
2332 bool setup_partial_update(bool logical_diffs);
2333
2334 /**
2335 @see setup_partial_update(bool)
2336
2337 This is a wrapper that auto-computes the value of the parameter
2338 logical_diffs.
2339
2340 @retval false on success
2341 @retval true on out-of-memory
2342 */
2343 bool setup_partial_update();
2344
2345 /**
2346 Add a binary diff for a column that is updated using partial update.
2347
2348 @param field the column that is being updated
2349 @param offset the offset of the changed portion
2350 @param length the length of the changed portion
2351
2352 @retval false on success
2353 @retval true on out-of-memory
2354 */
2355 bool add_binary_diff(const Field *field, size_t offset, size_t length);
2356
2357 /**
2358 Clear the diffs that have been collected for partial update of
2359 JSON columns, and re-enable partial update for any columns where
2360 partial update was temporarily disabled for the current row.
2361 Should be called between each row that is updated.
2362 */
2364
2365 /**
2366 Clean up state used for partial update of JSON columns.
2367
2368 This function should be called at the end of each statement
2369 execution.
2370 */
2372
2373 /**
2374 Temporarily disable collection of binary diffs for a column in the current
2375 row.
2376
2377 This function is called during execution to disable partial update of a
2378 column that was previously marked as eligible for partial update with
2379 #mark_column_for_partial_update() during preparation.
2380
2381 Partial update of this column will be re-enabled when we go to the next
2382 row.
2383
2384 @param field the column to stop collecting binary diffs for
2385 */
2387
2388 /**
2389 Temporarily disable collection of Json_diff objects describing the
2390 logical changes of a JSON column in the current row.
2391
2392 Collection of logical JSON diffs is re-enabled when we go to the next row.
2393
2394 @param field the column to stop collecting logical JSON diffs for
2395 */
2397
2398 /**
2399 Get a buffer that can be used to hold the partially updated column value
2400 while performing partial update.
2401 */
2403
2404 /**
2405 Add a logical JSON diff describing a logical change to a JSON column in
2406 partial update.
2407
2408 @param field the column that is updated
2409 @param path the JSON path that is changed
2410 @param operation the operation to perform
2411 @param new_value the new value in the path
2412
2413 @throws std::bad_alloc if memory cannot be allocated
2414 */
2416 enum_json_diff_operation operation,
2417 const Json_wrapper *new_value);
2418
2419 /**
2420 Get the list of JSON diffs that have been collected for a given column in
2421 the current row, or `nullptr` if partial update cannot be used for that
2422 column.
2423
2424 @param field the column to get JSON diffs for
2425 @return the list of JSON diffs for the column, or `nullptr` if the column
2426 cannot be updated using partial update
2427 */
2429
2430 /**
2431 Is partial update using binary diffs enabled on this JSON column?
2432
2433 @param field the column to check
2434 @return whether the column can be updated with binary diffs
2435 */
2436 bool is_binary_diff_enabled(const Field *field) const;
2437
2438 /**
2439 Is partial update using logical diffs enabled on this JSON column?
2440
2441 @param field the column to check
2442 @return whether the column can be updated with JSON diffs
2443 */
2444 bool is_logical_diff_enabled(const Field *field) const;
2445
2446 /**
2447 Virtual fields of type BLOB have a flag m_keep_old_value. This flag is set
2448 to false for all such fields in this table.
2449 */
2451
2452 /**
2453 Set the variable should_binlog_drop_if_temp_flag, so that
2454 the logging of temporary tables can be decided.
2455
2456 @param should_binlog the value to set flag should_binlog_drop_if_temp_flag
2457 */
2458 void set_binlog_drop_if_temp(bool should_binlog);
2459
2460 /**
2461 @return whether should_binlog_drop_if_temp_flag flag is
2462 set or not
2463 */
2464 bool should_binlog_drop_if_temp(void) const;
2465
2466 /**
2467 Find the histogram for the given field index.
2468
2469 @param field_index The index of the field we want to find a histogram for.
2470
2471 @retval nullptr if no histogram is found.
2472 @retval Pointer to a histogram if one is found.
2473 */
2474 const histograms::Histogram *find_histogram(uint field_index) const;
2475};
2476
2477static inline void empty_record(TABLE *table) {
2478 restore_record(table, s->default_values);
2479 if (table->s->null_bytes > 0)
2480 memset(table->null_flags, 255, table->s->null_bytes);
2481}
2482
2483#define MY_I_S_MAYBE_NULL 1
2484#define MY_I_S_UNSIGNED 2
2485
2487 /**
2488 This is used as column name.
2489 */
2490 const char *field_name;
2491 /**
2492 For string-type columns, this is the maximum number of
2493 characters. Otherwise, it is the 'display-length' for the column.
2494 For the data type MYSQL_TYPE_DATETIME this field specifies the
2495 number of digits in the fractional part of time value.
2496 */
2498 /**
2499 This denotes data type for the column. For the most part, there seems to
2500 be one entry in the enum for each SQL data type, although there seem to
2501 be a number of additional entries in the enum.
2502 */
2505 /**
2506 This is used to set column attributes. By default, columns are @c NOT
2507 @c NULL and @c SIGNED, and you can deviate from the default
2508 by setting the appropriate flags. You can use either one of the flags
2509 @c MY_I_S_MAYBE_NULL and @c MY_I_S_UNSIGNED or
2510 combine them using the bitwise or operator @c |. Both flags are
2511 defined in table.h.
2512 */
2513 uint field_flags; // Field attributes (maybe_null, signed, unsigned etc.)
2514 const char *old_name;
2515 uint open_method; // Not used
2516};
2517
2519 const char *table_name;
2521 /* Fill table with data */
2522 int (*fill_table)(THD *thd, Table_ref *tables, Item *cond);
2523 /* Handle fields for old SHOW */
2524 int (*old_format)(THD *thd, ST_SCHEMA_TABLE *schema_table);
2525 int (*process_table)(THD *thd, Table_ref *tables, TABLE *table, bool res,
2528};
2529
2530/**
2531 Strategy for how to process a view or derived table (merge or materialization)
2532*/
2538
2539#define VIEW_SUID_INVOKER 0
2540#define VIEW_SUID_DEFINER 1
2541#define VIEW_SUID_DEFAULT 2
2542
2543/* view WITH CHECK OPTION parameter options */
2544#define VIEW_CHECK_NONE 0
2545#define VIEW_CHECK_LOCAL 1
2546#define VIEW_CHECK_CASCADED 2
2547
2548/* result of view WITH CHECK OPTION parameter check */
2549#define VIEW_CHECK_OK 0
2550#define VIEW_CHECK_ERROR 1
2551#define VIEW_CHECK_SKIP 2
2552
2553/** The threshold size a blob field buffer before it is freed */
2554#define MAX_TDC_BLOB_SIZE 65536
2555
2556/**
2557 Struct that describes an expression selected from a derived table or view.
2558*/
2560 /**
2561 Points to an item that represents the expression.
2562 If the item is determined to be unused, the pointer is set to NULL.
2563 */
2565 /// Name of selected expression
2566 const char *name;
2567};
2568
2569/*
2570 Column reference of a NATURAL/USING join. Since column references in
2571 joins can be both from views and stored tables, may point to either a
2572 Field (for tables), or a Field_translator (for views).
2573*/
2574
2576 public:
2577 Field_translator *view_field; /* Column reference of merge view. */
2578 Item_field *table_field; /* Column reference of table or temp view. */
2579 Table_ref *table_ref; /* Original base table/view reference. */
2580 /*
2581 True if a common join column of two NATURAL/USING join operands. Notice
2582 that when we have a hierarchy of nested NATURAL/USING joins, a column can
2583 be common at some level of nesting but it may not be common at higher
2584 levels of nesting. Thus this flag may change depending on at which level
2585 we are looking at some column.
2586 */
2588
2589 public:
2591 Natural_join_column(Item_field *field_param, Table_ref *tab);
2592 const char *name();
2593 Item *create_item(THD *thd);
2594 Field *field();
2595 const char *table_name();
2596 const char *db_name();
2597 GRANT_INFO *grant();
2598};
2599
2600/**
2601 This is generic enum. It may be reused in the ACL statements
2602 for clauses that can map to the values defined in this enum.
2603*/
2605 UNCHANGED, /* The clause is not specified */
2606 DEFAULT, /* Default value of clause is specified */
2607 YES, /* Value that maps to True is specified */
2608 NO /* Value that maps to False is specified */
2609};
2610
2611struct LEX_MFA {
2618 /*
2619 The following flags are indicators for the SQL syntax used while
2620 parsing CREATE/ALTER user. While other members are self-explanatory,
2621 'uses_authentication_string_clause' signifies if the password is in
2622 hash form (if the var was set to true) or not.
2623 */
2628 /* flag set during CREATE USER .. INITIAL AUTHENTICATION BY */
2630 /* flag set during ALTER USER .. ADD nth FACTOR */
2632 /* flag set during ALTER USER .. MODIFY nth FACTOR */
2634 /* flag set during ALTER USER .. DROP nth FACTOR */
2636 /*
2637 flag used during authentication and to decide if server should
2638 be in sandbox mode or not
2639 */
2641 /* flag set during ALTER USER .. nth FACTOR UNREGISTER */
2643 /* flag set during ALTER USER .. INITIATE REGISTRATION */
2645 /* flag set during ALTER USER .. FINISH REGISTRATION */
2647
2649 void reset() {
2651 auth = NULL_CSTR;
2655 nth_factor = 1;
2659 has_password_generator = false;
2660 passwordless = false;
2661 add_factor = false;
2662 drop_factor = false;
2663 modify_factor = false;
2664 requires_registration = false;
2665 unregister = false;
2666 init_registration = false;
2667 finish_registration = false;
2668 }
2669 void copy(LEX_MFA *m, MEM_ROOT *alloc);
2670};
2671
2672/*
2673 This structure holds the specifications relating to
2674 ALTER user ... PASSWORD EXPIRE ...
2675*/
2693 /* Holds the specification of 'PASSWORD REQUIRE CURRENT' clause. */
2695 void cleanup() {
2701 account_locked = false;
2713 }
2714};
2715
2716/*
2717 This structure holds the specifications related to
2718 mysql user and the associated auth details.
2719*/
2720struct LEX_USER {
2728 /* restrict MFA methods to atmost 3 authentication plugins */
2732
2733 void init() {
2734 user = NULL_CSTR;
2735 host = NULL_CSTR;
2737 uses_replace_clause = false;
2739 discard_old_password = false;
2756 mfa_list.clear();
2757 with_initial_auth = false;
2758 }
2759
2761
2762 bool add_mfa_identifications(LEX_MFA *factor2, LEX_MFA *factor3 = nullptr);
2763
2764 /*
2765 Allocates the memory in the THD mem pool and initialize the members of
2766 this struct. It is preferable to use this method to create a LEX_USER
2767 rather allocating the memory in the THD and initializing the members
2768 explicitly.
2769 */
2770 static LEX_USER *alloc(THD *thd);
2771 static LEX_USER *alloc(THD *thd, LEX_STRING *user, LEX_STRING *host);
2772 /*
2773 Initialize the members of this struct. It is preferable to use this method
2774 to initialize a LEX_USER rather initializing the members explicitly.
2775 */
2776 static LEX_USER *init(LEX_USER *to_init, THD *thd, LEX_STRING *user,
2777 LEX_STRING *host);
2778};
2779
2780/**
2781 Derive type of metadata lock to be requested for table used by a DML
2782 statement from the type of THR_LOCK lock requested for this table.
2783*/
2784
2785inline enum enum_mdl_type mdl_type_for_dml(enum thr_lock_type lock_type) {
2786 return lock_type >= TL_WRITE_ALLOW_WRITE
2790}
2791
2792/**
2793 Type of table which can be open for an element of table list.
2794*/
2795
2801
2802/**
2803 This structure is used to keep info about possible key for the result table
2804 of a derived table/view.
2805 The 'referenced_by' is the table map of tables to which this possible
2806 key corresponds.
2807 The 'used_field' is a map of fields of which this key consists of.
2808 See also the comment for the Table_ref::update_derived_keys function.
2809*/
2810
2812 public:
2816};
2817
2818class Table_function;
2819/*
2820 Table reference in the FROM clause.
2821
2822 These table references can be of several types that correspond to
2823 different SQL elements. Below we list all types of TABLE_LISTs with
2824 the necessary conditions to determine when a Table_ref instance
2825 belongs to a certain type.
2826
2827 1) table (Table_ref::view == NULL)
2828 - base table
2829 (Table_ref::derived == NULL)
2830 - subquery - Table_ref::table is a temp table
2831 (Table_ref::derived != NULL)
2832 - information schema table
2833 (Table_ref::schema_table != NULL)
2834 NOTICE: for schema tables Table_ref::field_translation may be != NULL
2835 2) view (Table_ref::view != NULL)
2836 - merge (Table_ref::effective_algorithm == VIEW_ALGORITHM_MERGE)
2837 also (Table_ref::field_translation != NULL)
2838 - temptable(Table_ref::effective_algorithm == VIEW_ALGORITHM_TEMPTABLE)
2839 also (Table_ref::field_translation == NULL)
2840 3) nested table reference (Table_ref::nested_join != NULL)
2841 - table sequence - e.g. (t1, t2, t3)
2842 TODO: how to distinguish from a JOIN?
2843 - general JOIN
2844 TODO: how to distinguish from a table sequence?
2845 - NATURAL JOIN
2846 (Table_ref::natural_join != NULL)
2847 - JOIN ... USING
2848 (Table_ref::join_using_fields != NULL)
2849 - semi-join
2850 ;
2851*/
2852
2854 public:
2855 Table_ref() = default;
2856
2857 /**
2858 Only to be used by legacy code that temporarily needs a Table_ref,
2859 more specifically: Query_result_create::binlog_show_create_table().
2860 */
2861 explicit Table_ref(TABLE *table_arg) : table(table_arg) {}
2862
2863 /// Constructor that can be used when the strings are null terminated.
2864 Table_ref(const char *db_name, const char *table_name,
2865 enum thr_lock_type lock_type)
2866 : Table_ref(db_name, strlen(db_name), table_name, strlen(table_name),
2867 table_name, lock_type) {}
2868
2869 /**
2870 Creates a Table_ref object with pre-allocated strings for database,
2871 table and alias.
2872 */
2873 Table_ref(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg,
2874 const char *table_name_arg, size_t table_name_length_arg,
2875 const char *alias_arg, enum thr_lock_type lock_type_arg)
2876 : db(db_name_arg),
2877 table_name(table_name_arg),
2878 alias(alias_arg),
2879 m_map(1),
2880 table(table_arg),
2881 m_lock_descriptor{lock_type_arg},
2882 db_length(db_length_arg),
2883 table_name_length(table_name_length_arg) {
2886 }
2887
2888 /// Constructor that can be used when the strings are null terminated.
2889 Table_ref(const char *db_name, const char *table_name, const char *alias,
2890 enum thr_lock_type lock_type)
2891 : Table_ref(db_name, strlen(db_name), table_name, strlen(table_name),
2892 alias, lock_type) {}
2893
2894 /**
2895 This constructor can be used when a Table_ref is needed for an
2896 existing temporary table. These typically have very long table names, since
2897 it is a fully qualified path. For this reason, the table is set to the
2898 alias. The database name is left blank. The lock descriptor is set to
2899 TL_READ.
2900 */
2901 Table_ref(TABLE *table_arg, const char *alias_arg)
2902 : db(""),
2903 table_name(alias_arg),
2904 alias(alias_arg),
2905 m_map(1),
2906 table(table_arg),
2908 db_length(0),
2909 table_name_length(strlen(alias_arg)) {
2912 }
2913
2914 /**
2915 Sets an explicit enum_mdl_type value, without initializing
2916 m_lock_descriptor.
2917 */
2918 Table_ref(TABLE *table_arg, const char *alias_arg, enum_mdl_type mdl_type)
2919 : db(table_arg->s->db.str),
2920 table_name(table_arg->s->table_name.str),
2921 alias(alias_arg),
2922 m_map(1),
2923 table(table_arg),
2924 db_length(table_arg->s->db.length),
2925 table_name_length(table_arg->s->table_name.length) {
2928 }
2929
2930 Table_ref(const char *db_name, const char *table_name_arg,
2931 enum thr_lock_type lock_type_arg,
2932 enum enum_mdl_type mdl_request_type)
2933 : db(db_name),
2934 table_name(table_name_arg),
2935 alias(table_name_arg),
2936 m_map(1),
2937 m_lock_descriptor{lock_type_arg},
2938 db_length(strlen(db_name)),
2939 table_name_length(strlen(table_name_arg)) {
2942 mdl_request.set_type(mdl_request_type);
2943 }
2944
2945 Table_ref(const char *db_name, size_t db_length_arg,
2946 const char *table_name_arg, size_t table_name_length_arg,
2947 enum thr_lock_type lock_type_arg,
2948 enum enum_mdl_type mdl_request_type)
2949 : db(db_name),
2950 table_name(table_name_arg),
2951 alias(table_name_arg),
2952 m_map(1),
2953 m_lock_descriptor{lock_type_arg},
2954 db_length(db_length_arg),
2955 table_name_length(table_name_length_arg) {
2958 mdl_request.set_type(mdl_request_type);
2959 }
2960
2961 Table_ref(const char *db_name, size_t db_length_arg,
2962 const char *table_name_arg, size_t table_name_length_arg,
2963 enum thr_lock_type lock_type_arg)
2964 : db(db_name),
2965 table_name(table_name_arg),
2966 alias(table_name_arg),
2967 m_map(1),
2968 m_lock_descriptor{lock_type_arg},
2969 db_length(db_length_arg),
2970 table_name_length(table_name_length_arg) {}
2971
2972 /**
2973 Sets an explicit enum_mdl_type value, without initializing
2974 m_lock_descriptor.
2975 */
2976 Table_ref(const char *db_name, size_t db_length_arg,
2977 const char *table_name_arg, size_t table_name_length_arg,
2978 const char *alias_arg, enum enum_mdl_type mdl_request_type)
2979 : db(db_name),
2980 table_name(table_name_arg),
2981 alias(alias_arg),
2982 m_map(1),
2983 db_length(db_length_arg),
2984 table_name_length(table_name_length_arg) {
2987 mdl_request.set_type(mdl_request_type);
2988 }
2989
2990 Table_ref(const char *db_name, size_t db_length_arg,
2991 const char *table_name_arg, size_t table_name_length_arg,
2992 const char *alias_arg, enum thr_lock_type lock_type_arg,
2993 enum enum_mdl_type mdl_request_type)
2994 : db(db_name),
2995 table_name(table_name_arg),
2996 alias(alias_arg),
2997 m_map(1),
2998 m_lock_descriptor{lock_type_arg},
2999 db_length(db_length_arg),
3000 table_name_length(table_name_length_arg) {
3003 mdl_request.set_type(mdl_request_type);
3004 }
3005
3006 Table_ref(const char *db_name_arg, size_t db_length_arg,
3007 const char *table_name_arg, size_t table_name_length_arg,
3008 const char *alias_arg, enum thr_lock_type lock_type_arg)
3009 : db(db_name_arg),
3010 table_name(table_name_arg),
3011 alias(alias_arg),
3012 m_map(1),
3013 m_lock_descriptor{lock_type_arg},
3014 db_length(db_length_arg),
3015 table_name_length(table_name_length_arg) {
3018 }
3019
3020 /// Create a Table_ref object representing a nested join
3021 static Table_ref *new_nested_join(MEM_ROOT *allocator, const char *alias,
3023 mem_root_deque<Table_ref *> *belongs_to,
3024 Query_block *select);
3026 Item *join_cond() const { return m_join_cond; }
3027 void set_join_cond(Item *val) {
3028 // If optimization has started, it's too late to change m_join_cond.
3029 assert(m_join_cond_optim == nullptr || m_join_cond_optim == (Item *)1);
3030 m_join_cond = val;
3031 }
3034 /*
3035 Either we are setting to "empty", or there must pre-exist a
3036 permanent condition.
3037 */
3038 assert(cond == nullptr || cond == (Item *)1 || m_join_cond != nullptr);
3039 m_join_cond_optim = cond;
3040 }
3042
3043 /// @returns true if semi-join nest
3044 bool is_sj_nest() const { return m_is_sj_or_aj_nest && !m_join_cond; }
3045 /// @returns true if anti-join nest
3046 bool is_aj_nest() const { return m_is_sj_or_aj_nest && m_join_cond; }
3047 /// @returns true if anti/semi-join nest
3048 bool is_sj_or_aj_nest() const { return m_is_sj_or_aj_nest; }
3049 /// Makes the next a semi/antijoin nest
3051 assert(!m_is_sj_or_aj_nest);
3052 m_is_sj_or_aj_nest = true;
3053 }
3054
3055 /// Merge tables from a query block into a nested join structure
3057
3058 /// Reset table
3059 void reset();
3060
3061 /// Evaluate the check option of a view
3062 int view_check_option(THD *thd) const;
3063
3064 /// Produce a textual identification of this object
3065 void print(const THD *thd, String *str, enum_query_type query_type) const;
3066
3067 /// Check which single table inside a view that matches a table map
3068 bool check_single_table(Table_ref **table_ref, table_map map);
3069
3070 /// Allocate a buffer for inserted column values
3072
3074 /**
3075 Retrieve the last (right-most) leaf in a nested join tree with
3076 respect to name resolution.
3077
3078
3079 Given that 'this' is a nested table reference, recursively walk
3080 down the right-most children of 'this' until we reach a leaf
3081 table reference with respect to name resolution.
3082
3083 The right-most child of a nested table reference is the first
3084 element in the list of children because the children are inserted
3085 in reverse order.
3086
3087 @return
3088 - If 'this' is a nested table reference - the right-most child
3089 of the tree rooted in 'this',
3090 - else - 'this'
3091 */
3093 bool is_leaf_for_name_resolution() const;
3094
3095 /// Return the outermost view this table belongs to, or itself
3096 inline const Table_ref *top_table() const {
3097 return belong_to_view ? belong_to_view : this;
3098 }
3099
3101 return const_cast<Table_ref *>(
3102 const_cast<const Table_ref *>(this)->top_table());
3103 }
3104
3105 /// Prepare check option for a view
3106 bool prepare_check_option(THD *thd, bool is_cascaded = false);
3107
3108 /// Merge WHERE condition of view or derived table into outer query
3109 bool merge_where(THD *thd);
3110
3111 /// Prepare replace filter for a view (used for REPLACE command)
3112 bool prepare_replace_filter(THD *thd);
3113
3114 /// Return true if this represents a named view
3115 bool is_view() const { return view != nullptr; }
3116
3117 /// Return true if this represents a derived table (an unnamed view)
3118 bool is_derived() const { return derived != nullptr && view == nullptr; }
3119
3120 /// Return true if this represents a named view or a derived table
3121 bool is_view_or_derived() const { return derived != nullptr; }
3122
3123 /// Return true if this represents a table function
3124 bool is_table_function() const { return table_function != nullptr; }
3125 /**
3126 @returns true if this is a recursive reference inside the definition of a
3127 recursive CTE.
3128 @note that it starts its existence as a dummy derived table, until the
3129 end of resolution when it's not a derived table anymore, just a reference
3130 to the materialized temporary table. Whereas a non-recursive
3131 reference to the recursive CTE is a derived table.
3132 */
3134
3135 /// @returns true if this is a base table (permanent or temporary)
3136 bool is_base_table() const {
3137 return !(is_view_or_derived() || is_table_function() ||
3139 }
3140 /**
3141 @see is_recursive_reference().
3142 @returns true if error
3143 */
3145
3146 /**
3147 @returns true for a table that represents an optimizer internal table,
3148 is a derived table, a recursive reference, a table function.
3149 Internal tables are only visible inside a query expression, and is hence
3150 not visible in any schema, or need any kind of privilege checking.
3151 */
3152 bool is_internal() const {
3154 }
3155
3156 /**
3157 @returns true for a table that is a placeholder, ie a derived table,
3158 a view, a recursive reference, a table function or a schema table.
3159 A table is also considered to be a placeholder if it does not have a
3160 TABLE object for some other reason.
3161 */
3162 bool is_placeholder() const {
3164 is_table_function() || schema_table || table == nullptr;
3165 }
3166
3167 /// Return true if view or derived table and can be merged
3168 bool is_mergeable() const;
3169
3170 /**
3171 Checks if this is a table that contains zero rows or one row, and that can
3172 be materialized during optimization.
3173
3174 @returns true if materializable table contains one or zero rows, and
3175 materialization during optimization is permitted
3176
3177 Returning true, if the hypergraph optimizer is not active, implies that the
3178 table is materialized during optimization, so it need not be optimized
3179 during execution. The hypergraph optimizer does not care about const tables,
3180 so such tables are not executed during optimization time when it is active.
3181 */
3182 bool materializable_is_const() const;
3183
3184 /// Return true if this is a derived table or view that is merged
3186
3187 /// Set table to be merged
3188 void set_merged() {
3191 }
3192
3193 /// Return true if this is a materializable derived table/view
3196 }
3197
3198 /// Set table to be materialized
3200 // @todo We should do this only once, but currently we cannot:
3201 // assert(effective_algorithm == VIEW_ALGORITHM_UNDEFINED);
3204 }
3205
3206 /// Return true if table is updatable
3207 bool is_updatable() const { return m_updatable; }
3208
3209 /// Set table as updatable. (per default, a table is non-updatable)
3210 void set_updatable() { m_updatable = true; }
3211
3212 /// Return true if table is insertable-into
3213 bool is_insertable() const { return m_insertable; }
3214
3215 /// Set table as insertable-into. (per default, a table is not insertable)
3216 void set_insertable() { m_insertable = true; }
3217
3218 /// Return true if table is being updated
3219 bool is_updated() const { return m_updated; }
3220
3221 /// Set table and all referencing views as being updated
3223 for (Table_ref *tr = this; tr != nullptr; tr = tr->referencing_view)
3224 tr->m_updated = true;
3225 }
3226
3227 /// Return true if table is being inserted into
3228 bool is_inserted() const { return m_inserted; }
3229
3230 /// Set table and all referencing views as being inserted into
3232 for (Table_ref *tr = this; tr != nullptr; tr = tr->referencing_view)
3233 tr->m_inserted = true;
3234 }
3235
3236 /// Return true if table is being deleted from
3237 bool is_deleted() const { return m_deleted; }
3238
3239 /// Set table and all referencing views as being deleted from
3241 for (Table_ref *tr = this; tr != nullptr; tr = tr->referencing_view)
3242 tr->m_deleted = true;
3243 }
3244
3245 /// Set table as full-text search (default is not fulltext searched)
3247
3248 /// Returns true if a MATCH function references this table.
3250
3251 /// Is this table only available in an external storage engine?
3252 bool is_external() const;
3253
3254 /**
3255 Set table as readonly, ie it is neither updatable, insertable nor
3256 deletable during this statement.
3257 */
3259 m_updatable = false;
3260 m_insertable = false;
3261 }
3262
3263 /**
3264 Return true if this is a view or derived table that is defined over
3265 more than one base table, and false otherwise.
3266 */
3267 bool is_multiple_tables() const {
3268 if (is_view_or_derived()) {
3269 assert(is_merged()); // Cannot be a materialized view
3270 return leaf_tables_count() > 1;
3271 } else {
3272 assert(nested_join == nullptr); // Must be a base table
3273 return false;
3274 }
3275 }
3276
3277 /// Return no. of base tables a merged view or derived table is defined over.
3278 uint leaf_tables_count() const;
3279
3280 /// Return first leaf table of a base table or a view/derived table
3282 Table_ref *tr = this;
3283 while (tr->merge_underlying_list) tr = tr->merge_underlying_list;
3284 return tr;
3285 }
3286
3287 /// Return any leaf table that is not an inner table of an outer join
3288 /// @todo WL#6570 with prepare-once, replace with first_leaf_table()
3289 /// when WL#6059 is merged in (it really converts RIGHT JOIN to
3290 /// LEFT JOIN so the first leaf is part of a LEFT JOIN,
3291 /// guaranteed).
3293 Table_ref *tr = this;
3294 while (tr->merge_underlying_list) {
3295 tr = tr->merge_underlying_list;
3296 /*
3297 "while" is used, however, an "if" might be sufficient since there is
3298 no more than one inner table in a join nest (with outer_join true).
3299 */
3300 while (tr->outer_join) tr = tr->next_local;
3301 }
3302 return tr;
3303 }
3304 /**
3305 Set the LEX object of a view (will also define this as a view).
3306 @note: The value 1 is used to indicate a view but without a valid
3307 query object. Use only if the LEX object is not going to
3308 be used in later processing.
3309 */
3310 void set_view_query(LEX *lex) { view = lex; }
3311
3312 /// Return the valid LEX object for a view.
3313 LEX *view_query() const {
3314 assert(view != nullptr && view != (LEX *)1);
3315 return view;
3316 }
3317
3318 /**
3319 Set the query expression of a derived table or view.
3320 (Will also define this as a derived table, unless it is a named view.)
3321 */
3323 derived = query_expr;
3324 }
3325
3326 /// Return the query expression of a derived table or view.
3328 assert(derived);
3329 return derived;
3330 }
3331
3332 /// Resolve a derived table or view reference
3333 bool resolve_derived(THD *thd, bool apply_semijoin);
3334
3335 /// Optimize the query expression representing a derived table/view
3336 bool optimize_derived(THD *thd);
3337
3338 /// Create result table for a materialized derived table/view
3339 bool create_materialized_table(THD *thd);
3340
3341 /// Materialize derived table
3342 bool materialize_derived(THD *thd);
3343
3344 /// Check if we can push outer where condition to this derived table
3346
3347 /// Return the number of hidden fields added for the temporary table
3348 /// created for this derived table.
3350
3351 /// Prepare security context for a view
3352 bool prepare_security(THD *thd);
3353
3356
3357 /**
3358 Compiles the tagged hints list and fills up TABLE::keys_in_use_for_query,
3359 TABLE::keys_in_use_for_group_by, TABLE::keys_in_use_for_order_by,
3360 TABLE::force_index and TABLE::covering_keys.
3361 */
3362 bool process_index_hints(const THD *thd, TABLE *table);
3363
3364 /**
3365 Compare the version of metadata from the previous execution
3366 (if any) with values obtained from the current table
3367 definition cache element.
3368
3369 @sa check_and_update_table_version()
3370 */
3372 return (m_table_ref_type == s->get_table_ref_type() &&
3374 }
3375
3376 /**
3377 Record the value of metadata version of the corresponding
3378 table definition cache element in this parse tree node.
3379
3380 @sa check_and_update_table_version()
3381 */
3384 }
3385
3386 void set_table_ref_id(enum_table_ref_type table_ref_type_arg,
3387 ulonglong table_ref_version_arg) {
3388 m_table_ref_type = table_ref_type_arg;
3389 m_table_ref_version = table_ref_version_arg;
3390 }
3391
3392 /**
3393 If a derived table, returns query block id of first underlying query block.
3394 Zero if not derived.
3395 */
3396 uint query_block_id() const;
3397
3398 /**
3399 This is for showing in EXPLAIN.
3400 If a derived table, returns query block id of first underlying query block
3401 of first materialized Table_ref instance. Zero if not derived.
3402 */
3403 uint query_block_id_for_explain() const;
3404
3405 /**
3406 @brief Returns the name of the database that the referenced table belongs
3407 to.
3408 */
3409 const char *get_db_name() const { return db; }
3410
3411 /**
3412 @brief Returns the name of the table that this Table_ref represents.
3413
3414 @details The unqualified table name or view name for a table or view,
3415 respectively.
3416 */
3417 const char *get_table_name() const { return table_name; }
3419 ha_rows fallback_estimate = PLACEHOLDER_TABLE_ROW_ESTIMATE);
3420 bool update_derived_keys(THD *, Field *, Item **, uint, bool *);
3421 bool generate_keys();
3422
3423 /// Setup a derived table to use materialization
3426
3427 /// Setup a table function to use materialization
3428 bool setup_table_function(THD *thd);
3429
3430 bool create_field_translation(THD *thd);
3431
3432 /**
3433 @brief Returns the outer join nest that this Table_ref belongs to, if
3434 any.
3435
3436 @details There are two kinds of join nests, outer-join nests and semi-join
3437 nests. This function returns non-NULL in the following cases:
3438 @li 1. If this table/nest is embedded in a nest and this nest IS NOT a
3439 semi-join nest. (In other words, it is an outer-join nest.)
3440 @li 2. If this table/nest is embedded in a nest and this nest IS a
3441 semi-join nest, but this semi-join nest is embedded in another
3442 nest. (This other nest will be an outer-join nest, since all inner
3443 joined nested semi-join nests have been merged in
3444 @c simplify_joins() ).
3445 Note: This function assumes that @c simplify_joins() has been performed.
3446 Before that, join nests will be present for all types of join.
3447
3448 @return outer join nest, or NULL if none.
3449 */
3450
3452 if (!embedding) return nullptr;
3453 if (embedding->is_sj_nest()) return embedding->embedding;
3454 return embedding;
3455 }
3456 /**
3457 Return true if this table is an inner table of some outer join.
3458
3459 Examine all the embedding join nests of the table.
3460 @note This function works also before redundant join nests have been
3461 eliminated.
3462
3463 @return true if table is an inner table of some outer join, false otherwise.
3464 */
3465
3467 if (outer_join) return true;
3468 for (Table_ref *emb = embedding; emb; emb = emb->embedding) {
3469 if (emb->outer_join) return true;
3470 }
3471 return false;
3472 }
3473
3474 /**
3475 Return the base table entry of an updatable table.
3476 In DELETE and UPDATE, a view used as a target table must be mergeable,
3477 updatable and defined over a single table.
3478 */
3480 const Table_ref *tbl = this;
3481 assert(tbl->is_updatable() && !tbl->is_multiple_tables());
3482 while (tbl->is_view_or_derived()) {
3483 tbl = tbl->merge_underlying_list;
3484 assert(tbl->is_updatable() && !tbl->is_multiple_tables());
3485 }
3486 return tbl;
3487 }
3488
3490 return const_cast<Table_ref *>(
3491 static_cast<const Table_ref *>(this)->updatable_base_table());
3492 }
3493
3494 /**
3495 Mark that there is a NATURAL JOIN or JOIN ... USING between two tables.
3496
3497 This function marks that table b should be joined with a either via
3498 a NATURAL JOIN or via JOIN ... USING. Both join types are special
3499 cases of each other, so we treat them together. The function
3500 setup_conds() creates a list of equal condition between all fields
3501 of the same name for NATURAL JOIN or the fields in
3502 Table_ref::join_using_fields for JOIN ... USING.
3503 The list of equality conditions is stored
3504 either in b->join_cond(), or in JOIN::conds, depending on whether there
3505 was an outer join.
3506
3507 EXAMPLE
3508 @verbatim
3509 SELECT * FROM t1 NATURAL LEFT JOIN t2
3510 <=>
3511 SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
3512
3513 SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
3514 <=>
3515 SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)
3516
3517 SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
3518 <=>
3519 SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
3520 @endverbatim
3521
3522 @param b Right join argument.
3523 */
3525
3526 /**
3527 Set granted privileges for a table.
3528
3529 Can be used when generating temporary tables that are also used in
3530 resolver process, such as when generating a UNION table
3531
3532 @param privilege Privileges granted for this table.
3533 */
3534 void set_privileges(ulong privilege) { grant.privilege |= privilege; }
3535
3536 bool save_properties();
3537 void restore_properties();
3538
3539 /*
3540 List of tables local to a subquery or the top-level SELECT (used by
3541 SQL_I_List). Considers views as leaves (unlike 'next_leaf' below).
3542 Created at parse time in Query_block::add_table_to_list() ->
3543 table_list.link_in_list().
3544 */
3546 /* link in a global list of all queries tables */
3547 Table_ref *next_global{nullptr}, **prev_global{nullptr};
3548 const char *db{nullptr}, *table_name{nullptr}, *alias{nullptr};
3549 /*
3550 Target tablespace name: When creating or altering tables, this
3551 member points to the tablespace_name in the HA_CREATE_INFO struct.
3552 */
3554 char *option{nullptr}; /* Used by cache index */
3555
3556 /** Table level optimizer hints for this table. */
3558 /* Hints for query block of this table. */
3560
3561 void set_lock(const Lock_descriptor &descriptor) {
3562 m_lock_descriptor = descriptor;
3563 }
3564
3566
3568
3569 private:
3570 /**
3571 The members below must be kept aligned so that (1 << m_tableno) == m_map.
3572 A table that takes part in a join operation must be assigned a unique
3573 table number.
3574 */
3575 uint m_tableno{0}; ///< Table number within query block
3576 table_map m_map{0}; ///< Table map, derived from m_tableno
3577 /**
3578 If this table or join nest is the Y in "X [LEFT] JOIN Y ON C", this
3579 member points to C. May also be generated from JOIN ... USING clause.
3580 It may be modified only by permanent transformations (permanent = done
3581 once for all executions of a prepared statement).
3582 */
3585
3586 public:
3587 /*
3588 (Valid only for semi-join nests) Bitmap of tables that are within the
3589 semi-join (this is different from bitmap of all nest's children because
3590 tables that were pulled out of the semi-join nest remain listed as
3591 nest's children).
3592 */
3594
3595 /*
3596 During parsing - left operand of NATURAL/USING join where 'this' is
3597 the right operand. After parsing (this->natural_join == this) iff
3598 'this' represents a NATURAL or USING join operation. Thus after
3599 parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
3600 */
3602 /*
3603 True if 'this' represents a nested join that is a NATURAL JOIN.
3604 For one of the operands of 'this', the member 'natural_join' points
3605 to the other operand of 'this'.
3606 */
3607 bool is_natural_join{false};
3608 /* Field names in a USING clause for JOIN ... USING. */
3610 /*
3611 Explicitly store the result columns of either a NATURAL/USING join or
3612 an operand of such a join.
3613 */
3615 /* true if join_columns contains all columns of this table reference. */
3617
3618 /*
3619 List of nodes in a nested join tree, that should be considered as
3620 leaves with respect to name resolution. The leaves are: views,
3621 top-most nodes representing NATURAL/USING joins, subqueries, and
3622 base tables. All of these Table_ref instances contain a
3623 materialized list of columns. The list is local to a subquery.
3624 */
3626 /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
3628 TABLE *table{nullptr}; /* opened table */
3630 table_id{}; /* table id (from binlog) for opened table */
3631 /*
3632 Query_result for derived table to pass it from table creation to table
3633 filling procedure
3634 */
3636 /*
3637 Reference from aux_tables to local list entry of main select of
3638 multi-delete statement:
3639 delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
3640 here it will be reference of first occurrence of t1 to second (as you
3641 can see this lists can't be merged)
3642 */
3644
3645 /*
3646 Holds the function used as the table function
3647 */
3649
3650 /**
3651 If we've previously made an access path for “derived”, it is cached here.
3652 This is useful if we need to plan the query block twice (the hypergraph
3653 optimizer can do so, with and without in2exists predicates), both saving
3654 work and avoiding issues when we try to throw away the old items_to_copy
3655 for a new (identical) one.
3656 */
3658
3659 private:
3660 /**
3661 This field is set to non-null for derived tables and views. It points
3662 to the Query_expression representing the derived table/view.
3663 E.g. for a query
3664 @verbatim SELECT * FROM (SELECT a FROM t1) b @endverbatim
3665 */
3666 Query_expression *derived{nullptr}; /* Query_expression of derived table */
3667
3668 /// If non-NULL, the CTE which this table is derived from.
3670 /**
3671 If the user has specified column names with the syntaxes "table name
3672 parenthesis column names":
3673 WITH qn(column names) AS (select...)
3674 or
3675 FROM (select...) dt(column names)
3676 or
3677 CREATE VIEW v(column_names) AS ...
3678 then this points to the list of column names. NULL otherwise.
3679 */
3681
3682 public:
3683 ST_SCHEMA_TABLE *schema_table{nullptr}; /* Information_schema table */
3685 /*
3686 True when the view field translation table is used to convert
3687 schema table fields for backwards compatibility with SHOW command.
3688 */
3690 /* link to query_block where this table was used */
3692
3693 private:
3694 LEX *view{nullptr}; /* link on VIEW lex for merging */
3695
3696 public:
3697 /// Array of selected expressions from a derived table or view.
3699
3700 /// pointer to element after last one in translation table above
3702 /*
3703 List (based on next_local) of underlying tables of this view. I.e. it
3704 does not include the tables of subqueries used in the view. Is set only
3705 for merged views.
3706 */
3708 /*
3709 - 0 for base tables
3710 - in case of the view it is the list of all (not only underlying
3711 tables but also used in subquery ones) tables of the view.
3712 */
3714 /* most upper view this table belongs to */
3716 /*
3717 The view directly referencing this table
3718 (non-zero only for merged underlying tables of a view).
3719 */
3721 /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
3723 /*
3724 Security context (non-zero only for tables which belong
3725 to view with SQL SECURITY DEFINER)
3726 */
3728 /*
3729 This view security context (non-zero only for views with
3730 SQL SECURITY DEFINER)
3731 */
3733 /*
3734 List of all base tables local to a subquery including all view
3735 tables. Unlike 'next_local', this in this list views are *not*
3736 leaves. Created in setup_tables() -> make_leaf_tables().
3737 */
3739 Item *derived_where_cond{nullptr}; ///< WHERE condition from derived table
3740 Item *check_option{nullptr}; ///< WITH CHECK OPTION condition
3741 Item *replace_filter{nullptr}; ///< Filter for REPLACE command
3742 LEX_STRING select_stmt{nullptr, 0}; ///< text of (CREATE/SELECT) statement
3743 LEX_STRING source{nullptr, 0}; ///< source of CREATE VIEW
3744 LEX_STRING timestamp{nullptr, 0}; ///< GMT time stamp of last operation
3745 LEX_USER definer; ///< definer of view
3746 /**
3747 @note: This field is currently not reliable when read from dictionary:
3748 If an underlying view is changed, updatable_view is not changed,
3749 due to lack of dependency checking in dictionary implementation.
3750 Prefer to use is_updatable() during preparation and optimization.
3751 */
3752 ulonglong updatable_view{0}; ///< VIEW can be updated
3753 /**
3754 @brief The declared algorithm, if this is a view.
3755 @details One of
3756 - VIEW_ALGORITHM_UNDEFINED
3757 - VIEW_ALGORITHM_TEMPTABLE
3758 - VIEW_ALGORITHM_MERGE
3759 @todo Replace with an enum
3760 */
3762 ulonglong view_suid{0}; ///< view is suid (true by default)
3763 ulonglong with_check{0}; ///< WITH CHECK OPTION
3764
3765 private:
3766 /// The view algorithm that is actually used, if this is a view.
3769
3770 public:
3772
3773 public:
3774 /// True if right argument of LEFT JOIN; false in other cases (i.e. if left
3775 /// argument of LEFT JOIN, if argument of INNER JOIN; RIGHT JOINs are
3776 /// converted to LEFT JOIN during contextualization).
3777 bool outer_join{false};
3778 /// True if was originally the left argument of a RIGHT JOIN, before we
3779 /// made it the right argument of a LEFT JOIN.
3781 uint shared{0}; /* Used in multi-upd */
3782 size_t db_length{0};
3784
3785 private:
3786 /// True if VIEW/TABLE is updatable, based on analysis of query (SQL rules).
3787 bool m_updatable{false};
3788 /// True if VIEW/TABLE is insertable, based on analysis of query (SQL rules).
3789 bool m_insertable{false};
3790 /// True if table is target of UPDATE statement, or updated in IODKU stmt.
3791 bool m_updated{false};
3792 /// True if table is target of INSERT statement.
3793 bool m_inserted{false};
3794 /// True if table is target of DELETE statement, or deleted in REPLACE stmt.
3795 bool m_deleted{false};
3796 bool m_fulltext_searched{false}; ///< True if fulltext searched
3797 public:
3798 bool straight{false}; /* optimize with prev table */
3799 /**
3800 True for tables and views being changed in a data change statement.
3801 Also true for tables subject to a SELECT ... FOR UPDATE.
3802 Also used by replication to filter out statements that can be ignored,
3803 especially important for multi-table UPDATE and DELETE.
3804 */
3805 bool updating{false};
3806 /// preload only non-leaf nodes (IS THIS USED???)
3807 bool ignore_leaves{false};
3808 /**
3809 The set of tables in the query block that this table depends on.
3810 Can be set due to outer join, join order hints or NOT EXISTS relationship.
3811 */
3813 /// The outer tables that an outer join's join condition depends on
3815 /**
3816 Is non-NULL if this table reference is a nested join, ie it represents
3817 the inner tables of an outer join, the tables contained in the
3818 parentheses of an inner join (eliminated during resolving), the tables
3819 referenced in a derived table or view, in a semi-join nest, the tables
3820 from the subquery.
3821 */
3823 /// The nested join containing this table reference.
3825 /// The join list immediately containing this table reference
3827 /// stop PS caching
3828 bool cacheable_table{false};
3829 /**
3830 Specifies which kind of table should be open for this element
3831 of table list.
3832 */
3834 /* true if this merged view contain auto_increment field */
3836 /// true <=> VIEW CHECK OPTION condition is processed (also for prep. stmts)
3838 /// true <=> Filter condition is processed
3840
3842 char timestamp_buffer[20]{0}; /* buffer for timestamp (19+1) */
3843 /*
3844 This Table_ref object is just placeholder for prelocking, it will be
3845 used for implicit LOCK TABLES only and won't be used in real statement.
3846 */
3848 /**
3849 Indicates that if Table_ref object corresponds to the table/view
3850 which requires special handling.
3851 */
3852 enum {
3853 /* Normal open. */
3855 /* Associate a table share only if the the table exists. */
3857 /*
3858 Associate a table share only if the the table exists.
3859 Also upgrade metadata lock to exclusive if table doesn't exist.
3860 */
3862 /* Don't associate a table share. */
3863 OPEN_STUB
3864 } open_strategy{OPEN_NORMAL};
3866 /** true if an alias for this table was specified in the SQL. */
3867 bool is_alias{false};
3868 /** true if the table is referred to in the statement using a fully
3869 qualified name (@<db_name@>.@<table_name@>).
3870 */
3871 bool is_fqtn{false};
3872 /**
3873 If true, this table is a derived (materialized) table which was created
3874 from a scalar subquery, cf.
3875 Query_block::transform_scalar_subqueries_to_join_with_derived
3876 */
3878
3879 /* View creation context. */
3880
3882
3883 /*
3884 Attributes to save/load view creation context in/from frm-file.
3885
3886 They are required only to be able to use existing parser to load
3887 view-definition file. As soon as the parser parsed the file, view
3888 creation context is initialized and the attributes become redundant.
3889
3890 These attributes MUST NOT be used for any purposes but the parsing.
3891 */
3892
3895
3896 /*
3897 View definition (SELECT-statement) in the UTF-form.
3898 */
3899
3901
3902 // True, If this is a system view
3903 bool is_system_view{false};
3904
3905 /*
3906 Set to 'true' if this is a DD table being opened in the context of a
3907 dictionary operation. Note that when 'false', this may still be a DD
3908 table when opened in a non-DD context, e.g. as part of an I_S view
3909 query.
3910 */
3911 bool is_dd_ctx_table{false};
3912
3913 /* End of view definition context. */
3914
3915 /* List of possible keys. Valid only for materialized derived tables/views. */
3917
3918 /**
3919 Indicates what triggers we need to pre-load for this Table_ref
3920 when opening an associated TABLE. This is filled after
3921 the parsed tree is created.
3922 */
3925
3927
3928 /// if true, EXPLAIN can't explain view due to insufficient rights.
3929 bool view_no_explain{false};
3930
3931 /* List to carry partition names from PARTITION (...) clause in statement */
3933
3934 /// Set table number
3936 assert(tableno < MAX_TABLES);
3938 m_map = (table_map)1 << tableno;
3939 }
3940 /// Return table number
3941 uint tableno() const { return m_tableno; }
3942
3943 /// Return table map derived from table number
3944 table_map map() const {
3945 assert(((table_map)1 << m_tableno) == m_map);
3946 return m_map;
3947 }
3948
3949 /// If non-NULL, the CTE which this table is derived from.
3952 /// @see m_derived_column_names
3955 }
3958 }
3959
3960 private:
3961 /*
3962 A group of members set and used only during JOIN::optimize().
3963 */
3964 /**
3965 Optimized copy of m_join_cond (valid for one single
3966 execution). Initialized by Query_block::get_optimizable_conditions().
3967 */
3969
3970 public:
3971 COND_EQUAL *cond_equal{nullptr}; ///< Used with outer join
3972 /// true <=> this table is a const one and was optimized away.
3973
3974 bool optimized_away{false};
3975 /**
3976 true <=> all possible keys for a derived table were collected and
3977 could be re-used while statement re-execution.
3978 */
3979
3981
3982 private:
3983 /// If a recursive reference inside the definition of a CTE.
3985 // End of group for optimization
3986
3987 /** See comments for set_metadata_id() */
3989 /** See comments for TABLE_SHARE::get_table_ref_version() */
3991
3992 /*
3993 All members whose names are suffixed with "_saved" are duplicated in
3994 class TABLE but actually belong in this class. They are saved from class
3995 TABLE when preparing a statement and restored when executing the statement.
3996 They are not required for a regular (non-prepared) statement.
3997 */
4003 bool nullable_saved{false};
4011};
4012
4013/*
4014 Iterator over the fields of a generic table reference.
4015*/
4016
4018 public:
4019 virtual ~Field_iterator() = default;
4020 virtual void set(Table_ref *) = 0;
4021 virtual void next() = 0;
4022 virtual bool end_of_fields() = 0; /* Return 1 at end of list */
4023 virtual const char *name() = 0;
4024 virtual Item *create_item(THD *) = 0;
4025 virtual Field *field() = 0;
4026};
4027
4028/*
4029 Iterator over the fields of a base table, view with temporary
4030 table, or subquery.
4031*/
4032
4035
4036 public:
4038 void set(Table_ref *table) override { ptr = table->table->field; }
4039 void set_table(TABLE *table) { ptr = table->field; }
4040 void next() override { ptr++; }
4041 bool end_of_fields() override { return *ptr == nullptr; }
4042 const char *name() override;
4043 Item *create_item(THD *thd) override;
4044 Field *field() override { return *ptr; }
4045};
4046
4047/**
4048 Iterator over the fields of a merged derived table or view.
4049*/
4050
4054
4055 public:
4057 void set(Table_ref *table) override;
4058 void next() override { ptr++; }
4059 bool end_of_fields() override { return ptr == array_end; }
4060 const char *name() override;
4061 Item *create_item(THD *thd) override;
4062 Item **item_ptr() { return &ptr->item; }
4063 Field *field() override { return nullptr; }
4064 inline Item *item() { return ptr->item; }
4066};
4067
4068/*
4069 Field_iterator interface to the list of materialized fields of a
4070 NATURAL/USING join.
4071*/
4072
4076
4077 public:
4079 ~Field_iterator_natural_join() override = default;
4080 void set(Table_ref *table) override;
4081 void next() override;
4082 bool end_of_fields() override { return !cur_column_ref; }
4083 const char *name() override { return cur_column_ref->name(); }
4084 Item *create_item(THD *thd) override {
4085 return cur_column_ref->create_item(thd);
4086 }
4087 Field *field() override { return cur_column_ref->field(); }
4089};
4090
4091/**
4092 Generic iterator over the fields of an arbitrary table reference.
4093
4094 This class unifies the various ways of iterating over the columns
4095 of a table reference depending on the type of SQL entity it
4096 represents. If such an entity represents a nested table reference,
4097 this iterator encapsulates the iteration over the columns of the
4098 members of the table reference.
4099
4100 The implementation assumes that all underlying NATURAL/USING table
4101 references already contain their result columns and are linked into
4102 the list Table_ref::next_name_resolution_table.
4103*/
4104
4111 void set_field_iterator();
4112
4113 public:
4115 void set(Table_ref *table) override;
4116 void next() override;
4117 bool end_of_fields() override {
4118 return (table_ref == last_leaf && field_it->end_of_fields());
4119 }
4120 const char *name() override { return field_it->name(); }
4121 const char *get_table_name();
4122 const char *get_db_name();
4123 GRANT_INFO *grant();
4124 Item *create_item(THD *thd) override { return field_it->create_item(thd); }
4125 Field *field() override { return field_it->field(); }
4127 Table_ref *parent_table_ref);
4129};
4130
4133 char *db, *table;
4135};
4136
4138 MY_BITMAP *bitmap) {
4139 my_bitmap_map *old = bitmap->bitmap;
4140 bitmap->bitmap = table->s->all_set.bitmap; // does not repoint last_word_ptr
4141 return old;
4142}
4143
4144static inline void tmp_restore_column_map(MY_BITMAP *bitmap,
4145 my_bitmap_map *old) {
4146 bitmap->bitmap = old;
4147}
4148
4149/* The following is only needed for debugging */
4150
4152 [[maybe_unused]],
4153 MY_BITMAP *bitmap
4154 [[maybe_unused]]) {
4155#ifndef NDEBUG
4156 return tmp_use_all_columns(table, bitmap);
4157#else
4158 return nullptr;
4159#endif
4160}
4161
4162static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap
4163 [[maybe_unused]],
4164 my_bitmap_map *old
4165 [[maybe_unused]]) {
4166#ifndef NDEBUG
4167 tmp_restore_column_map(bitmap, old);
4168#endif
4169}
4170
4171/*
4172 Variant of the above : handle both read and write sets.
4173 Provide for the possibility of the read set being the same as the write set
4174*/
4175static inline void dbug_tmp_use_all_columns(
4176 TABLE *table [[maybe_unused]], my_bitmap_map **save [[maybe_unused]],
4177 MY_BITMAP *read_set [[maybe_unused]],
4178 MY_BITMAP *write_set [[maybe_unused]]) {
4179#ifndef NDEBUG
4180 save[0] = read_set->bitmap;
4181 save[1] = write_set->bitmap;
4182 (void)tmp_use_all_columns(table, read_set);
4183 (void)tmp_use_all_columns(table, write_set);
4184#endif
4185}
4186
4188 MY_BITMAP *read_set [[maybe_unused]], MY_BITMAP *write_set [[maybe_unused]],
4189 my_bitmap_map **old [[maybe_unused]]) {
4190#ifndef NDEBUG
4191 tmp_restore_column_map(read_set, old[0]);
4192 tmp_restore_column_map(write_set, old[1]);
4193#endif
4194}
4195
4196void init_mdl_requests(Table_ref *table_list);
4197
4198/**
4199 Unpacks the definition of a value generator in all its forms: generated
4200 column, default expression or checked constraint.
4201 The function parses the text definition of this expression, resolves its
4202 items and runs validation and calculates the base_columns_map which is used
4203 for tracking the columns the expression depends on.
4204
4205 @param[in] thd Thread handler
4206 @param[in] table Table having the value generator to be unpacked
4207 @param[in,out] val_generator Contains the expression in string format, and,
4208 if successful will be replaced by the parser
4209 with a new one having the unpacked expression.
4210 @param[in] source Source of value generator(a generated column,
4211 a regular column with generated default value or
4212 a check constraint).
4213 @param[in] source_name Name of the source (generated column, a regular
4214 column with generated default value or a check
4215 constraint).
4216 @param[in] field The column the value generator depends on. Can
4217 be null for checked constraints which do not
4218 depend on a single column.
4219 @param[in] is_create_table Indicates that table is opened as part
4220 of CREATE or ALTER and does not yet exist in SE
4221 @param[out] error_reported updated flag for the caller that no other error
4222 messages are to be generated.
4223
4224 @retval true Failure.
4225 @retval false Success.
4226*/
4227
4229 Value_generator **val_generator,
4231 const char *source_name, Field *field,
4232 bool is_create_table, bool *error_reported);
4233
4234/**
4235 Unpack the partition expression. Parse the partition expression
4236 to produce an Item.
4237
4238 @param[in] thd Thread handler
4239 @param[in] outparam Table object
4240 @param[in] share TABLE_SHARE object
4241 @param[in] engine_type Engine type of the partitions.
4242 @param[in] is_create_table Indicates that table is opened as part of
4243 CREATE or ALTER and does not yet exist in SE
4244
4245 @retval true Failure.
4246 @retval false Success.
4247*/
4248
4249bool unpack_partition_info(THD *thd, TABLE *outparam, TABLE_SHARE *share,
4250 handlerton *engine_type, bool is_create_table);
4251
4252int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
4253 uint db_stat, uint prgflag, uint ha_open_flags,
4254 TABLE *outparam, bool is_create_table,
4255 const dd::Table *table_def_param);
4256TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
4257 const char *key, size_t key_length,
4258 bool open_secondary);
4259void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
4260 size_t key_length, const char *table_name,
4261 const char *path, MEM_ROOT *mem_root);
4262void free_table_share(TABLE_SHARE *share);
4264Ident_name_check check_db_name(const char *name, size_t length);
4266 bool preserve_lettercase);
4267bool check_column_name(const char *name);
4268Ident_name_check check_table_name(const char *name, size_t length);
4269int rename_file_ext(const char *from, const char *to, const char *ext);
4270char *get_field(MEM_ROOT *mem, Field *field);
4271bool get_field(MEM_ROOT *mem, Field *field, class String *res);
4272
4273int closefrm(TABLE *table, bool free_share);
4274void free_blobs(TABLE *table);
4276int set_zone(int nr, int min_zone, int max_zone);
4277void append_unescaped(String *res, const char *pos, size_t length);
4278char *fn_rext(char *name);
4280 const LEX_CSTRING &name);
4281
4282/* performance schema */
4284
4287
4288/* information schema */
4290
4291/* mysql schema name and DD ID */
4293static const uint MYSQL_SCHEMA_DD_ID = 1;
4294
4295/* mysql tablespace name and DD ID */
4297static const uint MYSQL_TABLESPACE_DD_ID = 1;
4298
4299/* replication's tables */
4303
4304inline bool is_infoschema_db(const char *name, size_t len) {
4305 return (
4308}
4309
4310inline bool is_infoschema_db(const char *name) {
4312}
4313
4314inline bool is_perfschema_db(const char *name, size_t len) {
4315 return (PERFORMANCE_SCHEMA_DB_NAME.length == len &&
4317 name));
4318}
4319
4320inline bool is_perfschema_db(const char *name) {
4322 name);
4323}
4324
4325/**
4326 Check if the table belongs to the P_S, excluding setup and threads tables.
4327
4328 @note Performance Schema tables must be accessible independently of the
4329 LOCK TABLE mode. This function is needed to handle the special case
4330 of P_S tables being used under LOCK TABLE mode.
4331*/
4332inline bool belongs_to_p_s(Table_ref *tl) {
4333 return (!strcmp("performance_schema", tl->db) &&
4334 strcmp(tl->table_name, "threads") &&
4335 strstr(tl->table_name, "setup_") == nullptr);
4336}
4337
4338/**
4339 return true if the table was created explicitly.
4340*/
4342 const char *name = table->s->table_name.str;
4344}
4345
4346bool is_simple_order(ORDER *order);
4347
4348uint add_pk_parts_to_sk(KEY *sk, uint sk_n, KEY *pk, uint pk_n,
4349 TABLE_SHARE *share, handler *handler_file,
4350 uint *usable_parts, bool use_extended_sk);
4351void setup_key_part_field(TABLE_SHARE *share, handler *handler_file,
4352 uint primary_key_n, KEY *keyinfo, uint key_n,
4353 uint key_part_n, uint *usable_parts,
4354 bool part_of_key_not_extended);
4355
4356const uchar *get_field_name(const uchar *arg, size_t *length);
4357
4358void repoint_field_to_record(TABLE *table, uchar *old_rec, uchar *new_rec);
4361 uint active_index = MAX_KEY);
4362
4363/**
4364 Check if a Table_ref instance represents a pre-opened temporary table.
4365*/
4366
4367inline bool is_temporary_table(const Table_ref *tl) {
4368 if (tl->is_view() || tl->schema_table) return false;
4369
4370 if (!tl->table) return false;
4371
4372 /*
4373 NOTE: 'table->s' might be NULL for specially constructed TABLE
4374 instances. See SHOW TRIGGERS for example.
4375 */
4376
4377 if (!tl->table->s) return false;
4378
4379 return tl->table->s->tmp_table != NO_TMP_TABLE;
4380}
4381
4382/**
4383 After parsing, a Common Table Expression is accessed through a
4384 Table_ref. This class contains all information about the CTE which the
4385 Table_ref needs.
4386
4387 @note that before and during parsing, the CTE is described by a
4388 PT_common_table_expr.
4389*/
4391 public:
4394 TABLE *clone_tmp_table(THD *thd, Table_ref *tl);
4396 /// Remove one table reference.
4397 void remove_table(Table_ref *tr);
4398 /// Empties the materialized CTE and informs all of its clones.
4399 bool clear_all_references();
4400 /**
4401 All references to this CTE in the statement, except those inside the
4402 query expression defining this CTE.
4403 In other words, all non-recursive references.
4404 */
4406 /// True if it's a recursive CTE
4408 /**
4409 List of all TABLE_LISTSs reading/writing to the tmp table created to
4410 materialize this CTE. Due to shared materialization, only the first one
4411 has a TABLE generated by create_tmp_table(); other ones have a TABLE
4412 generated by open_table_from_share().
4413 */
4415 /// Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
4417};
4418
4419/**
4420 This iterates on those references to a derived table / view / CTE which are
4421 materialized. If a recursive CTE, this includes recursive references.
4422 Upon construction it is passed a non-recursive materialized reference
4423 to the derived table (Table_ref*).
4424 For a CTE it may return more than one reference; for a derived table or a
4425 view, there is only one (as references to a same view are treated as
4426 independent objects).
4427 References are returned as TABLE*.
4428*/
4430 Table_ref *const start; ///< The reference provided in construction.
4431 size_t ref_idx{0}; ///< Current index in cte->tmp_tables
4432 bool m_is_first{true}; ///< True when at first reference in list
4433 public:
4434 explicit Derived_refs_iterator(Table_ref *start_arg) : start(start_arg) {}
4437 m_is_first = ref_idx == 0;
4438 // Derived tables and views have a single reference.
4439 if (cte == nullptr) {
4440 return ref_idx++ == 0 ? start->table : nullptr;
4441 }
4442 /*
4443 CTEs may have multiple references. Return the next one, but notice that
4444 some references may have been deleted.
4445 */
4446 while (ref_idx < cte->tmp_tables.size()) {
4447 TABLE *table = cte->tmp_tables[ref_idx++]->table;
4448 if (table != nullptr) return table;
4449 }
4450 return nullptr;
4451 }
4452 void rewind() {
4453 ref_idx = 0;
4454 m_is_first = true;
4455 }
4456 /// @returns true if the last get_next() returned the first element.
4457 bool is_first() const {
4458 // Call after get_next() has been called:
4459 assert(ref_idx > 0);
4460 return m_is_first;
4461 }
4462};
4463
4464/**
4465 RAII class to reset TABLE::autoinc_field_has_explicit_non_null_value after
4466 processing individual row in INSERT or LOAD DATA statements.
4467*/
4469 public:
4471 : m_table(table) {}
4474 }
4475
4476 private:
4478};
4479
4480// Whether we can ask the storage engine for the row ID of the last row read.
4481//
4482// Some operations needs a row ID to operate correctly (i.e. weedout). Normally,
4483// the row ID is provided by the storage engine by calling handler::position().
4484// But there are cases when position() should not be called:
4485//
4486// 1. If we have a const table (rows are fetched during optimization), we
4487// should not call position().
4488// 2. If we have a NULL-complemented row, calling position() would give a
4489// random row ID back, as there has not been any row read.
4490//
4491// Operations that needs the row ID must also check the value of
4492// QEP_TAB::rowid_status to see whether they actually need a row ID.
4493// See QEP_TAB::rowid_status for more details.
4494inline bool can_call_position(const TABLE *table) {
4495 return !table->const_table && !(table->is_nullable() && table->null_row);
4496}
4497
4498//////////////////////////////////////////////////////////////////////////
4499
4500/*
4501 NOTE:
4502 These structures are added to read .frm file in upgrade scenario.
4503
4504 They should not be used any where else in the code.
4505 They will be removed in future release.
4506 Any new code should not be added in this section.
4507*/
4508
4509/**
4510 These members were removed from TABLE_SHARE as they are not used in
4511 in the code. open_binary_frm() uses these members while reading
4512 .frm files.
4513*/
4515 public:
4518 null_field_first(false),
4519 stored_fields(0),
4521 frm_version(0),
4522 fieldnames() {}
4523
4526 uint stored_fields; /* Number of stored fields
4527 (i.e. without generated-only ones) */
4528
4529 enum utype {
4542 EMPTY_VAL, // EMPTY_VAL rather than EMPTY since EMPTY can conflict with
4543 // system headers.
4555 GENERATED_FIELD = 128
4557
4558 /**
4559 For shares representing views File_parser object with view
4560 definition read from .FRM file.
4561 */
4564 TYPELIB fieldnames; /* Pointer to fieldnames */
4565};
4566
4567/**
4568 Create TABLE_SHARE from .frm file.
4569
4570 FRM_context object is used to store the value removed from
4571 TABLE_SHARE. These values are used only for .frm file parsing.
4572
4573 @param[in] thd Thread handle.
4574 @param[in] path Path of the frm file.
4575 @param[out] share TABLE_SHARE to be populated.
4576 @param[out] frm_context FRM_context object.
4577 @param[in] db Database name.
4578 @param[in] table Table name.
4579 @param[in] is_fix_view_cols_and_deps Fix view column data, table
4580 and routine dependency.
4581
4582 @retval 0 ON SUCCESS
4583 @retval -1 ON FAILURE
4584 @retval -2 ON LESS SEVER FAILURE (see read_frm_file)
4585*/
4586int create_table_share_for_upgrade(THD *thd, const char *path,
4587 TABLE_SHARE *share, FRM_context *frm_context,
4588 const char *db, const char *table,
4589 bool is_fix_view_cols_and_deps);
4590//////////////////////////////////////////////////////////////////////////
4591
4592/**
4593 Create a copy of the key_info from TABLE_SHARE object to TABLE object.
4594
4595 Wherever prefix key is present, allocate a new Field object, having its
4596 field_length set to the prefix key length, and point the table's matching
4597 key_part->field to this new Field object.
4598
4599 This ensures that unpack_partition_info() reads the correct prefix length of
4600 partitioned fields
4601
4602 @param table Table for which key_info is to be allocated
4603 @param root MEM_ROOT in which to allocate key_info
4604
4605 @retval false Success
4606 @retval true Failed to allocate memory for table.key_info in root
4607*/
4608
4610
4611#endif /* TABLE_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:250
int64 query_id_t
Definition: binlog.h:71
Per internal schema ACL access rules.
Definition: auth_common.h:143
Per internal table ACL access rules.
Definition: auth_common.h:105
RAII class to reset TABLE::autoinc_field_has_explicit_non_null_value after processing individual row ...
Definition: table.h:4468
Autoinc_field_has_explicit_non_null_value_reset_guard(TABLE *table)
Definition: table.h:4470
~Autoinc_field_has_explicit_non_null_value_reset_guard()
Definition: table.h:4472
Class that represents a single change to a column value in partial update of a JSON column.
Definition: table.h:1320
const char * old_data(const Field *field) const
Get a pointer to the start of the old data to be replaced.
Definition: table.cc:7716
size_t length() const
Definition: table.h:1341
size_t m_length
The size of the portion that is to be replaced.
Definition: table.h:1325
const char * new_data(const Field *field) const
Get a pointer to the start of the replacement data.
Definition: table.cc:7707
Binary_diff(size_t offset, size_t length)
Create a new Binary_diff object.
Definition: table.h:1334
size_t m_offset
The offset of the start of the change.
Definition: table.h:1322
size_t offset() const
Definition: table.h:1338
Definition: sql_bitmap.h:153
Class is used as a BLOB field value storage for intermediate GROUP_CONCAT results.
Definition: table.h:1280
bool truncated_value
Sign that some values were cut during saving into the storage.
Definition: table.h:1287
Blob_mem_storage()
Definition: table.cc:4090
void reset()
Definition: table.h:1293
void set_truncated_value(bool is_truncated_value)
Definition: table.h:1310
MEM_ROOT storage
Definition: table.h:1282
~Blob_mem_storage()
Definition: table.cc:4094
bool is_truncated_value() const
Definition: table.h:1313
char * store(const char *from, size_t length)
Function creates duplicate of 'from' string in 'storage' MEM_ROOT.
Definition: table.h:1307
Definition: item_cmpfunc.h:2725
After parsing, a Common Table Expression is accessed through a Table_ref.
Definition: table.h:4390
Common_table_expr(MEM_ROOT *mem_root)
Definition: table.h:4392
LEX_STRING name
Name of the WITH block. Used only for EXPLAIN FORMAT=tree.
Definition: table.h:4416
TABLE * clone_tmp_table(THD *thd, Table_ref *tl)
Produces, from the first tmp TABLE object, a clone TABLE object for Table_ref 'tl',...
Definition: sql_derived.cc:169
bool clear_all_references()
Empties the materialized CTE and informs all of its clones.
Definition: sql_union.cc:1592
bool recursive
True if it's a recursive CTE.
Definition: table.h:4407
Mem_root_array< Table_ref * > references
All references to this CTE in the statement, except those inside the query expression defining this C...
Definition: table.h:4405
void remove_table(Table_ref *tr)
Remove one table reference.
Definition: sql_derived.cc:252
bool substitute_recursive_reference(THD *thd, Query_block *sl)
Replaces the recursive reference in query block 'sl' with a clone of the first tmp table.
Definition: sql_derived.cc:239
Mem_root_array< Table_ref * > tmp_tables
List of all TABLE_LISTSs reading/writing to the tmp table created to materialize this CTE.
Definition: table.h:4414
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:53
API for getting cost estimates for operations on table data.
Definition: opt_costmodel.h:241
void init(const Cost_model_server *cost_model_server, const TABLE *table)
Initializes the cost model object.
Definition: opt_costmodel.cc:67
Default_object_creation_ctx – default implementation of Object_creation_ctx.
Definition: table.h:222
const CHARSET_INFO * get_client_cs()
Definition: table.h:224
void change_env(THD *thd) const override
Definition: table.cc:218
void delete_backup_ctx() override
Definition: table.cc:216
Default_object_creation_ctx(THD *thd)
Definition: table.cc:203
const CHARSET_INFO * get_connection_cl()
Definition: table.h:226
Object_creation_ctx * create_backup_ctx(THD *thd) const override
Definition: table.cc:211
const CHARSET_INFO * m_connection_cl
connection_cl stores the value of collation_connection session variable.
Definition: table.h:260
const CHARSET_INFO * m_client_cs
client_cs stores the value of character_set_client session variable.
Definition: table.h:250
This structure is used to keep info about possible key for the result table of a derived table/view.
Definition: table.h:2811
table_map referenced_by
Definition: table.h:2813
Field_map used_fields
Definition: table.h:2814
uint key_part_count
Definition: table.h:2815
This iterates on those references to a derived table / view / CTE which are materialized.
Definition: table.h:4429
bool is_first() const
Definition: table.h:4457
TABLE * get_next()
Definition: table.h:4435
Table_ref *const start
The reference provided in construction.
Definition: table.h:4430
Derived_refs_iterator(Table_ref *start_arg)
Definition: table.h:4434
bool m_is_first
True when at first reference in list.
Definition: table.h:4432
size_t ref_idx
Current index in cte->tmp_tables.
Definition: table.h:4431
void rewind()
Definition: table.h:4452
These members were removed from TABLE_SHARE as they are not used in in the code.
Definition: table.h:4514
utype
Definition: table.h:4529
@ CASEUP
Definition: table.h:4534
@ NO
Definition: table.h:4539
@ NONE
Definition: table.h:4530
@ REL
Definition: table.h:4540
@ NEXT_NUMBER
Definition: table.h:4546
@ DATE
Definition: table.h:4531
@ PNR
Definition: table.h:4535
@ BIT_FIELD
Definition: table.h:4548
@ TIMESTAMP_OLD_FIELD
Definition: table.h:4549
@ GENERATED_FIELD
Definition: table.h:4555
@ INTERVAL_FIELD
Definition: table.h:4547
@ TIMESTAMP_UN_FIELD
Definition: table.h:4553
@ NOEMPTY
Definition: table.h:4533
@ CHECK
Definition: table.h:4541
@ YES
Definition: table.h:4538
@ TIMESTAMP_DNUN_FIELD
Definition: table.h:4554
@ BLOB_FIELD
Definition: table.h:4551
@ UNKNOWN_FIELD
Definition: table.h:4544
@ CASEDN
Definition: table.h:4545
@ TIMESTAMP_DN_FIELD
Definition: table.h:4552
@ PGNR
Definition: table.h:4537
@ EMPTY_VAL
Definition: table.h:4542
@ CAPITALIZE
Definition: table.h:4550
@ SHIELD
Definition: table.h:4532
@ BGNR
Definition: table.h:4536
bool null_field_first
Definition: table.h:4525
uchar frm_version
Definition: table.h:4563
handlerton * default_part_db_type
Definition: table.h:4524
TYPELIB fieldnames
Definition: table.h:4564
const File_parser * view_def
For shares representing views File_parser object with view definition read from .FRM file.
Definition: table.h:4562
uint stored_fields
Definition: table.h:4526
FRM_context()
Definition: table.h:4516
Definition: table.h:4073
~Field_iterator_natural_join() override=default
Natural_join_column * column_ref()
Definition: table.h:4088
void next() override
Definition: table.cc:5150
void set(Table_ref *table) override
Definition: table.cc:5144
Natural_join_column * cur_column_ref
Definition: table.h:4075
Field_iterator_natural_join()
Definition: table.h:4078
const char * name() override
Definition: table.h:4083
List_iterator_fast< Natural_join_column > column_ref_it
Definition: table.h:4074
bool end_of_fields() override
Definition: table.h:4082
Item * create_item(THD *thd) override
Definition: table.h:4084
Field * field() override
Definition: table.h:4087
Generic iterator over the fields of an arbitrary table reference.
Definition: table.h:4105
Field_iterator * field_it
Definition: table.h:4110
Field_iterator_view view_field_it
Definition: table.h:4108
Table_ref * table_ref
Definition: table.h:4106
const char * get_table_name()
Definition: table.cc:5223
Field * field() override
Definition: table.h:4125
const char * get_db_name()
Definition: table.cc:5230
Field_iterator_table_ref()
Definition: table.h:4114
void set(Table_ref *table) override
Definition: table.cc:5200
Natural_join_column * get_or_create_column_ref(THD *thd, Table_ref *parent_table_ref)
Create new or return existing column reference to a column of a natural/using join.
Definition: table.cc:5291
Table_ref * first_leaf
Definition: table.h:4106
GRANT_INFO * grant()
Definition: table.cc:5250
void next() override
Definition: table.cc:5209
Field_iterator_table table_field_it
Definition: table.h:4107
Table_ref * last_leaf
Definition: table.h:4106
const char * name() override
Definition: table.h:4120
Natural_join_column * get_natural_column_ref()
Return an existing reference to a column of a natural/using join.
Definition: table.cc:5371
void set_field_iterator()
Definition: table.cc:5157
Item * create_item(THD *thd) override
Definition: table.h:4124
bool end_of_fields() override
Definition: table.h:4117
Field_iterator_natural_join natural_join_it
Definition: table.h:4109
Definition: table.h:4033
const char * name() override
Definition: table.cc:5067
Field ** ptr
Definition: table.h:4034
Item * create_item(THD *thd) override
Definition: table.cc:5069
void set_table(TABLE *table)
Definition: table.h:4039
void next() override
Definition: table.h:4040
Field_iterator_table()
Definition: table.h:4037
bool end_of_fields() override
Definition: table.h:4041
void set(Table_ref *table) override
Definition: table.h:4038
Field * field() override
Definition: table.h:4044
Iterator over the fields of a merged derived table or view.
Definition: table.h:4051
void next() override
Definition: table.h:4058
Item * item()
Definition: table.h:4064
Table_ref * view
Definition: table.h:4053
Field_iterator_view()
Definition: table.h:4056
Field_translator * field_translator()
Definition: table.h:4065
Item ** item_ptr()
Definition: table.h:4062
void set(Table_ref *table) override
Definition: table.cc:5060
Field * field() override
Definition: table.h:4063
Field_translator * array_end
Definition: table.h:4052
Item * create_item(THD *thd) override
Definition: table.cc:5087
const char * name() override
Definition: table.cc:5085
Field_translator * ptr
Definition: table.h:4052
bool end_of_fields() override
Definition: table.h:4059
Definition: table.h:4017
virtual const char * name()=0
virtual Field * field()=0
virtual void next()=0
virtual void set(Table_ref *)=0
virtual ~Field_iterator()=default
virtual Item * create_item(THD *)=0
virtual bool end_of_fields()=0
A field that stores a JSON value.
Definition: field.h:3990
Definition: field.h:2391
Definition: field.h:574
Definition: parse_file.h:86
Definition: sql_auth_cache.h:463
Base class to be used by handlers different shares.
Definition: handler.h:4090
Intrusive parameterized list.
Definition: sql_plist.h:74
Definition: sql_lex.h:487
Definition: item.h:4340
A wrapper Item that normally returns its parameter, but becomes NULL when processing rows for rollup.
Definition: item_func.h:1671
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
Query optimization plan node.
Definition: sql_select.h:601
Vector of logical diffs describing changes to a JSON column.
Definition: json_diff.h:140
A path expression which can be used to seek to a position inside a JSON value.
Definition: json_path.h:297
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1161
Definition: key.h:56
Definition: key.h:112
ulong flags
dupp key and pack flags
Definition: key.h:117
Definition: sql_list.h:594
Definition: sql_list.h:434
Context of the owner of metadata locks.
Definition: mdl.h:1411
A pending metadata lock request.
Definition: mdl.h:801
void set_type(enum_mdl_type type_arg)
Set type of lock request.
Definition: mdl.h:852
A granted metadata lock.
Definition: mdl.h:984
An abstract class for inspection of a connected subgraph of the wait-for graph.
Definition: mdl.h:919
Abstract class representing an edge in the waiters graph to be traversed by deadlock detection algori...
Definition: mdl.h:945
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
Definition: table.h:2575
Item * create_item(THD *thd)
Definition: table.cc:5021
Item_field * table_field
Definition: table.h:2578
Field_translator * view_field
Definition: table.h:2577
Natural_join_column(Field_translator *field_param, Table_ref *tab)
Definition: table.cc:4989
const char * name()
Definition: table.cc:5012
Table_ref * table_ref
Definition: table.h:2579
bool is_common
Definition: table.h:2587
const char * db_name()
Definition: table.cc:5044
GRANT_INFO * grant()
Definition: table.cc:5058
Field * field()
Definition: table.cc:5031
const char * table_name()
Definition: table.cc:5039
Object_creation_ctx – interface for creation context of database objects (views, stored routines,...
Definition: table.h:198
void restore_env(THD *thd, Object_creation_ctx *backup_ctx)
Definition: table.cc:191
Object_creation_ctx()=default
virtual Object_creation_ctx * create_backup_ctx(THD *thd) const =0
virtual void change_env(THD *thd) const =0
virtual void delete_backup_ctx()=0
virtual ~Object_creation_ctx()=default
Object_creation_ctx * set_n_backup(THD *thd)
Definition: table.cc:181
Query block level hints.
Definition: opt_hints.h:371
Table level hints.
Definition: opt_hints.h:548
Definition: sql_executor.h:253
uint index() const
Definition: sql_opt_exec_shared.h:521
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1161
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:624
Definition: sql_union.h:39
This class represents a buffer that can be used for multi-row reads.
Definition: record_buffer.h:46
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:52
Definition: sql_sort.h:155
An adapter that takes in another RowIterator and produces the same rows, just in sorted order.
Definition: sorting_iterator.h:55
Class to represent check constraint in the TABLE_SHARE.
Definition: sql_check_constraint.h:109
Class to represent check constraint in the TABLE instance.
Definition: sql_check_constraint.h:144
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Element that represents the table in the specific table cache.
Definition: table_cache.h:230
Definition: table.h:603
Table_check_intact()
Definition: table.h:609
bool has_keys
Definition: table.h:605
virtual void report_error(uint code, const char *fmt,...)=0
bool check(THD *thd, TABLE *table, const TABLE_FIELD_DEF *table_def)
Checks whether a table is intact.
Definition: table.cc:3757
virtual ~Table_check_intact()=default
Class representing a table function.
Definition: table_function.h:52
The Table_histograms_collection manages a collection of reference-counted snapshots of histogram stat...
Definition: table_histograms.h:238
The Table_histograms class represents a snapshot of the collection of histograms associated with a ta...
Definition: table_histograms.h:144
Definition: table.h:2853
bool m_inserted
True if table is target of INSERT statement.
Definition: table.h:3793
LEX_STRING view_body_utf8
Definition: table.h:3900
bool force_index_group_saved
Definition: table.h:4006
bool view_no_explain
if true, EXPLAIN can't explain view due to insufficient rights.
Definition: table.h:3929
Common_table_expr * m_common_table_expr
If non-NULL, the CTE which this table is derived from.
Definition: table.h:3669
bool is_base_table() const
Definition: table.h:3136
bool m_is_sj_or_aj_nest
Definition: table.h:3584
const char * get_table_name() const
Returns the name of the table that this Table_ref represents.
Definition: table.h:3417
Key_map keys_in_use_for_group_by_saved
Definition: table.h:4001
List< String > * join_using_fields
Definition: table.h:3609
Item * derived_where_cond
WHERE condition from derived table.
Definition: table.h:3739
char timestamp_buffer[20]
Definition: table.h:3842
bool process_index_hints(const THD *thd, TABLE *table)
Compiles the tagged hints list and fills up TABLE::keys_in_use_for_query, TABLE::keys_in_use_for_grou...
Definition: table.cc:6375
MY_BITMAP read_set_saved
Definition: table.h:4008
bool is_updatable() const
Return true if table is updatable.
Definition: table.h:3207
ulonglong with_check
WITH CHECK OPTION.
Definition: table.h:3763
void set_privileges(ulong privilege)
Set granted privileges for a table.
Definition: table.h:3534
void set_lock(const Lock_descriptor &descriptor)
Definition: table.h:3561
Table_ref(TABLE *table_arg, const char *alias_arg)
This constructor can be used when a Table_ref is needed for an existing temporary table.
Definition: table.h:2901
Lock_descriptor m_lock_descriptor
Definition: table.h:3768
bool prepare_replace_filter(THD *thd)
Prepare replace filter for a view (used for REPLACE command)
Definition: table.cc:4712
bool can_push_condition_to_derived(THD *thd)
Check if we can push outer where condition to this derived table.
Definition: sql_derived.cc:1044
COND_EQUAL * cond_equal
Used with outer join.
Definition: table.h:3971
bool setup_table_function(THD *thd)
Setup a table function to use materialization.
Definition: sql_derived.cc:960
bool is_aj_nest() const
Definition: table.h:3046
table_map sj_inner_tables
Definition: table.h:3593
LEX * view_query() const
Return the valid LEX object for a view.
Definition: table.h:3313
Table_ref * first_leaf_table()
Return first leaf table of a base table or a view/derived table.
Definition: table.h:3281
@ OPEN_IF_EXISTS
Definition: table.h:3856
@ OPEN_STUB
Definition: table.h:3863
@ OPEN_FOR_CREATE
Definition: table.h:3861
table_map m_map
Table map, derived from m_tableno.
Definition: table.h:3576
const Create_col_name_list * derived_column_names() const
Definition: table.h:3953
Table_ref * first_leaf_for_name_resolution()
Retrieve the first (left-most) leaf in a nested join tree with respect to name resolution.
Definition: table.cc:4850
const Create_col_name_list * m_derived_column_names
If the user has specified column names with the syntaxes "table name parenthesis column names": WITH ...
Definition: table.h:3680
Field_translator * field_translation
Array of selected expressions from a derived table or view.
Definition: table.h:3698
bool join_order_swapped
True if was originally the left argument of a RIGHT JOIN, before we made it the right argument of a L...
Definition: table.h:3780
Table_ref(TABLE *table_arg, const char *db_name_arg, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum thr_lock_type lock_type_arg)
Creates a Table_ref object with pre-allocated strings for database, table and alias.
Definition: table.h:2873
bool is_multiple_tables() const
Return true if this is a view or derived table that is defined over more than one base table,...
Definition: table.h:3267
ulonglong m_table_ref_version
See comments for TABLE_SHARE::get_table_ref_version()
Definition: table.h:3990
Table_ref * outer_join_nest() const
Returns the outer join nest that this Table_ref belongs to, if any.
Definition: table.h:3451
void set_updatable()
Set table as updatable. (per default, a table is non-updatable)
Definition: table.h:3210
bool prepare_security(THD *thd)
Prepare security context for a view.
Definition: table.cc:4966
void set_deleted()
Set table and all referencing views as being deleted from.
Definition: table.h:3240
bool check_option_processed
true <=> VIEW CHECK OPTION condition is processed (also for prep. stmts)
Definition: table.h:3837
bool check_single_table(Table_ref **table_ref, table_map map)
Check which single table inside a view that matches a table map.
Definition: table.cc:4778
bool is_external() const
Is this table only available in an external storage engine?
Definition: table.cc:7325
void set_derived_query_expression(Query_expression *query_expr)
Set the query expression of a derived table or view.
Definition: table.h:3322
Query_block * schema_query_block
Definition: table.h:3684
ST_SCHEMA_TABLE * schema_table
Definition: table.h:3683
enum_table_ref_type m_table_ref_type
See comments for set_metadata_id()
Definition: table.h:3988
ulonglong updatable_view
VIEW can be updated.
Definition: table.h:3752
table_map map() const
Return table map derived from table number.
Definition: table.h:3944
Item * m_join_cond
If this table or join nest is the Y in "X [LEFT] JOIN Y ON C", this member points to C.
Definition: table.h:3583
bool cacheable_table
stop PS caching
Definition: table.h:3828
bool is_derived_unfinished_materialization() const
Definition: table.cc:7315
void set_derived_column_names(const Create_col_name_list *d)
Definition: table.h:3956
Table_ref * embedding
The nested join containing this table reference.
Definition: table.h:3824
bool is_placeholder() const
Definition: table.h:3162
bool schema_table_filled
Definition: table.h:3924
void set_updated()
Set table and all referencing views as being updated.
Definition: table.h:3222
void set_uses_materialization()
Set table to be materialized.
Definition: table.h:3199
Table_ref(const char *db_name, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum thr_lock_type lock_type_arg, enum enum_mdl_type mdl_request_type)
Definition: table.h:2990
Field_translator * field_translation_end
pointer to element after last one in translation table above
Definition: table.h:3701
Security_context * find_view_security_context(THD *thd)
Find security context of current view.
Definition: table.cc:4935
Key_map merge_keys_saved
Definition: table.h:3999
bool setup_materialized_derived_tmp_table(THD *thd)
Sets up the tmp table to contain the derived table's rows.
Definition: sql_derived.cc:836
mem_root_deque< Table_ref * > * join_list
The join list immediately containing this table reference.
Definition: table.h:3826
bool is_mergeable() const
Return true if view or derived table and can be merged.
Definition: table.cc:6507
mem_root_deque< Table_ref * > * view_tables
Definition: table.h:3713
uint m_tableno
The members below must be kept aligned so that (1 << m_tableno) == m_map.
Definition: table.h:3575
void print(const THD *thd, String *str, enum_query_type query_type) const
Produce a textual identification of this object.
Definition: sql_lex.cc:2933
Table_ref * referencing_view
Definition: table.h:3720
void set_fulltext_searched()
Set table as full-text search (default is not fulltext searched)
Definition: table.h:3246
Table_ref * correspondent_table
Definition: table.h:3643
bool is_view() const
Return true if this represents a named view.
Definition: table.h:3115
List< Natural_join_column > * join_columns
Definition: table.h:3614
int view_check_option(THD *thd) const
Evaluate the check option of a view.
Definition: table.cc:4755
const char * get_db_name() const
Returns the name of the database that the referenced table belongs to.
Definition: table.h:3409
bool updating
True for tables and views being changed in a data change statement.
Definition: table.h:3805
bool m_insertable
True if VIEW/TABLE is insertable, based on analysis of query (SQL rules).
Definition: table.h:3789
void set_readonly()
Set table as readonly, ie it is neither updatable, insertable nor deletable during this statement.
Definition: table.h:3258
bool is_updated() const
Return true if table is being updated.
Definition: table.h:3219
bool m_updatable
True if VIEW/TABLE is updatable, based on analysis of query (SQL rules).
Definition: table.h:3787
void set_tableno(uint tableno)
Set table number.
Definition: table.h:3935
enum_view_algorithm effective_algorithm
The view algorithm that is actually used, if this is a view.
Definition: table.h:3767
bool is_inner_table_of_outer_join() const
Return true if this table is an inner table of some outer join.
Definition: table.h:3466
Table_ref * belong_to_view
Definition: table.h:3715
LEX * view
Definition: table.h:3694
bool set_insert_values(MEM_ROOT *mem_root)
Allocate a buffer for inserted column values.
Definition: table.cc:4799
MY_BITMAP read_set_internal_saved
Definition: table.h:4010
bool is_derived() const
Return true if this represents a derived table (an unnamed view)
Definition: table.h:3118
bool derived_keys_ready
true <=> all possible keys for a derived table were collected and could be re-used while statement re...
Definition: table.h:3980
const Table_ref * updatable_base_table() const
Return the base table entry of an updatable table.
Definition: table.h:3479
void restore_properties()
Restore persistent properties into TABLE from Table_ref.
Definition: table.cc:4483
Table_ref ** prev_global
Definition: table.h:3547
Query_block * query_block
Definition: table.h:3691
const Table_ref * top_table() const
Return the outermost view this table belongs to, or itself.
Definition: table.h:3096
void set_merged()
Set table to be merged.
Definition: table.h:3188
void set_insertable()
Set table as insertable-into. (per default, a table is not insertable)
Definition: table.h:3216
uint tableno() const
Return table number.
Definition: table.h:3941
size_t db_length
Definition: table.h:3782
List< Index_hint > * index_hints
Definition: table.h:3627
LEX_STRING select_stmt
text of (CREATE/SELECT) statement
Definition: table.h:3742
Table_ref(const char *db_name_arg, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum thr_lock_type lock_type_arg)
Definition: table.h:3006
bool is_natural_join
Definition: table.h:3607
Query_expression * derived
This field is set to non-null for derived tables and views.
Definition: table.h:3666
MY_BITMAP lock_partitions_saved
Definition: table.h:4007
bool is_fulltext_searched() const
Returns true if a MATCH function references this table.
Definition: table.h:3249
Table_ref * natural_join
Definition: table.h:3601
bool outer_join
True if right argument of LEFT JOIN; false in other cases (i.e.
Definition: table.h:3777
Table_ref * parent_l
Definition: table.h:3722
bool is_table_function() const
Return true if this represents a table function.
Definition: table.h:3124
bool m_updated
True if table is target of UPDATE statement, or updated in IODKU stmt.
Definition: table.h:3791
bool optimized_away
true <=> this table is a const one and was optimized away.
Definition: table.h:3974
bool is_insertable() const
Return true if table is insertable-into.
Definition: table.h:3213
AccessPath * access_path_for_derived
If we've previously made an access path for “derived”, it is cached here.
Definition: table.h:3657
bool is_alias
true if an alias for this table was specified in the SQL.
Definition: table.h:3867
Table_ref()=default
bool straight
Definition: table.h:3798
int fetch_number_of_rows(ha_rows fallback_estimate=PLACEHOLDER_TABLE_ROW_ESTIMATE)
Retrieve number of rows in the table.
Definition: table.cc:6565
void set_join_cond(Item *val)
Definition: table.h:3027
bool is_system_view
Definition: table.h:3903
uint8 trg_event_map
Indicates what triggers we need to pre-load for this Table_ref when opening an associated TABLE.
Definition: table.h:3923
Table_ref * last_leaf_for_name_resolution()
Retrieve the last (right-most) leaf in a nested join tree with respect to name resolution.
Definition: table.cc:4866
bool schema_table_reformed
Definition: table.h:3689
bool is_sj_or_aj_nest() const
Definition: table.h:3048
Key_map keys_in_use_for_query_saved
Definition: table.h:4000
MY_BITMAP write_set_saved
Definition: table.h:4009
List< String > * partition_names
Definition: table.h:3932
bool force_index_order_saved
Definition: table.h:4005
Query_expression * derived_query_expression() const
Return the query expression of a derived table or view.
Definition: table.h:3327
bool ignore_leaves
preload only non-leaf nodes (IS THIS USED???)
Definition: table.h:3807
Table_ref * next_leaf
Definition: table.h:3738
bool is_leaf_for_name_resolution() const
Test if this is a leaf with respect to name resolution.
Definition: table.cc:4827
Table_ref * next_local
Definition: table.h:3545
Table_ref * merge_underlying_list
Definition: table.h:3707
LEX_CSTRING target_tablespace_name
Definition: table.h:3553
dd::enum_table_type required_type
Definition: table.h:3841
static Table_ref * new_nested_join(MEM_ROOT *allocator, const char *alias, Table_ref *embedding, mem_root_deque< Table_ref * > *belongs_to, Query_block *select)
Create a Table_ref object representing a nested join.
Definition: table.cc:4355
bool m_was_scalar_subquery
If true, this table is a derived (materialized) table which was created from a scalar subquery,...
Definition: table.h:3877
bool is_recursive_reference() const
Definition: table.h:3133
GRANT_INFO grant
Definition: table.h:3771
Table_ref * top_table()
Definition: table.h:3100
bool is_table_ref_id_equal(TABLE_SHARE *s) const
Compare the version of metadata from the previous execution (if any) with values obtained from the cu...
Definition: table.h:3371
void set_sj_or_aj_nest()
Makes the next a semi/antijoin nest.
Definition: table.h:3050
void set_table_ref_id(enum_table_ref_type table_ref_type_arg, ulonglong table_ref_version_arg)
Definition: table.h:3386
bool is_internal() const
Definition: table.h:3152
bool prepare_view_security_context(THD *thd)
Load security context information for this view.
Definition: table.cc:4890
const Lock_descriptor & lock_descriptor() const
Definition: table.h:3565
bool nullable_saved
Definition: table.h:4003
NESTED_JOIN * nested_join
Is non-NULL if this table reference is a nested join, ie it represents the inner tables of an outer j...
Definition: table.h:3822
Table_ref(TABLE *table_arg, const char *alias_arg, enum_mdl_type mdl_type)
Sets an explicit enum_mdl_type value, without initializing m_lock_descriptor.
Definition: table.h:2918
const char * db
Definition: table.h:3548
Security_context * security_ctx
Definition: table.h:3727
bool is_inserted() const
Return true if table is being inserted into.
Definition: table.h:3228
Table_ref(const char *db_name, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, enum thr_lock_type lock_type_arg, enum enum_mdl_type mdl_request_type)
Definition: table.h:2945
bool materialize_derived(THD *thd)
Materialize derived table.
Definition: sql_derived.cc:1714
Security_context * view_sctx
Definition: table.h:3732
bool merge_where(THD *thd)
Merge WHERE condition of view or derived table into outer query.
Definition: table.cc:4519
ulonglong view_suid
view is suid (true by default)
Definition: table.h:3762
ulonglong algorithm
The declared algorithm, if this is a view.
Definition: table.h:3761
uint get_hidden_field_count_for_derived() const
Return the number of hidden fields added for the temporary table created for this derived table.
Definition: table.cc:7320
List< Derived_key > derived_key_list
Definition: table.h:3916
bool prepare_check_option(THD *thd, bool is_cascaded=false)
Prepare check option for a view.
Definition: table.cc:4653
void set_common_table_expr(Common_table_expr *c)
Definition: table.h:3951
Table_ref * next_global
Definition: table.h:3547
bool optimize_derived(THD *thd)
Optimize the query expression representing a derived table/view.
Definition: sql_derived.cc:1604
LEX_STRING timestamp
GMT time stamp of last operation.
Definition: table.h:3744
enum Table_ref::@185 OPEN_NORMAL
Indicates that if Table_ref object corresponds to the table/view which requires special handling.
bool replace_filter_processed
true <=> Filter condition is processed
Definition: table.h:3839
Table_ref(const char *db_name, const char *table_name_arg, enum thr_lock_type lock_type_arg, enum enum_mdl_type mdl_request_type)
Definition: table.h:2930
mysql::binlog::event::Table_id table_id
Definition: table.h:3630
bool generate_keys()
Generate keys for a materialized derived table/view.
Definition: table.cc:6946
enum_open_type open_type
Specifies which kind of table should be open for this element of table list.
Definition: table.h:3833
bool materializable_is_const() const
Checks if this is a table that contains zero rows or one row, and that can be materialized during opt...
Definition: table.cc:6521
Item * m_join_cond_optim
Optimized copy of m_join_cond (valid for one single execution).
Definition: table.h:3968
table_map join_cond_dep_tables
The outer tables that an outer join's join condition depends on.
Definition: table.h:3814
Table_ref * updatable_base_table()
Definition: table.h:3489
Item * replace_filter
Filter for REPLACE command.
Definition: table.h:3741
bool merge_underlying_tables(Query_block *select)
Merge tables from a query block into a nested join structure.
Definition: table.cc:4391
Common_table_expr * common_table_expr() const
If non-NULL, the CTE which this table is derived from.
Definition: table.h:3950
bool internal_tmp_table
Definition: table.h:3865
LEX_STRING source
source of CREATE VIEW
Definition: table.h:3743
Table_ref(const char *db_name, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, enum thr_lock_type lock_type_arg)
Definition: table.h:2961
LEX_CSTRING view_connection_cl_name
Definition: table.h:3894
LEX_CSTRING view_client_cs_name
Definition: table.h:3893
bool save_properties()
Save persistent properties from TABLE into Table_ref.
Definition: table.cc:4452
bool is_join_columns_complete
Definition: table.h:3616
bool m_is_recursive_reference
If a recursive reference inside the definition of a CTE.
Definition: table.h:3984
bool is_deleted() const
Return true if table is being deleted from.
Definition: table.h:3237
bool prelocking_placeholder
Definition: table.h:3847
LEX_USER definer
definer of view
Definition: table.h:3745
const char * table_name
Definition: table.h:3548
uint shared
Definition: table.h:3781
Item ** join_cond_optim_ref()
Definition: table.h:3041
bool create_field_translation(THD *thd)
Create field translation for merged derived table/view.
Definition: table.cc:4556
bool create_materialized_table(THD *thd)
Create result table for a materialized derived table/view.
Definition: sql_derived.cc:1652
uint query_block_id_for_explain() const
This is for showing in EXPLAIN.
Definition: table.cc:6320
Opt_hints_table * opt_hints_table
Table level optimizer hints for this table.
Definition: table.h:3557
bool setup_materialized_derived(THD *thd)
Setup a derived table to use materialization.
Definition: sql_derived.cc:824
Table_ref * any_outer_leaf_table()
Return any leaf table that is not an inner table of an outer join.
Definition: table.h:3292
View_creation_ctx * view_creation_ctx
Definition: table.h:3881
char * option
Definition: table.h:3554
Table_ref(const char *db_name, size_t db_length_arg, const char *table_name_arg, size_t table_name_length_arg, const char *alias_arg, enum enum_mdl_type mdl_request_type)
Sets an explicit enum_mdl_type value, without initializing m_lock_descriptor.
Definition: table.h:2976
TABLE * table
Definition: table.h:3628
void set_view_query(LEX *lex)
Set the LEX object of a view (will also define this as a view).
Definition: table.h:3310
void set_inserted()
Set table and all referencing views as being inserted into.
Definition: table.h:3231
bool update_derived_keys(THD *, Field *, Item **, uint, bool *)
Update derived table's list of possible keys.
Definition: table.cc:6886
uint query_block_id() const
If a derived table, returns query block id of first underlying query block.
Definition: table.cc:6315
bool m_fulltext_searched
True if fulltext searched.
Definition: table.h:3796
Item * join_cond() const
Definition: table.h:3026
Table_ref * next_name_resolution_table
Definition: table.h:3625
bool is_view_or_derived() const
Return true if this represents a named view or a derived table.
Definition: table.h:3121
bool is_merged() const
Return true if this is a derived table or view that is merged.
Definition: table.h:3185
void set_join_cond_optim(Item *cond)
Definition: table.h:3033
table_map dep_tables
The set of tables in the query block that this table depends on.
Definition: table.h:3812
size_t table_name_length
Definition: table.h:3783
bool uses_materialization() const
Return true if this is a materializable derived table/view.
Definition: table.h:3194
void add_join_natural(Table_ref *b)
Mark that there is a NATURAL JOIN or JOIN ... USING between two tables.
Definition: table.h:3524
bool is_sj_nest() const
Definition: table.h:3044
bool contain_auto_increment
Definition: table.h:3835
bool resolve_derived(THD *thd, bool apply_semijoin)
Resolve a derived table or view reference.
Definition: sql_derived.cc:266
Key_map covering_keys_saved
Definition: table.h:3998
uint leaf_tables_count() const
Return no. of base tables a merged view or derived table is defined over.
Definition: table.cc:6533
const char * alias
Definition: table.h:3548
Item * join_cond_optim() const
Definition: table.h:3032
bool set_recursive_reference()
Definition: table.cc:7308
Opt_hints_qb * opt_hints_qb
Definition: table.h:3559
bool is_dd_ctx_table
Definition: table.h:3911
Table_ref(TABLE *table_arg)
Only to be used by legacy code that temporarily needs a Table_ref, more specifically: Query_result_cr...
Definition: table.h:2861
bool is_fqtn
true if the table is referred to in the statement using a fully qualified name (<db_name>.
Definition: table.h:3871
bool force_index_saved
Definition: table.h:4004
Table_ref(const char *db_name, const char *table_name, enum thr_lock_type lock_type)
Constructor that can be used when the strings are null terminated.
Definition: table.h:2864
Item ** join_cond_ref()
Definition: table.h:3025
Key_map keys_in_use_for_order_by_saved
Definition: table.h:4002
Table_function * table_function
Definition: table.h:3648
bool m_deleted
True if table is target of DELETE statement, or deleted in REPLACE stmt.
Definition: table.h:3795
MDL_request mdl_request
Definition: table.h:3926
Table_ref(const char *db_name, const char *table_name, const char *alias, enum thr_lock_type lock_type)
Constructor that can be used when the strings are null terminated.
Definition: table.h:2889
Item * check_option
WITH CHECK OPTION condition.
Definition: table.h:3740
Query_result_union * derived_result
Definition: table.h:3635
void set_table_ref_id(TABLE_SHARE *s)
Record the value of metadata version of the corresponding table definition cache element in this pars...
Definition: table.h:3382
void reset()
Reset table.
Definition: table.cc:4406
This class holds all information about triggers of a table.
Definition: table_trigger_dispatcher.h:62
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:94
Used for storing information associated with generated column, default values generated from expressi...
Definition: field.h:482
View_creation_ctx – creation context of view objects.
Definition: table.h:267
static View_creation_ctx * create(THD *thd)
Definition: table.cc:229
View_creation_ctx(THD *thd)
Definition: table.h:274
Class representing the fact that some thread waits for table share to be flushed.
Definition: table.h:633
MDL_context * m_ctx
Definition: table.h:634
Wait_for_flush ** prev_in_share
Definition: table.h:655
Wait_for_flush * next_in_share
Pointers for participating in the list of waiters for table share.
Definition: table.h:654
TABLE_SHARE * m_share
Definition: table.h:635
MDL_context * get_ctx() const
Definition: table.h:645
uint m_deadlock_weight
Definition: table.h:636
bool accept_visitor(MDL_wait_for_graph_visitor *dvisitor) override
Traverse portion of wait-for graph which is reachable through edge represented by this flush ticket i...
Definition: table.cc:3895
Wait_for_flush(MDL_context *ctx_arg, TABLE_SHARE *share_arg, uint deadlock_weight_arg)
Definition: table.h:639
uint get_deadlock_weight() const override
Definition: table.cc:3899
enum_rule
Definition: foreign_key.h:53
Definition: table.h:46
Definition: view.h:38
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4548
@ NONE
Definition: handler.h:4634
enum handler::@53 inited
Histogram base class.
Definition: histogram.h:312
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:110
Each table share has a table id, it is mainly used for row based replication.
Definition: table_id.h:41
Definition: partition_info.h:208
A table definition from the master.
Definition: rpl_utility.h:247
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:54
void * memdup_root(MEM_ROOT *root, const void *str, size_t len)
Definition: my_alloc.cc:295
struct PSI_table_share PSI_table_share
Definition: psi_table_bits.h:99
static void free_share(st_blackhole_share *share)
Definition: ha_blackhole.cc:307
static int flag
Definition: hp_test1.cc:39
static uint keys
Definition: hp_test2.cc:48
enum_json_diff_operation
Enum that describes what kind of operation a Json_diff object represents.
Definition: json_diff.h:51
float rec_per_key_t
Data type for records per key estimates that are stored in the KEY::rec_per_key_float[] array.
Definition: key.h:95
enum_order
Definition: key_spec.h:64
@ ORDER_NOT_RELEVANT
Definition: key_spec.h:64
constexpr const LEX_CSTRING EMPTY_CSTR
Definition: lex_string.h:47
constexpr const LEX_CSTRING NULL_CSTR
Definition: lex_string.h:46
A better implementation of the UNIX ctype(3) library.
int my_strcasecmp(const CHARSET_INFO *cs, const char *s1, const char *s2)
Definition: m_ctype.h:652
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1556
#define MDL_REQUEST_INIT(R, P1, P2, P3, P4, P5)
Definition: mdl.h:905
@ MDL_TRANSACTION
Locks with transaction duration are automatically released at the end of transaction.
Definition: mdl.h:342
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
#define HA_VIRTUAL_GEN_KEY
Set if a key is on any virtual generated columns.
Definition: my_base.h:552
ulong key_part_map
Definition: my_base.h:1007
my_off_t ha_rows
Definition: my_base.h:1140
#define HA_POS_ERROR
Definition: my_base.h:1142
ha_storage_media
Definition: my_base.h:115
@ HA_SM_DEFAULT
Definition: my_base.h:116
uint32 my_bitmap_map
Definition: my_bitmap.h:40
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
uint8_t uint8
Definition: my_inttypes.h:62
unsigned char uchar
Definition: my_inttypes.h:51
int64_t int64
Definition: my_inttypes.h:67
uint16_t uint16
Definition: my_inttypes.h:64
uint32_t uint32
Definition: my_inttypes.h:66
Common header for many mysys elements.
uint64_t table_map
Definition: my_table_map.h:29
#define NAME_CHAR_LEN
Field/table name length.
Definition: mysql_com.h:59
ABI for instrumented mutexes.
static char * path
Definition: mysqldump.cc:148
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1065
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
Definition: buf0block_hint.cc:29
const std::string charset("charset")
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
enum_table_type
Definition: abstract_table.h:52
Definition: os0file.h:88
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
Definition: column_statistics.h:33
Json_data_extension ext
Definition: backend.cc:50
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2891
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:59
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:60
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:41
Value_generator_source
Enum to indicate source for which value generator is used.
Definition: field.h:472
enum_stats_auto_recalc
Definition: handler.h:3168
row_type
Definition: handler.h:683
void free_blobs(TABLE *table)
Definition: table.cc:3372
LEX_CSTRING SLOW_LOG_NAME
Definition: table.cc:150
bool update_generated_write_fields(const MY_BITMAP *bitmap, TABLE *table)
Calculate data for each generated field marked for write in the corresponding column map.
Definition: table.cc:7243
I_P_List< Wait_for_flush, I_P_List_adapter< Wait_for_flush, &Wait_for_flush::next_in_share, &Wait_for_flush::prev_in_share > > Wait_for_flush_list
Definition: table.h:662
enum_open_type
Type of table which can be open for an element of table list.
Definition: table.h:2796
@ OT_TEMPORARY_OR_BASE
Definition: table.h:2797
@ OT_TEMPORARY_ONLY
Definition: table.h:2798
@ OT_BASE_ONLY
Definition: table.h:2799
static my_bitmap_map * tmp_use_all_columns(TABLE *table, MY_BITMAP *bitmap)
Definition: table.h:4137
int64 query_id_t
Definition: table.h:137
bool unpack_value_generator(THD *thd, TABLE *table, Value_generator **val_generator, Value_generator_source source, const char *source_name, Field *field, bool is_create_table, bool *error_reported)
Unpacks the definition of a value generator in all its forms: generated column, default expression or...
Definition: table.cc:2583
static void tmp_restore_column_map(MY_BITMAP *bitmap, my_bitmap_map *old)
Definition: table.h:4144
static void empty_record(TABLE *table)
Definition: table.h:2477
bool assert_invalid_stats_is_locked(const TABLE *)
Assert that caller holds lock on the table cache when TABLE::m_invalid_stats is accessed.
Definition: table.cc:8039
static my_bitmap_map * dbug_tmp_use_all_columns(TABLE *table, MY_BITMAP *bitmap)
Definition: table.h:4151
char * fn_rext(char *name)
Returns pointer to '.frm' extension of the file name.
Definition: table.cc:304
bool is_simple_order(ORDER *order)
Test if the order list consists of simple field expressions.
Definition: table.cc:7086
LEX_CSTRING MYSQL_SCHEMA_NAME
Definition: table.cc:141
enum enum_mdl_type mdl_type_for_dml(enum thr_lock_type lock_type)
Derive type of metadata lock to be requested for table used by a DML statement from the type of THR_L...
Definition: table.h:2785
bool create_key_part_field_with_prefix_length(TABLE *table, MEM_ROOT *root)
Create a copy of the key_info from TABLE_SHARE object to TABLE object.
Definition: table.cc:2805
bool is_user_table(TABLE *table)
return true if the table was created explicitly.
Definition: table.h:4341
bool check_column_name(const char *name)
Definition: table.cc:3734
bool assert_invalid_dict_is_locked(const TABLE *)
Assert that LOCK_thd_data is held when TABLE::m_invalid_dict is accessed.
Definition: table.cc:8026
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form)
Definition: table.cc:3540
enum_view_algorithm
Strategy for how to process a view or derived table (merge or materialization)
Definition: table.h:2533
@ VIEW_ALGORITHM_TEMPTABLE
Definition: table.h:2535
@ VIEW_ALGORITHM_UNDEFINED
Definition: table.h:2534
@ VIEW_ALGORITHM_MERGE
Definition: table.h:2536
Mem_root_array_YY< LEX_CSTRING > Create_col_name_list
Definition: table.h:135
LEX_CSTRING MI_INFO_NAME
Definition: table.cc:156
bool is_infoschema_db(const char *name, size_t len)
Definition: table.h:4304
bool update_generated_read_fields(uchar *buf, TABLE *table, uint active_index=MAX_KEY)
Evaluate necessary virtual generated columns.
Definition: table.cc:7181
bool is_perfschema_db(const char *name, size_t len)
Definition: table.h:4314
Ident_name_check
Enumerate possible status of a identifier name while determining its validity.
Definition: table.h:187
Ident_name_check check_and_convert_db_name(LEX_STRING *db, bool preserve_lettercase)
Check if database name is valid, and convert to lower case if necessary.
Definition: table.cc:3668
LEX_CSTRING GENERAL_LOG_NAME
Definition: table.cc:147
const uchar * get_field_name(const uchar *arg, size_t *length)
LEX_CSTRING WORKER_INFO_NAME
Definition: table.cc:159
tmp_table_type
Definition: table.h:407
@ TRANSACTIONAL_TMP_TABLE
Definition: table.h:410
@ NON_TRANSACTIONAL_TMP_TABLE
Definition: table.h:409
@ INTERNAL_TMP_TABLE
Definition: table.h:411
@ NO_TMP_TABLE
Definition: table.h:408
@ SYSTEM_TMP_TABLE
Definition: table.h:412
int closefrm(TABLE *table, bool free_share)
Free information allocated by openfrm.
Definition: table.cc:3330
enum_table_category
Category of table found in the table share.
Definition: table.h:418
@ TABLE_CATEGORY_ACL_TABLE
A ACL metadata table.
Definition: table.h:586
@ TABLE_UNKNOWN_CATEGORY
Unknown value.
Definition: table.h:422
@ TABLE_CATEGORY_USER
User table.
Definition: table.h:457
@ TABLE_CATEGORY_RPL_INFO
Replication Information Tables.
Definition: table.h:554
@ TABLE_CATEGORY_INFORMATION
Information schema tables.
Definition: table.h:491
@ TABLE_CATEGORY_GTID
Gtid Table.
Definition: table.h:571
@ TABLE_CATEGORY_DICTIONARY
A data dictionary table.
Definition: table.h:579
@ TABLE_CATEGORY_PERFORMANCE
Performance schema tables.
Definition: table.h:535
@ TABLE_CATEGORY_LOG
Log tables.
Definition: table.h:513
@ TABLE_CATEGORY_SYSTEM
System table, maintained by the server.
Definition: table.h:469
@ TABLE_CATEGORY_TEMPORARY
Temporary table.
Definition: table.h:447
bool is_temporary_table(const Table_ref *tl)
Check if a Table_ref instance represents a pre-opened temporary table.
Definition: table.h:4367
enum_table_ref_type
Enumerate possible types of a table from re-execution standpoint.
Definition: table.h:174
@ TABLE_REF_VIEW
Definition: table.h:177
@ TABLE_REF_BASE_TABLE
Definition: table.h:178
@ TABLE_REF_I_S_TABLE
Definition: table.h:179
@ TABLE_REF_TMP_TABLE
Definition: table.h:180
@ TABLE_REF_NULL
Initial value set by the parser.
Definition: table.h:176
#define STATUS_DELETED
Reserved for use by multi-table delete. Means the row has been deleted.
Definition: table.h:1391
TABLE_CATEGORY get_table_category(const LEX_CSTRING &db, const LEX_CSTRING &name)
Definition: table.cc:310
uint add_pk_parts_to_sk(KEY *sk, uint sk_n, KEY *pk, uint pk_n, TABLE_SHARE *share, handler *handler_file, uint *usable_parts, bool use_extended_sk)
Generate extended secondary keys by adding primary key parts to the existing secondary key.
Definition: table.cc:812
bool can_call_position(const TABLE *table)
Definition: table.h:4494
#define STATUS_UPDATED
Reserved for use by multi-table update. Means the row has been updated.
Definition: table.h:1384
#define tmp_file_prefix
Prefix for tmp tables.
Definition: table.h:154
Lex_acl_attrib_udyn
This is generic enum.
Definition: table.h:2604
static const uint MYSQL_SCHEMA_DD_ID
Definition: table.h:4293
Bitmap< MAX_FIELDS > Field_map
Definition: table.h:1397
index_hint_type
Definition: table.h:1394
@ INDEX_HINT_FORCE
Definition: table.h:1394
@ INDEX_HINT_IGNORE
Definition: table.h:1394
@ INDEX_HINT_USE
Definition: table.h:1394
int create_table_share_for_upgrade(THD *thd, const char *path, TABLE_SHARE *share, FRM_context *frm_context, const char *db, const char *table, bool is_fix_view_cols_and_deps)
Create TABLE_SHARE from .frm file.
Definition: table.cc:7932
void append_unescaped(String *res, const char *pos, size_t length)
Store an SQL quoted string.
Definition: table.cc:3503
Ident_name_check check_table_name(const char *name, size_t length)
Function to check if table name is valid or not.
Definition: table.cc:3707
char * get_field(MEM_ROOT *mem, Field *field)
Allocate string field in MEM_ROOT and return it as NULL-terminated string.
Definition: table.cc:3602
LEX_CSTRING MYSQL_TABLESPACE_NAME
Definition: table.cc:144
static const uint MYSQL_TABLESPACE_DD_ID
Definition: table.h:4297
#define STATUS_NOT_STARTED
Flags for TABLE::m_status (maximum 8 bits).
Definition: table.h:1376
void setup_key_part_field(TABLE_SHARE *share, handler *handler_file, uint primary_key_n, KEY *keyinfo, uint key_n, uint key_part_n, uint *usable_parts, bool part_of_key_not_extended)
Setup key-related fields of Field object for given key and key part.
Definition: table.cc:737
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, size_t key_length, const char *table_name, const char *path, MEM_ROOT *mem_root)
Initialize share for temporary tables.
Definition: table.cc:466
enum enum_table_category TABLE_CATEGORY
Definition: table.h:588
LEX_CSTRING INFORMATION_SCHEMA_NAME
Definition: table.cc:134
void init_mdl_requests(Table_ref *table_list)
Helper function which allows to allocate metadata lock request objects for all elements of table list...
Definition: table.cc:6495
struct Table_share_foreign_key_info TABLE_SHARE_FOREIGN_KEY_INFO
static void dbug_tmp_restore_column_maps(MY_BITMAP *read_set, MY_BITMAP *write_set, my_bitmap_map **old)
Definition: table.h:4187
void repoint_field_to_record(TABLE *table, uchar *old_rec, uchar *new_rec)
Repoint a table's fields from old_rec to new_rec.
Definition: table.cc:7101
#define PLACEHOLDER_TABLE_ROW_ESTIMATE
Definition: table.h:157
void free_blob_buffers_and_reset(TABLE *table, uint32 size)
Reclaims temporary blob storage which is bigger than a threshold.
Definition: table.cc:3393
bool unpack_partition_info(THD *thd, TABLE *outparam, TABLE_SHARE *share, handlerton *engine_type, bool is_create_table)
Unpack the partition expression.
Definition: table.cc:2713
#define STATUS_NOT_FOUND
Means we were searching for a row and didn't find it.
Definition: table.h:1382
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, uint db_stat, uint prgflag, uint ha_open_flags, TABLE *outparam, bool is_create_table, const dd::Table *table_def_param)
Open a table based on a TABLE_SHARE.
Definition: table.cc:2882
LEX_CSTRING PERFORMANCE_SCHEMA_DB_NAME
Definition: table.cc:137
#define STATUS_NULL_ROW
Means that table->null_row is set.
Definition: table.h:1389
ulong refresh_version
Definition: mysqld.cc:1373
static void dbug_tmp_restore_column_map(MY_BITMAP *bitmap, my_bitmap_map *old)
Definition: table.h:4162
#define restore_record(A, B)
Definition: table.h:149
int set_zone(int nr, int min_zone, int max_zone)
Definition: table.cc:3485
Ident_name_check check_db_name(const char *name, size_t length)
Check if database name is valid.
Definition: table.cc:3632
int rename_file_ext(const char *from, const char *to, const char *ext)
Definition: table.cc:3559
TABLE_SHARE * alloc_table_share(const char *db, const char *table_name, const char *key, size_t key_length, bool open_secondary)
Allocate and setup a TABLE_SHARE structure.
Definition: table.cc:375
void free_table_share(TABLE_SHARE *share)
Free table share and memory used by it.
Definition: table.cc:606
bool belongs_to_p_s(Table_ref *tl)
Check if the table belongs to the P_S, excluding setup and threads tables.
Definition: table.h:4332
bool assert_ref_count_is_locked(const TABLE_SHARE *)
Assert that the LOCK_open mutex is held when the reference count of a TABLE_SHARE is accessed.
Definition: table.cc:518
#define tmp_file_prefix_length
Definition: table.h:155
LEX_CSTRING RLI_INFO_NAME
Definition: table.cc:153
struct Table_share_foreign_key_parent_info TABLE_SHARE_FOREIGN_KEY_PARENT_INFO
File containing constants that can be used throughout the server.
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:45
constexpr const size_t MAX_TABLES
Max tables in join.
Definition: sql_const.h:107
enum_mark_columns
Definition: sql_const.h:230
enum_mdl_type
Type of metadata lock request.
Definition: sql_lexer_yacc_state.h:105
@ MDL_SHARED_WRITE
Definition: sql_lexer_yacc_state.h:178
@ MDL_SHARED_WRITE_LOW_PRIO
Definition: sql_lexer_yacc_state.h:184
@ MDL_SHARED_READ
Definition: sql_lexer_yacc_state.h:168
int plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:53
static MEM_ROOT mem
Definition: sql_servers.cc:99
case opt name
Definition: sslopt-case.h:32
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:212
Definition: m_ctype.h:422
Struct that describes an expression selected from a derived table or view.
Definition: table.h:2559
Item * item
Points to an item that represents the expression.
Definition: table.h:2564
const char * name
Name of selected expression.
Definition: table.h:2566
The current state of the privilege checking process for the current user, SQL statement and SQL objec...
Definition: table.h:366
GRANT_INTERNAL_INFO m_internal
The grant state for internal tables.
Definition: table.h:404
GRANT_INFO()
Definition: table.cc:280
GRANT_TABLE * grant_table
A copy of the privilege information regarding the current host, database, object and user.
Definition: table.h:374
ulong privilege
The set of privileges that the current user has fulfilled for a certain host, database,...
Definition: table.h:402
uint version
Used for cache invalidation when caching privilege information.
Definition: table.h:390
State information for internal tables grants.
Definition: table.h:343
bool m_table_lookup_done
True if the internal lookup by table name was done.
Definition: table.h:349
const ACL_internal_table_access * m_table_access
Cached internal table access.
Definition: table.h:351
bool m_schema_lookup_done
True if the internal lookup by schema name was done.
Definition: table.h:345
const ACL_internal_schema_access * m_schema_access
Cached internal schema access.
Definition: table.h:347
Struct to hold information about the table that should be created.
Definition: handler.h:3177
Hook class which via its methods specifies which members of T should be used for participating in a i...
Definition: sql_plist.h:197
Definition of name for generated keys, owned by TABLE_SHARE.
Definition: table.h:689
char name[NAME_CHAR_LEN]
Definition: table.h:690
Definition: table.h:2676
bool use_default_password_lifetime
Definition: table.h:2679
bool update_password_expired_column
Definition: table.h:2678
bool update_failed_login_attempts
Definition: table.h:2690
uint32 password_reuse_interval
Definition: table.h:2686
bool use_default_password_reuse_interval
Definition: table.h:2687
Lex_acl_attrib_udyn update_password_require_current
Definition: table.h:2694
uint failed_login_attempts
Definition: table.h:2689
bool update_password_reuse_interval
Definition: table.h:2688
bool update_password_history
Definition: table.h:2685
int password_lock_time
Definition: table.h:2691
bool update_account_locked_column
Definition: table.h:2681
bool update_password_expired_fields
Definition: table.h:2677
bool use_default_password_history
Definition: table.h:2684
bool update_password_lock_time
Definition: table.h:2692
bool account_locked
Definition: table.h:2682
void cleanup()
Definition: table.h:2695
uint16 expire_after_days
Definition: table.h:2680
uint32 password_history_length
Definition: table.h:2683
Definition: table.h:2611
bool modify_factor
Definition: table.h:2633
LEX_CSTRING generated_password
Definition: table.h:2614
LEX_CSTRING auth
Definition: table.h:2613
bool uses_identified_with_clause
Definition: table.h:2626
bool uses_authentication_string_clause
Definition: table.h:2625
bool finish_registration
Definition: table.h:2646
LEX_CSTRING plugin
Definition: table.h:2612
LEX_CSTRING client_plugin
Definition: table.h:2616
void copy(LEX_MFA *m, MEM_ROOT *alloc)
Definition: table.cc:7339
bool uses_identified_by_clause
Definition: table.h:2624
bool drop_factor
Definition: table.h:2635
bool init_registration
Definition: table.h:2644
uint nth_factor
Definition: table.h:2617
bool requires_registration
Definition: table.h:2640
LEX_CSTRING challenge_response
Definition: table.h:2615
bool add_factor
Definition: table.h:2631
bool has_password_generator
Definition: table.h:2627
LEX_MFA()
Definition: table.h:2648
bool unregister
Definition: table.h:2642
void reset()
Definition: table.h:2649
bool passwordless
Definition: table.h:2629
Definition: table.h:2720
bool retain_current_password
Definition: table.h:2725
LEX_ALTER alter_status
Definition: table.h:2727
List< LEX_MFA > mfa_list
Definition: table.h:2730
bool uses_replace_clause
Definition: table.h:2724
LEX_CSTRING host
Definition: table.h:2722
static LEX_USER * alloc(THD *thd)
Definition: table.cc:7375
void init()
Definition: table.h:2733
LEX_CSTRING current_auth
Definition: table.h:2723
bool with_initial_auth
Definition: table.h:2731
LEX_CSTRING user
Definition: table.h:2721
LEX_MFA first_factor_auth_info
Definition: table.h:2729
LEX_USER()
Definition: table.h:2760
bool discard_old_password
Definition: table.h:2726
bool add_mfa_identifications(LEX_MFA *factor2, LEX_MFA *factor3=nullptr)
Definition: table.cc:7382
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3787
Definition: thr_lock.h:98
thr_lock_type type
Definition: thr_lock.h:99
@ TABLE
Definition: mdl.h:404
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
void ClearForReuse()
Similar to Clear(), but anticipates that the block will be reused for further allocations.
Definition: my_alloc.cc:189
Definition: mysql_lex_string.h:39
const char * str
Definition: mysql_lex_string.h:40
size_t length
Definition: mysql_lex_string.h:41
Definition: mysql_lex_string.h:34
Definition: my_bitmap.h:42
my_bitmap_map * bitmap
Definition: my_bitmap.h:43
Struct NESTED_JOIN is used to represent how tables are connected through outer join operations and se...
Definition: nested_join.h:77
Definition: item.h:400
Definition: table.h:4131
uint32 locked
Definition: table.h:4134
char * table
Definition: table.h:4133
OPEN_TABLE_LIST * next
Definition: table.h:4132
uint32 in_use
Definition: table.h:4134
char * db
Definition: table.h:4133
Definition: table.h:283
const char * used_alias
Tells whether this ORDER element was referenced with an alias or with an expression in the query,...
Definition: table.h:321
char * buff
Definition: table.h:332
bool is_item_original() const
Definition: table.h:285
Item_rollup_group_item * rollup_item
Definition: table.h:310
bool in_field_list
Definition: table.h:314
Item * item_initial
The initial ordering expression.
Definition: table.h:300
ORDER * next
Definition: table.h:287
MY_BITMAP * grouping_set_info
If the query block includes non-primitive grouping, then these modifiers are represented as grouping ...
Definition: table.h:295
enum_order direction
Definition: table.h:312
Item ** item
Points at the item in the select fields.
Definition: table.h:308
table_map depend_map
Definition: table.h:333
Field * field_in_tmp_table
When GROUP BY is implemented with a temporary table (i.e.
Definition: table.h:331
table_map used
Definition: table.h:333
bool is_explicit
Definition: table.h:334
A struct that contains execution time state used for partial update of JSON columns.
Definition: table.cc:7430
Definition: table.h:2486
int value
Definition: table.h:2504
const char * field_name
This is used as column name.
Definition: table.h:2490
enum_field_types field_type
This denotes data type for the column.
Definition: table.h:2503
const char * old_name
Definition: table.h:2514
uint open_method
Definition: table.h:2515
uint field_flags
This is used to set column attributes.
Definition: table.h:2513
uint field_length
For string-type columns, this is the maximum number of characters.
Definition: table.h:2497
Definition: table.h:2518
int(* process_table)(THD *thd, Table_ref *tables, TABLE *table, bool res, LEX_CSTRING db_name, LEX_CSTRING table_name)
Definition: table.h:2525
int(* fill_table)(THD *thd, Table_ref *tables, Item *cond)
Definition: table.h:2522
ST_FIELD_INFO * fields_info
Definition: table.h:2520
int(* old_format)(THD *thd, ST_SCHEMA_TABLE *schema_table)
Definition: table.h:2524
bool hidden
Definition: table.h:2527
const char * table_name
Definition: table.h:2519
Definition: table.h:598
const TABLE_FIELD_TYPE * field
Definition: table.h:600
uint count
Definition: table.h:599
Definition: table.h:592
LEX_CSTRING cset
Definition: table.h:595
LEX_CSTRING name
Definition: table.h:593
LEX_CSTRING type
Definition: table.h:594
This structure is shared between different table objects.
Definition: table.h:698
ulong stored_rec_length
Definition: table.h:799
uint next_number_index
Definition: table.h:916
Key_map keys_in_use
The set of indexes that are not disabled for this table.
Definition: table.h:790
TABLE_SHARE_FOREIGN_KEY_PARENT_INFO * foreign_key_parent
Definition: table.h:1035
bool visit_subgraph(Wait_for_flush *waiting_ticket, MDL_wait_for_graph_visitor *gvisitor)
Traverse portion of wait-for graph which is reachable through this table share in search for deadlock...
Definition: table.cc:3913
Table_cache_element ** cache_element
Array of table_cache_instances pointers to elements of table caches respresenting this table in each ...
Definition: table.h:743
MEM_ROOT mem_root
Definition: table.h:724
bool is_primary_engine() const
Does this TABLE_SHARE represent a table in a primary storage engine?
Definition: table.h:1242
void destroy()
Release resources and free memory occupied by the table share.
Definition: table.cc:540
TABLE_SHARE_FOREIGN_KEY_INFO * foreign_key
Definition: table.h:1033
bool is_secondary_engine() const
Does this TABLE_SHARE represent a table in a secondary storage engine?
Definition: table.h:1245
uint stats_sample_pages
Definition: table.h:836
handlerton * db_type() const
Definition: table.h:804
Table_histograms_collection * m_histograms
Definition: table.h:719
LEX_STRING comment
Definition: table.h:752
Handler_share * ha_share
Main handler's share.
Definition: table.h:998
MEM_ROOT * alloc_for_tmp_file_handler
Used to allocate new handler for internal temporary table when the size limitation of the primary sto...
Definition: table.h:729
enum_stats_auto_recalc stats_auto_recalc
Definition: table.h:839
const char * tablespace
Definition: table.h:948
partition_info * m_part_info
Partition meta data.
Definition: table.h:968
LEX_STRING compress
Definition: table.h:753
const TABLE_FIELD_DEF * table_field_def_cache
Cache the checked structure of this table.
Definition: table.h:995
uint column_bitmap_size
Definition: table.h:920
ulong mysql_version
Definition: table.h:797
uint max_tmp_key_parts
For materialized derived tables: allocated size of base_key_parts array of all TABLE objects.
Definition: table.h:877
uint total_key_length
Definition: table.h:851
TYPELIB keynames
Definition: table.h:731
uchar * default_values
Definition: table.h:751
LEX_STRING encrypt_type
Definition: table.h:754
PSI_table_share * m_psi
Instrumentation for this table share.
Definition: table.h:1001
bool is_missing_primary_key() const
Determine if the table is missing a PRIMARY KEY.
Definition: table.h:1189
bool db_low_byte_first
Definition: table.h:926
Schema_read_only
Schema's read only mode - ON (true) or OFF (false).
Definition: table.h:1048
LEX_CSTRING table_cache_key
Definition: table.h:775
unsigned int m_ref_count
How many TABLE objects use this TABLE_SHARE.
Definition: table.h:1260
unsigned long version() const
Returns the version of this TABLE_SHARE.
Definition: table.h:1099
uint max_unique_length
Definition: table.h:850
tmp_table_type tmp_table
Definition: table.h:818
unsigned long m_version
TABLE_SHARE version, if changed the TABLE_SHARE must be reopened.
Definition: table.h:1267
uint find_first_unused_tmp_key(const Key_map &k)
For a materialized derived table: informs the share that certain not-yet-used keys are going to be us...
Definition: table.cc:6039
int cached_row_logging_check
Definition: table.h:938
ulong reclength
Definition: table.h:798
uint varchar_fields
Definition: table.h:863
uint next_number_keypart
Definition: table.h:918
bool secondary_load
Secondary engine load status.
Definition: table.h:759
uint tmp_handler_count
Only for internal temporary tables.
Definition: table.h:825
Field ** field
Definition: table.h:746
ulong avg_row_length
Definition: table.h:796
plugin_ref db_plugin
Definition: table.h:803
LEX_CSTRING table_name
Definition: table.h:777
const dd::View * view_object
View object holding view definition read from DD.
Definition: table.h:1013
uint db_create_options
Bitmap with flags representing some of table options/attributes.
Definition: table.h:903
uint rec_buff_length
Definition: table.h:844
uint blob_fields
Definition: table.h:862
uint max_tmp_keys
For materialized derived tables: allocated size of key_info array.
Definition: table.h:872
LEX_STRING connect_string
Definition: table.h:780
Field ** found_next_number_field
Definition: table.h:747
ha_rows min_rows
Definition: table.h:795
bool is_referenced_by_foreign_key() const
Returns whether this table is referenced by a foreign key.
Definition: table.h:1256
uint foreign_keys
Arrays with descriptions of foreign keys in which this table participates as child or parent.
Definition: table.h:1032
Schema_read_only schema_read_only
Definition: table.h:1049
bool wait_for_old_version(THD *thd, struct timespec *abstime, uint deadlock_weight)
Wait until the subject share is removed from the table definition cache and make sure it's destroyed.
Definition: table.cc:4007
uint fields
Definition: table.h:843
uint tmp_open_count
Only for internal temporary tables.
Definition: table.h:831
Key_name * key_names
Array of names for generated keys, used for materialized derived tables.
Definition: table.h:882
Key_map keys_for_keyread
Definition: table.h:794
char * partition_info_str
Storing the full partitioning clause (PARTITION BY ...) which is used when creating new partition_inf...
Definition: table.h:982
TABLE_SHARE(unsigned long version, bool secondary)
Create a new TABLE_SHARE with the given version number.
Definition: table.h:707
uint null_bytes
Definition: table.h:842
bool system
Definition: table.h:925
bool is_view
Definition: table.h:928
ulonglong get_table_ref_version() const
Return a table metadata version.
Definition: table.cc:4080
uint rowid_field_offset
Definition: table.h:913
uint max_key_length
Definition: table.h:849
ulong * base_rec_per_key
Records per key array, used for materialized derived tables.
Definition: table.h:888
bool has_secondary_engine() const
Does this TABLE_SHARE represent a primary table that has a shadow copy in a secondary storage engine?
Definition: table.h:1251
bool is_distinct
Whether this is a temporary table that already has a UNIQUE index (removing duplicate rows on insert)...
Definition: table.h:859
dd::Table * tmp_table_def
Data-dictionary object describing explicit temporary table represented by this share.
Definition: table.h:1021
TABLE_SHARE * next
Definition: table.h:734
LEX_STRING path
Definition: table.h:778
bool m_open_in_progress
Definition: table.h:929
uint next_number_key_offset
Definition: table.h:917
uint keys
Definition: table.h:845
Key_map visible_indexes
The set of visible and enabled indexes for this table.
Definition: table.h:793
uint foreign_key_parents
Definition: table.h:1034
bool has_old_version() const
Is this table share being expelled from the table definition cache?
Definition: table.h:1109
mysql_mutex_t LOCK_ha_data
Definition: table.h:733
Wait_for_flush_list m_flush_tickets
List of tickets representing threads waiting for the share to be flushed.
Definition: table.h:1006
void clear_version()
Set the version of this TABLE_SHARE to zero.
Definition: table.cc:529
uint gen_def_field_count
Number of fields having the default value generated.
Definition: table.h:924
MY_BITMAP all_set
Definition: table.h:764
unsigned int ref_count() const
How many TABLE objects use this TABLE_SHARE.
Definition: table.h:1215
uint last_null_bit_pos
Definition: table.h:842
TABLE_CATEGORY table_category
Category of this table.
Definition: table.h:722
bool error
Definition: table.h:919
unsigned int decrement_ref_count()
Decrement the reference count by one.
Definition: table.h:1234
const CHARSET_INFO * table_charset
Definition: table.h:761
unsigned int increment_ref_count()
Increment the reference count by one.
Definition: table.h:1224
mysql::binlog::event::Table_id table_map_id
Definition: table.h:930
bool auto_partitioned
Filled in when reading from frm.
Definition: table.h:975
void set_table_cache_key(char *key_buff, const char *key, size_t key_length)
Set share's table cache key and update its db and table name appropriately.
Definition: table.h:1091
void set_table_cache_key(char *key_buff, size_t key_length)
Set share's table cache key and update its db and table name appropriately.
Definition: table.h:1065
ulonglong autoextend_size
Definition: table.h:801
uint primary_key
Definition: table.h:915
ha_storage_media default_storage_media
Definition: table.h:945
rec_per_key_t * base_rec_per_key_float
Records per key array, float rep., used for materialized derived tables.
Definition: table.h:894
bool m_secondary_engine
Does this TABLE_SHARE represent a table in a secondary storage engine?
Definition: table.h:1271
std::uint32_t key_block_size
Definition: table.h:835
bool crashed
Definition: table.h:927
Key_map usable_indexes(const THD *thd) const
The set of indexes that the optimizer may use when creating an execution plan.
Definition: table.cc:503
LEX_CSTRING normalized_path
Definition: table.h:779
uint key_parts
Definition: table.h:846
uint vfields
Number of generated fields.
Definition: table.h:922
enum enum_table_ref_type get_table_ref_type() const
Convert unrelated members of TABLE_SHARE to one enum representing its type.
Definition: table.h:1117
uint db_options_in_use
Bitmap with flags representing some of table options/attributes which are in use by storage engine.
Definition: table.h:912
ha_rows max_rows
Definition: table.h:795
ulonglong get_table_def_version() const
Definition: table.h:1096
TYPELIB * intervals
Definition: table.h:732
uint first_unused_tmp_key
For materialized derived tables;.
Definition: table.h:868
TABLE_SHARE ** prev
Definition: table.h:734
uint null_fields
Definition: table.h:861
LEX_CSTRING secondary_engine
Secondary storage engine.
Definition: table.h:757
KEY * key_info
Definition: table.h:748
uint partition_info_str_len
Definition: table.h:983
LEX_CSTRING db
Definition: table.h:776
LEX_CSTRING engine_attribute
Definition: table.h:782
LEX_CSTRING secondary_engine_attribute
Definition: table.h:783
uint * blob_field
Definition: table.h:749
enum row_type real_row_type
Real row format used for the table by the storage engine.
Definition: table.h:817
TABLE_SHARE()=default
Sql_check_constraint_share_list * check_constraint_share_list
Definition: table.h:1038
Query_block * owner_of_possible_tmp_keys
For materialized derived tables;.
Definition: table.h:1024
Definition: table.h:1403
void mark_columns_used_by_index(uint index)
Definition: table.cc:5493
bool materialized
For a materializable derived or SJ table: true if has been materialized.
Definition: table.h:1879
void mark_generated_columns(bool is_update)
Update the write/read_set for generated columns when doing update and insert operation.
Definition: table.cc:6225
class QEP_TAB * qep_tab
Definition: table.h:1883
bool m_invalid_dict
This TABLE object is invalid and cannot be reused.
Definition: table.h:1859
query_id_t query_id
Definition: table.h:1731
bool force_index_order
Flag set when the statement contains FORCE INDEX FOR ORDER BY See Table_ref::process_index_hints().
Definition: table.h:1793
void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg, MY_BITMAP *write_set_arg)
Definition: table.h:1957
void mark_columns_needed_for_update(THD *thd, bool mark_binlog_columns)
Mark columns needed for doing an update of a row.
Definition: table.cc:5661
const char * alias
alias or table name
Definition: table.h:1632
partition_info * part_info
Definition: table.h:1918
void set_hashing(bool use_hashing)
Definition: table.h:1576
uint8 m_status
Definition: table.h:1771
bool key_read
If set, the optimizer has found that row retrieval should access index tree only.
Definition: table.h:1808
bool no_replicate
If set, indicate that the table is not replicated by the server.
Definition: table.h:1817
class JOIN_TAB * join_tab
Definition: table.h:1882
void set_no_row()
Set status for row buffer: contains no row.
Definition: table.h:2090
void mark_columns_needed_for_insert(THD *thd)
Definition: table.cc:6169
Field ** vfield
Pointer to generated columns.
Definition: table.h:1506
void clear_column_bitmaps(void)
Definition: table.cc:5393
uint tmp_table_seq_id
Internal tmp table sequential number.
Definition: table.h:1932
TABLE ** cache_prev
Definition: table.h:1416
Key_map covering_keys
Definition: table.h:1462
uchar * null_flags
Pointer to the null flags of record[0].
Definition: table.h:1633
Key_map keys_in_use_for_group_by
Definition: table.h:1493
Key_map keys_in_use_for_query
Definition: table.h:1491
Field_longlong * set_counter()
Definition: table.h:1619
void set_storage_handler(handler *file_arg)
Set storage handler for temporary table.
Definition: table.h:2020
bool has_null_row() const
Definition: table.h:2143
Record_buffer m_record_buffer
Buffer for use in multi-row reads. Initially empty.
Definition: table.h:1456
void set_deleted()
Set the contents of table to be "deleted", ie "not created", after having deleted the contents.
Definition: table.h:2040
Set_operator_type m_set_op_type
Holds the set operation type.
Definition: table.h:1568
void set_created()
Set the table as "created", and enable flags in storage engine that could not be enabled without an i...
Definition: table.cc:6156
void use_all_columns()
Definition: table.h:1962
bool has_updated_row() const
Definition: table.h:2146
TABLE * cache_next
Links for the lists of used/unused TABLE objects for the particular table in the specific instance of...
Definition: table.h:1416
Set_operator_type set_op_type()
Returns the set operation type.
Definition: table.h:1583
void blobs_need_not_keep_old_value()
Virtual fields of type BLOB have a flag m_keep_old_value.
Definition: table.cc:7955
Table_ref * pos_in_table_list
Definition: table.h:1628
bool uses_hashing() const
Definition: table.h:1580
void set_set_op(Field_longlong *set_counter, bool except, bool distinct)
Initialize the set counter field pointer and the type of set operation other than UNION*.
Definition: table.h:1610
ORDER * group
Definition: table.h:1631
bool has_binary_diff_columns() const
Does this table have any columns that can be updated using partial update in the current row?
Definition: table.cc:7551
void mark_columns_per_binlog_row_image(THD *thd)
Definition: table.cc:5733
ha_rows quick_condition_rows
Definition: table.h:1753
THD * in_use
The current session using this table object.
Definition: table.h:1445
void disable_logical_diffs_for_current_row(const Field *field) const
Temporarily disable collection of Json_diff objects describing the logical changes of a JSON column i...
Definition: table.cc:7786
MY_BITMAP * fields_set_during_insert
A pointer to the bitmap of table fields (columns), which are explicitly set in the INSERT INTO statem...
Definition: table.h:1711
void mark_columns_needed_for_delete(THD *thd)
Definition: table.cc:5584
ha_rows quick_rows[MAX_KEY]
Definition: table.h:1737
thr_lock_type lock_type
Definition: table.h:1884
bool null_row
Definition: table.h:1778
uint lock_data_start
Definition: table.h:1756
bool const_table
Definition: table.h:1800
MY_BITMAP read_set_internal
A bitmap of fields that are explicitly referenced by the query.
Definition: table.h:1698
bool is_marked_for_partial_update(const Field *field) const
Has this column been marked for partial update?
Definition: table.cc:7545
bool force_index_group
Flag set when the statement contains FORCE INDEX FOR GROUP BY See Table_ref::process_index_hints().
Definition: table.h:1799
bool has_storage_handler() const
Definition: table.h:2017
bool open_by_handler
Definition: table.h:1819
void bind_value_generators_to_fields()
Bind all the table's value generator columns in all the forms: stored/virtual GC, default expressions...
Definition: table.cc:4272
Table_ref * pos_in_locked_tables
Definition: table.h:1630
void disable_binary_diffs_for_current_row(const Field *field)
Temporarily disable collection of binary diffs for a column in the current row.
Definition: table.cc:7533
void set_keyread(bool flag)
Definition: table.cc:6145
bool index_contains_some_virtual_gcol(uint index_no) const
Check whether the given index has a virtual generated columns.
Definition: table.h:2004
uint db_stat
Definition: table.h:1758
bool is_logical_diff_enabled(const Field *field) const
Is partial update using logical diffs enabled on this JSON column?
Definition: table.cc:7764
bool has_invalid_dict() const
Definition: table.h:1975
bool has_invalid_stats()
Definition: table.h:1980
uchar * insert_values
Definition: table.h:1453
ptrdiff_t default_values_offset() const
Definition: table.h:2012
uchar * record[2]
Definition: table.h:1450
void invalidate_dict()
Definition: table.cc:8002
void mark_auto_increment_column(void)
Mark auto-increment fields as used fields in both read and write maps.
Definition: table.cc:5553
bool alias_name_used
Definition: table.h:1837
bool fill_item_list(mem_root_deque< Item * > *item_list) const
Create Item_field for each column in the table.
Definition: table.cc:4329
bool impossible_range
Definition: table.h:1890
bool is_binary_diff_enabled(const Field *field) const
Is partial update using binary diffs enabled on this JSON column?
Definition: table.cc:7758
void invalidate_stats()
Definition: table.cc:8013
Cost_model_table m_cost_model
Cost model object for operations on this table.
Definition: table.h:1925
bool should_binlog_drop_if_temp_flag
This flag decides whether or not we should log the drop temporary table command.
Definition: table.h:2252
void cleanup_value_generator_items()
Clean any state in items associated with generated columns to be ready for the next statement.
Definition: table.cc:4298
bool m_deduplicate_with_hashing
If false, de-duplication happens via an index on this table, if true, via an in-memory hash table,...
Definition: table.h:1553
Field_longlong * m_set_counter
The set counter.
Definition: table.h:1542
void init_cost_model(const Cost_model_server *cost_model_server)
Initialize the optimizer cost model.
Definition: table.h:2177
bool not_exists_optimize
Definition: table.h:1885
bool force_index
Definition: table.h:1787
void init(THD *thd, Table_ref *tl)
Initialize TABLE instance (newly created, or coming either from table cache or THD::temporary_tables ...
Definition: table.cc:4107
bool is_except() const
Definition: table.h:1596
MY_BITMAP * read_set
The read set contains the set of columns that the execution engine needs to process the query.
Definition: table.h:1680
bool should_binlog_drop_if_temp(void) const
Definition: table.cc:7970
bool get_fields_in_item_tree
Definition: table.h:1838
uint visible_field_count() const
Definition: table.h:1987
const Binary_diff_vector * get_binary_diffs(const Field *field) const
Get the list of binary diffs that have been collected for a given column in the current row,...
Definition: table.cc:7642
void mark_check_constraint_columns(bool is_update)
Update the read_map with columns needed for check constraint evaluation when doing update and insert ...
Definition: table.cc:6285
int current_lock
Definition: table.h:1759
void move_tmp_key(int old_idx, bool modify_share)
For a materialized derived table: moves a KEY definition from a position to the first not-yet-used po...
Definition: table.cc:6062
uint quick_n_ranges[MAX_KEY]
Definition: table.h:1743
TABLE * next
Definition: table.h:1406
bool add_binary_diff(const Field *field, size_t offset, size_t length)
Add a binary diff for a column that is updated using partial update.
Definition: table.cc:7647
bool m_invalid_stats
This TABLE object is invalid and cannot be reused as it has outdated rec_per_key and handler stats.
Definition: table.h:1868
bool empty_result_table()
Empties internal temporary table (deletes rows, closes scan)
Definition: table.cc:7974
void cleanup_partial_update()
Clean up state used for partial update of JSON columns.
Definition: table.cc:7612
uint lock_position
Definition: table.h:1755
Key_map quick_keys
Definition: table.h:1463
void restore_null_flags()
Restore the NULL flags of the current row from the designated buffer.
Definition: table.h:2163
Table_trigger_dispatcher * triggers
Definition: table.h:1627
bool no_keyread
Certain statements which need the full row, set this to ban index-only access.
Definition: table.h:1813
bool is_intersect() const
Definition: table.h:1591
void set_tmp_table_seq_id(uint arg)
Definition: table.h:2206
Partial_update_info * m_partial_update_info
Object which contains execution time state used for partial update of JSON columns.
Definition: table.h:2246
void set_binlog_drop_if_temp(bool should_binlog)
Set the variable should_binlog_drop_if_temp_flag, so that the logging of temporary tables can be deci...
Definition: table.cc:7966
void mark_gcol_in_maps(const Field *field)
Adds a generated column and its dependencies to the read_set/write_set bitmaps.
Definition: table.cc:7263
void set_deleted_row()
Set "deleted" property for the current row.
Definition: table.h:2134
void reset_null_row()
Clear "null row" status for the current row.
Definition: table.h:2122
Field ** gen_def_fields_ptr
Pointer to fields having the default value generated.
Definition: table.h:1508
MY_BITMAP fields_for_functional_indexes
A bitmap marking the hidden generated columns that exists for functional indexes.
Definition: table.h:1433
void set_not_started()
Life cycle of the row buffer is as follows:
Definition: table.h:2070
const histograms::Histogram * find_histogram(uint field_index) const
Find the histogram for the given field index.
Definition: table.cc:7798
SortingIterator * sorting_iterator
Not owned by the TABLE; used only from filesort_free_buffers().
Definition: table.h:1910
bool m_last_operation_is_distinct
If m_set_counter is set: true if last block has DISTINCT semantics, either because it is marked as su...
Definition: table.h:1549
key_part_map const_key_parts[MAX_KEY]
Definition: table.h:1740
Field ** field
Definition: table.h:1446
bool alloc_tmp_keys(uint new_key_count, uint new_key_part_count, bool modify_share)
Allocate space for keys, for a materialized derived table.
Definition: table.cc:5815
MEM_ROOT mem_root
Definition: table.h:1898
void column_bitmaps_set(MY_BITMAP *read_set_arg, MY_BITMAP *write_set_arg)
Definition: table.cc:7293
uint hidden_field_count
Count of hidden fields, if internal temporary table; 0 otherwise.
Definition: table.h:1448
bool is_nullable() const
Return whether table is nullable.
Definition: table.h:2045
MY_BITMAP tmp_set
Definition: table.h:1638
MDL_ticket * mdl_ticket
Definition: table.h:1921
bool has_gcol() const
Definition: table.h:2048
bool all_partitions_pruned_away
Definition: table.h:1920
MY_BITMAP def_read_set
Definition: table.h:1638
String * get_partial_update_buffer()
Get a buffer that can be used to hold the partially updated column value while performing partial upd...
Definition: table.cc:7618
bool setup_partial_update()
Definition: table.cc:7583
bool has_deleted_row() const
Definition: table.h:2149
bool check_read_removal(uint index)
Read removal is possible if the selected quick read method is using full unique index.
Definition: table.cc:7055
const Json_diff_vector * get_logical_diffs(const Field_json *field) const
Get the list of JSON diffs that have been collected for a given column in the current row,...
Definition: table.cc:7752
KEY_PART_INFO * base_key_parts
Key part array for generated keys, used for materialized derived tables.
Definition: table.h:1501
bool is_started() const
Definition: table.h:2076
Set_operator_type
Definition: table.h:1556
@ SOT_EXCEPT_DISTINCT
Definition: table.h:1563
@ SOT_NONE
Definition: table.h:1557
@ SOT_UNION_ALL
Definition: table.h:1558
@ SOT_INTERSECT_ALL
Definition: table.h:1560
@ SOT_INTERSECT_DISTINCT
Definition: table.h:1561
@ SOT_UNION_DISTINCT
Definition: table.h:1559
@ SOT_EXCEPT_ALL
Definition: table.h:1562
MY_BITMAP cond_set
Definition: table.h:1647
void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map, uint key_parts=0) const
mark columns used by key, but don't reset other fields
Definition: table.cc:5531
void reset()
Reset state of fields after optimization and execution.
Definition: table.cc:4177
MY_BITMAP pack_row_tmp_set
Definition: table.h:1638
void default_column_bitmaps()
Definition: table.h:1965
void drop_unused_tmp_keys(bool modify_share)
For a materialized derived table: after move_tmp_key() has moved all definitions of used KEYs,...
Definition: table.cc:6119
void clear_partial_update_diffs()
Clear the diffs that have been collected for partial update of JSON columns, and re-enable partial up...
Definition: table.cc:7623
void set_null_row()
Set current row as "null row", for use in null-complemented outer join.
Definition: table.h:2115
handler * get_primary_handler() const
Returns the primary engine handler for the table.
Definition: table.cc:7300
Sql_table_check_constraint_list * table_check_constraint_list
Definition: table.h:1762
Key_map possible_quick_keys
Definition: table.h:1478
bool created
For tmp tables.
Definition: table.h:1875
bool has_row() const
Definition: table.h:2140
const Cost_model_table * cost_model() const
Return the cost model object for this table.
Definition: table.h:2184
Field * next_number_field
Definition: table.h:1503
void update_const_key_parts(Item *conds)
Update TABLE::const_key_parts for single table UPDATE/DELETE query.
Definition: table.cc:7025
void save_null_flags()
Save the NULL flags of the current row into the designated buffer.
Definition: table.h:2158
Field * found_next_number_field
Definition: table.h:1504
Key_map keys_in_use_for_order_by
Definition: table.h:1495
void set_row_status_from_handler(int status)
Set "row found" status from handler result.
Definition: table.h:2100
Field ** visible_field_ptr() const
Definition: table.h:1985
uchar * null_flags_saved
Saved null_flags while null_row is true.
Definition: table.h:1634
uchar * write_row_record
Definition: table.h:1451
ha_rows m_limit_rows
A priori unlimited.
Definition: table.h:1534
MY_BITMAP def_write_set
Definition: table.h:1638
bool is_union_or_table() const
Test if this tmp table stores the result of a UNION set operation or a single table.
Definition: table.h:1574
uint lock_count
Definition: table.h:1757
Field * hash_field
Field used by unique constraint.
Definition: table.h:1510
MY_BITMAP def_fields_set_during_insert
Bitmap of table fields (columns), which are explicitly set in the INSERT INTO statement.
Definition: table.h:1656
bool mark_column_for_partial_update(const Field *field)
Mark a given column as one that can potentially be updated using partial update during execution of a...
Definition: table.cc:7518
Field * fts_doc_id_field
Definition: table.h:1624
bool autoinc_field_has_explicit_non_null_value
To indicate that value of the auto_increment field was provided explicitly by the user or from some o...
Definition: table.h:1836
KEY * key_info
Definition: table.h:1496
bool init_tmp_table(THD *thd, TABLE_SHARE *share, MEM_ROOT *m_root, CHARSET_INFO *charset, const char *alias, Field **fld, uint *blob_fld, bool is_virtual)
Initialize table as internal tmp table.
Definition: table.cc:4222
void set_found_row()
Set status for row buffer: contains row.
Definition: table.h:2079
void mark_column_used(Field *field, enum enum_mark_columns mark)
Mark column as either read or written (or none) according to mark_used.
Definition: table.cc:5450
void set_nullable()
Set table as nullable, ie it is inner wrt some outer join.
Definition: table.h:2042
Blob_mem_storage * blob_storage
Initialized in Item_func_group_concat::setup for appropriate temporary table if GROUP_CONCAT is used ...
Definition: table.h:1904
void set_updated_row()
Set "updated" property for the current row.
Definition: table.h:2128
TABLE * prev
Definition: table.h:1406
void prepare_for_position(void)
Tell handler we are going to call position() and rnd_pos() later.
Definition: table.cc:5425
TABLE_SHARE * s
Definition: table.h:1404
bool has_columns_marked_for_partial_update() const
Does this table have any columns that were marked with mark_column_for_partial_update()?
Definition: table.cc:7603
MY_BITMAP * m_partial_update_columns
Bitmap that tells which columns are eligible for partial update in an update statement.
Definition: table.h:2237
bool copy_blobs
Definition: table.h:1780
void add_logical_diff(const Field_json *field, const Json_seekable_path &path, enum_json_diff_operation operation, const Json_wrapper *new_value)
Add a logical JSON diff describing a logical change to a JSON column in partial update.
Definition: table.cc:7722
bool is_distinct() const
Definition: table.h:1601
bool add_tmp_key(Field_map *key_parts, bool invisible, bool modify_share)
Add one key to a materialized derived table.
Definition: table.cc:5930
SortingIterator * duplicate_removal_iterator
Definition: table.h:1911
void update_covering_prefix_keys(Field *field, uint16 key_read_length, Key_map *covering_prefix_keys)
Update covering keys depending on max read key length.
Definition: table.cc:7986
bool nullable
If true, this table is inner w.r.t.
Definition: table.h:1769
Key_map merge_keys
Definition: table.h:1466
Sort_result unique_result
The result of applying a unique operation (by row ID) to the table, if done.
Definition: table.h:1917
bool is_created() const
Return true if table is instantiated, and false otherwise.
Definition: table.h:2029
uint quick_key_parts[MAX_KEY]
Definition: table.h:1742
MY_BITMAP * write_set
Definition: table.h:1682
struct TABLE::@184 reginfo
bool no_rows
True if writes to this table should not write rows and just write keys.
Definition: table.h:1802
Definition: typelib.h:34
Definition: table.h:664
LEX_CSTRING referenced_table_db
Definition: table.h:665
dd::Foreign_key::enum_rule delete_rule
Definition: table.h:672
LEX_CSTRING unique_constraint_name
Name of unique key matching FK in parent table, "" if there is no unique key.
Definition: table.h:671
LEX_CSTRING * column_name
Arrays with names of referencing columns of the FK.
Definition: table.h:677
uint columns
Definition: table.h:673
dd::Foreign_key::enum_rule update_rule
Definition: table.h:672
LEX_CSTRING referenced_table_name
Definition: table.h:666
dd::Foreign_key::enum_rule delete_rule
Definition: table.h:683
dd::Foreign_key::enum_rule update_rule
Definition: table.h:683
LEX_CSTRING referencing_table_name
Definition: table.h:682
LEX_CSTRING referencing_table_db
Definition: table.h:681
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2718
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: sql_plugin_ref.h:44
Contains the class Table_id, mainly used for row based replication.
thr_lock_type
Definition: thr_lock.h:50
@ TL_WRITE_LOW_PRIORITY
Definition: thr_lock.h:89
@ TL_UNLOCK
Definition: thr_lock.h:52
@ TL_READ
Definition: thr_lock.h:61
@ TL_WRITE_ALLOW_WRITE
Definition: thr_lock.h:72
static void mark()
Definition: xcom_transport.cc:690