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