MySQL 26.7.0
Source Code Documentation
handler.h
Go to the documentation of this file.
1#ifndef HANDLER_INCLUDED
2#define HANDLER_INCLUDED
3
4/*
5 Copyright (c) 2000, 2026, Oracle and/or its affiliates.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License, version 2.0,
9 as published by the Free Software Foundation.
10
11 This program is designed to work with certain software (including
12 but not limited to OpenSSL) that is licensed under separate terms,
13 as designated in a particular file or component or in included license
14 documentation. The authors of MySQL hereby grant you an additional
15 permission to link the program and your derivative works with the
16 separately licensed software that they have either included with
17 the program or referenced in the documentation.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License, version 2.0, for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27*/
28
29/* Definitions for parameters to do with handler-routines */
30
31#include <fcntl.h>
32#include <float.h>
33#include <string.h>
34#include <sys/types.h>
35#include <time.h>
36#include <algorithm>
37#include <atomic>
38#include <bit>
39#include <bitset>
40#include <functional>
41#include <map>
42#include <memory>
43#include <optional>
44#include <random> // std::mt19937
45#include <set>
46#include <string>
47#include <string_view>
48
51#include "ft_global.h" // ft_hints
52#include "lex_string.h"
53#include "map_helpers.h"
54#include "my_alloc.h"
55#include "my_base.h"
56#include "my_bitmap.h"
57#include "my_checksum.h" // ha_checksum
58#include "my_compiler.h"
59#include "my_dbug.h"
60#include "my_double2ulonglong.h"
61#include "my_inttypes.h"
62#include "my_io.h"
63#include "my_sys.h"
64#include "my_table_map.h"
65#include "my_thread_local.h" // my_errno
68#include "sql/dd/object_id.h" // dd::Object_id
69#include "sql/dd/string_type.h"
70#include "sql/dd/types/object_table.h" // dd::Object_table
71#include "sql/discrete_interval.h" // Discrete_interval
73#include "sql/key.h"
74#include "sql/sql_const.h" // SHOW_COMP_OPTION
75#include "sql/sql_list.h" // SQL_I_List
76#include "sql/sql_plugin_ref.h" // plugin_ref
77#include "string_with_len.h" // STRING_WITH_LEN
78#include "thr_lock.h" // thr_lock_type
79#include "typelib.h"
80
81class Alter_info;
82class Create_field;
83class Field;
84class Item;
85class JOIN;
86class Json_dom;
90class Plugin_table;
92class Record_buffer;
93class SE_cost_constants; // see opt_costconstants.h
94class String;
95class THD;
96class handler;
97class partition_info;
99class MDL_ticket;
100
101namespace dd {
102class Properties;
103} // namespace dd
104struct AccessPath;
105struct JoinHypergraph;
106struct KEY_CACHE;
107struct LEX;
108struct MY_BITMAP;
109struct SAVEPOINT;
110struct TABLE;
111class Table_ref;
112struct TABLE_SHARE;
113struct Tablespace_options;
114struct handlerton;
115
116typedef struct xid_t XID;
118struct MDL_key;
119
120namespace dd {
121enum class enum_column_types;
122class Table;
123class Tablespace;
124} // namespace dd
125
126constexpr const ha_rows EXTRA_RECORDS{10};
127
128/** Id for identifying Table SDIs */
129constexpr const uint32 SDI_TYPE_TABLE = 1;
130
131/** Id for identifying Tablespace SDIs */
132constexpr const uint32 SDI_TYPE_TABLESPACE = 2;
133
134/** Key to identify a dictionary object */
135struct sdi_key_t {
136 /** Type of Object, For ex: column, index, etc */
138
139 /** Object id which should be unique in tablespsace */
141};
142
143using sdi_container = std::vector<sdi_key_t>;
146};
147
148typedef bool (*qc_engine_callback)(THD *thd, const char *table_key,
149 uint key_length, ulonglong *engine_data);
150
151typedef bool(stat_print_fn)(THD *thd, const char *type, size_t type_len,
152 const char *file, size_t file_len,
153 const char *status, size_t status_len);
154
155class ha_statistics;
158class Unique_on_insert;
159
160extern ulong savepoint_alloc_size;
161
162/// Maps from slot to plugin. May return NULL if plugin has been unloaded.
163st_plugin_int *hton2plugin(uint slot);
164/// Returns the size of the array holding pointers to plugins.
165size_t num_hton2plugins();
166
167/**
168 For unit testing.
169 Insert plugin into arbitrary slot in array.
170 Remove plugin from arbitrary slot in array.
171*/
174
175extern const char *ha_row_type[];
176extern const char *tx_isolation_names[];
177extern const char *binlog_format_names[];
179extern ulong total_ha_2pc;
180
181// the following is for checking tables
182
183#define HA_ADMIN_ALREADY_DONE 1
184#define HA_ADMIN_OK 0
185#define HA_ADMIN_NOT_IMPLEMENTED -1
186#define HA_ADMIN_FAILED -2
187#define HA_ADMIN_CORRUPT -3
188#define HA_ADMIN_INTERNAL_ERROR -4
189#define HA_ADMIN_INVALID -5
190#define HA_ADMIN_REJECT -6
191#define HA_ADMIN_TRY_ALTER -7
192#define HA_ADMIN_WRONG_CHECKSUM -8
193#define HA_ADMIN_NOT_BASE_TABLE -9
194#define HA_ADMIN_NEEDS_UPGRADE -10
195#define HA_ADMIN_NEEDS_ALTER -11
196#define HA_ADMIN_NEEDS_CHECK -12
197#define HA_ADMIN_STATS_UPD_ERR -13
198/** User needs to dump and re-create table to fix pre 5.0 decimal types */
199#define HA_ADMIN_NEEDS_DUMP_UPGRADE -14
200
201/**
202 Return values for check_if_supported_inplace_alter().
203
204 @see check_if_supported_inplace_alter() for description of
205 the individual values.
206*/
217
218/**
219 * Used to identify which engine executed a SELECT query.
220 */
222
223/* Bits in table_flags() to show what database can do */
224
225#define HA_NO_TRANSACTIONS (1 << 0) /* Doesn't support transactions */
226#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
227/*
228 Used to avoid scanning full tables on an index. If this flag is set then
229 the handler always has a primary key (hidden if not defined) and this
230 index is used for scanning rather than a full table scan in all
231 situations. No separate data/index file.
232*/
233#define HA_TABLE_SCAN_ON_INDEX (1 << 2)
234
235/// Not in use.
236#define HA_UNUSED3 (1 << 3)
237
238/*
239 Can the storage engine handle spatial data.
240 Used to check that no spatial attributes are declared unless
241 the storage engine is capable of handling it.
242*/
243#define HA_CAN_GEOMETRY (1 << 4)
244/*
245 Reading keys in random order is as fast as reading keys in sort order
246 (Used by filesort to decide if we should sort key + data or key +
247 pointer-to-row.)
248*/
249#define HA_FAST_KEY_READ (1 << 5)
250/*
251 Set the following flag if we on delete should force all key to be read
252 and on update read all keys that changes
253*/
254#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
255/*
256 Is NULL values allowed in indexes.
257 If this is not allowed then it is not possible to use an index on a
258 NULLable field.
259*/
260#define HA_NULL_IN_KEY (1 << 7)
261/*
262 Tells that we can the position for the conflicting duplicate key
263 record is stored in table->file->dupp_ref. (insert uses rnd_pos() on
264 this to find the duplicated row)
265*/
266#define HA_DUPLICATE_POS (1 << 8)
267#define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
268/*
269 Is the storage engine capable of defining an index of a prefix on
270 a BLOB attribute.
271*/
272#define HA_CAN_INDEX_BLOBS (1 << 10)
273/*
274 Auto increment fields can be part of a multi-part key. For second part
275 auto-increment keys, the auto_incrementing is done in handler.cc
276*/
277#define HA_AUTO_PART_KEY (1 << 11)
278/*
279 Can't define a table without primary key (and cannot handle a table
280 with hidden primary key)
281*/
282#define HA_REQUIRE_PRIMARY_KEY (1 << 12)
283/*
284 Does the counter of records after the info call specify an exact
285 value or not. If it does this flag is set.
286*/
287#define HA_STATS_RECORDS_IS_EXACT (1 << 13)
288/// Not in use.
289#define HA_UNUSED14 (1 << 14)
290/*
291 This parameter is set when the handler will also return the primary key
292 when doing read-only-key on another index, i.e., if we get the primary
293 key columns for free when we do an index read (usually, it also implies
294 that HA_PRIMARY_KEY_REQUIRED_FOR_POSITION flag is set).
295*/
296#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
297/*
298 If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
299 uses a primary key given by the record argument.
300 Without primary key, we can't call position().
301 If not set, the position is returned as the current rows position
302 regardless of what argument is given.
303*/
304#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16)
305#define HA_CAN_RTREEKEYS (1 << 17)
306/// Not in use.
307#define HA_UNUSED18
308/*
309 The following is we need to a primary key to delete (and update) a row.
310 If there is no primary key, all columns needs to be read on update and delete
311*/
312#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
313/*
314 Indexes on prefixes of character fields are not allowed.
315*/
316#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
317/*
318 Does the storage engine support fulltext indexes.
319*/
320#define HA_CAN_FULLTEXT (1 << 21)
321/*
322 Can the HANDLER interface in the MySQL API be used towards this
323 storage engine.
324*/
325#define HA_CAN_SQL_HANDLER (1 << 22)
326/*
327 Set if the storage engine does not support auto increment fields.
328*/
329#define HA_NO_AUTO_INCREMENT (1 << 23)
330/*
331 Supports CHECKSUM option in CREATE TABLE (MyISAM feature).
332*/
333#define HA_HAS_CHECKSUM (1 << 24)
334/*
335 Table data are stored in separate files (for lower_case_table_names).
336 Should file names always be in lower case (used by engines that map
337 table names to file names.
338*/
339#define HA_FILE_BASED (1 << 26)
340#define HA_NO_VARCHAR (1 << 27)
341/*
342 Is the storage engine capable of handling bit fields.
343*/
344#define HA_CAN_BIT_FIELD (1 << 28)
345#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
346#define HA_NO_COPY_ON_ALTER (1LL << 31)
347#define HA_COUNT_ROWS_INSTANT (1LL << 32) /* records() gives exact count*/
348/* Has it's own method of binlog logging */
349#define HA_HAS_OWN_BINLOGGING (1LL << 33)
350/*
351 Engine is capable of row-format and statement-format logging,
352 respectively
353*/
354#define HA_BINLOG_ROW_CAPABLE (1LL << 34)
355#define HA_BINLOG_STMT_CAPABLE (1LL << 35)
356/*
357 When a multiple key conflict happens in a REPLACE command mysql
358 expects the conflicts to be reported in the ascending order of
359 key names.
360
361 For e.g.
362
363 CREATE TABLE t1 (a INT, UNIQUE (a), b INT NOT NULL, UNIQUE (b), c INT NOT
364 NULL, INDEX(c));
365
366 REPLACE INTO t1 VALUES (1,1,1),(2,2,2),(2,1,3);
367
368 MySQL expects the conflict with 'a' to be reported before the conflict with
369 'b'.
370
371 If the underlying storage engine does not report the conflicting keys in
372 ascending order, it causes unexpected errors when the REPLACE command is
373 executed.
374
375 This flag helps the underlying SE to inform the server that the keys are not
376 ordered.
377*/
378#define HA_DUPLICATE_KEY_NOT_IN_ORDER (1LL << 36)
379/*
380 Engine supports REPAIR TABLE. Used by CHECK TABLE FOR UPGRADE if an
381 incompatible table is detected. If this flag is set, CHECK TABLE FOR UPGRADE
382 will report ER_TABLE_NEEDS_UPGRADE, otherwise ER_TABLE_NEED_REBUILD.
383*/
384#define HA_CAN_REPAIR (1LL << 37)
385
386/*
387 Set of all binlog flags. Currently only contain the capabilities
388 flags.
389 */
390#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
391
392/**
393 The handler supports read before write removal optimization
394
395 Read before write removal may be used for storage engines which support
396 write without previous read of the row to be updated. Handler returning
397 this flag must implement start_read_removal() and end_read_removal().
398 The handler may return "fake" rows constructed from the key of the row
399 asked for. This is used to optimize UPDATE and DELETE by reducing the
400 number of round-trips between handler and storage engine.
401
402 Example:
403 UPDATE a=1 WHERE pk IN (@<keys@>)
404
405 @verbatim
406 mysql_update()
407 {
408 if (<conditions for starting read removal>)
409 start_read_removal()
410 -> handler returns true if read removal supported for this table/query
411
412 while(read_record("pk=<key>"))
413 -> handler returns fake row with column "pk" set to <key>
414
415 ha_update_row()
416 -> handler sends write "a=1" for row with "pk=<key>"
417
418 end_read_removal()
419 -> handler returns the number of rows actually written
420 }
421 @endverbatim
422
423 @note This optimization in combination with batching may be used to
424 remove even more round-trips.
425*/
426#define HA_READ_BEFORE_WRITE_REMOVAL (1LL << 38)
427
428/*
429 Engine supports extended fulltext API
430 */
431#define HA_CAN_FULLTEXT_EXT (1LL << 39)
432
433/*
434 Storage engine doesn't synchronize result set with expected table contents.
435 Used by replication slave to check if it is possible to retrieve rows from
436 the table when deciding whether to do a full table scan, index scan or hash
437 scan while applying a row event.
438 */
439#define HA_READ_OUT_OF_SYNC (1LL << 40)
440
441/*
442 Storage engine supports table export using the
443 FLUSH TABLE <table_list> FOR EXPORT statement.
444 */
445#define HA_CAN_EXPORT (1LL << 41)
446
447/*
448 The handler don't want accesses to this table to
449 be const-table optimized
450*/
451#define HA_BLOCK_CONST_TABLE (1LL << 42)
452
453/*
454 Handler supports FULLTEXT hints
455*/
456#define HA_CAN_FULLTEXT_HINTS (1LL << 43)
457
458/**
459 Storage engine doesn't support LOCK TABLE ... READ LOCAL locks
460 but doesn't want to use handler::store_lock() API for upgrading
461 them to LOCK TABLE ... READ locks, for example, because it doesn't
462 use THR_LOCK locks at all.
463*/
464#define HA_NO_READ_LOCAL_LOCK (1LL << 44)
465
466/**
467 A storage engine is compatible with the attachable transaction requirements
468 means that
469
470 - either SE detects the fact that THD::ha_data was reset and starts a new
471 attachable transaction, closes attachable transaction on close_connection
472 and resumes regular (outer) transaction when THD::ha_data is restored;
473
474 - or SE completely ignores THD::ha_data and close_connection like MyISAM
475 does.
476*/
477#define HA_ATTACHABLE_TRX_COMPATIBLE (1LL << 45)
478
479/**
480 Handler supports Generated Columns
481*/
482#define HA_GENERATED_COLUMNS (1LL << 46)
483
484/**
485 Supports index on virtual generated column
486*/
487#define HA_CAN_INDEX_VIRTUAL_GENERATED_COLUMN (1LL << 47)
488
489/**
490 Supports descending indexes
491*/
492#define HA_DESCENDING_INDEX (1LL << 48)
493
494/**
495 Supports partial update of BLOB columns.
496*/
497#define HA_BLOB_PARTIAL_UPDATE (1LL << 49)
498
499/**
500 If this isn't defined, only columns/indexes with Cartesian coordinate systems
501 (projected SRS or SRID 0) is supported. Columns/indexes without SRID
502 restriction is also supported if this isn't defined.
503*/
504#define HA_SUPPORTS_GEOGRAPHIC_GEOMETRY_COLUMN (1LL << 50)
505
506/**
507 Handler supports expressions as DEFAULT for a column.
508*/
509#define HA_SUPPORTS_DEFAULT_EXPRESSION (1LL << 51)
510
511/**
512 Handlers with this flag set do not support UPDATE operations.
513*/
514#define HA_UPDATE_NOT_SUPPORTED (1LL << 52)
515
516/**
517 Handlers with this flag set do not support DELETE operations.
518*/
519#define HA_DELETE_NOT_SUPPORTED (1LL << 53)
520
521/**
522 The storage engine does not support using indexes for access. Indexes can only
523 be used for estimating cost.
524*/
525#define HA_NO_INDEX_ACCESS (1LL << 54)
526
527/**
528 Supports multi-valued index
529*/
530#define HA_MULTI_VALUED_KEY_SUPPORT (1LL << 55)
531
532/*
533 Bits in index_flags(index_number) for what you can do with index.
534 If you do not implement indexes, just return zero here.
535*/
536/*
537 Does the index support read next, this is assumed in the server
538 code and never checked so all indexes must support this.
539 Note that the handler can be used even if it doesn't have any index.
540*/
541#define HA_READ_NEXT 1 /* TODO really use this flag */
542/*
543 Can the index be used to scan backwards (supports ::index_prev).
544*/
545#define HA_READ_PREV 2
546/*
547 Can the index deliver its record in index order. Typically true for
548 all ordered indexes and not true for hash indexes. Used to set keymap
549 part_of_sortkey.
550 This keymap is only used to find indexes usable for resolving an ORDER BY
551 in the query. Thus in most cases index_read will work just fine without
552 order in result production. When this flag is set it is however safe to
553 order all output started by index_read since most engines do this. With
554 read_multi_range calls there is a specific flag setting order or not
555 order so in those cases ordering of index output can be avoided.
556*/
557#define HA_READ_ORDER 4
558/*
559 Specify whether index can handle ranges, typically true for all
560 ordered indexes and not true for hash indexes.
561 Used by optimiser to check if ranges (as key >= 5) can be optimised
562 by index.
563*/
564#define HA_READ_RANGE 8
565/*
566 Can't use part key searches. This is typically true for hash indexes
567 and typically not true for ordered indexes.
568*/
569#define HA_ONLY_WHOLE_INDEX 16
570/*
571 Index does not store NULL values, even if the column is nullable.
572 (KEY::flags may still contain HA_NULL_PART_KEY)
573 If the key has a NULL-value, the handler need to do a full table scan
574 instead of using this key. This is typically true for NDB hash indexes.
575*/
576#define HA_TABLE_SCAN_ON_NULL 32
577/*
578 Does the storage engine support index-only scans on this index.
579 Enables use of HA_EXTRA_KEYREAD and HA_EXTRA_NO_KEYREAD
580 Used to set Key_map keys_for_keyread and to check in optimiser for
581 index-only scans. When doing a read under HA_EXTRA_KEYREAD the handler
582 only have to fill in the columns the key covers. If
583 HA_PRIMARY_KEY_IN_READ_INDEX is set then also the PRIMARY KEY columns
584 must be updated in the row.
585*/
586#define HA_KEYREAD_ONLY 64
587/*
588 Index scan will not return records in rowid order. Not guaranteed to be
589 set for unordered (e.g. HASH) indexes.
590*/
591#define HA_KEY_SCAN_NOT_ROR 128
592#define HA_DO_INDEX_COND_PUSHDOWN 256 /* Supports Index Condition Pushdown */
593
594/* operations for disable/enable indexes */
595#define HA_KEY_SWITCH_NONUNIQ 0
596#define HA_KEY_SWITCH_ALL 1
597#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
598#define HA_KEY_SWITCH_ALL_SAVE 3
599
600/*
601 Use this instead of 0 as the initial value for the slot number of
602 handlerton, so that we can distinguish uninitialized slot number
603 from slot 0.
604*/
605#define HA_SLOT_UNDEF ((uint)-1)
606
607/*
608 Parameters for open() (in register form->filestat)
609 HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
610*/
611
612#define HA_OPEN_KEYFILE 1
613#define HA_OPEN_RNDFILE 2
614#define HA_GET_INDEX 4
615#define HA_GET_INFO 8 /* do a handler::info() after open */
616#define HA_READ_ONLY 16 /* File opened as readonly */
617/* Try readonly if can't open with read and write */
618#define HA_TRY_READ_ONLY 32
619#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
620#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
621#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
622#define HA_OPEN_TEMPORARY 512
623
624/* Some key definitions */
625#define HA_KEY_NULL_LENGTH 1
626#define HA_KEY_BLOB_LENGTH 2
627
628#define HA_LEX_CREATE_TMP_TABLE 1
629#define HA_LEX_CREATE_IF_NOT_EXISTS 2
630#define HA_LEX_CREATE_TABLE_LIKE 4
631#define HA_LEX_CREATE_INTERNAL_TMP_TABLE 8
632#define HA_LEX_CREATE_EXTERNAL_TABLE 16
633#define HA_MAX_REC_LENGTH 65535U
634
635/**
636 Options for the START TRANSACTION statement.
637
638 Note that READ ONLY and READ WRITE are logically mutually exclusive.
639 This is enforced by the parser and depended upon by trans_begin().
640
641 We need two flags instead of one in order to differentiate between
642 situation when no READ WRITE/ONLY clause were given and thus transaction
643 is implicitly READ WRITE and the case when READ WRITE clause was used
644 explicitly.
645*/
646
647// WITH CONSISTENT SNAPSHOT option
649// READ ONLY option
651// READ WRITE option
653// HIGH PRIORITY option
655
677 DB_TYPE_PARTITION_DB, // No longer used.
682 DB_TYPE_MEMCACHE [[deprecated]],
685 /** Performance schema engine. */
689 DB_TYPE_DEFAULT = 127 // Must be last
691
692enum row_type : int {
700 /** Unused. Reserved for future versions. */
703
712
721};
722
724
725/* Bits in used_fields */
726#define HA_CREATE_USED_AUTO (1L << 0)
727#define HA_CREATE_USED_RAID (1L << 1) // RAID is no longer available
728#define HA_CREATE_USED_UNION (1L << 2)
729#define HA_CREATE_USED_INSERT_METHOD (1L << 3)
730#define HA_CREATE_USED_MIN_ROWS (1L << 4)
731#define HA_CREATE_USED_MAX_ROWS (1L << 5)
732#define HA_CREATE_USED_AVG_ROW_LENGTH (1L << 6)
733#define HA_CREATE_USED_PACK_KEYS (1L << 7)
734#define HA_CREATE_USED_CHARSET (1L << 8)
735#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
736#define HA_CREATE_USED_DATADIR (1L << 10)
737#define HA_CREATE_USED_INDEXDIR (1L << 11)
738#define HA_CREATE_USED_ENGINE (1L << 12)
739#define HA_CREATE_USED_CHECKSUM (1L << 13)
740#define HA_CREATE_USED_DELAY_KEY_WRITE (1L << 14)
741#define HA_CREATE_USED_ROW_FORMAT (1L << 15)
742#define HA_CREATE_USED_COMMENT (1L << 16)
743#define HA_CREATE_USED_PASSWORD (1L << 17)
744#define HA_CREATE_USED_CONNECTION (1L << 18)
745#define HA_CREATE_USED_KEY_BLOCK_SIZE (1L << 19)
746/** Unused. Reserved for future versions. */
747#define HA_CREATE_USED_TRANSACTIONAL (1L << 20)
748/** Unused. Reserved for future versions. */
749#define HA_CREATE_USED_PAGE_CHECKSUM (1L << 21)
750/** This is set whenever STATS_PERSISTENT=0|1|default has been
751specified in CREATE/ALTER TABLE. See also HA_OPTION_STATS_PERSISTENT in
752include/my_base.h. It is possible to distinguish whether
753STATS_PERSISTENT=default has been specified or no STATS_PERSISTENT= is
754given at all. */
755#define HA_CREATE_USED_STATS_PERSISTENT (1L << 22)
756/**
757 This is set whenever STATS_AUTO_RECALC=0|1|default has been
758 specified in CREATE/ALTER TABLE. See enum_stats_auto_recalc.
759 It is possible to distinguish whether STATS_AUTO_RECALC=default
760 has been specified or no STATS_AUTO_RECALC= is given at all.
761*/
762#define HA_CREATE_USED_STATS_AUTO_RECALC (1L << 23)
763/**
764 This is set whenever STATS_SAMPLE_PAGES=N|default has been
765 specified in CREATE/ALTER TABLE. It is possible to distinguish whether
766 STATS_SAMPLE_PAGES=default has been specified or no STATS_SAMPLE_PAGES= is
767 given at all.
768*/
769#define HA_CREATE_USED_STATS_SAMPLE_PAGES (1L << 24)
770
771/**
772 This is set whenever a 'TABLESPACE=...' phrase is used on CREATE TABLE
773*/
774#define HA_CREATE_USED_TABLESPACE (1L << 25)
775
776/** COMPRESSION="zlib|lz4|none" used during table create. */
777#define HA_CREATE_USED_COMPRESS (1L << 26)
778
779/** ENCRYPTION="Y" used during table create. */
780#define HA_CREATE_USED_ENCRYPT (1L << 27)
781
782/**
783 CREATE|ALTER SCHEMA|DATABASE|TABLE has an explicit COLLATE clause.
784
785 Implies HA_CREATE_USED_DEFAULT_CHARSET.
786*/
787#define HA_CREATE_USED_DEFAULT_COLLATE (1L << 28)
788
789/** SECONDARY_ENGINE used during table create. */
790#define HA_CREATE_USED_SECONDARY_ENGINE (1L << 29)
791
792/**
793 CREATE|ALTER SCHEMA|DATABASE has an explicit ENCRYPTION clause.
794
795 Implies HA_CREATE_USED_DEFAULT_ENCRYPTION.
796*/
797#define HA_CREATE_USED_DEFAULT_ENCRYPTION (1L << 30)
798
799/**
800 This option is used to convey that the create table should not
801 commit the operation and keep the transaction started.
802*/
803constexpr const uint64_t HA_CREATE_USED_START_TRANSACTION{1ULL << 31};
804
805constexpr const uint64_t HA_CREATE_USED_ENGINE_ATTRIBUTE{1ULL << 32};
806constexpr const uint64_t HA_CREATE_USED_SECONDARY_ENGINE_ATTRIBUTE{1ULL << 33};
807
808/**
809 ALTER SCHEMA|DATABASE has an explicit READ_ONLY clause.
810
811 Implies HA_CREATE_USED_READ_ONLY.
812*/
813constexpr const uint64_t HA_CREATE_USED_READ_ONLY{1ULL << 34};
814
815/**
816 These flags convey that the options AUTOEXTEND_SIZE has been
817 specified in the CREATE TABLE statement
818*/
819constexpr const uint64_t HA_CREATE_USED_AUTOEXTEND_SIZE{1ULL << 35};
820
821/** Table options for external tables */
822constexpr const uint64_t HA_CREATE_USED_FILE_FORMAT{1ULL << 36};
823constexpr const uint64_t HA_CREATE_USED_EXTERNAL_FILES{1ULL << 37};
824constexpr const uint64_t HA_CREATE_USED_ALLOW_MISSING_FILES{1ULL << 38};
825constexpr const uint64_t HA_CREATE_USED_VERIFY_KEY_CONSTRAINTS{1ULL << 39};
826constexpr const uint64_t HA_CREATE_USED_STRICT_LOAD{1ULL << 40};
827constexpr const uint64_t HA_CREATE_USED_AUTO_REFRESH{1ULL << 41};
828constexpr const uint64_t HA_CREATE_USED_AUTO_REFRESH_SOURCE{1ULL << 42};
829
830/**
831 These flags indicate that ENGINE/SECONDARY_ENGINE were set explicitly
832 (not by EXTERNAL keyword defaults)
833*/
834constexpr const uint64_t HA_CREATE_USED_EXPLICIT_ENGINE{1ULL << 43};
835constexpr const uint64_t HA_CREATE_USED_EXPLICIT_SECONDARY_ENGINE{1ULL << 44};
836
837/*
838 End of bits used in used_fields
839*/
840
841/*
842 Structure to hold list of database_name.table_name.
843 This is used at both mysqld and storage engine layer.
844*/
846 const char *db;
847 const char *tablename;
848};
849
850#define MAXGTRIDSIZE 64
851#define MAXBQUALSIZE 64
852
853#define COMPATIBLE_DATA_YES 0
854#define COMPATIBLE_DATA_NO 1
855
856/*
857 These structures are used to pass information from a set of SQL commands
858 on add/drop/change tablespace definitions to the proper hton.
859*/
860#define UNDEF_NODEGROUP 65535
861
862// FUTURE: Combine these two enums into one enum class
877
887
888/**
889 Legacy struct for passing tablespace information to SEs.
890
891 FUTURE: Pass all info through dd objects
892 */
894 public:
895 const char *tablespace_name = nullptr;
896 const char *logfile_group_name = nullptr;
900 const char *data_file_name = nullptr;
901 const char *undo_file_name = nullptr;
902 ulonglong extent_size = 1024 * 1024; // Default 1 MByte
903 ulonglong undo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
904 ulonglong redo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
905 ulonglong initial_size = 128 * 1024 * 1024; // Default 128 MByte
906 std::optional<ulonglong> autoextend_size; // No autoextension as default
907 ulonglong max_size = 0; // Max size == initial size => no extension
908 ulonglong file_block_size = 0; // 0=default or must be a valid Page Size
911 const char *ts_comment = nullptr;
912 const char *encryption = nullptr;
913
915 return ts_cmd_type == CREATE_TABLESPACE ||
919 }
920
921 /**
922 Proper constructor even for all-public class simplifies initialization and
923 allows members to be const.
924
925 FUTURE: With constructor all members can be made const, and do not need
926 default initializers.
927
928 @param tablespace name of tabelspace (nullptr for logfile group statements)
929 @param logfile_group name of logfile group or nullptr
930 @param cmd main statement type
931 @param alter_tablespace_cmd subcommand type for ALTER TABLESPACE
932 @param datafile tablespace file for CREATE and ALTER ... ADD ...
933 @param undofile only applies to logfile group statements. nullptr otherwise.
934 @param opts options provided by parser
935 */
936 st_alter_tablespace(const char *tablespace, const char *logfile_group,
937 ts_command_type cmd,
938 enum ts_alter_tablespace_type alter_tablespace_cmd,
939 const char *datafile, const char *undofile,
940 const Tablespace_options &opts);
941};
942
943/*
944 Make sure that the order of schema_tables and enum_schema_tables are the same.
945*/
962
965enum ha_ddl_type : int {
971
972/** Clone start operation mode */
974 /** Start a new clone operation */
976
977 /** Re-start a clone operation after failure */
979
980 /** Add a new task to a running clone operation */
982
983 /** Get version for transfer data format */
985
986 /** Max value for clone mode */
989
990/** Clone operation types. */
991enum Ha_clone_type : size_t {
992 /** Caller must block all write operation to the SE. */
994
995 /** For transactional SE, archive redo to support concurrent dml */
997
998 /** For transactional SE, track page changes to support concurrent dml */
1000
1001 /** For transactional SE, use both page tracking and redo to optimize
1002 clone with concurrent dml. Currently supported by Innodb. */
1004
1005 /** SE supports multiple threads for clone */
1007
1008 /** SE supports restarting clone after network failure */
1010
1011 /** Maximum value of clone type */
1014
1015using Ha_clone_flagset = std::bitset<HA_CLONE_TYPE_MAX>;
1016
1019
1020/** File reference for clone */
1022 /** File reference type */
1023 enum {
1024 /** File handle */
1026
1027 /** File descriptor */
1028 FILE_DESC
1029
1031
1032 /** File reference */
1033 union {
1034 /** File descriptor */
1036
1037 /** File handle for windows */
1039 };
1040};
1041
1042/* Abstract callback interface to stream data back to the caller. */
1044 protected:
1045 /** Constructor to initialize members. */
1047 : m_hton(),
1048 m_loc_idx(),
1050 m_data_desc(),
1051 m_desc_len(),
1052 m_src_name(),
1053 m_dest_name(),
1055 m_flag() {}
1056
1057 public:
1058 /** Callback providing data from current position of a
1059 file descriptor of specific length.
1060 @param[in] from_file source file to read from
1061 @param[in] len data length
1062 @return error code */
1063 virtual int file_cbk(Ha_clone_file from_file, uint len) = 0;
1064
1065 /** Callback providing data in buffer of specific length.
1066 @param[in] from_buffer source buffer to read from
1067 @param[in] len data length
1068 @return error code */
1069 virtual int buffer_cbk(uchar *from_buffer, uint len) = 0;
1070
1071 /** Callback providing a file descriptor to write data starting
1072 from current position.
1073 @param[in] to_file destination file to write data
1074 @return error code */
1075 virtual int apply_file_cbk(Ha_clone_file to_file) = 0;
1076
1077 /** Callback to get data in buffer.
1078 @param[out] to_buffer data buffer
1079 @param[out] len data length
1080 @return error code */
1081 virtual int apply_buffer_cbk(uchar *&to_buffer, uint &len) = 0;
1082
1083 /** virtual destructor. */
1084 virtual ~Ha_clone_cbk() = default;
1085
1086 /** Set current storage engine handlerton.
1087 @param[in] hton SE handlerton */
1088 void set_hton(handlerton *hton) { m_hton = hton; }
1089
1090 /** Get current storage engine handlerton.
1091 @return SE handlerton */
1092 handlerton *get_hton() { return (m_hton); }
1093
1094 /** Set caller's transfer buffer size. SE can adjust the data chunk size
1095 based on this parameter.
1096 @param[in] size buffer size in bytes */
1098
1099 /** Get caller's transfer buffer size.
1100 @return buffer size in bytes */
1102
1103 /** Set current SE index.
1104 @param[in] idx SE index in locator array */
1105 void set_loc_index(uint idx) { m_loc_idx = idx; }
1106
1107 /** Get current SE index.
1108 @return SE index in locator array */
1109 uint get_loc_index() { return (m_loc_idx); }
1110
1111 /** Set data descriptor. SE specific descriptor for the
1112 data transferred by the callbacks.
1113 @param[in] desc serialized data descriptor
1114 @param[in] len length of the descriptor byte stream */
1115 void set_data_desc(const uchar *desc, uint len) {
1116 m_data_desc = desc;
1117 m_desc_len = len;
1118 }
1119
1120 /** Get data descriptor. SE specific descriptor for the
1121 data transferred by the callbacks.
1122 @param[out] lenp length of the descriptor byte stream
1123 @return pointer to the serialized data descriptor */
1124 const uchar *get_data_desc(uint *lenp) {
1125 if (lenp != nullptr) {
1126 *lenp = m_desc_len;
1127 }
1128
1129 return (m_data_desc);
1130 }
1131
1132 /** Get SE source file name. Used for debug printing and error message.
1133 @return null terminated string for source file name */
1134 const char *get_source_name() { return (m_src_name); }
1135
1136 /** Set SE source file name.
1137 @param[in] name null terminated string for source file name */
1138 void set_source_name(const char *name) { m_src_name = name; }
1139
1140 /** Get SE destination file name. Used for debug printing and error message.
1141 @return null terminated string for destination file name */
1142 const char *get_dest_name() { return (m_dest_name); }
1143
1144 /** Set SE destination file name.
1145 @param[in] name null terminated string for destination file name */
1146 void set_dest_name(const char *name) { m_dest_name = name; }
1147
1148 /** Clear all flags set by SE */
1149 void clear_flags() { m_flag = 0; }
1150
1151 /** Mark that ACK is needed for the data transfer before returning
1152 from callback. Set by SE. */
1154
1155 /** Check if ACK is needed for the data transfer
1156 @return true if ACK is needed */
1157 bool is_ack_needed() const { return (m_flag & HA_CLONE_ACK); }
1158
1159 /** Mark that the file descriptor is opened for read/write
1160 with OS buffer cache. For O_DIRECT, the flag is not set. */
1162
1163 /** Check if the file descriptor is opened for read/write with OS
1164 buffer cache. Currently clone avoids using zero copy (sendfile on linux),
1165 if SE is using O_DIRECT. This improves data copy performance.
1166 @return true if O_DIRECT is not used */
1167 bool is_os_buffer_cache() const { return (m_flag & HA_CLONE_FILE_CACHE); }
1168
1169 /** Mark that the file can be transferred with zero copy. */
1171
1172 /** Check if zero copy optimization is suggested. */
1173 bool is_zero_copy() const { return (m_flag & HA_CLONE_ZERO_COPY); }
1174
1175 /** Mark that data needs secure transfer. */
1177
1178 /** Check if data needs secure transfer. */
1179 bool is_secure() const { return (m_flag & HA_CLONE_SECURE); }
1180
1181 /** Set state information and notify state change.
1182 @param[in] estimate estimated bytes for current state. */
1183 void mark_state_change(uint64_t estimate) {
1185 m_state_estimate = estimate;
1186 }
1187
1188 /** Check if SE notified state change. */
1189 bool is_state_change(uint64_t &estimate) {
1190 estimate = m_state_estimate;
1191 return (m_flag & HA_CLONE_STATE_CHANGE);
1192 }
1193
1194 private:
1195 /** Handlerton for the SE */
1197
1198 /** SE index in caller's locator array */
1200
1201 /** Caller's transfer buffer size. */
1203
1204 /** SE's Serialized data descriptor */
1206
1207 /** SE's Serialized descriptor length. */
1209
1210 /** Current source file name */
1211 const char *m_src_name;
1212
1213 /** Current destination file name */
1214 const char *m_dest_name;
1215
1216 /** Estimated bytes to be transferred. */
1218
1219 /** Flag storing data related options */
1221
1222 /** Acknowledgement is needed for the data transfer. */
1223 const int HA_CLONE_ACK = 0x01;
1224
1225 /** Data file is opened for read/write with OS buffer cache. */
1226 const int HA_CLONE_FILE_CACHE = 0x02;
1227
1228 /** Data file can be transferred with zero copy. */
1229 const int HA_CLONE_ZERO_COPY = 0x04;
1230
1231 /** Data needs to be transferred securely over SSL connection. */
1232 const int HA_CLONE_SECURE = 0x08;
1233
1234 /** State change notification by SE. */
1235 const int HA_CLONE_STATE_CHANGE = 0x10;
1236};
1237
1238/**
1239 Column type description for foreign key columns compatibility check.
1240
1241 Contains subset of information from dd::Column class. It is inconvenient
1242 to use dd::Column class directly for such checks because it requires valid
1243 dd::Table object and in some cases we want to produce Ha_fk_column_type
1244 right from column description in Create_field format.
1245*/
1248 /*
1249 Note that both dd::Column::char_length() and length here are really
1250 in bytes.
1251 */
1257};
1258
1259typedef ulonglong my_xid; // this line is the same as in log_event.h
1260/**
1261 Enumeration of possible states for externally coordinated transactions (XA).
1262 */
1264 NOT_FOUND = -1, // Trnasaction not found
1265 PREPARED_IN_SE = 0, // Transaction is prepared in SEs
1266 PREPARED_IN_TC = 1, // Transaction is prepared in SEs and TC
1267 COMMITTED_WITH_ONEPHASE = 2, // Transaction was one-phase committed
1268 COMMITTED = 3, // Transaction was committed
1269 ROLLEDBACK = 4 // Transaction was rolled back
1270};
1271/**
1272 Single occurrence set of XIDs of internally coordinated transactions
1273 found as been committed in the transaction coordinator state.
1274 */
1276 std::unordered_set<my_xid, std::hash<my_xid>, std::equal_to<my_xid>,
1278
1279/**
1280 Class to maintain list of externally coordinated transactions and their
1281 current state at recovery.
1282 */
1284 public:
1285 using pair = std::pair<const XID, enum_ha_recover_xa_state>;
1287 using list = std::map<XID, enum_ha_recover_xa_state, std::less<XID>,
1289 using iterator = std::map<XID, enum_ha_recover_xa_state, std::less<XID>,
1291 using instantiation_tuple = std::tuple<
1292 std::unique_ptr<MEM_ROOT>, std::unique_ptr<Xa_state_list::allocator>,
1293 std::unique_ptr<Xa_state_list::list>, std::unique_ptr<Xa_state_list>>;
1294
1295 /**
1296 Class constructor.
1297
1298 @param populated_by_tc The underlying list of XIDs and transaction
1299 states, after being populated by the transaction
1300 coodinator.
1301 */
1302 Xa_state_list(Xa_state_list::list &populated_by_tc);
1303 virtual ~Xa_state_list() = default;
1304
1305 /**
1306 Searches the underlying map to find an key that corresponds to the
1307 parameter.
1308
1309 @param to_find The XID to find within the underlying map.
1310
1311 @return Ha_recover_states::NOT_FOUND if the transaction wasn't found,
1312 the state of the transaction, otherwise.
1313 */
1314 enum_ha_recover_xa_state find(XID const &to_find);
1315 /**
1316 Adds a transaction and state to the underlying map. If the given XID
1317 already exists in the underlying map, the associated state changes according
1318 to the following rules:
1319
1320 - If the parameter state is `PREPARED_IN_SE` it means that the
1321 transaction didn't reach PREPARED_IN_TC, COMMIT or ROLLBACK for
1322 sure. In that case:
1323 . If other participants state is `COMMITTED`/`ROLLEDBACK`, it would
1324 mean that it's a state inherited from a previous execution with the
1325 same XID and we should set the state to `PREPARED_IN_SE`.
1326 . If other participants state is `PREPARED_IN_TC`/
1327 `COMMITTED_WITH_ONEPHASE` it means that the current participant
1328 didn't reach it but some other did so, keep the state as
1329 `PREPARED_IN_TC`/`COMMITTED_WITH_ONEPHASE`.
1330
1331 - If the parameter state is `PREPARED_IN_TC`, it means that other
1332 participants must have persisted either the PREPARE, the COMMIT or
1333 the ROLLBACK. In that case, keep whatever state is already there and
1334 ensure that is not `PREPARED_IN_SE`.
1335
1336 - If the parameter state is `COMMITTED_WITH_ONEPHASE`, `COMMITTED` or
1337 `ROLLEDBACK`, do nothing, only the active transaction coordinator has
1338 the ability, for now, to set the transaction state to those values.
1339
1340 @param xid The XID to be added (the key).
1341 @param state The state to be added (the value).
1342
1343 @return The current value of the transaction state if the XID has
1344 already been added, Ha_recover_states::NOT_FOUND otherwise.
1345 */
1347 /**
1348 Factory like method to instantiate all the infra-structure needed to
1349 create an `Xa_state_list`. Since such infra-structuer is dependent on
1350 `MEM_ROOT` and `Mem_root_allocator`, the method returns a tuple
1351 containing unique pointers to all 4 objects needed: MEM_ROOT;
1352 Mem_root_allocator; Xa_state_list::list; Xa_state_list.
1353
1354 @return An std::tuple containing unique pointers to all 4 objects
1355 needed: MEM_ROOT; Mem_root_allocator; Xa_state_list::list;
1356 Xa_state_list.
1357 */
1359
1360 private:
1361 /** The underlying map holding the trx and states*/
1363};
1364
1365/* handlerton methods */
1366
1367/**
1368 close_connection is only called if
1369 thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
1370 this storage area - set it to something, so that MySQL would know
1371 this storage engine was accessed in this connection
1372*/
1373typedef int (*close_connection_t)(handlerton *hton, THD *thd);
1374
1375/** Terminate connection/statement notification. */
1376typedef void (*kill_connection_t)(handlerton *hton, THD *thd);
1377
1378/**
1379 Shut down all storage engine background tasks that might access
1380 the data dictionary, before the main shutdown.
1381*/
1382typedef void (*pre_dd_shutdown_t)(handlerton *hton);
1383
1384/**
1385 Some plugin session variables may require some special handling
1386 upon clean up. Reset appropriately these variables before
1387 ending the THD connection
1388*/
1389typedef void (*reset_plugin_vars_t)(THD *thd);
1390
1391/**
1392 sv points to a storage area, that was earlier passed
1393 to the savepoint_set call
1394*/
1395typedef int (*savepoint_rollback_t)(handlerton *hton, THD *thd, void *sv);
1396
1397/**
1398 sv points to an uninitialized storage area of requested size
1399 (see savepoint_offset description)
1400*/
1401typedef int (*savepoint_set_t)(handlerton *hton, THD *thd, void *sv);
1402
1403/**
1404 Check if storage engine allows to release metadata locks which were
1405 acquired after the savepoint if rollback to savepoint is done.
1406 @return true - If it is safe to release MDL locks.
1407 false - If it is not.
1408*/
1410 THD *thd);
1411
1412typedef int (*savepoint_release_t)(handlerton *hton, THD *thd, void *sv);
1413
1414/**
1415 'all' is true if it's a real commit, that makes persistent changes
1416 'all' is false if it's not in fact a commit but an end of the
1417 statement that is part of the transaction.
1418 NOTE 'all' is also false in auto-commit mode where 'end of statement'
1419 and 'real commit' mean the same event.
1420*/
1421typedef int (*commit_t)(handlerton *hton, THD *thd, bool all);
1422
1423typedef int (*rollback_t)(handlerton *hton, THD *thd, bool all);
1424
1425typedef int (*prepare_t)(handlerton *hton, THD *thd, bool all);
1426
1427typedef int (*recover_t)(handlerton *hton, XA_recover_txn *xid_list, uint len,
1429/**
1430 Retrieves information about externally coordinated transactions for which
1431 the two-phase prepare was finished and transactions were prepared in the
1432 server TC.
1433 */
1435 Xa_state_list &xa_list);
1436/**
1437 Instructs the storage engine to mark the externally coordinated
1438 transactions held by the THD parameters as prepared in the server TC.
1439 */
1440using set_prepared_in_tc_t = int (*)(handlerton *hton, THD *thd);
1441
1442/** X/Open XA distributed transaction status codes */
1444 /**
1445 normal execution
1446 */
1448
1449 /**
1450 asynchronous operation already outstanding
1451 */
1453
1454 /**
1455 a resource manager error occurred in the transaction branch
1456 */
1458
1459 /**
1460 the XID is not valid
1461 */
1463
1464 /**
1465 invalid arguments were given
1466 */
1468
1469 /**
1470 routine invoked in an improper context
1471 */
1473
1474 /**
1475 resource manager unavailable
1476 */
1478
1479 /**
1480 the XID already exists
1481 */
1483
1484 /**
1485 resource manager doing work outside transaction
1486 */
1487 XAER_OUTSIDE = -9
1489
1491
1493
1494/**
1495 Instructs the storage engine to mark the externally coordinated
1496 transactions identified by the XID parameters as prepared in the server
1497 TC.
1498 */
1500 XID *xid);
1501
1502/**
1503 Create handler object for the table in the storage engine.
1504
1505 @param hton Handlerton object for the storage engine.
1506 @param table TABLE_SHARE for the table, can be NULL if caller
1507 didn't perform full-blown open of table definition.
1508 @param partitioned Indicates whether table is partitioned.
1509 @param mem_root Memory root to be used for allocating handler
1510 object.
1511*/
1512typedef handler *(*create_t)(handlerton *hton, TABLE_SHARE *table,
1513 bool partitioned, MEM_ROOT *mem_root);
1514
1515typedef void (*drop_database_t)(handlerton *hton, const char *db);
1516
1517typedef bool (*log_ddl_drop_schema_t)(handlerton *hton,
1518 const char *schema_name);
1519
1521 const char *schema_name);
1522
1523typedef int (*panic_t)(handlerton *hton, enum ha_panic_function flag);
1524
1525typedef int (*start_consistent_snapshot_t)(handlerton *hton, THD *thd);
1526
1527/**
1528 Flush the log(s) of storage engine(s).
1529
1530 @param hton Handlerton of storage engine.
1531 @param binlog_group_flush true if we got invoked by binlog group
1532 commit during flush stage, false in other cases.
1533 @retval false Succeed
1534 @retval true Error
1535*/
1536typedef bool (*flush_logs_t)(handlerton *hton, bool binlog_group_flush);
1537
1538typedef bool (*show_status_t)(handlerton *hton, THD *thd, stat_print_fn *print,
1539 enum ha_stat_type stat);
1540
1541/**
1542 The flag values are defined in sql_partition.h.
1543 If this function is set, then it implies that the handler supports
1544 partitioned tables.
1545 If this function exists, then handler::get_partition_handler must also be
1546 implemented.
1547*/
1548typedef uint (*partition_flags_t)();
1549
1550/**
1551 SE specific validation of the tablespace name.
1552
1553 This function will ask the relevant SE whether the submitted tablespace
1554 name is valid.
1555
1556 @param ts_cmd Purpose of usage - is this tablespace DDL?
1557 @param tablespace_name Name of the tablespace.
1558
1559 @return Tablespace name validity.
1560 @retval Whether the tablespace name is valid.
1561*/
1563 const char *tablespace_name);
1564
1565/**
1566 Create/drop or alter tablespace in the storage engine.
1567
1568 @param hton Hadlerton of the SE.
1569 @param thd Thread context.
1570 @param ts_info Description of tablespace and specific
1571 operation on it.
1572 @param old_ts_def dd::Tablespace object describing old version
1573 of tablespace.
1574 @param [in,out] new_ts_def dd::Tablespace object describing new version
1575 of tablespace. Engines which support atomic DDL
1576 can adjust this object. The updated information
1577 will be saved to the data-dictionary.
1578
1579 @return Operation status.
1580 @retval == 0 Success.
1581 @retval != 0 Error (handler error code returned).
1582*/
1583typedef int (*alter_tablespace_t)(handlerton *hton, THD *thd,
1584 st_alter_tablespace *ts_info,
1585 const dd::Tablespace *old_ts_def,
1586 dd::Tablespace *new_ts_def);
1587
1588/**
1589 SE interface for getting tablespace extension.
1590 @return Extension of tablespace datafile name.
1591*/
1592typedef const char *(*get_tablespace_filename_ext_t)();
1593
1594/**
1595 Get the tablespace data from SE and insert it into Data dictionary
1596
1597 @deprecated Was used to upgrade from 5.7.
1598
1599 @param thd Thread context
1600
1601 @return Operation status.
1602 @retval == 0 Success.
1603 @retval != 0 Error (handler error code returned)
1604*/
1605typedef int (*upgrade_tablespace_t)(THD *thd);
1606
1607/**
1608 Get the tablespace data from SE and insert it into Data dictionary
1609
1610 @deprecated Was used to upgrade from 5.7.
1611
1612 @param[in] tablespace tablespace object
1613
1614 @return Operation status.
1615 @retval == 0 Success.
1616 @retval != 0 Error (handler error code returned)
1617*/
1618typedef bool (*upgrade_space_version_t)(dd::Tablespace *tablespace);
1619
1620/**
1621 Finish upgrade process inside storage engines.
1622 This includes resetting flags to indicate upgrade process
1623 and cleanup after upgrade.
1624
1625 @deprecated Was used to upgrade from 5.7.
1626
1627 @param thd Thread context
1628 @param failed_upgrade True if the upgrade failed.
1629
1630 @return Operation status.
1631 @retval == 0 Success.
1632 @retval != 0 Error (handler error code returned)
1633*/
1634typedef int (*finish_upgrade_t)(THD *thd, bool failed_upgrade);
1635
1636/**
1637 Upgrade logs after the checkpoint from where upgrade
1638 process can only roll forward.
1639
1640 @deprecated Was used to upgrade from 5.7.
1641
1642 @param thd Thread context
1643
1644 @return Operation status.
1645 @retval == 0 Success.
1646 @retval != 0 Error (handler error code returned)
1647*/
1648typedef int (*upgrade_logs_t)(THD *thd);
1649
1657};
1658
1659/**
1660 Get the tablespace type from the SE.
1661
1662 @param[in] space tablespace object
1663 @param[out] space_type type of space
1664
1665 @return Operation status.
1666 @retval false on success and true for failure.
1667*/
1668typedef bool (*get_tablespace_type_t)(const dd::Tablespace &space,
1669 Tablespace_type *space_type);
1670
1671/**
1672 Get the tablespace type given the name, from the SE.
1673
1674 @param[in] tablespace_name tablespace name
1675 @param[out] space_type type of space
1676
1677 @return Operation status.
1678 @retval false on success and true for failure.
1679*/
1680typedef bool (*get_tablespace_type_by_name_t)(const char *tablespace_name,
1681 Tablespace_type *space_type);
1682
1683typedef int (*fill_is_table_t)(handlerton *hton, THD *thd, Table_ref *tables,
1684 class Item *cond, enum enum_schema_tables);
1685
1686typedef int (*binlog_func_t)(handlerton *hton, THD *thd, enum_binlog_func fn,
1687 void *arg);
1688
1689typedef void (*binlog_log_query_t)(handlerton *hton, THD *thd,
1690 enum_binlog_command binlog_command,
1691 const char *query, uint query_length,
1692 const char *db, const char *table_name);
1693
1694typedef void (*acl_notify_t)(THD *thd,
1695 const class Acl_change_notification *notice);
1696
1697typedef int (*discover_t)(handlerton *hton, THD *thd, const char *db,
1698 const char *name, uchar **frmblob, size_t *frmlen);
1699
1700typedef int (*find_files_t)(handlerton *hton, THD *thd, const char *db,
1701 const char *path, const char *wild, bool dir,
1702 List<LEX_STRING> *files);
1703
1704typedef int (*table_exists_in_engine_t)(handlerton *hton, THD *thd,
1705 const char *db, const char *name);
1706
1707/**
1708 Let storage engine inspect the query Accesspath and pick whatever
1709 it like for being pushed down to the engine. (Join, conditions, ..)
1710
1711 The handler implementation should itself keep track of what it 'pushed',
1712 such that later calls to the handlers access methods should
1713 activate the pushed parts of the execution plan on the storage
1714 engines.
1715
1716 @param thd Thread context
1717 @param query The AccessPath for the entire query.
1718 @param join The JOIN to be pushed
1719
1720 @returns
1721 0 on success
1722 error otherwise
1723*/
1724using push_to_engine_t = int (*)(THD *thd, AccessPath *query, JOIN *join);
1725
1726/**
1727 Check if the given db.tablename is a system table for this SE.
1728
1729 @param db Database name to check.
1730 @param table_name table name to check.
1731 @param is_sql_layer_system_table if the supplied db.table_name is a SQL
1732 layer system table.
1733
1734 @see example_is_supported_system_table in ha_example.cc
1735
1736 is_sql_layer_system_table is supplied to make more efficient
1737 checks possible for SEs that support all SQL layer tables.
1738
1739 This interface is optional, so every SE need not implement it.
1740*/
1741typedef bool (*is_supported_system_table_t)(const char *db,
1742 const char *table_name,
1743 bool is_sql_layer_system_table);
1744
1745/**
1746 Create SDI in a tablespace. This API should be used when upgrading
1747 a tablespace with no SDI or after invoking sdi_drop().
1748 @param[in] tablespace tablespace object
1749 @retval false success
1750 @retval true failure
1751*/
1752typedef bool (*sdi_create_t)(dd::Tablespace *tablespace);
1753
1754/**
1755 Drop SDI in a tablespace. This API should be used only when
1756 SDI is corrupted.
1757 @param[in] tablespace tablespace object
1758 @retval false success
1759 @retval true failure
1760*/
1761typedef bool (*sdi_drop_t)(dd::Tablespace *tablespace);
1762
1763/**
1764 Get the SDI keys in a tablespace into vector.
1765 @param[in] tablespace tablespace object
1766 @param[in,out] vector vector of SDI Keys
1767 @retval false success
1768 @retval true failure
1769*/
1770typedef bool (*sdi_get_keys_t)(const dd::Tablespace &tablespace,
1772
1773/**
1774 Retrieve SDI for a given SDI key.
1775
1776 Since the caller of this api will not know the SDI length, SDI retrieval
1777 should be done in the following way.
1778
1779 i. Allocate initial memory of some size (Lets say 64KB)
1780 ii. Pass the allocated memory to the below api.
1781 iii. If passed buffer is sufficient, sdi_get_by_id() copies the sdi
1782 to the buffer passed and returns success, else sdi_len is modified
1783 with the actual length of the SDI (and returns false on failure).
1784 For genuine errors, sdi_len is returned as UINT64_MAX
1785 iv. If sdi_len != UINT64_MAX, retry the call after allocating the memory
1786 of sdi_len
1787 v. Free the memory after using SDI (responsibility of caller)
1788
1789 @param[in] tablespace tablespace object
1790 @param[in] sdi_key SDI key to uniquely identify SDI obj
1791 @param[in,out] sdi SDI retrieved from tablespace
1792 A non-null pointer must be passed in
1793 @param[in,out] sdi_len in: length of the memory allocated
1794 out: actual length of SDI
1795 @retval false success
1796 @retval true failure
1797*/
1798typedef bool (*sdi_get_t)(const dd::Tablespace &tablespace,
1799 const sdi_key_t *sdi_key, void *sdi, uint64 *sdi_len);
1800
1801/**
1802 Insert/Update SDI for a given SDI key.
1803 @param[in] hton handlerton object
1804 @param[in] tablespace tablespace object
1805 @param[in] table table object
1806 @param[in] sdi_key SDI key to uniquely identify SDI obj
1807 @param[in] sdi SDI to write into the tablespace
1808 @param[in] sdi_len length of SDI BLOB returned
1809 @retval false success
1810 @retval true failure, my_error() should be called
1811 by SE
1812*/
1813typedef bool (*sdi_set_t)(handlerton *hton, const dd::Tablespace &tablespace,
1814 const dd::Table *table, const sdi_key_t *sdi_key,
1815 const void *sdi, uint64 sdi_len);
1816
1817/**
1818 Delete SDI for a given SDI key.
1819 @param[in] tablespace tablespace object
1820 @param[in] table table object
1821 @param[in] sdi_key SDI key to uniquely identify SDI obj
1822 @retval false success
1823 @retval true failure, my_error() should be called
1824 by SE
1825*/
1826typedef bool (*sdi_delete_t)(const dd::Tablespace &tablespace,
1827 const dd::Table *table, const sdi_key_t *sdi_key);
1828
1829/**
1830 Check if the DDSE is started in a way that leaves thd DD being read only.
1831
1832 @retval true The data dictionary can only be read.
1833 @retval false The data dictionary can be read and written.
1834 */
1835typedef bool (*is_dict_readonly_t)();
1836
1837/**
1838 Drop all temporary tables which have been left from previous server
1839 run belonging to this SE. Used on server start-up.
1840
1841 @param[in] hton Handlerton for storage engine.
1842 @param[in] thd Thread context.
1843 @param[in,out] files List of files in directories for temporary files
1844 which match tmp_file_prefix and thus can belong to
1845 temporary tables (but not necessarily in this SE).
1846 It is recommended to remove file from the list if
1847 SE recognizes it as belonging to temporary table
1848 in this SE and deletes it.
1849*/
1850typedef bool (*rm_tmp_tables_t)(handlerton *hton, THD *thd,
1851 List<LEX_STRING> *files);
1852
1853/**
1854 Retrieve cost constants to be used for this storage engine.
1855
1856 A storage engine that wants to provide its own cost constants to
1857 be used in the optimizer cost model, should implement this function.
1858 The server will call this function to get a cost constant object
1859 that will be used for tables stored in this storage engine instead
1860 of using the default cost constants.
1861
1862 Life cycle for the cost constant object: The storage engine must
1863 allocate the cost constant object on the heap. After the function
1864 returns, the server takes over the ownership of this object.
1865 The server will eventually delete the object by calling delete.
1866
1867 @note In the initial version the storage_category parameter will
1868 not be used. The only valid value this will have is DEFAULT_STORAGE_CLASS
1869 (see declaration in opt_costconstants.h).
1870
1871 @param storage_category the storage type that the cost constants will
1872 be used for
1873
1874 @return a pointer to the cost constant object, if NULL is returned
1875 the default cost constants will be used
1876*/
1877typedef SE_cost_constants *(*get_cost_constants_t)(uint storage_category);
1878
1879/**
1880 @param[in,out] thd pointer to THD
1881 @param[in] new_trx_arg pointer to replacement transaction
1882 @param[out] ptr_trx_arg double pointer to being replaced transaction
1883
1884 Associated with THD engine's native transaction is replaced
1885 with @c new_trx_arg. The old value is returned through a buffer if non-null
1886 pointer is provided with @c ptr_trx_arg.
1887 The method is adapted by XA start and XA prepare handlers to
1888 handle XA transaction that is logged as two parts by slave applier.
1889
1890 This interface concerns engines that are aware of XA transaction.
1891*/
1892typedef void (*replace_native_transaction_in_thd_t)(THD *thd, void *new_trx_arg,
1893 void **ptr_trx_arg);
1894
1895/** Mode for initializing the data dictionary. */
1897 DICT_INIT_CREATE_FILES, ///< Create all required SE files
1898 DICT_INIT_CHECK_FILES ///< Verify existence of expected files
1900
1901/**
1902 Initialize the SE for being used to store the DD tables. Create
1903 the required files according to the dict_init_mode. Create strings
1904 representing the required DDSE tables, i.e., tables that the DDSE
1905 expects to exist in the DD, and add them to the appropriate out
1906 parameter.
1907
1908 @note There are two variants of this function type, one is to be
1909 used by the DDSE, and has a different type of output parameters
1910 because the SQL layer needs more information about the DDSE tables
1911 in order to support upgrade.
1912
1913 @param dict_init_mode How to initialize files
1914 @param version Target DD version if a new
1915 server is being installed.
1916 0 if restarting an existing
1917 server.
1918 @param [out] DDSE_tables List of SQL DDL statements
1919 for creating DD tables that
1920 are needed by the DDSE.
1921 @param [out] DDSE_tablespaces List of meta data for predefined
1922 tablespaces created by the DDSE.
1923
1924 @retval true An error occurred.
1925 @retval false Success - no errors.
1926 */
1927
1928typedef bool (*dict_init_t)(dict_init_mode_t dict_init_mode, uint version,
1929 List<const Plugin_table> *DDSE_tables,
1930 List<const Plugin_tablespace> *DDSE_tablespaces);
1931
1932typedef bool (*ddse_dict_init_t)(
1933 dict_init_mode_t dict_init_mode, uint version,
1934 List<const dd::Object_table> *DDSE_tables,
1935 List<const Plugin_tablespace> *DDSE_tablespaces);
1936
1937/**
1938 Initialize the set of hard coded DD table ids.
1939*/
1940typedef void (*dict_register_dd_table_id_t)(dd::Object_id hard_coded_tables);
1941
1942/**
1943 Invalidate an entry in the local dictionary cache.
1944
1945 Needed during bootstrap to make sure the contents in the DDSE
1946 dictionary cache is in sync with the global DD.
1947
1948 @param schema_name Schema name.
1949 @param table_name Table name.
1950 */
1951
1952typedef void (*dict_cache_reset_t)(const char *schema_name,
1953 const char *table_name);
1954
1955/**
1956 Invalidate all table and tablespace entries in the local dictionary cache.
1957
1958 Needed for recovery during server restart.
1959 */
1960
1962
1963/** Mode for data dictionary recovery. */
1965 DICT_RECOVERY_INITIALIZE_SERVER, ///< First start of a new server
1966 DICT_RECOVERY_INITIALIZE_TABLESPACES, ///< First start, create tablespaces
1967 DICT_RECOVERY_RESTART_SERVER ///< Restart of an existing server
1969
1970/**
1971 Do recovery in the DDSE as part of initializing the data dictionary.
1972 The dict_recovery_mode indicates what kind of recovery should be
1973 done.
1974
1975 @param dict_recovery_mode How to do recovery
1976 @param version Target DD version if a new
1977 server is being installed.
1978 Actual DD version if restarting
1979 an existing server.
1980
1981 @retval true An error occurred.
1982 @retval false Success - no errors.
1983 */
1984
1985typedef bool (*dict_recover_t)(dict_recovery_mode_t dict_recovery_mode,
1986 uint version);
1987
1988/**
1989 Get the server version id stored in the header of the
1990 dictionary tablespace.
1991
1992 @param [out] version Version number from the DD
1993 tablespace header.
1994
1995 @retval Operation outcome, false if no error, otherwise true.
1996*/
1997typedef bool (*dict_get_server_version_t)(uint *version);
1998
1999/**
2000 Store the current server version number into the
2001 header of the dictionary tablespace.
2002
2003 @retval Operation outcome, false if no error, otherwise true.
2004*/
2006
2007/**
2008 Notify/get permission from storage engine before acquisition or after
2009 release of exclusive metadata lock on object represented by key.
2010
2011 @param thd Thread context.
2012 @param mdl_key MDL key identifying object on which exclusive
2013 lock is to be acquired/was released.
2014 @param notification_type Indicates whether this is pre-acquire or
2015 post-release notification.
2016 @param victimized 'true' if locking failed as we were selected
2017 as a victim in order to avoid possible deadlocks.
2018
2019 @note Notification is done only for objects from TABLESPACE, SCHEMA,
2020 TABLE, FUNCTION, PROCEDURE, TRIGGER and EVENT namespaces.
2021
2022 @note Problems during notification are to be reported as warnings, MDL
2023 subsystem will report generic error if pre-acquire notification
2024 fails/SE refuses lock acquisition.
2025 @note Return value is ignored/error is not reported in case of
2026 post-release notification.
2027
2028 @note In some cases post-release notification might happen even if
2029 there were no prior pre-acquire notification. For example,
2030 when SE was loaded after exclusive lock acquisition, or when
2031 we need notify SEs which permitted lock acquisition that it
2032 didn't happen because one of SEs didn't allow it (in such case
2033 we will do post-release notification for all SEs for simplicity).
2034
2035 @return False - if notification was successful/lock can be acquired,
2036 True - if it has failed/lock should not be acquired.
2037*/
2038typedef bool (*notify_exclusive_mdl_t)(THD *thd, const MDL_key *mdl_key,
2039 ha_notification_type notification_type,
2040 bool *victimized);
2041
2042/**
2043 Notify/get permission from storage engine before or after execution of
2044 ALTER TABLE operation on the table identified by the MDL key.
2045
2046 @param thd Thread context.
2047 @param mdl_key MDL key identifying table which is going to be
2048 or was ALTERed.
2049 @param notification_type Indicates whether this is pre-ALTER TABLE or
2050 post-ALTER TABLE notification.
2051
2052 @note This hook is necessary because for ALTER TABLE upgrade to X
2053 metadata lock happens fairly late during the execution process,
2054 so it can be expensive to abort ALTER TABLE operation at this
2055 stage by returning failure from notify_exclusive_mdl() hook.
2056
2057 @note This hook follows the same error reporting convention as
2058 @see notify_exclusive_mdl().
2059
2060 @note Similarly to notify_exclusive_mdl() in some cases post-ALTER
2061 notification might happen even if there were no prior pre-ALTER
2062 notification.
2063
2064 @note Post-ALTER notification can happen before post-release notification
2065 for exclusive metadata lock acquired by this ALTER TABLE.
2066
2067 @return False - if notification was successful/ALTER TABLE can proceed.
2068 True - if it has failed/ALTER TABLE should be aborted.
2069*/
2070typedef bool (*notify_alter_table_t)(THD *thd, const MDL_key *mdl_key,
2071 ha_notification_type notification_type);
2072
2073/**
2074 Notify/get permission from storage engine before or after execution of
2075 RENAME TABLE operation on the table identified by the MDL key.
2076
2077 @param thd Thread context.
2078 @param mdl_key MDL key identifying table which is going to be
2079 or was RENAMEd.
2080 @param notification_type Indicates whether this is pre-RENAME TABLE or
2081 post-RENAME TABLE notification.
2082 @param old_db_name old db name
2083 @param old_table_name old table name
2084 @param new_db_name new db name
2085 @param new_table_name new table name
2086*/
2087typedef bool (*notify_rename_table_t)(THD *thd, const MDL_key *mdl_key,
2088 ha_notification_type notification_type,
2089 const char *old_db_name,
2090 const char *old_table_name,
2091 const char *new_db_name,
2092 const char *new_table_name);
2093
2094/**
2095 Notify/get permission from storage engine before or after execution of
2096 TRUNCATE TABLE operation on the table identified by the MDL key.
2097
2098 @param thd Thread context.
2099 @param mdl_key MDL key identifying table which is going to be
2100 or was TRUNCATEd.
2101 @param notification_type Indicates whether this is pre-TRUNCATE TABLE or
2102 post-TRUNCATE TABLE notification.
2103*/
2104typedef bool (*notify_truncate_table_t)(THD *thd, const MDL_key *mdl_key,
2105 ha_notification_type notification_type);
2106
2107/**
2108 @brief
2109 Initiate master key rotation
2110
2111 @returns false on success,
2112 true on failure
2113*/
2115
2116/**
2117 @brief
2118 Enable or Disable SE write ahead logging.
2119
2120 @param[in] thd server thread handle
2121 @param[in] enable enable/disable redo logging
2122
2123 @return true iff failed.
2124*/
2125typedef bool (*redo_log_set_state_t)(THD *thd, bool enable);
2126
2127/**
2128 @brief
2129 Retrieve ha_statistics from SE.
2130
2131 @param db_name Name of schema
2132 @param table_name Name of table
2133 @param se_private_id SE private id of the table.
2134 @param ts_se_private_data Tablespace SE private data.
2135 @param tbl_se_private_data Table SE private data.
2136 @param flags Type of statistics to retrieve.
2137 @param[out] stats Contains statistics read from SE.
2138
2139 @note Handlers that implement this callback/API should adhere
2140 to servers expectation that, the implementation would invoke
2141 my_error() before returning 'true'/failure from this function.
2142
2143 @returns false on success,
2144 true on failure
2145*/
2147 const char *db_name, const char *table_name, dd::Object_id se_private_id,
2148 const dd::Properties &ts_se_private_data,
2149 const dd::Properties &tbl_se_private_data, uint flags,
2151
2152/**
2153 Retrieve column_statistics from SE.
2154 @param thd Current THD
2155 @param db_name Name of schema
2156 @param table_name Name of table
2157 @param column_name Name of column
2158 @param rows_in_table Nrows in table
2159
2160 @returns The statistics if available, empty value otherwise.
2161*/
2162typedef std::optional<ha_column_statistics> (*get_column_statistics_t)(
2163 THD *thd, const char *db_name, const char *table_name,
2164 const char *column_name, double rows_in_table);
2165
2166/**
2167 @brief
2168 Retrieve index column cardinality from SE.
2169
2170 @param db_name Name of schema
2171 @param table_name Name of table
2172 @param index_name Name of index
2173 @param index_ordinal_position Position of index.
2174 @param column_ordinal_position Position of column in index.
2175 @param se_private_id SE private id of the table.
2176 @param[out] cardinality cardinality being returned by SE.
2177
2178 @note Handlers that implement this callback/API should adhere
2179 to servers expectation that, the implementation would invoke
2180 my_error() before returning 'true'/failure from this function.
2181
2182 @returns false on success,
2183 true on failure
2184*/
2186 const char *db_name, const char *table_name, const char *index_name,
2187 uint index_ordinal_position, uint column_ordinal_position,
2188 dd::Object_id se_private_id, ulonglong *cardinality);
2189
2190/**
2191 Retrieve ha_tablespace_statistics from SE.
2192
2193 @param tablespace_name Tablespace_name
2194 @param file_name Tablespace file name.
2195 @param ts_se_private_data Tablespace SE private data.
2196 @param[out] stats Contains tablespace
2197 statistics read from SE.
2198
2199 @note Handlers that implement this callback/API should adhere
2200 to servers expectation that, the implementation would invoke
2201 my_error() before returning 'true'/failure from this function.
2202
2203 @returns false on success, true on failure
2204*/
2206 const char *tablespace_name, const char *file_name,
2207 const dd::Properties &ts_se_private_data, ha_tablespace_statistics *stats);
2208
2209/* Database physical clone interfaces */
2210
2211/** Get capability flags for clone operation
2212@param[out] flags capability flag */
2214
2215/** Begin copy from source database
2216@param[in] hton handlerton for SE
2217@param[in] thd server thread handle
2218@param[in,out] loc locator
2219@param[in,out] loc_len locator length
2220@param[out] task_id task identifier
2221@param[in] type clone type
2222@param[in] mode mode for starting clone
2223@return error code */
2224using Clone_begin_t = int (*)(handlerton *hton, THD *thd, const uchar *&loc,
2225 uint &loc_len, uint &task_id, Ha_clone_type type,
2227
2228/** Copy data from source database in chunks via callback
2229@param[in] hton handlerton for SE
2230@param[in] thd server thread handle
2231@param[in] loc locator
2232@param[in] loc_len locator length in bytes
2233@param[in] task_id task identifier
2234@param[in] cbk callback interface for sending data
2235@return error code */
2236using Clone_copy_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
2237 uint loc_len, uint task_id, Ha_clone_cbk *cbk);
2238
2239/** Acknowledge data transfer to source database
2240@param[in] hton handlerton for SE
2241@param[in] thd server thread handle
2242@param[in] loc locator
2243@param[in] loc_len locator length in bytes
2244@param[in] task_id task identifier
2245@param[in] in_err inform any error occurred
2246@param[in] cbk callback interface
2247@return error code */
2248using Clone_ack_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
2249 uint loc_len, uint task_id, int in_err,
2250 Ha_clone_cbk *cbk);
2251
2252/** End copy from source database
2253@param[in] hton handlerton for SE
2254@param[in] thd server thread handle
2255@param[in] loc locator
2256@param[in] loc_len locator length in bytes
2257@param[in] task_id task identifier
2258@param[in] in_err error code when ending after error
2259@return error code */
2260using Clone_end_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
2261 uint loc_len, uint task_id, int in_err);
2262
2263/** Begin apply to destination database
2264@param[in] hton handlerton for SE
2265@param[in] thd server thread handle
2266@param[in,out] loc locator
2267@param[in,out] loc_len locator length
2268@param[in] task_id task identifier
2269@param[in] mode mode for starting clone
2270@param[in] data_dir target data directory
2271@return error code */
2272using Clone_apply_begin_t = int (*)(handlerton *hton, THD *thd,
2273 const uchar *&loc, uint &loc_len,
2274 uint &task_id, Ha_clone_mode mode,
2275 const char *data_dir);
2276
2277/** Apply data to destination database in chunks via callback
2278@param[in] hton handlerton for SE
2279@param[in] thd server thread handle
2280@param[in] loc locator
2281@param[in] loc_len locator length in bytes
2282@param[in] task_id task identifier
2283@param[in] in_err inform any error occurred
2284@param[in] cbk callback interface for receiving data
2285@return error code */
2286using Clone_apply_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
2287 uint loc_len, uint task_id, int in_err,
2288 Ha_clone_cbk *cbk);
2289
2290/** End apply to destination database
2291@param[in] hton handlerton for SE
2292@param[in] thd server thread handle
2293@param[in] loc locator
2294@param[in] loc_len locator length in bytes
2295@param[in] task_id task identifier
2296@param[in] in_err error code when ending after error
2297@return error code */
2298using Clone_apply_end_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
2299 uint loc_len, uint task_id, int in_err);
2300
2302 /* Get clone capabilities of an SE */
2304
2305 /* Interfaces to copy data. */
2310
2311 /* Interfaces to apply data. */
2315};
2316
2317/**
2318 Perform post-commit/rollback cleanup after DDL statement (e.g. in
2319 case of DROP TABLES really remove table files from disk).
2320
2321 @note This hook will be invoked after DDL commit or rollback only
2322 for storage engines supporting atomic DDL.
2323
2324 @note Problems during execution of this method should be reported to
2325 error log and as warnings/notes to user. Since this method is
2326 called after successful commit of the statement we can't fail
2327 statement with error.
2328*/
2329typedef void (*post_ddl_t)(THD *thd);
2330
2331/**
2332 Perform SE-specific cleanup after recovery of transactions.
2333
2334 @note Particularly SEs supporting atomic DDL can use this call
2335 to perform post-DDL actions for DDL statements which were
2336 committed or rolled back during recovery stage.
2337*/
2338typedef void (*post_recover_t)(void);
2339
2340/**
2341 Lock a handlerton (resource) log to collect log information.
2342*/
2343
2344typedef bool (*lock_hton_log_t)(handlerton *hton);
2345
2346/**
2347 Unlock a handlerton (resource) log after collecting log information.
2348*/
2349
2350typedef bool (*unlock_hton_log_t)(handlerton *hton);
2351
2352/**
2353 Collect a handlerton (resource) log information.
2354*/
2355
2356typedef bool (*collect_hton_log_info_t)(handlerton *hton, Json_dom *json);
2357
2358/**
2359 Check SE considers types of child and parent columns in foreign key
2360 to be compatible.
2361
2362 @param child_column_type Child column type description.
2363 @param parent_column_type Parent column type description.
2364 @param check_charsets Indicates whether we need to check
2365 that charsets of string columns
2366 match. Which is true in most cases.
2367
2368 @returns True if types are compatible, False if not.
2369*/
2370
2372 const Ha_fk_column_type *child_column_type,
2373 const Ha_fk_column_type *parent_column_type, bool check_charsets);
2374
2375typedef bool (*is_reserved_db_name_t)(handlerton *hton, const char *name);
2376
2377/**
2378 Prepare the secondary engine for executing a statement. This function is
2379 called right after the secondary engine TABLE objects have been opened by
2380 open_secondary_engine_tables(), before the statement is optimized and
2381 executed. Secondary engines will typically create a context object in this
2382 function, which they can use to store state that is needed during the
2383 optimization and execution phases.
2384
2385 @param thd thread context
2386 @param lex the statement to execute
2387 @return true on error, false on success
2388*/
2389using prepare_secondary_engine_t = bool (*)(THD *thd, LEX *lex);
2390
2391/**
2392 Optimize a statement for execution on a secondary storage engine. This
2393 function is called when the optimization of a statement has completed, just
2394 before the statement is executed. Secondary engines can use this function to
2395 apply engine-specific optimizations to the execution plan. They can also
2396 reject executing the query by raising an error, in which case the query will
2397 be reprepared and executed by the primary storage engine.
2398
2399 @param thd thread context
2400 @param lex the statement being optimized
2401 @return true on error, false on success
2402*/
2403using optimize_secondary_engine_t = bool (*)(THD *thd, LEX *lex);
2404
2405/**
2406 Compares the cost of two join plans in the secondary storage engine. The cost
2407 of the current candidate is compared with the cost of the best plan seen so
2408 far.
2409
2410 @param thd thread context
2411 @param join the candidate plan to evaluate
2412 @param optimizer_cost the cost estimate calculated by the optimizer
2413 @param[out] use_best_so_far true if the optimizer should stop searching for
2414 a better plan and use the best plan it has seen so far
2415 @param[out] cheaper true if the candidate is the best plan seen so far for
2416 this JOIN (must be true if it is the first plan seen),
2417 false otherwise
2418 @param[out] secondary_engine_cost the cost estimated by the secondary engine
2419
2420 @return false on success, or true if an error has been raised
2421*/
2422using compare_secondary_engine_cost_t = bool (*)(THD *thd, const JOIN &join,
2423 double optimizer_cost,
2424 bool *use_best_so_far,
2425 bool *cheaper,
2426 double *secondary_engine_cost);
2427
2428/**
2429 Evaluates/Views the cost of executing the given access path in the secondary
2430 storage engine, and potentially modifies the cost estimates that are in the
2431 access path when optimization is being done for secondary engine. For primary
2432 engine, the cost should be only viewed. This function is only called from the
2433 hypergraph join optimizer.
2434
2435 The function is called on every access path that the join optimizer might
2436 compare to an alternative access path. This includes both paths that represent
2437 complete execution plans and paths that represent partial plans. It is not
2438 guaranteed to be called on every child path. For example, if GROUP BY is done
2439 by sorting first and then aggregating the sorted results, the function will
2440 only be called on the aggregation path, and not on the sort path, because only
2441 the aggregation path will be compared to other paths.
2442
2443 The secondary engine is allowed to modify the estimates in the access path to
2444 better match the costs of the access path in the secondary engine. It can
2445 change any of the following AccessPath members:
2446
2447 - init_once_cost
2448 - init_cost
2449 - cost
2450 - cost_before_filter
2451 - num_output_rows
2452 - num_output_rows_before_filter
2453 - secondary_engine_data
2454
2455 Any other members should be left unchanged. The AccessPath must be in an
2456 internally consistent state when the function returns, and satisfy invariants
2457 expected by the hypergraph join optimizer, such as:
2458
2459 - init_cost <= cost_before_filter <= cost
2460 - num_output_rows <= num_output_rows_before_filter
2461
2462 The secondary engine can also reject an access path altogether, by returning
2463 true, in which case the join optimizer will not use that path in the final
2464 plan. Since the secondary engine can reject any partial or complete plan, it
2465 is possible that the join optimizer does not find any valid plan that is
2466 accepted. In this case, the join optimizer will raise an error.
2467
2468 If the secondary encounters an error when evaluating the cost of the path, it
2469 can signal an error by calling my_error() and return true, in which case the
2470 join optimizer will not suggest any plan for the query.
2471
2472 @param thd The thread context.
2473 @param hypergraph The hypergraph that represents the search space.
2474 @param[in,out] access_path The AccessPath to evaluate.
2475
2476 @retval false on success.
2477 @retval true if the plan is to be rejected, or if an error was raised.
2478*/
2480 THD *thd, const JoinHypergraph &hypergraph, AccessPath *access_path);
2481
2482/**
2483 Type for signature generation and for retrieving nrows estimate
2484 from secondary engine for current AccessPath.
2485*/
2487 /** The thread context */
2489 /** The AccessPath to retrieve Nrows for. */
2491 /** Hypergraph for current query block. */
2493 /** Predicates actually applied for AccessPath::REF and other parameterized
2494 * types. */
2496 /** if ap->nrows should be acually updated. */
2497 bool to_update_rows{true};
2498 /** if ap->signature generation should be forced. Default behavior is to
2499 * generate if ap->signature != 0. */
2500 bool to_force_resign{false};
2501 /** if nonnull, an additional signature should be combined with current AP. */
2502 size_t *extra_sig{nullptr};
2503
2505 const JoinHypergraph *graph)
2507
2510};
2511
2512/**
2513 Type for signature generation and for retrieving nrows estimate
2514 from secondary engine for current AccessPath.
2515 @param params for this function. Refer to typedef for detailed description.
2516 @retval true if an updated nrow estimate is available.
2517 @retval false if no nrow estimate is available.
2518 */
2520 bool (*)(const SecondaryEngineNrowsParameters &params);
2521
2522/**
2523 Checks whether the tables used in an explain query are loaded in the secondary
2524 engine.
2525 @param thd thread context.
2526
2527 @retval true if there is a table not loaded to the secondary engine, false
2528 otherwise
2529*/
2531
2532/**
2533 Looks up and returns a specific secondary engine query offload or exec
2534 failure reason as a string given a thread context (representing the query)
2535 when the offloaded query fails in the secondary storage engine.
2536
2537 @param thd thread context.
2538
2539 @retval std::string_view as the offload failure reason.
2540 The memory pointed to is managed by the handlerton and may be freed
2541 when the statement completes.
2542*/
2544 std::string_view (*)(const THD *thd);
2545
2546/**
2547 Finds and returns a specific secondary engine query offload failure reason
2548 as a string given a thread context (representing the query) whenever
2549 get_secondary_engine_offload_or_exec_fail_reason_t returns an empty reason.
2550
2551 @param thd thread context.
2552
2553 @retval std::string_view as the offload failure reason.
2554*/
2556 std::string_view (*)(THD *thd);
2557
2558/**
2559 Sets a specific secondary engine offload failure reason for a query
2560 represented by the thread context when the offloaded query fails in
2561 the secondary storage engine.
2562
2563 @param thd thread context.
2564
2565 @param reason offload failure reason.
2566
2567 @retval bool to indicate if the setting succeeded or failed
2568*/
2570 bool (*)(const THD *thd, std::string_view reason);
2571
2573 /** Continue optimization phase with current hypergraph. */
2574 kContinue = 0,
2575 /** Trigger restart of hypergraph with provided number of subgraph pairs. */
2576 kRestart = 1,
2577};
2578
2580 /** Optimizer request from the secondary engine. */
2582 /** Subgraph pairs requested by the secondary engine. */
2584 /** Indicates if simplification is guided using secondary engine */
2586};
2587
2588/**
2589 Hook to evaluate the current hypergraph optimization state in optimization for
2590 all the engines, and returns the state that hypergraph should transition to.
2591 Usually invoked after secondary_engine_modify_view_ap_cost_t is invoked via
2592 the optimizer. The state is returned as object of type
2593 SecondaryEngineGraphSimplificationRequestParameters, and can lead to
2594 simplification of hypergraph search space, or resetting the graph and starting
2595 search afresh.
2596
2597 @param thd The thread context.
2598 @param hypergraph The hypergraph that represents the search space.
2599 @param access_path The AccessPath to evaluate.
2600 @param current_subgraph_pairs Count of subgraph pairs explored so far.
2601 @param current_subgraph_pairs_limit Limit for current hypergraph.
2602 @param is_root_access_path Indicating if access_path is root.
2603 @param trace Optimizer trace string.
2604
2605 @returns instance of SecondaryEngineGraphSimplificationRequestParameters which
2606 contains description of the state hypergraph optimizer should transition to.
2607*/
2610 THD *thd, const JoinHypergraph &hypergraph,
2611 const AccessPath *access_path, int current_subgraph_pairs,
2612 int current_subgraph_pairs_limit, bool is_root_access_path,
2613 std::string *trace);
2614
2615// Capabilities (bit flags) for secondary engines.
2616using SecondaryEngineFlags = uint64_t;
2620
2621 // If this flag is set, aggregation (GROUP BY and DISTINCT) do not require
2622 // ordered inputs and create unordered outputs. This is typically the case
2623 // if they are implemented using hash-based techniques.
2625
2626 /// This flag can be set to signal that a secondary storage engine will not
2627 /// use MySQL's executor (see JOIN::override_executor_func). In this case, it
2628 /// doesn't need MySQL's execution data structures, like internal temporary
2629 /// tables, filesort objects or iterators. If the flag is set,
2630 /// FinalizePlanForQueryBlock() will not make any changes to the plan, and
2631 /// CreateIteratorFromAccessPath() will not be called.
2633};
2634
2635/// Creates an empty bitmap of access path types. This is the base
2636/// case for the function template with the same name below.
2637inline constexpr SecondaryEngineFlags MakeSecondaryEngineFlags() { return 0; }
2638
2639/// Creates a bitmap representing a set of access path types.
2640template <typename... Args>
2642 SecondaryEngineFlag flag1, Args... rest) {
2643 return (uint64_t{1} << static_cast<int>(flag1)) |
2644 MakeSecondaryEngineFlags(rest...);
2645}
2646
2647/// Returns the handlerton of the secondary engine that is used in the session,
2648/// or nullptr if a secondary engine is not used.
2649const handlerton *SecondaryEngineHandlerton(const THD *thd);
2650
2651/// Returns the handlerton of the eligible secondary engine that is used in the
2652/// session, If found, also initialises the thd member which caches this
2653/// eligible secondary engine, or returns nullptr if a secondary engine is not
2654/// used.
2656 THD *thd, const LEX_CSTRING *secondary_engine_in_name);
2657
2658// FIXME: Temporary workaround to enable storage engine plugins to use the
2659// before_commit hook. Remove after WL#11320 has been completed.
2660using se_before_commit_t = void (*)(void *arg);
2661
2662// FIXME: Temporary workaround to enable storage engine plugins to use the
2663// after_commit hook. Remove after WL#11320 has been completed.
2664using se_after_commit_t = void (*)(void *arg);
2665
2666// FIXME: Temporary workaround to enable storage engine plugins to use the
2667// before_rollback hook. Remove after WL#11320 has been completed.
2668using se_before_rollback_t = void (*)(void *arg);
2669
2670/**
2671 Notify plugins when a SELECT query was executed. The plugins will be notified
2672 only if the query is not considered secondary engine relevant, i.e.:
2673 1. for a query with missing secondary_engine_statement_ctx, its estimated cost
2674 is greater than the currently configured 'secondary_engine_cost_threshold'
2675 2. for queries with secondary_engine_statement_ctx, wherever
2676 secondary_engine_statement_ctx::is_primary_engine_optimal() returns False
2677 indicating secondary engine relevance.
2678 */
2679using notify_after_select_t = void (*)(THD *thd, SelectExecutedIn executed_in);
2680
2681/**
2682 * Notify plugins when a table is created.
2683 */
2684using notify_create_table_t = void (*)(struct HA_CREATE_INFO *create_info,
2685 const char *db, const char *table_name);
2686
2687/**
2688 * Notify plugins when a materialized view is referenced in a query.
2689 * The plugin is expected to check if the materialized view is available.
2690 * @param[in] thd current thd.
2691 * @param[in] db_name view database
2692 * @param[in] table_name view name
2693 * @param[in] view_def view definition query
2694 *
2695 * @return :
2696 * @retval true The materialized view is found and can be used.
2697 * @retval false The materialzied view is not available and cannot be used.
2698 */
2700 std::string_view db_name,
2701 std::string_view table_name,
2702 std::string_view view_def);
2703
2704/**
2705 Secondary engine hook called after PRIMARY_TENTATIVELY optimization is
2706 complete, and decides if secondary engine optimization will be performed, and
2707 comparison of primary engine cost and secondary engine cost will determine
2708 which engine to use for execution.
2709 @param[in] thd current thd.
2710 @return :
2711 @retval true When secondary_engine's prepare hook is to be further called
2712 @retval false When secondary_engine's prepare hook is NOT to be further called
2713
2714 */
2716
2717/**
2718 Hook used to estimate the cardinality of table Node objects in the
2719 JoinHypergraph. For each Node, it attempts to estimate the cardinality,
2720 and if successful, stores it in the field `cardinality`.
2721
2722 @param thd The thread context.
2723 @param graph The JoinHypergraph where the estimates are to be made.
2724*/
2725using cardinality_estimation_hook_t = void (*)(THD *thd, JoinHypergraph *graph);
2726
2727/**
2728 * Notify plugins when a table is dropped.
2729 */
2730using notify_drop_table_t = void (*)(Table_ref *tab);
2731
2732/**
2733 * Store the name of default secondary engine, if any.
2734 */
2735extern std::atomic<const char *> default_secondary_engine_name;
2736/*
2737 Page Tracking : interfaces to handlerton functions which starts/stops page
2738 tracking, and purges/fetches page tracking information.
2739*/
2740
2741/**
2742 Start page tracking.
2743
2744 @param[out] start_id SE specific sequence number [LSN for InnoDB]
2745 indicating when the tracking was started
2746
2747 @return Operation status.
2748 @retval 0 Success
2749 @retval other ER_* mysql error. Get error details from THD.
2750*/
2751using page_track_start_t = int (*)(uint64_t *start_id);
2752
2753/**
2754 Stop page tracking.
2755
2756 @param[out] stop_id SE specific sequence number [LSN for InnoDB]
2757 indicating when the tracking was stopped
2758
2759 @return Operation status.
2760 @retval 0 Success
2761 @retval other ER_* mysql error. Get error details from THD.
2762*/
2763using page_track_stop_t = int (*)(uint64_t *stop_id);
2764
2765/**
2766 Purge page tracking data.
2767
2768 @param[in,out] purge_id SE specific sequence number [LSN for InnoDB]
2769 initially indicating till where the data needs to be purged and finally
2770 updated to until where it was actually purged
2771
2772 @return Operation status.
2773 @retval 0 Success
2774 @retval other ER_* mysql error. Get error details from THD.
2775*/
2776using page_track_purge_t = int (*)(uint64_t *purge_id);
2777
2778/**
2779 Fetch tracked pages.
2780
2781 @param[in] cbk_func callback function return page IDs
2782 @param[in] cbk_ctx caller's context for callback
2783 @param[in,out] start_id SE specific sequence number [LSN for InnoDB] from
2784 where the pages tracked would be returned.
2785 @note The range might get expanded and the actual start_id used for the
2786 querying will be updated.
2787 @param[in,out] stop_id SE specific sequence number [LSN for InnoDB]
2788 until where the pages tracked would be returned.
2789 @note The range might get expanded and the actual stop_id used for the
2790 querying will be updated.
2791 @param[out] buffer allocated buffer to copy page IDs
2792 @param[in] buffer_len length of buffer in bytes
2793
2794 @return Operation status.
2795 @retval 0 Success
2796 @retval other ER_* mysql error. Get error details from THD.
2797*/
2799 void *cbk_ctx, uint64_t *start_id,
2800 uint64_t *stop_id,
2801 unsigned char *buffer,
2802 size_t buffer_len);
2803
2804/**
2805 Fetch approximate number of tracked pages in the given range.
2806
2807 @param[in,out] start_id SE specific sequence number [LSN for InnoDB] from
2808 where the pages tracked would be returned.
2809 @note the range might get expanded and the actual start_id used for the
2810 querying will be updated.
2811 @param[in,out] stop_id SE specific sequence number [LSN for InnoDB]
2812 until where the pages tracked would be returned.
2813 @note the range might get expanded and the actual stop_id used for the
2814 querying will be updated.
2815 @param[out] num_pages number of pages tracked
2816
2817 @return Operation status.
2818 @retval 0 Success
2819 @retval other ER_* mysql error. Get error details from THD.
2820*/
2821using page_track_get_num_page_ids_t = int (*)(uint64_t *start_id,
2822 uint64_t *stop_id,
2823 uint64_t *num_pages);
2824
2825/** Fetch the status of the page tracking system.
2826@param[out] status vector of a pair of (ID, bool) where ID is the
2827start/stop point and bool is true if the ID is a start point else false */
2829 void (*)(std::vector<std::pair<uint64_t, bool>> &status);
2830
2831/** Page track interface */
2839};
2840
2841/**
2842 handlerton is a singleton structure - one instance per storage engine -
2843 to provide access to storage engine functionality that works on the
2844 "global" level (unlike handler class that works on a per-table basis).
2845
2846 usually handlerton instance is defined statically in ha_xxx.cc as
2847
2848 static handlerton { ... } xxx_hton;
2849
2850 savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
2851*/
2853 /**
2854 Historical marker for if the engine is available or not.
2855 */
2857
2858 /**
2859 Historical number used for frm file to determine the correct storage engine.
2860 This is going away and new engines will just use "name" for this.
2861 */
2863 /**
2864 Each storage engine has it's own memory area (actually a pointer)
2865 in the thd, for storing per-connection information.
2866 It is accessed as
2867
2868 thd->ha_data[xxx_hton.slot]
2869
2870 slot number is initialized by MySQL after xxx_init() is called.
2871 */
2872 uint slot;
2873 /**
2874 To store per-savepoint data storage engine is provided with an area
2875 of a requested size (0 is ok here).
2876 savepoint_offset must be initialized statically to the size of
2877 the needed memory to store per-savepoint information.
2878 After xxx_init it is changed to be an offset to savepoint storage
2879 area and need not be used by storage engine.
2880 see binlog_hton and binlog_savepoint_set/rollback for an example.
2881 */
2883
2884 /* handlerton methods */
2885
2915 /** @deprecated Was used to upgrade from 5.7. */
2917 /** @deprecated Was used to upgrade from 5.7. */
2921 /** @deprecated Was used to upgrade from 5.7. */
2923 /** @deprecated Was used to upgrade from 5.7. */
2936
2937 /** Global handler flags. */
2939
2940 /*
2941 Those handlerton functions below are properly initialized at handler
2942 init.
2943 */
2944
2953
2954 /*
2955 APIs for retrieving Serialized Dictionary Information by tablespace id
2956 */
2957
2964
2965 /**
2966 Null-ended array of file extensions that exist for the storage engine.
2967 Used by frm_error() and the default handler::rename_table and delete_table
2968 methods in handler.cc.
2969
2970 For engines that have two file name extensions (separate meta/index file
2971 and data file), the order of elements is relevant. First element of engine
2972 file name extensions array should be meta/index file extension. Second
2973 element - data file extension. This order is assumed by
2974 prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
2975
2976 For engines that don't have files, file_extensions is NULL.
2977
2978 Currently, the following alternatives are used:
2979 - file_extensions == NULL;
2980 - file_extensions[0] != NULL, file_extensions[1] == NULL;
2981 - file_extensions[0] != NULL, file_extensions[1] != NULL,
2982 file_extensions[2] == NULL;
2983 */
2984 const char **file_extensions;
2985
2996
3001
3004
3005 /** Clone data transfer interfaces */
3007
3008 /** Flag for Engine License. */
3010 /** Location for engines to keep personal structures. */
3011 void *data;
3012
3013 /*
3014 Log_resource functions that must be supported by storage engines
3015 with relevant log information to be collected.
3016 */
3020
3021 /** Flags describing details of foreign key support by storage engine. */
3023
3025
3026 /**
3027 Suffix for auto-generated foreign key names for tables using this storage
3028 engine. If such suffix is specified by SE then its generated foreign key
3029 names follow (table name)(SE-specific FK name suffix)(FK number) pattern.
3030 Length of such suffix should not exceed MAX_FK_NAME_SUFFIX_LENGTH bytes.
3031 If no suffix is specified then FK_NAME_DEFAULT_SUFFIX is used as
3032 default.
3033 */
3035
3036 /**
3037 Pointer to a function that prepares a secondary engine for executing a
3038 statement.
3039
3040 @see prepare_secondary_engine_t for function signature.
3041 */
3043
3044 /**
3045 Pointer to a function that optimizes the current statement for
3046 execution on the secondary storage engine represented by this
3047 handlerton.
3048
3049 @see optimize_secondary_engine_t for function signature.
3050 */
3052
3053 /**
3054 Pointer to a function that estimates the cost of executing a join in a
3055 secondary storage engine.
3056
3057 @see compare_secondary_engine_cost_t for function signature.
3058 */
3060
3061 /// Bitmap which contains the supported join types and other flags
3062 /// for a secondary storage engine when used with the hypergraph join
3063 /// optimizer. If it is empty, it means that the secondary engine
3064 /// does not support the hypergraph join optimizer.
3066
3067 /// Pointer to a function that checks if the table is loaded in the
3068 /// secondary engine in the case of an explain statement.
3069 ///
3070 /// @see external_engine_explain_check_t for function signature.
3072
3073 /// Pointer to a function that evaluates the cost of executing an access path
3074 /// in a secondary storage engine.
3075 ///
3076 /// @see secondary_engine_modify_view_ap_cost_t for function signature.
3078
3079 /// Pointer to a function that provides nrow estimates for access paths
3080 /// from secondary storage engine
3081 ///
3082 /// @see secondary_engine_nrows_t for function signature.
3084
3085 /// Pointer to a function that returns the query offload or exec failure
3086 /// reason as a string given a thread context (representing the query) when
3087 /// the offloaded query failed in a secondary storage engine.
3088 ///
3089 /// @see get_secondary_engine_offload_or_exec_fail_reason_t for function
3090 /// signature.
3093
3094 /// Pointer to a function that finds and returns the query offload failure
3095 /// reason as a string given a thread context (representing the query) when
3096 /// get_secondary_engine_offload_or_exec_fail_reason returns an empty reason.
3097 ///
3098 /// @see find_secondary_engine_offload_fail_reason_t for function
3099 /// signature.
3102
3103 /// Pointer to a function that sets the offload failure reason as a string
3104 /// for a thread context (representing the query) when the offloaded query
3105 /// failed in a secondary storage engine.
3106 ///
3107 /// @see set_secondary_engine_offload_fail_reason_t for function signature.
3110
3111 /// Pointer to function that checks secondary engine request for updating
3112 /// hypergraph join optimization.
3113 ///
3114 /// @see secondary_engine_check_optimizer_request_t for function signature.
3117
3118 /* Pointer to a function that is called at the end of the PRIMARY_TENTATIVELY
3119 * optimization stage, which also decides that the statement should be
3120 * attempted offloaded to a secondary storage engine. */
3122
3123 /* Pointer to a function to request table filter estimation to the
3124 * secondary_engine. */
3126
3130
3132
3135
3137
3138 /** Page tracking interface */
3140};
3141
3142/* Possible flags of a handlerton (there can be 32 of them) */
3143#define HTON_NO_FLAGS 0
3144#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
3145#define HTON_ALTER_NOT_SUPPORTED (1 << 1) // Engine does not support alter
3146#define HTON_CAN_RECREATE (1 << 2) // Delete all is used for truncate
3147#define HTON_HIDDEN (1 << 3) // Engine does not appear in lists
3148/*
3149 Bit 4 was occupied by BDB-specific HTON_FLUSH_AFTER_RENAME flag and is no
3150 longer used.
3151*/
3152#define HTON_NOT_USER_SELECTABLE (1 << 5)
3153#define HTON_TEMPORARY_NOT_SUPPORTED \
3154 (1 << 6) // Having temporary tables not supported
3155#define HTON_SUPPORT_LOG_TABLES (1 << 7) // Engine supports log tables
3156#define HTON_NO_PARTITION (1 << 8) // You can not partition these tables
3157
3158/*
3159 This flag should be set when deciding that the engine does not allow row based
3160 binary logging (RBL) optimizations.
3161
3162 Currently, setting this flag, means that table's read/write_set will be left
3163 untouched when logging changes to tables in this engine. In practice this
3164 means that the server will not mess around with table->write_set and/or
3165 table->read_set when using RBL and deciding whether to log full or minimal
3166 rows.
3167
3168 It's valuable for instance for virtual tables, eg: Performance Schema which
3169 have no meaning for replication.
3170*/
3171#define HTON_NO_BINLOG_ROW_OPT (1 << 9)
3172
3173/**
3174 Engine supports extended keys. The flag allows to
3175 use 'extended key' feature if the engine is able to
3176 do it (has primary key values in the secondary key).
3177 Note that handler flag HA_PRIMARY_KEY_IN_READ_INDEX is
3178 actually partial case of HTON_SUPPORTS_EXTENDED_KEYS.
3179*/
3180
3181#define HTON_SUPPORTS_EXTENDED_KEYS (1 << 10)
3182
3183// Engine support foreign key constraint.
3184
3185#define HTON_SUPPORTS_FOREIGN_KEYS (1 << 11)
3186
3187/**
3188 Engine supports atomic DDL. That is rollback of transaction for DDL
3189 statement will also rollback all changes in SE, commit of transaction
3190 of DDL statement will make it durable.
3191*/
3192
3193#define HTON_SUPPORTS_ATOMIC_DDL (1 << 12)
3194
3195/* Engine supports packed keys. */
3196#define HTON_SUPPORTS_PACKED_KEYS (1 << 13)
3197
3198/** Engine is a secondary storage engine. */
3199#define HTON_IS_SECONDARY_ENGINE (1 << 14)
3200
3201/** Engine supports secondary storage engines. */
3202#define HTON_SUPPORTS_SECONDARY_ENGINE (1 << 15)
3203
3204/** Engine supports table or tablespace encryption . */
3205#define HTON_SUPPORTS_TABLE_ENCRYPTION (1 << 16)
3206
3208 1 << 17};
3209
3210/** Engine supports Generated invisible primary key. */
3211// clang-format off
3212constexpr const decltype(
3214// clang-format on
3215
3216/** Whether the secondary engine supports DDLs. No meaning if the engine is not
3217 * secondary. */
3218#define HTON_SECONDARY_ENGINE_SUPPORTS_DDL (1 << 19)
3219
3220/** Whether the engine does not support triggers. */
3221#define HTON_NO_TRIGGER_SUPPORT (1 << 20)
3222
3223/** Whether the primary engine supports external data sources. This case refers
3224 to having tables with data in object store and the engine does not store any
3225 of those data, only metadata. Table contents can be accessed only after
3226 loading the table in the secondary storage engine. The flag is used for
3227 a primary engine only.
3228 */
3229#define HTON_SUPPORTS_EXTERNAL_SOURCE (1 << 21)
3230
3231constexpr const decltype(handlerton::flags) HTON_SUPPORTS_BULK_LOAD{1 << 22};
3232
3233/** Engine supports index distance scan. */
3234inline constexpr const decltype(handlerton::flags) HTON_SUPPORTS_DISTANCE_SCAN{
3235 1 << 23};
3236
3237/* Whether the engine supports being specified as a default storage engine */
3238inline constexpr const decltype(handlerton::flags)
3240
3241/** Whether the secondary engine supports creation of temporary tables. */
3242inline constexpr const decltype(handlerton::flags)
3244
3245/* Whether the handlerton is a secondary engine. */
3246inline bool hton_is_secondary_engine(const handlerton *hton) {
3247 return hton != nullptr && (hton->flags & HTON_IS_SECONDARY_ENGINE) != 0U;
3248}
3249
3250/* Disable foreign keys in storage engine and handle it in SQL Layer. */
3251inline constexpr const decltype(handlerton::flags) HTON_SUPPORTS_SQL_FK{1
3252 << 25};
3253
3254/* Whether the secondary engine handlerton supports DDLs */
3256 assert(hton->flags & HTON_IS_SECONDARY_ENGINE);
3257 return (hton->flags & HTON_SECONDARY_ENGINE_SUPPORTS_DDL) != 0;
3258}
3259
3260/* Whether the secondary engine handlerton supports temporary tables. */
3262 assert(hton->flags & HTON_IS_SECONDARY_ENGINE);
3263 return (hton->flags & HTON_SECONDARY_SUPPORTS_TEMPORARY_TABLE) != 0U;
3264}
3265
3266inline bool ddl_is_atomic(const handlerton *hton) {
3267 return (hton->flags & HTON_SUPPORTS_ATOMIC_DDL) != 0;
3268}
3269
3270/* Bits for handlerton::foreign_keys_flags bitmap. */
3271
3272/**
3273 Engine supports both unique and non-unique parent keys for
3274 foreign keys which contain full foreign key as its prefix.
3275
3276 Storage engines which support foreign keys but do not have
3277 this flag set are assumed to support only parent keys which
3278 are primary/unique and contain exactly the same columns as
3279 the foreign key, possibly, in different order.
3280*/
3281
3283
3284/**
3285 Storage engine supports hash keys as supporting keys for foreign
3286 keys. Hash key should contain all foreign key columns and only
3287 them (although in any order).
3288
3289 Storage engines which support foreign keys but do not have this
3290 flag set are assumed to not allow hash keys as supporting keys.
3291*/
3292
3294
3295/**
3296 Storage engine supports non-hash keys which have common prefix
3297 with the foreign key as supporting keys for it. If there are
3298 several such keys, one which shares biggest prefix with FK is
3299 chosen.
3300
3301 Storage engines which support foreign keys but do not have this
3302 flag set are assumed to require that supporting key contains full
3303 foreign key as its prefix.
3304*/
3305
3307
3308/**
3309 Storage engine does not support using the same key for both parent
3310 and supporting key, but requires the two to be different.
3311*/
3312
3314 (1 << 3);
3315
3316/**
3317 Engine takes into account hidden part of key (coming from primary key)
3318 when determines if it can serve as parent key for a foreign key.
3319
3320 Implies HTON_FKS_WITH_PREFIX_PARENT_KEYS and is related to
3321 HTON_SUPPORTS_EXTENDED_KEYS.
3322*/
3323
3325
3326/**
3327 Maximum possible length of SE-specific suffixes for auto-generated
3328 foreign key names.
3329*/
3330static const size_t MAX_FK_NAME_SUFFIX_LENGTH = 16;
3331
3332/**
3333 Suffix for auto-generated foreign key names for tables in SE's which
3334 don't specify own suffix. I.e. for foreign keys on tables in such
3335 SE's generated names follow (table name)FK_NAME_DEFAULT_SUFFIX(FK number)
3336 pattern.
3337*/
3339
3346
3352
3353/**
3354 Struct to hold information about the table that should be created.
3355 */
3359 bool schema_read_only{false};
3361 const char *password{nullptr};
3362 const char *tablespace{nullptr};
3363 LEX_STRING comment{nullptr, 0};
3364
3365 /**
3366 Algorithm (and possible options) to be used for InnoDB's transparent
3367 page compression. If this attribute is set then it is hint to the
3368 storage engine to try and compress the data using the specified algorithm
3369 where possible. Note: this value is interpreted by the storage engine only.
3370 and ignored by the Server layer. */
3371
3373
3374 /**
3375 This attribute is used for InnoDB's transparent page encryption.
3376 If this attribute is set then it is hint to the storage engine to encrypt
3377 the data. Note: this value is interpreted by the storage engine only.
3378 and ignored by the Server layer. */
3379
3381
3382 /**
3383 * Secondary engine of the table.
3384 * Is nullptr if no secondary engine defined.
3385 */
3387 /** Secondary engine load status */
3388 bool secondary_load{false};
3389
3390 /** Part info in order to maintain in HA_CREATE_INFO the per-partition
3391 * secondary_load status*/
3393
3394 const char *data_file_name{nullptr};
3395 const char *index_file_name{nullptr};
3396 const char *alias{nullptr};
3400 uint64_t table_options{0};
3402 uint64_t used_fields{0};
3403 // Can only be 1,2,4,8 or 16, but use uint32_t since that how it is
3404 // represented in InnoDB
3405 std::uint32_t key_block_size{0};
3406 uint stats_sample_pages{0}; /* number of pages to sample during
3407 stats estimation, if used, otherwise 0. */
3411 /**
3412 Row type of the table definition.
3413
3414 Defaults to ROW_TYPE_DEFAULT for all non-ALTER statements.
3415 For ALTER TABLE defaults to ROW_TYPE_NOT_USED (means "keep the current").
3416
3417 Can be changed either explicitly by the parser.
3418 If nothing specified inherits the value of the original table (if present).
3419 */
3421 uint null_bits{0}; /* NULL bits at start of record */
3422 uint options{0}; /* OR of HA_CREATE_ options */
3424 ha_storage_media storage_media{HA_SM_DEFAULT}; /* DEFAULT, DISK or MEMORY */
3425
3426 /*
3427 A flag to indicate if this table should be marked as a hidden table in
3428 the data dictionary. One use case is to mark the temporary tables
3429 created by ALTER to be marked as hidden.
3430 */
3431 bool m_hidden{false};
3432
3433 /*
3434 A flag to indicate if this table should be created but not committed at
3435 the end of statement.
3436 */
3438
3441
3443
3445
3449
3450 // Position in query text where column definitions end and table options start
3452
3453 /**
3454 Fill HA_CREATE_INFO to be used by ALTER as well as upgrade code.
3455 This function separates code from mysql_prepare_alter_table() to be
3456 used by upgrade code as well to reduce code duplication.
3457 For ALTER code path, this lets new create options override the old
3458 ones.
3459
3460 @param[in] share TABLE_SHARE object
3461 @param[in] used_fields If a given create option is not flagged, old
3462 value be copied from the TABLE_SHARE.
3463 */
3464
3466 uint64_t used_fields);
3467
3468 /**
3469 Populate the db_type member depending on internal state and thd variables.
3470
3471 @param[in] thd user session
3472 */
3473 bool set_db_type(THD *thd);
3474};
3475
3476/**
3477 Structure describing changes to an index to be caused by ALTER TABLE.
3478*/
3479
3480struct KEY_PAIR {
3481 /**
3482 Pointer to KEY object describing old version of index in
3483 TABLE::key_info array for TABLE instance representing old
3484 version of table.
3485 */
3487 /**
3488 Pointer to KEY object describing new version of index in
3489 Alter_inplace_info::key_info_buffer array.
3490 */
3492};
3493
3494/**
3495 In-place alter handler context.
3496
3497 This is a superclass intended to be subclassed by individual handlers
3498 in order to store handler unique context between in-place alter API calls.
3499
3500 The handler is responsible for creating the object. This can be done
3501 as early as during check_if_supported_inplace_alter().
3502
3503 The SQL layer is responsible for destroying the object.
3504
3505 @see Alter_inplace_info
3506*/
3507
3509 public:
3511
3513 [[maybe_unused]]) {}
3514 virtual ~inplace_alter_handler_ctx() = default;
3515};
3516
3517/**
3518 Class describing changes to be done by ALTER TABLE.
3519 Instance of this class is passed to storage engine in order
3520 to determine if this ALTER TABLE can be done using in-place
3521 algorithm. It is also used for executing the ALTER TABLE
3522 using in-place algorithm.
3523*/
3524
3526 public:
3527 /**
3528 Bits to show in detail what operations the storage engine is
3529 to execute.
3530
3531 All these operations are supported as in-place operations by the
3532 SQL layer. This means that operations that by their nature must
3533 be performed by copying the table to a temporary table, will not
3534 have their own flags here (e.g. ALTER TABLE FORCE, ALTER TABLE
3535 ENGINE).
3536
3537 We generally try to specify handler flags only if there are real
3538 changes. But in cases when it is cumbersome to determine if some
3539 attribute has really changed we might choose to set flag
3540 pessimistically, for example, relying on parser output only.
3541 */
3543
3544 // Add non-unique, non-primary index
3545 static const HA_ALTER_FLAGS ADD_INDEX = 1ULL << 0;
3546
3547 // Drop non-unique, non-primary index
3548 static const HA_ALTER_FLAGS DROP_INDEX = 1ULL << 1;
3549
3550 // Add unique, non-primary index
3551 static const HA_ALTER_FLAGS ADD_UNIQUE_INDEX = 1ULL << 2;
3552
3553 // Drop unique, non-primary index
3554 static const HA_ALTER_FLAGS DROP_UNIQUE_INDEX = 1ULL << 3;
3555
3556 // Add primary index
3557 static const HA_ALTER_FLAGS ADD_PK_INDEX = 1ULL << 4;
3558
3559 // Drop primary index
3560 static const HA_ALTER_FLAGS DROP_PK_INDEX = 1ULL << 5;
3561
3562 // Add column
3563
3564 // Virtual generated column
3565 static const HA_ALTER_FLAGS ADD_VIRTUAL_COLUMN = 1ULL << 6;
3566 // Stored base (non-generated) column
3567 static const HA_ALTER_FLAGS ADD_STORED_BASE_COLUMN = 1ULL << 7;
3568 // Stored generated column
3570 // Add generic column (convenience constant).
3573
3574 // Drop column
3575 static const HA_ALTER_FLAGS DROP_VIRTUAL_COLUMN = 1ULL << 9;
3576 static const HA_ALTER_FLAGS DROP_STORED_COLUMN = 1ULL << 10;
3579
3580 // Rename column
3581 static const HA_ALTER_FLAGS ALTER_COLUMN_NAME = 1ULL << 11;
3582
3583 // Change column datatype
3585 static const HA_ALTER_FLAGS ALTER_STORED_COLUMN_TYPE = 1ULL << 13;
3586
3587 /**
3588 Change column datatype in such way that new type has compatible
3589 packed representation with old type, so it is theoretically
3590 possible to perform change by only updating data dictionary
3591 without changing table rows.
3592 */
3594
3595 /// A virtual column has changed its position
3597
3598 /// A stored column has changed its position (disregarding virtual columns)
3600
3601 // Change column from NOT NULL to NULL
3602 static const HA_ALTER_FLAGS ALTER_COLUMN_NULLABLE = 1ULL << 17;
3603
3604 // Change column from NULL to NOT NULL
3606
3607 // Set or remove default column value
3608 static const HA_ALTER_FLAGS ALTER_COLUMN_DEFAULT = 1ULL << 19;
3609
3610 // Change column generation expression
3611 static const HA_ALTER_FLAGS ALTER_VIRTUAL_GCOL_EXPR = 1ULL << 20;
3612 static const HA_ALTER_FLAGS ALTER_STORED_GCOL_EXPR = 1ULL << 21;
3613
3614 // Add foreign key
3615 static const HA_ALTER_FLAGS ADD_FOREIGN_KEY = 1ULL << 22;
3616
3617 // Drop foreign key
3618 static const HA_ALTER_FLAGS DROP_FOREIGN_KEY = 1ULL << 23;
3619
3620 // table_options changed, see HA_CREATE_INFO::used_fields for details.
3621 static const HA_ALTER_FLAGS CHANGE_CREATE_OPTION = 1ULL << 24;
3622
3623 // Table is renamed
3624 static const HA_ALTER_FLAGS ALTER_RENAME = 1ULL << 25;
3625
3626 // Change the storage type of column
3628
3629 // Change the column format of column
3631
3632 // Add partition
3633 static const HA_ALTER_FLAGS ADD_PARTITION = 1ULL << 28;
3634
3635 // Drop partition
3636 static const HA_ALTER_FLAGS DROP_PARTITION = 1ULL << 29;
3637
3638 // Changing partition options
3639 static const HA_ALTER_FLAGS ALTER_PARTITION = 1ULL << 30;
3640
3641 // Coalesce partition
3642 static const HA_ALTER_FLAGS COALESCE_PARTITION = 1ULL << 31;
3643
3644 // Reorganize partition ... into
3645 static const HA_ALTER_FLAGS REORGANIZE_PARTITION = 1ULL << 32;
3646
3647 // Reorganize partition
3648 static const HA_ALTER_FLAGS ALTER_TABLE_REORG = 1ULL << 33;
3649
3650 // Remove partitioning
3652
3653 // Partition operation with ALL keyword
3654 static const HA_ALTER_FLAGS ALTER_ALL_PARTITION = 1ULL << 35;
3655
3656 /**
3657 Rename index. Note that we set this flag only if there are no other
3658 changes to the index being renamed. Also for simplicity we don't
3659 detect renaming of indexes which is done by dropping index and then
3660 re-creating index with identical definition under different name.
3661 */
3662 static const HA_ALTER_FLAGS RENAME_INDEX = 1ULL << 36;
3663
3664 /**
3665 Recreate the table for ALTER TABLE FORCE, ALTER TABLE ENGINE
3666 and OPTIMIZE TABLE operations.
3667 */
3668 static const HA_ALTER_FLAGS RECREATE_TABLE = 1ULL << 37;
3669
3670 // Add spatial index
3671 static const HA_ALTER_FLAGS ADD_SPATIAL_INDEX = 1ULL << 38;
3672
3673 // Alter index comment
3674 static const HA_ALTER_FLAGS ALTER_INDEX_COMMENT = 1ULL << 39;
3675
3676 // New/changed virtual generated column require validation
3677 static const HA_ALTER_FLAGS VALIDATE_VIRTUAL_COLUMN = 1ULL << 40;
3678
3679 /**
3680 Change index option in a way which is likely not to require index
3681 recreation. For example, change COMMENT or KEY::is_algorithm_explicit
3682 flag (without change of index algorithm itself).
3683 */
3684 static const HA_ALTER_FLAGS CHANGE_INDEX_OPTION = 1LL << 41;
3685
3686 // Rebuild partition
3687 static const HA_ALTER_FLAGS ALTER_REBUILD_PARTITION = 1ULL << 42;
3688
3689 /**
3690 Change in index length such that it does not require index rebuild.
3691 For example, change in index length due to column expansion like
3692 varchar(X) changed to varchar(X + N).
3693 */
3695
3696 /**
3697 Change to one of columns on which virtual generated column depends,
3698 so its values require re-evaluation.
3699 */
3700 static const HA_ALTER_FLAGS VIRTUAL_GCOL_REEVAL = 1ULL << 44;
3701
3702 /**
3703 Change to one of columns on which stored generated column depends,
3704 so its values require re-evaluation.
3705 */
3706 static const HA_ALTER_FLAGS STORED_GCOL_REEVAL = 1ULL << 45;
3707
3708 // Add check constraint.
3709 static const HA_ALTER_FLAGS ADD_CHECK_CONSTRAINT = 1ULL << 46;
3710
3711 // Drop check constraint.
3712 static const HA_ALTER_FLAGS DROP_CHECK_CONSTRAINT = 1ULL << 47;
3713
3714 // Suspend check constraint.
3715 static const HA_ALTER_FLAGS SUSPEND_CHECK_CONSTRAINT = 1ULL << 48;
3716
3717 // Alter column visibility.
3718 static const HA_ALTER_FLAGS ALTER_COLUMN_VISIBILITY = 1ULL << 49;
3719
3720 // Set or remove column's MASKING POLICY name
3721 static const HA_ALTER_FLAGS ALTER_COLUMN_MASKING = 1ULL << 50;
3722
3723 /**
3724 Create options (like MAX_ROWS) for the new version of table.
3725
3726 @note The referenced instance of HA_CREATE_INFO object was already
3727 used to create new .FRM file for table being altered. So it
3728 has been processed by mysql_prepare_create_table() already.
3729 For example, this means that it has HA_OPTION_PACK_RECORD
3730 flag in HA_CREATE_INFO::table_options member correctly set.
3731 */
3733
3734 /**
3735 Alter options, fields and keys for the new version of table.
3736
3737 @note The referenced instance of Alter_info object was already
3738 used to create new .FRM file for table being altered. So it
3739 has been processed by mysql_prepare_create_table() already.
3740 In particular, this means that in Create_field objects for
3741 fields which were present in some form in the old version
3742 of table, Create_field::field member points to corresponding
3743 Field instance for old version of table.
3744 */
3746
3747 /**
3748 Indicates whether operation should fail if table is non-empty.
3749 Storage engines should not suggest/allow execution of such operations
3750 using INSTANT algorithm since check whether table is empty done from
3751 SQL-layer is not "instant". Also SEs might choose different algorithm for
3752 ALTER TABLE execution knowing that it will be allowed to proceed only if
3753 table is empty.
3754
3755 Unlike for Alter_table_ctx::error_if_not_empty, we use bool for this flag
3756 and not bitmap, since SEs are really interested in the fact that ALTER
3757 will fail if table is not empty and not in exact reason behind this fact,
3758 and because we want to avoid extra dependency between Alter_table_ctx and
3759 Alter_inplace_info.
3760 */
3762
3763 /**
3764 Array of KEYs for new version of table - including KEYs to be added.
3765
3766 @note Currently this array is produced as result of
3767 mysql_prepare_create_table() call.
3768 This means that it follows different convention for
3769 KEY_PART_INFO::fieldnr values than objects in TABLE::key_info
3770 array.
3771
3772 @todo This is mainly due to the fact that we need to keep compatibility
3773 with removed handler::add_index() call. We plan to switch to
3774 TABLE::key_info numbering later.
3775
3776 KEYs are sorted - see sort_keys().
3777 */
3779
3780 /** Size of key_info_buffer array. */
3782
3783 /** Size of index_drop_buffer array. */
3785
3786 /**
3787 Array of pointers to KEYs to be dropped belonging to the TABLE instance
3788 for the old version of the table.
3789 */
3791
3792 /** Size of index_add_buffer array. */
3794
3795 /**
3796 Array of indexes into key_info_buffer for KEYs to be added,
3797 sorted in increasing order.
3798 */
3800
3801 /** Size of index_rename_buffer array. */
3803
3804 /** Size of index_rename_buffer array. */
3806
3807 /**
3808 Array of KEY_PAIR objects describing indexes being renamed.
3809 For each index renamed it contains object with KEY_PAIR::old_key
3810 pointing to KEY object belonging to the TABLE instance for old
3811 version of table representing old version of index and with
3812 KEY_PAIR::new_key pointing to KEY object for new version of
3813 index in key_info_buffer member.
3814 */
3817
3818 /** Number of virtual columns to be added. */
3820
3821 /** number of virtual columns to be dropped. */
3823
3824 /**
3825 Context information to allow handlers to keep context between in-place
3826 alter API calls.
3827
3828 @see inplace_alter_handler_ctx for information about object lifecycle.
3829 */
3831
3832 /**
3833 If the table uses several handlers, like ha_partition uses one handler
3834 per partition, this contains a Null terminated array of ctx pointers
3835 that should all be committed together.
3836 Or NULL if only handler_ctx should be committed.
3837 Set to NULL if the low level handler::commit_inplace_alter_table uses it,
3838 to signal to the main handler that everything was committed as atomically.
3839
3840 @see inplace_alter_handler_ctx for information about object lifecycle.
3841 */
3843
3844 /**
3845 Flags describing in detail which operations the storage engine is to
3846 execute.
3847 */
3849
3850 /**
3851 Partition_info taking into account the partition changes to be performed.
3852 Contains all partitions which are present in the old version of the table
3853 with partitions to be dropped or changed marked as such + all partitions
3854 to be added in the new version of table marked as such.
3855 */
3857
3858 /** true for online operation (LOCK=NONE) */
3860
3861 /**
3862 Can be set by handler along with handler_ctx. The difference is that
3863 this flag can be used to store SE-specific in-place ALTER context in cases
3864 when constructing full-blown inplace_alter_handler_ctx descendant is
3865 inconvenient.
3866 */
3868
3869 /**
3870 Can be set by handler to describe why a given operation cannot be done
3871 in-place (HA_ALTER_INPLACE_NOT_SUPPORTED) or why it cannot be done
3872 online (HA_ALTER_INPLACE_NO_LOCK or HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE)
3873 If set, it will be used with ER_ALTER_OPERATION_NOT_SUPPORTED_REASON if
3874 results from handler::check_if_supported_inplace_alter() doesn't match
3875 requirements set by user. If not set, the more generic
3876 ER_ALTER_OPERATION_NOT_SUPPORTED will be used.
3877
3878 Please set to a properly localized string, for example using
3879 my_get_err_msg(), so that the error message as a whole is localized.
3880 */
3882
3884 Alter_info *alter_info_arg, bool error_if_not_empty_arg,
3885 KEY *key_info_arg, uint key_count_arg,
3886 partition_info *modified_part_info_arg)
3887 : create_info(create_info_arg),
3888 alter_info(alter_info_arg),
3889 error_if_not_empty(error_if_not_empty_arg),
3890 key_info_buffer(key_info_arg),
3891 key_count(key_count_arg),
3894 index_add_count(0),
3903 handler_flags(0),
3904 modified_part_info(modified_part_info_arg),
3905 online(false),
3908
3910 if (handler_ctx != nullptr) ::destroy_at(handler_ctx);
3911 }
3912
3913 /**
3914 Used after check_if_supported_inplace_alter() to report
3915 error if the result does not match the LOCK/ALGORITHM
3916 requirements set by the user.
3917
3918 @param not_supported Part of statement that was not supported.
3919 @param try_instead Suggestion as to what the user should
3920 replace not_supported with.
3921 */
3922 void report_unsupported_error(const char *not_supported,
3923 const char *try_instead);
3924
3925 /** Add old and new version of key to array of indexes to be renamed. */
3926 void add_renamed_key(KEY *old_key, KEY *new_key) {
3928 key_pair->old_key = old_key;
3929 key_pair->new_key = new_key;
3930 DBUG_PRINT("info",
3931 ("index renamed: '%s' to '%s'", old_key->name, new_key->name));
3932 }
3933
3934 void add_altered_index_visibility(KEY *old_key, KEY *new_key) {
3935 KEY_PAIR *key_pair =
3937 key_pair->old_key = old_key;
3938 key_pair->new_key = new_key;
3939 DBUG_PRINT("info", ("index had visibility altered: %i to %i",
3940 old_key->is_visible, new_key->is_visible));
3941 }
3942
3943 /**
3944 Add old and new version of modified key to arrays of indexes to
3945 be dropped and added (correspondingly).
3946 */
3947 void add_modified_key(KEY *old_key, KEY *new_key) {
3949 index_add_buffer[index_add_count++] = (uint)(new_key - key_info_buffer);
3950 DBUG_PRINT("info", ("index changed: '%s'", old_key->name));
3951 }
3952
3953 /** Drop key to array of indexes to be dropped. */
3954 void add_dropped_key(KEY *old_key) {
3956 DBUG_PRINT("info", ("index dropped: '%s'", old_key->name));
3957 }
3958
3959 /** Add key to array of indexes to be added. */
3960 void add_added_key(KEY *new_key) {
3961 index_add_buffer[index_add_count++] = (uint)(new_key - key_info_buffer);
3962 DBUG_PRINT("info", ("index added: '%s'", new_key->name));
3963 }
3964};
3965
3967 uint flags{0}; /* isam layer flags (e.g. for myisamchk) */
3968 uint sql_flags{0}; /* sql layer flags - for something myisamchk cannot do */
3969 KEY_CACHE *key_cache; /* new key cache when changing key cache */
3970};
3971
3972/*
3973 This is a buffer area that the handler can use to store rows.
3974 'end_of_used_area' should be kept updated after calls to
3975 read-functions so that other parts of the code can use the
3976 remaining area (until next read calls is issued).
3977*/
3978
3980 uchar *buffer; /* Buffer one can start using */
3981 uchar *buffer_end; /* End of buffer */
3982 uchar *end_of_used_area; /* End of area that was used by handler */
3983};
3984
3985typedef void *range_seq_t;
3986
3988 /*
3989 Initialize the traversal of range sequence
3990
3991 SYNOPSIS
3992 init()
3993 init_params The seq_init_param parameter
3994 n_ranges The number of ranges obtained
3995 flags A combination of HA_MRR_SINGLE_POINT, HA_MRR_FIXED_KEY
3996
3997 RETURN
3998 An opaque value to be used as RANGE_SEQ_IF::next() parameter
3999 */
4000 range_seq_t (*init)(void *init_params, uint n_ranges, uint flags);
4001
4002 /*
4003 Get the next range in the range sequence
4004
4005 SYNOPSIS
4006 next()
4007 seq The value returned by RANGE_SEQ_IF::init()
4008 range OUT Information about the next range
4009
4010 RETURN
4011 0 - Ok, the range structure filled with info about the next range
4012 1 - No more ranges
4013 */
4015
4016 /*
4017 Check whether range_info orders to skip the next record
4018
4019 SYNOPSIS
4020 skip_record()
4021 seq The value returned by RANGE_SEQ_IF::init()
4022 range_info Information about the next range
4023 (Ignored if MRR_NO_ASSOCIATION is set)
4024 rowid Rowid of the record to be checked (ignored if set to 0)
4025
4026 RETURN
4027 1 - Record with this range_info and/or this rowid shall be filtered
4028 out from the stream of records returned by ha_multi_range_read_next()
4029 0 - The record shall be left in the stream
4030 */
4031 bool (*skip_record)(range_seq_t seq, char *range_info, uchar *rowid);
4032};
4033
4034/**
4035 Used to store optimizer cost estimates.
4036
4037 The class consists of PODs only: default operator=, copy constructor
4038 and destructor are used.
4039 */
4041 private:
4042 double io_cost; ///< cost of I/O operations
4043 double cpu_cost; ///< cost of CPU operations
4044 double import_cost; ///< cost of remote operations
4045 double mem_cost; ///< memory used (bytes)
4046
4047 public:
4049
4050 /// Returns sum of time-consuming costs, i.e., not counting memory cost
4051 double total_cost() const { return io_cost + cpu_cost + import_cost; }
4052 double get_io_cost() const { return io_cost; }
4053 double get_cpu_cost() const { return cpu_cost; }
4054 double get_import_cost() const { return import_cost; }
4055 double get_mem_cost() const { return mem_cost; }
4056
4057 /**
4058 Whether or not all costs in the object are zero
4059
4060 @return true if all costs are zero, false otherwise
4061 */
4062 bool is_zero() const {
4063 return !(io_cost || cpu_cost || import_cost || mem_cost);
4064 }
4065 /**
4066 Whether or not the total cost is the maximal double
4067
4068 @return true if total cost is the maximal double, false otherwise
4069 */
4070 bool is_max_cost() const { return io_cost == DBL_MAX; }
4071 /// Reset all costs to zero
4073 /// Set current cost to the maximal double
4075 reset();
4076 io_cost = DBL_MAX;
4077 }
4078
4079 /// Multiply io, cpu and import costs by parameter
4080 void multiply(double m) {
4081 assert(!is_max_cost());
4082
4083 io_cost *= m;
4084 cpu_cost *= m;
4085 import_cost *= m;
4086 /* Don't multiply mem_cost */
4087 }
4088
4090 assert(!is_max_cost() && !other.is_max_cost());
4091
4092 io_cost += other.io_cost;
4093 cpu_cost += other.cpu_cost;
4094 import_cost += other.import_cost;
4095 mem_cost += other.mem_cost;
4096
4097 return *this;
4098 }
4099
4101 Cost_estimate result = *this;
4102 result += other;
4103
4104 return result;
4105 }
4106
4109
4110 assert(!other.is_max_cost());
4111
4112 result.io_cost = io_cost - other.io_cost;
4113 result.cpu_cost = cpu_cost - other.cpu_cost;
4114 result.import_cost = import_cost - other.import_cost;
4115 result.mem_cost = mem_cost - other.mem_cost;
4116 return result;
4117 }
4118
4119 bool operator>(const Cost_estimate &other) const {
4120 return total_cost() > other.total_cost() ? true : false;
4121 }
4122
4123 bool operator<(const Cost_estimate &other) const {
4124 return other > *this ? true : false;
4125 }
4126
4127 /// Add to IO cost
4128 void add_io(double add_io_cost) {
4129 assert(!is_max_cost());
4130 io_cost += add_io_cost;
4131 }
4132
4133 /// Add to CPU cost
4134 void add_cpu(double add_cpu_cost) {
4135 assert(!is_max_cost());
4136 cpu_cost += add_cpu_cost;
4137 }
4138
4139 /// Add to import cost
4140 void add_import(double add_import_cost) {
4141 assert(!is_max_cost());
4142 import_cost += add_import_cost;
4143 }
4144
4145 /// Add to memory cost
4146 void add_mem(double add_mem_cost) {
4147 assert(!is_max_cost());
4148 mem_cost += add_mem_cost;
4149 }
4150};
4151
4153 Cost_estimate *cost);
4154
4155/*
4156 The below two are not used (and not handled) in this milestone of this WL
4157 entry because there seems to be no use for them at this stage of
4158 implementation.
4159*/
4160#define HA_MRR_SINGLE_POINT 1
4161#define HA_MRR_FIXED_KEY 2
4162
4163/*
4164 Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
4165 'range' parameter.
4166*/
4167#define HA_MRR_NO_ASSOCIATION 4
4168
4169/*
4170 The MRR user will provide ranges in key order, and MRR implementation
4171 must return rows in key order.
4172 Passing this flag to multi_read_range_init() may cause the
4173 default MRR handler to be used even if HA_MRR_USE_DEFAULT_IMPL
4174 was not specified.
4175 (If the native MRR impl. can not provide SORTED result)
4176*/
4177#define HA_MRR_SORTED 8
4178
4179/* MRR implementation doesn't have to retrieve full records */
4180#define HA_MRR_INDEX_ONLY 16
4181
4182/*
4183 The passed memory buffer is of maximum possible size, the caller can't
4184 assume larger buffer.
4185*/
4186#define HA_MRR_LIMITS 32
4187
4188/*
4189 Flag set <=> default MRR implementation is used
4190 (The choice is made by **_info[_const]() function which may set this
4191 flag. SQL layer remembers the flag value and then passes it to
4192 multi_read_range_init().
4193*/
4194#define HA_MRR_USE_DEFAULT_IMPL 64
4195
4196/*
4197 Used only as parameter to multi_range_read_info():
4198 Flag set <=> the caller guarantees that the bounds of the scanned ranges
4199 will not have NULL values.
4200*/
4201#define HA_MRR_NO_NULL_ENDPOINTS 128
4202
4203/*
4204 Set by the MRR implementation to signal that it will natively
4205 produced sorted result if multi_range_read_init() is called with
4206 the HA_MRR_SORTED flag - Else multi_range_read_init(HA_MRR_SORTED)
4207 will revert to use the default MRR implementation.
4208*/
4209#define HA_MRR_SUPPORT_SORTED 256
4210
4212 public:
4213 ulonglong data_file_length; /* Length off data file */
4214 ulonglong max_data_file_length; /* Length off data file */
4217 ulonglong delete_length; /* Free bytes */
4219 /*
4220 The number of records in the table.
4221 0 - means the table has exactly 0 rows
4222 other - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
4223 the value is the exact number of records in the table
4224 else
4225 it is an estimate
4226 */
4228 ha_rows deleted; /* Deleted records */
4229 ulong mean_rec_length; /* physical reclength */
4230 /* TODO: create_time should be retrieved from the new DD. Remove this. */
4231 time_t create_time; /* When table was created */
4234 uint block_size; /* index block size */
4235
4236 /*
4237 number of buffer bytes that native mrr implementation needs,
4238 */
4240
4241 /**
4242 Estimate for how much of the table that is available in a memory
4243 buffer. Valid range is [0..1]. If it has the special value
4244 IN_MEMORY_ESTIMATE_UNKNOWN (defined in structs.h), it means that
4245 the storage engine has not supplied any value for it.
4246 */
4248
4250 : data_file_length(0),
4253 delete_length(0),
4255 records(0),
4256 deleted(0),
4257 mean_rec_length(0),
4258 create_time(0),
4259 check_time(0),
4260 update_time(0),
4261 block_size(0),
4263};
4264
4266 public:
4268
4270};
4271
4272/**
4273 Calculates length of key.
4274
4275 Given a key index and a map of key parts return length of buffer used by key
4276 parts.
4277
4278 @param table Table containing the key
4279 @param key Key index
4280 @param keypart_map which key parts that is used
4281
4282 @return Length of used key parts.
4283*/
4284uint calculate_key_len(TABLE *table, uint key, key_part_map keypart_map);
4285/*
4286 bitmap with first N+1 bits set
4287 (keypart_map for a key prefix of [0..N] keyparts)
4288*/
4289#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
4290/*
4291 bitmap with first N bits set
4292 (keypart_map for a key prefix of [0..N-1] keyparts)
4293*/
4294#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
4295
4296/** Base class to be used by handlers different shares */
4298 public:
4299 Handler_share() = default;
4300 virtual ~Handler_share() = default;
4301};
4302
4303/**
4304 Wrapper for struct ft_hints.
4305*/
4306
4308 private:
4310
4311 public:
4312 explicit Ft_hints(uint ft_flags) {
4313 hints.flags = ft_flags;
4315 hints.op_value = 0.0;
4317 }
4318
4319 /**
4320 Set comparison operation type and and value for master MATCH function.
4321
4322 @param type comparison operation type
4323 @param value comparison operation value
4324 */
4325 void set_hint_op(enum ft_operation type, double value) {
4326 hints.op_type = type;
4328 }
4329
4330 /**
4331 Set Ft_hints flag.
4332
4333 @param ft_flag Ft_hints flag
4334 */
4335 void set_hint_flag(uint ft_flag) { hints.flags |= ft_flag; }
4336
4337 /**
4338 Set Ft_hints limit.
4339
4340 @param ft_limit limit
4341 */
4342 void set_hint_limit(ha_rows ft_limit) { hints.limit = ft_limit; }
4343
4344 /**
4345 Get Ft_hints limit.
4346
4347 @return Ft_hints limit
4348 */
4349 ha_rows get_limit() const { return hints.limit; }
4350
4351 /**
4352 Get Ft_hints operation value.
4353
4354 @return operation value
4355 */
4356 double get_op_value() const { return hints.op_value; }
4357
4358 /**
4359 Get Ft_hints operation type.
4360
4361 @return operation type
4362 */
4363 enum ft_operation get_op_type() const { return hints.op_type; }
4364
4365 /**
4366 Get Ft_hints flags.
4367
4368 @return Ft_hints flags
4369 */
4370 uint get_flags() const { return hints.flags; }
4371
4372 /**
4373 Get ft_hints struct.
4374
4375 @return pointer to ft_hints struct
4376 */
4377 struct ft_hints *get_hints() { return &hints; }
4378};
4379
4380/**
4381 The handler class is the interface for dynamically loadable
4382 storage engines. Do not add ifdefs and take care when adding or
4383 changing virtual functions to avoid vtable confusion
4384
4385 Functions in this class accept and return table columns data. Two data
4386 representation formats are used:
4387 1. TableRecordFormat - Used to pass [partial] table records to/from
4388 storage engine
4389
4390 2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
4391 storage engine. See opt_range.cc for description of this format.
4392
4393 TableRecordFormat
4394 =================
4395 [Warning: this description is work in progress and may be incomplete]
4396 The table record is stored in a fixed-size buffer:
4397
4398 record: null_bytes, column1_data, column2_data, ...
4399
4400 The offsets of the parts of the buffer are also fixed: every column has
4401 an offset to its column{i}_data, and if it is nullable it also has its own
4402 bit in null_bytes.
4403
4404 The record buffer only includes data about columns that are marked in the
4405 relevant column set (table->read_set and/or table->write_set, depending on
4406 the situation).
4407 <not-sure>It could be that it is required that null bits of non-present
4408 columns are set to 1</not-sure>
4409
4410 VARIOUS EXCEPTIONS AND SPECIAL CASES
4411
4412 If the table has no nullable columns, then null_bytes is still
4413 present, its length is one byte <not-sure> which must be set to 0xFF
4414 at all times. </not-sure>
4415
4416 If the table has columns of type BIT, then certain bits from those columns
4417 may be stored in null_bytes as well. Grep around for Field_bit for
4418 details.
4419
4420 For blob columns (see Field_blob), the record buffer stores length of the
4421 data, following by memory pointer to the blob data. The pointer is owned
4422 by the storage engine and is valid until the next operation.
4423
4424 If a blob column has NULL value, then its length and blob data pointer
4425 must be set to 0.
4426
4427
4428 Overview of main modules of the handler API
4429 ===========================================
4430 The overview below was copied from the storage/partition/ha_partition.h when
4431 support for non-native partitioning was removed.
4432
4433 -------------------------------------------------------------------------
4434 MODULE create/delete handler object
4435 -------------------------------------------------------------------------
4436 Object create/delete method. Normally called when a table object
4437 exists.
4438
4439 -------------------------------------------------------------------------
4440 MODULE meta data changes
4441 -------------------------------------------------------------------------
4442 Meta data routines to CREATE, DROP, RENAME table are often used at
4443 ALTER TABLE (update_create_info used from ALTER TABLE and SHOW ..).
4444
4445 Methods:
4446 delete_table()
4447 rename_table()
4448 create()
4449 update_create_info()
4450
4451 -------------------------------------------------------------------------
4452 MODULE open/close object
4453 -------------------------------------------------------------------------
4454 Open and close handler object to ensure all underlying files and
4455 objects allocated and deallocated for query handling is handled
4456 properly.
4457
4458 A handler object is opened as part of its initialisation and before
4459 being used for normal queries (not before meta-data changes always.
4460 If the object was opened it will also be closed before being deleted.
4461
4462 Methods:
4463 open()
4464 close()
4465
4466 -------------------------------------------------------------------------
4467 MODULE start/end statement
4468 -------------------------------------------------------------------------
4469 This module contains methods that are used to understand start/end of
4470 statements, transaction boundaries, and aid for proper concurrency
4471 control.
4472
4473 Methods:
4474 store_lock()
4475 external_lock()
4476 start_stmt()
4477 lock_count()
4478 unlock_row()
4479 was_semi_consistent_read()
4480 try_semi_consistent_read()
4481
4482 -------------------------------------------------------------------------
4483 MODULE change record
4484 -------------------------------------------------------------------------
4485 This part of the handler interface is used to change the records
4486 after INSERT, DELETE, UPDATE, REPLACE method calls but also other
4487 special meta-data operations as ALTER TABLE, LOAD DATA, TRUNCATE.
4488
4489 These methods are used for insert (write_row), update (update_row)
4490 and delete (delete_row). All methods to change data always work on
4491 one row at a time. update_row and delete_row also contains the old
4492 row.
4493 delete_all_rows will delete all rows in the table in one call as a
4494 special optimization for DELETE from table;
4495
4496 Bulk inserts are supported if all underlying handlers support it.
4497 start_bulk_insert and end_bulk_insert is called before and after a
4498 number of calls to write_row.
4499
4500 Methods:
4501 write_row()
4502 update_row()
4503 delete_row()
4504 delete_all_rows()
4505 start_bulk_insert()
4506 end_bulk_insert()
4507
4508 -------------------------------------------------------------------------
4509 MODULE full table scan
4510 -------------------------------------------------------------------------
4511 This module is used for the most basic access method for any table
4512 handler. This is to fetch all data through a full table scan. No
4513 indexes are needed to implement this part.
4514 It contains one method to start the scan (rnd_init) that can also be
4515 called multiple times (typical in a nested loop join). Then proceeding
4516 to the next record (rnd_next) and closing the scan (rnd_end).
4517 To remember a record for later access there is a method (position)
4518 and there is a method used to retrieve the record based on the stored
4519 position.
4520 The position can be a file position, a primary key, a ROWID dependent
4521 on the handler below.
4522
4523 All functions that retrieve records and are callable through the
4524 handler interface must indicate whether a record is present after the call
4525 or not. Record found is indicated by returning 0 and setting table status
4526 to "has row". Record not found is indicated by returning a non-zero value
4527 and setting table status to "no row".
4528 @see TABLE::set_found_row() and TABLE::set_no_row().
4529 By enforcing these rules in the handler interface, storage handler functions
4530 need not set any status in struct TABLE. These notes also apply to module
4531 index scan, documented below.
4532
4533 Methods:
4534
4535 rnd_init()
4536 rnd_end()
4537 rnd_next()
4538 rnd_pos()
4539 rnd_pos_by_record()
4540 position()
4541
4542 -------------------------------------------------------------------------
4543 MODULE index scan
4544 -------------------------------------------------------------------------
4545 This part of the handler interface is used to perform access through
4546 indexes. The interface is defined as a scan interface but the handler
4547 can also use key lookup if the index is a unique index or a primary
4548 key index.
4549 Index scans are mostly useful for SELECT queries but are an important
4550 part also of UPDATE, DELETE, REPLACE and CREATE TABLE table AS SELECT
4551 and so forth.
4552 Naturally an index is needed for an index scan and indexes can either
4553 be ordered, hash based. Some ordered indexes can return data in order
4554 but not necessarily all of them.
4555 There are many flags that define the behavior of indexes in the
4556 various handlers. These methods are found in the optimizer module.
4557
4558 index_read is called to start a scan of an index. The find_flag defines
4559 the semantics of the scan. These flags are defined in
4560 include/my_base.h
4561 index_read_idx is the same but also initializes index before calling doing
4562 the same thing as index_read. Thus it is similar to index_init followed
4563 by index_read. This is also how we implement it.
4564
4565 index_read/index_read_idx does also return the first row. Thus for
4566 key lookups, the index_read will be the only call to the handler in
4567 the index scan.
4568
4569 index_init initializes an index before using it and index_end does
4570 any end processing needed.
4571
4572 Methods:
4573 index_read_map()
4574 index_init()
4575 index_end()
4576 index_read_idx_map()
4577 index_next()
4578 index_prev()
4579 index_first()
4580 index_last()
4581 index_next_same()
4582 index_read_last_map()
4583 read_range_first()
4584 read_range_next()
4585
4586 -------------------------------------------------------------------------
4587 MODULE information calls
4588 -------------------------------------------------------------------------
4589 This calls are used to inform the handler of specifics of the ongoing
4590 scans and other actions. Most of these are used for optimisation
4591 purposes.
4592
4593 Methods:
4594 info()
4595 get_dynamic_partition_info
4596 extra()
4597 extra_opt()
4598 reset()
4599
4600 -------------------------------------------------------------------------
4601 MODULE optimizer support
4602 -------------------------------------------------------------------------
4603 NOTE:
4604 One important part of the public handler interface that is not depicted in
4605 the methods is the attribute records which is defined in the base class.
4606 This is looked upon directly and is set by calling info(HA_STATUS_INFO) ?
4607
4608 Methods:
4609 min_rows_for_estimate()
4610 get_biggest_used_partition()
4611 scan_time()
4612 read_time()
4613 records_in_range()
4614 estimate_rows_upper_bound()
4615 records()
4616
4617 -------------------------------------------------------------------------
4618 MODULE print messages
4619 -------------------------------------------------------------------------
4620 This module contains various methods that returns text messages for
4621 table types, index type and error messages.
4622
4623 Methods:
4624 table_type()
4625 get_row_type()
4626 print_error()
4627 get_error_message()
4628
4629 -------------------------------------------------------------------------
4630 MODULE handler characteristics
4631 -------------------------------------------------------------------------
4632 This module contains a number of methods defining limitations and
4633 characteristics of the handler (see also documentation regarding the
4634 individual flags).
4635
4636 Methods:
4637 table_flags()
4638 index_flags()
4639 min_of_the_max_uint()
4640 max_supported_record_length()
4641 max_supported_keys()
4642 max_supported_key_parts()
4643 max_supported_key_length()
4644 max_supported_key_part_length()
4645 low_byte_first()
4646 extra_rec_buf_length()
4647 min_record_length(uint options)
4648 primary_key_is_clustered()
4649 ha_key_alg get_default_index_algorithm()
4650 is_index_algorithm_supported()
4651
4652 -------------------------------------------------------------------------
4653 MODULE compare records
4654 -------------------------------------------------------------------------
4655 cmp_ref checks if two references are the same. For most handlers this is
4656 a simple memcmp of the reference. However some handlers use primary key
4657 as reference and this can be the same even if memcmp says they are
4658 different. This is due to character sets and end spaces and so forth.
4659
4660 Methods:
4661 cmp_ref()
4662
4663 -------------------------------------------------------------------------
4664 MODULE auto increment
4665 -------------------------------------------------------------------------
4666 This module is used to handle the support of auto increments.
4667
4668 This variable in the handler is used as part of the handler interface
4669 It is maintained by the parent handler object and should not be
4670 touched by child handler objects (see handler.cc for its use).
4671
4672 Methods:
4673 get_auto_increment()
4674 release_auto_increment()
4675
4676 -------------------------------------------------------------------------
4677 MODULE initialize handler for HANDLER call
4678 -------------------------------------------------------------------------
4679 This method is a special InnoDB method called before a HANDLER query.
4680
4681 Methods:
4682 init_table_handle_for_HANDLER()
4683
4684 -------------------------------------------------------------------------
4685 MODULE fulltext index
4686 -------------------------------------------------------------------------
4687 Fulltext index support.
4688
4689 Methods:
4690 ft_init_ext_with_hints()
4691 ft_init()
4692 ft_init_ext()
4693 ft_read()
4694
4695 -------------------------------------------------------------------------
4696 MODULE in-place ALTER TABLE
4697 -------------------------------------------------------------------------
4698 Methods for in-place ALTER TABLE support (implemented by InnoDB and NDB).
4699
4700 Methods:
4701 check_if_supported_inplace_alter()
4702 prepare_inplace_alter_table()
4703 inplace_alter_table()
4704 commit_inplace_alter_table()
4705 notify_table_changed()
4706
4707 -------------------------------------------------------------------------
4708 MODULE tablespace support
4709 -------------------------------------------------------------------------
4710 Methods:
4711 discard_or_import_tablespace()
4712
4713 -------------------------------------------------------------------------
4714 MODULE administrative DDL
4715 -------------------------------------------------------------------------
4716 Methods:
4717 optimize()
4718 analyze()
4719 check()
4720 repair()
4721 check_and_repair()
4722 auto_repair()
4723 is_crashed()
4724 check_for_upgrade()
4725 checksum()
4726 assign_to_keycache()
4727
4728 -------------------------------------------------------------------------
4729 MODULE enable/disable indexes
4730 -------------------------------------------------------------------------
4731 Enable/Disable Indexes are only supported by HEAP and MyISAM.
4732
4733 Methods:
4734 disable_indexes()
4735 enable_indexes()
4736 indexes_are_disabled()
4737
4738 -------------------------------------------------------------------------
4739 MODULE append_create_info
4740 -------------------------------------------------------------------------
4741 Only used by MyISAM MERGE tables.
4742
4743 Methods:
4744 append_create_info()
4745
4746 -------------------------------------------------------------------------
4747 MODULE partitioning specific handler API
4748 -------------------------------------------------------------------------
4749 Methods:
4750 get_partition_handler()
4751*/
4752
4753class handler {
4754 friend class Partition_handler;
4755
4756 public:
4758 using Blob_context = void *;
4759
4760 protected:
4761 TABLE_SHARE *table_share; /* The table definition */
4762 TABLE *table; /* The current open table */
4763 Table_flags cached_table_flags{0}; /* Set on init() and open() */
4764
4766
4767 public:
4768 handlerton *ht; /* storage engine of this handler */
4769 /** Pointer to current row */
4771 /** Pointer to duplicate row */
4773
4775
4776 /* MultiRangeRead-related members: */
4777 range_seq_t mrr_iter; /* Iterator to traverse the range sequence */
4778 RANGE_SEQ_IF mrr_funcs; /* Range sequence traversal functions */
4779 HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
4780 uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
4781 /* true <=> source MRR ranges and the output are ordered */
4783
4784 /* true <=> we're currently traversing a range in mrr_cur_range. */
4786 /* Current range (the one we're now returning rows from) */
4788
4789 /*
4790 The direction of the current range or index scan. This is used by
4791 the ICP implementation to determine if it has reached the end
4792 of the current range.
4793 */
4795
4796 private:
4797 Record_buffer *m_record_buffer = nullptr; ///< Buffer for multi-row reads.
4798 /*
4799 Storage space for the end range value. Should only be accessed using
4800 the end_range pointer. The content is invalid when end_range is NULL.
4801 */
4805
4806 /**
4807 Pointer to the handler of the table in the primary storage engine,
4808 if this handler represents a table in a secondary storage engine.
4809 */
4811
4812 protected:
4815 /*
4816 true <=> the engine guarantees that returned records are within the range
4817 being scanned.
4818 */
4820
4821 public:
4822 /**
4823 End value for a range scan. If this is NULL the range scan has no
4824 end value. Should also be NULL when there is no ongoing range scan.
4825 Used by the read_range() functions and also evaluated by pushed
4826 index conditions.
4827 */
4829 /**
4830 Flag which tells if #end_range contains a virtual generated column.
4831 The content is invalid when #end_range is @c nullptr.
4832 */
4834 uint errkey; /* Last dup key */
4837 /** Length of ref (1-8 or the clustered key length) */
4840 enum { NONE = 0, INDEX, RND, SAMPLING } inited;
4841 bool implicit_emptied; /* Can be !=0 only if HEAP */
4843
4845 uint pushed_idx_cond_keyno; /* The index which the above condition is for */
4846
4847 /**
4848 next_insert_id is the next value which should be inserted into the
4849 auto_increment column: in a inserting-multi-row statement (like INSERT
4850 SELECT), for the first row where the autoinc value is not specified by the
4851 statement, get_auto_increment() called and asked to generate a value,
4852 next_insert_id is set to the next value, then for all other rows
4853 next_insert_id is used (and increased each time) without calling
4854 get_auto_increment().
4855 */
4857 /**
4858 insert id for the current row (*autogenerated*; if not
4859 autogenerated, it's 0).
4860 At first successful insertion, this variable is stored into
4861 THD::first_successful_insert_id_in_cur_stmt.
4862 */
4864 /**
4865 Interval returned by get_auto_increment() and being consumed by the
4866 inserter.
4867 */
4869 /**
4870 Number of reserved auto-increment intervals. Serves as a heuristic
4871 when we have no estimation of how many records the statement will insert:
4872 the more intervals we have reserved, the bigger the next one. Reset in
4873 handler::ha_release_auto_increment().
4874 */
4876
4877 /**
4878 Instrumented table associated with this handler.
4879 */
4881
4882 std::mt19937 *m_random_number_engine{nullptr};
4884
4885 private:
4886 /** Internal state of the batch instrumentation. */
4888 /** Batch mode not used. */
4890 /** Batch mode used, before first table io. */
4892 /** Batch mode used, after first table io. */
4895 /**
4896 Batch mode state.
4897 @sa start_psi_batch_mode.
4898 @sa end_psi_batch_mode.
4899 */
4901 /**
4902 The number of rows in the batch.
4903 @sa start_psi_batch_mode.
4904 @sa end_psi_batch_mode.
4905 */
4907 /**
4908 The current event in a batch.
4909 @sa start_psi_batch_mode.
4910 @sa end_psi_batch_mode.
4911 */
4913 /**
4914 Storage for the event in a batch.
4915 @sa start_psi_batch_mode.
4916 @sa end_psi_batch_mode.
4917 */
4919
4920 public:
4921 void unbind_psi();
4922 void rebind_psi();
4923 /**
4924 Put the handler in 'batch' mode when collecting
4925 table io instrumented events.
4926 When operating in batch mode:
4927 - a single start event is generated in the performance schema.
4928 - all table io performed between @c start_psi_batch_mode
4929 and @c end_psi_batch_mode is not instrumented:
4930 the number of rows affected is counted instead in @c m_psi_numrows.
4931 - a single end event is generated in the performance schema
4932 when the batch mode ends with @c end_psi_batch_mode.
4933 */
4934 void start_psi_batch_mode();
4935 /** End a batch started with @c start_psi_batch_mode. */
4936 void end_psi_batch_mode();
4937 /**
4938 If a PSI batch was started, turn if off.
4939 @returns true if it was started.
4940 */
4942 const bool rc = m_psi_batch_mode;
4943 if (rc) end_psi_batch_mode();
4944 return rc;
4945 }
4946
4947 private:
4948 /**
4949 The lock type set by when calling::ha_external_lock(). This is
4950 propagated down to the storage engine. The reason for also storing
4951 it here, is that when doing MRR we need to create/clone a second handler
4952 object. This cloned handler object needs to know about the lock_type used.
4953 */
4955 /**
4956 Pointer where to store/retrieve the Handler_share pointer.
4957 For non partitioned handlers this is &TABLE_SHARE::ha_share.
4958 */
4960
4961 /**
4962 Some non-virtual ha_* functions, responsible for reading rows,
4963 like ha_rnd_pos(), must ensure that virtual generated columns are
4964 calculated before they return. For that, they should set this
4965 member to true at their start, and check it before they return: if
4966 the member is still true, it means they should calculate; if it's
4967 false, it means the calculation has been done by some called
4968 lower-level function and does not need to be re-done (which is why
4969 we need this status flag: to avoid redundant calculations, for
4970 performance).
4971
4972 Note that when updating generated fields, the NULL row status in
4973 the underlying TABLE objects matter, so be sure to reset them if needed!
4974 */
4976
4977 /* Filter row ids to weed out duplicates when multi-valued index is used */
4979
4980 public:
4981 handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
4982 : table_share(share_arg),
4983 table(nullptr),
4985 ht(ht_arg),
4986 ref(nullptr),
4992 ref_length(sizeof(my_off_t)),
4994 inited(NONE),
4995 implicit_emptied(false),
4999 next_insert_id(0),
5002 m_psi(nullptr),
5004 m_psi_numrows(0),
5006 m_lock_type(F_UNLCK),
5009 m_unique(nullptr) {
5010 DBUG_PRINT("info", ("handler created F_UNLCK %d F_RDLCK %d F_WRLCK %d",
5011 F_UNLCK, F_RDLCK, F_WRLCK));
5012 }
5013
5014 virtual ~handler(void) {
5015 assert(m_psi == nullptr);
5017 assert(m_psi_locker == nullptr);
5018 assert(m_lock_type == F_UNLCK);
5019 assert(inited == NONE);
5020 }
5021
5022 /**
5023 Return extra handler specific text for EXPLAIN.
5024 */
5025 virtual std::string explain_extra() const { return ""; }
5026
5027 /*
5028 @todo reorganize functions, make proper public/protected/private qualifiers
5029 */
5030 virtual handler *clone(const char *name, MEM_ROOT *mem_root);
5031 /** This is called after create to allow us to set up cached variables */
5033 /* ha_ methods: public wrappers for private virtual API */
5034
5035 /**
5036 Set a record buffer that the storage engine can use for multi-row reads.
5037 The buffer has to be provided prior to the first read from an index or a
5038 table.
5039
5040 @param buffer the buffer to use for multi-row reads
5041 */
5043
5044 /**
5045 Get the record buffer that was set with ha_set_record_buffer().
5046
5047 @return the buffer to use for multi-row reads, or nullptr if there is none
5048 */
5050
5051 /**
5052 Does this handler want to get a Record_buffer for multi-row reads
5053 via the ha_set_record_buffer() function? And if so, what is the
5054 maximum number of records to allocate space for in the buffer?
5055
5056 Storage engines that support using a Record_buffer should override
5057 handler::is_record_buffer_wanted().
5058
5059 @param[out] max_rows gets set to the maximum number of records to
5060 allocate space for in the buffer if the function
5061 returns true
5062
5063 @retval true if the handler would like a Record_buffer
5064 @retval false if the handler does not want a Record_buffer
5065 */
5066 bool ha_is_record_buffer_wanted(ha_rows *const max_rows) const {
5067 return is_record_buffer_wanted(max_rows);
5068 }
5069
5070 int ha_open(TABLE *table, const char *name, int mode, int test_if_locked,
5071 const dd::Table *table_def);
5072 int ha_close(void);
5073 int ha_index_init(uint idx, bool sorted);
5074 int ha_index_end();
5075 int ha_rnd_init(bool scan);
5076 int ha_rnd_end();
5077 int ha_rnd_next(uchar *buf);
5078 // See the comment on m_update_generated_read_fields.
5079 int ha_rnd_pos(uchar *buf, uchar *pos);
5080 int ha_index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
5081 enum ha_rkey_function find_flag);
5083 key_part_map keypart_map);
5084 int ha_index_read_idx_map(uchar *buf, uint index, const uchar *key,
5085 key_part_map keypart_map,
5086 enum ha_rkey_function find_flag);
5087 int ha_index_next(uchar *buf);
5088 int ha_index_prev(uchar *buf);
5089 int ha_index_first(uchar *buf);
5090 int ha_index_last(uchar *buf);
5091 int ha_index_next_same(uchar *buf, const uchar *key, uint keylen);
5092 int ha_reset();
5093 /* this is necessary in many places, e.g. in HANDLER command */
5095 return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
5096 }
5097 /**
5098 The cached_table_flags is set at ha_open and ha_external_lock
5099 */
5101 /**
5102 These functions represent the public interface to *users* of the
5103 handler class, hence they are *not* virtual. For the inheritance
5104 interface, see the (private) functions write_row(), update_row(),
5105 and delete_row() below.
5106 */
5107 int ha_external_lock(THD *thd, int lock_type);
5108 int ha_write_row(uchar *buf);
5109 /**
5110 Update the current row.
5111
5112 @param old_data the old contents of the row
5113 @param new_data the new contents of the row
5114 @return error status (zero on success, HA_ERR_* error code on error)
5115 */
5116 int ha_update_row(const uchar *old_data, uchar *new_data);
5117 int ha_delete_row(const uchar *buf);
5119
5120 int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
5121 /** to be actually called to get 'check()' functionality*/
5122 int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
5123 int ha_check_foreign_constraints(THD *thd, size_t n_threads);
5124 int ha_repair(THD *thd, HA_CHECK_OPT *check_opt);
5125 void ha_start_bulk_insert(ha_rows rows);
5126 int ha_end_bulk_insert();
5127 int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
5128 uint *dup_key_found);
5129 int ha_delete_all_rows();
5131 int ha_optimize(THD *thd, HA_CHECK_OPT *check_opt);
5132 int ha_analyze(THD *thd, HA_CHECK_OPT *check_opt);
5133 bool ha_check_and_repair(THD *thd);
5134 int ha_disable_indexes(uint mode);
5135 int ha_enable_indexes(uint mode);
5137 int ha_rename_table(const char *from, const char *to,
5138 const dd::Table *from_table_def, dd::Table *to_table_def);
5139 int ha_delete_table(const char *name, const dd::Table *table_def);
5140 void ha_drop_table(const char *name);
5141
5142 int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info,
5144
5145 int ha_load_table(const TABLE &table, bool *skip_metadata_update);
5146
5147 int ha_unload_table(const char *db_name, const char *table_name,
5148 bool error_if_not_loaded);
5149
5150 /**
5151 Initializes a parallel scan. It creates a parallel_scan_ctx that has to
5152 be used across all parallel_scan methods. Also, gets the number of
5153 threads that would be spawned for parallel scan.
5154 @param[out] scan_ctx The parallel scan context.
5155 @param[out] num_threads Number of threads used for the scan.
5156 @param[in] use_reserved_threads true if reserved threads are to be used
5157 if we exhaust the max cap of number of
5158 parallel read threads that can be
5159 spawned at a time
5160 @param[in] max_desired_threads Maximum number of desired scan threads;
5161 passing 0 has no effect, it is ignored.
5162 @return error code
5163 @retval 0 on success
5164 */
5165 virtual int parallel_scan_init(void *&scan_ctx [[maybe_unused]],
5166 size_t *num_threads [[maybe_unused]],
5167 bool use_reserved_threads [[maybe_unused]],
5168 size_t max_desired_threads [[maybe_unused]]) {
5169 return 0;
5170 }
5171
5172 /**
5173 This callback is called by each parallel load thread at the beginning of
5174 the parallel load for the adapter scan.
5175 @param cookie The cookie for this thread
5176 @param ncols Number of columns in each row
5177 @param row_len The size of a row in bytes
5178 @param col_offsets An array of size ncols, where each element represents
5179 the offset of a column in the row data. The memory of
5180 this array belongs to the caller and will be free-ed
5181 after the pload_end_cbk call.
5182 @param null_byte_offsets An array of size ncols, where each element
5183 represents the offset of a column in the row data. The
5184 memory of this array belongs to the caller and will be
5185 free-ed after the pload_end_cbk call.
5186 @param null_bitmasks An array of size ncols, where each element
5187 represents the bitmask required to get the null bit. The
5188 memory of this array belongs to the caller and will be
5189 free-ed after the pload_end_cbk call.
5190 */
5191 using Load_init_cbk = std::function<bool(
5192 void *cookie, ulong ncols, ulong row_len, const ulong *col_offsets,
5193 const ulong *null_byte_offsets, const ulong *null_bitmasks)>;
5194
5195 /**
5196 This callback is called by each parallel load thread when processing
5197 of rows is required for the adapter scan.
5198 @param[in] cookie The cookie for this thread
5199 @param[in] nrows The nrows that are available
5200 @param[in] rowdata The mysql-in-memory row data buffer. This is a
5201 memory buffer for nrows records. The length of each record is fixed and
5202 communicated via Load_init_cbk
5203 @param[in] partition_id Partition id if it's a partitioned table, else
5204 std::numeric_limits<uint64_t>::max()
5205 @returns true if there is an error, false otherwise.
5206 */
5207 using Load_cbk = std::function<bool(void *cookie, uint nrows, void *rowdata,
5208 uint64_t partition_id)>;
5209
5210 /**
5211 This callback is called by each parallel load thread when processing
5212 of rows has ended for the adapter scan.
5213 @param[in] cookie The cookie for this thread
5214 */
5215 using Load_end_cbk = std::function<void(void *cookie)>;
5216
5217 /**
5218 Run the parallel read of data.
5219 @param[in] scan_ctx Scan context of the parallel read.
5220 @param[in,out] thread_ctxs Caller thread contexts.
5221 @param[in] init_fn Callback called by each parallel load
5222 thread at the beginning of the parallel load.
5223 @param[in] load_fn Callback called by each parallel load
5224 thread when processing of rows is required.
5225 @param[in] end_fn Callback called by each parallel load
5226 thread when processing of rows has ended.
5227 @return error code
5228 @retval 0 on success
5229 */
5230 virtual int parallel_scan(void *scan_ctx [[maybe_unused]],
5231 void **thread_ctxs [[maybe_unused]],
5232 Load_init_cbk init_fn [[maybe_unused]],
5233 Load_cbk load_fn [[maybe_unused]],
5234 Load_end_cbk end_fn [[maybe_unused]]) {
5235 return 0;
5236 }
5237
5238 /**
5239 End of the parallel scan.
5240 @param[in] scan_ctx A scan context created by parallel_scan_init.
5241 */
5242 virtual void parallel_scan_end(void *scan_ctx [[maybe_unused]]) { return; }
5243
5244 /** Check if the table is ready for bulk load
5245 @param[in] thd user session
5246 @return true iff bulk load can be done on the table. */
5247 virtual bool bulk_load_check(THD *thd [[maybe_unused]]) const {
5248 return false;
5249 }
5250
5251 /** Check whether all records in the child table satisfy the foreign key
5252 constraints.
5253 @param[in] thd user session.
5254 @param[in] n_threads number of threads to use.
5255 @return true iff foreign key constraints are satisfied. */
5256 virtual int check_foreign_constraints(THD *thd [[maybe_unused]],
5257 size_t n_threads
5258 [[maybe_unused]]) const {
5259 return false;
5260 }
5261
5262 /** Used during bulk load on a non-empty table, called after the CSV file
5263 input is exhausted and we need to copy any existing data from the original
5264 table to the duplicated one.
5265 @param[in] load_ctx SE load context
5266 @param[in] thread_idx loader thread index
5267 @param[in] wait_cbk stat callbacks.
5268 @return 0 if successful, HA_ERR_GENERIC otherwise. */
5269 virtual int bulk_load_copy_existing_data(void *load_ctx [[maybe_unused]],
5270 size_t thread_idx [[maybe_unused]],
5272 [[maybe_unused]]) const {
5273 return 0;
5274 }
5275
5276 /** Generates a temporary table name to be used for table duplication during
5277 bulk load.
5278 @return a temporary table name. */
5279 virtual std::string bulk_load_generate_temporary_table_name() const {
5280 return "";
5281 }
5282
5283 /** Sets the source table data (table name and key range boundaries) for all
5284 loaders.
5285 @param[in,out] load_ctx SE load context
5286 @param[in] source_table_data vector containing the source table data
5287 @return true if successful, false otherwise. */
5289 void *load_ctx [[maybe_unused]],
5290 const std::vector<Bulk_load::Source_table_data> &source_table_data
5291 [[maybe_unused]]) const {
5292 return true;
5293 }
5294
5295 /** Get the row ID range of the table that we're bulk loading into. Only used
5296 when the table has a generated clustered index and is not empty.
5297 @param[out] min Minimum ROW_ID in table
5298 @param[out] max Maximum ROW_ID in table
5299 @return true if successful, false otherwise. */
5300 virtual bool bulk_load_get_row_id_range(size_t &min [[maybe_unused]],
5301 size_t &max [[maybe_unused]]) const {
5302 return false;
5303 }
5304
5305 /** Determines whether the table this handler was opened on is empty.
5306 @return true if table empty. */
5307 virtual bool is_table_empty() const { return false; }
5308
5309 /** Get the total memory available for bulk load in SE.
5310 @param[in] thd user session
5311 @return available memory for bulk load */
5312 virtual size_t bulk_load_available_memory(THD *thd [[maybe_unused]]) const {
5313 return 0;
5314 }
5315
5316 /** Begin parallel bulk data load to the table.
5317 @param[in] thd user session
5318 @param[in] data_size total data size to load
5319 @param[in] memory memory to be used by SE
5320 @param[in] num_threads number of concurrent threads used for load.
5321 @return bulk load context or nullptr if unsuccessful. */
5322 virtual void *bulk_load_begin(THD *thd [[maybe_unused]],
5323 size_t keynr [[maybe_unused]],
5324 size_t data_size [[maybe_unused]],
5325 size_t memory [[maybe_unused]],
5326 size_t num_threads [[maybe_unused]]) {
5327 return nullptr;
5328 }
5329
5330 /** Execute bulk load operation. To be called by each of the concurrent
5331 threads idenified by thread index.
5332 @param[in,out] thd user session
5333 @param[in,out] load_ctx load execution context
5334 @param[in] thread_idx index of the thread executing
5335 @param[in] rows rows to be loaded to the table
5336 @return error code. */
5337 virtual int bulk_load_execute(THD *thd [[maybe_unused]],
5338 void *load_ctx [[maybe_unused]],
5339 size_t thread_idx [[maybe_unused]],
5340 const Rows_mysql &rows [[maybe_unused]],
5342 [[maybe_unused]]) {
5343 return HA_ERR_UNSUPPORTED;
5344 }
5345
5346 /** Open a blob for write operation.
5347 @param[in,out] thd user session
5348 @param[in,out] load_ctx load execution context
5349 @param[in] thread_idx index of the thread executing
5350 @param[out] blob_ctx a blob context
5351 @param[out] blobref a blob reference to be placed in the record.
5352 @return 0 on success, error code on failure */
5353 virtual int open_blob(THD *thd [[maybe_unused]],
5354 void *load_ctx [[maybe_unused]],
5355 size_t thread_idx [[maybe_unused]],
5356 Blob_context &blob_ctx [[maybe_unused]],
5357 unsigned char *blobref [[maybe_unused]]) {
5358 return HA_ERR_UNSUPPORTED;
5359 }
5360
5361 /** Write to a blob
5362 @param[in,out] thd user session
5363 @param[in,out] load_ctx load execution context
5364 @param[in] thread_idx index of the thread executing
5365 @param[in] blob_ctx a blob context
5366 @param[in] data data to be written to blob.
5367 @param[in] data_len length of data to be written in bytes.
5368 @return 0 on success, error code on failure */
5369 virtual int write_blob(THD *thd [[maybe_unused]],
5370 void *load_ctx [[maybe_unused]],
5371 size_t thread_idx [[maybe_unused]],
5372 Blob_context blob_ctx [[maybe_unused]],
5373 unsigned char *blobref [[maybe_unused]],
5374 const unsigned char *data [[maybe_unused]],
5375 size_t data_len [[maybe_unused]]) {
5376 return HA_ERR_UNSUPPORTED;
5377 }
5378
5379 /** Close the blob
5380 @param[in,out] thd user session
5381 @param[in,out] load_ctx load execution context
5382 @param[in] thread_idx index of the thread executing
5383 @param[in] blob_ctx a blob context
5384 @return 0 on success, error code on failure */
5385 virtual int close_blob(THD *thd [[maybe_unused]],
5386 void *load_ctx [[maybe_unused]],
5387 size_t thread_idx [[maybe_unused]],
5388 Blob_context blob_ctx [[maybe_unused]],
5389 unsigned char *blobref [[maybe_unused]]) {
5390 return HA_ERR_UNSUPPORTED;
5391 }
5392
5393 /** End bulk load operation. Must be called after all execution threads have
5394 completed. Must be called even if the bulk load execution failed.
5395 @param[in,out] thd user session
5396 @param[in,out] load_ctx load execution context
5397 @param[in] is_error true, if bulk load execution have failed
5398 @return error code. */
5399 virtual int bulk_load_end(THD *thd [[maybe_unused]],
5400 void *load_ctx [[maybe_unused]],
5401 bool is_error [[maybe_unused]]) {
5402 return false;
5403 }
5404
5405 /**
5406 Submit a dd::Table object representing a core DD table having
5407 hardcoded data to be filled in by the DDSE. This function can be
5408 used for retrieving the hard coded SE private data for the
5409 mysql.dd_properties table, before creating or opening it, or for
5410 retrieving the hard coded SE private data for a core table,
5411 before creating or opening them.
5412
5413 @param dd_table [in,out] A dd::Table object representing
5414 a core DD table.
5415 @param reset Reset counters.
5416
5417 @retval true An error occurred.
5418 @retval false Success - no errors.
5419 */
5420
5421 bool ha_get_se_private_data(dd::Table *dd_table, bool reset);
5422
5425 virtual void print_error(int error, myf errflag);
5426 virtual bool get_error_message(int error, String *buf);
5427 uint get_dup_key(int error);
5428 /**
5429 Retrieves the names of the table and the key for which there was a
5430 duplicate entry in the case of HA_ERR_FOREIGN_DUPLICATE_KEY.
5431
5432 If any of the table or key name is not available this method will return
5433 false and will not change any of child_table_name or child_key_name.
5434
5435 @param [out] child_table_name Table name
5436 @param [in] child_table_name_len Table name buffer size
5437 @param [out] child_key_name Key name
5438 @param [in] child_key_name_len Key name buffer size
5439
5440 @retval true table and key names were available
5441 and were written into the corresponding
5442 out parameters.
5443 @retval false table and key names were not available,
5444 the out parameters were not touched.
5445 */
5446 virtual bool get_foreign_dup_key(char *child_table_name,
5447 uint child_table_name_len,
5448 char *child_key_name,
5449 uint child_key_name_len);
5450 /**
5451 Change the internal TABLE_SHARE pointer.
5452
5453 @param table_arg TABLE object
5454 @param share New share to use
5455
5456 @note Is used in error handling in ha_delete_table.
5457 */
5458
5459 virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share) {
5460 table = table_arg;
5462 }
5463 const TABLE_SHARE *get_table_share() const { return table_share; }
5464 const TABLE *get_table() const { return table; }
5465
5466 /* Estimates calculation */
5467
5468 /**
5469 @deprecated This function is deprecated and will be removed in a future
5470 version. Use table_scan_cost() instead.
5471 */
5472
5473 virtual double scan_time() {
5474 return ulonglong2double(stats.data_file_length) / IO_SIZE + 2;
5475 }
5476
5477 /**
5478 The cost of reading a set of ranges from the table using an index
5479 to access it.
5480
5481 @deprecated This function is deprecated and will be removed in a future
5482 version. Use read_cost() instead.
5483
5484 @param index The index number.
5485 @param ranges The number of ranges to be read.
5486 @param rows Total number of rows to be read.
5487
5488 This method can be used to calculate the total cost of scanning a table
5489 using an index by calling it using read_time(index, 1, table_size).
5490 */
5491
5492 virtual double read_time(uint index [[maybe_unused]], uint ranges,
5493 ha_rows rows) {
5494 return rows2double(ranges + rows);
5495 }
5496
5497 /**
5498 @deprecated This function is deprecated and will be removed in a future
5499 version. Use index_scan_cost() instead.
5500 */
5501
5502 virtual double index_only_read_time(uint keynr, double records);
5503
5504 /**
5505 Cost estimate for doing a complete table scan.
5506
5507 @note For this version it is recommended that storage engines continue
5508 to override scan_time() instead of this function.
5509
5510 @returns the estimated cost
5511 */
5512
5514
5515 /**
5516 Cost estimate for reading a number of ranges from an index.
5517
5518 The cost estimate will only include the cost of reading data that
5519 is contained in the index. If the records need to be read, use
5520 read_cost() instead.
5521
5522 @note The ranges parameter is currently ignored and is not taken
5523 into account in the cost estimate.
5524
5525 @note For this version it is recommended that storage engines continue
5526 to override index_only_read_time() instead of this function.
5527
5528 @param index the index number
5529 @param ranges the number of ranges to be read
5530 @param rows total number of rows to be read
5531
5532 @returns the estimated cost
5533 */
5534
5535 virtual Cost_estimate index_scan_cost(uint index, double ranges, double rows);
5536
5537 /**
5538 Cost estimate for reading a set of ranges from the table using an index
5539 to access it.
5540
5541 @note For this version it is recommended that storage engines continue
5542 to override read_time() instead of this function.
5543
5544 @param index the index number
5545 @param ranges the number of ranges to be read
5546 @param rows total number of rows to be read
5547
5548 @returns the estimated cost
5549 */
5550
5551 virtual Cost_estimate read_cost(uint index, double ranges, double rows);
5552
5553 /**
5554 Cost estimate for doing a number of non-sequentially accesses
5555 against the storage engine. Such accesses can be either number
5556 of rows to read, or number of disk pages to access.
5557 Each handler implementation is free to interpret that as best
5558 suited, depending on what is the dominating cost for that
5559 storage engine.
5560
5561 This method is mainly provided as a temporary workaround for
5562 bug#33317872, where we fix problems caused by calling
5563 Cost_model::page_read_cost() directly from the optimizer.
5564 That should be avoided, as it introduced assumption about all
5565 storage engines being disk-page based, and having a 'page' cost.
5566 Furthermore, this page cost was even compared against read_cost(),
5567 which was computed with an entirely different algorithm, and thus
5568 could not be compared.
5569
5570 The default implementation still call Cost_model::page_read_cost(),
5571 thus behaving just as before. However, handler implementation may
5572 override it to call handler::read_cost() instead(), which probably
5573 will be more correct. (If a page_read_cost should be included
5574 in the cost estimate, that should preferable be done inside
5575 each read_cost() implementation)
5576
5577 Longer term we should consider to remove all page_read_cost()
5578 usage from the optimizer itself, making this method obsolete.
5579
5580 @param index the index number
5581 @param reads the number of accesses being made
5582
5583 @returns the estimated cost
5584 */
5585 virtual double page_read_cost(uint index, double reads);
5586
5587 /**
5588 Provide an upper cost-limit of doing a specified number of
5589 seek-and-read key lookups. This need to be comparable and
5590 calculated with the same 'metric' as page_read_cost.
5591
5592 @param reads the number of rows read in the 'worst' case.
5593
5594 @returns the estimated cost
5595 */
5596 virtual double worst_seek_times(double reads);
5597
5598 /**
5599 Return an estimate on the amount of memory the storage engine will
5600 use for caching data in memory. If this is unknown or the storage
5601 engine does not cache data in memory -1 is returned.
5602 */
5603 virtual longlong get_memory_buffer_size() const { return -1; }
5604
5605 /**
5606 Return an estimate of how much of the table that is currently stored
5607 in main memory.
5608
5609 This estimate should be the fraction of the table that currently
5610 is available in a main memory buffer. The estimate should be in the
5611 range from 0.0 (nothing in memory) to 1.0 (entire table in memory).
5612
5613 @return The fraction of the table in main memory buffer
5614 */
5615
5616 double table_in_memory_estimate() const;
5617
5618 /**
5619 Return an estimate of how much of the index that is currently stored
5620 in main memory.
5621
5622 This estimate should be the fraction of the index that currently
5623 is available in a main memory buffer. The estimate should be in the
5624 range from 0.0 (nothing in memory) to 1.0 (entire index in memory).
5625
5626 @param keyno the index to get an estimate for
5627
5628 @return The fraction of the index in main memory buffer
5629 */
5630
5631 double index_in_memory_estimate(uint keyno) const;
5632
5633 /**
5634 Initialize sampling.
5635
5636 @param[out] scan_ctx A scan context created by this method that has to be
5637 used in sample_next
5638 @param[in] sampling_percentage percentage of records that need to be
5639 sampled
5640 @param[in] sampling_seed random seed that the random generator will
5641 use
5642 @param[in] sampling_method sampling method to be used; currently only
5643 SYSTEM sampling is supported
5644 @param[in] tablesample true if the sampling is for tablesample
5645
5646 @return 0 for success, else one of the HA_xxx values in case of error.
5647 */
5648 int ha_sample_init(void *&scan_ctx, double sampling_percentage,
5649 int sampling_seed, enum_sampling_method sampling_method,
5650 const bool tablesample);
5651
5652 /**
5653 Get the next record for sampling.
5654
5655 @param[in] scan_ctx Scan context of the sampling
5656 @param[in] buf buffer to place the read record
5657
5658 @return 0 for success, else one of the HA_xxx values in case of error.
5659 */
5660 int ha_sample_next(void *scan_ctx, uchar *buf);
5661
5662 /**
5663 End sampling.
5664
5665 @param[in] scan_ctx Scan context of the sampling
5666
5667 @return 0 for success, else one of the HA_xxx values in case of error.
5668 */
5669 int ha_sample_end(void *scan_ctx);
5670
5671 private:
5673
5674 /**
5675 Make a guesstimate for how much of a table or index is in a memory
5676 buffer in the case where the storage engine has not provided any
5677 estimate for this.
5678
5679 @param table_index_size size of the table or index
5680
5681 @return The fraction of the table or index in main memory buffer
5682 */
5683
5684 double estimate_in_memory_buffer(ulonglong table_index_size) const;
5685
5686 public:
5688 uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges,
5689 uint *bufsz, uint *flags, bool *force_default_mrr, Cost_estimate *cost);
5690 virtual ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
5691 uint *bufsz, uint *flags,
5692 Cost_estimate *cost);
5693 virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
5694 uint n_ranges, uint mode,
5696
5697 int ha_multi_range_read_next(char **range_info);
5698
5699 int ha_read_range_first(const key_range *start_key, const key_range *end_key,
5700 bool eq_range, bool sorted);
5701 int ha_read_range_next();
5702
5704 return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0;
5705 }
5706 virtual uint extra_rec_buf_length() const { return 0; }
5707
5708 /**
5709 @brief Determine whether an error can be ignored or not.
5710
5711 @details This method is used to analyze the error to see whether the
5712 error is ignorable or not. Such errors will be reported as warnings
5713 instead of errors for IGNORE statements. This means that the statement
5714 will not abort, but instead continue to the next row.
5715
5716 HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
5717 same thing as HA_ERR_FOUND_DUP_KEY, but can in some cases lead to
5718 a slightly different error message.
5719
5720 @param error error code received from the handler interface (HA_ERR_...)
5721
5722 @return whether the error is ignorable or not
5723 @retval true the error is ignorable
5724 @retval false the error is not ignorable
5725 */
5726
5727 virtual bool is_ignorable_error(int error);
5728
5729 /**
5730 @brief Determine whether an error is fatal or not.
5731
5732 @details This method is used to analyze the error to see whether the
5733 error is fatal or not. A fatal error is an error that will not be
5734 possible to handle with SP handlers and will not be subject to
5735 retry attempts on the slave.
5736
5737 @param error error code received from the handler interface (HA_ERR_...)
5738
5739 @return whether the error is fatal or not
5740 @retval true the error is fatal
5741 @retval false the error is not fatal
5742 */
5743
5744 virtual bool is_fatal_error(int error);
5745
5746 protected:
5747 virtual int multi_range_read_next(char **range_info);
5748
5749 /**
5750 Number of rows in table. If HA_COUNT_ROWS_INSTANT is set, count is
5751 available instantly. Else do a table scan.
5752
5753 @param num_rows [out] num_rows number of rows in table.
5754
5755 @retval 0 for OK, one of the HA_xxx values in case of error.
5756 */
5757 virtual int records(ha_rows *num_rows);
5758
5759 /**
5760 Number of rows in table counted using the secondary index chosen by
5761 optimizer. See comments in optimize_aggregated_query() .
5762
5763 @param num_rows [out] Number of rows in table.
5764 @param index Index chosen by optimizer for counting.
5765
5766 @retval 0 for OK, one of the HA_xxx values in case of error.
5767 */
5768 virtual int records_from_index(ha_rows *num_rows, uint index);
5769
5770 private:
5771 /**
5772 Function will handle the error code from call to records() and
5773 records_from_index().
5774
5775 @param error return code from records() and records_from_index().
5776 @param num_rows Check if it contains HA_POS_ERROR in case error < 0.
5777
5778 @retval 0 for OK, one of the HA_xxx values in case of error.
5779 */
5780 int handle_records_error(int error, ha_rows *num_rows);
5781
5782 public:
5783 /**
5784 Wrapper function to call records() in storage engine.
5785
5786 @param num_rows [out] Number of rows in table.
5787
5788 @retval 0 for OK, one of the HA_xxx values in case of error.
5789 */
5790 int ha_records(ha_rows *num_rows) {
5791 return handle_records_error(records(num_rows), num_rows);
5792 }
5793
5794 /**
5795 Wrapper function to call records_from_index() in storage engine.
5796
5797 @param num_rows [out] Number of rows in table.
5798 @param index Index chosen by optimizer for counting.
5799
5800 @retval 0 for OK, one of the HA_xxx values in case of error.
5801 */
5802 int ha_records(ha_rows *num_rows, uint index) {
5803 return handle_records_error(records_from_index(num_rows, index), num_rows);
5804 }
5805
5806 /**
5807 Return upper bound of current number of records in the table
5808 (max. of how many records one will retrieve when doing a full table scan)
5809 If upper bound is not known, HA_POS_ERROR should be returned as a max
5810 possible upper bound.
5811 */
5813 return stats.records + EXTRA_RECORDS;
5814 }
5815
5816 /**
5817 Get real row type for the table created based on one specified by user,
5818 CREATE TABLE options and SE capabilities.
5819 */
5821 const HA_CREATE_INFO *create_info) const {
5822 return (create_info->table_options & HA_OPTION_COMPRESS_RECORD)
5824 : ((create_info->table_options & HA_OPTION_PACK_RECORD)
5826 : ROW_TYPE_FIXED);
5827 }
5828
5829 /**
5830 Get default key algorithm for SE. It is used when user has not provided
5831 algorithm explicitly or when algorithm specified is not supported by SE.
5832 */
5835 }
5836
5837 /**
5838 Check if SE supports specific key algorithm.
5839
5840 @note This method is never used for FULLTEXT or SPATIAL keys.
5841 We rely on handler::ha_table_flags() to check if such keys
5842 are supported.
5843 */
5844 virtual bool is_index_algorithm_supported(enum ha_key_alg key_alg) const {
5845 return key_alg == HA_KEY_ALG_SE_SPECIFIC;
5846 }
5847
5848 /**
5849 Signal that the table->read_set and table->write_set table maps changed
5850 The handler is allowed to set additional bits in the above map in this
5851 call. Normally the handler should ignore all calls until we have done
5852 a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
5853 as there may be several calls to this routine.
5854 */
5855 virtual void column_bitmaps_signal();
5856 uint get_index(void) const { return active_index; }
5857
5858 /**
5859 @retval false Bulk update used by handler
5860 @retval true Bulk update not used, normal operation used
5861 */
5862 virtual bool start_bulk_update() { return true; }
5863 /**
5864 @retval false Bulk delete used by handler
5865 @retval true Bulk delete not used, normal operation used
5866 */
5867 virtual bool start_bulk_delete() { return true; }
5868 /**
5869 After this call all outstanding updates must be performed. The number
5870 of duplicate key errors are reported in the duplicate key parameter.
5871 It is allowed to continue to the batched update after this call, the
5872 handler has to wait until end_bulk_update with changing state.
5873
5874 @param dup_key_found Number of duplicate keys found
5875
5876 @retval 0 Success
5877 @retval >0 Error code
5878 */
5879 virtual int exec_bulk_update(uint *dup_key_found [[maybe_unused]]) {
5880 assert(false);
5881 return HA_ERR_WRONG_COMMAND;
5882 }
5883 /**
5884 Perform any needed clean-up, no outstanding updates are there at the
5885 moment.
5886 */
5887 virtual void end_bulk_update() { return; }
5888 /**
5889 Execute all outstanding deletes and close down the bulk delete.
5890
5891 @retval 0 Success
5892 @retval >0 Error code
5893 */
5894 virtual int end_bulk_delete() {
5895 assert(false);
5896 return HA_ERR_WRONG_COMMAND;
5897 }
5898
5899 protected:
5900 /**
5901 @brief
5902 Positions an index cursor to the index specified in the handle
5903 ('active_index'). Fetches the row if available. If the key value is null,
5904 begin at the first key of the index.
5905 @returns 0 if success (found a record); non-zero if no record.
5906 */
5907 virtual int index_read_map(uchar *buf, const uchar *key,
5908 key_part_map keypart_map,
5909 enum ha_rkey_function find_flag) {
5910 const uint key_len = calculate_key_len(table, active_index, keypart_map);
5911 return index_read(buf, key, key_len, find_flag);
5912 }
5913 /**
5914 Positions an index cursor to the index specified in argument. Fetches
5915 the row if available. If the key value is null, begin at the first key of
5916 the index.
5917 @sa index_read_map()
5918 */
5919 virtual int index_read_idx_map(uchar *buf, uint index, const uchar *key,
5920 key_part_map keypart_map,
5921 enum ha_rkey_function find_flag);
5922
5923 /*
5924 These methods are used to jump to next or previous entry in the index
5925 scan. There are also methods to jump to first and last entry.
5926 */
5927 /// @see index_read_map().
5928 virtual int index_next(uchar *) { return HA_ERR_WRONG_COMMAND; }
5929
5930 /// @see index_read_map().
5931 virtual int index_prev(uchar *) { return HA_ERR_WRONG_COMMAND; }
5932
5933 /// @see index_read_map().
5934 virtual int index_first(uchar *) { return HA_ERR_WRONG_COMMAND; }
5935
5936 /// @see index_read_map().
5937 virtual int index_last(uchar *) { return HA_ERR_WRONG_COMMAND; }
5938
5939 /// @see index_read_map().
5940 virtual int index_next_same(uchar *buf, const uchar *key, uint keylen);
5941
5942 /**
5943 The following functions works like index_read, but it find the last
5944 row with the current key value or prefix.
5945 @see index_read_map().
5946 */
5947 virtual int index_read_last_map(uchar *buf, const uchar *key,
5948 key_part_map keypart_map) {
5949 const uint key_len = calculate_key_len(table, active_index, keypart_map);
5950 return index_read_last(buf, key, key_len);
5951 }
5952
5953 virtual int read_range_first(const key_range *start_key,
5954 const key_range *end_key, bool eq_range_arg,
5955 bool sorted);
5956 virtual int read_range_next();
5957
5958 public:
5959 /**
5960 Set the end position for a range scan. This is used for checking
5961 for when to end the range scan and by the ICP code to determine
5962 that the next record is within the current range.
5963
5964 @param range The end value for the range scan
5965 @param direction Direction of the range scan
5966 */
5967 void set_end_range(const key_range *range,
5968 enum_range_scan_direction direction);
5970 int compare_key_icp(const key_range *range) const;
5971 int compare_key_in_buffer(const uchar *buf) const;
5972 virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
5973 virtual FT_INFO *ft_init_ext(uint flags, uint inx, String *key);
5975 Ft_hints *hints) {
5976 return ft_init_ext(hints->get_flags(), inx, key);
5977 }
5978 int ha_ft_read(uchar *buf);
5980
5981 protected:
5982 /// @see index_read_map().
5983 virtual int rnd_next(uchar *buf) = 0;
5984 /// @see index_read_map().
5985 virtual int rnd_pos(uchar *buf, uchar *pos) = 0;
5986
5987 virtual int ft_read(uchar *) { return HA_ERR_WRONG_COMMAND; }
5988
5989 public:
5990 /**
5991 This function only works for handlers having
5992 HA_PRIMARY_KEY_REQUIRED_FOR_POSITION set.
5993 It will return the row with the PK given in the record argument.
5994 */
5996 int error;
5998
5999 error = ha_rnd_init(false);
6000 if (error != 0) return error;
6001
6004
6005 ha_rnd_end();
6006 return error;
6007 }
6008
6009 /**
6010 Find number of records in a range.
6011
6012 Given a starting key, and an ending key estimate the number of rows that
6013 will exist between the two. max_key may be empty which in case determine
6014 if start_key matches any rows. Used by optimizer to calculate cost of
6015 using a particular index.
6016
6017 @param inx Index number
6018 @param min_key Start of range
6019 @param max_key End of range
6020
6021 @return Number of rows in range.
6022 */
6023
6024 virtual ha_rows records_in_range(uint inx [[maybe_unused]],
6025 key_range *min_key [[maybe_unused]],
6026 key_range *max_key [[maybe_unused]]) {
6027 return (ha_rows)10;
6028 }
6029 /*
6030 If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, then it sets ref
6031 (reference to the row, aka position, with the primary key given in
6032 the record).
6033 Otherwise it set ref to the current row.
6034 */
6035 virtual void position(const uchar *record) = 0;
6036
6037 /**
6038 General method to gather info from handler
6039
6040 ::info() is used to return information to the optimizer.
6041 SHOW also makes use of this data Another note, if your handler
6042 doesn't proved exact record count, you will probably want to
6043 have the following in your code:
6044 if (records < 2)
6045 records = 2;
6046 The reason is that the server will optimize for cases of only a single
6047 record. If in a table scan you don't know the number of records
6048 it will probably be better to set records to two so you can return
6049 as many records as you need.
6050
6051 Along with records a few more variables you may wish to set are:
6052 records
6053 deleted
6054 data_file_length
6055 index_file_length
6056 delete_length
6057 check_time
6058 Take a look at the public variables in handler.h for more information.
6059 See also my_base.h for a full description.
6060
6061 @param flag Specifies what info is requested
6062 */
6063
6064 virtual int info(uint flag) = 0;
6066 [[maybe_unused]]) {
6067 assert(0);
6068 return 0;
6069 }
6070 /**
6071 Request storage engine to do an extra operation: enable,disable or run some
6072 functionality.
6073
6074 @param operation the operation to perform
6075
6076 @returns
6077 0 on success
6078 error otherwise
6079 */
6080 int ha_extra(enum ha_extra_function operation);
6081
6082 private:
6083 /**
6084 Storage engine specific implementation of ha_extra()
6085
6086 @param operation the operation to perform
6087
6088 @returns
6089 0 on success
6090 error otherwise
6091 */
6092 virtual int extra(enum ha_extra_function operation [[maybe_unused]]) {
6093 return 0;
6094 }
6095
6096 public:
6097 virtual int extra_opt(enum ha_extra_function operation,
6098 ulong cache_size [[maybe_unused]]) {
6099 return extra(operation);
6100 }
6101
6102 /**
6103 Get the handlerton of the storage engine if the SE is capable of
6104 pushing down some of the AccessPath functionality.
6105 (Join, Filter conditions, ... possiby more)
6106
6107 Call the handlerton::push_to_engine() method for performing the
6108 actual pushdown of (parts of) the AccessPath functionality
6109
6110 @returns handlerton* of the SE if it may be capable of
6111 off loading part of the query by calling
6112 handlerton::push_to_engine()
6113
6114 Else, 'nullptr' is returned.
6115 */
6117 return nullptr;
6118 }
6119
6120 /**
6121 Start read (before write) removal on the current table.
6122 @see HA_READ_BEFORE_WRITE_REMOVAL
6123 */
6124 virtual bool start_read_removal(void) {
6125 assert(0);
6126 return false;
6127 }
6128
6129 /**
6130 End read (before write) removal and return the number of rows
6131 really written
6132 @see HA_READ_BEFORE_WRITE_REMOVAL
6133 */
6135 assert(0);
6136 return (ha_rows)0;
6137 }
6138
6139 /**
6140 Normally, when running UPDATE or DELETE queries, we need to wait for other
6141 transactions to release their locks on a given row before we can read it and
6142 potentially update it. However, in READ UNCOMMITTED and READ COMMITTED, we
6143 can ignore these locks if we don't intend to modify the row (e.g., because
6144 it failed a WHERE). This is signaled through enabling “semi-consistent
6145 read”, by calling try_semi_consistent_read(true) (and then setting it back
6146 to false after finishing the query).
6147
6148 If semi-consistent read is enabled, and we are in READ UNCOMMITTED or READ
6149 COMMITTED, the storage engine is permitted to return rows that are locked
6150 and thus un-updatable. If the optimizer doesn't want the row, e.g., because
6151 it got filtered out, it can call unlock_row() as usual. However, if it
6152 intends to update the row, it needs to call was_semi_consistent_read()
6153 before doing so. If was_semi_consistent_read() returns false, the row was
6154 never locked to begin with and can be updated as usual. However, if it
6155 returns 1, it was read optimistically, must be discarded (ie., do not try to
6156 update the row) and must be re-read with locking enabled. The next read call
6157 after was_semi_consistent_read() will automatically re-read the same row,
6158 this time with locking enabled.
6159
6160 Thus, typical use in an UPDATE scenario would look like this:
6161
6162 file->try_semi_consistent_read(true);
6163 file->ha_rnd_init(true);
6164 while (file->ha_rnd_next(table->record[0]) == 0) {
6165 if (row is filtered...) {
6166 file->unlock_row();
6167 continue;
6168 }
6169 if (file->was_semi_consistent_read()) {
6170 // Discard the row; next ha_rnd_next() will read it again with
6171 // locking.
6172 continue;
6173 }
6174 // Process row here.
6175 }
6176 file->ha_rnd_end();
6177 file->try_semi_consistent_read(false);
6178
6179 If the transaction isolation level is REPEATABLE READ or SERIALIZABLE,
6180 enabling this flag has no effect.
6181 */
6182 virtual bool was_semi_consistent_read() { return false; }
6183 /**
6184 Tell the engine whether it should avoid unnecessary lock waits.
6185 If yes, in an UPDATE or DELETE, if the row under the cursor was locked
6186 by another transaction, the engine may try an optimistic read of
6187 the last committed row value under the cursor.
6188 */
6189 virtual void try_semi_consistent_read(bool) {}
6190
6191 /**
6192 Unlock last accessed row.
6193
6194 Record currently processed was not in the result set of the statement
6195 and is thus unlocked. Used for UPDATE and DELETE queries.
6196 */
6197
6198 virtual void unlock_row() {}
6199
6200 /**
6201 Start a statement when table is locked
6202
6203 This method is called instead of external lock when the table is locked
6204 before the statement is executed.
6205
6206 @param thd Thread object.
6207 @param lock_type Type of external lock.
6208
6209 @retval >0 Error code.
6210 @retval 0 Success.
6211 */
6212
6213 virtual int start_stmt(THD *thd [[maybe_unused]],
6214 thr_lock_type lock_type [[maybe_unused]]) {
6215 return 0;
6216 }
6217 virtual void get_auto_increment(ulonglong offset, ulonglong increment,
6218 ulonglong nb_desired_values,
6219 ulonglong *first_value,
6220 ulonglong *nb_reserved_values);
6222 DBUG_PRINT("info", ("auto_increment: next value %lu", (ulong)id));
6224 }
6226 /*
6227 Insertion of a row failed, re-use the lastly generated auto_increment
6228 id, for the next row. This is achieved by resetting next_insert_id to
6229 what it was before the failed insertion (that old value is provided by
6230 the caller). If that value was 0, it was the first row of the INSERT;
6231 then if insert_id_for_cur_row contains 0 it means no id was generated
6232 for this first row, so no id was generated since the INSERT started, so
6233 we should set next_insert_id to 0; if insert_id_for_cur_row is not 0, it
6234 is the generated id of the first and failed row, so we use it.
6235 */
6238 }
6239
6240 /**
6241 Update create info as part of ALTER TABLE.
6242
6243 Forward this handler call to the storage engine foreach
6244 partition handler. The data_file_name for each partition may
6245 need to be reset if the tablespace was moved. Use a dummy
6246 HA_CREATE_INFO structure and transfer necessary data.
6247
6248 @param create_info Create info from ALTER TABLE.
6249 */
6250
6251 virtual void update_create_info(HA_CREATE_INFO *create_info
6252 [[maybe_unused]]) {}
6255 }
6256 virtual int preload_keys(THD *, HA_CHECK_OPT *) {
6258 }
6259 /* end of the list of admin commands */
6260
6261 /**
6262 Check if indexes are disabled.
6263
6264 @retval 0 Indexes are enabled.
6265 @retval != 0 Indexes are disabled.
6266 */
6267
6268 virtual int indexes_are_disabled(void) { return 0; }
6269 virtual void append_create_info(String *packet [[maybe_unused]]) {}
6271 return;
6272 } /* prepare InnoDB for HANDLER */
6273 /** The following can be called without an open handler */
6274 virtual const char *table_type() const = 0;
6275
6276 virtual ulong index_flags(uint idx, uint part, bool all_parts) const = 0;
6277
6278 uint max_record_length() const {
6280 }
6281 uint max_keys() const {
6282 return std::min<uint>(MAX_KEY, max_supported_keys());
6283 }
6284 uint max_key_parts() const {
6285 return std::min(MAX_REF_PARTS, max_supported_key_parts());
6286 }
6287 uint max_key_length() const {
6288 return std::min(MAX_KEY_LENGTH, max_supported_key_length());
6289 }
6290 uint max_key_part_length(HA_CREATE_INFO *create_info) const {
6291 return std::min(MAX_KEY_LENGTH, max_supported_key_part_length(create_info));
6292 }
6293
6294 virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
6295 virtual uint max_supported_keys() const { return 0; }
6296 virtual uint max_supported_key_parts() const { return MAX_REF_PARTS; }
6297 virtual uint max_supported_key_length() const { return MAX_KEY_LENGTH; }
6299 [[maybe_unused]]) const {
6300 return 255;
6301 }
6302 virtual uint min_record_length(uint options [[maybe_unused]]) const {
6303 return 1;
6304 }
6305
6306 virtual bool low_byte_first() const { return true; }
6307 virtual ha_checksum checksum() const { return 0; }
6308
6309 /**
6310 Check if the table is crashed.
6311
6312 @retval true Crashed
6313 @retval false Not crashed
6314 */
6315
6316 virtual bool is_crashed() const { return false; }
6317
6318 /**
6319 Check if the table can be automatically repaired.
6320
6321 @retval true Can be auto repaired
6322 @retval false Cannot be auto repaired
6323 */
6324
6325 virtual bool auto_repair() const { return false; }
6326
6327 /**
6328 Get number of lock objects returned in store_lock.
6329
6330 Returns the number of store locks needed in call to store lock.
6331 We return number of partitions we will lock multiplied with number of
6332 locks needed by each partition. Assists the above functions in allocating
6333 sufficient space for lock structures.
6334
6335 @returns Number of locks returned in call to store_lock.
6336
6337 @note lock_count() can return > 1 if the table is MERGE or partitioned.
6338 */
6339
6340 virtual uint lock_count(void) const { return 1; }
6341
6342 /**
6343 Is not invoked for non-transactional temporary tables.
6344
6345 @note store_lock() can return more than one lock if the table is MERGE
6346 or partitioned.
6347
6348 @note that one can NOT rely on table->in_use in store_lock(). It may
6349 refer to a different thread if called from mysql_lock_abort_for_thread().
6350
6351 @note If the table is MERGE, store_lock() can return less locks
6352 than lock_count() claimed. This can happen when the MERGE children
6353 are not attached when this is called from another thread.
6354
6355 The idea with handler::store_lock() is the following:
6356
6357 The statement decided which locks we should need for the table
6358 for updates/deletes/inserts we get WRITE locks, for SELECT... we get
6359 read locks.
6360
6361 Before adding the lock into the table lock handler (see thr_lock.c)
6362 mysqld calls store lock with the requested locks. Store lock can now
6363 modify a write lock to a read lock (or some other lock), ignore the
6364 lock (if we don't want to use MySQL table locks at all) or add locks
6365 for many tables (like we do when we are using a MERGE handler).
6366
6367 In some exceptional cases MySQL may send a request for a TL_IGNORE;
6368 This means that we are requesting the same lock as last time and this
6369 should also be ignored.
6370
6371 Called from lock.cc by get_lock_data().
6372 */
6374 enum thr_lock_type lock_type) = 0;
6375
6376 /**
6377 Check if the primary key is clustered or not.
6378
6379 @retval true Primary key (if there is one) is a clustered
6380 key covering all fields
6381 @retval false otherwise
6382 */
6383
6384 virtual bool primary_key_is_clustered() const { return false; }
6385
6386 /**
6387 Compare two positions.
6388
6389 @param ref1 First position.
6390 @param ref2 Second position.
6391
6392 @retval <0 ref1 < ref2.
6393 @retval 0 Equal.
6394 @retval >0 ref1 > ref2.
6395 */
6396
6397 virtual int cmp_ref(const uchar *ref1, const uchar *ref2) const {
6398 return memcmp(ref1, ref2, ref_length);
6399 }
6400
6401 /*
6402 Condition pushdown to storage engines
6403 */
6404
6405 /**
6406 Push condition down to the table handler.
6407
6408 @param cond Condition to be pushed. The condition tree
6409 must not be modified by the caller.
6410
6411 @return
6412 The 'remainder' condition that caller must use to filter out records.
6413 NULL means the handler will not return rows that do not match the
6414 passed condition.
6415
6416 @note
6417 handler->ha_reset() call discard any pushed conditions.
6418 Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
6419 pushed conditions.
6420 */
6421 virtual const Item *cond_push(const Item *cond) {
6422 assert(pushed_cond == nullptr);
6423 return cond;
6424 }
6425
6426 /**
6427 Push down an index condition to the handler.
6428
6429 The server will use this method to push down a condition it wants
6430 the handler to evaluate when retrieving records using a specified
6431 index. The pushed index condition will only refer to fields from
6432 this handler that is contained in the index (but it may also refer
6433 to fields in other handlers). Before the handler evaluates the
6434 condition it must read the content of the index entry into the
6435 record buffer.
6436
6437 The handler is free to decide if and how much of the condition it
6438 will take responsibility for evaluating. Based on this evaluation
6439 it should return the part of the condition it will not evaluate.
6440 If it decides to evaluate the entire condition it should return
6441 NULL. If it decides not to evaluate any part of the condition it
6442 should return a pointer to the same condition as given as argument.
6443
6444 @param keyno the index number to evaluate the condition on
6445 @param idx_cond the condition to be evaluated by the handler
6446
6447 @return The part of the pushed condition that the handler decides
6448 not to evaluate
6449 */
6450
6451 virtual Item *idx_cond_push(uint keyno [[maybe_unused]], Item *idx_cond) {
6452 return idx_cond;
6453 }
6454
6455 /** Reset information about pushed index conditions */
6456 virtual void cancel_pushed_idx_cond() {
6457 pushed_idx_cond = nullptr;
6460 }
6461
6462 /**
6463 Reports number of tables included in pushed join which this
6464 handler instance is part of. ==0 -> Not pushed
6465 */
6466 virtual uint number_of_pushed_joins() const { return 0; }
6467
6468 /**
6469 If this handler instance is part of a pushed join sequence
6470 returned TABLE instance being root of the pushed query?
6471 */
6472 virtual const TABLE *member_of_pushed_join() const { return nullptr; }
6473
6474 /**
6475 If this handler instance is a child in a pushed join sequence
6476 returned TABLE instance being my parent?
6477 */
6478 virtual const TABLE *parent_of_pushed_join() const { return nullptr; }
6479
6480 /// @returns a map of the tables involved in this pushed join, or 0 if not
6481 /// part of a pushed join.
6482 virtual table_map tables_in_pushed_join() const { return 0; }
6483
6484 int ha_index_read_pushed(uchar *buf, const uchar *key,
6485 key_part_map keypart_map);
6486
6488
6489 protected:
6490 virtual int index_read_pushed(uchar *, const uchar *, key_part_map) {
6491 return HA_ERR_WRONG_COMMAND;
6492 }
6493
6495
6496 public:
6497 /**
6498 Part of old, deprecated in-place ALTER API.
6499 */
6501 [[maybe_unused]],
6502 uint table_changes [[maybe_unused]]) {
6503 return COMPATIBLE_DATA_NO;
6504 }
6505
6506 /* On-line/in-place/instant ALTER TABLE interface. */
6507
6508 /*
6509 Here is an outline of on-line/in-place ALTER TABLE execution through
6510 this interface.
6511
6512 Phase 1 : Initialization
6513 ========================
6514 During this phase we determine which algorithm should be used
6515 for execution of ALTER TABLE and what level concurrency it will
6516 require.
6517
6518 *) This phase starts by opening the table and preparing description
6519 of the new version of the table.
6520 *) Then we check if it is impossible even in theory to carry out
6521 this ALTER TABLE using the in-place/instant algorithm. For example,
6522 because we need to change storage engine or the user has explicitly
6523 requested usage of the "copy" algorithm.
6524 *) If in-place/instant ALTER TABLE is theoretically possible, we continue
6525 by compiling differences between old and new versions of the table
6526 in the form of HA_ALTER_FLAGS bitmap. We also build a few
6527 auxiliary structures describing requested changes and store
6528 all these data in the Alter_inplace_info object.
6529 *) Then the handler::check_if_supported_inplace_alter() method is called
6530 in order to find if the storage engine can carry out changes requested
6531 by this ALTER TABLE using the in-place or instant algorithm.
6532 To determine this, the engine can rely on data in HA_ALTER_FLAGS/
6533 Alter_inplace_info passed to it as well as on its own checks.
6534 If the in-place algorithm can be used for this ALTER TABLE, the level
6535 of required concurrency for its execution is also returned.
6536 If any errors occur during the handler call, ALTER TABLE is aborted
6537 and no further handler functions are called.
6538 Note that in cases when there is difference between in-place and
6539 instant algorithm and user explicitly asked for usage of in-place
6540 algorithm storage engine MUST return one of values corresponding
6541 to in-place algorithm and not HA_ALTER_INPLACE_INSTANT from this
6542 method.
6543 *) Locking requirements of the in-place algorithm are compared to any
6544 concurrency requirements specified by user. If there is a conflict
6545 between them, we either switch to the copy algorithm or emit an error.
6546
6547 Phase 2 : Execution
6548 ===================
6549
6550 In this phase the operations are executed.
6551
6552 *) As the first step, we acquire a lock corresponding to the concurrency
6553 level which was returned by handler::check_if_supported_inplace_alter()
6554 and requested by the user. This lock is held for most of the
6555 duration of in-place ALTER (if HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE
6556 or HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE were returned we acquire an
6557 exclusive lock for duration of the next step only).
6558 For HA_ALTER_INPLACE_INSTANT we keep shared upgradable metadata lock
6559 which was acquired at table open time.
6560 *) After that we call handler::ha_prepare_inplace_alter_table() to give the
6561 storage engine a chance to update its internal structures with a higher
6562 lock level than the one that will be used for the main step of algorithm.
6563 After that we downgrade the lock if it is necessary.
6564 This step should be no-op for instant algorithm.
6565 *) After that, the main step of this phase and algorithm is executed.
6566 We call the handler::ha_inplace_alter_table() method, which carries out
6567 the changes requested by ALTER TABLE but does not makes them visible to
6568 other connections yet.
6569 This step should be no-op for instant algorithm as well.
6570 *) We ensure that no other connection uses the table by upgrading our
6571 lock on it to exclusive.
6572 *) a) If the previous step succeeds,
6573 handler::ha_commit_inplace_alter_table() is called to allow the storage
6574 engine to do any final updates to its structures, to make all earlier
6575 changes durable and visible to other connections.
6576 For instant algorithm this is the step during which SE changes are done.
6577 Engines that support atomic DDL only prepare for the commit during this
6578 step but do not finalize it. Real commit happens later when the whole
6579 statement is committed. Also in some situations statement might be rolled
6580 back after call to commit_inplace_alter_table() for such storage engines.
6581 In the latter special case SE might require call to
6582 handlerton::dict_cache_reset() in order to invalidate its internal table
6583 definition cache after rollback.
6584 b) If we have failed to upgrade lock or any errors have occurred during
6585 the handler functions calls (including commit), we call
6586 handler::ha_commit_inplace_alter_table() to rollback all changes which
6587 were done during previous steps.
6588
6589 All the above calls to SE are provided with dd::Table objects describing old
6590 and new version of table being altered. Engines which support atomic DDL are
6591 allowed to adjust object corresponding to the new version. During phase 3
6592 these changes are saved to the data-dictionary.
6593
6594
6595 Phase 3 : Final
6596 ===============
6597
6598 In this phase we:
6599
6600 a) For engines which don't support atomic DDL:
6601
6602 *) Update the SQL-layer data-dictionary by replacing description of old
6603 version of the table with its new version. This change is immediately
6604 committed.
6605 *) Inform the storage engine about this change by calling the
6606 handler::ha_notify_table_changed() method.
6607 *) Process the RENAME clause by calling handler::ha_rename_table() and
6608 updating the data-dictionary accordingly. Again this change is
6609 immediately committed.
6610 *) Destroy the Alter_inplace_info and handler_ctx objects.
6611
6612 b) For engines which support atomic DDL:
6613
6614 *) Update the SQL-layer data-dictionary by replacing description of old
6615 version of the table with its new version.
6616 *) Process the RENAME clause by calling handler::ha_rename_table() and
6617 updating the data-dictionary accordingly.
6618 *) Commit the statement/transaction.
6619 *) Finalize atomic DDL operation by calling handlerton::post_ddl() hook
6620 for the storage engine.
6621 *) Additionally inform the storage engine about completion of ALTER TABLE
6622 for the table by calling the handler::ha_notify_table_changed()
6623 method.
6624 *) Destroy the Alter_inplace_info and handler_ctx objects.
6625 */
6626
6627 /**
6628 Check if a storage engine supports a particular alter table in-place
6629
6630 @param altered_table TABLE object for new version of table.
6631 @param ha_alter_info Structure describing changes to be done
6632 by ALTER TABLE and holding data used
6633 during in-place alter.
6634
6635 @retval HA_ALTER_ERROR Unexpected error.
6636 @retval HA_ALTER_INPLACE_NOT_SUPPORTED Not supported, must use copy.
6637 @retval HA_ALTER_INPLACE_EXCLUSIVE_LOCK Supported, but requires X lock.
6638 @retval HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE
6639 Supported, but requires SNW lock
6640 during main phase. Prepare phase
6641 requires X lock.
6642 @retval HA_ALTER_INPLACE_SHARED_LOCK Supported, but requires SNW lock.
6643 @retval HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE
6644 Supported, concurrent
6645 reads/writes allowed. However, prepare phase requires X lock.
6646 @retval HA_ALTER_INPLACE_NO_LOCK Supported, concurrent
6647 reads/writes allowed.
6648 @retval HA_ALTER_INPLACE_INSTANT Instant algorithm is supported.
6649 Prepare and main phases are
6650 no-op. Changes happen during
6651 commit phase and it should be
6652 "instant". We keep SU lock,
6653 allowing concurrent reads and
6654 writes during no-op phases and
6655 upgrade it to X lock before
6656 commit phase.
6657
6658 @note The default implementation uses the old in-place ALTER API
6659 to determine if the storage engine supports in-place ALTER or not.
6660
6661 @note In cases when there is difference between in-place and instant
6662 algorithm and explicit ALGORITHM=INPLACE clause was provided SE MUST
6663 return one of values corresponding to in-place algorithm and not
6664 HA_ALTER_INPLACE_INSTANT from this method.
6665
6666 @note Called without holding thr_lock.c lock.
6667 */
6669 TABLE *altered_table, Alter_inplace_info *ha_alter_info);
6670
6671 /**
6672 Public functions wrapping the actual handler call.
6673 @see prepare_inplace_alter_table()
6674 */
6675 bool ha_prepare_inplace_alter_table(TABLE *altered_table,
6676 Alter_inplace_info *ha_alter_info,
6677 const dd::Table *old_table_def,
6678 dd::Table *new_table_def);
6679
6680 /**
6681 Public function wrapping the actual handler call.
6682 @see inplace_alter_table()
6683 */
6684 bool ha_inplace_alter_table(TABLE *altered_table,
6685 Alter_inplace_info *ha_alter_info,
6686 const dd::Table *old_table_def,
6687 dd::Table *new_table_def) {
6688 return inplace_alter_table(altered_table, ha_alter_info, old_table_def,
6689 new_table_def);
6690 }
6691
6692 /**
6693 Public function wrapping the actual handler call.
6694 Allows us to enforce asserts regardless of handler implementation.
6695 @see commit_inplace_alter_table()
6696 */
6697 bool ha_commit_inplace_alter_table(TABLE *altered_table,
6698 Alter_inplace_info *ha_alter_info,
6699 bool commit,
6700 const dd::Table *old_table_def,
6701 dd::Table *new_table_def);
6702
6703 /**
6704 Public function wrapping the actual handler call.
6705
6706 @see notify_table_changed()
6707 */
6709 notify_table_changed(ha_alter_info);
6710 }
6711
6712 protected:
6713 /**
6714 Allows the storage engine to update internal structures with concurrent
6715 writes blocked. If check_if_supported_inplace_alter() returns
6716 HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE or
6717 HA_ALTER_INPLACE_SHARED_AFTER_PREPARE, this function is called with
6718 exclusive lock otherwise the same level of locking as for
6719 inplace_alter_table() will be used.
6720
6721 @note Should be no-op for instant algorithm.
6722
6723 @note Storage engines are responsible for reporting any errors by
6724 calling my_error()/print_error()
6725
6726 @note If this function reports error, commit_inplace_alter_table()
6727 will be called with commit= false.
6728
6729 @note For partitioning, failing to prepare one partition, means that
6730 commit_inplace_alter_table() will be called to roll back changes for
6731 all partitions. This means that commit_inplace_alter_table() might be
6732 called without prepare_inplace_alter_table() having been called first
6733 for a given partition.
6734
6735 @param altered_table TABLE object for new version of table.
6736 @param ha_alter_info Structure describing changes to be done
6737 by ALTER TABLE and holding data used
6738 during in-place alter.
6739 @param old_table_def dd::Table object describing old version of
6740 the table.
6741 @param new_table_def dd::Table object for the new version of the
6742 table. Can be adjusted by this call if SE
6743 supports atomic DDL. These changes to the
6744 table definition will be persisted in the
6745 data-dictionary at statement commit time.
6746
6747 @retval true Error
6748 @retval false Success
6749 */
6751 TABLE *altered_table [[maybe_unused]],
6752 Alter_inplace_info *ha_alter_info [[maybe_unused]],
6753 const dd::Table *old_table_def [[maybe_unused]],
6754 dd::Table *new_table_def [[maybe_unused]]) {
6755 return false;
6756 }
6757
6758 /**
6759 Alter the table structure in-place with operations specified using
6760 HA_ALTER_FLAGS and Alter_inplace_info. The level of concurrency allowed
6761 during this operation depends on the return value from
6762 check_if_supported_inplace_alter().
6763
6764 @note Should be no-op for instant algorithm.
6765
6766 @note Storage engines are responsible for reporting any errors by
6767 calling my_error()/print_error()
6768
6769 @note If this function reports error, commit_inplace_alter_table()
6770 will be called with commit= false.
6771
6772 @param altered_table TABLE object for new version of table.
6773 @param ha_alter_info Structure describing changes to be done
6774 by ALTER TABLE and holding data used
6775 during in-place alter.
6776 @param old_table_def dd::Table object describing old version of
6777 the table.
6778 @param new_table_def dd::Table object for the new version of the
6779 table. Can be adjusted by this call if SE
6780 supports atomic DDL. These changes to the
6781 table definition will be persisted in the
6782 data-dictionary at statement commit time.
6783
6784 @retval true Error
6785 @retval false Success
6786 */
6787 virtual bool inplace_alter_table(TABLE *altered_table [[maybe_unused]],
6788 Alter_inplace_info *ha_alter_info
6789 [[maybe_unused]],
6790 const dd::Table *old_table_def
6791 [[maybe_unused]],
6792 dd::Table *new_table_def [[maybe_unused]]) {
6793 return false;
6794 }
6795
6796 /**
6797 Commit or rollback the changes made during prepare_inplace_alter_table()
6798 and inplace_alter_table() inside the storage engine.
6799 Note that in case of rollback the allowed level of concurrency during
6800 this operation will be the same as for inplace_alter_table() and thus
6801 might be higher than during prepare_inplace_alter_table(). (For example,
6802 concurrent writes were blocked during prepare, but might not be during
6803 rollback).
6804
6805 @note This is the place where SE changes happen for instant algorithm.
6806
6807 @note For storage engines supporting atomic DDL this method should only
6808 prepare for the commit but do not finalize it. Real commit should happen
6809 later when the whole statement is committed. Also in some situations
6810 statement might be rolled back after call to commit_inplace_alter_table()
6811 for such storage engines. In the latter special case SE might require call
6812 to handlerton::dict_cache_reset() in order to invalidate its internal
6813 table definition cache after rollback.
6814
6815 @note Storage engines are responsible for reporting any errors by
6816 calling my_error()/print_error()
6817
6818 @note If this function with commit= true reports error, it will be called
6819 again with commit= false.
6820
6821 @note In case of partitioning, this function might be called for rollback
6822 without prepare_inplace_alter_table() having been called first.
6823 Also partitioned tables sets ha_alter_info->group_commit_ctx to a NULL
6824 terminated array of the partitions handlers and if all of them are
6825 committed as one, then group_commit_ctx should be set to NULL to indicate
6826 to the partitioning handler that all partitions handlers are committed.
6827 @see prepare_inplace_alter_table().
6828
6829 @param altered_table TABLE object for new version of table.
6830 @param ha_alter_info Structure describing changes to be done
6831 by ALTER TABLE and holding data used
6832 during in-place alter.
6833 @param commit True => Commit, False => Rollback.
6834 @param old_table_def dd::Table object describing old version of
6835 the table.
6836 @param new_table_def dd::Table object for the new version of the
6837 table. Can be adjusted by this call if SE
6838 supports atomic DDL. These changes to the
6839 table definition will be persisted in the
6840 data-dictionary at statement commit time.
6841
6842 @retval true Error
6843 @retval false Success
6844 */
6845 virtual bool commit_inplace_alter_table(TABLE *altered_table [[maybe_unused]],
6846 Alter_inplace_info *ha_alter_info
6847 [[maybe_unused]],
6848 bool commit [[maybe_unused]],
6849 const dd::Table *old_table_def
6850 [[maybe_unused]],
6851 dd::Table *new_table_def
6852 [[maybe_unused]]) {
6853 /* Nothing to commit/rollback, mark all handlers committed! */
6854 ha_alter_info->group_commit_ctx = nullptr;
6855 return false;
6856 }
6857
6858 /**
6859 Notify the storage engine that the table definition has been updated.
6860
6861 @param ha_alter_info Structure describing changes done by
6862 ALTER TABLE and holding data used
6863 during in-place alter.
6864
6865 @note No errors are allowed during notify_table_changed().
6866
6867 @note For storage engines supporting atomic DDL this method is invoked
6868 after the whole ALTER TABLE is completed and committed.
6869 Particularly this means that for ALTER TABLE statements with RENAME
6870 clause TABLE/handler object used for invoking this method will be
6871 associated with new table name. If storage engine needs to know
6872 the old schema and table name in this method for some reason it
6873 has to use ha_alter_info object to figure it out.
6874 */
6875 virtual void notify_table_changed(Alter_inplace_info *ha_alter_info
6876 [[maybe_unused]]) {}
6877
6878 public:
6879 /* End of On-line/in-place ALTER TABLE interface. */
6880
6881 /**
6882 use_hidden_primary_key() is called in case of an update/delete when
6883 (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
6884 but we don't have a primary key
6885 */
6886 virtual void use_hidden_primary_key();
6887
6888 protected:
6889 /* Service methods for use by storage engines. */
6891 THD *ha_thd() const;
6892
6893 /**
6894 Acquire the instrumented table information from a table share.
6895 @param share a table share
6896 @return an instrumented table share, or NULL.
6897 */
6899
6900 /**
6901 Default rename_table() and delete_table() rename/delete files with a
6902 given name and extensions from handlerton::file_extensions.
6903
6904 These methods can be overridden, but their default implementation
6905 provide useful functionality.
6906
6907 @param [in] from Path for the old table name.
6908 @param [in] to Path for the new table name.
6909 @param [in] from_table_def Old version of definition for table
6910 being renamed (i.e. prior to rename).
6911 @param [in,out] to_table_def New version of definition for table
6912 being renamed. Storage engines which
6913 support atomic DDL (i.e. having
6914 HTON_SUPPORTS_ATOMIC_DDL flag set)
6915 are allowed to adjust this object.
6916
6917 @retval >0 Error.
6918 @retval 0 Success.
6919 */
6920 virtual int rename_table(const char *from, const char *to,
6921 const dd::Table *from_table_def,
6922 dd::Table *to_table_def);
6923
6924 /**
6925 Delete a table.
6926
6927 Used to delete a table. By the time delete_table() has been called all
6928 opened references to this table will have been closed (and your globally
6929 shared references released. The variable name will just be the name of
6930 the table. You will need to remove any files you have created at this
6931 point. Called for base as well as temporary tables.
6932
6933 @param name Full path of table name.
6934 @param table_def dd::Table describing table being deleted
6935 (can be NULL for temporary tables created
6936 by optimizer).
6937
6938 @return Zero on success, nonzero otherwise.
6939 */
6940 virtual int delete_table(const char *name, const dd::Table *table_def);
6941
6942 private:
6943 /* Private helpers */
6944 void mark_trx_read_write();
6945 /*
6946 Low-level primitives for storage engines. These should be
6947 overridden by the storage engine class. To call these methods, use
6948 the corresponding 'ha_*' method above.
6949 */
6950
6951 virtual int open(const char *name, int mode, uint test_if_locked,
6952 const dd::Table *table_def) = 0;
6953 virtual int close(void) = 0;
6954 virtual int index_init(uint idx, bool sorted [[maybe_unused]]) {
6955 active_index = idx;
6956 return 0;
6957 }
6958 virtual int index_end() {
6960 return 0;
6961 }
6962 /**
6963 rnd_init() can be called two times without rnd_end() in between
6964 (it only makes sense if scan=1).
6965 then the second call should prepare for the new table scan (e.g
6966 if rnd_init allocates the cursor, second call should position it
6967 to the start of the table, no need to deallocate and allocate it again
6968 */
6969 virtual int rnd_init(bool scan) = 0;
6970 virtual int rnd_end() { return 0; }
6971 /**
6972 Write a row.
6973
6974 write_row() inserts a row. buf is a byte array of data, normally
6975 record[0].
6976
6977 You can use the field information to extract the data from the native byte
6978 array type.
6979
6980 Example of this would be:
6981 for (Field **field=table->field ; *field ; field++)
6982 {
6983 ...
6984 }
6985
6986 @param buf Buffer to write from.
6987
6988 @return Operation status.
6989 @retval 0 Success.
6990 @retval != 0 Error code.
6991 */
6992 virtual int write_row(uchar *buf [[maybe_unused]]) {
6993 return HA_ERR_WRONG_COMMAND;
6994 }
6995
6996 /**
6997 Update a single row.
6998
6999 Note: If HA_ERR_FOUND_DUPP_KEY is returned, the handler must read
7000 all columns of the row so MySQL can create an error message. If
7001 the columns required for the error message are not read, the error
7002 message will contain garbage.
7003 */
7004 virtual int update_row(const uchar *old_data [[maybe_unused]],
7005 uchar *new_data [[maybe_unused]]) {
7006 return HA_ERR_WRONG_COMMAND;
7007 }
7008
7009 virtual int delete_row(const uchar *buf [[maybe_unused]]) {
7010 return HA_ERR_WRONG_COMMAND;
7011 }
7012 /**
7013 Reset state of file to after 'open'.
7014 This function is called after every statement for all tables used
7015 by that statement.
7016 */
7017 virtual int reset() { return 0; }
7018 virtual Table_flags table_flags(void) const = 0;
7019 /**
7020 Is not invoked for non-transactional temporary tables.
7021
7022 Tells the storage engine that we intend to read or write data
7023 from the table. This call is prefixed with a call to handler::store_lock()
7024 and is invoked only for those handler instances that stored the lock.
7025
7026 Calls to @c rnd_init / @c index_init are prefixed with this call. When table
7027 IO is complete, we call @code external_lock(F_UNLCK) @endcode.
7028 A storage engine writer should expect that each call to
7029 @code ::external_lock(F_[RD|WR]LOCK @endcode is followed by a call to
7030 @code ::external_lock(F_UNLCK) @endcode. If it is not, it is a bug in MySQL.
7031
7032 The name and signature originate from the first implementation
7033 in MyISAM, which would call @c fcntl to set/clear an advisory
7034 lock on the data file in this method.
7035
7036 Originally this method was used to set locks on file level to enable
7037 several MySQL Servers to work on the same data. For transactional
7038 engines it has been "abused" to also mean start and end of statements
7039 to enable proper rollback of statements and transactions. When LOCK
7040 TABLES has been issued the start_stmt method takes over the role of
7041 indicating start of statement but in this case there is no end of
7042 statement indicator(?).
7043
7044 Called from lock.cc by lock_external() and unlock_external(). Also called
7045 from sql_table.cc by copy_data_between_tables().
7046
7047 @param thd the current thread
7048 @param lock_type F_RDLCK, F_WRLCK, F_UNLCK
7049
7050 @return non-0 in case of failure, 0 in case of success.
7051 When lock_type is F_UNLCK, the return value is ignored.
7052 */
7053 virtual int external_lock(THD *thd [[maybe_unused]],
7054 int lock_type [[maybe_unused]]) {
7055 return 0;
7056 }
7057 virtual void release_auto_increment() { return; }
7058 /** admin commands - called from mysql_admin_table */
7059 virtual int check_for_upgrade(HA_CHECK_OPT *) { return 0; }
7060 virtual int check(THD *, HA_CHECK_OPT *) { return HA_ADMIN_NOT_IMPLEMENTED; }
7061
7062 /**
7063 In this method check_opt can be modified
7064 to specify CHECK option to use to call check()
7065 upon the table.
7066 */
7067 virtual int repair(THD *, HA_CHECK_OPT *) {
7068 assert(!(ha_table_flags() & HA_CAN_REPAIR));
7070 }
7072 virtual int end_bulk_insert() { return 0; }
7073
7074 /**
7075 Does this handler want to get a Record_buffer for multi-row reads
7076 via the ha_set_record_buffer() function? And if so, what is the
7077 maximum number of records to allocate space for in the buffer?
7078
7079 Storage engines that support using a Record_buffer should override
7080 this function and return true for scans that could benefit from a
7081 buffer.
7082
7083 @param[out] max_rows gets set to the maximum number of records to
7084 allocate space for in the buffer if the function
7085 returns true
7086
7087 @retval true if the handler would like a Record_buffer
7088 @retval false if the handler does not want a Record_buffer
7089 */
7090 virtual bool is_record_buffer_wanted(ha_rows *const max_rows) const {
7091 *max_rows = 0;
7092 return false;
7093 }
7094
7095 // Set se_private_id and se_private_data during upgrade
7096 virtual bool upgrade_table(THD *thd [[maybe_unused]],
7097 const char *dbname [[maybe_unused]],
7098 const char *table_name [[maybe_unused]],
7099 dd::Table *dd_table [[maybe_unused]]) {
7100 return false;
7101 }
7102
7103 /** Initialize sampling.
7104 @param[out] scan_ctx A scan context created by this method that has to be
7105 used in sample_next
7106 @param[in] sampling_percentage percentage of records that need to be sampled
7107 @param[in] sampling_seed random seed
7108 @param[in] sampling_method sampling method to be used; currently only
7109 SYSTEM sampling is supported
7110 @param[in] tablesample true if the sampling is for tablesample
7111 @return 0 for success, else failure. */
7112 virtual int sample_init(void *&scan_ctx, double sampling_percentage,
7113 int sampling_seed,
7114 enum_sampling_method sampling_method,
7115 const bool tablesample);
7116
7117 /** Get the next record for sampling.
7118 @param[in] scan_ctx Scan context of the sampling
7119 @param[in] buf buffer to place the read record
7120 @return 0 for success, else failure. */
7121 virtual int sample_next(void *scan_ctx, uchar *buf);
7122
7123 /** End sampling.
7124 @param[in] scan_ctx Scan context of the sampling
7125 @return 0 for success, else failure. */
7126 virtual int sample_end(void *scan_ctx);
7127
7128 /**
7129 * Loads a table into its defined secondary storage engine.
7130 *
7131 * @param[in] table - Table opened in primary storage engine. Its read_set
7132 * tells which columns to load.
7133 * @param[out] skip_metadata_update - should the DD metadata be updated for
7134 * the load of this table
7135 *
7136 * @return 0 if success, error code otherwise.
7137 */
7138 virtual int load_table(const TABLE &table [[maybe_unused]],
7139 bool *skip_metadata_update [[maybe_unused]]) {
7140 /* purecov: begin inspected */
7141 assert(false);
7142 return HA_ERR_WRONG_COMMAND;
7143 /* purecov: end */
7144 }
7145
7146 /**
7147 * Unloads a table from its defined secondary storage engine.
7148 *
7149 * @param db_name Database name.
7150 * @param table_name Table name.
7151 * @param error_if_not_loaded If true, then errors will be reported by this
7152 * function. If false, no errors will be reported
7153 * (silently fail). This case of false is useful
7154 * during DROP TABLE where a failure to unload
7155 * should not prevent dropping the whole table.
7156 * @return 0 if success, error code otherwise.
7157 */
7158 virtual int unload_table(const char *db_name [[maybe_unused]],
7159 const char *table_name [[maybe_unused]],
7160 bool error_if_not_loaded [[maybe_unused]]) {
7161 /* purecov: begin inspected */
7162 assert(false);
7163 return HA_ERR_WRONG_COMMAND;
7164 /* purecov: end */
7165 }
7166
7167 protected:
7168 virtual int index_read(uchar *buf [[maybe_unused]],
7169 const uchar *key [[maybe_unused]],
7170 uint key_len [[maybe_unused]],
7171 enum ha_rkey_function find_flag [[maybe_unused]]) {
7172 return HA_ERR_WRONG_COMMAND;
7173 }
7174 virtual int index_read_last(uchar *buf [[maybe_unused]],
7175 const uchar *key [[maybe_unused]],
7176 uint key_len [[maybe_unused]]) {
7178 return HA_ERR_WRONG_COMMAND;
7179 }
7180
7181 public:
7182 /**
7183 This method is similar to update_row, however the handler doesn't need
7184 to execute the updates at this point in time. The handler can be certain
7185 that another call to bulk_update_row will occur OR a call to
7186 exec_bulk_update before the set of updates in this query is concluded.
7187
7188 Note: If HA_ERR_FOUND_DUPP_KEY is returned, the handler must read
7189 all columns of the row so MySQL can create an error message. If
7190 the columns required for the error message are not read, the error
7191 message will contain garbage.
7192
7193 @param old_data Old record
7194 @param new_data New record
7195 @param dup_key_found Number of duplicate keys found
7196
7197 */
7198 virtual int bulk_update_row(const uchar *old_data [[maybe_unused]],
7199 uchar *new_data [[maybe_unused]],
7200 uint *dup_key_found [[maybe_unused]]) {
7201 assert(false);
7202 return HA_ERR_WRONG_COMMAND;
7203 }
7204 /**
7205 Delete all rows in a table.
7206
7207 This is called both for cases of truncate and for cases where the
7208 optimizer realizes that all rows will be removed as a result of an
7209 SQL statement.
7210
7211 If the handler don't support this, then this function will
7212 return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
7213 by one.
7214 */
7215 virtual int delete_all_rows() {
7217 return HA_ERR_WRONG_COMMAND;
7218 }
7219 /**
7220 Quickly remove all rows from a table.
7221
7222 @param[in,out] table_def dd::Table object for table being truncated.
7223
7224 @remark This method is responsible for implementing MySQL's TRUNCATE
7225 TABLE statement, which is a DDL operation. As such, a engine
7226 can bypass certain integrity checks and in some cases avoid
7227 fine-grained locking (e.g. row locks) which would normally be
7228 required for a DELETE statement.
7229
7230 @remark Typically, truncate is not used if it can result in integrity
7231 violation. For example, truncate is not used when a foreign
7232 key references the table, but it might be used if foreign key
7233 checks are disabled.
7234
7235 @remark Engine is responsible for resetting the auto-increment counter.
7236
7237 @remark The table is locked in exclusive mode. All open TABLE/handler
7238 instances except the one which is used for truncate() call
7239 are closed.
7240
7241 @note It is assumed that transactional storage engines implementing
7242 this method can revert its effects if transaction is rolled
7243 back (e.g. because we failed to write statement to the binary
7244 log).
7245
7246 @note Changes to dd::Table object done by this method will be saved
7247 to data-dictionary only if storage engine supports atomic DDL
7248 (i.e. has HTON_SUPPORTS_ATOMIC_DDL flag set).
7249 */
7250 virtual int truncate(dd::Table *table_def [[maybe_unused]]) {
7251 return HA_ERR_WRONG_COMMAND;
7252 }
7253 virtual int optimize(THD *, HA_CHECK_OPT *) {
7255 }
7256 virtual int analyze(THD *, HA_CHECK_OPT *) {
7258 }
7259
7260 /**
7261 @brief Check and repair the table if necessary.
7262
7263 @param thd Thread object
7264
7265 @retval true Error/Not supported
7266 @retval false Success
7267
7268 @note Called if open_table_from_share fails and is_crashed().
7269 */
7270
7271 virtual bool check_and_repair(THD *thd [[maybe_unused]]) { return true; }
7272
7273 /**
7274 Disable indexes for a while.
7275
7276 @param mode Mode.
7277
7278 @retval 0 Success.
7279 @retval != 0 Error.
7280 */
7281
7282 virtual int disable_indexes(uint mode [[maybe_unused]]) {
7283 return HA_ERR_WRONG_COMMAND;
7284 }
7285
7286 /**
7287 Enable indexes again.
7288
7289 @param mode Mode.
7290
7291 @retval 0 Success.
7292 @retval != 0 Error.
7293 */
7294
7295 virtual int enable_indexes(uint mode [[maybe_unused]]) {
7296 return HA_ERR_WRONG_COMMAND;
7297 }
7298
7299 /**
7300 Discard or import tablespace.
7301
7302 @param [in] discard Indicates whether this is discard operation.
7303 @param [in,out] table_def dd::Table object describing the table
7304 in which tablespace needs to be discarded
7305 or imported. This object can be adjusted by
7306 storage engine if it supports atomic DDL
7307 (i.e. has HTON_SUPPORTS_ATOMIC_DDL flag set).
7308 These changes will be persisted in the
7309 data-dictionary.
7310 @retval 0 Success.
7311 @retval != 0 Error.
7312 */
7313
7314 virtual int discard_or_import_tablespace(bool discard [[maybe_unused]],
7316 [[maybe_unused]]) {
7318 return HA_ERR_WRONG_COMMAND;
7319 }
7320
7321 virtual void drop_table(const char *name);
7322
7323 /**
7324 Create table (implementation).
7325
7326 @param [in] name Table name.
7327 @param [in] form TABLE object describing the table to be
7328 created.
7329 @param [in] info HA_CREATE_INFO describing table.
7330 @param [in,out] table_def dd::Table object describing the table
7331 to be created. This object can be
7332 adjusted by storage engine if it
7333 supports atomic DDL (i.e. has
7334 HTON_SUPPORTS_ATOMIC_DDL flag set).
7335 These changes will be persisted in the
7336 data-dictionary. Can be NULL for
7337 temporary tables created by optimizer.
7338
7339 @retval 0 Success.
7340 @retval non-0 Error.
7341 */
7342 virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info,
7343 dd::Table *table_def) = 0;
7344
7345 virtual bool get_se_private_data(dd::Table *dd_table [[maybe_unused]],
7346 bool reset [[maybe_unused]]) {
7347 return false;
7348 }
7349
7350 /**
7351 Adjust definition of table to be created by adding implicit columns
7352 and indexes necessary for the storage engine.
7353
7354 @param [in] create_info HA_CREATE_INFO describing the table.
7355 @param [in] create_list List of columns in the table.
7356 @param [in] key_info Array of KEY objects describing table
7357 indexes.
7358 @param [in] key_count Number of indexes in the table.
7359 @param [in,out] table_obj dd::Table object describing the table
7360 to be created. Implicit columns and
7361 indexes are to be added to this object.
7362 Adjusted table description will be
7363 saved into the data-dictionary.
7364
7365 @retval 0 Success.
7366 @retval non-0 Error.
7367 */
7369 const HA_CREATE_INFO *create_info [[maybe_unused]],
7370 const List<Create_field> *create_list [[maybe_unused]],
7371 const KEY *key_info [[maybe_unused]], uint key_count [[maybe_unused]],
7372 dd::Table *table_obj [[maybe_unused]]) {
7373 return 0;
7374 }
7375
7376 virtual bool set_ha_share_ref(Handler_share **arg_ha_share) {
7377 ha_share = arg_ha_share;
7378 return false;
7379 }
7380
7381 void set_ha_table(TABLE *table_arg) { table = table_arg; }
7382
7383 int get_lock_type() const { return m_lock_type; }
7384
7385 /**
7386 Callback function that will be called by my_prepare_gcolumn_template
7387 once the table has been opened.
7388 */
7389 typedef void (*my_gcolumn_template_callback_t)(const TABLE *, void *);
7390 static bool my_prepare_gcolumn_template(THD *thd, const char *db_name,
7391 const char *table_name,
7393 void *ib_table);
7394 static bool my_eval_gcolumn_expr_with_open(THD *thd, const char *db_name,
7395 const char *table_name,
7396 const MY_BITMAP *const fields,
7397 uchar *record,
7398 const char **mv_data_ptr,
7399 ulong *mv_length);
7400
7401 /**
7402 Callback for computing generated column values.
7403
7404 Storage engines that need to have virtual column values for a row
7405 can use this function to get the values computed. The storage
7406 engine must have filled in the values for the base columns that
7407 the virtual columns depend on.
7408
7409 @param thd thread handle
7410 @param table table object
7411 @param fields bitmap of field index of evaluated generated
7412 column
7413 @param[in,out] record buff of base columns generated column depends.
7414 After calling this function, it will be
7415 used to return the value of the generated
7416 columns.
7417 @param[out] mv_data_ptr When given (not null) and the field
7418 needs to be calculated is a typed array field, it
7419 will contain pointer to field's calculated value.
7420 @param[out] mv_length Length of the data above
7421 @param[in] include_stored_gcols if true, evaluate both stored and virtual
7422 gcols. if false, evaluate only virtual gcol.
7423
7424 @retval true in case of error
7425 @retval false on success
7426 */
7427 static bool my_eval_gcolumn_expr(THD *thd, TABLE *table,
7428 const MY_BITMAP *const fields, uchar *record,
7429 const char **mv_data_ptr, ulong *mv_length,
7430 bool include_stored_gcols);
7431
7432 /* This must be implemented if the handlerton's partition_flags() is set. */
7433 virtual Partition_handler *get_partition_handler() { return nullptr; }
7434
7435 /**
7436 Set se_private_id and se_private_data during upgrade
7437
7438 @param thd Pointer of THD
7439 @param dbname Database name
7440 @param table_name Table name
7441 @param dd_table dd::Table for the table
7442 @param table_arg TABLE object for the table.
7443
7444 @return Operation status
7445 @retval false Success
7446 @retval true Error
7447 */
7448
7449 bool ha_upgrade_table(THD *thd, const char *dbname, const char *table_name,
7450 dd::Table *dd_table, TABLE *table_arg);
7451
7452 /**
7453 Store a pointer to the handler of the primary table that
7454 corresponds to the secondary table in this handler.
7455 */
7456 void ha_set_primary_handler(handler *primary_handler);
7457
7458 /**
7459 Get a pointer to a handler for the table in the primary storage
7460 engine, if this handler is for a table in a secondary storage
7461 engine.
7462 */
7464
7465 /**
7466 Return max limits for a single set of multi-valued keys
7467
7468 @param[out] num_keys number of keys to store
7469 @param[out] keys_length total length of keys, bytes
7470 */
7471 void ha_mv_key_capacity(uint *num_keys, size_t *keys_length) const {
7472 return mv_key_capacity(num_keys, keys_length);
7473 }
7474
7475 /**
7476 Propagates the secondary storage engine offload failure reason for a query
7477 to the external engine when the offloaded query fails in the secondary
7478 storage engine.
7479 */
7480 virtual void set_external_table_offload_error(const char * /*reason*/) {}
7481
7482 /**
7483 Identifies and throws the propagated external engine query offload or exec
7484 failure reason given by the external engine handler.
7485 */
7486 virtual void external_table_offload_error() const {}
7487
7488 private:
7489 /**
7490 Engine-specific function for ha_can_store_mv_keys().
7491 Dummy function. SE's overloaded method is used instead.
7492 */
7493 /* purecov: begin inspected */
7494 virtual void mv_key_capacity(uint *num_keys, size_t *keys_length) const {
7495 *num_keys = 0;
7496 *keys_length = 0;
7497 }
7498 /* purecov: end */
7499
7500 /**
7501 Filter duplicate records when multi-valued index is used for retrieval
7502
7503 @returns
7504 true duplicate, such row id was already seen
7505 false row id is seen for the first time
7506 */
7507 bool filter_dup_records();
7508
7509 protected:
7511 void set_ha_share_ptr(Handler_share *arg_ha_share);
7512 void lock_shared_ha_data();
7513 void unlock_shared_ha_data();
7514
7515 friend class DsMrr_impl;
7516};
7517
7518/* Temporary Table handle for opening uncached table */
7520 public:
7522
7523 /** Open the table handler
7524 @param[in] thd Thread object
7525 @param[in] db_name Database name
7526 @param[in] table_name Table name
7527 @return table object or nullptr */
7528 TABLE *open(THD *thd, const char *db_name, const char *table_name);
7529
7531
7532 private:
7534};
7535
7536/**
7537 Function identifies any old data type present in table.
7538
7539 This function was handler::check_old_types().
7540 Function is not part of SE API. It is now converted to
7541 auxiliary standalone function.
7542
7543 @param[in] table TABLE object
7544
7545 @retval 0 ON SUCCESS
7546 @retval error code ON FAILURE
7547*/
7548
7550
7551/*
7552 A Disk-Sweep MRR interface implementation
7553
7554 This implementation makes range (and, in the future, 'ref') scans to read
7555 table rows in disk sweeps.
7556
7557 Currently it is used by MyISAM and InnoDB. Potentially it can be used with
7558 any table handler that has non-clustered indexes and on-disk rows.
7559*/
7560
7562 public:
7563 DsMrr_impl(handler *owner) : h(owner), table(nullptr), h2(nullptr) {}
7564
7566 /*
7567 If ha_reset() has not been called then the h2 dialog might still
7568 exist. This must be closed and deleted (this is the case for
7569 internally created temporary tables).
7570 */
7571 if (h2) reset();
7572 assert(h2 == nullptr);
7573 }
7574
7575 private:
7576 /*
7577 The "owner" handler object (the one that calls dsmrr_XXX functions.
7578 It is used to retrieve full table rows by calling rnd_pos().
7579 */
7580 handler *const h;
7581 TABLE *table; /* Always equal to h->table */
7582
7583 /* Secondary handler object. It is used for scanning the index */
7585
7586 /* Buffer to store rowids, or (rowid, range_id) pairs */
7588 uchar *rowids_buf_cur; /* Current position when reading/writing */
7589 uchar *rowids_buf_last; /* When reading: end of used buffer space */
7590 uchar *rowids_buf_end; /* End of the buffer */
7591
7592 bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
7593
7594 /* true <=> need range association, buffer holds {rowid, range_id} pairs */
7596
7597 bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
7598 public:
7599 /**
7600 Initialize the DsMrr_impl object.
7601
7602 This object is used for both doing default MRR scans and DS-MRR scans.
7603 This function just initializes the object. To do a DS-MRR scan,
7604 this must also be initialized by calling dsmrr_init().
7605
7606 @param table_arg pointer to the TABLE that owns the handler
7607 */
7608
7609 void init(TABLE *table_arg) {
7610 assert(table_arg != nullptr);
7611 table = table_arg;
7612 }
7613
7614 int dsmrr_init(RANGE_SEQ_IF *seq_funcs, void *seq_init_param, uint n_ranges,
7615 uint mode, HANDLER_BUFFER *buf);
7616 void dsmrr_close();
7617
7618 /**
7619 Resets the DS-MRR object to the state it had after being initialized.
7620
7621 If there is an open scan then it will be closed.
7622
7623 This function should be called by handler::ha_reset() which is called
7624 when a statement is completed in order to make the handler object ready
7625 for re-use by a different statement.
7626 */
7627
7628 void reset();
7629 int dsmrr_fill_buffer();
7630 int dsmrr_next(char **range_info);
7631
7632 ha_rows dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
7633 uint *flags, Cost_estimate *cost);
7634
7635 ha_rows dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param,
7636 uint n_ranges, uint *bufsz, uint *flags,
7637 Cost_estimate *cost);
7638
7639 private:
7640 bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz,
7641 Cost_estimate *cost);
7642 bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags,
7643 uint *buffer_size, Cost_estimate *cost);
7644};
7645
7646/* lookups */
7650/**
7651 Resolve handlerton plugin by name, without checking for "DEFAULT" or
7652 HTON_NOT_USER_SELECTABLE.
7653
7654 @param thd Thread context.
7655 @param name Plugin name.
7656
7657 @return plugin or NULL if not found.
7658*/
7661 bool is_temp_table);
7662plugin_ref ha_lock_engine(THD *thd, const handlerton *hton);
7664handler *get_new_handler(TABLE_SHARE *share, bool partitioned, MEM_ROOT *alloc,
7665 handlerton *db_type);
7666handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
7667 bool no_substitute, bool report_error);
7668
7670 THD *thd, const LEX_CSTRING &secondary_engine) noexcept;
7671
7672/**
7673 Get default handlerton, if handler supplied is null.
7674
7675 @param thd Thread context.
7676 @param hton The handlerton passed.
7677
7678 @returns pointer to handlerton.
7679*/
7681 if (!hton) {
7682 hton = ha_checktype(thd, DB_TYPE_UNKNOWN, false, false);
7683 assert(hton);
7684 }
7685 return hton;
7686}
7687
7688static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type) {
7689 return (db_type == nullptr) ? DB_TYPE_UNKNOWN : db_type->db_type;
7690}
7691
7692const char *ha_resolve_storage_engine_name(const handlerton *db_type);
7693
7694static inline bool ha_check_storage_engine_flag(const handlerton *db_type,
7695 uint32 flag) {
7696 return db_type == nullptr ? false : (db_type->flags & flag);
7697}
7698
7699/**
7700 Predicate to determine if a storage engine, represented by a handlerton*, is
7701 enabled.
7702 @note "Enabled" in this context refers only the state of the handlerton
7703 object, and does not consider the disabled_storage_engines system variable.
7704 This leads to the very counter-intuitive and confusing situation that it is
7705 possible for a storage engine to be enabled, but at the same time also be
7706 disabled.
7707 */
7708inline bool ha_storage_engine_is_enabled(const handlerton *db_type) {
7709 return (db_type && db_type->create) ? (db_type->state == SHOW_OPTION_YES)
7710 : false;
7711}
7712
7713/* basic stuff */
7714int ha_init_errors(void);
7715int ha_init(void);
7716void ha_end();
7719
7722void ha_reset_plugin_vars(THD *thd);
7723void ha_close_connection(THD *thd);
7724void ha_kill_connection(THD *thd);
7725/** Invoke handlerton::pre_dd_shutdown() on every storage engine plugin. */
7726void ha_pre_dd_shutdown(void);
7727
7728/**
7729 Flush the log(s) of storage engine(s).
7730
7731 @param binlog_group_flush true if we got invoked by binlog group
7732 commit during flush stage, false in other cases.
7733 @retval false Succeed
7734 @retval true Error
7735*/
7736bool ha_flush_logs(bool binlog_group_flush = false);
7737
7738/**
7739 Call the "drop_database_t" handlerton API for storage engines that
7740 implemented it to drop the database.
7741
7742 @param schema_name name of the database to be dropped.
7743*/
7744void ha_drop_database(const char *schema_name);
7745
7746/**
7747 Call "log_ddl_drop_schema" handletron for
7748 storage engines who implement it.
7749
7750 @param schema_name name of the database to be dropped.
7751 @retval false Succeed
7752 @retval true Error
7753*/
7754bool ha_log_ddl_drop_schema(const char *schema_name);
7755
7756/**
7757 Call "log_ddl_create_schema" handletron for
7758 storage engines who implement it.
7759
7760 @param schema_name name of the database to be dropped.
7761 @retval false Succeed
7762 @retval true Error
7763*/
7764bool ha_log_ddl_create_schema(const char *schema_name);
7765
7766int ha_create_table(THD *thd, const char *path, const char *db,
7767 const char *table_name, HA_CREATE_INFO *create_info,
7768 bool update_create_info, bool is_temp_table,
7770
7771int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
7772 const char *db, const char *alias,
7773 const dd::Table *table_def, bool generate_warning);
7774bool ha_check_reserved_db_name(const char *name);
7775
7776/* statistics and info */
7777bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
7778
7779typedef bool Log_func(THD *, TABLE *, bool, const uchar *, const uchar *);
7780
7781int binlog_log_row(TABLE *table, const uchar *before_record,
7782 const uchar *after_record, Log_func *log_func);
7783
7784/* discovery */
7785int ha_create_table_from_engine(THD *thd, const char *db, const char *name);
7786bool ha_check_if_table_exists(THD *thd, const char *db, const char *name,
7787 bool *exists);
7788int ha_find_files(THD *thd, const char *db, const char *path, const char *wild,
7789 bool dir, List<LEX_STRING> *files);
7790int ha_table_exists_in_engine(THD *thd, const char *db, const char *name);
7791bool ha_check_if_supported_system_table(handlerton *hton, const char *db,
7792 const char *table_name);
7793bool ha_rm_tmp_tables(THD *thd, List<LEX_STRING> *files);
7794bool default_rm_tmp_tables(handlerton *hton, THD *thd, List<LEX_STRING> *files);
7795
7796/* key cache */
7797int ha_init_key_cache(std::string_view name, KEY_CACHE *key_cache);
7798int ha_resize_key_cache(KEY_CACHE *key_cache);
7799int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
7800
7801/* transactions: interface to handlerton functions */
7803int ha_commit_trans(THD *thd, bool all, bool ignore_global_read_lock = false);
7804int ha_commit_attachable(THD *thd);
7805int ha_rollback_trans(THD *thd, bool all);
7806
7807/**
7808 Stage of the recovery process where information is collected from the
7809 storage engines (SE), merged with information from the transaction
7810 coordinator (TC) and transactions states are determined and enforced.
7811
7812 Implemented heuristics is as follows:
7813
7814 1. The `commit_list` parameter contains the set of internally coordinated
7815 transactions that the TC ensures were marked as committed.
7816
7817 2. The `xa_state_list` parameter contains the list of externally
7818 coordinated transactions and their states, as recorded by the TC.
7819
7820 3. For each SE:
7821 a. Collect list of transactions found in `PREPARED_IN_TC` state in the
7822 SE and merge it with the information collected from the TC, in
7823 `xa_state_list`.
7824 b. Retrieve the list of transactions found in prepared state in the
7825 SE.
7826
7827 c. For each internally coordinated transactions found in prepared
7828 state:
7829 1. If the transaction is found in `commit_list`, commit it.
7830 2. If the transaction is NOT found in `commit_list` but
7831 `tc_heuristic_recover = TC_HEURISTIC_RECOVER_COMMIT`, commit it.
7832 3. Otherwise, roll it back.
7833
7834 d. For each externally coordinated transactions found in prepared
7835 state:
7836 1. If the transaction isn't found in `xa_state_list`, roll it back.
7837 2. If the transaction is found in `xa_state_list` in `COMMITTED`
7838 state, commit it.
7839 3. If the transaction is found in `xa_state_list` in `ROLLEDBACK`
7840 state, roll it back.
7841 4. If the transaction is found in `xa_state_list` in `PREPARED`
7842 state, ensure that the transaction state in the SE is
7843 `PREPARED_IN_TC`.
7844
7845 @param commit_list Set of XIDs of internally coordinated transactions
7846 found as been committed in the transaction coordinator
7847 state.
7848 @param xa_state_list Map between XIDs and states of externally
7849 coordinated transactions as found in the internal
7850 transaction coordinator state.
7851
7852 @return 0 if recovery was successful, non-zero otherwise.
7853*/
7854int ha_recover(Xid_commit_list *commit_list = nullptr,
7855 Xa_state_list *xa_state_list = nullptr);
7856
7857/**
7858 Perform SE-specific cleanup after recovery of transactions.
7859
7860 @note SE supporting atomic DDL can use this method to perform
7861 post-DDL actions for DDL statements which were committed
7862 or rolled back during recovery stage.
7863*/
7864void ha_post_recover();
7865
7866/*
7867 transactions: interface to low-level handlerton functions. These are
7868 intended to be used by the transaction coordinators to
7869 commit/prepare/rollback transactions in the engines.
7870*/
7871int ha_commit_low(THD *thd, bool all, bool run_after_commit = true);
7872/**
7873 Prepares the underlying transaction of the THD session object parameter
7874 in the storage engines that participate in the transaction.
7875
7876 In case of failure, an error will be emitted by the function in the case
7877 of internally coordinated transactions. In the case of externally
7878 coordinated transactions (XA), the error treatment must follow the
7879 XA/Open specification and is handled by the `Sql_cmd_xa_prepare` class.
7880
7881 @param thd The THD session object holding the transaction to be prepared.
7882 @param all Whether or not the prepare regards a full transaction or the
7883 statement being executed..
7884
7885 @return 0 if the transaction was successfully prepared, non-zero
7886 otherwise.
7887 */
7888int ha_prepare_low(THD *thd, bool all);
7889int ha_rollback_low(THD *thd, bool all);
7890
7891/* transactions: these functions never call handlerton functions directly */
7892int ha_enable_transaction(THD *thd, bool on);
7893
7894/* savepoints */
7897int ha_savepoint(THD *thd, SAVEPOINT *sv);
7898int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
7899
7900/* these are called by storage engines */
7901void trans_register_ha(THD *thd, bool all, handlerton *ht,
7902 const ulonglong *trxid);
7903
7904int ha_reset_logs(THD *thd);
7905
7906/**
7907 Inform storage engine(s) that a binary log file will be purged and any
7908 references to it should be removed.
7909
7910 The function is called for all purged files, regardless if it is an explicit
7911 PURGE BINARY LOGS statement, or an automatic purge performed by the server.
7912
7913 @note Since function is called with the LOCK_index mutex held the work
7914 performed in this callback should be kept at minimum. One way to defer work is
7915 to schedule work and use the `ha_binlog_index_purge_wait` callback to wait for
7916 completion.
7917
7918 @param thd Thread handle of session purging file. The nullptr value indicates
7919 that purge is done at server startup.
7920 @param file Name of file being purged.
7921 @return Always 0, return value are ignored by caller.
7922*/
7923int ha_binlog_index_purge_file(THD *thd, const char *file);
7924
7925/**
7926 Request the storage engine to complete any operations that were initiated
7927 by `ha_binlog_index_purge_file` and which need to complete
7928 before PURGE BINARY LOGS completes.
7929
7930 The function is called only from PURGE BINARY LOGS. Each PURGE BINARY LOGS
7931 statement will result in 0, 1 or more calls to `ha_binlog_index_purge_file`,
7932 followed by exactly 1 call to `ha_binlog_index_purge_wait`.
7933
7934 @note This function is called without LOCK_index mutex held and thus any
7935 waiting performed will only affect the current session.
7936
7937 @param thd Thread handle of session.
7938*/
7940
7941void ha_reset_slave(THD *thd);
7942void ha_binlog_log_query(THD *thd, handlerton *db_type,
7943 enum_binlog_command binlog_command, const char *query,
7944 size_t query_length, const char *db,
7945 const char *table_name);
7946void ha_acl_notify(THD *thd, class Acl_change_notification *);
7947void ha_binlog_wait(THD *thd);
7948
7949/* It is required by basic binlog features on both MySQL server and libmysqld */
7950int ha_binlog_end(THD *thd);
7951
7952const char *get_canonical_filename(handler *file, const char *path,
7953 char *tmp_path);
7954
7955const char *table_case_name(const HA_CREATE_INFO *info, const char *name);
7956
7957void print_keydup_error(TABLE *table, KEY *key, const char *msg, myf errflag,
7958 const char *org_table_name);
7959void print_keydup_error(TABLE *table, KEY *key, myf errflag,
7960 const char *org_table_name);
7961
7962inline void print_keydup_error(TABLE *table, KEY *key, const char *msg,
7963 myf errflag) {
7964 print_keydup_error(table, key, msg, errflag, nullptr);
7965}
7966inline void print_keydup_error(TABLE *table, KEY *key, myf errflag) {
7967 print_keydup_error(table, key, errflag, nullptr);
7968}
7969
7971
7972bool ha_notify_exclusive_mdl(THD *thd, const MDL_key *mdl_key,
7973 ha_notification_type notification_type,
7974 bool *victimized);
7975bool ha_notify_table_ddl(THD *thd, const MDL_key *mdl_key,
7976 ha_notification_type notification_type,
7977 ha_ddl_type ddl_type, const char *old_db_name,
7978 const char *old_table_name, const char *new_db_name,
7979 const char *new_table_name);
7980
7981std::pair<int, bool> commit_owned_gtids(THD *thd, bool all);
7982bool set_tx_isolation(THD *thd, enum_tx_isolation tx_isolation, bool one_shot);
7984
7985/**
7986 Check if index statistics can be used for an equality range.
7987
7988 Index statistics are suitable for equality ranges when:
7989 1) It is an equality range (EQ_RANGE flag set)
7990 2) It contains no NULL parts (NULL_RANGE flag not set)
7991 3) Index statistics are available for the required keyparts
7992
7993 Ranges of the form "x IS NULL" will not use index statistics because
7994 the number of rows with NULL values are likely to be very different
7995 than the values in the index statistics.
7996
7997 @param table The table structure
7998 @param keyno The index number
7999 @param range_flag The range flags (EQ_RANGE, NULL_RANGE, etc.)
8000 @param keypart_map Bitmap of keyparts used in the range
8001 @param[out] keyparts_used Number of keyparts used (output parameter)
8002
8003 @retval true Index statistics can be used for this range
8004 @retval false Index statistics cannot be used for this range
8005*/
8006bool can_use_index_statistics(const TABLE *table, uint keyno, uint range_flag,
8007 key_part_map keypart_map, int *keyparts_used);
8008
8009/*
8010 This class is used by INFORMATION_SCHEMA.FILES to read SE specific
8011 tablespace dynamic metadata. Some member like m_type and id, is not
8012 really dynamic, but as this information is not stored in data dictionary
8013 in a generic format and still is SE specific Some member like m_type and
8014 id, is not really dynamic, but as this information is not stored in data
8015 dictionary in a generic format and still needs SE specific decision, we
8016 are requesting the same from SE.
8017*/
8018
8020 public:
8022 : m_id(0),
8024 m_free_extents(0),
8025 m_total_extents(0),
8026 m_extent_size(0),
8027 m_initial_size(0),
8028 m_maximum_size(0),
8030 m_version(~0ULL),
8031 m_data_free(0) {}
8032
8048};
8049
8050#endif /* HANDLER_INCLUDED */
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
Services for bulk data conversion and load to SE.
Definition: acl_change_notification.h:32
const std::string db
Definition: acl_change_notification.h:51
Data describing the table being created by CREATE TABLE or altered by ALTER TABLE.
Definition: sql_alter.h:210
Class describing changes to be done by ALTER TABLE.
Definition: handler.h:3525
static const HA_ALTER_FLAGS COALESCE_PARTITION
Definition: handler.h:3642
Alter_info * alter_info
Alter options, fields and keys for the new version of table.
Definition: handler.h:3745
static const HA_ALTER_FLAGS CHANGE_INDEX_OPTION
Change index option in a way which is likely not to require index recreation.
Definition: handler.h:3684
uint key_count
Size of key_info_buffer array.
Definition: handler.h:3781
static const HA_ALTER_FLAGS ALTER_VIRTUAL_COLUMN_TYPE
Definition: handler.h:3584
static const HA_ALTER_FLAGS DROP_PARTITION
Definition: handler.h:3636
static const HA_ALTER_FLAGS ADD_VIRTUAL_COLUMN
Definition: handler.h:3565
const char * unsupported_reason
Can be set by handler to describe why a given operation cannot be done in-place (HA_ALTER_INPLACE_NOT...
Definition: handler.h:3881
KEY * key_info_buffer
Array of KEYs for new version of table - including KEYs to be added.
Definition: handler.h:3778
static const HA_ALTER_FLAGS ADD_FOREIGN_KEY
Definition: handler.h:3615
static const HA_ALTER_FLAGS DROP_COLUMN
Definition: handler.h:3577
static const HA_ALTER_FLAGS ALTER_COLUMN_INDEX_LENGTH
Change in index length such that it does not require index rebuild.
Definition: handler.h:3694
static const HA_ALTER_FLAGS ADD_STORED_GENERATED_COLUMN
Definition: handler.h:3569
static const HA_ALTER_FLAGS ALTER_TABLE_REORG
Definition: handler.h:3648
static const HA_ALTER_FLAGS VALIDATE_VIRTUAL_COLUMN
Definition: handler.h:3677
static const HA_ALTER_FLAGS ADD_SPATIAL_INDEX
Definition: handler.h:3671
static const HA_ALTER_FLAGS DROP_CHECK_CONSTRAINT
Definition: handler.h:3712
static const HA_ALTER_FLAGS ALTER_STORED_GCOL_EXPR
Definition: handler.h:3612
uint virtual_column_add_count
Number of virtual columns to be added.
Definition: handler.h:3819
static const HA_ALTER_FLAGS RECREATE_TABLE
Recreate the table for ALTER TABLE FORCE, ALTER TABLE ENGINE and OPTIMIZE TABLE operations.
Definition: handler.h:3668
static const HA_ALTER_FLAGS STORED_GCOL_REEVAL
Change to one of columns on which stored generated column depends, so its values require re-evaluatio...
Definition: handler.h:3706
static const HA_ALTER_FLAGS ADD_PARTITION
Definition: handler.h:3633
static const HA_ALTER_FLAGS ADD_STORED_BASE_COLUMN
Definition: handler.h:3567
static const HA_ALTER_FLAGS ADD_PK_INDEX
Definition: handler.h:3557
uint index_drop_count
Size of index_drop_buffer array.
Definition: handler.h:3784
ulonglong HA_ALTER_FLAGS
Bits to show in detail what operations the storage engine is to execute.
Definition: handler.h:3542
static const HA_ALTER_FLAGS ALTER_COLUMN_STORAGE_TYPE
Definition: handler.h:3627
static const HA_ALTER_FLAGS ALTER_COLUMN_NAME
Definition: handler.h:3581
static const HA_ALTER_FLAGS ALTER_COLUMN_COLUMN_FORMAT
Definition: handler.h:3630
static const HA_ALTER_FLAGS ALTER_COLUMN_MASKING
Definition: handler.h:3721
static const HA_ALTER_FLAGS ADD_COLUMN
Definition: handler.h:3571
static const HA_ALTER_FLAGS ALTER_REBUILD_PARTITION
Definition: handler.h:3687
static const HA_ALTER_FLAGS ALTER_INDEX_COMMENT
Definition: handler.h:3674
KEY_PAIR * index_rename_buffer
Array of KEY_PAIR objects describing indexes being renamed.
Definition: handler.h:3815
uint index_altered_visibility_count
Size of index_rename_buffer array.
Definition: handler.h:3805
void report_unsupported_error(const char *not_supported, const char *try_instead)
Used after check_if_supported_inplace_alter() to report error if the result does not match the LOCK/A...
Definition: handler.cc:5179
bool error_if_not_empty
Indicates whether operation should fail if table is non-empty.
Definition: handler.h:3761
static const HA_ALTER_FLAGS ADD_CHECK_CONSTRAINT
Definition: handler.h:3709
static const HA_ALTER_FLAGS ALTER_RENAME
Definition: handler.h:3624
void add_renamed_key(KEY *old_key, KEY *new_key)
Add old and new version of key to array of indexes to be renamed.
Definition: handler.h:3926
static const HA_ALTER_FLAGS SUSPEND_CHECK_CONSTRAINT
Definition: handler.h:3715
static const HA_ALTER_FLAGS ALTER_REMOVE_PARTITIONING
Definition: handler.h:3651
static const HA_ALTER_FLAGS ALTER_COLUMN_EQUAL_PACK_LENGTH
Change column datatype in such way that new type has compatible packed representation with old type,...
Definition: handler.h:3593
uint index_add_count
Size of index_add_buffer array.
Definition: handler.h:3793
static const HA_ALTER_FLAGS REORGANIZE_PARTITION
Definition: handler.h:3645
inplace_alter_handler_ctx * handler_ctx
Context information to allow handlers to keep context between in-place alter API calls.
Definition: handler.h:3830
static const HA_ALTER_FLAGS ALTER_VIRTUAL_GCOL_EXPR
Definition: handler.h:3611
static const HA_ALTER_FLAGS ADD_INDEX
Definition: handler.h:3545
static const HA_ALTER_FLAGS DROP_FOREIGN_KEY
Definition: handler.h:3618
uint index_rename_count
Size of index_rename_buffer array.
Definition: handler.h:3802
static const HA_ALTER_FLAGS ADD_UNIQUE_INDEX
Definition: handler.h:3551
HA_CREATE_INFO * create_info
Create options (like MAX_ROWS) for the new version of table.
Definition: handler.h:3732
uint handler_trivial_ctx
Can be set by handler along with handler_ctx.
Definition: handler.h:3867
KEY_PAIR * index_altered_visibility_buffer
Definition: handler.h:3816
static const HA_ALTER_FLAGS DROP_INDEX
Definition: handler.h:3548
static const HA_ALTER_FLAGS ALTER_COLUMN_NOT_NULLABLE
Definition: handler.h:3605
static const HA_ALTER_FLAGS DROP_UNIQUE_INDEX
Definition: handler.h:3554
static const HA_ALTER_FLAGS ALTER_PARTITION
Definition: handler.h:3639
static const HA_ALTER_FLAGS ALTER_COLUMN_NULLABLE
Definition: handler.h:3602
partition_info * modified_part_info
Partition_info taking into account the partition changes to be performed.
Definition: handler.h:3856
HA_ALTER_FLAGS handler_flags
Flags describing in detail which operations the storage engine is to execute.
Definition: handler.h:3848
Alter_inplace_info(HA_CREATE_INFO *create_info_arg, Alter_info *alter_info_arg, bool error_if_not_empty_arg, KEY *key_info_arg, uint key_count_arg, partition_info *modified_part_info_arg)
Definition: handler.h:3883
~Alter_inplace_info()
Definition: handler.h:3909
static const HA_ALTER_FLAGS VIRTUAL_GCOL_REEVAL
Change to one of columns on which virtual generated column depends, so its values require re-evaluati...
Definition: handler.h:3700
void add_added_key(KEY *new_key)
Add key to array of indexes to be added.
Definition: handler.h:3960
void add_altered_index_visibility(KEY *old_key, KEY *new_key)
Definition: handler.h:3934
static const HA_ALTER_FLAGS ALTER_VIRTUAL_COLUMN_ORDER
A virtual column has changed its position.
Definition: handler.h:3596
static const HA_ALTER_FLAGS RENAME_INDEX
Rename index.
Definition: handler.h:3662
uint virtual_column_drop_count
number of virtual columns to be dropped.
Definition: handler.h:3822
void add_modified_key(KEY *old_key, KEY *new_key)
Add old and new version of modified key to arrays of indexes to be dropped and added (correspondingly...
Definition: handler.h:3947
static const HA_ALTER_FLAGS DROP_PK_INDEX
Definition: handler.h:3560
static const HA_ALTER_FLAGS ALTER_STORED_COLUMN_ORDER
A stored column has changed its position (disregarding virtual columns)
Definition: handler.h:3599
bool online
true for online operation (LOCK=NONE)
Definition: handler.h:3859
KEY ** index_drop_buffer
Array of pointers to KEYs to be dropped belonging to the TABLE instance for the old version of the ta...
Definition: handler.h:3790
uint * index_add_buffer
Array of indexes into key_info_buffer for KEYs to be added, sorted in increasing order.
Definition: handler.h:3799
void add_dropped_key(KEY *old_key)
Drop key to array of indexes to be dropped.
Definition: handler.h:3954
static const HA_ALTER_FLAGS CHANGE_CREATE_OPTION
Definition: handler.h:3621
static const HA_ALTER_FLAGS DROP_VIRTUAL_COLUMN
Definition: handler.h:3575
static const HA_ALTER_FLAGS ALTER_COLUMN_VISIBILITY
Definition: handler.h:3718
static const HA_ALTER_FLAGS ALTER_STORED_COLUMN_TYPE
Definition: handler.h:3585
inplace_alter_handler_ctx ** group_commit_ctx
If the table uses several handlers, like ha_partition uses one handler per partition,...
Definition: handler.h:3842
static const HA_ALTER_FLAGS ALTER_COLUMN_DEFAULT
Definition: handler.h:3608
static const HA_ALTER_FLAGS DROP_STORED_COLUMN
Definition: handler.h:3576
static const HA_ALTER_FLAGS ALTER_ALL_PARTITION
Definition: handler.h:3654
Used to store optimizer cost estimates.
Definition: handler.h:4040
Cost_estimate & operator+=(const Cost_estimate &other)
Definition: handler.h:4089
Cost_estimate operator-(const Cost_estimate &other)
Definition: handler.h:4107
void add_import(double add_import_cost)
Add to import cost.
Definition: handler.h:4140
void reset()
Reset all costs to zero.
Definition: handler.h:4072
void set_max_cost()
Set current cost to the maximal double.
Definition: handler.h:4074
Cost_estimate()
Definition: handler.h:4048
void add_cpu(double add_cpu_cost)
Add to CPU cost.
Definition: handler.h:4134
double mem_cost
memory used (bytes)
Definition: handler.h:4045
double io_cost
cost of I/O operations
Definition: handler.h:4042
bool is_max_cost() const
Whether or not the total cost is the maximal double.
Definition: handler.h:4070
void add_mem(double add_mem_cost)
Add to memory cost.
Definition: handler.h:4146
bool operator<(const Cost_estimate &other) const
Definition: handler.h:4123
double get_cpu_cost() const
Definition: handler.h:4053
double get_mem_cost() const
Definition: handler.h:4055
double total_cost() const
Returns sum of time-consuming costs, i.e., not counting memory cost.
Definition: handler.h:4051
double get_io_cost() const
Definition: handler.h:4052
void add_io(double add_io_cost)
Add to IO cost.
Definition: handler.h:4128
double import_cost
cost of remote operations
Definition: handler.h:4044
double cpu_cost
cost of CPU operations
Definition: handler.h:4043
double get_import_cost() const
Definition: handler.h:4054
void multiply(double m)
Multiply io, cpu and import costs by parameter.
Definition: handler.h:4080
bool is_zero() const
Whether or not all costs in the object are zero.
Definition: handler.h:4062
bool operator>(const Cost_estimate &other) const
Definition: handler.h:4119
Cost_estimate operator+(const Cost_estimate &other)
Definition: handler.h:4100
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:51
Definition: discrete_interval.h:41
Definition: handler.h:7561
DsMrr_impl(handler *owner)
Definition: handler.h:7563
bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags, uint *buffer_size, Cost_estimate *cost)
Get cost of DS-MRR scan.
Definition: handler.cc:7249
void reset()
Resets the DS-MRR object to the state it had after being initialized.
Definition: handler.cc:6919
ha_rows dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz, uint *flags, Cost_estimate *cost)
Definition: handler.cc:7061
ha_rows dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint *bufsz, uint *flags, Cost_estimate *cost)
Definition: handler.cc:7090
void dsmrr_close()
Definition: handler.cc:6908
uchar * rowids_buf_end
Definition: handler.h:7590
uchar * rowids_buf_cur
Definition: handler.h:7588
int dsmrr_fill_buffer()
DS-MRR: Fill the buffer with rowids and sort it by rowid.
Definition: handler.cc:6948
uchar * rowids_buf
Definition: handler.h:7587
handler * h2
Definition: handler.h:7584
handler *const h
Definition: handler.h:7580
~DsMrr_impl()
Definition: handler.h:7565
bool use_default_impl
Definition: handler.h:7597
void init(TABLE *table_arg)
Initialize the DsMrr_impl object.
Definition: handler.h:7609
int dsmrr_init(RANGE_SEQ_IF *seq_funcs, void *seq_init_param, uint n_ranges, uint mode, HANDLER_BUFFER *buf)
DS-MRR: Initialize and start MRR scan.
Definition: handler.cc:6731
bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz, Cost_estimate *cost)
DS-MRR Internals: Choose between Default MRR implementation and DS-MRR.
Definition: handler.cc:7152
bool dsmrr_eof
Definition: handler.h:7592
bool is_mrr_assoc
Definition: handler.h:7595
uchar * rowids_buf_last
Definition: handler.h:7589
TABLE * table
Definition: handler.h:7581
int dsmrr_next(char **range_info)
Definition: handler.cc:7015
Definition: field.h:573
Wrapper for struct ft_hints.
Definition: handler.h:4307
uint get_flags() const
Get Ft_hints flags.
Definition: handler.h:4370
void set_hint_flag(uint ft_flag)
Set Ft_hints flag.
Definition: handler.h:4335
double get_op_value() const
Get Ft_hints operation value.
Definition: handler.h:4356
struct ft_hints * get_hints()
Get ft_hints struct.
Definition: handler.h:4377
Ft_hints(uint ft_flags)
Definition: handler.h:4312
ha_rows get_limit() const
Get Ft_hints limit.
Definition: handler.h:4349
enum ft_operation get_op_type() const
Get Ft_hints operation type.
Definition: handler.h:4363
void set_hint_limit(ha_rows ft_limit)
Set Ft_hints limit.
Definition: handler.h:4342
void set_hint_op(enum ft_operation type, double value)
Set comparison operation type and and value for master MATCH function.
Definition: handler.h:4325
struct ft_hints hints
Definition: handler.h:4309
Definition: handler.h:1043
const char * get_source_name()
Get SE source file name.
Definition: handler.h:1134
void set_dest_name(const char *name)
Set SE destination file name.
Definition: handler.h:1146
virtual int file_cbk(Ha_clone_file from_file, uint len)=0
Callback providing data from current position of a file descriptor of specific length.
uint m_desc_len
SE's Serialized descriptor length.
Definition: handler.h:1208
void set_hton(handlerton *hton)
Set current storage engine handlerton.
Definition: handler.h:1088
handlerton * get_hton()
Get current storage engine handlerton.
Definition: handler.h:1092
virtual int buffer_cbk(uchar *from_buffer, uint len)=0
Callback providing data in buffer of specific length.
Ha_clone_cbk()
Constructor to initialize members.
Definition: handler.h:1046
const int HA_CLONE_FILE_CACHE
Data file is opened for read/write with OS buffer cache.
Definition: handler.h:1226
void mark_state_change(uint64_t estimate)
Set state information and notify state change.
Definition: handler.h:1183
bool is_os_buffer_cache() const
Check if the file descriptor is opened for read/write with OS buffer cache.
Definition: handler.h:1167
void set_os_buffer_cache()
Mark that the file descriptor is opened for read/write with OS buffer cache.
Definition: handler.h:1161
const int HA_CLONE_STATE_CHANGE
State change notification by SE.
Definition: handler.h:1235
const char * m_dest_name
Current destination file name.
Definition: handler.h:1214
int m_flag
Flag storing data related options.
Definition: handler.h:1220
void set_source_name(const char *name)
Set SE source file name.
Definition: handler.h:1138
bool is_zero_copy() const
Check if zero copy optimization is suggested.
Definition: handler.h:1173
const char * m_src_name
Current source file name.
Definition: handler.h:1211
bool is_state_change(uint64_t &estimate)
Check if SE notified state change.
Definition: handler.h:1189
uint m_loc_idx
SE index in caller's locator array.
Definition: handler.h:1199
const uchar * get_data_desc(uint *lenp)
Get data descriptor.
Definition: handler.h:1124
uint64_t m_state_estimate
Estimated bytes to be transferred.
Definition: handler.h:1217
const uchar * m_data_desc
SE's Serialized data descriptor.
Definition: handler.h:1205
const char * get_dest_name()
Get SE destination file name.
Definition: handler.h:1142
bool is_secure() const
Check if data needs secure transfer.
Definition: handler.h:1179
void set_zero_copy()
Mark that the file can be transferred with zero copy.
Definition: handler.h:1170
virtual ~Ha_clone_cbk()=default
virtual destructor.
const int HA_CLONE_SECURE
Data needs to be transferred securely over SSL connection.
Definition: handler.h:1232
virtual int apply_buffer_cbk(uchar *&to_buffer, uint &len)=0
Callback to get data in buffer.
uint m_client_buff_size
Caller's transfer buffer size.
Definition: handler.h:1202
virtual int apply_file_cbk(Ha_clone_file to_file)=0
Callback providing a file descriptor to write data starting from current position.
void set_ack()
Mark that ACK is needed for the data transfer before returning from callback.
Definition: handler.h:1153
bool is_ack_needed() const
Check if ACK is needed for the data transfer.
Definition: handler.h:1157
void set_client_buffer_size(uint size)
Set caller's transfer buffer size.
Definition: handler.h:1097
void set_secure()
Mark that data needs secure transfer.
Definition: handler.h:1176
const int HA_CLONE_ACK
Acknowledgement is needed for the data transfer.
Definition: handler.h:1223
void set_loc_index(uint idx)
Set current SE index.
Definition: handler.h:1105
void clear_flags()
Clear all flags set by SE.
Definition: handler.h:1149
handlerton * m_hton
Handlerton for the SE.
Definition: handler.h:1196
uint get_client_buffer_size()
Get caller's transfer buffer size.
Definition: handler.h:1101
uint get_loc_index()
Get current SE index.
Definition: handler.h:1109
const int HA_CLONE_ZERO_COPY
Data file can be transferred with zero copy.
Definition: handler.h:1229
void set_data_desc(const uchar *desc, uint len)
Set data descriptor.
Definition: handler.h:1115
Base class to be used by handlers different shares.
Definition: handler.h:4297
Handler_share()=default
virtual ~Handler_share()=default
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:929
Definition: sql_optimizer.h:133
JSON DOM abstract base class.
Definition: json_dom.h:179
Definition: key.h:57
Definition: key.h:113
const char * name
Name of key.
Definition: key.h:153
bool is_visible
True if this index is visible to the query optimizer.
Definition: key.h:201
Definition: sql_list.h:494
A granted metadata lock.
Definition: mdl.h:988
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: mem_root_allocator.h:68
Definition: overflow_bitset.h:81
Definition: parse_tree_nodes.h:3069
Definition: parse_tree_nodes.h:3092
Class for partitioning specific operations.
Definition: partition_handler.h:194
Class to hold information regarding a table to be created on behalf of a plugin.
Definition: plugin_table.h:40
Class to hold information regarding a predefined tablespace created by a storage engine.
Definition: plugin_table.h:129
This class represents a buffer that can be used for multi-row reads.
Definition: record_buffer.h:47
Implements the row and column memory management for parse and load operations.
Definition: bulk_data_service.h:325
Cost constants for a storage engine.
Definition: opt_costconstants.h:208
Simple intrusive linked list.
Definition: sql_list.h:48
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2958
Definition: handler.h:7519
Temp_table_handle()
Definition: handler.h:7521
~Temp_table_handle()
Definition: handler.cc:8756
TABLE * open(THD *thd, const char *db_name, const char *table_name)
Open the table handler.
Definition: handler.cc:8726
TABLE * table
Definition: handler.h:7533
Unique_on_insert – similar to above, but rejects duplicates on insert, not just on read of the final ...
Definition: uniques.h:123
Class to maintain list of externally coordinated transactions and their current state at recovery.
Definition: handler.h:1283
enum_ha_recover_xa_state add(XID const &xid, enum_ha_recover_xa_state state)
Adds a transaction and state to the underlying map.
Definition: handler.cc:9141
std::map< XID, enum_ha_recover_xa_state, std::less< XID >, Xa_state_list::allocator >::iterator iterator
Definition: handler.h:1290
enum_ha_recover_xa_state find(XID const &to_find)
Searches the underlying map to find an key that corresponds to the parameter.
Definition: handler.cc:9135
static Xa_state_list::instantiation_tuple new_instance()
Factory like method to instantiate all the infra-structure needed to create an Xa_state_list.
Definition: handler.cc:9173
Xa_state_list(Xa_state_list::list &populated_by_tc)
Class constructor.
Definition: handler.cc:9132
std::pair< const XID, enum_ha_recover_xa_state > pair
Definition: handler.h:1285
Xa_state_list::list & m_underlying
The underlying map holding the trx and states.
Definition: handler.h:1362
std::map< XID, enum_ha_recover_xa_state, std::less< XID >, Xa_state_list::allocator > list
Definition: handler.h:1288
std::tuple< std::unique_ptr< MEM_ROOT >, std::unique_ptr< Xa_state_list::allocator >, std::unique_ptr< Xa_state_list::list >, std::unique_ptr< Xa_state_list > > instantiation_tuple
Definition: handler.h:1293
virtual ~Xa_state_list()=default
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:74
Definition: table.h:47
Definition: tablespace.h:56
Definition: handler.h:4265
ha_rows num_distinct_values
Definition: handler.h:4267
ha_column_statistics()
Definition: handler.h:4269
Definition: handler.h:4211
ulonglong index_file_length
Definition: handler.h:4215
uint block_size
Definition: handler.h:4234
ulonglong data_file_length
Definition: handler.h:4213
ulong update_time
Definition: handler.h:4233
ha_rows records
Definition: handler.h:4227
ulonglong max_data_file_length
Definition: handler.h:4214
ulong check_time
Definition: handler.h:4232
time_t create_time
Definition: handler.h:4231
ulonglong max_index_file_length
Definition: handler.h:4216
ulong mean_rec_length
Definition: handler.h:4229
ulonglong auto_increment_value
Definition: handler.h:4218
ha_statistics()
Definition: handler.h:4249
double table_in_mem_estimate
Estimate for how much of the table that is available in a memory buffer.
Definition: handler.h:4247
ulonglong delete_length
Definition: handler.h:4217
uint mrr_length_per_rec
Definition: handler.h:4239
ha_rows deleted
Definition: handler.h:4228
Definition: handler.h:8019
ulonglong m_id
Definition: handler.h:8033
ulonglong m_initial_size
Definition: handler.h:8040
dd::String_type m_row_format
Definition: handler.h:8044
ulonglong m_data_free
Definition: handler.h:8045
ulonglong m_version
Definition: handler.h:8043
dd::String_type m_status
Definition: handler.h:8046
ulonglong m_maximum_size
Definition: handler.h:8041
ulonglong m_logfile_group_number
Definition: handler.h:8036
ulonglong m_free_extents
Definition: handler.h:8037
ha_tablespace_statistics()
Definition: handler.h:8021
ulonglong m_autoextend_size
Definition: handler.h:8042
ulonglong m_total_extents
Definition: handler.h:8038
ulonglong m_extent_size
Definition: handler.h:8039
dd::String_type m_logfile_group_name
Definition: handler.h:8035
dd::String_type m_type
Definition: handler.h:8034
dd::String_type m_extra
Definition: handler.h:8047
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4753
virtual int sample_end(void *scan_ctx)
End sampling.
Definition: handler.cc:3249
KEY_PART_INFO * range_key_part
Definition: handler.h:4813
virtual int ft_read(uchar *)
Definition: handler.h:5987
virtual bool get_foreign_dup_key(char *child_table_name, uint child_table_name_len, char *child_key_name, uint child_key_name_len)
Retrieves the names of the table and the key for which there was a duplicate entry in the case of HA_...
Definition: handler.cc:4772
virtual int repair(THD *, HA_CHECK_OPT *)
In this method check_opt can be modified to specify CHECK option to use to call check() upon the tabl...
Definition: handler.h:7067
ulonglong insert_id_for_cur_row
insert id for the current row (autogenerated; if not autogenerated, it's 0).
Definition: handler.h:4863
virtual bool is_index_algorithm_supported(enum ha_key_alg key_alg) const
Check if SE supports specific key algorithm.
Definition: handler.h:5844
virtual void set_external_table_offload_error(const char *)
Propagates the secondary storage engine offload failure reason for a query to the external engine whe...
Definition: handler.h:7480
virtual double read_time(uint index, uint ranges, ha_rows rows)
The cost of reading a set of ranges from the table using an index to access it.
Definition: handler.h:5492
handler * m_primary_handler
Pointer to the handler of the table in the primary storage engine, if this handler represents a table...
Definition: handler.h:4810
void * Blob_context
Definition: handler.h:4758
virtual ~handler(void)
Definition: handler.h:5014
virtual int open_blob(THD *thd, void *load_ctx, size_t thread_idx, Blob_context &blob_ctx, unsigned char *blobref)
Open a blob for write operation.
Definition: handler.h:5353
int ha_index_init(uint idx, bool sorted)
Initialize use of index.
Definition: handler.cc:3026
virtual int index_prev(uchar *)
Definition: handler.h:5931
virtual FT_INFO * ft_init_ext(uint flags, uint inx, String *key)
Definition: handler.cc:3162
virtual void external_table_offload_error() const
Identifies and throws the propagated external engine query offload or exec failure reason given by th...
Definition: handler.h:7486
virtual uint max_supported_key_length() const
Definition: handler.h:6297
enum handler::@60 inited
const Item * pushed_cond
Definition: handler.h:4842
void set_ha_table(TABLE *table_arg)
Definition: handler.h:7381
Unique_on_insert * m_unique
Definition: handler.h:4978
virtual int check_foreign_constraints(THD *thd, size_t n_threads) const
Check whether all records in the child table satisfy the foreign key constraints.
Definition: handler.h:5256
virtual int reset()
Reset state of file to after 'open'.
Definition: handler.h:7017
virtual int records_from_index(ha_rows *num_rows, uint index)
Number of rows in table counted using the secondary index chosen by optimizer.
Definition: handler.cc:3296
virtual int open(const char *name, int mode, uint test_if_locked, const dd::Table *table_def)=0
virtual int index_first(uchar *)
Definition: handler.h:5934
Handler_share * get_ha_share_ptr()
Get an initialized ha_share.
Definition: handler.cc:8312
bool m_update_generated_read_fields
Some non-virtual ha_* functions, responsible for reading rows, like ha_rnd_pos(), must ensure that vi...
Definition: handler.h:4975
batch_mode_t
Internal state of the batch instrumentation.
Definition: handler.h:4887
@ PSI_BATCH_MODE_STARTING
Batch mode used, before first table io.
Definition: handler.h:4891
@ PSI_BATCH_MODE_STARTED
Batch mode used, after first table io.
Definition: handler.h:4893
@ PSI_BATCH_MODE_NONE
Batch mode not used.
Definition: handler.h:4889
Discrete_interval auto_inc_interval_for_cur_row
Interval returned by get_auto_increment() and being consumed by the inserter.
Definition: handler.h:4868
void restore_auto_increment(ulonglong prev_insert_id)
Definition: handler.h:6225
bool ha_check_and_repair(THD *thd)
Check and repair table: public interface.
Definition: handler.cc:5043
virtual enum ha_key_alg get_default_index_algorithm() const
Get default key algorithm for SE.
Definition: handler.h:5833
double table_in_memory_estimate() const
Return an estimate of how much of the table that is currently stored in main memory.
Definition: handler.cc:6121
virtual const char * table_type() const =0
The following can be called without an open handler.
virtual Cost_estimate read_cost(uint index, double ranges, double rows)
Cost estimate for reading a set of ranges from the table using an index to access it.
Definition: handler.cc:6259
bool in_range_check_pushed_down
Definition: handler.h:4819
uint ranges_in_seq
Definition: handler.h:4780
uint max_key_parts() const
Definition: handler.h:6284
virtual bool primary_key_is_clustered() const
Check if the primary key is clustered or not.
Definition: handler.h:6384
bool m_virt_gcol_in_end_range
Flag which tells if end_range contains a virtual generated column.
Definition: handler.h:4833
int ha_index_next_pushed(uchar *buf)
Definition: handler.cc:3732
ha_statistics stats
Definition: handler.h:4774
void rebind_psi()
Definition: handler.cc:2861
int ha_update_row(const uchar *old_data, uchar *new_data)
Update the current row.
Definition: handler.cc:8233
int ha_delete_all_rows()
Delete all rows: public interface.
Definition: handler.cc:4991
virtual int index_init(uint idx, bool sorted)
Definition: handler.h:6954
virtual int enable_indexes(uint mode)
Enable indexes again.
Definition: handler.h:7295
int check_collation_compatibility()
Check for incompatible collation changes.
Definition: handler.cc:4659
virtual uint lock_count(void) const
Get number of lock objects returned in store_lock.
Definition: handler.h:6340
std::function< void(void *cookie)> Load_end_cbk
This callback is called by each parallel load thread when processing of rows has ended for the adapte...
Definition: handler.h:5215
virtual int bulk_load_end(THD *thd, void *load_ctx, bool is_error)
End bulk load operation.
Definition: handler.h:5399
virtual const TABLE * parent_of_pushed_join() const
If this handler instance is a child in a pushed join sequence returned TABLE instance being my parent...
Definition: handler.h:6478
virtual uint max_supported_key_parts() const
Definition: handler.h:6296
enum_range_scan_direction range_scan_direction
Definition: handler.h:4803
bool eq_range
Definition: handler.h:4814
virtual int disable_indexes(uint mode)
Disable indexes for a while.
Definition: handler.h:7282
virtual uint extra_rec_buf_length() const
Definition: handler.h:5706
key_range * end_range
End value for a range scan.
Definition: handler.h:4828
virtual void init_table_handle_for_HANDLER()
Definition: handler.h:6270
uint active_index
Definition: handler.h:4836
RANGE_SEQ_IF mrr_funcs
Definition: handler.h:4778
int ha_index_last(uchar *buf)
Reads the last row via index.
Definition: handler.cc:3608
virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
Change the internal TABLE_SHARE pointer.
Definition: handler.h:5459
virtual int extra(enum ha_extra_function operation)
Storage engine specific implementation of ha_extra()
Definition: handler.h:6092
virtual void end_bulk_update()
Perform any needed clean-up, no outstanding updates are there at the moment.
Definition: handler.h:5887
int ha_multi_range_read_next(char **range_info)
Definition: handler.cc:6600
int ha_end_bulk_insert()
End bulk insert.
Definition: handler.cc:4964
uint errkey
Definition: handler.h:4834
virtual ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key)
Find number of records in a range.
Definition: handler.h:6024
virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint mode, HANDLER_BUFFER *buf)
Initialize the MRR scan.
Definition: handler.cc:6588
virtual int multi_range_read_next(char **range_info)
Get next record in MRR scan.
Definition: handler.cc:6630
virtual int update_row(const uchar *old_data, uchar *new_data)
Update a single row.
Definition: handler.h:7004
virtual int index_read_pushed(uchar *, const uchar *, key_part_map)
Definition: handler.h:6490
virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info, uint table_changes)
Part of old, deprecated in-place ALTER API.
Definition: handler.h:6500
int ha_enable_indexes(uint mode)
Enable indexes: public interface.
Definition: handler.cc:5069
virtual bool is_fatal_error(int error)
Determine whether an error is fatal or not.
Definition: handler.cc:4304
virtual int sample_next(void *scan_ctx, uchar *buf)
Get the next record for sampling.
Definition: handler.cc:3251
double index_in_memory_estimate(uint keyno) const
Return an estimate of how much of the index that is currently stored in main memory.
Definition: handler.cc:6140
bool filter_dup_records()
Filter duplicate records when multi-valued index is used for retrieval.
Definition: handler.cc:8693
int m_lock_type
The lock type set by when calling::ha_external_lock().
Definition: handler.h:4954
handlerton * ht
Definition: handler.h:4768
virtual bool is_ignorable_error(int error)
Determine whether an error can be ignored or not.
Definition: handler.cc:4279
TABLE_SHARE * table_share
Definition: handler.h:4761
int ha_read_range_next()
Definition: handler.cc:7564
int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info, dd::Table *table_def)
Create a table in the engine: public interface.
Definition: handler.cc:5236
virtual int info(uint flag)=0
General method to gather info from handler.
virtual bool bulk_load_set_source_table_data(void *load_ctx, const std::vector< Bulk_load::Source_table_data > &source_table_data) const
Sets the source table data (table name and key range boundaries) for all loaders.
Definition: handler.h:5288
virtual bool start_read_removal(void)
Start read (before write) removal on the current table.
Definition: handler.h:6124
int ha_sample_end(void *scan_ctx)
End sampling.
Definition: handler.cc:3212
void ha_start_bulk_insert(ha_rows rows)
Start bulk insert.
Definition: handler.cc:4949
int ha_delete_row(const uchar *buf)
Definition: handler.cc:8261
int ha_index_next_same(uchar *buf, const uchar *key, uint keylen)
Reads the next same row via index.
Definition: handler.cc:3644
int ha_index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map)
Definition: handler.cc:3420
virtual void cancel_pushed_idx_cond()
Reset information about pushed index conditions.
Definition: handler.h:6456
int ha_sample_init(void *&scan_ctx, double sampling_percentage, int sampling_seed, enum_sampling_method sampling_method, const bool tablesample)
Initialize sampling.
Definition: handler.cc:3185
virtual size_t bulk_load_available_memory(THD *thd) const
Get the total memory available for bulk load in SE.
Definition: handler.h:5312
virtual void append_create_info(String *packet)
Definition: handler.h:6269
virtual uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const
Definition: handler.h:6298
bool ha_upgrade_table(THD *thd, const char *dbname, const char *table_name, dd::Table *dd_table, TABLE *table_arg)
Set se_private_id and se_private_data during upgrade.
Definition: handler.cc:8603
virtual int check(THD *, HA_CHECK_OPT *)
Definition: handler.h:7060
virtual const Item * cond_push(const Item *cond)
Push condition down to the table handler.
Definition: handler.h:6421
virtual longlong get_memory_buffer_size() const
Return an estimate on the amount of memory the storage engine will use for caching data in memory.
Definition: handler.h:5603
virtual int rnd_next(uchar *buf)=0
virtual void unlock_row()
Unlock last accessed row.
Definition: handler.h:6198
virtual int preload_keys(THD *, HA_CHECK_OPT *)
Definition: handler.h:6256
uint max_keys() const
Definition: handler.h:6281
void ha_statistic_increment(ulonglong System_status_var::*offset) const
Definition: handler.cc:2837
int ha_bulk_update_row(const uchar *old_data, uchar *new_data, uint *dup_key_found)
Bulk update row: public interface.
Definition: handler.cc:4977
virtual double index_only_read_time(uint keynr, double records)
Calculate cost of 'index only' scan for given index and number of records.
Definition: handler.cc:6110
virtual int bulk_load_copy_existing_data(void *load_ctx, size_t thread_idx, Bulk_load::Stat_callbacks &wait_cbk) const
Used during bulk load on a non-empty table, called after the CSV file input is exhausted and we need ...
Definition: handler.h:5269
double m_sampling_percentage
Definition: handler.h:4883
virtual FT_INFO * ft_init_ext_with_hints(uint inx, String *key, Ft_hints *hints)
Definition: handler.h:5974
void set_end_range(const key_range *range, enum_range_scan_direction direction)
Set the end position for a range scan.
Definition: handler.cc:7630
int ha_index_next(uchar *buf)
Reads the next row via index.
Definition: handler.cc:3489
virtual int index_read(uchar *buf, const uchar *key, uint key_len, enum ha_rkey_function find_flag)
Definition: handler.h:7168
int ha_discard_or_import_tablespace(bool discard, dd::Table *table_def)
Discard or import tablespace: public interface.
Definition: handler.cc:5082
uint pushed_idx_cond_keyno
Definition: handler.h:4845
virtual void column_bitmaps_signal()
Signal that the table->read_set and table->write_set table maps changed The handler is allowed to set...
Definition: handler.cc:4106
virtual int close_blob(THD *thd, void *load_ctx, size_t thread_idx, Blob_context blob_ctx, unsigned char *blobref)
Close the blob.
Definition: handler.h:5385
virtual Partition_handler * get_partition_handler()
Definition: handler.h:7433
virtual ha_rows end_read_removal(void)
End read (before write) removal and return the number of rows really written.
Definition: handler.h:6134
HANDLER_BUFFER * multi_range_buffer
Definition: handler.h:4779
const TABLE * get_table() const
Definition: handler.h:5464
uchar * ref
Pointer to current row.
Definition: handler.h:4770
int ha_reset()
Check handler usage and reset state of file to after 'open'.
Definition: handler.cc:8177
virtual int index_next_same(uchar *buf, const uchar *key, uint keylen)
Definition: handler.cc:5303
virtual bool was_semi_consistent_read()
Definition: handler.h:6182
int ha_records(ha_rows *num_rows, uint index)
Wrapper function to call records_from_index() in storage engine.
Definition: handler.h:5802
virtual Cost_estimate index_scan_cost(uint index, double ranges, double rows)
Cost estimate for reading a number of ranges from an index.
Definition: handler.cc:6239
int ha_check(THD *thd, HA_CHECK_OPT *check_opt)
to be actually called to get 'check()' functionality
Definition: handler.cc:4846
virtual int load_table(const TABLE &table, bool *skip_metadata_update)
Loads a table into its defined secondary storage engine.
Definition: handler.h:7138
virtual int index_next(uchar *)
Definition: handler.h:5928
int ha_read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range, bool sorted)
Definition: handler.cc:7545
virtual void update_create_info(HA_CREATE_INFO *create_info)
Update create info as part of ALTER TABLE.
Definition: handler.h:6251
virtual int rnd_end()
Definition: handler.h:6970
uint key_used_on_scan
Definition: handler.h:4835
virtual ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys, uint *bufsz, uint *flags, Cost_estimate *cost)
Get cost and other information about MRR scan over some sequence of ranges.
Definition: handler.cc:6529
@ SAMPLING
Definition: handler.h:4840
@ NONE
Definition: handler.h:4840
@ INDEX
Definition: handler.h:4840
@ RND
Definition: handler.h:4840
virtual Cost_estimate table_scan_cost()
Cost estimate for doing a complete table scan.
Definition: handler.cc:6225
virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0
virtual int external_lock(THD *thd, int lock_type)
Is not invoked for non-transactional temporary tables.
Definition: handler.h:7053
virtual int parallel_scan_init(void *&scan_ctx, size_t *num_threads, bool use_reserved_threads, size_t max_desired_threads)
Initializes a parallel scan.
Definition: handler.h:5165
int ha_extra(enum ha_extra_function operation)
Request storage engine to do an extra operation: enable,disable or run some functionality.
Definition: handler.cc:8699
ulonglong next_insert_id
next_insert_id is the next value which should be inserted into the auto_increment column: in a insert...
Definition: handler.h:4856
virtual bool low_byte_first() const
Definition: handler.h:6306
void ha_set_primary_handler(handler *primary_handler)
Store a pointer to the handler of the primary table that corresponds to the secondary table in this h...
Definition: handler.cc:9012
uint ref_length
Length of ref (1-8 or the clustered key length)
Definition: handler.h:4838
virtual double scan_time()
Definition: handler.h:5473
int ha_analyze(THD *thd, HA_CHECK_OPT *check_opt)
Analyze table: public interface.
Definition: handler.cc:5030
virtual uint max_supported_record_length() const
Definition: handler.h:6294
virtual enum_alter_inplace_result check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_info *ha_alter_info)
Check if a storage engine supports a particular alter table in-place.
Definition: handler.cc:5126
ulonglong Table_flags
Definition: handler.h:4757
virtual void parallel_scan_end(void *scan_ctx)
End of the parallel scan.
Definition: handler.h:5242
bool ha_commit_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit, const dd::Table *old_table_def, dd::Table *new_table_def)
Public function wrapping the actual handler call.
Definition: handler.cc:5101
PSI_table_share * ha_table_share_psi(const TABLE_SHARE *share) const
Acquire the instrumented table information from a table share.
Definition: handler.cc:2895
int get_lock_type() const
Definition: handler.h:7383
std::function< bool(void *cookie, ulong ncols, ulong row_len, const ulong *col_offsets, const ulong *null_byte_offsets, const ulong *null_bitmasks)> Load_init_cbk
This callback is called by each parallel load thread at the beginning of the parallel load for the ad...
Definition: handler.h:5193
Table_flags ha_table_flags() const
The cached_table_flags is set at ha_open and ha_external_lock.
Definition: handler.h:5100
int ha_load_table(const TABLE &table, bool *skip_metadata_update)
Loads a table into its defined secondary storage engine: public interface.
Definition: handler.cc:5254
virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
Definition: handler.h:6097
void ha_drop_table(const char *name)
Drop table in the engine: public interface.
Definition: handler.cc:5223
bool ha_prepare_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const dd::Table *old_table_def, dd::Table *new_table_def)
Public functions wrapping the actual handler call.
Definition: handler.cc:5090
void start_psi_batch_mode()
Put the handler in 'batch' mode when collecting table io instrumented events.
Definition: handler.cc:2874
int ha_index_or_rnd_end()
Definition: handler.h:5094
virtual bool is_crashed() const
Check if the table is crashed.
Definition: handler.h:6316
int ha_truncate(dd::Table *table_def)
Truncate table: public interface.
Definition: handler.cc:5004
virtual int close(void)=0
int ha_index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Read [part of] row via [part of] index.
Definition: handler.cc:3390
int ha_sample_next(void *scan_ctx, uchar *buf)
Get the next record for sampling.
Definition: handler.cc:3223
void unbind_psi()
Definition: handler.cc:2849
virtual int assign_to_keycache(THD *, HA_CHECK_OPT *)
Definition: handler.h:6253
virtual std::string bulk_load_generate_temporary_table_name() const
Generates a temporary table name to be used for table duplication during bulk load.
Definition: handler.h:5279
virtual bool start_bulk_update()
Definition: handler.h:5862
uchar * dup_ref
Pointer to duplicate row.
Definition: handler.h:4772
bool end_psi_batch_mode_if_started()
If a PSI batch was started, turn if off.
Definition: handler.h:4941
virtual ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint *bufsz, uint *flags, bool *force_default_mrr, Cost_estimate *cost)
Get cost and other information about MRR scan over a known list of ranges.
Definition: handler.cc:6360
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt)
Definition: handler.cc:4691
handler * ha_get_primary_handler() const
Get a pointer to a handler for the table in the primary storage engine, if this handler is for a tabl...
Definition: handler.h:7463
bool ha_get_se_private_data(dd::Table *dd_table, bool reset)
Submit a dd::Table object representing a core DD table having hardcoded data to be filled in by the D...
Definition: handler.cc:5273
virtual uint32 calculate_key_hash_value(Field **field_array)
Definition: handler.h:6065
uint max_record_length() const
Definition: handler.h:6278
void unlock_shared_ha_data()
Release lock for protecting ha_share.
Definition: handler.cc:8358
void mark_trx_read_write()
A helper function to mark a transaction read-write, if it is started.
Definition: handler.cc:4872
virtual uint number_of_pushed_joins() const
Reports number of tables included in pushed join which this handler instance is part of.
Definition: handler.h:6466
virtual int sample_init(void *&scan_ctx, double sampling_percentage, int sampling_seed, enum_sampling_method sampling_method, const bool tablesample)
Initialize sampling.
Definition: handler.cc:3244
PSI_table * m_psi
Instrumented table associated with this handler.
Definition: handler.h:4880
virtual int discard_or_import_tablespace(bool discard, dd::Table *table_def)
Discard or import tablespace.
Definition: handler.h:7314
virtual int exec_bulk_update(uint *dup_key_found)
After this call all outstanding updates must be performed.
Definition: handler.h:5879
int update_auto_increment()
Definition: handler.cc:3903
virtual int indexes_are_disabled(void)
Check if indexes are disabled.
Definition: handler.h:6268
Record_buffer * ha_get_record_buffer() const
Get the record buffer that was set with ha_set_record_buffer().
Definition: handler.h:5049
virtual Table_flags table_flags(void) const =0
THD * ha_thd() const
Definition: handler.cc:2842
batch_mode_t m_psi_batch_mode
Batch mode state.
Definition: handler.h:4900
virtual int index_read_last(uchar *buf, const uchar *key, uint key_len)
Definition: handler.h:7174
virtual int start_stmt(THD *thd, thr_lock_type lock_type)
Start a statement when table is locked.
Definition: handler.h:6213
virtual const TABLE * member_of_pushed_join() const
If this handler instance is part of a pushed join sequence returned TABLE instance being root of the ...
Definition: handler.h:6472
virtual int index_next_pushed(uchar *)
Definition: handler.h:6494
FT_INFO * ft_handler
Definition: handler.h:4839
int ha_index_read_pushed(uchar *buf, const uchar *key, key_part_map keypart_map)
Definition: handler.cc:3716
virtual const handlerton * hton_supporting_engine_pushdown()
Get the handlerton of the storage engine if the SE is capable of pushing down some of the AccessPath ...
Definition: handler.h:6116
virtual bool is_record_buffer_wanted(ha_rows *const max_rows) const
Does this handler want to get a Record_buffer for multi-row reads via the ha_set_record_buffer() func...
Definition: handler.h:7090
Handler_share ** ha_share
Pointer where to store/retrieve the Handler_share pointer.
Definition: handler.h:4959
virtual handler * clone(const char *name, MEM_ROOT *mem_root)
Definition: handler.cc:2805
int ha_optimize(THD *thd, HA_CHECK_OPT *check_opt)
Optimize table: public interface.
Definition: handler.cc:5017
Table_flags cached_table_flags
Definition: handler.h:4763
virtual int analyze(THD *, HA_CHECK_OPT *)
Definition: handler.h:7256
int ha_external_lock(THD *thd, int lock_type)
These functions represent the public interface to users of the handler class, hence they are not virt...
Definition: handler.cc:8134
virtual void notify_table_changed(Alter_inplace_info *ha_alter_info)
Notify the storage engine that the table definition has been updated.
Definition: handler.h:6875
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
Definition: handler.h:4981
virtual uint max_supported_keys() const
Definition: handler.h:6295
virtual int records(ha_rows *num_rows)
Number of rows in table.
Definition: handler.cc:3262
virtual int rnd_init(bool scan)=0
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
uint max_key_length() const
Definition: handler.h:6287
range_seq_t mrr_iter
Definition: handler.h:4777
int handle_records_error(int error, ha_rows *num_rows)
Function will handle the error code from call to records() and records_from_index().
Definition: handler.cc:3336
virtual int rename_table(const char *from, const char *to, const dd::Table *from_table_def, dd::Table *to_table_def)
Default rename_table() and delete_table() rename/delete files with a given name and extensions from h...
Definition: handler.cc:4805
int ha_records(ha_rows *num_rows)
Wrapper function to call records() in storage engine.
Definition: handler.h:5790
void lock_shared_ha_data()
Take a lock for protecting shared handler data.
Definition: handler.cc:8348
PSI_table_locker * m_psi_locker
The current event in a batch.
Definition: handler.h:4912
int ha_open(TABLE *table, const char *name, int mode, int test_if_locked, const dd::Table *table_def)
Definition: handler.cc:2925
virtual void start_bulk_insert(ha_rows)
Definition: handler.h:7071
static bool my_prepare_gcolumn_template(THD *thd, const char *db_name, const char *table_name, my_gcolumn_template_callback_t myc, void *ib_table)
Callback to allow InnoDB to prepare a template for generated column processing.
Definition: handler.cc:8625
virtual bool inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const dd::Table *old_table_def, dd::Table *new_table_def)
Alter the table structure in-place with operations specified using HA_ALTER_FLAGS and Alter_inplace_i...
Definition: handler.h:6787
virtual bool bulk_load_check(THD *thd) const
Check if the table is ready for bulk load.
Definition: handler.h:5247
uint get_index(void) const
Definition: handler.h:5856
virtual int read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range_arg, bool sorted)
Read first row between two ranges.
Definition: handler.cc:7515
virtual void * bulk_load_begin(THD *thd, size_t keynr, size_t data_size, size_t memory, size_t num_threads)
Begin parallel bulk data load to the table.
Definition: handler.h:5322
int ha_delete_table(const char *name, const dd::Table *table_def)
Delete table: public interface.
Definition: handler.cc:5210
virtual void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values)
Reserves an interval of auto_increment values from the handler.
Definition: handler.cc:4128
virtual bool prepare_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const dd::Table *old_table_def, dd::Table *new_table_def)
Allows the storage engine to update internal structures with concurrent writes blocked.
Definition: handler.h:6750
std::mt19937 * m_random_number_engine
Definition: handler.h:4882
virtual uint min_record_length(uint options) const
Definition: handler.h:6302
void init()
This is called after create to allow us to set up cached variables.
Definition: handler.h:5032
void set_ha_share_ptr(Handler_share *arg_ha_share)
Set ha_share to be used by all instances of the same table/partition.
Definition: handler.cc:8333
virtual std::string explain_extra() const
Return extra handler specific text for EXPLAIN.
Definition: handler.h:5025
virtual int write_row(uchar *buf)
Write a row.
Definition: handler.h:6992
virtual void try_semi_consistent_read(bool)
Tell the engine whether it should avoid unnecessary lock waits.
Definition: handler.h:6189
enum_range_scan_direction
Definition: handler.h:4794
@ RANGE_SCAN_ASC
Definition: handler.h:4794
@ RANGE_SCAN_DESC
Definition: handler.h:4794
void end_psi_batch_mode()
End a batch started with start_psi_batch_mode.
Definition: handler.cc:2883
void set_next_insert_id(ulonglong id)
Definition: handler.h:6221
virtual int ft_init()
Definition: handler.h:5972
int compare_key_icp(const key_range *range) const
Definition: handler.cc:7714
TABLE * table
Definition: handler.h:4762
void ha_notify_table_changed(Alter_inplace_info *ha_alter_info)
Public function wrapping the actual handler call.
Definition: handler.h:6708
int ha_index_prev(uchar *buf)
Reads the previous row via index.
Definition: handler.cc:3534
int ha_rnd_pos(uchar *buf, uchar *pos)
Read row via random scan from position.
Definition: handler.cc:3142
int ha_index_first(uchar *buf)
Reads the first row via index.
Definition: handler.cc:3570
bool ha_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const dd::Table *old_table_def, dd::Table *new_table_def)
Public function wrapping the actual handler call.
Definition: handler.h:6684
Record_buffer * m_record_buffer
Buffer for multi-row reads.
Definition: handler.h:4797
void ha_release_auto_increment()
Definition: handler.cc:4192
virtual int truncate(dd::Table *table_def)
Quickly remove all rows from a table.
Definition: handler.h:7250
virtual int index_end()
Definition: handler.h:6958
virtual table_map tables_in_pushed_join() const
Definition: handler.h:6482
virtual int delete_all_rows()
Delete all rows in a table.
Definition: handler.h:7215
virtual int rnd_pos_by_record(uchar *record)
This function only works for handlers having HA_PRIMARY_KEY_REQUIRED_FOR_POSITION set.
Definition: handler.h:5995
virtual void drop_table(const char *name)
Definition: handler.cc:4826
virtual int unload_table(const char *db_name, const char *table_name, bool error_if_not_loaded)
Unloads a table from its defined secondary storage engine.
Definition: handler.h:7158
void ha_mv_key_capacity(uint *num_keys, size_t *keys_length) const
Return max limits for a single set of multi-valued keys.
Definition: handler.h:7471
virtual bool bulk_load_get_row_id_range(size_t &min, size_t &max) const
Get the row ID range of the table that we're bulk loading into.
Definition: handler.h:5300
virtual int optimize(THD *, HA_CHECK_OPT *)
Definition: handler.h:7253
int ha_index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Initializes an index and read it.
Definition: handler.cc:3450
virtual int bulk_update_row(const uchar *old_data, uchar *new_data, uint *dup_key_found)
This method is similar to update_row, however the handler doesn't need to execute the updates at this...
Definition: handler.h:7198
virtual bool check_and_repair(THD *thd)
Check and repair the table if necessary.
Definition: handler.h:7271
virtual bool auto_repair() const
Check if the table can be automatically repaired.
Definition: handler.h:6325
virtual int end_bulk_insert()
Definition: handler.h:7072
virtual int index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Positions an index cursor to the index specified in argument.
Definition: handler.cc:7775
virtual bool start_bulk_delete()
Definition: handler.h:5867
uint auto_inc_intervals_count
Number of reserved auto-increment intervals.
Definition: handler.h:4875
void ha_set_record_buffer(Record_buffer *buffer)
Set a record buffer that the storage engine can use for multi-row reads.
Definition: handler.h:5042
virtual ha_checksum checksum() const
Definition: handler.h:6307
virtual void mv_key_capacity(uint *num_keys, size_t *keys_length) const
Engine-specific function for ha_can_store_mv_keys().
Definition: handler.h:7494
static bool my_eval_gcolumn_expr_with_open(THD *thd, const char *db_name, const char *table_name, const MY_BITMAP *const fields, uchar *record, const char **mv_data_ptr, ulong *mv_length)
Callback for generated columns processing.
Definition: handler.cc:8663
virtual bool get_se_private_data(dd::Table *dd_table, bool reset)
Definition: handler.h:7345
int ha_repair(THD *thd, HA_CHECK_OPT *check_opt)
Repair table: public interface.
Definition: handler.cc:4926
int ha_rnd_next(uchar *buf)
Read next row via random scan.
Definition: handler.cc:3111
virtual void position(const uchar *record)=0
void adjust_next_insert_id_after_explicit_value(ulonglong nr)
Definition: handler.cc:3778
void(* my_gcolumn_template_callback_t)(const TABLE *, void *)
Callback function that will be called by my_prepare_gcolumn_template once the table has been opened.
Definition: handler.h:7389
int ha_rnd_end()
End use of random access.
Definition: handler.cc:3089
uint get_dup_key(int error)
Definition: handler.cc:4762
virtual bool upgrade_table(THD *thd, const char *dbname, const char *table_name, dd::Table *dd_table)
Definition: handler.h:7096
int ha_write_row(uchar *buf)
Definition: handler.cc:8205
virtual int delete_table(const char *name, const dd::Table *table_def)
Delete a table.
Definition: handler.cc:4777
virtual int get_extra_columns_and_keys(const HA_CREATE_INFO *create_info, const List< Create_field > *create_list, const KEY *key_info, uint key_count, dd::Table *table_obj)
Adjust definition of table to be created by adding implicit columns and indexes necessary for the sto...
Definition: handler.h:7368
virtual void use_hidden_primary_key()
use_hidden_primary_key() is called in case of an update/delete when (table_flags() and HA_PRIMARY_KEY...
Definition: handler.cc:8296
int ha_ft_read(uchar *buf)
Definition: handler.cc:3169
key_range save_end_range
Definition: handler.h:4802
PSI_table_locker_state m_psi_locker_state
Storage for the event in a batch.
Definition: handler.h:4918
ha_rows estimation_rows_to_insert
Definition: handler.h:4765
virtual int rnd_pos(uchar *buf, uchar *pos)=0
virtual int bulk_load_execute(THD *thd, void *load_ctx, size_t thread_idx, const Rows_mysql &rows, Bulk_load::Stat_callbacks &wait_cbk)
Execute bulk load operation.
Definition: handler.h:5337
bool mrr_is_output_sorted
Definition: handler.h:4782
virtual int index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map)
The following functions works like index_read, but it find the last row with the current key value or...
Definition: handler.h:5947
int ha_close(void)
Close handler.
Definition: handler.cc:2995
uint max_key_part_length(HA_CREATE_INFO *create_info) const
Definition: handler.h:6290
virtual bool set_ha_share_ref(Handler_share **arg_ha_share)
Definition: handler.h:7376
virtual void release_auto_increment()
Definition: handler.h:7057
const TABLE_SHARE * get_table_share() const
Definition: handler.h:5463
virtual int read_range_next()
Read next row between two endpoints.
Definition: handler.cc:7592
int ha_read_first_row(uchar *buf, uint primary_key)
Read first row (only) from a table.
Definition: handler.cc:3686
virtual ha_rows estimate_rows_upper_bound()
Return upper bound of current number of records in the table (max.
Definition: handler.h:5812
bool has_transactions()
Definition: handler.h:5703
virtual int delete_row(const uchar *buf)
Definition: handler.h:7009
Item * pushed_idx_cond
Definition: handler.h:4844
virtual bool is_table_empty() const
Determines whether the table this handler was opened on is empty.
Definition: handler.h:5307
int compare_key_in_buffer(const uchar *buf) const
Check if the key in the given buffer (which is not necessarily TABLE::record[0]) is within range.
Definition: handler.cc:7750
virtual int parallel_scan(void *scan_ctx, void **thread_ctxs, Load_init_cbk init_fn, Load_cbk load_fn, Load_end_cbk end_fn)
Run the parallel read of data.
Definition: handler.h:5230
virtual int check_for_upgrade(HA_CHECK_OPT *)
admin commands - called from mysql_admin_table
Definition: handler.h:7059
int ha_disable_indexes(uint mode)
Disable indexes: public interface.
Definition: handler.cc:5056
double estimate_in_memory_buffer(ulonglong table_index_size) const
Make a guesstimate for how much of a table or index is in a memory buffer in the case where the stora...
Definition: handler.cc:6168
virtual int index_last(uchar *)
Definition: handler.h:5937
virtual double page_read_cost(uint index, double reads)
Cost estimate for doing a number of non-sequentially accesses against the storage engine.
Definition: handler.cc:6278
virtual Item * idx_cond_push(uint keyno, Item *idx_cond)
Push down an index condition to the handler.
Definition: handler.h:6451
int key_compare_result_on_equal
Definition: handler.h:4804
int compare_key(key_range *range)
Compare if found key (in row) is over max-value.
Definition: handler.cc:7673
KEY_MULTI_RANGE mrr_cur_range
Definition: handler.h:4787
bool mrr_have_range
Definition: handler.h:4785
virtual int cmp_ref(const uchar *ref1, const uchar *ref2) const
Compare two positions.
Definition: handler.h:6397
bool ha_is_record_buffer_wanted(ha_rows *const max_rows) const
Does this handler want to get a Record_buffer for multi-row reads via the ha_set_record_buffer() func...
Definition: handler.h:5066
ulonglong m_psi_numrows
The number of rows in the batch.
Definition: handler.h:4906
virtual bool commit_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit, const dd::Table *old_table_def, dd::Table *new_table_def)
Commit or rollback the changes made during prepare_inplace_alter_table() and inplace_alter_table() in...
Definition: handler.h:6845
virtual int end_bulk_delete()
Execute all outstanding deletes and close down the bulk delete.
Definition: handler.h:5894
virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info, dd::Table *table_def)=0
Create table (implementation).
virtual double worst_seek_times(double reads)
Provide an upper cost-limit of doing a specified number of seek-and-read key lookups.
Definition: handler.cc:6292
int ha_rename_table(const char *from, const char *to, const dd::Table *from_table_def, dd::Table *to_table_def)
Rename table: public interface.
Definition: handler.cc:5195
virtual enum row_type get_real_row_type(const HA_CREATE_INFO *create_info) const
Get real row type for the table created based on one specified by user, CREATE TABLE options and SE c...
Definition: handler.h:5820
virtual int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Positions an index cursor to the index specified in the handle ('active_index').
Definition: handler.h:5907
std::function< bool(void *cookie, uint nrows, void *rowdata, uint64_t partition_id)> Load_cbk
This callback is called by each parallel load thread when processing of rows is required for the adap...
Definition: handler.h:5208
int ha_index_end()
End use of index.
Definition: handler.cc:3046
virtual THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type)=0
Is not invoked for non-transactional temporary tables.
int ha_unload_table(const char *db_name, const char *table_name, bool error_if_not_loaded)
Unloads a table from its defined secondary storage engine: public interface.
Definition: handler.cc:5263
int ha_rnd_init(bool scan)
Initialize table for random read or scan.
Definition: handler.cc:3070
static bool my_eval_gcolumn_expr(THD *thd, TABLE *table, const MY_BITMAP *const fields, uchar *record, const char **mv_data_ptr, ulong *mv_length, bool include_stored_gcols)
Callback for computing generated column values.
Definition: handler.cc:8681
virtual bool get_error_message(int error, String *buf)
Return an error message specific to this handler.
Definition: handler.cc:4645
int ha_check_foreign_constraints(THD *thd, size_t n_threads)
Definition: handler.cc:4863
bool implicit_emptied
Definition: handler.h:4841
virtual void print_error(int error, myf errflag)
Print error that we got from handler function.
Definition: handler.cc:4339
virtual int write_blob(THD *thd, void *load_ctx, size_t thread_idx, Blob_context blob_ctx, unsigned char *blobref, const unsigned char *data, size_t data_len)
Write to a blob.
Definition: handler.h:5369
In-place alter handler context.
Definition: handler.h:3508
virtual void set_shared_data(const inplace_alter_handler_ctx *ctx)
Definition: handler.h:3512
virtual ~inplace_alter_handler_ctx()=default
inplace_alter_handler_ctx()=default
Definition: partition_info.h:209
Legacy struct for passing tablespace information to SEs.
Definition: handler.h:893
ts_command_type ts_cmd_type
Definition: handler.h:897
bool wait_until_completed
Definition: handler.h:910
ulonglong undo_buffer_size
Definition: handler.h:903
ulonglong extent_size
Definition: handler.h:902
st_alter_tablespace(const char *tablespace, const char *logfile_group, ts_command_type cmd, enum ts_alter_tablespace_type alter_tablespace_cmd, const char *datafile, const char *undofile, const Tablespace_options &opts)
Proper constructor even for all-public class simplifies initialization and allows members to be const...
Definition: sql_tablespace.cc:93
const char * logfile_group_name
Definition: handler.h:896
ulonglong file_block_size
Definition: handler.h:908
const char * encryption
Definition: handler.h:912
const char * undo_file_name
Definition: handler.h:901
const char * tablespace_name
Definition: handler.h:895
const char * ts_comment
Definition: handler.h:911
std::optional< ulonglong > autoextend_size
Definition: handler.h:906
ulonglong redo_buffer_size
Definition: handler.h:904
ulonglong max_size
Definition: handler.h:907
ulonglong initial_size
Definition: handler.h:905
const char * data_file_name
Definition: handler.h:900
uint nodegroup_id
Definition: handler.h:909
bool is_tablespace_command()
Definition: handler.h:914
A table definition from the master.
Definition: rpl_utility.h:250
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
#define U
Definition: ctype-tis620.cc:73
static bool report_error(THD *thd, int error_code, Sql_condition::enum_severity_level level, Args... args)
Definition: error_handler.cc:291
Some definitions for full-text indices.
ft_operation
Operation types, used in FT_HINTS.
Definition: ft_global.h:99
@ FT_OP_UNDEFINED
Definition: ft_global.h:100
struct PSI_table_locker PSI_table_locker
Definition: psi_table_bits.h:43
struct PSI_table_share PSI_table_share
Definition: psi_table_bits.h:100
struct PSI_table PSI_table
Definition: psi_table_bits.h:107
static int flags[50]
Definition: hp_test1.cc:40
static int flag
Definition: hp_test1.cc:40
static uint keys
Definition: hp_test2.cc:49
#define IN_MEMORY_ESTIMATE_UNKNOWN
If the "in memory estimate" for a table (in ha_statistics.table_in_mem_estimate) or index (in KEY::m_...
Definition: key.h:111
constexpr const LEX_CSTRING NULL_CSTR
Definition: lex_string.h:48
A better implementation of the UNIX ctype(3) library.
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
void destroy_at(T *ptr)
Definition: my_alloc.h:462
This file includes constants used by all storage engines.
#define HA_OPTION_PACK_RECORD
Indicates that storage engine needs to use packed row format.
Definition: my_base.h:607
#define rows2double(A)
Definition: my_base.h:1227
ha_panic_function
Definition: my_base.h:436
ha_key_alg
Definition: my_base.h:98
@ HA_KEY_ALG_SE_SPECIFIC
Used for cases when key algorithm which is supported by SE can't be described by one of other classes...
Definition: my_base.h:107
#define HA_ERR_UNSUPPORTED
unsupported extension used
Definition: my_base.h:942
ha_rkey_function
Definition: my_base.h:78
ulong key_part_map
Definition: my_base.h:1095
my_off_t ha_rows
Definition: my_base.h:1228
ha_extra_function
Definition: my_base.h:185
#define HA_POS_ERROR
Definition: my_base.h:1230
#define HA_ERR_WRONG_COMMAND
Command not supported.
Definition: my_base.h:928
#define HA_OPTION_COMPRESS_RECORD
Flag indicating that table is compressed.
Definition: my_base.h:633
ha_storage_media
Definition: my_base.h:116
@ HA_SM_DEFAULT
Definition: my_base.h:117
Abstraction functions over zlib/intrinsics.
std::uint32_t ha_checksum
Definition: my_checksum.h:106
Header for compiler-dependent features.
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
Utility functions for converting between ulonglong and double.
#define ulonglong2double(A)
Definition: my_double2ulonglong.h:46
Some integer typedefs for easier portability.
int myf
Definition: my_inttypes.h:94
unsigned long long int ulonglong
Definition: my_inttypes.h:56
ulonglong my_off_t
Definition: my_inttypes.h:72
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
uint64_t uint64
Definition: my_inttypes.h:69
uint32_t uint32
Definition: my_inttypes.h:67
Common #defines and includes for file and socket I/O.
constexpr const size_t IO_SIZE
Definition: my_io.h:163
Common header for many mysys elements.
uint64_t table_map
Definition: my_table_map.h:30
void set_my_errno(int my_errno)
Set the MySQL thread-local storage variant of errno.
Definition: my_thr_init.cc:366
static char * query
Definition: myisam_ftdump.cc:47
static HashTable ht
Definition: mysql.cc:162
static bool interrupted
Definition: mysqladmin.cc:73
void error(const char *format,...)
static char * path
Definition: mysqldump.cc:151
struct stats stats
Definition: mysqlslap.cc:241
static Secondary_engine * secondary_engine
Definition: mysqltest.cc:260
static int record
Definition: mysqltest.cc:195
bool is_temp_table(const HA_CREATE_INFO &ci)
Definition: sql_table.cc:237
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
constexpr value_type primary_key
Definition: classic_protocol_constants.h:269
static PFS_engine_table_share_proxy share
Definition: connection_control_pfs_table.cc:92
std::string dir
Double write files location.
Definition: buf0dblwr.cc:81
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:44
unsigned long long Object_id
Definition: object_id.h:31
enum_column_types
Definition: column.h:53
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
Definition: os0file.h:89
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
Definition: hypergraph.cc:30
void print(trx_t *trx, dict_index_t *index, std::ostream &out, ref_t ref, bool fatal)
Print information about the given LOB.
Definition: lob0impl.cc:1319
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:45
Definition: aligned_atomic.h:44
entry::Table Table
Definition: select.h:51
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
ValueType max(X &&first)
Definition: gtid.h:103
std::string join(const detail::range auto &rng, std::string_view delim)
join elements of a range into a string separated by a delimiter.
Definition: string.h:74
size_t size(const char *const c)
Definition: base64.h:46
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313
Definition: options.cc:57
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
mode
Definition: file_handle.h:61
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2724
static int exists(node_address *name, node_list const *nodes, u_int with_uid)
Definition: node_list.cc:107
OverflowBitset is a fixed-size (once allocated) bitmap that is optimized for the common case of few e...
int(* Page_Track_Callback)(MYSQL_THD thd, const unsigned char *buffer, size_t buf_len, int num_pages, void *user_ctx)
Page tracking callback function.
Definition: page_track_service.h:66
struct result result
Definition: result.h:34
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
required uint64 version
Definition: replication_group_member_actions.proto:41
required string type
Definition: replication_group_member_actions.proto:34
ulonglong prev_insert_id(ulonglong nr, struct System_variables *variables)
Computes the largest number X:
Definition: handler.cc:3803
constexpr const uint64_t HA_CREATE_USED_EXTERNAL_FILES
Definition: handler.h:823
void trans_register_ha(THD *thd, bool all, handlerton *ht, const ulonglong *trxid)
Register a storage engine for a transaction.
Definition: handler.cc:1368
bool(* sdi_get_t)(const dd::Tablespace &tablespace, const sdi_key_t *sdi_key, void *sdi, uint64 *sdi_len)
Retrieve SDI for a given SDI key.
Definition: handler.h:1798
int ha_finalize_handlerton(st_plugin_int *plugin)
Definition: handler.cc:734
bool(* ddse_dict_init_t)(dict_init_mode_t dict_init_mode, uint version, List< const dd::Object_table > *DDSE_tables, List< const Plugin_tablespace > *DDSE_tablespaces)
Definition: handler.h:1932
handlerton * ha_checktype(THD *thd, enum legacy_db_type database_type, bool no_substitute, bool report_error)
Use other database handler if databasehandler is not compiled in.
Definition: handler.cc:576
bool(* qc_engine_callback)(THD *thd, const char *table_key, uint key_length, ulonglong *engine_data)
Definition: handler.h:148
int(* savepoint_set_t)(handlerton *hton, THD *thd, void *sv)
sv points to an uninitialized storage area of requested size (see savepoint_offset description)
Definition: handler.h:1401
bool(* show_status_t)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat)
Definition: handler.h:1538
bool(*)(const THD *thd, std::string_view reason) set_secondary_engine_offload_fail_reason_t
Sets a specific secondary engine offload failure reason for a query represented by the thread context...
Definition: handler.h:2570
#define UNDEF_NODEGROUP
Definition: handler.h:860
static const uint32 HTON_FKS_WITH_ANY_PREFIX_SUPPORTING_KEYS
Storage engine supports non-hash keys which have common prefix with the foreign key as supporting key...
Definition: handler.h:3306
int(*)(uint64_t *purge_id) page_track_purge_t
Purge page tracking data.
Definition: handler.h:2776
bool(* sdi_set_t)(handlerton *hton, const dd::Tablespace &tablespace, const dd::Table *table, const sdi_key_t *sdi_key, const void *sdi, uint64 sdi_len)
Insert/Update SDI for a given SDI key.
Definition: handler.h:1813
int ha_rollback_low(THD *thd, bool all)
Definition: handler.cc:2066
bool ha_notify_exclusive_mdl(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type, bool *victimized)
Notify/get permission from all interested storage engines before acquisition or after release of excl...
Definition: handler.cc:8832
size_t num_hton2plugins()
Returns the size of the array holding pointers to plugins.
Definition: handler.cc:243
int ha_find_files(THD *thd, const char *db, const char *path, const char *wild, bool dir, List< LEX_STRING > *files)
Definition: handler.cc:5907
bool(* dict_recover_t)(dict_recovery_mode_t dict_recovery_mode, uint version)
Do recovery in the DDSE as part of initializing the data dictionary.
Definition: handler.h:1985
int(*)(handlerton *hton, THD *thd, const uchar *&loc, uint &loc_len, uint &task_id, Ha_clone_mode mode, const char *data_dir) Clone_apply_begin_t
Begin apply to destination database.
Definition: handler.h:2275
void(* reset_plugin_vars_t)(THD *thd)
Some plugin session variables may require some special handling upon clean up.
Definition: handler.h:1389
constexpr const uint32 SDI_TYPE_TABLE
Id for identifying Table SDIs.
Definition: handler.h:129
void ha_kill_connection(THD *thd)
Definition: handler.cc:1029
enum_ha_recover_xa_state
Enumeration of possible states for externally coordinated transactions (XA).
Definition: handler.h:1263
#define COMPATIBLE_DATA_NO
Definition: handler.h:854
constexpr const decltype(handlerton::flags) HTON_NO_DEFAULT_ENGINE_SUPPORT
Definition: handler.h:3239
std::unordered_set< my_xid, std::hash< my_xid >, std::equal_to< my_xid >, Mem_root_allocator< my_xid > > Xid_commit_list
Single occurrence set of XIDs of internally coordinated transactions found as been committed in the t...
Definition: handler.h:1277
bool(* lock_hton_log_t)(handlerton *hton)
Lock a handlerton (resource) log to collect log information.
Definition: handler.h:2344
Ha_clone_mode
Clone start operation mode.
Definition: handler.h:973
@ HA_CLONE_MODE_ADD_TASK
Add a new task to a running clone operation.
Definition: handler.h:981
@ HA_CLONE_MODE_START
Start a new clone operation.
Definition: handler.h:975
@ HA_CLONE_MODE_MAX
Max value for clone mode.
Definition: handler.h:987
@ HA_CLONE_MODE_VERSION
Get version for transfer data format.
Definition: handler.h:984
@ HA_CLONE_MODE_RESTART
Re-start a clone operation after failure.
Definition: handler.h:978
int(*)(uint64_t *start_id) page_track_start_t
Start page tracking.
Definition: handler.h:2751
static const size_t MAX_FK_NAME_SUFFIX_LENGTH
Maximum possible length of SE-specific suffixes for auto-generated foreign key names.
Definition: handler.h:3330
ha_stat_type
Definition: handler.h:963
@ HA_ENGINE_LOGS
Definition: handler.h:963
@ HA_ENGINE_MUTEX
Definition: handler.h:963
@ HA_ENGINE_STATUS
Definition: handler.h:963
st_plugin_int * remove_hton2plugin(uint slot)
Definition: handler.cc:251
SecondaryEngineGraphSimplificationRequestParameters(*)(THD *thd, const JoinHypergraph &hypergraph, const AccessPath *access_path, int current_subgraph_pairs, int current_subgraph_pairs_limit, bool is_root_access_path, std::string *trace) secondary_engine_check_optimizer_request_t
Hook to evaluate the current hypergraph optimization state in optimization for all the engines,...
Definition: handler.h:2613
static const uint MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT
Options for the START TRANSACTION statement.
Definition: handler.h:648
void(* drop_database_t)(handlerton *hton, const char *db)
Definition: handler.h:1515
int ha_create_table(THD *thd, const char *path, const char *db, const char *table_name, HA_CREATE_INFO *create_info, bool update_create_info, bool is_temp_table, dd::Table *table_def)
Initiates table-file and calls appropriate database-creator.
Definition: handler.cc:5374
std::pair< int, bool > commit_owned_gtids(THD *thd, bool all)
The function computes condition to call gtid persistor wrapper, and executes it.
Definition: handler.cc:1614
int ha_resize_key_cache(KEY_CACHE *key_cache)
Resize key cache.
Definition: handler.cc:5795
std::bitset< HA_CLONE_TYPE_MAX > Ha_clone_flagset
Definition: handler.h:1015
bool ha_log_ddl_create_schema(const char *schema_name)
Call "log_ddl_create_schema" handletron for storage engines who implement it.
Definition: handler.cc:979
bool(*)(THD *thd, LEX *lex) optimize_secondary_engine_t
Optimize a statement for execution on a secondary storage engine.
Definition: handler.h:2403
bool(* notify_alter_table_t)(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type)
Notify/get permission from storage engine before or after execution of ALTER TABLE operation on the t...
Definition: handler.h:2070
bool(* savepoint_rollback_can_release_mdl_t)(handlerton *hton, THD *thd)
Check if storage engine allows to release metadata locks which were acquired after the savepoint if r...
Definition: handler.h:1409
void(* dict_register_dd_table_id_t)(dd::Object_id hard_coded_tables)
Initialize the set of hard coded DD table ids.
Definition: handler.h:1940
ts_command_type
Definition: handler.h:863
@ CREATE_LOGFILE_GROUP
Definition: handler.h:867
@ DROP_UNDO_TABLESPACE
Definition: handler.h:875
@ TS_CMD_NOT_DEFINED
Definition: handler.h:864
@ ALTER_TABLESPACE
Definition: handler.h:866
@ DROP_LOGFILE_GROUP
Definition: handler.h:870
@ ALTER_ACCESS_MODE_TABLESPACE
Definition: handler.h:872
@ ALTER_UNDO_TABLESPACE
Definition: handler.h:874
@ CHANGE_FILE_TABLESPACE
Definition: handler.h:871
@ DROP_TABLESPACE
Definition: handler.h:869
@ CREATE_UNDO_TABLESPACE
Definition: handler.h:873
@ CREATE_TABLESPACE
Definition: handler.h:865
@ ALTER_LOGFILE_GROUP
Definition: handler.h:868
bool(* is_dict_readonly_t)()
Check if the DDSE is started in a way that leaves thd DD being read only.
Definition: handler.h:1835
constexpr const uint64_t HA_CREATE_USED_VERIFY_KEY_CONSTRAINTS
Definition: handler.h:825
int(* recover_t)(handlerton *hton, XA_recover_txn *xid_list, uint len, MEM_ROOT *mem_root)
Definition: handler.h:1427
bool(* get_table_statistics_t)(const char *db_name, const char *table_name, dd::Object_id se_private_id, const dd::Properties &ts_se_private_data, const dd::Properties &tbl_se_private_data, uint flags, ha_statistics *stats)
Retrieve ha_statistics from SE.
Definition: handler.h:2146
#define HA_MAX_REC_LENGTH
Definition: handler.h:633
#define HTON_SUPPORTS_ATOMIC_DDL
Engine supports atomic DDL.
Definition: handler.h:3193
void(*)(void *arg) se_before_rollback_t
Definition: handler.h:2668
bool(* log_ddl_drop_schema_t)(handlerton *hton, const char *schema_name)
Definition: handler.h:1517
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache)
Move all tables from one key cache to another one.
Definition: handler.cc:5816
int(* savepoint_release_t)(handlerton *hton, THD *thd, void *sv)
Definition: handler.h:1412
bool(*)(THD *thd) external_engine_explain_check_t
Checks whether the tables used in an explain query are loaded in the secondary engine.
Definition: handler.h:2530
plugin_ref ha_lock_engine(THD *thd, const handlerton *hton)
Definition: handler.cc:527
int(*)(handlerton *hton, THD *thd, const uchar *loc, uint loc_len, uint task_id, int in_err) Clone_apply_end_t
End apply to destination database.
Definition: handler.h:2299
int(* find_files_t)(handlerton *hton, THD *thd, const char *db, const char *path, const char *wild, bool dir, List< LEX_STRING > *files)
Definition: handler.h:1700
bool(* redo_log_set_state_t)(THD *thd, bool enable)
Enable or Disable SE write ahead logging.
Definition: handler.h:2125
void ha_post_recover()
Perform SE-specific cleanup after recovery of transactions.
Definition: handler.cc:9007
void(* acl_notify_t)(THD *thd, const class Acl_change_notification *notice)
Definition: handler.h:1694
constexpr const decltype(handlerton::flags) HTON_SUPPORTS_BULK_LOAD
Definition: handler.h:3231
int(*)(handlerton *hton, THD *thd, const uchar *loc, uint loc_len, uint task_id, int in_err, Ha_clone_cbk *cbk) Clone_apply_t
Apply data to destination database in chunks via callback.
Definition: handler.h:2288
TYPELIB tx_isolation_typelib
Definition: handler.cc:302
handlerton * ha_default_temp_handlerton(THD *thd)
Return the default storage engine handlerton used for explicitly created temp tables for a thread.
Definition: handler.cc:381
bool(* collect_hton_log_info_t)(handlerton *hton, Json_dom *json)
Collect a handlerton (resource) log information.
Definition: handler.h:2356
int(*)(handlerton *hton, THD *thd) set_prepared_in_tc_t
Instructs the storage engine to mark the externally coordinated transactions held by the THD paramete...
Definition: handler.h:1440
void ha_reset_slave(THD *thd)
Definition: handler.cc:6014
void ha_end()
Definition: handler.cc:925
static enum legacy_db_type ha_legacy_type(const handlerton *db_type)
Definition: handler.h:7688
int(*)(handlerton *hton, THD *thd, const uchar *loc, uint loc_len, uint task_id, int in_err) Clone_end_t
End copy from source database.
Definition: handler.h:2261
int ha_release_savepoint(THD *thd, SAVEPOINT *sv)
Definition: handler.cc:2467
static const uint MYSQL_START_TRANS_OPT_READ_WRITE
Definition: handler.h:652
bool ha_log_ddl_drop_schema(const char *schema_name)
Call "log_ddl_drop_schema" handletron for storage engines who implement it.
Definition: handler.cc:958
int(*)(uint64_t *stop_id) page_track_stop_t
Stop page tracking.
Definition: handler.h:2763
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat)
Definition: handler.cc:7878
bool(* unlock_hton_log_t)(handlerton *hton)
Unlock a handlerton (resource) log after collecting log information.
Definition: handler.h:2350
constexpr const uint64_t HA_CREATE_USED_ENGINE_ATTRIBUTE
Definition: handler.h:805
constexpr const decltype(handlerton::flags) HTON_SUPPORTS_SQL_FK
Definition: handler.h:3251
int(*)(Page_Track_Callback cbk_func, void *cbk_ctx, uint64_t *start_id, uint64_t *stop_id, unsigned char *buffer, size_t buffer_len) page_track_get_page_ids_t
Fetch tracked pages.
Definition: handler.h:2802
plugin_ref ha_resolve_by_name_raw(THD *thd, const LEX_CSTRING &name)
Resolve handlerton plugin by name, without checking for "DEFAULT" or HTON_NOT_USER_SELECTABLE.
Definition: handler.cc:398
constexpr const decltype(handlerton::flags) HTON_SUPPORTS_DISTANCE_SCAN
Engine supports index distance scan.
Definition: handler.h:3234
void ha_binlog_index_purge_wait(THD *thd)
Request the storage engine to complete any operations that were initiated by ha_binlog_index_purge_fi...
Definition: handler.cc:6030
#define HA_ADMIN_NOT_IMPLEMENTED
Definition: handler.h:185
bool(* is_supported_system_table_t)(const char *db, const char *table_name, bool is_sql_layer_system_table)
Check if the given db.tablename is a system table for this SE.
Definition: handler.h:1741
bool ha_rm_tmp_tables(THD *thd, List< LEX_STRING > *files)
Ask all SEs to drop all temporary tables which have been left from previous server run.
Definition: handler.cc:5719
bool(*)(THD *thd, LEX *lex) prepare_secondary_engine_t
Prepare the secondary engine for executing a statement.
Definition: handler.h:2389
#define HA_CAN_REPAIR
Definition: handler.h:384
bool ha_check_if_supported_system_table(handlerton *hton, const char *db, const char *table_name)
Check if a given table is a system table.
Definition: handler.cc:5599
int ha_commit_attachable(THD *thd)
Commit the attachable transaction in storage engines.
Definition: handler.cc:2230
bool ha_secondary_engine_supports_ddl(THD *thd, const LEX_CSTRING &secondary_engine) noexcept
Definition: handler.cc:448
xa_status_code(*)(handlerton *hton, XID *xid) set_prepared_in_tc_by_xid_t
Instructs the storage engine to mark the externally coordinated transactions identified by the XID pa...
Definition: handler.h:1500
int(* close_connection_t)(handlerton *hton, THD *thd)
close_connection is only called if thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need...
Definition: handler.h:1373
const char * tx_isolation_names[]
Definition: handler.cc:300
int check_table_for_old_types(const TABLE *table)
Function identifies any old data type present in table.
Definition: handler.cc:4721
TYPELIB * ha_known_exts()
Definition: handler.cc:7833
bool(* sdi_create_t)(dd::Tablespace *tablespace)
Create SDI in a tablespace.
Definition: handler.h:1752
bool(* dict_init_t)(dict_init_mode_t dict_init_mode, uint version, List< const Plugin_table > *DDSE_tables, List< const Plugin_tablespace > *DDSE_tablespaces)
Initialize the SE for being used to store the DD tables.
Definition: handler.h:1928
int(* panic_t)(handlerton *hton, enum ha_panic_function flag)
Definition: handler.h:1523
constexpr const uint64_t HA_CREATE_USED_SECONDARY_ENGINE_ATTRIBUTE
Definition: handler.h:806
static bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
Definition: handler.h:7694
int ha_prepare_low(THD *thd, bool all)
Prepares the underlying transaction of the THD session object parameter in the storage engines that p...
Definition: handler.cc:2380
ha_ddl_type
Definition: handler.h:965
@ HA_TRUNCATE_DDL
Definition: handler.h:968
@ HA_INVALID_DDL
Definition: handler.h:966
@ HA_ALTER_DDL
Definition: handler.h:967
@ HA_RENAME_DDL
Definition: handler.h:969
int ha_init_key_cache(std::string_view name, KEY_CACHE *key_cache)
Init a key cache if it has not been initied before.
Definition: handler.cc:5776
uint64_t SecondaryEngineFlags
Definition: handler.h:2616
int(* finish_upgrade_t)(THD *thd, bool failed_upgrade)
Finish upgrade process inside storage engines.
Definition: handler.h:1634
void(*)(std::vector< std::pair< uint64_t, bool > > &status) page_track_get_status_t
Fetch the status of the page tracking system.
Definition: handler.h:2829
bool(* rm_tmp_tables_t)(handlerton *hton, THD *thd, List< LEX_STRING > *files)
Drop all temporary tables which have been left from previous server run belonging to this SE.
Definition: handler.h:1850
static const uint32 HTON_FKS_WITH_SUPPORTING_HASH_KEYS
Storage engine supports hash keys as supporting keys for foreign keys.
Definition: handler.h:3293
static const uint MYSQL_START_TRANS_OPT_HIGH_PRIORITY
Definition: handler.h:654
int ha_binlog_index_purge_file(THD *thd, const char *file)
Inform storage engine(s) that a binary log file will be purged and any references to it should be rem...
Definition: handler.cc:6024
#define HTON_SECONDARY_ENGINE_SUPPORTS_DDL
Whether the secondary engine supports DDLs.
Definition: handler.h:3218
bool(* get_index_column_cardinality_t)(const char *db_name, const char *table_name, const char *index_name, uint index_ordinal_position, uint column_ordinal_position, dd::Object_id se_private_id, ulonglong *cardinality)
Retrieve index column cardinality from SE.
Definition: handler.h:2185
bool(*)(const SecondaryEngineNrowsParameters &params) secondary_engine_nrows_t
Type for signature generation and for retrieving nrows estimate from secondary engine for current Acc...
Definition: handler.h:2520
bool default_rm_tmp_tables(handlerton *hton, THD *thd, List< LEX_STRING > *files)
Default implementation for handlerton::rm_tmp_tables() method which simply removes all files from "fi...
Definition: handler.cc:5731
enum_alter_inplace_result
Return values for check_if_supported_inplace_alter().
Definition: handler.h:207
@ HA_ALTER_INPLACE_NOT_SUPPORTED
Definition: handler.h:209
@ HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE
Definition: handler.h:213
@ HA_ALTER_INPLACE_INSTANT
Definition: handler.h:215
@ HA_ALTER_INPLACE_SHARED_LOCK
Definition: handler.h:212
@ HA_ALTER_INPLACE_NO_LOCK
Definition: handler.h:214
@ HA_ALTER_INPLACE_EXCLUSIVE_LOCK
Definition: handler.h:210
@ HA_ALTER_ERROR
Definition: handler.h:208
@ HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE
Definition: handler.h:211
constexpr const decltype(handlerton::flags) HTON_SUPPORTS_ENGINE_ATTRIBUTE
Definition: handler.h:3207
bool Log_func(THD *, TABLE *, bool, const uchar *, const uchar *)
Definition: handler.h:7779
bool hton_is_secondary_engine(const handlerton *hton)
Definition: handler.h:3246
void(*)(struct HA_CREATE_INFO *create_info, const char *db, const char *table_name) notify_create_table_t
Notify plugins when a table is created.
Definition: handler.h:2685
static const uint MYSQL_START_TRANS_OPT_READ_ONLY
Definition: handler.h:650
void(* kill_connection_t)(handlerton *hton, THD *thd)
Terminate connection/statement notification.
Definition: handler.h:1376
uint calculate_key_len(TABLE *table, uint key, key_part_map keypart_map)
Calculates length of key.
Definition: handler.cc:7787
int(* prepare_t)(handlerton *hton, THD *thd, bool all)
Definition: handler.h:1425
bool(* sdi_drop_t)(dd::Tablespace *tablespace)
Drop SDI in a tablespace.
Definition: handler.h:1761
void print_keydup_error(TABLE *table, KEY *key, const char *msg, myf errflag, const char *org_table_name)
Construct and emit duplicate key error message using information from table's record buffer.
Definition: handler.cc:4227
int ha_init(void)
Definition: handler.cc:910
int(* alter_tablespace_t)(handlerton *hton, THD *thd, st_alter_tablespace *ts_info, const dd::Tablespace *old_ts_def, dd::Tablespace *new_ts_def)
Create/drop or alter tablespace in the storage engine.
Definition: handler.h:1583
int ha_enable_transaction(THD *thd, bool on)
Tell the storage engine that it is allowed to "disable transaction" in the handler.
Definition: handler.cc:5285
bool secondary_engine_supports_ddl(const handlerton *hton)
Definition: handler.h:3255
Ha_clone_type
Clone operation types.
Definition: handler.h:991
@ HA_CLONE_BLOCKING
Caller must block all write operation to the SE.
Definition: handler.h:993
@ HA_CLONE_RESTART
SE supports restarting clone after network failure.
Definition: handler.h:1009
@ HA_CLONE_HYBRID
For transactional SE, use both page tracking and redo to optimize clone with concurrent dml.
Definition: handler.h:1003
@ HA_CLONE_MULTI_TASK
SE supports multiple threads for clone.
Definition: handler.h:1006
@ HA_CLONE_TYPE_MAX
Maximum value of clone type.
Definition: handler.h:1012
@ HA_CLONE_PAGE
For transactional SE, track page changes to support concurrent dml.
Definition: handler.h:999
@ HA_CLONE_REDO
For transactional SE, archive redo to support concurrent dml.
Definition: handler.h:996
enum_schema_tables
Definition: handler.h:946
@ SCH_OPTIMIZER_TRACE
Definition: handler.h:951
@ SCH_ENGINES
Definition: handler.h:949
@ SCH_TABLE_PRIVILEGES
Definition: handler.h:956
@ SCH_COLUMN_PRIVILEGES
Definition: handler.h:948
@ SCH_SCHEMA_PRIVILEGES
Definition: handler.h:955
@ SCH_PLUGINS
Definition: handler.h:952
@ SCH_PROFILES
Definition: handler.h:954
@ SCH_LAST
Definition: handler.h:960
@ SCH_TMP_TABLE_KEYS
Definition: handler.h:959
@ SCH_USER_PRIVILEGES
Definition: handler.h:957
@ SCH_PROCESSLIST
Definition: handler.h:953
@ SCH_OPEN_TABLES
Definition: handler.h:950
@ SCH_TMP_TABLE_COLUMNS
Definition: handler.h:958
@ SCH_FIRST
Definition: handler.h:947
constexpr const uint64_t HA_CREATE_USED_AUTOEXTEND_SIZE
These flags convey that the options AUTOEXTEND_SIZE has been specified in the CREATE TABLE statement.
Definition: handler.h:819
bool(* get_tablespace_type_by_name_t)(const char *tablespace_name, Tablespace_type *space_type)
Get the tablespace type given the name, from the SE.
Definition: handler.h:1680
bool ha_check_if_table_exists(THD *thd, const char *db, const char *name, bool *exists)
Try to find a table in a storage engine.
Definition: handler.cc:5536
void(*)(void *arg) se_after_commit_t
Definition: handler.h:2664
std::vector< sdi_key_t > sdi_container
Definition: handler.h:143
st_plugin_int * hton2plugin(uint slot)
Maps from slot to plugin. May return NULL if plugin has been unloaded.
Definition: handler.cc:241
st_plugin_int * insert_hton2plugin(uint slot, st_plugin_int *plugin)
For unit testing.
Definition: handler.cc:245
SecondaryEngineFlag
Definition: handler.h:2617
@ USE_EXTERNAL_EXECUTOR
This flag can be set to signal that a secondary storage engine will not use MySQL's executor (see JOI...
void ha_pre_dd_shutdown(void)
Invoke handlerton::pre_dd_shutdown() on every storage engine plugin.
Definition: handler.cc:1057
void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, Cost_estimate *cost)
Get cost of reading nrows table records in a "disk sweep".
Definition: handler.cc:7425
plugin_ref ha_default_temp_plugin(THD *thd)
Definition: handler.cc:363
constexpr const decltype(handlerton::flags) HTON_SUPPORTS_GENERATED_INVISIBLE_PK
Engine supports Generated invisible primary key.
Definition: handler.h:3213
bool(* get_tablespace_type_t)(const dd::Tablespace &space, Tablespace_type *space_type)
Get the tablespace type from the SE.
Definition: handler.h:1668
bool(* rotate_encryption_master_key_t)(void)
Initiate master key rotation.
Definition: handler.h:2114
void(* post_recover_t)(void)
Perform SE-specific cleanup after recovery of transactions.
Definition: handler.h:2338
bool(* notify_rename_table_t)(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type, const char *old_db_name, const char *old_table_name, const char *new_db_name, const char *new_table_name)
Notify/get permission from storage engine before or after execution of RENAME TABLE operation on the ...
Definition: handler.h:2087
int ha_commit_trans(THD *thd, bool all, bool ignore_global_read_lock=false)
Definition: handler.cc:1686
#define HTON_IS_SECONDARY_ENGINE
Engine is a secondary storage engine.
Definition: handler.h:3199
int(* start_consistent_snapshot_t)(handlerton *hton, THD *thd)
Definition: handler.h:1525
enum_stats_auto_recalc
Definition: handler.h:3347
@ HA_STATS_AUTO_RECALC_DEFAULT
Definition: handler.h:3348
@ HA_STATS_AUTO_RECALC_OFF
Definition: handler.h:3350
@ HA_STATS_AUTO_RECALC_ON
Definition: handler.h:3349
const char *(* get_tablespace_filename_ext_t)()
SE interface for getting tablespace extension.
Definition: handler.h:1592
ts_alter_tablespace_type
Definition: handler.h:878
@ TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED
Definition: handler.h:879
@ ALTER_UNDO_TABLESPACE_SET_ACTIVE
Definition: handler.h:884
@ ALTER_UNDO_TABLESPACE_SET_INACTIVE
Definition: handler.h:885
@ ALTER_TABLESPACE_OPTIONS
Definition: handler.h:883
@ ALTER_TABLESPACE_DROP_FILE
Definition: handler.h:881
@ ALTER_TABLESPACE_RENAME
Definition: handler.h:882
@ ALTER_TABLESPACE_ADD_FILE
Definition: handler.h:880
void(* binlog_log_query_t)(handlerton *hton, THD *thd, enum_binlog_command binlog_command, const char *query, uint query_length, const char *db, const char *table_name)
Definition: handler.h:1689
xa_status_code(* commit_by_xid_t)(handlerton *hton, XID *xid)
Definition: handler.h:1490
bool is_index_access_error(int error)
Check whether an error is index access error or not after an index read.
Definition: handler.cc:9118
plugin_ref ha_resolve_by_name(THD *thd, const LEX_CSTRING *name, bool is_temp_table)
Return the storage engine handlerton for the supplied name.
Definition: handler.cc:413
void(* replace_native_transaction_in_thd_t)(THD *thd, void *new_trx_arg, void **ptr_trx_arg)
Definition: handler.h:1892
constexpr const uint64_t HA_CREATE_USED_READ_ONLY
ALTER SCHEMA|DATABASE has an explicit READ_ONLY clause.
Definition: handler.h:813
bool(*)(THD *thd, std::string_view db_name, std::string_view table_name, std::string_view view_def) notify_materialized_view_usage_t
Notify plugins when a materialized view is referenced in a query.
Definition: handler.h:2702
constexpr const uint64_t HA_CREATE_USED_EXPLICIT_ENGINE
These flags indicate that ENGINE/SECONDARY_ENGINE were set explicitly (not by EXTERNAL keyword defaul...
Definition: handler.h:834
bool(* sdi_delete_t)(const dd::Tablespace &tablespace, const dd::Table *table, const sdi_key_t *sdi_key)
Delete SDI for a given SDI key.
Definition: handler.h:1826
std::string_view(*)(THD *thd) find_secondary_engine_offload_fail_reason_t
Finds and returns a specific secondary engine query offload failure reason as a string given a thread...
Definition: handler.h:2556
bool(* get_tablespace_statistics_t)(const char *tablespace_name, const char *file_name, const dd::Properties &ts_se_private_data, ha_tablespace_statistics *stats)
Retrieve ha_tablespace_statistics from SE.
Definition: handler.h:2205
SecondaryEngineGraphSimplificationRequest
Definition: handler.h:2572
@ kRestart
Trigger restart of hypergraph with provided number of subgraph pairs.
@ kContinue
Continue optimization phase with current hypergraph.
int(* discover_t)(handlerton *hton, THD *thd, const char *db, const char *name, uchar **frmblob, size_t *frmlen)
Definition: handler.h:1697
ulong total_ha_2pc
Definition: handler.cc:271
int(* table_exists_in_engine_t)(handlerton *hton, THD *thd, const char *db, const char *name)
Definition: handler.h:1704
enum_binlog_command
Definition: handler.h:713
@ LOGCOM_DROP_TABLE
Definition: handler.h:717
@ LOGCOM_CREATE_DB
Definition: handler.h:718
@ LOGCOM_DROP_DB
Definition: handler.h:720
@ LOGCOM_RENAME_TABLE
Definition: handler.h:716
@ LOGCOM_ALTER_TABLE
Definition: handler.h:715
@ LOGCOM_ALTER_DB
Definition: handler.h:719
@ LOGCOM_CREATE_TABLE
Definition: handler.h:714
static const uint32 HTON_FKS_NEED_DIFFERENT_PARENT_AND_SUPPORTING_KEYS
Storage engine does not support using the same key for both parent and supporting key,...
Definition: handler.h:3313
bool set_tx_isolation(THD *thd, enum_tx_isolation tx_isolation, bool one_shot)
Set the transaction isolation level for the next transaction and update session tracker information a...
Definition: handler.cc:8962
bool ha_is_storage_engine_disabled(handlerton *se_engine)
Definition: handler.cc:522
const char * ha_row_type[]
Definition: handler.cc:289
bool ha_notify_table_ddl(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type, ha_ddl_type ddl_type, const char *old_db_name, const char *old_table_name, const char *new_db_name, const char *new_table_name)
Notify/get permission from all interested storage engines before or after executed DDL (ALTER TABLE,...
Definition: handler.cc:8930
handlerton * ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
Definition: handler.cc:558
std::string_view(*)(const THD *thd) get_secondary_engine_offload_or_exec_fail_reason_t
Looks up and returns a specific secondary engine query offload or exec failure reason as a string giv...
Definition: handler.h:2544
std::optional< ha_column_statistics >(* get_column_statistics_t)(THD *thd, const char *db_name, const char *table_name, const char *column_name, double rows_in_table)
Retrieve column_statistics from SE.
Definition: handler.h:2162
handler * get_new_handler(TABLE_SHARE *share, bool partitioned, MEM_ROOT *alloc, handlerton *db_type)
Create handler object for the table in the storage engine.
Definition: handler.cc:614
std::atomic< const char * > default_secondary_engine_name
Store the name of default secondary engine, if any.
Definition: handler.cc:9025
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION
Definition: handler.h:304
enum_tx_isolation
Definition: handler.h:3340
@ ISO_READ_UNCOMMITTED
Definition: handler.h:3341
@ ISO_REPEATABLE_READ
Definition: handler.h:3343
@ ISO_READ_COMMITTED
Definition: handler.h:3342
@ ISO_SERIALIZABLE
Definition: handler.h:3344
bool(* notify_truncate_table_t)(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type)
Notify/get permission from storage engine before or after execution of TRUNCATE TABLE operation on th...
Definition: handler.h:2104
void(* pre_dd_shutdown_t)(handlerton *hton)
Shut down all storage engine background tasks that might access the data dictionary,...
Definition: handler.h:1382
const char * ha_resolve_storage_engine_name(const handlerton *db_type)
Definition: handler.cc:258
bool(* flush_logs_t)(handlerton *hton, bool binlog_group_flush)
Flush the log(s) of storage engine(s).
Definition: handler.h:1536
bool ha_check_reserved_db_name(const char *name)
Check if the database name is reserved word used by SE.
Definition: handler.cc:9101
const char * table_case_name(const HA_CREATE_INFO *info, const char *name)
Definition: handler.cc:4210
const char * get_canonical_filename(handler *file, const char *path, char *tmp_path)
make canonical filename
Definition: handler.cc:2562
bool can_use_index_statistics(const TABLE *table, uint keyno, uint range_flag, key_part_map keypart_map, int *keyparts_used)
Check if index statistics can be used for an equality range.
Definition: handler.cc:9122
bool(* dict_set_server_version_t)()
Store the current server version number into the header of the dictionary tablespace.
Definition: handler.h:2005
bool(* log_ddl_create_schema_t)(handlerton *hton, const char *schema_name)
Definition: handler.h:1520
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv)
Definition: handler.cc:2316
int(*)(THD *thd, AccessPath *query, JOIN *join) push_to_engine_t
Let storage engine inspect the query Accesspath and pick whatever it like for being pushed down to th...
Definition: handler.h:1724
int ha_panic(enum ha_panic_function flag)
int(* commit_t)(handlerton *hton, THD *thd, bool all)
'all' is true if it's a real commit, that makes persistent changes 'all' is false if it's not in fact...
Definition: handler.h:1421
int ha_recover(Xid_commit_list *commit_list=nullptr, Xa_state_list *xa_state_list=nullptr)
Stage of the recovery process where information is collected from the storage engines (SE),...
Definition: xa.cc:270
int ha_delete_table(THD *thd, handlerton *db_type, const char *path, const char *db, const char *alias, const dd::Table *table_def, bool generate_warning)
Delete table from the storage engine.
Definition: handler.cc:2609
constexpr const decltype(handlerton::flags) HTON_SECONDARY_SUPPORTS_TEMPORARY_TABLE(1<< 25)
Whether the secondary engine supports creation of temporary tables.
static const uint32 HTON_FKS_WITH_EXTENDED_PARENT_KEYS
Engine takes into account hidden part of key (coming from primary key) when determines if it can serv...
Definition: handler.h:3324
row_type
Definition: handler.h:692
@ ROW_TYPE_COMPRESSED
Definition: handler.h:697
@ ROW_TYPE_REDUNDANT
Definition: handler.h:698
@ ROW_TYPE_NOT_USED
Definition: handler.h:693
@ ROW_TYPE_FIXED
Definition: handler.h:695
@ ROW_TYPE_PAGED
Unused.
Definition: handler.h:701
@ ROW_TYPE_DEFAULT
Definition: handler.h:694
@ ROW_TYPE_COMPACT
Definition: handler.h:699
@ ROW_TYPE_DYNAMIC
Definition: handler.h:696
bool() stat_print_fn(THD *thd, const char *type, size_t type_len, const char *file, size_t file_len, const char *status, size_t status_len)
Definition: handler.h:151
void ha_drop_database(const char *schema_name)
Call the "drop_database_t" handlerton API for storage engines that implemented it to drop the databas...
Definition: handler.cc:939
const handlerton * SecondaryEngineHandlerton(const THD *thd)
Returns the handlerton of the secondary engine that is used in the session, or nullptr if a secondary...
Definition: handler.cc:9018
static const LEX_CSTRING FK_NAME_DEFAULT_SUFFIX
Suffix for auto-generated foreign key names for tables in SE's which don't specify own suffix.
Definition: handler.h:3338
handlerton * ha_default_handlerton(THD *thd)
Return the default storage engine handlerton used for non-temp tables for thread.
Definition: handler.cc:355
int ha_savepoint(THD *thd, SAVEPOINT *sv)
Definition: handler.cc:2424
void(*)(THD *thd, SelectExecutedIn executed_in) notify_after_select_t
Notify plugins when a SELECT query was executed.
Definition: handler.h:2679
void ha_close_connection(THD *thd)
Definition: handler.cc:1014
int(*)(handlerton *hton, THD *thd, const uchar *&loc, uint &loc_len, uint &task_id, Ha_clone_type type, Ha_clone_mode mode) Clone_begin_t
Begin copy from source database.
Definition: handler.h:2226
int(* upgrade_logs_t)(THD *thd)
Upgrade logs after the checkpoint from where upgrade process can only roll forward.
Definition: handler.h:1648
bool(* is_reserved_db_name_t)(handlerton *hton, const char *name)
Definition: handler.h:2375
int(* savepoint_rollback_t)(handlerton *hton, THD *thd, void *sv)
sv points to a storage area, that was earlier passed to the savepoint_set call
Definition: handler.h:1395
void(*)(Ha_clone_flagset &flags) Clone_capability_t
Get capability flags for clone operation.
Definition: handler.h:2213
int ha_binlog_end(THD *thd)
Definition: handler.cc:6076
bool(*)(THD *thd) secondary_engine_pre_prepare_hook_t
Secondary engine hook called after PRIMARY_TENTATIVELY optimization is complete, and decides if secon...
Definition: handler.h:2715
constexpr const uint64_t HA_CREATE_USED_FILE_FORMAT
Table options for external tables.
Definition: handler.h:822
void(*)(Table_ref *tab) notify_drop_table_t
Notify plugins when a table is dropped.
Definition: handler.h:2730
const char * binlog_format_names[]
Definition: mysqld.cc:1355
constexpr const uint64_t HA_CREATE_USED_START_TRANSACTION
This option is used to convey that the create table should not commit the operation and keep the tran...
Definition: handler.h:803
int(*)(uint64_t *start_id, uint64_t *stop_id, uint64_t *num_pages) page_track_get_num_page_ids_t
Fetch approximate number of tracked pages in the given range.
Definition: handler.h:2823
int(*)(handlerton *hton, THD *thd, const uchar *loc, uint loc_len, uint task_id, Ha_clone_cbk *cbk) Clone_copy_t
Copy data from source database in chunks via callback.
Definition: handler.h:2237
xa_status_code
X/Open XA distributed transaction status codes.
Definition: handler.h:1443
@ XAER_ASYNC
asynchronous operation already outstanding
Definition: handler.h:1452
@ XAER_PROTO
routine invoked in an improper context
Definition: handler.h:1472
@ XAER_INVAL
invalid arguments were given
Definition: handler.h:1467
@ XAER_NOTA
the XID is not valid
Definition: handler.h:1462
@ XAER_OUTSIDE
resource manager doing work outside transaction
Definition: handler.h:1487
@ XAER_RMFAIL
resource manager unavailable
Definition: handler.h:1477
@ XA_OK
normal execution
Definition: handler.h:1447
@ XAER_DUPID
the XID already exists
Definition: handler.h:1482
@ XAER_RMERR
a resource manager error occurred in the transaction branch
Definition: handler.h:1457
void ha_binlog_wait(THD *thd)
Definition: handler.cc:6019
constexpr const uint64_t HA_CREATE_USED_ALLOW_MISSING_FILES
Definition: handler.h:824
bool(* dict_get_server_version_t)(uint *version)
Get the server version id stored in the header of the dictionary tablespace.
Definition: handler.h:1997
void ha_reset_plugin_vars(THD *thd)
Definition: handler.cc:1005
int ha_start_consistent_snapshot(THD *thd)
Definition: handler.cc:2508
constexpr const uint32 SDI_TYPE_TABLESPACE
Id for identifying Tablespace SDIs.
Definition: handler.h:132
int(*)(handlerton *hton, THD *thd, const uchar *loc, uint loc_len, uint task_id, int in_err, Ha_clone_cbk *cbk) Clone_ack_t
Acknowledge data transfer to source database.
Definition: handler.h:2250
bool(*)(THD *thd, const JoinHypergraph &hypergraph, AccessPath *access_path) secondary_engine_modify_view_ap_cost_t
Evaluates/Views the cost of executing the given access path in the secondary storage engine,...
Definition: handler.h:2480
bool(* is_valid_tablespace_name_t)(ts_command_type ts_cmd, const char *tablespace_name)
SE specific validation of the tablespace name.
Definition: handler.h:1562
int ha_table_exists_in_engine(THD *thd, const char *db, const char *name)
Definition: handler.cc:5950
constexpr const uint64_t HA_CREATE_USED_EXPLICIT_SECONDARY_ENGINE
Definition: handler.h:835
int(* upgrade_tablespace_t)(THD *thd)
Get the tablespace data from SE and insert it into Data dictionary.
Definition: handler.h:1605
bool(* notify_exclusive_mdl_t)(THD *thd, const MDL_key *mdl_key, ha_notification_type notification_type, bool *victimized)
Notify/get permission from storage engine before acquisition or after release of exclusive metadata l...
Definition: handler.h:2038
int ha_commit_low(THD *thd, bool all, bool run_after_commit=true)
Commit the sessions outstanding transaction.
Definition: handler.cc:1959
uint(* partition_flags_t)()
The flag values are defined in sql_partition.h.
Definition: handler.h:1548
bool ha_flush_logs(bool binlog_group_flush=false)
Flush the log(s) of storage engine(s).
Definition: handler.cc:2532
dict_recovery_mode_t
Mode for data dictionary recovery.
Definition: handler.h:1964
@ DICT_RECOVERY_RESTART_SERVER
Restart of an existing server.
Definition: handler.h:1967
@ DICT_RECOVERY_INITIALIZE_TABLESPACES
First start, create tablespaces.
Definition: handler.h:1966
@ DICT_RECOVERY_INITIALIZE_SERVER
First start of a new server.
Definition: handler.h:1965
bool(* sdi_get_keys_t)(const dd::Tablespace &tablespace, sdi_vector_t &vector)
Get the SDI keys in a tablespace into vector.
Definition: handler.h:1770
ulong savepoint_alloc_size
Definition: handler.cc:273
int(* fill_is_table_t)(handlerton *hton, THD *thd, Table_ref *tables, class Item *cond, enum enum_schema_tables)
Definition: handler.h:1683
int(* binlog_func_t)(handlerton *hton, THD *thd, enum_binlog_func fn, void *arg)
Definition: handler.h:1686
int ha_create_table_from_engine(THD *thd, const char *db, const char *name)
Try to discover table from engine.
Definition: handler.cc:5456
enum_binlog_func
Definition: handler.h:704
@ BFN_BINLOG_WAIT
Definition: handler.h:707
@ BFN_BINLOG_PURGE_WAIT
Definition: handler.h:710
@ BFN_BINLOG_END
Definition: handler.h:708
@ BFN_RESET_SLAVE
Definition: handler.h:706
@ BFN_BINLOG_PURGE_FILE
Definition: handler.h:709
@ BFN_RESET_LOGS
Definition: handler.h:705
constexpr const uint64_t HA_CREATE_USED_STRICT_LOAD
Definition: handler.h:826
void set_externally_disabled_storage_engine_names(const char *)
Read a comma-separated list of storage engine names.
Definition: handler.cc:471
void(*)(void *arg) se_before_commit_t
Definition: handler.h:2660
int(* rollback_t)(handlerton *hton, THD *thd, bool all)
Definition: handler.h:1423
void(* dict_cache_reset_t)(const char *schema_name, const char *table_name)
Invalidate an entry in the local dictionary cache.
Definition: handler.h:1952
bool ha_rollback_to_savepoint_can_release_mdl(THD *thd)
Check if all storage engines used in transaction agree that after rollback to savepoint it is safe to...
Definition: handler.cc:2293
int binlog_log_row(TABLE *table, const uchar *before_record, const uchar *after_record, Log_func *log_func)
Definition: handler.cc:8063
void * range_seq_t
Definition: handler.h:3985
int ha_init_errors(void)
Register handler error messages for use with my_error().
Definition: handler.cc:649
bool(*)(THD *thd, const JOIN &join, double optimizer_cost, bool *use_best_so_far, bool *cheaper, double *secondary_engine_cost) compare_secondary_engine_cost_t
Compares the cost of two join plans in the secondary storage engine.
Definition: handler.h:2426
handlerton * get_default_handlerton(THD *thd, handlerton *hton)
Get default handlerton, if handler supplied is null.
Definition: handler.h:7680
int ha_rollback_trans(THD *thd, bool all)
Definition: handler.cc:2129
constexpr const ha_rows EXTRA_RECORDS
Definition: handler.h:126
void(*)(THD *thd, JoinHypergraph *graph) cardinality_estimation_hook_t
Hook used to estimate the cardinality of table Node objects in the JoinHypergraph.
Definition: handler.h:2725
enum_sampling_method
Definition: handler.h:723
int ha_reset_logs(THD *thd)
Definition: handler.cc:6008
bool ha_storage_engine_is_enabled(const handlerton *db_type)
Predicate to determine if a storage engine, represented by a handlerton*, is enabled.
Definition: handler.h:7708
dict_init_mode_t
Mode for initializing the data dictionary.
Definition: handler.h:1896
@ DICT_INIT_CREATE_FILES
Create all required SE files.
Definition: handler.h:1897
@ DICT_INIT_CHECK_FILES
Verify existence of expected files.
Definition: handler.h:1898
bool(* check_fk_column_compat_t)(const Ha_fk_column_type *child_column_type, const Ha_fk_column_type *parent_column_type, bool check_charsets)
Check SE considers types of child and parent columns in foreign key to be compatible.
Definition: handler.h:2371
constexpr SecondaryEngineFlags MakeSecondaryEngineFlags()
Creates an empty bitmap of access path types.
Definition: handler.h:2637
bool ha_is_externally_disabled(const handlerton &)
Returns true if the storage engine of the handlerton argument has been listed in the disabled_storage...
Definition: handler.cc:515
int(*)(handlerton *hton, Xa_state_list &xa_list) recover_prepared_in_tc_t
Retrieves information about externally coordinated transactions for which the two-phase prepare was f...
Definition: handler.h:1435
constexpr const uint64_t HA_CREATE_USED_AUTO_REFRESH
Definition: handler.h:827
static const uint32 HTON_FKS_WITH_PREFIX_PARENT_KEYS
Engine supports both unique and non-unique parent keys for foreign keys which contain full foreign ke...
Definition: handler.h:3282
bool secondary_engine_supports_temporary_tables(const handlerton *hton)
Definition: handler.h:3261
void(* dict_cache_reset_tables_and_tablespaces_t)()
Invalidate all table and tablespace entries in the local dictionary cache.
Definition: handler.h:1961
#define HA_NO_TRANSACTIONS
Definition: handler.h:225
void(* post_ddl_t)(THD *thd)
Perform post-commit/rollback cleanup after DDL statement (e.g.
Definition: handler.h:2329
bool ddl_is_atomic(const handlerton *hton)
Definition: handler.h:3266
const handlerton * EligibleSecondaryEngineHandlerton(THD *thd, const LEX_CSTRING *secondary_engine_in_name)
Returns the handlerton of the eligible secondary engine that is used in the session,...
Definition: handler.cc:9036
ulonglong my_xid
Definition: handler.h:1259
legacy_db_type
Definition: handler.h:656
@ DB_TYPE_MARIA
Definition: handler.h:684
@ DB_TYPE_FEDERATED_DB
Definition: handler.h:675
@ DB_TYPE_GEMINI
Definition: handler.h:670
@ DB_TYPE_FIRST_DYNAMIC
Definition: handler.h:688
@ DB_TYPE_MISAM
Definition: handler.h:660
@ DB_TYPE_HEAP
Definition: handler.h:663
@ DB_TYPE_TABLE_FUNCTION
Definition: handler.h:681
@ DB_TYPE_DIAB_ISAM
Definition: handler.h:658
@ DB_TYPE_TEMPTABLE
Definition: handler.h:687
@ DB_TYPE_HASH
Definition: handler.h:659
@ DB_TYPE_PARTITION_DB
Definition: handler.h:677
@ DB_TYPE_BINLOG
Definition: handler.h:678
@ DB_TYPE_SOLID
Definition: handler.h:679
@ DB_TYPE_UNKNOWN
Definition: handler.h:657
@ DB_TYPE_ISAM
Definition: handler.h:664
@ DB_TYPE_MRG_MYISAM
Definition: handler.h:667
@ DB_TYPE_PERFORMANCE_SCHEMA
Performance schema engine.
Definition: handler.h:686
@ DB_TYPE_EXAMPLE_DB
Definition: handler.h:672
@ DB_TYPE_CSV_DB
Definition: handler.h:674
@ DB_TYPE_NDBCLUSTER
Definition: handler.h:671
@ DB_TYPE_INNODB
Definition: handler.h:669
@ DB_TYPE_FALCON
Definition: handler.h:683
@ DB_TYPE_DEFAULT
Definition: handler.h:689
@ DB_TYPE_BLACKHOLE_DB
Definition: handler.h:676
@ DB_TYPE_MYISAM
Definition: handler.h:666
@ DB_TYPE_RMS_ISAM
Definition: handler.h:662
@ DB_TYPE_BERKELEY_DB
Definition: handler.h:668
@ DB_TYPE_MRG_ISAM
Definition: handler.h:665
@ DB_TYPE_PBXT
Definition: handler.h:680
@ DB_TYPE_PISAM
Definition: handler.h:661
@ DB_TYPE_ARCHIVE_DB
Definition: handler.h:673
@ DB_TYPE_MEMCACHE
Definition: handler.h:682
int ha_initialize_handlerton(st_plugin_int *plugin)
Definition: handler.cc:784
ha_notification_type
Definition: handler.h:964
@ HA_NOTIFY_POST_EVENT
Definition: handler.h:964
@ HA_NOTIFY_PRE_EVENT
Definition: handler.h:964
bool(* upgrade_space_version_t)(dd::Tablespace *tablespace)
Get the tablespace data from SE and insert it into Data dictionary.
Definition: handler.h:1618
Tablespace_type
Definition: handler.h:1650
xa_status_code(* rollback_by_xid_t)(handlerton *hton, XID *xid)
Definition: handler.h:1492
SelectExecutedIn
Used to identify which engine executed a SELECT query.
Definition: handler.h:221
constexpr const uint64_t HA_CREATE_USED_AUTO_REFRESH_SOURCE
Definition: handler.h:828
void ha_binlog_log_query(THD *thd, handlerton *db_type, enum_binlog_command binlog_command, const char *query, size_t query_length, const char *db, const char *table_name)
Definition: handler.cc:6059
handler *(* create_t)(handlerton *hton, TABLE_SHARE *table, bool partitioned, MEM_ROOT *mem_root)
Create handler object for the table in the storage engine.
Definition: handler.h:1512
void ha_acl_notify(THD *thd, class Acl_change_notification *)
Definition: handler.cc:6090
SE_cost_constants *(* get_cost_constants_t)(uint storage_category)
Retrieve cost constants to be used for this storage engine.
Definition: handler.h:1877
static bool commit(THD *thd)
Commit the current statement and transaction.
Definition: sql_cmd_srs.cc:152
File containing constants that can be used throughout the server.
SHOW_COMP_OPTION
Definition: sql_const.h:230
@ SHOW_OPTION_YES
Definition: sql_const.h:230
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:45
constexpr const unsigned int MAX_REF_PARTS
Definition: sql_const.h:46
constexpr const unsigned int MAX_KEY_LENGTH
Definition: sql_const.h:47
case opt name
Definition: sslopt-case.h:29
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:243
Callbacks for collecting time statistics.
Definition: bulk_data_service.h:931
Definition: m_ctype.h:421
Definition: handler.h:2301
Clone_apply_t clone_apply
Definition: handler.h:2313
Clone_end_t clone_end
Definition: handler.h:2309
Clone_capability_t clone_capability
Definition: handler.h:2303
Clone_apply_begin_t clone_apply_begin
Definition: handler.h:2312
Clone_begin_t clone_begin
Definition: handler.h:2306
Clone_copy_t clone_copy
Definition: handler.h:2307
Clone_apply_end_t clone_apply_end
Definition: handler.h:2314
Clone_ack_t clone_ack
Definition: handler.h:2308
Definition: ft_global.h:72
Definition: handler.h:3979
uchar * buffer_end
Definition: handler.h:3981
uchar * buffer
Definition: handler.h:3980
uchar * end_of_used_area
Definition: handler.h:3982
Definition: handler.h:3966
KEY_CACHE * key_cache
Definition: handler.h:3969
uint sql_flags
Definition: handler.h:3968
uint flags
Definition: handler.h:3967
Struct to hold information about the table that should be created.
Definition: handler.h:3356
ulonglong auto_increment_value
Definition: handler.h:3399
bool m_hidden
Definition: handler.h:3431
bool m_transactional_ddl
Definition: handler.h:3437
PT_create_external_file_format * file_format
Definition: handler.h:3446
bool m_implicit_tablespace_autoextend_size_change
Definition: handler.h:3444
handlerton * db_type
Definition: handler.h:3410
LEX_STRING compress
Algorithm (and possible options) to be used for InnoDB's transparent page compression.
Definition: handler.h:3372
LEX_STRING encrypt_type
This attribute is used for InnoDB's transparent page encryption.
Definition: handler.h:3380
LEX_CSTRING engine_attribute
Definition: handler.h:3439
ulong avg_row_length
Definition: handler.h:3401
size_t create_table_columns_end_pos
Definition: handler.h:3451
const CHARSET_INFO * table_charset
Definition: handler.h:3357
PT_create_external_files * external_files
Definition: handler.h:3447
const char * data_file_name
Definition: handler.h:3394
LEX_CSTRING auto_refresh_event_source
Definition: handler.h:3448
ulonglong m_implicit_tablespace_autoextend_size
Definition: handler.h:3442
bool secondary_load
Secondary engine load status.
Definition: handler.h:3388
const CHARSET_INFO * default_table_charset
Definition: handler.h:3358
uint stats_sample_pages
Definition: handler.h:3406
const char * alias
Definition: handler.h:3396
uint null_bits
Definition: handler.h:3421
uint merge_insert_method
Definition: handler.h:3423
LEX_STRING connect_string
Definition: handler.h:3360
partition_info * part_info
Part info in order to maintain in HA_CREATE_INFO the per-partition secondary_load status.
Definition: handler.h:3392
const char * tablespace
Definition: handler.h:3362
ulonglong max_rows
Definition: handler.h:3397
void init_create_options_from_share(const TABLE_SHARE *share, uint64_t used_fields)
Fill HA_CREATE_INFO to be used by ALTER as well as upgrade code.
Definition: handler.cc:2677
const char * password
Definition: handler.h:3361
ha_storage_media storage_media
Definition: handler.h:3424
LEX_STRING comment
Definition: handler.h:3363
const char * index_file_name
Definition: handler.h:3395
SQL_I_List< Table_ref > merge_list
Definition: handler.h:3409
std::uint32_t key_block_size
Definition: handler.h:3405
uint64_t table_options
Definition: handler.h:3400
LEX_CSTRING secondary_engine_attribute
Definition: handler.h:3440
LEX_CSTRING secondary_engine
Secondary engine of the table.
Definition: handler.h:3386
bool set_db_type(THD *thd)
Populate the db_type member depending on internal state and thd variables.
Definition: handler.cc:2789
ulonglong min_rows
Definition: handler.h:3398
uint64_t used_fields
Definition: handler.h:3402
bool schema_read_only
Definition: handler.h:3359
enum_stats_auto_recalc stats_auto_recalc
Definition: handler.h:3408
File reference for clone.
Definition: handler.h:1021
@ FILE_DESC
File descriptor.
Definition: handler.h:1028
@ FILE_HANDLE
File handle.
Definition: handler.h:1025
void * file_handle
File handle for windows.
Definition: handler.h:1038
int file_desc
File descriptor.
Definition: handler.h:1035
enum Ha_clone_file::@57 type
File reference type.
Column type description for foreign key columns compatibility check.
Definition: handler.h:1246
size_t elements_count
Definition: handler.h:1254
bool is_unsigned
Definition: handler.h:1256
size_t char_length
Definition: handler.h:1252
const CHARSET_INFO * field_charset
Definition: handler.h:1253
uint numeric_scale
Definition: handler.h:1255
dd::enum_column_types type
Definition: handler.h:1247
A struct containing a join hypergraph of a single query block, encapsulating the constraints given by...
Definition: make_join_hypergraph.h:99
Definition: keycache.h:73
Definition: my_base.h:1219
Structure describing changes to an index to be caused by ALTER TABLE.
Definition: handler.h:3480
KEY * new_key
Pointer to KEY object describing new version of index in Alter_inplace_info::key_info_buffer array.
Definition: handler.h:3491
KEY * old_key
Pointer to KEY object describing old version of index in TABLE::key_info array for TABLE instance rep...
Definition: handler.h:3486
The LEX object currently serves three different purposes:
Definition: sql_lex.h:4021
Metadata lock object key.
Definition: mdl.h:366
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
Definition: mysql_lex_string.h:35
Definition: my_bitmap.h:43
State data storage for start_table_io_wait_v1_t, start_table_lock_wait_v1_t.
Definition: psi_table_bits.h:69
Page track interface.
Definition: handler.h:2832
page_track_get_num_page_ids_t get_num_page_ids
Definition: handler.h:2837
page_track_purge_t purge
Definition: handler.h:2835
page_track_start_t start
Definition: handler.h:2833
page_track_stop_t stop
Definition: handler.h:2834
page_track_get_status_t get_status
Definition: handler.h:2838
page_track_get_page_ids_t get_page_ids
Definition: handler.h:2836
Definition: handler.h:3987
range_seq_t(* init)(void *init_params, uint n_ranges, uint flags)
Definition: handler.h:4000
uint(* next)(range_seq_t seq, KEY_MULTI_RANGE *range)
Definition: handler.h:4014
bool(* skip_record)(range_seq_t seq, char *range_info, uchar *rowid)
Definition: handler.h:4031
Definition: transaction_info.h:58
bool is_enabled
Indicates if simplification is guided using secondary engine.
Definition: handler.h:2585
int subgraph_pair_limit
Subgraph pairs requested by the secondary engine.
Definition: handler.h:2583
SecondaryEngineGraphSimplificationRequest secondary_engine_optimizer_request
Optimizer request from the secondary engine.
Definition: handler.h:2581
Type for signature generation and for retrieving nrows estimate from secondary engine for current Acc...
Definition: handler.h:2486
bool to_force_resign
if ap->signature generation should be forced.
Definition: handler.h:2500
OverflowBitset applied_predicates
Predicates actually applied for AccessPath::REF and other parameterized types.
Definition: handler.h:2495
SecondaryEngineNrowsParameters(THD *thd)
Definition: handler.h:2508
THD * thd
The thread context.
Definition: handler.h:2488
AccessPath * access_path
The AccessPath to retrieve Nrows for.
Definition: handler.h:2490
const JoinHypergraph * graph
Hypergraph for current query block.
Definition: handler.h:2492
size_t * extra_sig
if nonnull, an additional signature should be combined with current AP.
Definition: handler.h:2502
SecondaryEngineNrowsParameters(THD *thd, AccessPath *access_path, const JoinHypergraph *graph)
Definition: handler.h:2504
bool to_update_rows
if ap->nrows should be acually updated.
Definition: handler.h:2497
Per thread status variables.
Definition: system_variables.h:539
This structure is shared between different table objects.
Definition: table.h:731
Definition: table.h:1456
Definition: thr_lock.h:124
Definition: typelib.h:35
Structure used by parser to store options for tablespace statements and pass them on to Execution cla...
Definition: sql_tablespace.h:43
Info about FULLTEXT index hints, passed to the storage engine.
Definition: ft_global.h:117
double op_value
Operation value.
Definition: ft_global.h:123
ha_rows limit
LIMIT value, HA_POS_ERROR if not set.
Definition: ft_global.h:125
enum ft_operation op_type
Operation type.
Definition: ft_global.h:121
uint flags
FULLTEXT flags, see FT_NL, etc.
Definition: ft_global.h:119
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2852
sdi_get_keys_t sdi_get_keys
Definition: handler.h:2960
sdi_drop_t sdi_drop
Definition: handler.h:2959
unlock_hton_log_t unlock_hton_log
Definition: handler.h:3018
notify_alter_table_t notify_alter_table
Definition: handler.h:2991
dict_cache_reset_t dict_cache_reset
Definition: handler.h:2929
void * data
Location for engines to keep personal structures.
Definition: handler.h:3011
set_prepared_in_tc_by_xid_t set_prepared_in_tc_by_xid
Definition: handler.h:2902
se_before_rollback_t se_before_rollback
Definition: handler.h:3129
sdi_set_t sdi_set
Definition: handler.h:2962
lock_hton_log_t lock_hton_log
Definition: handler.h:3017
is_dict_readonly_t is_dict_readonly
Definition: handler.h:2986
alter_tablespace_t alter_tablespace
Definition: handler.h:2913
finish_upgrade_t finish_upgrade
Definition: handler.h:2924
create_t create
Definition: handler.h:2903
collect_hton_log_info_t collect_hton_log_info
Definition: handler.h:3019
secondary_engine_pre_prepare_hook_t secondary_engine_pre_prepare_hook
Definition: handler.h:3121
notify_materialized_view_usage_t notify_materialized_view_usage
Definition: handler.h:3136
dict_register_dd_table_id_t dict_register_dd_table_id
Definition: handler.h:2928
redo_log_set_state_t redo_log_set_state
Definition: handler.h:2995
find_files_t find_files
Definition: handler.h:2949
external_engine_explain_check_t external_engine_explain_check
Pointer to a function that checks if the table is loaded in the secondary engine in the case of an ex...
Definition: handler.h:3071
ddse_dict_init_t ddse_dict_init
Definition: handler.h:2927
replace_native_transaction_in_thd_t replace_native_transaction_in_thd
Definition: handler.h:2989
LEX_CSTRING fk_name_suffix
Suffix for auto-generated foreign key names for tables using this storage engine.
Definition: handler.h:3034
pre_dd_shutdown_t pre_dd_shutdown
Definition: handler.h:2888
check_fk_column_compat_t check_fk_column_compat
Definition: handler.h:3024
cardinality_estimation_hook_t cardinality_estimation_hook
Definition: handler.h:3125
SecondaryEngineFlags secondary_engine_flags
Bitmap which contains the supported join types and other flags for a secondary storage engine when us...
Definition: handler.h:3065
uint32 license
Flag for Engine License.
Definition: handler.h:3009
is_supported_system_table_t is_supported_system_table
Definition: handler.h:2952
commit_t commit
Definition: handler.h:2894
get_tablespace_statistics_t get_tablespace_statistics
Definition: handler.h:3000
se_after_commit_t se_after_commit
Definition: handler.h:3128
savepoint_set_t savepoint_set
Definition: handler.h:2890
uint savepoint_offset
To store per-savepoint data storage engine is provided with an area of a requested size (0 is ok here...
Definition: handler.h:2882
drop_database_t drop_database
Definition: handler.h:2904
savepoint_release_t savepoint_release
Definition: handler.h:2893
enum legacy_db_type db_type
Historical number used for frm file to determine the correct storage engine.
Definition: handler.h:2862
is_valid_tablespace_name_t is_valid_tablespace_name
Definition: handler.h:2912
se_before_commit_t se_before_commit
Definition: handler.h:3127
flush_logs_t flush_logs
Definition: handler.h:2909
log_ddl_create_schema_t log_ddl_create_schema
Definition: handler.h:2906
uint slot
Each storage engine has it's own memory area (actually a pointer) in the thd, for storing per-connect...
Definition: handler.h:2872
find_secondary_engine_offload_fail_reason_t find_secondary_engine_offload_fail_reason
Pointer to a function that finds and returns the query offload failure reason as a string given a thr...
Definition: handler.h:3101
dict_get_server_version_t dict_get_server_version
Definition: handler.h:2933
get_tablespace_type_t get_tablespace_type
Definition: handler.h:2919
close_connection_t close_connection
Definition: handler.h:2886
rotate_encryption_master_key_t rotate_encryption_master_key
Definition: handler.h:2994
secondary_engine_check_optimizer_request_t secondary_engine_check_optimizer_request
Pointer to function that checks secondary engine request for updating hypergraph join optimization.
Definition: handler.h:3116
notify_truncate_table_t notify_truncate_table
Definition: handler.h:2993
start_consistent_snapshot_t start_consistent_snapshot
Definition: handler.h:2908
savepoint_rollback_t savepoint_rollback
Definition: handler.h:2891
fill_is_table_t fill_is_table
Definition: handler.h:2925
binlog_func_t binlog_func
Definition: handler.h:2945
optimize_secondary_engine_t optimize_secondary_engine
Pointer to a function that optimizes the current statement for execution on the secondary storage eng...
Definition: handler.h:3051
log_ddl_drop_schema_t log_ddl_drop_schema
Definition: handler.h:2905
notify_exclusive_mdl_t notify_exclusive_mdl
Definition: handler.h:2990
get_cost_constants_t get_cost_constants
Definition: handler.h:2988
set_secondary_engine_offload_fail_reason_t set_secondary_engine_offload_fail_reason
Pointer to a function that sets the offload failure reason as a string for a thread context (represen...
Definition: handler.h:3109
notify_create_table_t notify_create_table
Definition: handler.h:3133
rollback_by_xid_t rollback_by_xid
Definition: handler.h:2900
sdi_delete_t sdi_delete
Definition: handler.h:2963
get_index_column_cardinality_t get_index_column_cardinality
Definition: handler.h:2999
rollback_t rollback
Definition: handler.h:2895
dict_recover_t dict_recover
Definition: handler.h:2932
rm_tmp_tables_t rm_tmp_tables
Definition: handler.h:2987
prepare_secondary_engine_t prepare_secondary_engine
Pointer to a function that prepares a secondary engine for executing a statement.
Definition: handler.h:3042
get_table_statistics_t get_table_statistics
Definition: handler.h:2997
Page_track_t page_track
Page tracking interface.
Definition: handler.h:3139
sdi_create_t sdi_create
Definition: handler.h:2958
notify_drop_table_t notify_drop_table
Definition: handler.h:3134
dict_init_t dict_init
Definition: handler.h:2926
uint32 foreign_keys_flags
Flags describing details of foreign key support by storage engine.
Definition: handler.h:3022
binlog_log_query_t binlog_log_query
Definition: handler.h:2946
get_tablespace_filename_ext_t get_tablespace_filename_ext
Definition: handler.h:2914
upgrade_logs_t upgrade_logs
Definition: handler.h:2922
get_secondary_engine_offload_or_exec_fail_reason_t get_secondary_engine_offload_or_exec_fail_reason
Pointer to a function that returns the query offload or exec failure reason as a string given a threa...
Definition: handler.h:3092
partition_flags_t partition_flags
Definition: handler.h:2911
const char ** file_extensions
Null-ended array of file extensions that exist for the storage engine.
Definition: handler.h:2984
dict_cache_reset_tables_and_tablespaces_t dict_cache_reset_tables_and_tablespaces
Definition: handler.h:2931
push_to_engine_t push_to_engine
Definition: handler.h:2951
Clone_interface_t clone_interface
Clone data transfer interfaces.
Definition: handler.h:3006
recover_prepared_in_tc_t recover_prepared_in_tc
Definition: handler.h:2898
discover_t discover
Definition: handler.h:2948
table_exists_in_engine_t table_exists_in_engine
Definition: handler.h:2950
upgrade_tablespace_t upgrade_tablespace
Definition: handler.h:2916
sdi_get_t sdi_get
Definition: handler.h:2961
reset_plugin_vars_t reset_plugin_vars
Definition: handler.h:2889
get_tablespace_type_by_name_t get_tablespace_type_by_name
Definition: handler.h:2920
dict_set_server_version_t dict_set_server_version
Definition: handler.h:2934
recover_t recover
Definition: handler.h:2897
SHOW_COMP_OPTION state
Historical marker for if the engine is available or not.
Definition: handler.h:2856
post_recover_t post_recover
Definition: handler.h:3003
uint32 flags
Global handler flags.
Definition: handler.h:2938
upgrade_space_version_t upgrade_space_version
Definition: handler.h:2918
kill_connection_t kill_connection
Definition: handler.h:2887
get_column_statistics_t get_column_statistics
Definition: handler.h:2998
prepare_t prepare
Definition: handler.h:2896
panic_t panic
Definition: handler.h:2907
post_ddl_t post_ddl
Definition: handler.h:3002
compare_secondary_engine_cost_t compare_secondary_engine_cost
Pointer to a function that estimates the cost of executing a join in a secondary storage engine.
Definition: handler.h:3059
notify_after_select_t notify_after_select
Definition: handler.h:3131
commit_by_xid_t commit_by_xid
Definition: handler.h:2899
set_prepared_in_tc_t set_prepared_in_tc
Definition: handler.h:2901
acl_notify_t acl_notify
Definition: handler.h:2947
show_status_t show_status
Definition: handler.h:2910
secondary_engine_modify_view_ap_cost_t secondary_engine_modify_view_ap_cost
Pointer to a function that evaluates the cost of executing an access path in a secondary storage engi...
Definition: handler.h:3077
is_reserved_db_name_t is_reserved_db_name
Definition: handler.h:2935
savepoint_rollback_can_release_mdl_t savepoint_rollback_can_release_mdl
Definition: handler.h:2892
secondary_engine_nrows_t secondary_engine_nrows
Pointer to a function that provides nrow estimates for access paths from secondary storage engine.
Definition: handler.h:3083
notify_rename_table_t notify_rename_table
Definition: handler.h:2992
Definition: my_base.h:1212
Definition: gen_lex_token.cc:149
Definition: result.h:30
Key to identify a dictionary object.
Definition: handler.h:135
uint32 type
Type of Object, For ex: column, index, etc.
Definition: handler.h:137
uint64 id
Object id which should be unique in tablespsace.
Definition: handler.h:140
Definition: handler.h:144
sdi_container m_vec
Definition: handler.h:145
Definition: handler.h:845
const char * db
Definition: handler.h:846
const char * tablename
Definition: handler.h:847
Definition: sql_plugin_ref.h:45
Plain structure to store information about XA transaction id and a list of table names involved into ...
Definition: xa.h:290
Definition: mysqlslap.cc:243
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification,...
Definition: xa.h:83
thr_lock_type
Definition: thr_lock.h:51
Definition: dtoa.cc:595
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510
static uint64_t cache_size
Definition: xcom_cache.cc:363
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:890