/
sql_class.h
6727 lines (5977 loc) · 212 KB
/
sql_class.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
/*
Copyright (c) 2000, 2016, Oracle and/or its affiliates.
Copyright (c) 2009, 2017, 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-1301, USA */
#ifndef SQL_CLASS_INCLUDED
#define SQL_CLASS_INCLUDED
/* Classes in mysql */
#include "dur_prop.h"
#include <waiting_threads.h>
#include "sql_const.h"
#include <mysql/plugin_audit.h>
#include "log.h"
#include "rpl_tblmap.h"
#include "mdl.h"
#include "field.h" // Create_field
#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 "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"
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.h"
#include "wsrep_mysqld.h"
class Reprepare_observer;
class Relay_log_info;
struct rpl_group_info;
class Rpl_filter;
class Query_log_event;
class Load_log_event;
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;
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_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};
enum enum_slave_type_conversions { SLAVE_TYPE_CONVERSIONS_ALL_LOSSY,
SLAVE_TYPE_CONVERSIONS_ALL_NON_LOSSY};
/*
MARK_COLUMNS_READ: A column is goind to be read.
MARK_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
};
/* 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)
#define MODE_EMPTY_STRING_IS_NULL (1ULL << 32)
#define MODE_SIMULTANEOUS_ASSIGNMENT (1ULL << 33)
/* 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)
extern char internal_table_name[2];
extern char empty_c_string[1];
extern MYSQL_PLUGIN_IMPORT const char **errmesg;
extern bool volatile shutdown_in_progress;
extern "C" LEX_STRING * thd_query_string (MYSQL_THD thd);
extern "C" size_t thd_query_safe(MYSQL_THD thd, char *buf, size_t buflen);
/**
@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);
};
#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;
Item_result type;
uint charset_number;
bool unsigned_flag;
} 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 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_CSTRING field_name;
uint length;
Key_part_spec(const LEX_CSTRING *name, uint len)
: field_name(*name), length(len)
{}
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); }
};
class Alter_drop :public Sql_alloc {
public:
enum drop_type {KEY, COLUMN, FOREIGN_KEY, CHECK_CONSTRAINT };
const char *name;
enum drop_type type;
bool drop_if_exists;
Alter_drop(enum drop_type par_type,const char *par_name, bool par_exists)
:name(par_name), type(par_type), drop_if_exists(par_exists)
{
DBUG_ASSERT(par_name != 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 == KEY ? "INDEX" : "FOREIGN KEY";
}
};
class Alter_column :public Sql_alloc {
public:
const char *name;
Virtual_column_info *default_value;
bool alter_if_exists;
Alter_column(const char *par_name, Virtual_column_info *expr, bool par_exists)
:name(par_name), default_value(expr), alter_if_exists(par_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); }
};
class Key :public Sql_alloc, public DDL_options {
public:
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY};
enum Keytype type;
KEY_CREATE_INFO key_create_info;
List<Key_part_spec> columns;
LEX_CSTRING name;
engine_option_value *option_list;
bool generated;
bool invisible;
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)
{
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)
{}
Key(const Key &rhs, MEM_ROOT *mem_root);
virtual ~Key() {}
/* Equality comparison of keys (ignoring name) */
friend bool 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 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 *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),
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)
{
// We don't check for duplicate FKs.
key_create_info.check_for_duplicate_indexes= false;
}
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
*/
virtual Key *clone(MEM_ROOT *mem_root) const
{ 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;
uint rights;
LEX_COLUMN (const String& x,const uint& 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,
LAST_DIAG_SET_PROPERTY= DIAG_MYSQL_ERRNO
} 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
};
#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 long_query_time;
ulonglong max_statement_time;
ulonglong optimizer_switch;
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
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 bulk_insert_buff_size;
ulonglong join_buff_size;
ulonglong sortbuff_size;
ulonglong group_concat_max_len;
ulonglong default_regex_flags;
ulonglong max_mem_used;
/**
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;
ha_rows select_limit;
ha_rows max_join_size;
ha_rows expensive_subquery_limit;
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_tmp_tables;
ulong max_insert_delayed_threads;
ulong min_examined_row_limit;
ulong multi_range_count;
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_prune_level;
ulong optimizer_search_depth;
ulong optimizer_selectivity_sampling_limit;
ulong optimizer_use_condition_selectivity;
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;
/* 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;
int max_user_connections;
ulong server_id;
/**
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.
*/
uint32 gtid_domain_id;
uint64 gtid_seq_no;
/**
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_mode;
my_bool old_passwords;
my_bool big_tables;
my_bool only_standard_compliant_cte;
my_bool query_cache_strip_comments;
my_bool sql_log_slow;
my_bool sql_log_bin;
/*
A flag to help detect whether binary logging was temporarily disabled
(see tmp_disable_binlog(A) macro).
*/
my_bool sql_log_bin_off;
my_bool binlog_annotate_row_events;
my_bool binlog_direct_non_trans_update;
my_bool column_compression_zlib_wrap;
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;
my_bool sysdate_is_now;
/* deadlock detection */
ulong wt_timeout_short, wt_deadlock_search_depth_short;
ulong wt_timeout_long, wt_deadlock_search_depth_long;
my_bool wsrep_on;
my_bool wsrep_causal_reads;
my_bool wsrep_dirty_reads;
uint wsrep_sync_wait;
ulong wsrep_retry_autocommit;
ulong wsrep_OSU_method;
double long_query_time_double, max_statement_time_double;
my_bool pseudo_slave_mode;
char *session_track_system_variables;
ulong session_track_transaction_info;
my_bool session_track_schema;
my_bool session_track_state_change;
ulong threadpool_priority;
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;
vers_asof_timestamp_t vers_asof_timestamp;
ulong vers_alter_history;
} 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_multi;
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;
ulong ha_delete_count;
ulong ha_read_first_count;
ulong ha_read_last_count;
ulong ha_read_key_count;
ulong ha_read_next_count;
ulong ha_read_prev_count;
ulong ha_read_retry_count;
ulong ha_read_rnd_count;
ulong ha_read_rnd_next_count;
ulong ha_read_rnd_deleted_count;
/*
This number doesn't include calls to the default implementation and
calls made by range access. The intent is to count only calls made by
BatchedKeyAccess.
*/
ulong ha_mrr_init_count;
ulong ha_mrr_key_refills_count;
ulong ha_mrr_rowid_refills_count;
ulong ha_rollback_count;
ulong ha_update_count;
ulong ha_write_count;
/* The following are for internal temporary tables */
ulong ha_tmp_update_count;
ulong ha_tmp_write_count;
ulong ha_tmp_delete_count;
ulong ha_prepare_count;
ulong ha_icp_attempts;
ulong ha_icp_match;
ulong ha_discover_count;
ulong ha_savepoint_count;
ulong ha_savepoint_rollback_count;
ulong ha_external_lock_count;
ulong opened_tables;
ulong opened_shares;
ulong opened_views; /* +1 opening a view */
ulong select_full_join_count_;
ulong select_full_range_join_count_;
ulong select_range_count_;
ulong select_range_check_count_;
ulong select_scan_count_;
ulong update_scan_count;
ulong delete_scan_count;
ulong executed_triggers;
ulong long_query_count;
ulong filesort_merge_passes_;
ulong filesort_range_count_;
ulong filesort_rows_;
ulong filesort_scan_count_;
ulong filesort_pq_sorts_;
/* Features used */
ulong feature_custom_aggregate_functions; /* +1 when custom aggregate
functions are used */
ulong feature_dynamic_columns; /* +1 when creating a dynamic column */
ulong feature_fulltext; /* +1 when MATCH is used */
ulong feature_gis; /* +1 opening a table with GIS features */
ulong feature_invisible_columns; /* +1 opening a table with invisible column */
ulong feature_json; /* +1 when JSON function appears in the statement */
ulong feature_locale; /* +1 when LOCALE is set */
ulong feature_subquery; /* +1 when subqueries are used */
ulong feature_system_versioning; /* +1 opening a table WITH SYSTEM VERSIONING */
ulong feature_timezone; /* +1 when XPATH is used */
ulong feature_trigger; /* +1 opening a table with triggers */
ulong feature_xml; /* +1 when XPATH is used */
ulong feature_window_functions; /* +1 when window functions are used */
/* From MASTER_GTID_WAIT usage */
ulonglong master_gtid_wait_timeouts; /* Number of timeouts */
ulonglong master_gtid_wait_time; /* Time in microseconds */
ulonglong master_gtid_wait_count;
ulong empty_queries;
ulong access_denied_errors;
ulong lost_connections;
ulong max_statement_time_exceeded;
/*
Number of statements sent from the client
*/
ulong questions;
/*
IMPORTANT!
SEE last_system_status_var DEFINITION BELOW.
Below 'last_system_status_var' are all variables that cannot be handled
automatically by add_to_status()/add_diff_to_status().
*/
ulonglong bytes_received;
ulonglong bytes_sent;
ulonglong rows_read;
ulonglong rows_sent;
ulonglong rows_tmp_read;
ulonglong binlog_bytes_written;
ulonglong table_open_cache_hits;
ulonglong table_open_cache_misses;
ulonglong table_open_cache_overflows;
double last_query_cost;
double cpu_time, busy_time;
uint32 threads_running;
/* Don't initialize */
/* Memory used for thread local storage */
int64 max_local_memory_used;
volatile int64 local_memory_used;
/* Memory allocated for global usage */
volatile int64 global_memory_used;
} STATUS_VAR;
/*
This is used for 'SHOW STATUS'. It must be updated to the last ulong
variable in system_status_var which is makes sense to add to the global
counter
*/
#define last_system_status_var questions
#define last_cleared_system_status_var local_memory_used
/*
Global status variables
*/
extern ulong feature_files_opened_with_delayed_keys, feature_check_constraint;
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
STATUS_VAR *dec_var);
/*
Update global_memory_used. We have to do this with atomic_add as the
global value can change outside of LOCK_status.
*/
inline void update_global_memory_status(int64 size)
{
DBUG_PRINT("info", ("global memory_used: %lld size: %lld",
(longlong) global_status_var.global_memory_used,
size));
// workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1)
int64 volatile * volatile ptr= &global_status_var.global_memory_used;
my_atomic_add64_explicit(ptr, size, MY_MEMORY_ORDER_RELAXED);
}
/**
Get collation by name, send error to client on failure.
@param name Collation name
@param name_cs Character set of the name string
@return
@retval NULL on error
@retval Pointter to CHARSET_INFO with the given name on success
*/
inline CHARSET_INFO *
mysqld_collation_get_by_name(const char *name,
CHARSET_INFO *name_cs= system_charset_info)
{
CHARSET_INFO *cs;
MY_CHARSET_LOADER loader;
my_charset_loader_init_mysys(&loader);
if (!(cs= my_collation_get_by_name(&loader, name, MYF(0))))
{
ErrConvString err(name, name_cs);
my_error(ER_UNKNOWN_COLLATION, MYF(0), err.ptr());
if (loader.error[0])
push_warning_printf(current_thd,
Sql_condition::WARN_LEVEL_WARN,
ER_UNKNOWN_COLLATION, "%s", loader.error);
}
return cs;
}
inline bool is_supported_parser_charset(CHARSET_INFO *cs)
{
return MY_TEST(cs->mbminlen == 1);
}
#ifdef MYSQL_SERVER
void free_tmp_table(THD *thd, TABLE *entry);
/* The following macro is to make init of Query_arena simpler */
#ifdef DBUG_ASSERT_EXISTS
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0; is_reprepared= FALSE;
#else
#define INIT_ARENA_DBUG_INFO
#endif
class Query_arena
{
public:
/*
List of items created in the parser for this query. Every item puts
itself to the list on creation (see Item::Item() for details))
*/
Item *free_list;
MEM_ROOT *mem_root; // Pointer to current memroot
#ifdef DBUG_ASSERT_EXISTS
bool is_backup_arena; /* True if this arena is used for backup. */
bool is_reprepared;
#endif
/*
The states relfects three diffrent life cycles for three
different types of statements:
Prepared statement: STMT_INITIALIZED -> STMT_PREPARED -> STMT_EXECUTED.
Stored procedure: STMT_INITIALIZED_FOR_SP -> STMT_EXECUTED.
Other statements: STMT_CONVENTIONAL_EXECUTION never changes.
*/
enum enum_state
{
STMT_INITIALIZED= 0, STMT_INITIALIZED_FOR_SP= 1, STMT_PREPARED= 2,
STMT_CONVENTIONAL_EXECUTION= 3, STMT_EXECUTED= 4, STMT_ERROR= -1
};
enum_state state;
public:
/* We build without RTTI, so dynamic_cast can't be used. */
enum Type
{
STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE
};
Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) :
free_list(0), mem_root(mem_root_arg), state(state_arg)
{ INIT_ARENA_DBUG_INFO; }
/*
This constructor is used only when Query_arena is created as
backup storage for another instance of Query_arena.
*/
Query_arena() { INIT_ARENA_DBUG_INFO; }
virtual Type type() const;
virtual ~Query_arena() {};
inline bool is_stmt_prepare() const { return state == STMT_INITIALIZED; }
inline bool is_stmt_prepare_or_first_sp_execute() const
{ return (int)state < (int)STMT_PREPARED; }
inline bool is_stmt_prepare_or_first_stmt_execute() const
{ return (int)state <= (int)STMT_PREPARED; }