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