forked from mysql/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.h
4139 lines (3491 loc) · 142 KB
/
handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef HANDLER_INCLUDED
#define HANDLER_INCLUDED
/*
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Definitions for parameters to do with handler-routines */
#include "my_global.h"
#include "ft_global.h" // ft_hints
#include "my_thread_local.h" // my_errno
#include "thr_lock.h" // thr_lock_type
#include "discrete_interval.h" // Discrete_interval
#include "key.h" // KEY
#include "mysqld.h" // lower_case_table_names
#include "sql_const.h" // SHOW_COMP_OPTION
#include "sql_list.h" // SQL_I_List
#include "sql_plugin_ref.h" // plugin_ref
#include "mysql/psi/psi.h"
#include <algorithm>
#include <string>
class Alter_info;
class SE_cost_constants; // see opt_costconstants.h
class String;
struct TABLE_LIST;
typedef struct st_bitmap MY_BITMAP;
typedef struct st_hash HASH;
typedef struct st_key_cache KEY_CACHE;
typedef struct xid_t XID;
class partition_info;
class Partition_handler;
typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
uint key_length,
ulonglong *engine_data);
// the following is for checking tables
#define HA_ADMIN_ALREADY_DONE 1
#define HA_ADMIN_OK 0
#define HA_ADMIN_NOT_IMPLEMENTED -1
#define HA_ADMIN_FAILED -2
#define HA_ADMIN_CORRUPT -3
#define HA_ADMIN_INTERNAL_ERROR -4
#define HA_ADMIN_INVALID -5
#define HA_ADMIN_REJECT -6
#define HA_ADMIN_TRY_ALTER -7
#define HA_ADMIN_WRONG_CHECKSUM -8
#define HA_ADMIN_NOT_BASE_TABLE -9
#define HA_ADMIN_NEEDS_UPGRADE -10
#define HA_ADMIN_NEEDS_ALTER -11
#define HA_ADMIN_NEEDS_CHECK -12
/** Needs ALTER TABLE t UPGRADE PARTITIONING. */
#define HA_ADMIN_NEEDS_UPG_PART -13
/**
Return values for check_if_supported_inplace_alter().
@see check_if_supported_inplace_alter() for description of
the individual values.
*/
enum enum_alter_inplace_result {
HA_ALTER_ERROR,
HA_ALTER_INPLACE_NOT_SUPPORTED,
HA_ALTER_INPLACE_EXCLUSIVE_LOCK,
HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE,
HA_ALTER_INPLACE_SHARED_LOCK,
HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE,
HA_ALTER_INPLACE_NO_LOCK
};
/* Bits in table_flags() to show what database can do */
#define HA_NO_TRANSACTIONS (1 << 0) /* Doesn't support transactions */
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
/*
The following should be set if the following is not true when scanning
a table with rnd_next()
- We will see all rows (including deleted ones)
- Row positions are 'table->s->db_record_offset' apart
If this flag is not set, filesort will do a position() call for each matched
row to be able to find the row later.
*/
#define HA_REC_NOT_IN_SEQ (1 << 3)
#define HA_CAN_GEOMETRY (1 << 4)
/*
Reading keys in random order is as fast as reading keys in sort order
(Used in records.cc to decide if we should use a record cache and by
filesort to decide if we should sort key + data or key + pointer-to-row
*/
#define HA_FAST_KEY_READ (1 << 5)
/*
Set the following flag if we on delete should force all key to be read
and on update read all keys that changes
*/
#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
#define HA_NULL_IN_KEY (1 << 7) /* One can have keys with NULL */
#define HA_DUPLICATE_POS (1 << 8) /* position() gives dup row */
#define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
#define HA_CAN_INDEX_BLOBS (1 << 10)
#define HA_AUTO_PART_KEY (1 << 11) /* auto-increment in multi-part key */
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
/// Not in use.
#define HA_UNUSED (1 << 14)
/*
If we get the primary key columns for free when we do an index read
(usually, it also implies that HA_PRIMARY_KEY_REQUIRED_FOR_POSITION
flag is set).
*/
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
/*
If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
uses a primary key given by the record argument.
Without primary key, we can't call position().
If not set, the position is returned as the current rows position
regardless of what argument is given.
*/
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16)
#define HA_CAN_RTREEKEYS (1 << 17)
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
/*
The following is we need to a primary key to delete (and update) a row.
If there is no primary key, all columns needs to be read on update and delete
*/
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
#define HA_CAN_FULLTEXT (1 << 21)
#define HA_CAN_SQL_HANDLER (1 << 22)
#define HA_NO_AUTO_INCREMENT (1 << 23)
#define HA_HAS_CHECKSUM (1 << 24)
/* Table data are stored in separate files (for lower_case_table_names) */
#define HA_FILE_BASED (1 << 26)
#define HA_NO_VARCHAR (1 << 27)
#define HA_CAN_BIT_FIELD (1 << 28) /* supports bit fields */
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
#define HA_NO_COPY_ON_ALTER (1LL << 31)
#define HA_HAS_RECORDS (1LL << 32) /* records() gives exact count*/
/* Has it's own method of binlog logging */
#define HA_HAS_OWN_BINLOGGING (1LL << 33)
/*
Engine is capable of row-format and statement-format logging,
respectively
*/
#define HA_BINLOG_ROW_CAPABLE (1LL << 34)
#define HA_BINLOG_STMT_CAPABLE (1LL << 35)
/*
When a multiple key conflict happens in a REPLACE command mysql
expects the conflicts to be reported in the ascending order of
key names.
For e.g.
CREATE TABLE t1 (a INT, UNIQUE (a), b INT NOT NULL, UNIQUE (b), c INT NOT
NULL, INDEX(c));
REPLACE INTO t1 VALUES (1,1,1),(2,2,2),(2,1,3);
MySQL expects the conflict with 'a' to be reported before the conflict with
'b'.
If the underlying storage engine does not report the conflicting keys in
ascending order, it causes unexpected errors when the REPLACE command is
executed.
This flag helps the underlying SE to inform the server that the keys are not
ordered.
*/
#define HA_DUPLICATE_KEY_NOT_IN_ORDER (1LL << 36)
/*
Engine supports REPAIR TABLE. Used by CHECK TABLE FOR UPGRADE if an
incompatible table is detected. If this flag is set, CHECK TABLE FOR UPGRADE
will report ER_TABLE_NEEDS_UPGRADE, otherwise ER_TABLE_NEED_REBUILD.
*/
#define HA_CAN_REPAIR (1LL << 37)
/*
Set of all binlog flags. Currently only contain the capabilities
flags.
*/
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
/**
The handler supports read before write removal optimization
Read before write removal may be used for storage engines which support
write without previous read of the row to be updated. Handler returning
this flag must implement start_read_removal() and end_read_removal().
The handler may return "fake" rows constructed from the key of the row
asked for. This is used to optimize UPDATE and DELETE by reducing the
numer of roundtrips between handler and storage engine.
Example:
UPDATE a=1 WHERE pk IN (<keys>)
mysql_update()
{
if (<conditions for starting read removal>)
start_read_removal()
-> handler returns true if read removal supported for this table/query
while(read_record("pk=<key>"))
-> handler returns fake row with column "pk" set to <key>
ha_update_row()
-> handler sends write "a=1" for row with "pk=<key>"
end_read_removal()
-> handler returns the number of rows actually written
}
@note This optimization in combination with batching may be used to
remove even more roundtrips.
*/
#define HA_READ_BEFORE_WRITE_REMOVAL (1LL << 38)
/*
Engine supports extended fulltext API
*/
#define HA_CAN_FULLTEXT_EXT (1LL << 39)
/*
Storage engine doesn't synchronize result set with expected table contents.
Used by replication slave to check if it is possible to retrieve rows from
the table when deciding whether to do a full table scan, index scan or hash
scan while applying a row event.
*/
#define HA_READ_OUT_OF_SYNC (1LL << 40)
/*
Storage engine supports table export using the
FLUSH TABLE <table_list> FOR EXPORT statement.
*/
#define HA_CAN_EXPORT (1LL << 41)
/*
The handler don't want accesses to this table to
be const-table optimized
*/
#define HA_BLOCK_CONST_TABLE (1LL << 42)
/*
Handler supports FULLTEXT hints
*/
#define HA_CAN_FULLTEXT_HINTS (1LL << 43)
/**
Storage engine doesn't support LOCK TABLE ... READ LOCAL locks
but doesn't want to use handler::store_lock() API for upgrading
them to LOCK TABLE ... READ locks, for example, because it doesn't
use THR_LOCK locks at all.
*/
#define HA_NO_READ_LOCAL_LOCK (1LL << 44)
/**
A storage engine is compatible with the attachable transaction requirements
means that
- either SE detects the fact that THD::ha_data was reset and starts a new
attachable transaction, closes attachable transaction on close_connection
and resumes regular (outer) transaction when THD::ha_data is restored;
- or SE completely ignores THD::ha_data and close_connection like MyISAM
does.
*/
#define HA_ATTACHABLE_TRX_COMPATIBLE (1LL << 45)
/**
Handler supports Generated Columns
*/
#define HA_GENERATED_COLUMNS (1LL << 46)
/**
Supports index on virtual generated column
*/
#define HA_CAN_INDEX_VIRTUAL_GENERATED_COLUMN (1LL << 47)
/* bits in index_flags(index_number) for what you can do with index */
#define HA_READ_NEXT 1 /* TODO really use this flag */
#define HA_READ_PREV 2 /* supports ::index_prev */
#define HA_READ_ORDER 4 /* index_next/prev follow sort order */
#define HA_READ_RANGE 8 /* can find all records in a range */
#define HA_ONLY_WHOLE_INDEX 16 /* Can't use part key searches */
#define HA_KEYREAD_ONLY 64 /* Support HA_EXTRA_KEYREAD */
/*
Index scan will not return records in rowid order. Not guaranteed to be
set for unordered (e.g. HASH) indexes.
*/
#define HA_KEY_SCAN_NOT_ROR 128
#define HA_DO_INDEX_COND_PUSHDOWN 256 /* Supports Index Condition Pushdown */
/* operations for disable/enable indexes */
#define HA_KEY_SWITCH_NONUNIQ 0
#define HA_KEY_SWITCH_ALL 1
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
#define HA_KEY_SWITCH_ALL_SAVE 3
/*
Note: the following includes binlog and closing 0.
so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
example + csv + heap + blackhole + federated + 0
(yes, the sum is deliberately inaccurate)
TODO remove the limit, use dynarrays
*/
#define MAX_HA 15
/*
Use this instead of 0 as the initial value for the slot number of
handlerton, so that we can distinguish uninitialized slot number
from slot 0.
*/
#define HA_SLOT_UNDEF ((uint)-1)
/*
Parameters for open() (in register form->filestat)
HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
*/
#define HA_OPEN_KEYFILE 1
#define HA_OPEN_RNDFILE 2
#define HA_GET_INDEX 4
#define HA_GET_INFO 8 /* do a handler::info() after open */
#define HA_READ_ONLY 16 /* File opened as readonly */
/* Try readonly if can't open with read and write */
#define HA_TRY_READ_ONLY 32
#define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
#define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */
#define HA_OPEN_TEMPORARY 512
/* Some key definitions */
#define HA_KEY_NULL_LENGTH 1
#define HA_KEY_BLOB_LENGTH 2
#define HA_LEX_CREATE_TMP_TABLE 1
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
#define HA_LEX_CREATE_TABLE_LIKE 4
#define HA_LEX_CREATE_INTERNAL_TMP_TABLE 8
#define HA_OPTION_NO_CHECKSUM (1L << 17)
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
#define HA_MAX_REC_LENGTH 65535U
/* Table caching type */
#define HA_CACHE_TBL_NONTRANSACT 0
#define HA_CACHE_TBL_NOCACHE 1
#define HA_CACHE_TBL_ASKTRANSACT 2
#define HA_CACHE_TBL_TRANSACT 4
/**
Options for the START TRANSACTION statement.
Note that READ ONLY and READ WRITE are logically mutually exclusive.
This is enforced by the parser and depended upon by trans_begin().
We need two flags instead of one in order to differentiate between
situation when no READ WRITE/ONLY clause were given and thus transaction
is implicitly READ WRITE and the case when READ WRITE clause was used
explicitly.
*/
// WITH CONSISTENT SNAPSHOT option
static const uint MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT = 1;
// READ ONLY option
static const uint MYSQL_START_TRANS_OPT_READ_ONLY = 2;
// READ WRITE option
static const uint MYSQL_START_TRANS_OPT_READ_WRITE = 4;
// HIGH PRIORITY option
static const uint MYSQL_START_TRANS_OPT_HIGH_PRIORITY = 8;
enum legacy_db_type
{
DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
DB_TYPE_FEDERATED_DB,
DB_TYPE_BLACKHOLE_DB,
DB_TYPE_PARTITION_DB,
DB_TYPE_BINLOG,
DB_TYPE_SOLID,
DB_TYPE_PBXT,
DB_TYPE_TABLE_FUNCTION,
DB_TYPE_MEMCACHE,
DB_TYPE_FALCON,
DB_TYPE_MARIA,
/** Performance schema engine. */
DB_TYPE_PERFORMANCE_SCHEMA,
DB_TYPE_FIRST_DYNAMIC=42,
DB_TYPE_DEFAULT=127 // Must be last
};
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT,
/** Unused. Reserved for future versions. */
ROW_TYPE_PAGE };
/* Specifies data storage format for individual columns */
enum column_format_type {
COLUMN_FORMAT_TYPE_DEFAULT= 0, /* Not specified (use engine default) */
COLUMN_FORMAT_TYPE_FIXED= 1, /* FIXED format */
COLUMN_FORMAT_TYPE_DYNAMIC= 2 /* DYNAMIC format */
};
enum enum_binlog_func {
BFN_RESET_LOGS= 1,
BFN_RESET_SLAVE= 2,
BFN_BINLOG_WAIT= 3,
BFN_BINLOG_END= 4,
BFN_BINLOG_PURGE_FILE= 5
};
enum enum_binlog_command {
LOGCOM_CREATE_TABLE,
LOGCOM_ALTER_TABLE,
LOGCOM_RENAME_TABLE,
LOGCOM_DROP_TABLE,
LOGCOM_CREATE_DB,
LOGCOM_ALTER_DB,
LOGCOM_DROP_DB,
LOGCOM_ACL_NOTIFY
};
/* struct to hold information about the table that should be created */
/* Bits in used_fields */
#define HA_CREATE_USED_AUTO (1L << 0)
#define HA_CREATE_USED_RAID (1L << 1) //RAID is no longer availble
#define HA_CREATE_USED_UNION (1L << 2)
#define HA_CREATE_USED_INSERT_METHOD (1L << 3)
#define HA_CREATE_USED_MIN_ROWS (1L << 4)
#define HA_CREATE_USED_MAX_ROWS (1L << 5)
#define HA_CREATE_USED_AVG_ROW_LENGTH (1L << 6)
#define HA_CREATE_USED_PACK_KEYS (1L << 7)
#define HA_CREATE_USED_CHARSET (1L << 8)
#define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
#define HA_CREATE_USED_DATADIR (1L << 10)
#define HA_CREATE_USED_INDEXDIR (1L << 11)
#define HA_CREATE_USED_ENGINE (1L << 12)
#define HA_CREATE_USED_CHECKSUM (1L << 13)
#define HA_CREATE_USED_DELAY_KEY_WRITE (1L << 14)
#define HA_CREATE_USED_ROW_FORMAT (1L << 15)
#define HA_CREATE_USED_COMMENT (1L << 16)
#define HA_CREATE_USED_PASSWORD (1L << 17)
#define HA_CREATE_USED_CONNECTION (1L << 18)
#define HA_CREATE_USED_KEY_BLOCK_SIZE (1L << 19)
/** Unused. Reserved for future versions. */
#define HA_CREATE_USED_TRANSACTIONAL (1L << 20)
/** Unused. Reserved for future versions. */
#define HA_CREATE_USED_PAGE_CHECKSUM (1L << 21)
/** This is set whenever STATS_PERSISTENT=0|1|default has been
specified in CREATE/ALTER TABLE. See also HA_OPTION_STATS_PERSISTENT in
include/my_base.h. It is possible to distinguish whether
STATS_PERSISTENT=default has been specified or no STATS_PERSISTENT= is
given at all. */
#define HA_CREATE_USED_STATS_PERSISTENT (1L << 22)
/**
This is set whenever STATS_AUTO_RECALC=0|1|default has been
specified in CREATE/ALTER TABLE. See enum_stats_auto_recalc.
It is possible to distinguish whether STATS_AUTO_RECALC=default
has been specified or no STATS_AUTO_RECALC= is given at all.
*/
#define HA_CREATE_USED_STATS_AUTO_RECALC (1L << 23)
/**
This is set whenever STATS_SAMPLE_PAGES=N|default has been
specified in CREATE/ALTER TABLE. It is possible to distinguish whether
STATS_SAMPLE_PAGES=default has been specified or no STATS_SAMPLE_PAGES= is
given at all.
*/
#define HA_CREATE_USED_STATS_SAMPLE_PAGES (1L << 24)
/**
This is set whenever a 'TABLESPACE=...' phrase is used on CREATE TABLE
*/
#define HA_CREATE_USED_TABLESPACE (1L << 25)
/** COMPRESSION="zlib|lz4|none" used during table create. */
#define HA_CREATE_USED_COMPRESS (1L << 26)
/*
This is master database for most of system tables. However there
can be other databases which can hold system tables. Respective
storage engines define their own system database names.
*/
extern const char *mysqld_system_database;
/*
Structure to hold list of database_name.table_name.
This is used at both mysqld and storage engine layer.
*/
struct st_handler_tablename
{
const char *db;
const char *tablename;
};
#define MAXGTRIDSIZE 64
#define MAXBQUALSIZE 64
#define COMPATIBLE_DATA_YES 0
#define COMPATIBLE_DATA_NO 1
namespace AQP {
class Join_plan;
};
/** ENCRYPTION="Y" used during table create. */
#define HA_CREATE_USED_ENCRYPT (1L << 27)
/*
These structures are used to pass information from a set of SQL commands
on add/drop/change tablespace definitions to the proper hton.
*/
#define UNDEF_NODEGROUP 65535
enum ts_command_type
{
TS_CMD_NOT_DEFINED = -1,
CREATE_TABLESPACE = 0,
ALTER_TABLESPACE = 1,
CREATE_LOGFILE_GROUP = 2,
ALTER_LOGFILE_GROUP = 3,
DROP_TABLESPACE = 4,
DROP_LOGFILE_GROUP = 5,
CHANGE_FILE_TABLESPACE = 6,
ALTER_ACCESS_MODE_TABLESPACE = 7
};
enum ts_alter_tablespace_type
{
TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1,
ALTER_TABLESPACE_ADD_FILE = 1,
ALTER_TABLESPACE_DROP_FILE = 2
};
enum tablespace_access_mode
{
TS_NOT_DEFINED= -1,
TS_READ_ONLY = 0,
TS_READ_WRITE = 1,
TS_NOT_ACCESSIBLE = 2
};
struct handlerton;
class st_alter_tablespace : public Sql_alloc
{
public:
const char *tablespace_name;
const char *logfile_group_name;
enum ts_command_type ts_cmd_type;
enum ts_alter_tablespace_type ts_alter_tablespace_type;
const char *data_file_name;
const char *undo_file_name;
const char *redo_file_name;
ulonglong extent_size;
ulonglong undo_buffer_size;
ulonglong redo_buffer_size;
ulonglong initial_size;
ulonglong autoextend_size;
ulonglong max_size;
ulonglong file_block_size;
uint nodegroup_id;
handlerton *storage_engine;
bool wait_until_completed;
const char *ts_comment;
enum tablespace_access_mode ts_access_mode;
bool is_tablespace_command()
{
return ts_cmd_type == CREATE_TABLESPACE ||
ts_cmd_type == ALTER_TABLESPACE ||
ts_cmd_type == DROP_TABLESPACE ||
ts_cmd_type == CHANGE_FILE_TABLESPACE ||
ts_cmd_type == ALTER_ACCESS_MODE_TABLESPACE;
}
/** Default constructor */
st_alter_tablespace()
{
tablespace_name= NULL;
logfile_group_name= "DEFAULT_LG"; //Default log file group
ts_cmd_type= TS_CMD_NOT_DEFINED;
data_file_name= NULL;
undo_file_name= NULL;
redo_file_name= NULL;
extent_size= 1024*1024; // Default 1 MByte
undo_buffer_size= 8*1024*1024; // Default 8 MByte
redo_buffer_size= 8*1024*1024; // Default 8 MByte
initial_size= 128*1024*1024; // Default 128 MByte
autoextend_size= 0; // No autoextension as default
max_size= 0; // Max size == initial size => no extension
storage_engine= NULL;
file_block_size= 0; // 0=default or must be a valid Page Size
nodegroup_id= UNDEF_NODEGROUP;
wait_until_completed= TRUE;
ts_comment= NULL;
ts_access_mode= TS_NOT_DEFINED;
}
};
/* The handler for a table type. Will be included in the TABLE structure */
struct TABLE;
/*
Make sure that the order of schema_tables and enum_schema_tables are the same.
*/
enum enum_schema_tables
{
SCH_CHARSETS= 0,
SCH_COLLATIONS,
SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
SCH_COLUMNS,
SCH_COLUMN_PRIVILEGES,
SCH_ENGINES,
SCH_EVENTS,
SCH_FILES,
SCH_GLOBAL_STATUS,
SCH_GLOBAL_VARIABLES,
SCH_KEY_COLUMN_USAGE,
SCH_OPEN_TABLES,
SCH_OPTIMIZER_TRACE,
SCH_PARAMETERS,
SCH_PARTITIONS,
SCH_PLUGINS,
SCH_PROCESSLIST,
SCH_PROFILES,
SCH_REFERENTIAL_CONSTRAINTS,
SCH_PROCEDURES,
SCH_SCHEMATA,
SCH_SCHEMA_PRIVILEGES,
SCH_SESSION_STATUS,
SCH_SESSION_VARIABLES,
SCH_STATISTICS,
SCH_STATUS,
SCH_TABLES,
SCH_TABLESPACES,
SCH_TABLE_CONSTRAINTS,
SCH_TABLE_NAMES,
SCH_TABLE_PRIVILEGES,
SCH_TRIGGERS,
SCH_USER_PRIVILEGES,
SCH_VARIABLES,
SCH_VIEWS
};
struct TABLE_SHARE;
struct st_foreign_key_info;
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
typedef 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);
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
enum ha_notification_type { HA_NOTIFY_PRE_EVENT, HA_NOTIFY_POST_EVENT };
extern st_plugin_int *hton2plugin[MAX_HA];
class handler;
/*
handlerton is a singleton structure - one instance per storage engine -
to provide access to storage engine functionality that works on the
"global" level (unlike handler class that works on a per-table basis)
usually handlerton instance is defined statically in ha_xxx.cc as
static handlerton { ... } xxx_hton;
savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
*/
struct handlerton
{
/*
Historical marker for if the engine is available of not
*/
SHOW_COMP_OPTION state;
/*
Historical number used for frm file to determine the correct storage engine.
This is going away and new engines will just use "name" for this.
*/
enum legacy_db_type db_type;
/*
each storage engine has it's own memory area (actually a pointer)
in the thd, for storing per-connection information.
It is accessed as
thd->ha_data[xxx_hton.slot]
slot number is initialized by MySQL after xxx_init() is called.
*/
uint slot;
/*
to store per-savepoint data storage engine is provided with an area
of a requested size (0 is ok here).
savepoint_offset must be initialized statically to the size of
the needed memory to store per-savepoint information.
After xxx_init it is changed to be an offset to savepoint storage
area and need not be used by storage engine.
see binlog_hton and binlog_savepoint_set/rollback for an example.
*/
uint savepoint_offset;
/*
handlerton methods:
close_connection is only called if
thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
this storage area - set it to something, so that MySQL would know
this storage engine was accessed in this connection
*/
int (*close_connection)(handlerton *hton, THD *thd);
/* Terminate connection/statement notification. */
void (*kill_connection)(handlerton *hton, THD *thd);
/*
sv points to an uninitialized storage area of requested size
(see savepoint_offset description)
*/
int (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
/*
sv points to a storage area, that was earlier passed
to the savepoint_set call
*/
int (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
/**
Check if storage engine allows to release metadata locks which were
acquired after the savepoint if rollback to savepoint is done.
@return true - If it is safe to release MDL locks.
false - If it is not.
*/
bool (*savepoint_rollback_can_release_mdl)(handlerton *hton, THD *thd);
int (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
/*
'all' is true if it's a real commit, that makes persistent changes
'all' is false if it's not in fact a commit but an end of the
statement that is part of the transaction.
NOTE 'all' is also false in auto-commit mode where 'end of statement'
and 'real commit' mean the same event.
*/
int (*commit)(handlerton *hton, THD *thd, bool all);
int (*rollback)(handlerton *hton, THD *thd, bool all);
int (*prepare)(handlerton *hton, THD *thd, bool all);
int (*recover)(handlerton *hton, XID *xid_list, uint len);
int (*commit_by_xid)(handlerton *hton, XID *xid);
int (*rollback_by_xid)(handlerton *hton, XID *xid);
handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
void (*drop_database)(handlerton *hton, char* path);
int (*panic)(handlerton *hton, enum ha_panic_function flag);
int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
/**
Flush the log(s) of storage engine(s).
@param hton Handlerton of storage engine.
@param binlog_group_flush true if we got invoked by binlog group
commit during flush stage, false in other cases.
@retval false Succeed
@retval true Error
*/
bool (*flush_logs)(handlerton *hton, bool binlog_group_flush);
bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
/*
The flag values are defined in sql_partition.h.
If this function is set, then it implies that the handler supports
partitioned tables.
If this function exists, then handler::get_partition_handler must also be
implemented.
*/
uint (*partition_flags)();
/**
Get the tablespace name from the SE for the given schema and table.
@param thd Thread context.
@param db_name Name of the relevant schema.
@param table_name Name of the relevant table.
@param [out] tablespace_name Name of the tablespace containing the table.
@return Operation status.
@retval == 0 Success.
@retval != 0 Error (handler error code returned).
*/
int (*get_tablespace)(THD* thd, LEX_CSTRING db_name, LEX_CSTRING table_name,
LEX_CSTRING *tablespace_name);
int (*alter_tablespace)(handlerton *hton, THD *thd, st_alter_tablespace *ts_info);
int (*fill_is_table)(handlerton *hton, THD *thd, TABLE_LIST *tables,
class Item *cond,
enum enum_schema_tables);
uint32 flags; /* global handler flags */
/*
Those handlerton functions below are properly initialized at handler
init.
*/
int (*binlog_func)(handlerton *hton, THD *thd, enum_binlog_func fn, void *arg);
void (*binlog_log_query)(handlerton *hton, THD *thd,
enum_binlog_command binlog_command,
const char *query, uint query_length,
const char *db, const char *table_name);
int (*release_temporary_latches)(handlerton *hton, THD *thd);
int (*discover)(handlerton *hton, THD* thd, const char *db,
const char *name,
uchar **frmblob,
size_t *frmlen);
int (*find_files)(handlerton *hton, THD *thd,
const char *db,
const char *path,
const char *wild, bool dir, List<LEX_STRING> *files);
int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
const char *name);
int (*make_pushed_join)(handlerton *hton, THD* thd,
const AQP::Join_plan* plan);
/**
List of all system tables specific to the SE.
Array element would look like below,
{ "<database_name>", "<system table name>" },
The last element MUST be,
{ (const char*)NULL, (const char*)NULL }
@see ha_example_system_tables in ha_example.cc
This interface is optional, so every SE need not implement it.
*/
const char* (*system_database)();
/**
Check if the given db.tablename is a system table for this SE.
@param db Database name to check.
@param table_name table name to check.
@param is_sql_layer_system_table if the supplied db.table_name is a SQL
layer system table.
@see example_is_supported_system_table in ha_example.cc
is_sql_layer_system_table is supplied to make more efficient
checks possible for SEs that support all SQL layer tables.
This interface is optional, so every SE need not implement it.
*/
bool (*is_supported_system_table)(const char *db,
const char *table_name,
bool is_sql_layer_system_table);
/**
Retrieve cost constants to be used for this storage engine.
A storage engine that wants to provide its own cost constants to
be used in the optimizer cost model, should implement this function.
The server will call this function to get a cost constant object
that will be used for tables stored in this storage engine instead
of using the default cost constants.
Life cycle for the cost constant object: The storage engine must
allocate the cost constant object on the heap. After the function
returns, the server takes over the ownership of this object.
The server will eventually delete the object by calling delete.
@note In the initial version the storage_category parameter will
not be used. The only valid value this will have is DEFAULT_STORAGE_CLASS
(see declartion in opt_costconstants.h).
@param storage_category the storage type that the cost constants will
be used for
@return a pointer to the cost constant object, if NULL is returned
the default cost constants will be used
*/
SE_cost_constants *(*get_cost_constants)(uint storage_category);
/**
@param[in,out] thd pointer to THD
@param[in] new_trx_arg pointer to replacement transaction
@param[out] ptr_trx_arg double pointer to being replaced transaction
Associated with THD engine's native transaction is replaced
with @c new_trx_arg. The old value is returned through a buffer if non-null
pointer is provided with @c ptr_trx_arg.
The method is adapted by XA start and XA prepare handlers to
handle XA transaction that is logged as two parts by slave applier.
This interface concerns engines that are aware of XA transaction.
*/
void (*replace_native_transaction_in_thd)(THD *thd, void *new_trx_arg,
void **ptr_trx_arg);
/**
Notify/get permission from storage engine before acquisition or after
release of exclusive metadata lock on object represented by key.
@param thd Thread context.
@param mdl_key MDL key identifying object on which exclusive
lock is to be acquired/was released.
@param notification_type Indicates whether this is pre-acquire or
post-release notification.
@param victimized 'true' if locking failed as we were selected
as a victim in order to avoid possible deadlocks.
@note Notification is done only for objects from TABLESPACE, SCHEMA,
TABLE, FUNCTION, PROCEDURE, TRIGGER and EVENT namespaces.
@note Problems during notification are to be reported as warnings, MDL
subsystem will report generic error if pre-acquire notification
fails/SE refuses lock acquisition.
@note Return value is ignored/error is not reported in case of
post-release notification.
@note In some cases post-release notification might happen even if
there were no prior pre-acquire notification. For example,
when SE was loaded after exclusive lock acquisition, or when
we need notify SEs which permitted lock acquisition that it
didn't happen because one of SEs didn't allow it (in such case
we will do post-release notification for all SEs for simplicity).
@return False - if notification was successful/lock can be acquired,
True - if it has failed/lock should not be acquired.
*/
bool (*notify_exclusive_mdl)(THD *thd, const MDL_key *mdl_key,
ha_notification_type notification_type,
bool *victimized);
/**
Notify/get permission from storage engine before or after execution of
ALTER TABLE operation on the table identified by the MDL key.
@param thd Thread context.
@param mdl_key MDL key identifying table which is going to be
or was ALTERed.
@param notification_type Indicates whether this is pre-ALTER TABLE or
post-ALTER TABLE notification.
@note This hook is necessary because for ALTER TABLE upgrade to X
metadata lock happens fairly late during the execution process,
so it can be expensive to abort ALTER TABLE operation at this
stage by returning failure from notify_exclusive_mdl() hook.
@note This hook follows the same error reporting convention as
@see notify_exclusive_mdl().
@note Similarly to notify_exclusive_mdl() in some cases post-ALTER
notification might happen even if there were no prior pre-ALTER
notification.
@note Post-ALTER notification can happen before post-release notification
for exclusive metadata lock acquired by this ALTER TABLE.
@return False - if notification was successful/ALTER TABLE can proceed.
True - if it has failed/ALTER TABLE should be aborted.
*/
bool (*notify_alter_table)(THD *thd, const MDL_key *mdl_key,
ha_notification_type notification_type);
/**
@brief
Initiate master key rotation
@returns false on success,
true on failure
*/
bool (*rotate_encryption_master_key)(void);
uint32 license; /* Flag for Engine License */
void *data; /* Location for engines to keep personal structures */
};
/* Possible flags of a handlerton (there can be 32 of them) */
#define HTON_NO_FLAGS 0
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
#define HTON_ALTER_NOT_SUPPORTED (1 << 1) //Engine does not support alter
#define HTON_CAN_RECREATE (1 << 2) //Delete all is used fro truncate
#define HTON_HIDDEN (1 << 3) //Engine does not appear in lists
#define HTON_FLUSH_AFTER_RENAME (1 << 4)
#define HTON_NOT_USER_SELECTABLE (1 << 5)
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
#define HTON_SUPPORT_LOG_TABLES (1 << 7) //Engine supports log tables