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