1 #ifndef HANDLER_INCLUDED
2 #define HANDLER_INCLUDED
24 #include "my_pthread.h"
28 #include "sql_plugin.h"
30 #include "sql_cache.h"
33 #include <my_global.h>
34 #include <my_compare.h>
35 #include <ft_global.h>
42 #define HA_ADMIN_ALREADY_DONE 1
44 #define HA_ADMIN_NOT_IMPLEMENTED -1
45 #define HA_ADMIN_FAILED -2
46 #define HA_ADMIN_CORRUPT -3
47 #define HA_ADMIN_INTERNAL_ERROR -4
48 #define HA_ADMIN_INVALID -5
49 #define HA_ADMIN_REJECT -6
50 #define HA_ADMIN_TRY_ALTER -7
51 #define HA_ADMIN_WRONG_CHECKSUM -8
52 #define HA_ADMIN_NOT_BASE_TABLE -9
53 #define HA_ADMIN_NEEDS_UPGRADE -10
54 #define HA_ADMIN_NEEDS_ALTER -11
55 #define HA_ADMIN_NEEDS_CHECK -12
63 enum enum_alter_inplace_result {
65 HA_ALTER_INPLACE_NOT_SUPPORTED,
66 HA_ALTER_INPLACE_EXCLUSIVE_LOCK,
67 HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE,
68 HA_ALTER_INPLACE_SHARED_LOCK,
69 HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE,
70 HA_ALTER_INPLACE_NO_LOCK
75 #define HA_NO_TRANSACTIONS (1 << 0)
76 #define HA_PARTIAL_COLUMN_READ (1 << 1)
77 #define HA_TABLE_SCAN_ON_INDEX (1 << 2)
86 #define HA_REC_NOT_IN_SEQ (1 << 3)
87 #define HA_CAN_GEOMETRY (1 << 4)
93 #define HA_FAST_KEY_READ (1 << 5)
98 #define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
99 #define HA_NULL_IN_KEY (1 << 7)
100 #define HA_DUPLICATE_POS (1 << 8)
101 #define HA_NO_BLOBS (1 << 9)
102 #define HA_CAN_INDEX_BLOBS (1 << 10)
103 #define HA_AUTO_PART_KEY (1 << 11)
104 #define HA_REQUIRE_PRIMARY_KEY (1 << 12)
105 #define HA_STATS_RECORDS_IS_EXACT (1 << 13)
110 #define HA_CAN_INSERT_DELAYED (1 << 14)
116 #define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
124 #define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16)
125 #define HA_CAN_RTREEKEYS (1 << 17)
126 #define HA_NOT_DELETE_WITH_CACHE (1 << 18)
131 #define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
132 #define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
133 #define HA_CAN_FULLTEXT (1 << 21)
134 #define HA_CAN_SQL_HANDLER (1 << 22)
135 #define HA_NO_AUTO_INCREMENT (1 << 23)
136 #define HA_HAS_CHECKSUM (1 << 24)
138 #define HA_FILE_BASED (1 << 26)
139 #define HA_NO_VARCHAR (1 << 27)
140 #define HA_CAN_BIT_FIELD (1 << 28)
141 #define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
142 #define HA_NO_COPY_ON_ALTER (LL(1) << 31)
143 #define HA_HAS_RECORDS (LL(1) << 32)
145 #define HA_HAS_OWN_BINLOGGING (LL(1) << 33)
150 #define HA_BINLOG_ROW_CAPABLE (LL(1) << 34)
151 #define HA_BINLOG_STMT_CAPABLE (LL(1) << 35)
174 #define HA_DUPLICATE_KEY_NOT_IN_ORDER (LL(1) << 36)
180 #define HA_CAN_REPAIR (LL(1) << 37)
186 #define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
220 #define HA_READ_BEFORE_WRITE_REMOVAL (LL(1) << 38)
225 #define HA_CAN_FULLTEXT_EXT (LL(1) << 39)
233 #define HA_READ_OUT_OF_SYNC (LL(1) << 40)
239 #define HA_CAN_EXPORT (LL(1) << 41)
245 #define HA_BLOCK_CONST_TABLE (LL(1) << 42)
248 #define HA_READ_NEXT 1
249 #define HA_READ_PREV 2
250 #define HA_READ_ORDER 4
251 #define HA_READ_RANGE 8
252 #define HA_ONLY_WHOLE_INDEX 16
253 #define HA_KEYREAD_ONLY 64
258 #define HA_KEY_SCAN_NOT_ROR 128
259 #define HA_DO_INDEX_COND_PUSHDOWN 256
290 #define HA_PARTITION_FUNCTION_SUPPORTED (1L << 0)
291 #define HA_FAST_CHANGE_PARTITION (1L << 1)
292 #define HA_PARTITION_ONE_PHASE (1L << 2)
295 #define HA_KEY_SWITCH_NONUNIQ 0
296 #define HA_KEY_SWITCH_ALL 1
297 #define HA_KEY_SWITCH_NONUNIQ_SAVE 2
298 #define HA_KEY_SWITCH_ALL_SAVE 3
314 #define HA_SLOT_UNDEF ((uint)-1)
321 #define HA_OPEN_KEYFILE 1
322 #define HA_OPEN_RNDFILE 2
323 #define HA_GET_INDEX 4
324 #define HA_GET_INFO 8
325 #define HA_READ_ONLY 16
327 #define HA_TRY_READ_ONLY 32
328 #define HA_WAIT_IF_LOCKED 64
329 #define HA_ABORT_IF_LOCKED 128
330 #define HA_BLOCK_LOCK 256
331 #define HA_OPEN_TEMPORARY 512
334 #define HA_KEY_NULL_LENGTH 1
335 #define HA_KEY_BLOB_LENGTH 2
337 #define HA_LEX_CREATE_TMP_TABLE 1
338 #define HA_LEX_CREATE_IF_NOT_EXISTS 2
339 #define HA_LEX_CREATE_TABLE_LIKE 4
340 #define HA_OPTION_NO_CHECKSUM (1L << 17)
341 #define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
342 #define HA_MAX_REC_LENGTH 65535U
345 #define HA_CACHE_TBL_NONTRANSACT 0
346 #define HA_CACHE_TBL_NOCACHE 1
347 #define HA_CACHE_TBL_ASKTRANSACT 2
348 #define HA_CACHE_TBL_TRANSACT 4
363 static const uint MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT = 1;
365 static const uint MYSQL_START_TRANS_OPT_READ_ONLY = 2;
367 static const uint MYSQL_START_TRANS_OPT_READ_WRITE = 4;
370 #define HA_CHECK_DUP_KEY 1
371 #define HA_CHECK_DUP_UNIQUE 2
372 #define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
376 DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
377 DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
378 DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
379 DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
380 DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
381 DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
382 DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
383 DB_TYPE_FEDERATED_DB,
384 DB_TYPE_BLACKHOLE_DB,
385 DB_TYPE_PARTITION_DB,
389 DB_TYPE_TABLE_FUNCTION,
394 DB_TYPE_PERFORMANCE_SCHEMA,
395 DB_TYPE_FIRST_DYNAMIC=42,
399 enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
400 ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
401 ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT,
406 enum column_format_type {
407 COLUMN_FORMAT_TYPE_DEFAULT= 0,
408 COLUMN_FORMAT_TYPE_FIXED= 1,
409 COLUMN_FORMAT_TYPE_DYNAMIC= 2
412 enum enum_binlog_func {
417 BFN_BINLOG_PURGE_FILE= 5
420 enum enum_binlog_command {
433 #define HA_CREATE_USED_AUTO (1L << 0)
434 #define HA_CREATE_USED_RAID (1L << 1) //RAID is no longer availble
435 #define HA_CREATE_USED_UNION (1L << 2)
436 #define HA_CREATE_USED_INSERT_METHOD (1L << 3)
437 #define HA_CREATE_USED_MIN_ROWS (1L << 4)
438 #define HA_CREATE_USED_MAX_ROWS (1L << 5)
439 #define HA_CREATE_USED_AVG_ROW_LENGTH (1L << 6)
440 #define HA_CREATE_USED_PACK_KEYS (1L << 7)
441 #define HA_CREATE_USED_CHARSET (1L << 8)
442 #define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
443 #define HA_CREATE_USED_DATADIR (1L << 10)
444 #define HA_CREATE_USED_INDEXDIR (1L << 11)
445 #define HA_CREATE_USED_ENGINE (1L << 12)
446 #define HA_CREATE_USED_CHECKSUM (1L << 13)
447 #define HA_CREATE_USED_DELAY_KEY_WRITE (1L << 14)
448 #define HA_CREATE_USED_ROW_FORMAT (1L << 15)
449 #define HA_CREATE_USED_COMMENT (1L << 16)
450 #define HA_CREATE_USED_PASSWORD (1L << 17)
451 #define HA_CREATE_USED_CONNECTION (1L << 18)
452 #define HA_CREATE_USED_KEY_BLOCK_SIZE (1L << 19)
454 #define HA_CREATE_USED_TRANSACTIONAL (1L << 20)
456 #define HA_CREATE_USED_PAGE_CHECKSUM (1L << 21)
462 #define HA_CREATE_USED_STATS_PERSISTENT (1L << 22)
469 #define HA_CREATE_USED_STATS_AUTO_RECALC (1L << 23)
476 #define HA_CREATE_USED_STATS_SAMPLE_PAGES (1L << 24)
493 const char *tablename;
497 typedef ulonglong my_xid;
498 #define MYSQL_XID_PREFIX "MySQLXid"
499 #define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
500 #define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
501 #define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid))
503 #define XIDDATASIZE MYSQL_XIDDATASIZE
504 #define MAXGTRIDSIZE 64
505 #define MAXBQUALSIZE 64
507 #define COMPATIBLE_DATA_YES 0
508 #define COMPATIBLE_DATA_NO 1
529 bool eq(
struct xid_t *xid)
531 bool eq(
long g,
long b,
const char *d)
533 void set(
struct xid_t *xid)
534 { memcpy(
this, xid, xid->length()); }
535 void set(
long f,
const char *g,
long gl,
const char *b,
long bl)
541 void set(ulonglong xid)
545 set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
546 memcpy(
data+MYSQL_XID_PREFIX_LEN, &server_id,
sizeof(server_id));
548 memcpy(
data+MYSQL_XID_OFFSET, &tmp,
sizeof(tmp));
551 void set(
long g,
long b,
const char *d)
556 memcpy(
data, d, g+b);
558 bool is_null() {
return formatID == -1; }
560 my_xid quick_get_my_xid()
563 memcpy(&tmp,
data+MYSQL_XID_OFFSET,
sizeof(tmp));
569 !memcmp(
data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
570 quick_get_my_xid() : 0;
589 #define MIN_XID_LIST_SIZE 128
590 #define MAX_XID_LIST_SIZE (1024*128)
596 #define UNDEF_NODEGROUP 65535
599 TS_CMD_NOT_DEFINED = -1,
600 CREATE_TABLESPACE = 0,
601 ALTER_TABLESPACE = 1,
602 CREATE_LOGFILE_GROUP = 2,
603 ALTER_LOGFILE_GROUP = 3,
605 DROP_LOGFILE_GROUP = 5,
606 CHANGE_FILE_TABLESPACE = 6,
607 ALTER_ACCESS_MODE_TABLESPACE = 7
610 enum ts_alter_tablespace_type
612 TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1,
613 ALTER_TABLESPACE_ADD_FILE = 1,
614 ALTER_TABLESPACE_DROP_FILE = 2
617 enum tablespace_access_mode
622 TS_NOT_ACCESSIBLE = 2
629 const char *tablespace_name;
630 const char *logfile_group_name;
631 enum ts_command_type ts_cmd_type;
632 enum ts_alter_tablespace_type ts_alter_tablespace_type;
633 const char *data_file_name;
634 const char *undo_file_name;
635 const char *redo_file_name;
636 ulonglong extent_size;
637 ulonglong undo_buffer_size;
638 ulonglong redo_buffer_size;
639 ulonglong initial_size;
640 ulonglong autoextend_size;
644 bool wait_until_completed;
645 const char *ts_comment;
646 enum tablespace_access_mode ts_access_mode;
649 tablespace_name= NULL;
650 logfile_group_name=
"DEFAULT_LG";
651 ts_cmd_type= TS_CMD_NOT_DEFINED;
652 data_file_name= NULL;
653 undo_file_name= NULL;
654 redo_file_name= NULL;
655 extent_size= 1024*1024;
656 undo_buffer_size= 8*1024*1024;
657 redo_buffer_size= 8*1024*1024;
658 initial_size= 128*1024*1024;
661 storage_engine= NULL;
662 nodegroup_id= UNDEF_NODEGROUP;
663 wait_until_completed= TRUE;
665 ts_access_mode= TS_NOT_DEFINED;
676 enum enum_schema_tables
680 SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
682 SCH_COLUMN_PRIVILEGES,
687 SCH_GLOBAL_VARIABLES,
688 SCH_KEY_COLUMN_USAGE,
696 SCH_REFERENTIAL_CONSTRAINTS,
699 SCH_SCHEMA_PRIVILEGES,
701 SCH_SESSION_VARIABLES,
706 SCH_TABLE_CONSTRAINTS,
708 SCH_TABLE_PRIVILEGES,
718 typedef bool (stat_print_fn)(THD *thd,
const char *
type, uint type_len,
719 const char *
file, uint file_len,
720 const char *status, uint status_len);
721 enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
727 HA_LOG_STATUS_FREE= 0,
728 HA_LOG_STATUS_INUSE= 1,
729 HA_LOG_STATUS_NOSUCHLOG= 2
746 enum log_status status;
750 enum handler_iterator_type
753 HA_TRANSACTLOG_ITERATOR= 1
755 enum handler_create_iterator_result
758 HA_ITERATOR_UNSUPPORTED,
807 SHOW_COMP_OPTION state;
813 enum legacy_db_type db_type;
833 uint savepoint_offset;
842 int (*close_connection)(
handlerton *hton, THD *thd);
847 int (*savepoint_set)(
handlerton *hton, THD *thd,
void *sv);
852 int (*savepoint_rollback)(
handlerton *hton, THD *thd,
void *sv);
853 int (*savepoint_release)(
handlerton *hton, THD *thd,
void *sv);
861 int (*commit)(
handlerton *hton, THD *thd,
bool all);
862 int (*rollback)(
handlerton *hton, THD *thd,
bool all);
863 int (*prepare)(
handlerton *hton, THD *thd,
bool all);
867 void *(*create_cursor_read_view)(
handlerton *hton, THD *thd);
868 void (*set_cursor_read_view)(
handlerton *hton, THD *thd,
void *read_view);
869 void (*close_cursor_read_view)(
handlerton *hton, THD *thd,
void *read_view);
871 void (*drop_database)(
handlerton *hton,
char* path);
872 int (*panic)(
handlerton *hton,
enum ha_panic_function flag);
873 int (*start_consistent_snapshot)(
handlerton *hton, THD *thd);
875 bool (*show_status)(
handlerton *hton, THD *thd, stat_print_fn *print,
enum ha_stat_type stat);
876 uint (*partition_flags)();
877 uint (*alter_table_flags)(uint flags);
881 enum enum_schema_tables);
887 int (*binlog_func)(
handlerton *hton, THD *thd, enum_binlog_func fn,
void *arg);
888 void (*binlog_log_query)(
handlerton *hton, THD *thd,
889 enum_binlog_command binlog_command,
890 const char *
query, uint query_length,
892 int (*release_temporary_latches)(
handlerton *hton, THD *thd);
901 enum log_status (*get_log_status)(
handlerton *hton,
char *log);
907 enum handler_create_iterator_result
908 (*create_iterator)(
handlerton *hton,
enum handler_iterator_type
type,
910 int (*discover)(
handlerton *hton, THD* thd,
const char *db,
918 int (*table_exists_in_engine)(
handlerton *hton, THD* thd,
const char *db,
920 int (*make_pushed_join)(
handlerton *hton, THD* thd,
934 const char* (*system_database)();
953 bool is_sql_layer_system_table);
961 #define HTON_NO_FLAGS 0
962 #define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
963 #define HTON_ALTER_NOT_SUPPORTED (1 << 1) //Engine does not support alter
964 #define HTON_CAN_RECREATE (1 << 2) //Delete all is used fro truncate
965 #define HTON_HIDDEN (1 << 3) //Engine does not appear in lists
966 #define HTON_FLUSH_AFTER_RENAME (1 << 4)
967 #define HTON_NOT_USER_SELECTABLE (1 << 5)
968 #define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
969 #define HTON_SUPPORT_LOG_TABLES (1 << 7) //Engine supports log tables
970 #define HTON_NO_PARTITION (1 << 8) //You can not partition these tables
984 #define HTON_NO_BINLOG_ROW_OPT (1 << 9)
994 #define HTON_SUPPORTS_EXTENDED_KEYS (1 << 10)
997 enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
998 ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
1002 ulonglong data_file_length;
1003 ulonglong max_data_file_length;
1004 ulonglong index_file_length;
1005 ulonglong delete_length;
1007 ulong mean_rec_length;
1011 ulonglong check_sum;
1014 #define UNDEF_NODEGROUP 65535
1016 struct st_table_log_memory_entry;
1022 enum enum_ha_unused { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
1024 enum enum_stats_auto_recalc { HA_STATS_AUTO_RECALC_DEFAULT= 0,
1025 HA_STATS_AUTO_RECALC_ON,
1026 HA_STATS_AUTO_RECALC_OFF };
1030 const CHARSET_INFO *table_charset, *default_table_charset;
1032 const char *password, *tablespace;
1034 const char *data_file_name, *index_file_name;
1036 ulonglong max_rows,min_rows;
1037 ulonglong auto_increment_value;
1038 ulong table_options;
1039 ulong avg_row_length;
1041 ulong key_block_size;
1042 uint stats_sample_pages;
1044 enum_stats_auto_recalc stats_auto_recalc;
1059 uint merge_insert_method;
1062 enum ha_storage_media storage_media;
1162 static const HA_ALTER_FLAGS ALTER_COLUMN_NOT_NULLABLE = 1L << 13;
1180 static const HA_ALTER_FLAGS ALTER_COLUMN_STORAGE_TYPE = 1L << 19;
1183 static const HA_ALTER_FLAGS ALTER_COLUMN_COLUMN_FORMAT = 1L << 20;
1204 static const HA_ALTER_FLAGS ALTER_REMOVE_PARTITIONING = 1L << 27;
1326 KEY *key_info_arg, uint key_count_arg,
1361 const char *try_instead);
1367 enum ha_key_alg algorithm;
1401 inline void prelock(
TABLE **tables, uint count)
1403 do_prelock(tables, count);
1406 inline int postlock(
TABLE **tables, uint count)
1408 return do_postlock(tables, count);
1412 virtual void do_prelock(
TABLE **tables, uint count)
1425 virtual int do_postlock(
TABLE **tables, uint count)
1431 typedef struct st_savepoint SAVEPOINT;
1432 extern ulong savepoint_alloc_size;
1457 uchar *end_of_used_area;
1463 typedef void *range_seq_t;
1479 range_seq_t (*init)(
void *init_params, uint n_ranges, uint
flags);
1511 bool (*skip_record) (range_seq_t seq,
char *range_info, uchar *rowid);
1524 bool (*skip_index_tuple) (range_seq_t seq,
char *range_info);
1527 uint16 &mrr_persistent_flag_storage(range_seq_t seq, uint idx);
1528 char* &mrr_get_ptr_by_idx(range_seq_t seq, uint idx);
1557 double total_cost()
const {
return io_cost + cpu_cost + import_cost; }
1558 double get_io_cost()
const {
return io_cost; }
1559 double get_cpu_cost()
const {
return cpu_cost; }
1560 double get_import_cost()
const {
return import_cost; }
1561 double get_mem_cost()
const {
return mem_cost; }
1570 return !(io_cost || cpu_cost || import_cost || mem_cost);
1576 io_cost= cpu_cost= import_cost= mem_cost= 0;
1590 io_cost+= other.io_cost;
1591 cpu_cost+= other.cpu_cost;
1592 import_cost+= other.import_cost;
1593 mem_cost+= other.mem_cost;
1606 void add_io(
double add_io_cost) { io_cost+= add_io_cost; }
1609 void add_cpu(
double add_cpu_cost) { cpu_cost+= add_cpu_cost; }
1612 void add_import(
double add_import_cost) { import_cost+= add_import_cost; }
1615 void add_mem(
double add_mem_cost) { mem_cost+= add_mem_cost; }
1626 #define HA_MRR_SINGLE_POINT 1
1627 #define HA_MRR_FIXED_KEY 2
1633 #define HA_MRR_NO_ASSOCIATION 4
1643 #define HA_MRR_SORTED 8
1646 #define HA_MRR_INDEX_ONLY 16
1652 #define HA_MRR_LIMITS 32
1661 #define HA_MRR_USE_DEFAULT_IMPL 64
1668 #define HA_MRR_NO_NULL_ENDPOINTS 128
1676 #define HA_MRR_SUPPORT_SORTED 256
1682 ulonglong data_file_length;
1683 ulonglong max_data_file_length;
1684 ulonglong index_file_length;
1685 ulonglong max_index_file_length;
1686 ulonglong delete_length;
1687 ulonglong auto_increment_value;
1698 ulong mean_rec_length;
1707 uint mrr_length_per_rec;
1710 data_file_length(0), max_data_file_length(0),
1711 index_file_length(0), delete_length(0), auto_increment_value(0),
1712 records(0), deleted(0), mean_rec_length(0), create_time(0),
1713 check_time(0), update_time(0), block_size(0)
1717 uint calculate_key_len(
TABLE *, uint,
const uchar *, key_part_map);
1722 #define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
1727 #define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
1790 typedef ulonglong Table_flags;
1794 Table_flags cached_table_flags;
1796 ha_rows estimation_rows_to_insert;
1805 range_seq_t mrr_iter;
1810 bool mrr_is_output_sorted;
1813 bool mrr_have_range;
1822 enum enum_range_scan_direction {
1832 enum_range_scan_direction range_scan_direction;
1833 int key_compare_result_on_equal;
1842 bool in_range_check_pushed_down;
1853 uint key_used_on_scan;
1858 enum {NONE=0, INDEX, RND} inited;
1859 bool implicit_emptied;
1860 const Item *pushed_cond;
1862 Item *pushed_idx_cond;
1863 uint pushed_idx_cond_keyno;
1909 virtual void unbind_psi();
1910 virtual void rebind_psi();
1929 :table_share(share_arg), table(0),
1930 estimation_rows_to_insert(0), ht(ht_arg),
1931 ref(0), range_scan_direction(RANGE_SCAN_ASC),
1932 in_range_check_pushed_down(false), end_range(NULL),
1933 key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1935 ft_handler(0), inited(NONE),
1936 implicit_emptied(0),
1937 pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
1940 m_psi(NULL), m_lock_type(F_UNLCK), ha_share(NULL)
1943 (
"handler created F_UNLCK %d F_RDLCK %d F_WRLCK %d",
1944 F_UNLCK, F_RDLCK, F_WRLCK));
1948 DBUG_ASSERT(m_lock_type == F_UNLCK);
1949 DBUG_ASSERT(inited == NONE);
1955 cached_table_flags= table_flags();
1968 key_part_map keypart_map,
1969 enum ha_rkey_function find_flag);
1970 int ha_index_read_last_map(uchar *
buf,
const uchar * key,
1971 key_part_map keypart_map);
1973 key_part_map keypart_map,
1974 enum ha_rkey_function find_flag);
1981 enum ha_rkey_function find_flag);
1985 int ha_index_or_rnd_end()
2000 int ha_write_row(uchar *
buf);
2001 int ha_update_row(
const uchar * old_data, uchar * new_data);
2002 int ha_delete_row(
const uchar *
buf);
2003 void ha_release_auto_increment();
2013 uint *dup_key_found);
2034 ulonglong *
const copied,
2035 ulonglong *
const deleted,
2036 const uchar *pack_frm_data,
2037 size_t pack_frm_len);
2041 void adjust_next_insert_id_after_explicit_value(ulonglong nr);
2042 int update_auto_increment();
2065 uint child_table_name_len,
2066 char *child_key_name,
2067 uint child_key_name_len)
2068 { DBUG_ASSERT(
false);
return(
false); }
2075 virtual double scan_time()
2076 {
return ulonglong2double(
stats.data_file_length) / IO_SIZE + 2; }
2091 {
return rows2double(ranges+rows); }
2103 void *seq_init_param,
2104 uint n_ranges, uint *bufsz,
2108 uint *bufsz, uint *
flags,
2111 uint n_ranges, uint
mode,
2116 virtual const key_map *keys_to_use_for_scanning() {
return &key_map_empty; }
2117 bool has_transactions()
2119 virtual uint extra_rec_buf_length()
const {
return 0; }
2134 ((flags & HA_CHECK_DUP_KEY) &&
2135 (error == HA_ERR_FOUND_DUPP_KEY ||
2136 error == HA_ERR_FOUND_DUPP_UNIQUE)))
2153 {
return stats.records+EXTRA_RECORDS; }
2161 virtual const char *index_type(uint key_number) { DBUG_ASSERT(0);
return "";}
2172 uint get_index(
void)
const {
return active_index; }
2198 return HA_ERR_WRONG_COMMAND;
2214 return HA_ERR_WRONG_COMMAND;
2227 key_part_map keypart_map,
2228 enum ha_rkey_function find_flag)
2230 uint key_len= calculate_key_len(table, active_index, key, keypart_map);
2231 return index_read(buf, key, key_len, find_flag);
2241 key_part_map keypart_map,
2242 enum ha_rkey_function find_flag);
2245 {
return HA_ERR_WRONG_COMMAND; }
2248 {
return HA_ERR_WRONG_COMMAND; }
2251 {
return HA_ERR_WRONG_COMMAND; }
2254 {
return HA_ERR_WRONG_COMMAND; }
2264 key_part_map keypart_map)
2266 uint key_len= calculate_key_len(table, active_index, key, keypart_map);
2267 return index_read_last(buf, key, key_len);
2272 bool eq_range,
bool sorted);
2284 enum_range_scan_direction direction);
2286 int compare_key_icp(
const key_range *range)
const;
2287 virtual int ft_init() {
return HA_ERR_WRONG_COMMAND; }
2288 void ft_end() { ft_handler=NULL; }
2291 virtual int ft_read(uchar *
buf) {
return HA_ERR_WRONG_COMMAND; }
2296 virtual int rnd_pos(uchar *
buf, uchar *pos)=0;
2305 DBUG_ASSERT(table_flags() & HA_PRIMARY_KEY_REQUIRED_FOR_POSITION);
2315 {
return HA_ERR_WRONG_COMMAND; }
2316 virtual int rnd_same(uchar *
buf, uint inx)
2317 {
return HA_ERR_WRONG_COMMAND; }
2319 {
return (ha_rows) 10; }
2326 virtual void position(
const uchar *
record)=0;
2327 virtual int info(uint)=0;
2330 virtual uint32 calculate_key_hash_value(
Field **field_array)
2331 { DBUG_ASSERT(0);
return 0; }
2332 virtual int extra(
enum ha_extra_function operation)
2334 virtual int extra_opt(
enum ha_extra_function operation, ulong cache_size)
2335 {
return extra(operation); }
2342 { DBUG_ASSERT(0);
return false; }
2350 { DBUG_ASSERT(0);
return (ha_rows) 0; }
2372 virtual void unlock_row() {}
2373 virtual int start_stmt(THD *thd, thr_lock_type lock_type) {
return 0;}
2375 ulonglong nb_desired_values,
2376 ulonglong *first_value,
2377 ulonglong *nb_reserved_values);
2378 void set_next_insert_id(ulonglong
id)
2380 DBUG_PRINT(
"info",(
"auto_increment: next value %lu", (ulong)
id));
2400 int check_old_types();
2401 virtual int assign_to_keycache(THD* thd,
HA_CHECK_OPT* check_opt)
2402 {
return HA_ADMIN_NOT_IMPLEMENTED; }
2403 virtual int preload_keys(THD* thd,
HA_CHECK_OPT* check_opt)
2404 {
return HA_ADMIN_NOT_IMPLEMENTED; }
2407 virtual int indexes_are_disabled(
void) {
return 0;}
2408 virtual char *update_table_comment(
const char * comment)
2409 {
return (
char*) comment;}
2410 virtual void append_create_info(
String *packet) {}
2423 virtual char* get_foreign_key_create_info()
2462 virtual uint referenced_by_foreign_key() {
return 0;}
2463 virtual void init_table_handle_for_HANDLER()
2465 virtual void free_foreign_key_create_info(
char* str) {}
2479 virtual const char **
bas_ext()
const =0;
2481 virtual int get_default_no_partitions(
HA_CREATE_INFO *info) {
return 1;}
2482 virtual void set_auto_partitions(
partition_info *part_info) {
return; }
2500 virtual void set_part_info(
partition_info *part_info,
bool early) {
return;}
2502 virtual ulong index_flags(uint idx, uint part,
bool all_parts)
const =0;
2504 uint max_record_length()
const
2507 return min(HA_MAX_REC_LENGTH, max_supported_record_length());
2509 uint max_keys()
const
2512 return min(MAX_KEY, max_supported_keys());
2514 uint max_key_parts()
const
2517 return min(MAX_REF_PARTS, max_supported_key_parts());
2519 uint max_key_length()
const
2522 return min(MAX_KEY_LENGTH, max_supported_key_length());
2524 uint max_key_part_length()
const
2527 return min(MAX_KEY_LENGTH, max_supported_key_part_length());
2530 virtual uint max_supported_record_length()
const {
return HA_MAX_REC_LENGTH; }
2531 virtual uint max_supported_keys()
const {
return 0; }
2532 virtual uint max_supported_key_parts()
const {
return MAX_REF_PARTS; }
2533 virtual uint max_supported_key_length()
const {
return MAX_KEY_LENGTH; }
2534 virtual uint max_supported_key_part_length()
const {
return 255; }
2535 virtual uint min_record_length(uint options)
const {
return 1; }
2537 virtual bool low_byte_first()
const {
return 1; }
2538 virtual uint checksum()
const {
return 0; }
2539 virtual bool is_crashed()
const {
return 0; }
2540 virtual bool auto_repair()
const {
return 0; }
2543 #define CHF_CREATE_FLAG 0
2544 #define CHF_DELETE_FLAG 1
2545 #define CHF_RENAME_FLAG 2
2546 #define CHF_INDEX_FLAG 3
2568 enum thr_lock_type lock_type)=0;
2608 ulonglong *engine_data)
2610 *engine_callback= 0;
2620 virtual bool primary_key_is_clustered() {
return FALSE; }
2621 virtual int cmp_ref(
const uchar *ref1,
const uchar *ref2)
2690 pushed_idx_cond= NULL;
2691 pushed_idx_cond_keyno= MAX_KEY;
2692 in_range_check_pushed_down=
false;
2716 virtual int index_read_pushed(uchar *
buf,
const uchar * key,
2717 key_part_map keypart_map)
2718 {
return HA_ERR_WRONG_COMMAND; }
2720 virtual int index_next_pushed(uchar *
buf)
2721 {
return HA_ERR_WRONG_COMMAND; }
2728 {
return COMPATIBLE_DATA_NO; }
2836 virtual enum_alter_inplace_result
2997 virtual uint alter_table_flags(uint
flags)
2999 if (ht->alter_table_flags)
3000 return ht->alter_table_flags(flags);
3006 void ha_statistic_increment(ulonglong
SSV::*
offset)
const;
3007 void **ha_data(THD *)
const;
3008 THD *ha_thd(
void)
const;
3032 inline void mark_trx_read_write();
3039 virtual int open(
const char *
name,
int mode, uint test_if_locked)=0;
3040 virtual int close(
void)=0;
3041 virtual int index_init(uint idx,
bool sorted) { active_index= idx;
return 0; }
3042 virtual int index_end() { active_index= MAX_KEY;
return 0; }
3050 virtual int rnd_init(
bool scan)= 0;
3051 virtual int rnd_end() {
return 0; }
3052 virtual int write_row(uchar *
buf __attribute__((unused)))
3054 return HA_ERR_WRONG_COMMAND;
3065 virtual int update_row(
const uchar *old_data __attribute__((unused)),
3066 uchar *new_data __attribute__((unused)))
3068 return HA_ERR_WRONG_COMMAND;
3071 virtual int delete_row(
const uchar *
buf __attribute__((unused)))
3073 return HA_ERR_WRONG_COMMAND;
3080 virtual int reset() {
return 0; }
3081 virtual Table_flags table_flags(
void)
const= 0;
3104 virtual int external_lock(THD *thd __attribute__((unused)),
3105 int lock_type __attribute__((unused)))
3109 virtual void release_auto_increment() {
return; };
3114 {
return HA_ADMIN_NOT_IMPLEMENTED; }
3124 return HA_ADMIN_NOT_IMPLEMENTED;
3126 virtual void start_bulk_insert(ha_rows rows) {}
3127 virtual int end_bulk_insert() {
return 0; }
3129 virtual int index_read(uchar *
buf,
const uchar * key, uint key_len,
3130 enum ha_rkey_function find_flag)
3131 {
return HA_ERR_WRONG_COMMAND; }
3132 virtual int index_read_last(uchar *
buf,
const uchar * key, uint key_len)
3133 {
return (my_errno= HA_ERR_WRONG_COMMAND); }
3152 uint *dup_key_found)
3155 return HA_ERR_WRONG_COMMAND;
3164 {
return (my_errno=HA_ERR_WRONG_COMMAND); }
3184 {
return HA_ERR_WRONG_COMMAND; }
3191 {
return HA_ERR_WRONG_COMMAND; }
3192 virtual int optimize(THD* thd,
HA_CHECK_OPT* check_opt)
3193 {
return HA_ADMIN_NOT_IMPLEMENTED; }
3195 {
return HA_ADMIN_NOT_IMPLEMENTED; }
3196 virtual bool check_and_repair(THD *thd) {
return TRUE; }
3197 virtual int disable_indexes(uint
mode) {
return HA_ERR_WRONG_COMMAND; }
3198 virtual int enable_indexes(uint
mode) {
return HA_ERR_WRONG_COMMAND; }
3199 virtual int discard_or_import_tablespace(my_bool discard)
3200 {
return (my_errno=HA_ERR_WRONG_COMMAND); }
3201 virtual void drop_table(
const char *
name);
3204 virtual int create_handler_files(
const char *
name,
const char *old_name,
3210 ulonglong *
const copied,
3211 ulonglong *
const deleted,
3212 const uchar *pack_frm_data,
3213 size_t pack_frm_len)
3214 {
return HA_ERR_WRONG_COMMAND; }
3215 virtual int drop_partitions(
const char *path)
3216 {
return HA_ERR_WRONG_COMMAND; }
3217 virtual int rename_partitions(
const char *path)
3218 {
return HA_ERR_WRONG_COMMAND; }
3221 DBUG_ASSERT(!ha_share);
3222 DBUG_ASSERT(arg_ha_share);
3223 if (ha_share || !arg_ha_share)
3225 ha_share= arg_ha_share;
3228 int get_lock_type()
const {
return m_lock_type; }
3252 typedef void (
handler::*range_check_toggle_func_t)(
bool on);
3256 ~DsMrr_impl() { DBUG_ASSERT(h2 == NULL); }
3270 uchar *rowids_buf_cur;
3271 uchar *rowids_buf_last;
3272 uchar *rowids_buf_end;
3279 bool use_default_impl;
3302 int dsmrr_next(
char **range_info);
3304 ha_rows dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
3307 ha_rows dsmrr_info_const(uint keyno,
RANGE_SEQ_IF *seq,
3308 void *seq_init_param, uint n_ranges, uint *bufsz,
3311 bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz,
3313 bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags,
3318 extern const char *ha_row_type[];
3319 extern MYSQL_PLUGIN_IMPORT
const char *tx_isolation_names[];
3320 extern MYSQL_PLUGIN_IMPORT
const char *binlog_format_names[];
3321 extern TYPELIB tx_isolation_typelib;
3322 extern const char *myisam_stats_method_names[];
3323 extern ulong total_ha, total_ha_2pc;
3329 bool is_temp_table);
3331 handlerton *ha_resolve_by_legacy_type(THD *thd,
enum legacy_db_type db_type);
3335 bool no_substitute,
bool report_error);
3338 static inline enum legacy_db_type ha_legacy_type(
const handlerton *db_type)
3340 return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
3343 static inline const char *ha_resolve_storage_engine_name(
const handlerton *db_type)
3345 return db_type == NULL ?
"UNKNOWN" : hton2plugin[db_type->slot]->name.str;
3348 static inline bool ha_check_storage_engine_flag(
const handlerton *db_type, uint32 flag)
3350 return db_type == NULL ? FALSE :
test(db_type->flags & flag);
3353 static inline bool ha_storage_engine_is_enabled(
const handlerton *db_type)
3355 return (db_type && db_type->create) ?
3356 (db_type->state == SHOW_OPTION_YES) : FALSE;
3367 int ha_panic(
enum ha_panic_function flag);
3370 void ha_drop_database(
char* path);
3374 bool update_create_info,
3375 bool is_temp_table=
false);
3378 const char *db,
const char *alias,
bool generate_warning);
3381 bool ha_show_status(THD *thd,
handlerton *db_type,
enum ha_stat_type stat);
3387 int ha_discover(THD* thd,
const char* dbname,
const char*
name,
3388 uchar** frmblob,
size_t* frmlen);
3389 int ha_find_files(THD *thd,
const char *db,
const char *path,
3391 int ha_table_exists_in_engine(THD* thd,
const char* db,
const char*
name);
3405 int ha_start_consistent_snapshot(THD *thd);
3406 int ha_commit_or_rollback_by_xid(THD *thd,
XID *xid,
bool commit);
3407 int ha_commit_trans(THD *thd,
bool all,
bool ignore_global_read_lock=
false);
3408 int ha_rollback_trans(THD *thd,
bool all);
3410 int ha_recover(
HASH *commit_list);
3417 int ha_commit_low(THD *thd,
bool all,
bool run_after_commit=
true);
3418 int ha_prepare_low(THD *thd,
bool all);
3419 int ha_rollback_low(THD *thd,
bool all);
3425 int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
3427 int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
3440 #define trans_need_2pc(thd, all) ((total_ha_2pc > 1) && \
3441 !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
3443 #ifdef HAVE_NDB_BINLOG
3444 int ha_reset_logs(THD *thd);
3445 int ha_binlog_index_purge_file(THD *thd,
const char *file);
3446 void ha_reset_slave(THD *thd);
3447 void ha_binlog_log_query(THD *thd,
handlerton *db_type,
3448 enum_binlog_command binlog_command,
3449 const char *
query, uint query_length,
3451 void ha_binlog_wait(THD *thd);
3453 #define ha_reset_logs(a) do {} while (0)
3454 #define ha_binlog_index_purge_file(a,b) do {} while (0)
3455 #define ha_reset_slave(a) do {} while (0)
3456 #define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
3457 #define ha_binlog_wait(a) do {} while (0)
3461 int ha_binlog_end(THD *thd);
3463 const char *ha_legacy_type_name(legacy_db_type legacy_type);
3471 return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);