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