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