-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathsql_class.h
More file actions
8713 lines (7708 loc) · 275 KB
/
sql_class.h
File metadata and controls
8713 lines (7708 loc) · 275 KB
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
/*
Copyright (c) 2000, 2016, Oracle and/or its affiliates.
Copyright (c) 2009, 2025, MariaDB Corporation.
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 Street, Fifth Floor, Boston, MA 02110-1335 USA */
#ifndef SQL_CLASS_INCLUDED
#define SQL_CLASS_INCLUDED
/* Classes in mysql */
#include <atomic>
#include <thread>
#include "dur_prop.h"
#include <waiting_threads.h>
#include "sql_array.h"
#include "sql_const.h"
#include "lex_ident.h"
#include "sql_used.h"
#include <mysql/plugin_audit.h>
#include "log.h"
#include "rpl_tblmap.h"
#include "mdl.h"
#include "field.h" // Create_field
#include "opt_trace_context.h"
#include "probes_mysql.h"
#include "sql_locale.h" /* my_locale_st */
#include "sql_profile.h" /* PROFILING */
#include "scheduler.h" /* thd_scheduler */
#include "protocol.h" /* Protocol_text, Protocol_binary */
#include "violite.h" /* vio_is_connected */
#include "thr_lock.h" /* thr_lock_type, THR_LOCK_DATA, THR_LOCK_INFO */
#include "thr_timer.h"
#include "thr_malloc.h"
#include "log_slow.h" /* LOG_SLOW_DISABLE_... */
#include <my_tree.h>
#include "sql_digest_stream.h" // sql_digest_state
#include <mysql/psi/mysql_stage.h>
#include <mysql/psi/mysql_statement.h>
#include <mysql/psi/mysql_idle.h>
#include <mysql/psi/mysql_table.h>
#include <mysql_com_server.h>
#include "session_tracker.h"
#include "sql_path.h"
#include "backup.h"
#include "xa.h"
#include "scope.h"
#include "ddl_log.h" /* DDL_LOG_STATE */
#include "ha_handler_stats.h" // ha_handler_stats */
#include "sql_basic_types.h" // enum class active_dml_stmt
#include "sql_trigger.h"
extern "C"
void set_thd_stage_info(void *thd,
const PSI_stage_info *new_stage,
PSI_stage_info *old_stage,
const char *calling_func,
const char *calling_file,
const unsigned int calling_line);
#define THD_STAGE_INFO(thd, stage) \
(thd)->enter_stage(&stage, __func__, __FILE__, __LINE__)
#include "my_apc.h"
#include "rpl_gtid_base.h"
#include "wsrep.h"
#include "wsrep_on.h"
#include <inttypes.h>
#include <ilist.h>
#ifdef WITH_WSREP
/* wsrep-lib */
#include "wsrep_client_service.h"
#include "wsrep_client_state.h"
#include "wsrep_mutex.h"
#include "wsrep_condition_variable.h"
class Wsrep_applier_service;
enum wsrep_consistency_check_mode {
NO_CONSISTENCY_CHECK,
CONSISTENCY_CHECK_DECLARED,
CONSISTENCY_CHECK_RUNNING,
};
#endif /* WITH_WSREP */
class Reprepare_observer;
class Relay_log_info;
struct rpl_group_info;
struct rpl_parallel_thread;
class Rpl_filter;
class Query_log_event;
class Log_event_writer;
class sp_rcontext;
class sp_cache;
class Lex_input_stream;
class Parser_state;
class Rows_log_event;
class Sroutine_hash_entry;
class user_var_entry;
struct Trans_binlog_info;
class rpl_io_thread_info;
class rpl_sql_thread_info;
#ifdef HAVE_REPLICATION
struct Slave_info;
#endif
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME };
enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
DELAY_KEY_WRITE_ALL };
enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRINGENT,
SLAVE_EXEC_MODE_STRICT,
SLAVE_EXEC_MODE_IDEMPOTENT,
SLAVE_EXEC_MODE_LAST_BIT };
enum enum_slave_run_triggers_for_rbr { SLAVE_RUN_TRIGGERS_FOR_RBR_NO,
SLAVE_RUN_TRIGGERS_FOR_RBR_YES,
SLAVE_RUN_TRIGGERS_FOR_RBR_LOGGING,
SLAVE_RUN_TRIGGERS_FOR_RBR_ENFORCE};
enum enum_slave_type_conversions { SLAVE_TYPE_CONVERSIONS_ALL_LOSSY,
SLAVE_TYPE_CONVERSIONS_ALL_NON_LOSSY,
SLAVE_TYPE_CONVERSIONS_ERROR_IF_MISSING_FIELD };
enum read_only_options { READONLY_OFF, READONLY_ON, READONLY_NO_LOCK,
READONLY_NO_LOCK_NO_ADMIN};
/*
COLUMNS_READ: A column is goind to be read.
COLUMNS_WRITE: A column is going to be written to.
MARK_COLUMNS_READ: A column is goind to be read.
A bit in read set is set to inform handler that the field
is to be read. If field list contains duplicates, then
thd->dup_field is set to point to the last found
duplicate.
MARK_COLUMNS_WRITE: A column is going to be written to.
A bit is set in write set to inform handler that it needs
to update this field in write_row and update_row.
*/
enum enum_column_usage
{ COLUMNS_READ, COLUMNS_WRITE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE};
static inline bool should_mark_column(enum_column_usage column_usage)
{ return column_usage >= MARK_COLUMNS_READ; }
enum enum_filetype { FILETYPE_CSV, FILETYPE_XML };
enum enum_binlog_row_image {
/** PKE in the before image and changed columns in the after image */
BINLOG_ROW_IMAGE_MINIMAL= 0,
/** Whenever possible, before and after image contain all columns except blobs. */
BINLOG_ROW_IMAGE_NOBLOB= 1,
/** All columns in both before and after image. */
BINLOG_ROW_IMAGE_FULL= 2,
/** All columns in before image, but only updated columns in after image */
BINLOG_ROW_IMAGE_FULL_NODUP= 3
};
/* Bits for different SQL modes modes (including ANSI mode) */
#define MODE_REAL_AS_FLOAT (1ULL << 0)
#define MODE_PIPES_AS_CONCAT (1ULL << 1)
#define MODE_ANSI_QUOTES (1ULL << 2)
#define MODE_IGNORE_SPACE (1ULL << 3)
#define MODE_IGNORE_BAD_TABLE_OPTIONS (1ULL << 4)
#define MODE_ONLY_FULL_GROUP_BY (1ULL << 5)
#define MODE_NO_UNSIGNED_SUBTRACTION (1ULL << 6)
#define MODE_NO_DIR_IN_CREATE (1ULL << 7)
#define MODE_POSTGRESQL (1ULL << 8)
#define MODE_ORACLE (1ULL << 9)
#define MODE_MSSQL (1ULL << 10)
#define MODE_DB2 (1ULL << 11)
#define MODE_MAXDB (1ULL << 12)
#define MODE_NO_KEY_OPTIONS (1ULL << 13)
#define MODE_NO_TABLE_OPTIONS (1ULL << 14)
#define MODE_NO_FIELD_OPTIONS (1ULL << 15)
#define MODE_MYSQL323 (1ULL << 16)
#define MODE_MYSQL40 (1ULL << 17)
#define MODE_ANSI (1ULL << 18)
#define MODE_NO_AUTO_VALUE_ON_ZERO (1ULL << 19)
#define MODE_NO_BACKSLASH_ESCAPES (1ULL << 20)
#define MODE_STRICT_TRANS_TABLES (1ULL << 21)
#define MODE_STRICT_ALL_TABLES (1ULL << 22)
#define MODE_NO_ZERO_IN_DATE (1ULL << 23)
#define MODE_NO_ZERO_DATE (1ULL << 24)
#define MODE_INVALID_DATES (1ULL << 25)
#define MODE_ERROR_FOR_DIVISION_BY_ZERO (1ULL << 26)
#define MODE_TRADITIONAL (1ULL << 27)
#define MODE_NO_AUTO_CREATE_USER (1ULL << 28)
#define MODE_HIGH_NOT_PRECEDENCE (1ULL << 29)
#define MODE_NO_ENGINE_SUBSTITUTION (1ULL << 30)
#define MODE_PAD_CHAR_TO_FULL_LENGTH (1ULL << 31)
/* SQL mode bits defined above are common for MariaDB and MySQL */
#define MODE_MASK_MYSQL_COMPATIBLE 0xFFFFFFFFULL
/* The following modes are specific to MariaDB */
#define MODE_EMPTY_STRING_IS_NULL (1ULL << 32)
#define MODE_SIMULTANEOUS_ASSIGNMENT (1ULL << 33)
#define MODE_TIME_ROUND_FRACTIONAL (1ULL << 34)
/* The following modes are specific to MySQL */
#define MODE_MYSQL80_TIME_TRUNCATE_FRACTIONAL (1ULL << 32)
#define WAS_ORACLE (1ULL << 35)
#define IS_OR_WAS_ORACLE (MODE_ORACLE | WAS_ORACLE)
/* Bits for different old style modes */
#define OLD_MODE_NO_DUP_KEY_WARNINGS_WITH_IGNORE (1 << 0)
#define OLD_MODE_NO_PROGRESS_INFO (1 << 1)
#define OLD_MODE_ZERO_DATE_TIME_CAST (1 << 2)
#define OLD_MODE_UTF8_IS_UTF8MB3 (1 << 3)
#define OLD_MODE_IGNORE_INDEX_ONLY_FOR_JOIN (1 << 4)
#define OLD_MODE_COMPAT_5_1_CHECKSUM (1 << 5)
#define OLD_MODE_NO_NULL_COLLATION_IDS (1 << 6)
#define OLD_MODE_LOCK_ALTER_TABLE_COPY (1 << 7)
#define OLD_MODE_OLD_FLUSH_STATUS (1 << 8)
#define OLD_MODE_SESSION_USER_IS_USER (1 << 9)
#define OLD_MODE_2_DIGIT_YEAR (1 << 10)
#define OLD_MODE_DEFAULT_VALUE OLD_MODE_UTF8_IS_UTF8MB3
void old_mode_deprecated_warnings(ulonglong v);
/*
Bits for @@new_mode -> thd->variables.new_behaviour system variable
See sys_vars.cc /new_mode_all_names
*/
#define NEW_MODE_MAX 0
/* Definitions above that have transitioned from new behaviour to default */
#define NOW_DEFAULT -1
#define TEST_NEW_MODE_FLAG(thd, flag) \
(flag == NOW_DEFAULT ? TRUE : thd->variables.new_behavior & flag)
extern char internal_table_name[2];
extern char empty_c_string[1];
extern MYSQL_PLUGIN_IMPORT const char **errmesg;
extern "C" LEX_STRING * thd_query_string (MYSQL_THD thd);
extern "C" unsigned long long thd_query_id(const MYSQL_THD thd);
extern "C" size_t thd_query_safe(MYSQL_THD thd, char *buf, size_t buflen);
extern "C" const char *thd_priv_user(MYSQL_THD thd, size_t *length);
extern "C" const char *thd_priv_host(MYSQL_THD thd, size_t *length);
extern "C" const char *thd_user_name(MYSQL_THD thd);
extern "C" const char *thd_client_host(MYSQL_THD thd);
extern "C" const char *thd_client_ip(MYSQL_THD thd);
extern "C" LEX_CSTRING *thd_current_db(MYSQL_THD thd);
extern "C" int thd_current_status(MYSQL_THD thd);
extern "C" enum enum_server_command thd_current_command(MYSQL_THD thd);
extern "C" int thd_double_innodb_cardinality(MYSQL_THD thd);
extern void mariadb_error_read_only();
/**
@class CSET_STRING
@brief Character set armed LEX_STRING
*/
class CSET_STRING
{
private:
LEX_STRING string;
CHARSET_INFO *cs;
public:
CSET_STRING() : cs(&my_charset_bin)
{
string.str= NULL;
string.length= 0;
}
CSET_STRING(char *str_arg, size_t length_arg, CHARSET_INFO *cs_arg) :
cs(cs_arg)
{
DBUG_ASSERT(cs_arg != NULL);
string.str= str_arg;
string.length= length_arg;
}
inline char *str() const { return string.str; }
inline size_t length() const { return string.length; }
CHARSET_INFO *charset() const { return cs; }
friend LEX_STRING * thd_query_string (MYSQL_THD thd);
};
template <typename T> class Slice
{
T m_offset;
T m_count;
public:
Slice(T offset, T count)
:m_offset(offset), m_count(count)
{ }
T offset() const { return m_offset; }
T count() const { return m_count; }
};
class Recreate_info
{
public:
ha_rows copied;
ha_rows duplicate;
uchar tabledef_version[MY_UUID_SIZE];
Recreate_info()
:copied(0),
duplicate(0)
{
bzero(tabledef_version, sizeof(tabledef_version));
}
ha_rows records_copied() const { return copied; }
ha_rows records_duplicate() const { return duplicate; }
ha_rows records_processed() const
{
return copied + duplicate;
}
};
#define TC_HEURISTIC_RECOVER_COMMIT 1
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
extern ulong tc_heuristic_recover;
typedef struct st_user_var_events
{
user_var_entry *user_var_event;
char *value;
size_t length;
const Type_handler *th;
uint charset_number;
} BINLOG_USER_VAR_EVENT;
/*
The COPY_INFO structure is used by INSERT/REPLACE code.
The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
UPDATE code:
If a row is inserted then the copied variable is incremented.
If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
new data differs from the old one then the copied and the updated
variables are incremented.
The touched variable is incremented if a row was touched by the update part
of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
was actually changed or not.
*/
typedef struct st_copy_info {
ha_rows records; /**< Number of processed records */
ha_rows deleted; /**< Number of deleted records */
ha_rows updated; /**< Number of updated records */
ha_rows copied; /**< Number of copied records */
ha_rows accepted_rows; /**< Number of accepted original rows
(same as number of rows in RETURNING) */
ha_rows error_count;
ha_rows touched; /* Number of touched records */
enum enum_duplicates handle_duplicates;
int escape_char, last_errno;
bool ignore;
/* for INSERT ... UPDATE */
List<Item> *update_fields;
List<Item> *update_values;
/* for VIEW ... WITH CHECK OPTION */
TABLE_LIST *view;
TABLE_LIST *table_list; /* Normal table */
} COPY_INFO;
class Key_part_spec :public Sql_alloc {
public:
Lex_ident_column field_name;
uint length;
bool generated, asc;
Key_part_spec(const LEX_CSTRING *name, uint len, bool gen= false)
: field_name(*name), length(len), generated(gen), asc(1)
{}
bool operator==(const Key_part_spec& other) const;
/**
Construct a copy of this Key_part_spec. field_name is copied
by-pointer as it is known to never change. At the same time
'length' may be reset in mysql_prepare_create_table, and this
is why we supply it with a copy.
@return If out of memory, 0 is returned and an error is set in
THD.
*/
Key_part_spec *clone(MEM_ROOT *mem_root) const
{ return new (mem_root) Key_part_spec(*this); }
bool check_key_for_blob(const class handler *file) const;
bool check_key_length_for_blob() const;
bool check_primary_key_for_blob(const class handler *file) const
{
return check_key_for_blob(file) || check_key_length_for_blob();
}
bool check_foreign_key_for_blob(const class handler *file) const
{
return check_key_for_blob(file) || check_key_length_for_blob();
}
bool init_multiple_key_for_blob(const class handler *file);
};
class Alter_drop :public Sql_alloc {
public:
enum drop_type { KEY, COLUMN, FOREIGN_KEY, CHECK_CONSTRAINT, PERIOD };
Lex_ident_column name;
enum drop_type type;
bool drop_if_exists;
Alter_drop(enum drop_type par_type,
const LEX_CSTRING &par_name,
bool par_exists)
:name(par_name), type(par_type), drop_if_exists(par_exists)
{
DBUG_ASSERT(par_name.str != NULL);
}
/**
Used to make a clone of this object for ALTER/CREATE TABLE
@sa comment for Key_part_spec::clone
*/
Alter_drop *clone(MEM_ROOT *mem_root) const
{ return new (mem_root) Alter_drop(*this); }
const char *type_name()
{
return type == COLUMN ? "COLUMN" :
type == CHECK_CONSTRAINT ? "CONSTRAINT" :
type == PERIOD ? "PERIOD" :
type == KEY ? "INDEX" : "FOREIGN KEY";
}
};
class Alter_column :public Sql_alloc {
public:
LEX_CSTRING name;
LEX_CSTRING new_name;
Virtual_column_info *default_value;
bool alter_if_exists;
Alter_column(LEX_CSTRING par_name, Virtual_column_info *expr, bool par_exists)
:name(par_name), new_name{NULL, 0}, default_value(expr), alter_if_exists(par_exists) {}
Alter_column(LEX_CSTRING par_name, LEX_CSTRING _new_name, bool exists)
:name(par_name), new_name(_new_name), default_value(NULL), alter_if_exists(exists) {}
/**
Used to make a clone of this object for ALTER/CREATE TABLE
@sa comment for Key_part_spec::clone
*/
Alter_column *clone(MEM_ROOT *mem_root) const
{ return new (mem_root) Alter_column(*this); }
bool is_rename()
{
DBUG_ASSERT(!new_name.str || !default_value);
return new_name.str;
}
};
class Alter_rename_key : public Sql_alloc
{
public:
const Lex_ident_column old_name;
const Lex_ident_column new_name;
bool alter_if_exists;
Alter_rename_key(LEX_CSTRING old_name_arg, LEX_CSTRING new_name_arg, bool exists)
: old_name(old_name_arg), new_name(new_name_arg), alter_if_exists(exists) {}
Alter_rename_key *clone(MEM_ROOT *mem_root) const
{ return new (mem_root) Alter_rename_key(*this); }
};
/* An ALTER INDEX operation that changes the ignorability of an index. */
class Alter_index_ignorability: public Sql_alloc
{
public:
Alter_index_ignorability(const LEX_CSTRING &name,
bool is_ignored, bool if_exists) :
m_name(name), m_is_ignored(is_ignored), m_if_exists(if_exists)
{
DBUG_ASSERT(name.str != NULL);
}
const Lex_ident_column &name() const { return m_name; }
bool if_exists() const { return m_if_exists; }
/* The ignorability after the operation is performed. */
bool is_ignored() const { return m_is_ignored; }
Alter_index_ignorability *clone(MEM_ROOT *mem_root) const
{ return new (mem_root) Alter_index_ignorability(*this); }
private:
const Lex_ident_column m_name;
bool m_is_ignored;
bool m_if_exists;
};
class Key :public Sql_alloc, public DDL_options {
public:
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, VECTOR,
FOREIGN_KEY, IGNORE_KEY};
enum Keytype type;
KEY_CREATE_INFO key_create_info;
List<Key_part_spec> columns;
Lex_ident_column name;
engine_option_value *option_list;
bool generated;
bool invisible;
bool without_overlaps;
bool old;
uint length;
Lex_ident_column period;
Key(enum Keytype type_par, const LEX_CSTRING *name_arg,
ha_key_alg algorithm_arg, bool generated_arg, DDL_options_st ddl_options)
:DDL_options(ddl_options),
type(type_par), key_create_info(default_key_create_info),
name(*name_arg), option_list(NULL), generated(generated_arg),
invisible(false), without_overlaps(false), old(false), length(0)
{
key_create_info.algorithm= algorithm_arg;
}
Key(enum Keytype type_par, const LEX_CSTRING *name_arg,
KEY_CREATE_INFO *key_info_arg,
bool generated_arg, List<Key_part_spec> *cols,
engine_option_value *create_opt, DDL_options_st ddl_options)
:DDL_options(ddl_options),
type(type_par), key_create_info(*key_info_arg), columns(*cols),
name(*name_arg), option_list(create_opt), generated(generated_arg),
invisible(false), without_overlaps(false), old(false), length(0)
{}
Key(const Key &rhs, MEM_ROOT *mem_root);
virtual ~Key() = default;
/* Equality comparison of keys (ignoring name) */
friend bool is_foreign_key_prefix(Key *a, Key *b);
/**
Used to make a clone of this object for ALTER/CREATE TABLE
@sa comment for Key_part_spec::clone
*/
virtual Key *clone(MEM_ROOT *mem_root) const
{ return new (mem_root) Key(*this, mem_root); }
};
class Foreign_key: public Key {
public:
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
LEX_CSTRING constraint_name;
LEX_CSTRING ref_db;
LEX_CSTRING ref_table;
List<Key_part_spec> ref_columns;
enum enum_fk_option delete_opt, update_opt;
enum fk_match_opt match_opt;
Foreign_key(const LEX_CSTRING *name_arg, List<Key_part_spec> *cols,
const LEX_CSTRING *constraint_name_arg,
const LEX_CSTRING *ref_db_arg, const LEX_CSTRING *ref_table_arg,
List<Key_part_spec> *ref_cols,
enum_fk_option delete_opt_arg, enum_fk_option update_opt_arg,
fk_match_opt match_opt_arg,
DDL_options ddl_options)
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols, NULL,
ddl_options),
constraint_name(*constraint_name_arg),
ref_db(*ref_db_arg), ref_table(*ref_table_arg), ref_columns(*ref_cols),
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
match_opt(match_opt_arg)
{
}
Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
/**
Used to make a clone of this object for ALTER/CREATE TABLE
@sa comment for Key_part_spec::clone
*/
Key *clone(MEM_ROOT *mem_root) const override
{ return new (mem_root) Foreign_key(*this, mem_root); }
/* Used to validate foreign key options */
bool validate(List<Create_field> &table_fields);
};
typedef struct st_mysql_lock
{
TABLE **table;
THR_LOCK_DATA **locks;
uint table_count,lock_count;
uint flags;
} MYSQL_LOCK;
class LEX_COLUMN : public Sql_alloc
{
public:
String column;
privilege_t rights;
LEX_COLUMN (const String& x,const privilege_t & y ): column (x),rights (y) {}
};
class MY_LOCALE;
/**
Query_cache_tls -- query cache thread local data.
*/
struct Query_cache_block;
struct Query_cache_tls
{
/*
'first_query_block' should be accessed only via query cache
functions and methods to maintain proper locking.
*/
Query_cache_block *first_query_block;
void set_first_query_block(Query_cache_block *first_query_block_arg)
{
first_query_block= first_query_block_arg;
}
Query_cache_tls() :first_query_block(NULL) {}
};
/* SIGNAL / RESIGNAL / GET DIAGNOSTICS */
/**
This enumeration list all the condition item names of a condition in the
SQL condition area.
*/
typedef enum enum_diag_condition_item_name
{
/*
Conditions that can be set by the user (SIGNAL/RESIGNAL),
and by the server implementation.
*/
DIAG_CLASS_ORIGIN= 0,
FIRST_DIAG_SET_PROPERTY= DIAG_CLASS_ORIGIN,
DIAG_SUBCLASS_ORIGIN= 1,
DIAG_CONSTRAINT_CATALOG= 2,
DIAG_CONSTRAINT_SCHEMA= 3,
DIAG_CONSTRAINT_NAME= 4,
DIAG_CATALOG_NAME= 5,
DIAG_SCHEMA_NAME= 6,
DIAG_TABLE_NAME= 7,
DIAG_COLUMN_NAME= 8,
DIAG_CURSOR_NAME= 9,
DIAG_MESSAGE_TEXT= 10,
DIAG_MYSQL_ERRNO= 11,
DIAG_ROW_NUMBER= 12,
LAST_DIAG_SET_PROPERTY= DIAG_ROW_NUMBER
} Diag_condition_item_name;
/**
Name of each diagnostic condition item.
This array is indexed by Diag_condition_item_name.
*/
extern const LEX_CSTRING Diag_condition_item_names[];
/**
These states are bit coded with HARD. For each state there must be a pair
<state_even_num>, and <state_odd_num>_HARD.
*/
enum killed_state
{
NOT_KILLED= 0,
KILL_HARD_BIT= 1, /* Bit for HARD KILL */
KILL_BAD_DATA= 2,
KILL_BAD_DATA_HARD= 3,
KILL_QUERY= 4,
KILL_QUERY_HARD= 5,
/*
ABORT_QUERY signals to the query processor to stop execution ASAP without
issuing an error. Instead a warning is issued, and when possible a partial
query result is returned to the client.
*/
ABORT_QUERY= 6,
ABORT_QUERY_HARD= 7,
KILL_TIMEOUT= 8,
KILL_TIMEOUT_HARD= 9,
/*
When binlog reading thread connects to the server it kills
all the binlog threads with the same ID.
*/
KILL_SLAVE_SAME_ID= 10,
/*
All of the following killed states will kill the connection
KILL_CONNECTION must be the first of these and it must start with
an even number (becasue of HARD bit)!
*/
KILL_CONNECTION= 12,
KILL_CONNECTION_HARD= 13,
KILL_SYSTEM_THREAD= 14,
KILL_SYSTEM_THREAD_HARD= 15,
KILL_SERVER= 16,
KILL_SERVER_HARD= 17,
/*
Used in threadpool to signal wait timeout.
*/
KILL_WAIT_TIMEOUT= 18,
KILL_WAIT_TIMEOUT_HARD= 19
};
#define killed_mask_hard(killed) ((killed_state) ((killed) & ~KILL_HARD_BIT))
enum killed_type
{
KILL_TYPE_ID,
KILL_TYPE_USER,
KILL_TYPE_QUERY
};
#define SECONDS_TO_WAIT_FOR_KILL 2
#define SECONDS_TO_WAIT_FOR_DUMP_THREAD_KILL 10
#if !defined(_WIN32) && defined(HAVE_SELECT)
/* my_sleep() can wait for sub second times */
#define WAIT_FOR_KILL_TRY_TIMES 20
#else
#define WAIT_FOR_KILL_TRY_TIMES 2
#endif
#include "sql_lex.h" /* Must be here */
class Delayed_insert;
class select_result;
class Time_zone;
#define THD_SENTRY_MAGIC 0xfeedd1ff
#define THD_SENTRY_GONE 0xdeadbeef
#define THD_CHECK_SENTRY(thd) DBUG_ASSERT(thd->dbug_sentry == THD_SENTRY_MAGIC)
typedef struct system_variables
{
/*
How dynamically allocated system variables are handled:
The global_system_variables and max_system_variables are "authoritative"
They both should have the same 'version' and 'size'.
When attempting to access a dynamic variable, if the session version
is out of date, then the session version is updated and realloced if
neccessary and bytes copied from global to make up for missing data.
Note that one should use my_bool instead of bool here, as the variables
are used with my_getopt.c
*/
ulong dynamic_variables_version;
char* dynamic_variables_ptr;
uint dynamic_variables_head; /* largest valid variable offset */
uint dynamic_variables_size; /* how many bytes are in use */
ulonglong max_heap_table_size;
ulonglong tmp_memory_table_size;
ulonglong tmp_disk_table_size;
ulonglong log_slow_query_time;
ulonglong log_slow_always_query_time;
ulonglong max_statement_time;
ulonglong optimizer_switch;
ulonglong optimizer_trace;
sql_mode_t sql_mode; ///< which non-standard SQL behaviour should be enabled
sql_mode_t old_behavior; ///< which old SQL behaviour should be enabled
sql_mode_t new_behavior; ///< which new SQL behaviour should be enabled
ulonglong option_bits; ///< OPTION_xxx constants, e.g. OPTION_PROFILING
ulonglong join_buff_space_limit;
ulonglong log_slow_filter;
ulonglong log_slow_verbosity;
ulonglong log_slow_disabled_statements;
ulonglong log_disabled_statements;
ulonglong note_verbosity;
ulonglong bulk_insert_buff_size;
ulonglong join_buff_size;
ulonglong sortbuff_size;
ulonglong default_regex_flags;
ulonglong max_mem_used;
ulonglong max_rowid_filter_size;
ulonglong create_temporary_table_binlog_formats;
/**
Place holders to store Multi-source variables in sys_var.cc during
update and show of variables.
*/
ulonglong slave_skip_counter;
ulonglong max_relay_log_size;
ulonglong max_tmp_space_usage;
double optimizer_where_cost, optimizer_scan_setup_cost;
double log_slow_query_time_double, max_statement_time_double;
double log_slow_always_query_time_double;
double sample_percentage;
ha_rows select_limit;
ha_rows max_join_size;
ha_rows expensive_subquery_limit;
#ifdef WITH_WSREP
/*
Stored values of the auto_increment_increment and auto_increment_offset
that are will be restored when wsrep_auto_increment_control will be set
to 'OFF', because the setting it to 'ON' leads to overwriting of the
original values (which are set by the user) by calculated ones (which
are based on the cluster size):
*/
ulonglong wsrep_gtid_seq_no;
ulong saved_auto_increment_increment, saved_auto_increment_offset;
ulong saved_lock_wait_timeout;
#endif /* WITH_WSREP */
uint analyze_max_length;
ulong auto_increment_increment, auto_increment_offset;
ulong column_compression_zlib_strategy;
ulong lock_wait_timeout;
ulong join_cache_level;
ulong max_allowed_packet;
ulong max_error_count;
ulong max_length_for_sort_data;
ulong max_recursive_iterations;
ulong max_sort_length;
ulong max_insert_delayed_threads;
ulong min_examined_row_limit;
ulong net_buffer_length;
ulong net_interactive_timeout;
ulong net_read_timeout;
ulong net_retry_count;
ulong net_wait_timeout;
ulong net_write_timeout;
ulong optimizer_extra_pruning_depth;
ulonglong optimizer_join_limit_pref_ratio;
ulong optimizer_prune_level;
ulong optimizer_search_depth;
ulong optimizer_selectivity_sampling_limit;
ulong optimizer_use_condition_selectivity;
ulong optimizer_max_sel_arg_weight;
ulong optimizer_max_sel_args;
ulong optimizer_trace_max_mem_size;
ulong optimizer_adjust_secondary_key_costs;
ulong use_stat_tables;
ulong histogram_size;
ulong histogram_type;
ulong preload_buff_size;
ulong profiling_history_size;
ulong read_buff_size;
ulong read_rnd_buff_size;
ulong mrr_buff_size;
ulong div_precincrement;
/* Total size of all buffers used by the subselect_rowid_merge_engine. */
ulong rowid_merge_buff_size;
ulong max_sp_recursion_depth;
ulong default_week_format;
ulong max_seeks_for_key;
ulong range_alloc_block_size;
ulong query_alloc_block_size;
ulong query_prealloc_size;
ulong trans_alloc_block_size;
ulong trans_prealloc_size;
ulong log_warnings;
ulong block_encryption_mode;
ulong log_slow_max_warnings;
/* Flags for slow log filtering */
ulong log_slow_rate_limit;
ulong binlog_format; ///< binlog format for this thd (see enum_binlog_format)
ulong binlog_row_image;
ulong progress_report_time;
ulong completion_type;
ulong query_cache_type;
ulong tx_isolation;
ulong updatable_views_with_limit;
ulong alter_algorithm_unused;
ulong server_id;
ulong session_track_transaction_info;
ulong threadpool_priority;
ulong vers_alter_history;
/* deadlock detection */
ulong wt_timeout_short, wt_deadlock_search_depth_short;
ulong wt_timeout_long, wt_deadlock_search_depth_long;
/**
In slave thread we need to know in behalf of which
thread the query is being run to replicate temp tables properly
*/
my_thread_id pseudo_thread_id;
/**
When replicating an event group with GTID, keep these values around so
slave binlog can receive the same GTID as the original.
*/
uint64 gtid_seq_no;
uint32 gtid_domain_id;
uint group_concat_max_len;
uint eq_range_index_dive_limit;
uint idle_transaction_timeout;
uint idle_readonly_transaction_timeout;
uint idle_write_transaction_timeout;
uint column_compression_threshold;
uint column_compression_zlib_level;
uint in_subquery_conversion_threshold;
uint max_open_cursors;
int max_user_connections;
/**
Default transaction access mode. READ ONLY (true) or READ WRITE (false).
*/
my_bool tx_read_only;
my_bool low_priority_updates;
my_bool query_cache_wlock_invalidate;
my_bool keep_files_on_create;
my_bool old_passwords;
my_bool only_standard_compliant_cte;
my_bool query_cache_strip_comments;
my_bool sql_log_slow;
my_bool sql_log_bin;
my_bool binlog_annotate_row_events;
my_bool binlog_direct_non_trans_update;
my_bool column_compression_zlib_wrap;
my_bool sysdate_is_now;
my_bool wsrep_on;
my_bool wsrep_dirty_reads;
my_bool pseudo_slave_mode;
my_bool session_track_schema;
my_bool session_track_state_change;
#ifdef USER_VAR_TRACKING
my_bool session_track_user_variables;
#endif // USER_VAR_TRACKING
my_bool tcp_nodelay;
my_bool optimizer_record_context;
plugin_ref table_plugin;
plugin_ref tmp_table_plugin;
plugin_ref enforced_table_plugin;
/* Only charset part of these variables is sensible */
CHARSET_INFO *character_set_filesystem;
CHARSET_INFO *character_set_client;
CHARSET_INFO *character_set_results;
/* Both charset and collation parts of these variables are important */
CHARSET_INFO *collation_server;
CHARSET_INFO *collation_database;
CHARSET_INFO *collation_connection;
/* Names. These will be allocated in buffers in thd */
LEX_CSTRING default_master_connection;
/* Error messages */
MY_LOCALE *lc_messages;
const char ***errmsgs; /* lc_messages->errmsg->errmsgs */
/* Locale Support */
MY_LOCALE *lc_time_names;
Time_zone *time_zone;
char *session_track_system_variables;
char *redirect_url;
/* Some wsrep variables */
ulonglong wsrep_trx_fragment_size;
ulong wsrep_retry_autocommit;
ulong wsrep_trx_fragment_unit;
ulong wsrep_OSU_method;
uint wsrep_sync_wait;
vers_asof_timestamp_t vers_asof_timestamp;
my_bool binlog_alter_two_phase;
Charset_collation_map_st character_set_collations;
Sql_path path;
} SV;
/**
Per thread status variables.
Must be long/ulong up to last_system_status_var so that
add_to_status/add_diff_to_status can work.
*/
typedef struct system_status_var
{
ulong column_compressions;
ulong column_decompressions;
ulong com_stat[(uint) SQLCOM_END];
ulong com_create_tmp_table;
ulong com_drop_tmp_table;
ulong com_other;
ulong com_stmt_prepare;
ulong com_stmt_reprepare;
ulong com_stmt_execute;
ulong com_stmt_send_long_data;
ulong com_stmt_fetch;
ulong com_stmt_reset;
ulong com_stmt_close;
ulong com_register_slave;
ulong created_tmp_disk_tables_;
ulong created_tmp_tables_;
ulong ha_commit_count;