forked from mysql/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.h
6058 lines (5047 loc) · 211 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, 2018, 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, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
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, version 2.0, 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 <fcntl.h>
#include <float.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <algorithm>
#include <random> // std::mt19937
#include <set>
#include <string>
#include "ft_global.h" // ft_hints
#include "lex_string.h"
#include "m_ctype.h"
#include "map_helpers.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_double2ulonglong.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_sys.h"
#include "my_thread_local.h" // my_errno
#include "mysql/components/services/psi_table_bits.h"
#include "sql/dd/object_id.h" // dd::Object_id
#include "sql/dd/properties.h" // dd::Properties
#include "sql/dd/string_type.h"
#include "sql/dd/types/object_table.h" // dd::Object_table
#include "sql/discrete_interval.h" // Discrete_interval
#include "sql/json_dom.h"
#include "sql/key.h"
#include "sql/sql_const.h" // SHOW_COMP_OPTION
#include "sql/sql_list.h" // SQL_I_List
#include "sql/sql_plugin_ref.h" // plugin_ref
#include "thr_lock.h" // thr_lock_type
#include "typelib.h"
class Alter_info;
class Create_field;
class Field;
class Item;
class Partition_handler;
class Plugin_table;
class Plugin_tablespace;
class Record_buffer;
class SE_cost_constants; // see opt_costconstants.h
class String;
class THD;
class handler;
class partition_info;
struct System_status_var;
namespace dd {
class Properties;
} // namespace dd
struct FOREIGN_KEY_INFO;
struct KEY_CACHE;
struct MY_BITMAP;
struct SAVEPOINT;
struct TABLE;
struct TABLE_LIST;
struct TABLE_SHARE;
struct Tablespace_options;
struct handlerton;
typedef struct xid_t XID;
struct MDL_key;
namespace dd {
class Table;
class Tablespace;
struct sdi_key;
struct sdi_vector;
typedef sdi_key sdi_key_t;
typedef sdi_vector sdi_vector_t;
} // namespace dd
typedef bool (*qc_engine_callback)(THD *thd, const char *table_key,
uint key_length, ulonglong *engine_data);
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);
class ha_statistics;
class ha_tablespace_statistics;
namespace AQP {
class Join_plan;
}
extern ulong savepoint_alloc_size;
/// Maps from slot to plugin. May return NULL if plugin has been unloaded.
st_plugin_int *hton2plugin(uint slot);
/// Returns the size of the array holding pointers to plugins.
size_t num_hton2plugins();
/**
For unit testing.
Insert plugin into arbitrary slot in array.
Remove plugin from arbitrary slot in array.
*/
st_plugin_int *insert_hton2plugin(uint slot, st_plugin_int *plugin);
st_plugin_int *remove_hton2plugin(uint slot);
extern const char *ha_row_type[];
extern const char *tx_isolation_names[];
extern const char *binlog_format_names[];
extern TYPELIB tx_isolation_typelib;
extern ulong total_ha_2pc;
// 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
#define HA_ADMIN_STATS_UPD_ERR -13
/** User needs to dump and re-create table to fix pre 5.0 decimal types */
#define HA_ADMIN_NEEDS_DUMP_UPGRADE -14
/**
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,
HA_ALTER_INPLACE_INSTANT
};
/* 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 */
/*
Used to avoid scanning full tables on an index. If this flag is set then
the handler always has a primary key (hidden if not defined) and this
index is used for scanning rather than a full table scan in all
situations. No separate data/index file.
*/
#define HA_TABLE_SCAN_ON_INDEX (1 << 2)
/// Not in use.
#define HA_UNUSED3 (1 << 3)
/*
Can the storage engine handle spatial data.
Used to check that no spatial attributes are declared unless
the storage engine is capable of handling it.
*/
#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.
For further explanation see intro to init_read_record.
*/
#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)
/*
Is NULL values allowed in indexes.
If this is not allowed then it is not possible to use an index on a
NULLable field.
*/
#define HA_NULL_IN_KEY (1 << 7)
/*
Tells that we can the position for the conflicting duplicate key
record is stored in table->file->dupp_ref. (insert uses rnd_pos() on
this to find the duplicated row)
*/
#define HA_DUPLICATE_POS (1 << 8)
#define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
/*
Is the storage engine capable of defining an index of a prefix on
a BLOB attribute.
*/
#define HA_CAN_INDEX_BLOBS (1 << 10)
/*
Auto increment fields can be part of a multi-part key. For second part
auto-increment keys, the auto_incrementing is done in handler.cc
*/
#define HA_AUTO_PART_KEY (1 << 11)
/*
Can't define a table without primary key (and cannot handle a table
with hidden primary key)
*/
#define HA_REQUIRE_PRIMARY_KEY (1 << 12)
/*
Does the counter of records after the info call specify an exact
value or not. If it does this flag is set.
*/
#define HA_STATS_RECORDS_IS_EXACT (1 << 13)
/// Not in use.
#define HA_UNUSED14 (1 << 14)
/*
This parameter is set when the handler will also return the primary key
when doing read-only-key on another index, i.e., 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)
/*
Seems to be an old MyISAM feature that is no longer used. No handler
has it defined but it is checked in init_read_record. Further investigation
needed.
*/
#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)
/*
Indexes on prefixes of character fields are not allowed.
*/
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
/*
Does the storage engine support fulltext indexes.
*/
#define HA_CAN_FULLTEXT (1 << 21)
/*
Can the HANDLER interface in the MySQL API be used towards this
storage engine.
*/
#define HA_CAN_SQL_HANDLER (1 << 22)
/*
Set if the storage engine does not support auto increment fields.
*/
#define HA_NO_AUTO_INCREMENT (1 << 23)
/*
Supports CHECKSUM option in CREATE TABLE (MyISAM feature).
*/
#define HA_HAS_CHECKSUM (1 << 24)
/*
Table data are stored in separate files (for lower_case_table_names).
Should file names always be in lower case (used by engines that map
table names to file names.
*/
#define HA_FILE_BASED (1 << 26)
#define HA_NO_VARCHAR (1 << 27)
/*
Is the storage engine capable of handling bit fields.
*/
#define HA_CAN_BIT_FIELD (1 << 28)
#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
number of round-trips between handler and storage engine.
Example:
UPDATE a=1 WHERE pk IN (@<keys@>)
@verbatim
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
}
@endverbatim
@note This optimization in combination with batching may be used to
remove even more round-trips.
*/
#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)
/**
Supports descending indexes
*/
#define HA_DESCENDING_INDEX (1LL << 48)
/**
Supports partial update of BLOB columns.
*/
#define HA_BLOB_PARTIAL_UPDATE (1LL << 49)
/**
If this isn't defined, only columns/indexes with Cartesian coordinate systems
(projected SRS or SRID 0) is supported. Columns/indexes without SRID
restriction is also supported if this isn't defined.
*/
#define HA_SUPPORTS_GEOGRAPHIC_GEOMETRY_COLUMN (1LL << 50)
/*
Bits in index_flags(index_number) for what you can do with index.
If you do not implement indexes, just return zero here.
*/
/*
Does the index support read next, this is assumed in the server
code and never checked so all indexes must support this.
Note that the handler can be used even if it doesn't have any index.
*/
#define HA_READ_NEXT 1 /* TODO really use this flag */
/*
Can the index be used to scan backwards (supports ::index_prev).
*/
#define HA_READ_PREV 2
/*
Can the index deliver its record in index order. Typically true for
all ordered indexes and not true for hash indexes. Used to set keymap
part_of_sortkey.
This keymap is only used to find indexes usable for resolving an ORDER BY
in the query. Thus in most cases index_read will work just fine without
order in result production. When this flag is set it is however safe to
order all output started by index_read since most engines do this. With
read_multi_range calls there is a specific flag setting order or not
order so in those cases ordering of index output can be avoided.
*/
#define HA_READ_ORDER 4
/*
Specify whether index can handle ranges, typically true for all
ordered indexes and not true for hash indexes.
Used by optimiser to check if ranges (as key >= 5) can be optimised
by index.
*/
#define HA_READ_RANGE 8
/*
Can't use part key searches. This is typically true for hash indexes
and typically not true for ordered indexes.
*/
#define HA_ONLY_WHOLE_INDEX 16
/*
Does the storage engine support index-only scans on this index.
Enables use of HA_EXTRA_KEYREAD and HA_EXTRA_NO_KEYREAD
Used to set Key_map keys_for_keyread and to check in optimiser for
index-only scans. When doing a read under HA_EXTRA_KEYREAD the handler
only have to fill in the columns the key covers. If
HA_PRIMARY_KEY_IN_READ_INDEX is set then also the PRIMARY KEY columns
must be updated in the row.
*/
#define HA_KEYREAD_ONLY 64
/*
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
/*
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_MAX_REC_LENGTH 65535U
/**
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, // No longer used.
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_TEMPTABLE,
DB_TYPE_FIRST_DYNAMIC = 42,
DB_TYPE_DEFAULT = 127 // Must be last
};
enum row_type : int {
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_PAGED
};
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
};
enum class enum_sampling_method { SYSTEM };
/* 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)
/** ENCRYPTION="Y" used during table create. */
#define HA_CREATE_USED_ENCRYPT (1L << 27)
/**
CREATE|ALTER SCHEMA|DATABASE|TABLE has an explicit COLLATE clause.
Implies HA_CREATE_USED_DEFAULT_CHARSET.
*/
#define HA_CREATE_USED_DEFAULT_COLLATE (1L << 28)
/*
End of bits used in used_fields
*/
/*
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
/*
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
// FUTURE: Combine these two enums into one enum class
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,
// FUTURE: Remove these as they are never used, execpt as case labels in SE
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,
ALTER_TABLESPACE_RENAME = 3
};
/**
Legacy struct for passing tablespace information to SEs.
FUTURE: Pass all info through dd objects
*/
class st_alter_tablespace {
public:
const char *tablespace_name = nullptr;
const char *logfile_group_name = nullptr;
ts_command_type ts_cmd_type = TS_CMD_NOT_DEFINED;
enum ts_alter_tablespace_type ts_alter_tablespace_type =
TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED;
const char *data_file_name = nullptr;
const char *undo_file_name = nullptr;
ulonglong extent_size = 1024 * 1024; // Default 1 MByte
ulonglong undo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
ulonglong redo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
ulonglong initial_size = 128 * 1024 * 1024; // Default 128 MByte
ulonglong autoextend_size = 0; // No autoextension as default
ulonglong max_size = 0; // Max size == initial size => no extension
ulonglong file_block_size = 0; // 0=default or must be a valid Page Size
uint nodegroup_id = UNDEF_NODEGROUP;
bool wait_until_completed = true;
const char *ts_comment = nullptr;
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;
}
/**
Proper constructor even for all-public class simplifies initialization and
allows members to be const.
FUTURE: With constructor all members can be made const, and do not need
default initializers.
@param tablespace name of tabelspace (nullptr for logfile group statements)
@param logfile_group name of logfile group or nullptr
@param cmd main statement type
@param alter_tablespace_cmd subcommand type for ALTER TABLESPACE
@param datafile tablespace file for CREATE and ALTER ... ADD ...
@param undofile only applies to logfile group statements. nullptr otherwise.
@param opts options provided by parser
*/
st_alter_tablespace(const char *tablespace, const char *logfile_group,
ts_command_type cmd,
enum ts_alter_tablespace_type alter_tablespace_cmd,
const char *datafile, const char *undofile,
const Tablespace_options &opts);
};
/*
Make sure that the order of schema_tables and enum_schema_tables are the same.
*/
enum enum_schema_tables {
SCH_FIRST = 0,
SCH_COLUMN_PRIVILEGES = SCH_FIRST,
SCH_ENGINES,
SCH_OPEN_TABLES,
SCH_OPTIMIZER_TRACE,
SCH_PLUGINS,
SCH_PROCESSLIST,
SCH_PROFILES,
SCH_SCHEMA_PRIVILEGES,
SCH_TABLESPACES,
SCH_TABLE_PRIVILEGES,
SCH_USER_PRIVILEGES,
SCH_TMP_TABLE_COLUMNS,
SCH_TMP_TABLE_KEYS,
SCH_LAST = SCH_TMP_TABLE_KEYS
};
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
enum ha_notification_type : int { HA_NOTIFY_PRE_EVENT, HA_NOTIFY_POST_EVENT };
/** Clone operation types. */
enum Ha_clone_type {
/** Caller must block all write operation to the SE. */
HA_CLONE_BLOCKING = 1,
/** For transactional SE, archive redo to support concurrent dml */
HA_CLONE_REDO,
/** For transactional SE, track page changes to support concurrent dml */
HA_CLONE_PAGE,
/** For transactional SE, use both page tracking and redo to optimize
clone with concurrent dml. Currently supported by Innodb. */
HA_CLONE_HYBRID
};
/** File reference for clone */
struct Ha_clone_file {
/** File reference type */
enum {
/** File handle */
FILE_HANDLE,
/** File descriptor */
FILE_DESC
} type;
/** File reference */
union {
/** File descriptor */
int file_desc;
/** File handle for windows */
void *file_handle;
};
};
/* Abstract callback interface to stream data back to the caller. */
class Ha_clone_cbk {
public:
/** Callback providing data from current position of a
file descriptor of specific length.
@param[in] from_file source file to read from
@param[in] len data length
@return error code */
virtual int file_cbk(Ha_clone_file from_file, uint len) = 0;
/** Callback providing data in buffer of specific length.
@param[in] from_buffer source buffer to read from
@param[in] len data length
@return error code */
virtual int buffer_cbk(uchar *from_buffer, uint len) = 0;
/** Callback providing a file descriptor to write data starting
from current position.
@param[in] to_file destination file to write data
@return error code */
virtual int apply_file_cbk(Ha_clone_file to_file) = 0;
/** virtual destructor. */
virtual ~Ha_clone_cbk() {}
/** Set current storage engine handlerton.
@param[in] hton SE handlerton */
void set_hton(handlerton *hton) { m_hton = hton; }
/** Get current storage engine handlerton.
@return SE handlerton */
handlerton *get_hton() { return (m_hton); }
/** Set caller's transfer buffer size. SE can adjust the data chunk size
based on this parameter.
@param[in] size buffer size in bytes */
void set_client_buffer_size(uint size) { m_client_buff_size = size; }
/** Get caller's transfer buffer size.
@return buffer size in bytes */
uint get_client_buffer_size() { return (m_client_buff_size); }
/** Set current SE index.
@param[in] idx SE index in locator array */
void set_loc_index(uint idx) { m_loc_idx = idx; }
/** Get current SE index.
@return SE index in locator array */
uint get_loc_index() { return (m_loc_idx); }
/** Set data descriptor. SE specific descriptor for the
data transferred by the callbacks.
@param[in] desc serialized data descriptor
@param[in] len length of the descriptor byte stream */
void set_data_desc(uchar *desc, uint len) {
m_data_desc = desc;
m_desc_len = len;
}
/** Get data descriptor. SE specific descriptor for the
data transferred by the callbacks.
@param[out] lenp length of the descriptor byte stream
@return pointer to the serialized data descriptor */
uchar *get_data_desc(uint *lenp) {
if (lenp != nullptr) {
*lenp = m_desc_len;
}
return (m_data_desc);
}
/** Get SE source file name. Used for debug printing and error message.
@return null terminated string for source file name */
const char *get_source_name() { return (m_src_name); }
/** Set SE source file name.
@param[in] name null terminated string for source file name */
void set_source_name(const char *name) { m_src_name = name; }
/** Get SE destination file name. Used for debug printing and error message.
@return null terminated string for destination file name */
const char *get_dest_name() { return (m_dest_name); }
/** Set SE destination file name.
@param[in] name null terminated string for destination file name */
void set_dest_name(const char *name) { m_dest_name = name; }
/** Clear all flags set by SE */
void clear_flags() { m_flag = 0; }
/* Mark that ACK is needed for the data transfer before returning
from callback. Set by SE. */
void set_ack() { m_flag |= HA_CLONE_ACK; }
/** Check if ACK is needed for the data transfer
@return true if ACK is needed */
bool is_ack_needed() { return (m_flag & HA_CLONE_ACK); }
/* Mark that the file descriptor is opened for read/write
with OS buffer cache. For O_DIRECT, the flag is not set. */
void set_os_buffer_cache() { m_flag |= HA_CLONE_FILE_CACHE; }
/** Check if the file descriptor is opened for read/write with OS
buffer cache. Currently clone avoids using zero copy (sendfile on linux),
if SE is using O_DIRECT. This improves data copy performance.
@return true if O_DIRECT is not used */
bool is_os_buffer_cache() { return (m_flag & HA_CLONE_FILE_CACHE); }
private:
/** Handlerton for the SE */
handlerton *m_hton;
/** SE index in caller's locator array */
uint m_loc_idx;
/** Caller's transfer buffer size. */
uint m_client_buff_size;
/** SE's Serialized data descriptor */
uchar *m_data_desc;
uint m_desc_len;