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