/
handler.h
4891 lines (4248 loc) · 172 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, 2019, Oracle and/or its affiliates.
Copyright (c) 2009, 2019, MariaDB
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-1335 USA
*/
/* Definitions for parameters to do with handler-routines */
#ifdef USE_PRAGMA_INTERFACE
#pragma interface /* gcc class implementation */
#endif
#include "sql_const.h"
#include "sql_basic_types.h"
#include "mysqld.h" /* server_id */
#include "sql_plugin.h" /* plugin_ref, st_plugin_int, plugin */
#include "thr_lock.h" /* thr_lock_type, THR_LOCK_DATA */
#include "sql_cache.h"
#include "structs.h" /* SHOW_COMP_OPTION */
#include "sql_array.h" /* Dynamic_array<> */
#include "mdl.h"
#include "vers_string.h"
#include "sql_analyze_stmt.h" // for Exec_time_tracker
#include <my_compare.h>
#include <ft_global.h>
#include <keycache.h>
#include <mysql/psi/mysql_table.h>
#include "sql_sequence.h"
class Alter_info;
class Virtual_column_info;
class sequence_definition;
// 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
/**
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_COPY_NO_LOCK,
HA_ALTER_INPLACE_COPY_LOCK,
HA_ALTER_INPLACE_NOCOPY_LOCK,
HA_ALTER_INPLACE_NOCOPY_NO_LOCK,
HA_ALTER_INPLACE_INSTANT,
HA_ALTER_INPLACE_NOT_SUPPORTED,
HA_ALTER_INPLACE_EXCLUSIVE_LOCK,
HA_ALTER_INPLACE_SHARED_LOCK,
HA_ALTER_INPLACE_NO_LOCK
};
/* Bits in table_flags() to show what database can do */
#define HA_NO_TRANSACTIONS (1ULL << 0) /* Doesn't support transactions */
#define HA_PARTIAL_COLUMN_READ (1ULL << 1) /* read may not return all columns */
#define HA_TABLE_SCAN_ON_INDEX (1ULL << 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 (1ULL << 3)
#define HA_CAN_GEOMETRY (1ULL << 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 (1ULL << 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 (1ULL << 6)
#define HA_NULL_IN_KEY (1ULL << 7) /* One can have keys with NULL */
#define HA_DUPLICATE_POS (1ULL << 8) /* ha_position() gives dup row */
#define HA_NO_BLOBS (1ULL << 9) /* Doesn't support blobs */
#define HA_CAN_INDEX_BLOBS (1ULL << 10)
#define HA_AUTO_PART_KEY (1ULL << 11) /* auto-increment in multi-part key */
#define HA_REQUIRE_PRIMARY_KEY (1ULL << 12) /* .. and can't create a hidden one */
#define HA_STATS_RECORDS_IS_EXACT (1ULL << 13) /* stats.records is exact */
/*
INSERT_DELAYED only works with handlers that uses MySQL internal table
level locks
*/
#define HA_CAN_INSERT_DELAYED (1ULL << 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 (1ULL << 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 (1ULL << 16)
#define HA_CAN_RTREEKEYS (1ULL << 17)
#define HA_NOT_DELETE_WITH_CACHE (1ULL << 18) /* unused */
/*
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 (1ULL << 19)
#define HA_NO_PREFIX_CHAR_KEYS (1ULL << 20)
#define HA_CAN_FULLTEXT (1ULL << 21)
#define HA_CAN_SQL_HANDLER (1ULL << 22)
#define HA_NO_AUTO_INCREMENT (1ULL << 23)
/* Has automatic checksums and uses the old checksum format */
#define HA_HAS_OLD_CHECKSUM (1ULL << 24)
/* Table data are stored in separate files (for lower_case_table_names) */
#define HA_FILE_BASED (1ULL << 26)
#define HA_CAN_BIT_FIELD (1ULL << 28) /* supports bit fields */
#define HA_NEED_READ_RANGE_BUFFER (1ULL << 29) /* for read_multi_range */
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1ULL << 30)
#define HA_NO_COPY_ON_ALTER (1ULL << 31)
#define HA_HAS_RECORDS (1ULL << 32) /* records() gives exact count*/
/* Has it's own method of binlog logging */
#define HA_HAS_OWN_BINLOGGING (1ULL << 33)
/*
Engine is capable of row-format and statement-format logging,
respectively
*/
#define HA_BINLOG_ROW_CAPABLE (1ULL << 34)
#define HA_BINLOG_STMT_CAPABLE (1ULL << 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 (1ULL << 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 (1ULL << 37)
/* Has automatic checksums and uses the new checksum format */
#define HA_HAS_NEW_CHECKSUM (1ULL << 38)
#define HA_CAN_VIRTUAL_COLUMNS (1ULL << 39)
#define HA_MRR_CANT_SORT (1ULL << 40)
#define HA_RECORD_MUST_BE_CLEAN_ON_WRITE (1ULL << 41) /* unused */
/*
This storage engine supports condition pushdown
*/
#define HA_CAN_TABLE_CONDITION_PUSHDOWN (1ULL << 42)
/* old name for the same flag */
#define HA_MUST_USE_TABLE_CONDITION_PUSHDOWN HA_CAN_TABLE_CONDITION_PUSHDOWN
/**
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 (1ULL << 43)
/*
Engine supports extended fulltext API
*/
#define HA_CAN_FULLTEXT_EXT (1ULL << 44)
/*
Storage engine supports table export using the
FLUSH TABLE <table_list> FOR EXPORT statement
(meaning, after this statement one can copy table files out of the
datadir and later "import" (somehow) in another MariaDB instance)
*/
#define HA_CAN_EXPORT (1ULL << 45)
/*
Storage engine does not require an exclusive metadata lock
on the table during optimize. (TODO and repair?).
It can allow other connections to open the table.
(it does not necessarily mean that other connections can
read or modify the table - this is defined by THR locks and the
::store_lock() method).
*/
#define HA_CONCURRENT_OPTIMIZE (1ULL << 46)
/*
If the storage engine support tables that will not roll back on commit
In addition the table should not lock rows and support READ and WRITE
UNCOMMITTED.
This is useful for implementing things like SEQUENCE but can also in
the future be useful to do logging that should never roll back.
*/
#define HA_CAN_TABLES_WITHOUT_ROLLBACK (1ULL << 47)
/*
Mainly for usage by SEQUENCE engine. Setting this flag means
that the table will never roll back and that all operations
for this table should stored in the non transactional log
space that will always be written, even on rollback.
*/
#define HA_PERSISTENT_TABLE (1ULL << 48)
/*
Set of all binlog flags. Currently only contain the capabilities
flags.
*/
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
/* The following are used by Spider */
#define HA_CAN_FORCE_BULK_UPDATE (1ULL << 50)
#define HA_CAN_FORCE_BULK_DELETE (1ULL << 51)
#define HA_CAN_DIRECT_UPDATE_AND_DELETE (1ULL << 52)
/* The following is for partition handler */
#define HA_CAN_MULTISTEP_MERGE (1LL << 53)
/* calling cmp_ref() on the engine is expensive */
#define HA_CMP_REF_IS_EXPENSIVE (1ULL << 54)
/* Engine wants primary keys for everything except sequences */
#define HA_WANTS_PRIMARY_KEY (1ULL << 55)
/* 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 */
/*
Data is clustered on this key. This means that when you read the key
you also get the row data without any additional disk reads.
*/
#define HA_CLUSTERED_INDEX 512
/*
bits in alter_table_flags:
*/
/*
These bits are set if different kinds of indexes can be created or dropped
in-place without re-creating the table using a temporary table.
NO_READ_WRITE indicates that the handler needs concurrent reads and writes
of table data to be blocked.
Partitioning needs both ADD and DROP to be supported by its underlying
handlers, due to error handling, see bug#57778.
*/
#define HA_INPLACE_ADD_INDEX_NO_READ_WRITE (1UL << 0)
#define HA_INPLACE_DROP_INDEX_NO_READ_WRITE (1UL << 1)
#define HA_INPLACE_ADD_UNIQUE_INDEX_NO_READ_WRITE (1UL << 2)
#define HA_INPLACE_DROP_UNIQUE_INDEX_NO_READ_WRITE (1UL << 3)
#define HA_INPLACE_ADD_PK_INDEX_NO_READ_WRITE (1UL << 4)
#define HA_INPLACE_DROP_PK_INDEX_NO_READ_WRITE (1UL << 5)
/*
These are set if different kinds of indexes can be created or dropped
in-place while still allowing concurrent reads (but not writes) of table
data. If a handler is capable of one or more of these, it should also set
the corresponding *_NO_READ_WRITE bit(s).
*/
#define HA_INPLACE_ADD_INDEX_NO_WRITE (1UL << 6)
#define HA_INPLACE_DROP_INDEX_NO_WRITE (1UL << 7)
#define HA_INPLACE_ADD_UNIQUE_INDEX_NO_WRITE (1UL << 8)
#define HA_INPLACE_DROP_UNIQUE_INDEX_NO_WRITE (1UL << 9)
#define HA_INPLACE_ADD_PK_INDEX_NO_WRITE (1UL << 10)
#define HA_INPLACE_DROP_PK_INDEX_NO_WRITE (1UL << 11)
/*
HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
supported at all.
HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
exists but they are not necessarily done online.
HA_ONLINE_DOUBLE_WRITE means that the handler supports writing to both
the new partition and to the old partitions when updating through the
old partitioning schema while performing a change of the partitioning.
This means that we can support updating of the table while performing
the copy phase of the change. For no lock at all also a double write
from new to old must exist and this is not required when this flag is
set.
This is actually removed even before it was introduced the first time.
The new idea is that handlers will handle the lock level already in
store_lock for ALTER TABLE partitions.
HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
care of changing the partitions online and in one phase. Thus all phases
needed to handle the change are implemented inside the storage engine.
The storage engine must also support auto-discovery since the frm file
is changed as part of the change and this change must be controlled by
the storage engine. A typical engine to support this is NDB (through
WL #2498).
*/
#define HA_PARTITION_FUNCTION_SUPPORTED (1UL << 12)
#define HA_FAST_CHANGE_PARTITION (1UL << 13)
#define HA_PARTITION_ONE_PHASE (1UL << 14)
/* 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.
TODO remove the limit, use dynarrays
*/
#define MAX_HA 64
/*
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 1U
#define HA_READ_ONLY 16U /* File opened as readonly */
/* Try readonly if can't open with read and write */
#define HA_TRY_READ_ONLY 32U
/* Some key definitions */
#define HA_KEY_NULL_LENGTH 1
#define HA_KEY_BLOB_LENGTH 2
/* Maximum length of any index lookup key, in bytes */
#define MAX_KEY_LENGTH (MAX_DATA_LENGTH_FOR_KEY \
+(MAX_REF_PARTS \
*(HA_KEY_NULL_LENGTH + HA_KEY_BLOB_LENGTH)))
#define HA_LEX_CREATE_TMP_TABLE 1U
#define HA_CREATE_TMP_ALTER 8U
#define HA_LEX_CREATE_SEQUENCE 16U
#define HA_VERSIONED_TABLE 32U
#define HA_MAX_REC_LENGTH 65535
/* Table caching type */
#define HA_CACHE_TBL_NONTRANSACT 0
#define HA_CACHE_TBL_NOCACHE 1U
#define HA_CACHE_TBL_ASKTRANSACT 2U
#define HA_CACHE_TBL_TRANSACT 4U
/**
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;
/* Flags for method is_fatal_error */
#define HA_CHECK_DUP_KEY 1U
#define HA_CHECK_DUP_UNIQUE 2U
#define HA_CHECK_FK_ERROR 4U
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
#define HA_CHECK_ALL (~0U)
/* Options for info_push() */
#define INFO_KIND_UPDATE_FIELDS 101
#define INFO_KIND_UPDATE_VALUES 102
#define INFO_KIND_FORCE_LIMIT_BEGIN 103
#define INFO_KIND_FORCE_LIMIT_END 104
enum legacy_db_type
{
/* note these numerical values are fixed and can *not* be changed */
DB_TYPE_UNKNOWN=0,
DB_TYPE_HEAP=6,
DB_TYPE_MYISAM=9,
DB_TYPE_MRG_MYISAM=10,
DB_TYPE_INNODB=12,
DB_TYPE_EXAMPLE_DB=15,
DB_TYPE_ARCHIVE_DB=16,
DB_TYPE_CSV_DB=17,
DB_TYPE_FEDERATED_DB=18,
DB_TYPE_BLACKHOLE_DB=19,
DB_TYPE_PARTITION_DB=20,
DB_TYPE_BINLOG=21,
DB_TYPE_PBXT=23,
DB_TYPE_PERFORMANCE_SCHEMA=28,
DB_TYPE_ARIA=42,
DB_TYPE_TOKUDB=43,
DB_TYPE_SEQUENCE=44,
DB_TYPE_FIRST_DYNAMIC=45,
DB_TYPE_DEFAULT=127 // Must be last
};
/*
Better name for DB_TYPE_UNKNOWN. Should be used for engines that do not have
a hard-coded type value here.
*/
#define DB_TYPE_AUTOASSIGN DB_TYPE_UNKNOWN
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, ROW_TYPE_PAGE };
/* not part of the enum, so that it shouldn't be in switch(row_type) */
#define ROW_TYPE_MAX ((uint)ROW_TYPE_PAGE + 1)
/* 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
};
/* struct to hold information about the table that should be created */
/* Bits in used_fields */
#define HA_CREATE_USED_AUTO (1UL << 0)
#define HA_CREATE_USED_RAID (1UL << 1) //RAID is no longer availble
#define HA_CREATE_USED_UNION (1UL << 2)
#define HA_CREATE_USED_INSERT_METHOD (1UL << 3)
#define HA_CREATE_USED_MIN_ROWS (1UL << 4)
#define HA_CREATE_USED_MAX_ROWS (1UL << 5)
#define HA_CREATE_USED_AVG_ROW_LENGTH (1UL << 6)
#define HA_CREATE_USED_PACK_KEYS (1UL << 7)
#define HA_CREATE_USED_CHARSET (1UL << 8)
#define HA_CREATE_USED_DEFAULT_CHARSET (1UL << 9)
#define HA_CREATE_USED_DATADIR (1UL << 10)
#define HA_CREATE_USED_INDEXDIR (1UL << 11)
#define HA_CREATE_USED_ENGINE (1UL << 12)
#define HA_CREATE_USED_CHECKSUM (1UL << 13)
#define HA_CREATE_USED_DELAY_KEY_WRITE (1UL << 14)
#define HA_CREATE_USED_ROW_FORMAT (1UL << 15)
#define HA_CREATE_USED_COMMENT (1UL << 16)
#define HA_CREATE_USED_PASSWORD (1UL << 17)
#define HA_CREATE_USED_CONNECTION (1UL << 18)
#define HA_CREATE_USED_KEY_BLOCK_SIZE (1UL << 19)
/* The following two are used by Maria engine: */
#define HA_CREATE_USED_TRANSACTIONAL (1UL << 20)
#define HA_CREATE_USED_PAGE_CHECKSUM (1UL << 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 (1UL << 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 (1UL << 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 (1UL << 24)
/* Create a sequence */
#define HA_CREATE_USED_SEQUENCE (1UL << 25)
typedef ulonglong alter_table_operations;
/*
These flags are set by the parser and describes the type of
operation(s) specified by the ALTER TABLE statement.
*/
// Set by parser for ADD [COLUMN]
#define ALTER_PARSER_ADD_COLUMN (1ULL << 0)
// Set by parser for DROP [COLUMN]
#define ALTER_PARSER_DROP_COLUMN (1ULL << 1)
// Set for CHANGE [COLUMN] | MODIFY [CHANGE] & mysql_recreate_table
#define ALTER_CHANGE_COLUMN (1ULL << 2)
// Set for ADD INDEX | ADD KEY | ADD PRIMARY KEY | ADD UNIQUE KEY |
// ADD UNIQUE INDEX | ALTER ADD [COLUMN]
#define ALTER_ADD_INDEX (1ULL << 3)
// Set for DROP PRIMARY KEY | DROP FOREIGN KEY | DROP KEY | DROP INDEX
#define ALTER_DROP_INDEX (1ULL << 4)
// Set for RENAME [TO]
#define ALTER_RENAME (1ULL << 5)
// Set for ORDER BY
#define ALTER_ORDER (1ULL << 6)
// Set for table_options, like table comment
#define ALTER_OPTIONS (1ULL << 7)
// Set for ALTER [COLUMN] ... SET DEFAULT ... | DROP DEFAULT
#define ALTER_CHANGE_COLUMN_DEFAULT (1ULL << 8)
// Set for DISABLE KEYS | ENABLE KEYS
#define ALTER_KEYS_ONOFF (1ULL << 9)
// Set for FORCE, ENGINE(same engine), by mysql_recreate_table()
#define ALTER_RECREATE (1ULL << 10)
// Set for ADD FOREIGN KEY
#define ALTER_ADD_FOREIGN_KEY (1ULL << 21)
// Set for DROP FOREIGN KEY
#define ALTER_DROP_FOREIGN_KEY (1ULL << 22)
// Set for ADD [COLUMN] FIRST | AFTER
#define ALTER_COLUMN_ORDER (1ULL << 25)
#define ALTER_ADD_CHECK_CONSTRAINT (1ULL << 27)
#define ALTER_DROP_CHECK_CONSTRAINT (1ULL << 28)
#define ALTER_RENAME_COLUMN (1ULL << 29)
#define ALTER_COLUMN_UNVERSIONED (1ULL << 30)
#define ALTER_ADD_SYSTEM_VERSIONING (1ULL << 31)
#define ALTER_DROP_SYSTEM_VERSIONING (1ULL << 32)
#define ALTER_ADD_PERIOD (1ULL << 33)
#define ALTER_DROP_PERIOD (1ULL << 34)
/*
Following defines are used by ALTER_INPLACE_TABLE
They do describe in more detail the type operation(s) to be executed
by the storage engine. For example, which type of type of index to be
added/dropped. These are set by fill_alter_inplace_info().
*/
#define ALTER_RECREATE_TABLE ALTER_RECREATE
#define ALTER_CHANGE_CREATE_OPTION ALTER_OPTIONS
#define ALTER_ADD_COLUMN (ALTER_ADD_VIRTUAL_COLUMN | \
ALTER_ADD_STORED_BASE_COLUMN | \
ALTER_ADD_STORED_GENERATED_COLUMN)
#define ALTER_DROP_COLUMN (ALTER_DROP_VIRTUAL_COLUMN | \
ALTER_DROP_STORED_COLUMN)
#define ALTER_COLUMN_DEFAULT ALTER_CHANGE_COLUMN_DEFAULT
// Add non-unique, non-primary index
#define ALTER_ADD_NON_UNIQUE_NON_PRIM_INDEX (1ULL << 35)
// Drop non-unique, non-primary index
#define ALTER_DROP_NON_UNIQUE_NON_PRIM_INDEX (1ULL << 36)
// Add unique, non-primary index
#define ALTER_ADD_UNIQUE_INDEX (1ULL << 37)
// Drop unique, non-primary index
#define ALTER_DROP_UNIQUE_INDEX (1ULL << 38)
// Add primary index
#define ALTER_ADD_PK_INDEX (1ULL << 39)
// Drop primary index
#define ALTER_DROP_PK_INDEX (1ULL << 40)
// Virtual generated column
#define ALTER_ADD_VIRTUAL_COLUMN (1ULL << 41)
// Stored base (non-generated) column
#define ALTER_ADD_STORED_BASE_COLUMN (1ULL << 42)
// Stored generated column
#define ALTER_ADD_STORED_GENERATED_COLUMN (1ULL << 43)
// Drop column
#define ALTER_DROP_VIRTUAL_COLUMN (1ULL << 44)
#define ALTER_DROP_STORED_COLUMN (1ULL << 45)
// Rename column (verified; ALTER_RENAME_COLUMN may use original name)
#define ALTER_COLUMN_NAME (1ULL << 46)
// Change column datatype
#define ALTER_VIRTUAL_COLUMN_TYPE (1ULL << 47)
#define ALTER_STORED_COLUMN_TYPE (1ULL << 48)
/**
Change column datatype in such way that new type has compatible
packed representation with old type, so it is theoretically
possible to perform change by only updating data dictionary
without changing table rows.
*/
#define ALTER_COLUMN_EQUAL_PACK_LENGTH (1ULL << 49)
// Reorder column
#define ALTER_STORED_COLUMN_ORDER (1ULL << 50)
// Reorder column
#define ALTER_VIRTUAL_COLUMN_ORDER (1ULL << 51)
// Change column from NOT NULL to NULL
#define ALTER_COLUMN_NULLABLE (1ULL << 52)
// Change column from NULL to NOT NULL
#define ALTER_COLUMN_NOT_NULLABLE (1ULL << 53)
// Change column generation expression
#define ALTER_VIRTUAL_GCOL_EXPR (1ULL << 54)
#define ALTER_STORED_GCOL_EXPR (1ULL << 55)
// column's engine options changed, something in field->option_struct
#define ALTER_COLUMN_OPTION (1ULL << 56)
// MySQL alias for the same thing:
#define ALTER_COLUMN_STORAGE_TYPE ALTER_COLUMN_OPTION
// Change the column format of column
#define ALTER_COLUMN_COLUMN_FORMAT (1ULL << 57)
/**
Changes in generated columns that affect storage,
for example, when a vcol type or expression changes
and this vcol is indexed or used in a partitioning expression
*/
#define ALTER_COLUMN_VCOL (1ULL << 58)
/**
ALTER TABLE for a partitioned table. The engine needs to commit
online alter of all partitions atomically (using group_commit_ctx)
*/
#define ALTER_PARTITIONED (1ULL << 59)
/**
Change in index length such that it doesn't require index rebuild.
*/
#define ALTER_COLUMN_INDEX_LENGTH (1ULL << 60)
/*
Flags set in partition_flags when altering partitions
*/
// Set for ADD PARTITION
#define ALTER_PARTITION_ADD (1ULL << 1)
// Set for DROP PARTITION
#define ALTER_PARTITION_DROP (1ULL << 2)
// Set for COALESCE PARTITION
#define ALTER_PARTITION_COALESCE (1ULL << 3)
// Set for REORGANIZE PARTITION ... INTO
#define ALTER_PARTITION_REORGANIZE (1ULL << 4)
// Set for partition_options
#define ALTER_PARTITION_INFO (1ULL << 5)
// Set for LOAD INDEX INTO CACHE ... PARTITION
// Set for CACHE INDEX ... PARTITION
#define ALTER_PARTITION_ADMIN (1ULL << 6)
// Set for REBUILD PARTITION
#define ALTER_PARTITION_REBUILD (1ULL << 7)
// Set for partitioning operations specifying ALL keyword
#define ALTER_PARTITION_ALL (1ULL << 8)
// Set for REMOVE PARTITIONING
#define ALTER_PARTITION_REMOVE (1ULL << 9)
// Set for EXCHANGE PARITION
#define ALTER_PARTITION_EXCHANGE (1ULL << 10)
// Set by Sql_cmd_alter_table_truncate_partition::execute()
#define ALTER_PARTITION_TRUNCATE (1ULL << 11)
// Set for REORGANIZE PARTITION
#define ALTER_PARTITION_TABLE_REORG (1ULL << 12)
/*
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 system_database.system_table.
This is used at both mysqld and storage engine layer.
*/
struct st_system_tablename
{
const char *db;
const char *tablename;
};
typedef ulonglong my_xid; // this line is the same as in log_event.h
#define MYSQL_XID_PREFIX "MySQLXid"
#define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
#define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
#define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid))
#define XIDDATASIZE MYSQL_XIDDATASIZE
#define MAXGTRIDSIZE 64
#define MAXBQUALSIZE 64
#define COMPATIBLE_DATA_YES 0
#define COMPATIBLE_DATA_NO 1
/**
struct xid_t is binary compatible with the XID structure as
in the X/Open CAE Specification, Distributed Transaction Processing:
The XA Specification, X/Open Company Ltd., 1991.
http://www.opengroup.org/bookstore/catalog/c193.htm
@see MYSQL_XID in mysql/plugin.h
*/
struct xid_t {
long formatID;
long gtrid_length;
long bqual_length;
char data[XIDDATASIZE]; // not \0-terminated !
xid_t() {} /* Remove gcc warning */
bool eq(struct xid_t *xid) const
{ return !xid->is_null() && eq(xid->gtrid_length, xid->bqual_length, xid->data); }
bool eq(long g, long b, const char *d) const
{ return !is_null() && g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
void set(struct xid_t *xid)
{ memcpy(this, xid, xid->length()); }
void set(long f, const char *g, long gl, const char *b, long bl)
{
formatID= f;
memcpy(data, g, gtrid_length= gl);
memcpy(data+gl, b, bqual_length= bl);
}
void set(ulonglong xid)
{
my_xid tmp;
formatID= 1;
set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
tmp= xid;
memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
gtrid_length=MYSQL_XID_GTRID_LEN;
}
void set(long g, long b, const char *d)
{
formatID= 1;
gtrid_length= g;
bqual_length= b;
memcpy(data, d, g+b);
}
bool is_null() const { return formatID == -1; }
void null() { formatID= -1; }
my_xid quick_get_my_xid()
{
my_xid tmp;
memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
return tmp;
}
my_xid get_my_xid()
{
return gtrid_length == MYSQL_XID_GTRID_LEN && bqual_length == 0 &&
!memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
quick_get_my_xid() : 0;
}
uint length()
{
return static_cast<uint>(sizeof(formatID)) + key_length();
}
uchar *key() const
{
return (uchar *)>rid_length;
}
uint key_length() const
{
return static_cast<uint>(sizeof(gtrid_length)+sizeof(bqual_length)+
gtrid_length+bqual_length);
}
};
typedef struct xid_t XID;
/*
The size of XID string representation in the form
'gtrid', 'bqual', formatID
see xid_t::get_sql_string() for details.
*/
#define SQL_XIDSIZE (XIDDATASIZE * 2 + 8 + MY_INT64_NUM_DECIMAL_DIGITS)
/* The 'buf' has to have space for at least SQL_XIDSIZE bytes. */
uint get_sql_xid(XID *xid, char *buf);
/* for recover() handlerton call */
#define MIN_XID_LIST_SIZE 128
#define MAX_XID_LIST_SIZE (1024*128)
/*
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;
uint nodegroup_id;
handlerton *storage_engine;
bool wait_until_completed;
const char *ts_comment;
enum tablespace_access_mode ts_access_mode;
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;
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_ALL_PLUGINS,
SCH_APPLICABLE_ROLES,
SCH_CHARSETS,
SCH_CHECK_CONSTRAINTS,
SCH_COLLATIONS,
SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
SCH_COLUMNS,
SCH_COLUMN_PRIVILEGES,
SCH_ENABLED_ROLES,
SCH_ENGINES,
SCH_EVENTS,
SCH_EXPLAIN,
SCH_FILES,
SCH_GLOBAL_STATUS,
SCH_GLOBAL_VARIABLES,
SCH_KEY_CACHES,
SCH_KEY_COLUMN_USAGE,
SCH_OPEN_TABLES,
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_SYSTEM_VARIABLES,
SCH_TABLES,
SCH_TABLESPACES,
SCH_TABLE_CONSTRAINTS,
SCH_TABLE_NAMES,
SCH_TABLE_PRIVILEGES,
SCH_TRIGGERS,
SCH_USER_PRIVILEGES,