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