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