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