-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
sysvar.go
2157 lines (2101 loc) · 115 KB
/
sysvar.go
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 2015 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package variable
import (
"encoding/json"
"fmt"
"math"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/cznic/mathutil"
"github.com/pingcap/errors"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/stmtsummary"
"github.com/pingcap/tidb/util/versioninfo"
tikvstore "github.com/tikv/client-go/v2/kv"
atomic2 "go.uber.org/atomic"
)
// ScopeFlag is for system variable whether can be changed in global/session dynamically or not.
type ScopeFlag uint8
// TypeFlag is the SysVar type, which doesn't exactly match MySQL types.
type TypeFlag byte
const (
// ScopeNone means the system variable can not be changed dynamically.
ScopeNone ScopeFlag = 0
// ScopeGlobal means the system variable can be changed globally.
ScopeGlobal ScopeFlag = 1 << 0
// ScopeSession means the system variable can only be changed in current session.
ScopeSession ScopeFlag = 1 << 1
// TypeStr is the default
TypeStr TypeFlag = 0
// TypeBool for boolean
TypeBool TypeFlag = 1
// TypeInt for integer
TypeInt TypeFlag = 2
// TypeEnum for Enum
TypeEnum TypeFlag = 3
// TypeFloat for Double
TypeFloat TypeFlag = 4
// TypeUnsigned for Unsigned integer
TypeUnsigned TypeFlag = 5
// TypeTime for time of day (a TiDB extension)
TypeTime TypeFlag = 6
// TypeDuration for a golang duration (a TiDB extension)
TypeDuration TypeFlag = 7
// On is the canonical string for ON
On = "ON"
// Off is the canonical string for OFF
Off = "OFF"
// Warn means return warnings
Warn = "WARN"
// IntOnly means enable for int type
IntOnly = "INT_ONLY"
)
// SysVar is for system variable.
// All the fields of SysVar should be READ ONLY after created.
type SysVar struct {
// Scope is for whether can be changed or not
Scope ScopeFlag
// Name is the variable name.
Name string
// Value is the variable value.
Value string
// Type is the MySQL type (optional)
Type TypeFlag
// MinValue will automatically be validated when specified (optional)
MinValue int64
// MaxValue will automatically be validated when specified (optional)
MaxValue uint64
// AutoConvertNegativeBool applies to boolean types (optional)
AutoConvertNegativeBool bool
// AutoConvertOutOfRange applies to int and unsigned types.
AutoConvertOutOfRange bool
// ReadOnly applies to all types
ReadOnly bool
// PossibleValues applies to ENUM type
PossibleValues []string
// AllowEmpty is a special TiDB behavior which means "read value from config" (do not use)
AllowEmpty bool
// AllowEmptyAll is a special behavior that only applies to TiDBCapturePlanBaseline, TiDBTxnMode (do not use)
AllowEmptyAll bool
// AllowAutoValue means that the special value "-1" is permitted, even when outside of range.
AllowAutoValue bool
// Validation is a callback after the type validation has been performed, but before the Set function
Validation func(*SessionVars, string, string, ScopeFlag) (string, error)
// SetSession is called after validation but before updating systems[]. It also doubles as an Init function
// and will be called on all variables in builtinGlobalVariable, regardless of their scope.
SetSession func(*SessionVars, string) error
// SetGlobal is called after validation
SetGlobal func(*SessionVars, string) error
// IsHintUpdatable indicate whether it's updatable via SET_VAR() hint (optional)
IsHintUpdatable bool
// Hidden means that it still responds to SET but doesn't show up in SHOW VARIABLES
Hidden bool
// Aliases is a list of sysvars that should also be updated when this sysvar is updated.
// Updating aliases calls the SET function of the aliases, but does not update their aliases (preventing SET recursion)
Aliases []string
// GetSession is a getter function for session scope.
// It can be used by instance-scoped variables to overwrite the previously expected value.
GetSession func(*SessionVars) (string, error)
// GetGlobal is a getter function for global scope.
GetGlobal func(*SessionVars) (string, error)
// skipInit defines if the sysvar should be loaded into the session on init.
// This is only important to set for sysvars that include session scope,
// since global scoped sysvars are not-applicable.
skipInit bool
// IsNoop defines if the sysvar is a noop included for MySQL compatibility
IsNoop bool
}
// GetGlobalFromHook calls the GetSession func if it exists.
func (sv *SysVar) GetGlobalFromHook(s *SessionVars) (string, error) {
// Call the Getter if there is one defined.
if sv.GetGlobal != nil {
val, err := sv.GetGlobal(s)
if err != nil {
return val, err
}
// Ensure that the results from the getter are validated
// Since some are read directly from tables.
return sv.ValidateWithRelaxedValidation(s, val, ScopeGlobal), nil
}
if sv.HasNoneScope() {
return sv.Value, nil
}
return s.GlobalVarsAccessor.GetGlobalSysVar(sv.Name)
}
// GetSessionFromHook calls the GetSession func if it exists.
func (sv *SysVar) GetSessionFromHook(s *SessionVars) (string, error) {
if sv.HasNoneScope() {
return sv.Value, nil
}
// Call the Getter if there is one defined.
if sv.GetSession != nil {
val, err := sv.GetSession(s)
if err != nil {
return val, err
}
// Ensure that the results from the getter are validated
// Since some are read directly from tables.
return sv.ValidateWithRelaxedValidation(s, val, ScopeSession), nil
}
var (
ok bool
val string
)
if val, ok = s.stmtVars[sv.Name]; ok {
return val, nil
}
if val, ok = s.systems[sv.Name]; !ok {
return val, errors.New("sysvar has not yet loaded")
}
return val, nil
}
// SetSessionFromHook calls the SetSession func if it exists.
func (sv *SysVar) SetSessionFromHook(s *SessionVars, val string) error {
if sv.SetSession != nil {
if err := sv.SetSession(s, val); err != nil {
return err
}
}
s.systems[sv.Name] = val
// Call the Set function on all the aliases for this sysVar
// Skipping the validation function, and not calling aliases of
// aliases. By skipping the validation function it means that things
// like duplicate warnings should not appear.
if sv.Aliases != nil {
for _, aliasName := range sv.Aliases {
aliasSv := GetSysVar(aliasName)
if aliasSv.SetSession != nil {
if err := aliasSv.SetSession(s, val); err != nil {
return err
}
}
s.systems[aliasSv.Name] = val
}
}
return nil
}
// SetGlobalFromHook calls the SetGlobal func if it exists.
func (sv *SysVar) SetGlobalFromHook(s *SessionVars, val string, skipAliases bool) error {
if sv.SetGlobal != nil {
return sv.SetGlobal(s, val)
}
// Call the SetGlobalSysVarOnly function on all the aliases for this sysVar
// which skips the validation function and when SetGlobalFromHook is called again
// it will be with skipAliases=true. This helps break recursion because
// most aliases are reciprocal.
if !skipAliases && sv.Aliases != nil {
for _, aliasName := range sv.Aliases {
if err := s.GlobalVarsAccessor.SetGlobalSysVarOnly(aliasName, val); err != nil {
return err
}
}
}
return nil
}
// HasNoneScope returns true if the scope for the sysVar is None.
func (sv *SysVar) HasNoneScope() bool {
return sv.Scope == ScopeNone
}
// HasSessionScope returns true if the scope for the sysVar includes session.
func (sv *SysVar) HasSessionScope() bool {
return sv.Scope&ScopeSession != 0
}
// HasGlobalScope returns true if the scope for the sysVar includes global.
func (sv *SysVar) HasGlobalScope() bool {
return sv.Scope&ScopeGlobal != 0
}
// Validate checks if system variable satisfies specific restriction.
func (sv *SysVar) Validate(vars *SessionVars, value string, scope ScopeFlag) (string, error) {
// Check that the scope is correct first.
if err := sv.validateScope(scope); err != nil {
return value, err
}
// Normalize the value and apply validation based on type.
// i.e. TypeBool converts 1/on/ON to ON.
normalizedValue, err := sv.validateFromType(vars, value, scope)
if err != nil {
return normalizedValue, err
}
// If type validation was successful, call the (optional) validation function
if sv.Validation != nil {
return sv.Validation(vars, normalizedValue, value, scope)
}
return normalizedValue, nil
}
// validateFromType provides automatic validation based on the SysVar's type
func (sv *SysVar) validateFromType(vars *SessionVars, value string, scope ScopeFlag) (string, error) {
// The string "DEFAULT" is a special keyword in MySQL, which restores
// the compiled sysvar value. In which case we can skip further validation.
if strings.EqualFold(value, "DEFAULT") {
return sv.Value, nil
}
// Some sysvars in TiDB have a special behavior where the empty string means
// "use the config file value". This needs to be cleaned up once the behavior
// for instance variables is determined.
if value == "" && ((sv.AllowEmpty && scope == ScopeSession) || sv.AllowEmptyAll) {
return value, nil
}
// Provide validation using the SysVar struct
switch sv.Type {
case TypeUnsigned:
return sv.checkUInt64SystemVar(value, vars)
case TypeInt:
return sv.checkInt64SystemVar(value, vars)
case TypeBool:
return sv.checkBoolSystemVar(value, vars)
case TypeFloat:
return sv.checkFloatSystemVar(value, vars)
case TypeEnum:
return sv.checkEnumSystemVar(value, vars)
case TypeTime:
return sv.checkTimeSystemVar(value, vars)
case TypeDuration:
return sv.checkDurationSystemVar(value, vars)
}
return value, nil // typeString
}
func (sv *SysVar) validateScope(scope ScopeFlag) error {
if sv.ReadOnly || sv.Scope == ScopeNone {
return ErrIncorrectScope.FastGenByArgs(sv.Name, "read only")
}
if scope == ScopeGlobal && !sv.HasGlobalScope() {
return errLocalVariable.FastGenByArgs(sv.Name)
}
if scope == ScopeSession && !sv.HasSessionScope() {
return errGlobalVariable.FastGenByArgs(sv.Name)
}
return nil
}
// ValidateWithRelaxedValidation normalizes values but can not return errors.
// Normalization+validation needs to be applied when reading values because older versions of TiDB
// may be less sophisticated in normalizing values. But errors should be caught and handled,
// because otherwise there will be upgrade issues.
func (sv *SysVar) ValidateWithRelaxedValidation(vars *SessionVars, value string, scope ScopeFlag) string {
normalizedValue, err := sv.validateFromType(vars, value, scope)
if err != nil {
return normalizedValue
}
if sv.Validation != nil {
normalizedValue, err = sv.Validation(vars, normalizedValue, value, scope)
if err != nil {
return normalizedValue
}
}
return normalizedValue
}
const (
localDayTimeFormat = "15:04"
// FullDayTimeFormat is the full format of analyze start time and end time.
FullDayTimeFormat = "15:04 -0700"
)
func (sv *SysVar) checkTimeSystemVar(value string, vars *SessionVars) (string, error) {
var t time.Time
var err error
if len(value) <= len(localDayTimeFormat) {
t, err = time.ParseInLocation(localDayTimeFormat, value, vars.Location())
} else {
t, err = time.ParseInLocation(FullDayTimeFormat, value, vars.Location())
}
if err != nil {
return "", err
}
return t.Format(FullDayTimeFormat), nil
}
func (sv *SysVar) checkDurationSystemVar(value string, vars *SessionVars) (string, error) {
d, err := time.ParseDuration(value)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
// Check for min/max violations
if int64(d) < sv.MinValue {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if uint64(d) > sv.MaxValue {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
// return a string representation of the duration
return d.String(), nil
}
func (sv *SysVar) checkUInt64SystemVar(value string, vars *SessionVars) (string, error) {
if sv.AllowAutoValue && value == "-1" {
return value, nil
}
// There are two types of validation behaviors for integer values. The default
// is to return an error saying the value is out of range. For MySQL compatibility, some
// values prefer convert the value to the min/max and return a warning.
if !sv.AutoConvertOutOfRange {
return sv.checkUint64SystemVarWithError(value)
}
if len(value) == 0 {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if value[0] == '-' {
_, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MinValue), nil
}
val, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if val < uint64(sv.MinValue) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MinValue), nil
}
if val > sv.MaxValue {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MaxValue), nil
}
return value, nil
}
func (sv *SysVar) checkInt64SystemVar(value string, vars *SessionVars) (string, error) {
if sv.AllowAutoValue && value == "-1" {
return value, nil
}
// There are two types of validation behaviors for integer values. The default
// is to return an error saying the value is out of range. For MySQL compatibility, some
// values prefer convert the value to the min/max and return a warning.
if !sv.AutoConvertOutOfRange {
return sv.checkInt64SystemVarWithError(value)
}
val, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if val < sv.MinValue {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MinValue), nil
}
if val > int64(sv.MaxValue) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MaxValue), nil
}
return value, nil
}
func (sv *SysVar) checkEnumSystemVar(value string, vars *SessionVars) (string, error) {
// The value could be either a string or the ordinal position in the PossibleValues.
// This allows for the behavior 0 = OFF, 1 = ON, 2 = DEMAND etc.
var iStr string
for i, v := range sv.PossibleValues {
iStr = fmt.Sprintf("%d", i)
if strings.EqualFold(value, v) || strings.EqualFold(value, iStr) {
return v, nil
}
}
return value, ErrWrongValueForVar.GenWithStackByArgs(sv.Name, value)
}
func (sv *SysVar) checkFloatSystemVar(value string, vars *SessionVars) (string, error) {
if len(value) == 0 {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
val, err := strconv.ParseFloat(value, 64)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if val < float64(sv.MinValue) || val > float64(sv.MaxValue) {
return value, ErrWrongValueForVar.GenWithStackByArgs(sv.Name, value)
}
return value, nil
}
func (sv *SysVar) checkBoolSystemVar(value string, vars *SessionVars) (string, error) {
if strings.EqualFold(value, "ON") {
return On, nil
} else if strings.EqualFold(value, "OFF") {
return Off, nil
}
val, err := strconv.ParseInt(value, 10, 64)
if err == nil {
// There are two types of conversion rules for integer values.
// The default only allows 0 || 1, but a subset of values convert any
// negative integer to 1.
if !sv.AutoConvertNegativeBool {
if val == 0 {
return Off, nil
} else if val == 1 {
return On, nil
}
} else {
if val == 1 || val < 0 {
return On, nil
} else if val == 0 {
return Off, nil
}
}
}
return value, ErrWrongValueForVar.GenWithStackByArgs(sv.Name, value)
}
func (sv *SysVar) checkUint64SystemVarWithError(value string) (string, error) {
if len(value) == 0 {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if value[0] == '-' {
// // in strict it expects the error WrongValue, but in non-strict it returns WrongType
return value, ErrWrongValueForVar.GenWithStackByArgs(sv.Name, value)
}
val, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if val < uint64(sv.MinValue) || val > sv.MaxValue {
return value, ErrWrongValueForVar.GenWithStackByArgs(sv.Name, value)
}
return value, nil
}
func (sv *SysVar) checkInt64SystemVarWithError(value string) (string, error) {
if len(value) == 0 {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
val, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if val < sv.MinValue || val > int64(sv.MaxValue) {
return value, ErrWrongValueForVar.GenWithStackByArgs(sv.Name, value)
}
return value, nil
}
// GetNativeValType attempts to convert the val to the approx MySQL non-string type
func (sv *SysVar) GetNativeValType(val string) (types.Datum, byte, uint) {
switch sv.Type {
case TypeUnsigned:
u, err := strconv.ParseUint(val, 10, 64)
if err != nil {
u = 0
}
return types.NewUintDatum(u), mysql.TypeLonglong, mysql.UnsignedFlag
case TypeBool:
optVal := int64(0) // OFF
if TiDBOptOn(val) {
optVal = 1
}
return types.NewIntDatum(optVal), mysql.TypeLong, 0
}
return types.NewStringDatum(val), mysql.TypeVarString, 0
}
// SkipInit returns true if when a new session is created we should "skip" copying
// an initial value to it (and call the SetSession func if it exists)
func (sv *SysVar) SkipInit() bool {
if sv.skipInit || sv.IsNoop {
return true
}
// These a special "Global-only" sysvars that for backward compatibility
// are currently cached in the session. Please don't add to this list.
switch sv.Name {
case TiDBEnableChangeMultiSchema, TiDBDDLReorgBatchSize, TiDBEnableAlterPlacement,
TiDBMaxDeltaSchemaCount, InitConnect, MaxPreparedStmtCount,
TiDBDDLReorgWorkerCount, TiDBDDLErrorCountLimit, TiDBRowFormatVersion,
TiDBEnableTelemetry, TiDBEnablePointGetCache:
return false
}
return !sv.HasSessionScope()
}
var sysVars map[string]*SysVar
var sysVarsLock sync.RWMutex
// RegisterSysVar adds a sysvar to the SysVars list
func RegisterSysVar(sv *SysVar) {
name := strings.ToLower(sv.Name)
sysVarsLock.Lock()
sysVars[name] = sv
sysVarsLock.Unlock()
}
// UnregisterSysVar removes a sysvar from the SysVars list
// currently only used in tests.
func UnregisterSysVar(name string) {
name = strings.ToLower(name)
sysVarsLock.Lock()
delete(sysVars, name)
sysVarsLock.Unlock()
}
// GetSysVar returns sys var info for name as key.
func GetSysVar(name string) *SysVar {
name = strings.ToLower(name)
sysVarsLock.RLock()
defer sysVarsLock.RUnlock()
return sysVars[name]
}
// SetSysVar sets a sysvar. In fact, SysVar is immutable.
// SetSysVar is implemented by register a new SysVar with the same name again.
// This will not propagate to the cluster, so it should only be
// used for instance scoped AUTO variables such as system_time_zone.
func SetSysVar(name string, value string) {
old := GetSysVar(name)
tmp := *old
tmp.Value = value
RegisterSysVar(&tmp)
}
// GetSysVars deep copies the sysVars list under a RWLock
func GetSysVars() map[string]*SysVar {
sysVarsLock.RLock()
defer sysVarsLock.RUnlock()
copy := make(map[string]*SysVar, len(sysVars))
for name, sv := range sysVars {
tmp := *sv
copy[name] = &tmp
}
return copy
}
func init() {
sysVars = make(map[string]*SysVar)
for _, v := range defaultSysVars {
RegisterSysVar(v)
}
for _, v := range noopSysVars {
v.IsNoop = true
RegisterSysVar(v)
}
}
var defaultSysVars = []*SysVar{
{Scope: ScopeGlobal | ScopeSession, Name: SQLSelectLimit, Value: "18446744073709551615", Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxUint64, AutoConvertOutOfRange: true, SetSession: func(s *SessionVars, val string) error {
result, err := strconv.ParseUint(val, 10, 64)
if err != nil {
return errors.Trace(err)
}
s.SelectLimit = result
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: DefaultWeekFormat, Value: "0", Type: TypeUnsigned, MinValue: 0, MaxValue: 7, AutoConvertOutOfRange: true},
{Scope: ScopeGlobal | ScopeSession, Name: SQLModeVar, Value: mysql.DefaultSQLMode, IsHintUpdatable: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
// Ensure the SQL mode parses
normalizedValue = mysql.FormatSQLModeStr(normalizedValue)
if _, err := mysql.GetSQLMode(normalizedValue); err != nil {
return originalValue, err
}
return normalizedValue, nil
}, SetSession: func(s *SessionVars, val string) error {
val = mysql.FormatSQLModeStr(val)
// Modes is a list of different modes separated by commas.
sqlMode, err := mysql.GetSQLMode(val)
if err != nil {
return errors.Trace(err)
}
s.StrictSQLMode = sqlMode.HasStrictMode()
s.SQLMode = sqlMode
s.SetStatusFlag(mysql.ServerStatusNoBackslashEscaped, sqlMode.HasNoBackslashEscapesMode())
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: MaxExecutionTime, Value: "0", Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, AutoConvertOutOfRange: true, IsHintUpdatable: true, SetSession: func(s *SessionVars, val string) error {
timeoutMS := tidbOptPositiveInt32(val, 0)
s.MaxExecutionTime = uint64(timeoutMS)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: CollationServer, Value: mysql.DefaultCollationName, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkCollation(vars, normalizedValue, originalValue, scope)
}, SetSession: func(s *SessionVars, val string) error {
if coll, err := collate.GetCollationByName(val); err == nil {
s.systems[CharacterSetServer] = coll.CharsetName
}
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: SQLLogBin, Value: On, Type: TypeBool, skipInit: true},
{Scope: ScopeGlobal | ScopeSession, Name: TimeZone, Value: "SYSTEM", IsHintUpdatable: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
if strings.EqualFold(normalizedValue, "SYSTEM") {
return "SYSTEM", nil
}
_, err := parseTimeZone(normalizedValue)
return normalizedValue, err
}, SetSession: func(s *SessionVars, val string) error {
tz, err := parseTimeZone(val)
if err != nil {
return err
}
s.TimeZone = tz
return nil
}},
{Scope: ScopeNone, Name: SystemTimeZone, Value: "CST"},
{Scope: ScopeGlobal | ScopeSession, Name: ForeignKeyChecks, Value: Off, Type: TypeBool, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
if TiDBOptOn(normalizedValue) {
// TiDB does not yet support foreign keys.
// Return the original value in the warning, so that users are not confused.
vars.StmtCtx.AppendWarning(ErrUnsupportedValueForVar.GenWithStackByArgs(ForeignKeyChecks, originalValue))
return Off, nil
} else if !TiDBOptOn(normalizedValue) {
return Off, nil
}
return normalizedValue, ErrWrongValueForVar.GenWithStackByArgs(ForeignKeyChecks, originalValue)
}},
{Scope: ScopeNone, Name: Hostname, Value: DefHostname},
{Scope: ScopeSession, Name: Timestamp, Value: "", skipInit: true},
{Scope: ScopeGlobal | ScopeSession, Name: CollationDatabase, Value: mysql.DefaultCollationName, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkCollation(vars, normalizedValue, originalValue, scope)
}, SetSession: func(s *SessionVars, val string) error {
if coll, err := collate.GetCollationByName(val); err == nil {
s.systems[CharsetDatabase] = coll.CharsetName
}
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: AutoIncrementIncrement, Value: strconv.FormatInt(DefAutoIncrementIncrement, 10), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint16, AutoConvertOutOfRange: true, SetSession: func(s *SessionVars, val string) error {
// AutoIncrementIncrement is valid in [1, 65535].
s.AutoIncrementIncrement = tidbOptPositiveInt32(val, DefAutoIncrementIncrement)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: AutoIncrementOffset, Value: strconv.FormatInt(DefAutoIncrementOffset, 10), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint16, AutoConvertOutOfRange: true, SetSession: func(s *SessionVars, val string) error {
// AutoIncrementOffset is valid in [1, 65535].
s.AutoIncrementOffset = tidbOptPositiveInt32(val, DefAutoIncrementOffset)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: CharacterSetClient, Value: mysql.DefaultCharset, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkCharacterSet(normalizedValue, CharacterSetClient)
}},
{Scope: ScopeNone, Name: Port, Value: "4000", Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxUint16},
{Scope: ScopeNone, Name: LowerCaseTableNames, Value: "2"},
{Scope: ScopeNone, Name: LogBin, Value: Off, Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: CharacterSetResults, Value: mysql.DefaultCharset, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
if normalizedValue == "" {
return normalizedValue, nil
}
return checkCharacterSet(normalizedValue, "")
}},
{Scope: ScopeNone, Name: VersionComment, Value: "TiDB Server (Apache License 2.0) " + versioninfo.TiDBEdition + " Edition, MySQL 5.7 compatible"},
{Scope: ScopeGlobal | ScopeSession, Name: TxnIsolation, Value: "REPEATABLE-READ", Type: TypeEnum, Aliases: []string{TransactionIsolation}, PossibleValues: []string{"READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ", "SERIALIZABLE"}, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
// MySQL appends a warning here for tx_isolation is deprecated
// TiDB doesn't currently, but may in future. It is still commonly used by applications
// So it might be noisy to do so.
return checkIsolationLevel(vars, normalizedValue, originalValue, scope)
}},
{Scope: ScopeGlobal | ScopeSession, Name: TransactionIsolation, Value: "REPEATABLE-READ", Type: TypeEnum, Aliases: []string{TxnIsolation}, PossibleValues: []string{"READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ", "SERIALIZABLE"}, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkIsolationLevel(vars, normalizedValue, originalValue, scope)
}},
{Scope: ScopeGlobal | ScopeSession, Name: CollationConnection, Value: mysql.DefaultCollationName, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkCollation(vars, normalizedValue, originalValue, scope)
}, SetSession: func(s *SessionVars, val string) error {
if coll, err := collate.GetCollationByName(val); err == nil {
s.systems[CharacterSetConnection] = coll.CharsetName
}
return nil
}},
{Scope: ScopeNone, Name: Version, Value: mysql.ServerVersion},
{Scope: ScopeGlobal | ScopeSession, Name: AutoCommit, Value: On, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
isAutocommit := TiDBOptOn(val)
s.SetStatusFlag(mysql.ServerStatusAutocommit, isAutocommit)
if isAutocommit {
s.SetInTxn(false)
}
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: CharsetDatabase, Value: mysql.DefaultCharset, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkCharacterSet(normalizedValue, CharsetDatabase)
}, SetSession: func(s *SessionVars, val string) error {
if cs, err := charset.GetCharsetInfo(val); err == nil {
s.systems[CollationDatabase] = cs.DefaultCollation
}
return nil
}},
{Scope: ScopeGlobal, Name: MaxPreparedStmtCount, Value: strconv.FormatInt(DefMaxPreparedStmtCount, 10), Type: TypeInt, MinValue: -1, MaxValue: 1048576, AutoConvertOutOfRange: true},
{Scope: ScopeNone, Name: DataDir, Value: "/usr/local/mysql/data/"},
{Scope: ScopeGlobal | ScopeSession, Name: WaitTimeout, Value: strconv.FormatInt(DefWaitTimeout, 10), Type: TypeUnsigned, MinValue: 0, MaxValue: secondsPerYear, AutoConvertOutOfRange: true},
{Scope: ScopeGlobal | ScopeSession, Name: InteractiveTimeout, Value: "28800", Type: TypeUnsigned, MinValue: 1, MaxValue: secondsPerYear, AutoConvertOutOfRange: true},
{Scope: ScopeGlobal | ScopeSession, Name: InnodbLockWaitTimeout, Value: strconv.FormatInt(DefInnodbLockWaitTimeout, 10), Type: TypeUnsigned, MinValue: 1, MaxValue: 1073741824, AutoConvertOutOfRange: true, SetSession: func(s *SessionVars, val string) error {
lockWaitSec := tidbOptInt64(val, DefInnodbLockWaitTimeout)
s.LockWaitTimeout = lockWaitSec * 1000
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: GroupConcatMaxLen, Value: "1024", AutoConvertOutOfRange: true, IsHintUpdatable: true, skipInit: true, Type: TypeUnsigned, MinValue: 4, MaxValue: math.MaxUint64, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
// https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_group_concat_max_len
// Minimum Value 4
// Maximum Value (64-bit platforms) 18446744073709551615
// Maximum Value (32-bit platforms) 4294967295
if mathutil.IntBits == 32 {
if val, err := strconv.ParseUint(normalizedValue, 10, 64); err == nil {
if val > uint64(math.MaxUint32) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(GroupConcatMaxLen, originalValue))
return fmt.Sprintf("%d", math.MaxUint32), nil
}
}
}
return normalizedValue, nil
}},
{Scope: ScopeNone, Name: Socket, Value: ""},
{Scope: ScopeGlobal | ScopeSession, Name: CharacterSetConnection, Value: mysql.DefaultCharset, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkCharacterSet(normalizedValue, CharacterSetConnection)
}, SetSession: func(s *SessionVars, val string) error {
if cs, err := charset.GetCharsetInfo(val); err == nil {
s.systems[CollationConnection] = cs.DefaultCollation
}
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: CharacterSetServer, Value: mysql.DefaultCharset, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return checkCharacterSet(normalizedValue, CharacterSetServer)
}, SetSession: func(s *SessionVars, val string) error {
if cs, err := charset.GetCharsetInfo(val); err == nil {
s.systems[CollationServer] = cs.DefaultCollation
}
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: MaxAllowedPacket, Value: "67108864", Type: TypeUnsigned, MinValue: 1024, MaxValue: MaxOfMaxAllowedPacket, AutoConvertOutOfRange: true},
{Scope: ScopeSession, Name: WarningCount, Value: "0", ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return strconv.Itoa(s.SysWarningCount), nil
}},
{Scope: ScopeSession, Name: ErrorCount, Value: "0", ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return strconv.Itoa(int(s.SysErrorCount)), nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: WindowingUseHighPrecision, Value: On, Type: TypeBool, IsHintUpdatable: true, SetSession: func(s *SessionVars, val string) error {
s.WindowingUseHighPrecision = TiDBOptOn(val)
return nil
}},
{Scope: ScopeNone, Name: "license", Value: "Apache License 2.0"},
{Scope: ScopeGlobal | ScopeSession, Name: BlockEncryptionMode, Value: "aes-128-ecb"},
{Scope: ScopeSession, Name: LastInsertID, Value: "", skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return strconv.FormatUint(s.StmtCtx.PrevLastInsertID, 10), nil
}},
{Scope: ScopeSession, Name: Identity, Value: "", skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return strconv.FormatUint(s.StmtCtx.PrevLastInsertID, 10), nil
}},
{Scope: ScopeNone, Name: "have_ssl", Value: "DISABLED"},
{Scope: ScopeNone, Name: "have_openssl", Value: "DISABLED"},
{Scope: ScopeNone, Name: "ssl_ca", Value: ""},
{Scope: ScopeNone, Name: "ssl_cert", Value: ""},
{Scope: ScopeNone, Name: "ssl_key", Value: ""},
{Scope: ScopeGlobal, Name: InitConnect, Value: ""},
/* TiDB specific variables */
{Scope: ScopeGlobal, Name: TiDBEnableLocalTxn, Value: BoolToOnOff(DefTiDBEnableLocalTxn), Hidden: true, Type: TypeBool, GetGlobal: func(sv *SessionVars) (string, error) {
return BoolToOnOff(EnableLocalTxn.Load()), nil
}, SetGlobal: func(s *SessionVars, val string) error {
oldVal := EnableLocalTxn.Load()
newVal := TiDBOptOn(val)
// Make sure the TxnScope is always Global when disable the Local Txn.
// ON -> OFF
if oldVal && !newVal {
s.TxnScope = kv.NewGlobalTxnScopeVar()
}
EnableLocalTxn.Store(newVal)
return nil
}},
// TODO: TiDBTxnScope is hidden because local txn feature is not done.
{Scope: ScopeSession, Name: TiDBTxnScope, skipInit: true, Hidden: true, Value: kv.GlobalTxnScope, SetSession: func(s *SessionVars, val string) error {
switch val {
case kv.GlobalTxnScope:
s.TxnScope = kv.NewGlobalTxnScopeVar()
case kv.LocalTxnScope:
if !EnableLocalTxn.Load() {
return ErrWrongValueForVar.GenWithStack("@@txn_scope can not be set to local when tidb_enable_local_txn is off")
}
txnScope := config.GetTxnScopeFromConfig()
if txnScope == kv.GlobalTxnScope {
return ErrWrongValueForVar.GenWithStack("@@txn_scope can not be set to local when zone label is empty or \"global\"")
}
s.TxnScope = kv.NewLocalTxnScopeVar(txnScope)
default:
return ErrWrongValueForVar.GenWithStack("@@txn_scope value should be global or local")
}
return nil
}, GetSession: func(s *SessionVars) (string, error) {
return s.TxnScope.GetVarValue(), nil
}},
{Scope: ScopeSession, Name: TiDBTxnReadTS, Value: "", Hidden: true, SetSession: func(s *SessionVars, val string) error {
return setTxnReadTS(s, val)
}, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
return normalizedValue, nil
}},
{Scope: ScopeSession, Name: TiDBReadStaleness, Value: "", Hidden: false, SetSession: func(s *SessionVars, val string) error {
return setReadStaleness(s, val)
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAllowMPPExecution, Type: TypeBool, Value: BoolToOnOff(DefTiDBAllowMPPExecution), SetSession: func(s *SessionVars, val string) error {
s.allowMPPExecution = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBMPPStoreFailTTL, Type: TypeStr, Value: DefTiDBMPPStoreFailTTL, SetSession: func(s *SessionVars, val string) error {
s.MPPStoreFailTTL = val
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBHashExchangeWithNewCollation, Type: TypeBool, Value: BoolToOnOff(DefTiDBHashExchangeWithNewCollation), SetSession: func(s *SessionVars, val string) error {
s.HashExchangeWithNewCollation = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBEnforceMPPExecution, Type: TypeBool, Value: BoolToOnOff(config.GetGlobalConfig().Performance.EnforceMPP), Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
if TiDBOptOn(normalizedValue) && !vars.allowMPPExecution {
return normalizedValue, ErrWrongValueForVar.GenWithStackByArgs("tidb_enforce_mpp", "1' but tidb_allow_mpp is 0, please activate tidb_allow_mpp at first.")
}
return normalizedValue, nil
}, SetSession: func(s *SessionVars, val string) error {
s.enforceMPPExecution = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBCJThresholdCount, Value: strconv.Itoa(DefBroadcastJoinThresholdCount), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt64, SetSession: func(s *SessionVars, val string) error {
s.BroadcastJoinThresholdCount = tidbOptInt64(val, DefBroadcastJoinThresholdCount)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBCJThresholdSize, Value: strconv.Itoa(DefBroadcastJoinThresholdSize), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt64, SetSession: func(s *SessionVars, val string) error {
s.BroadcastJoinThresholdSize = tidbOptInt64(val, DefBroadcastJoinThresholdSize)
return nil
}},
{Scope: ScopeSession, Name: TiDBSnapshot, Value: "", skipInit: true, SetSession: func(s *SessionVars, val string) error {
err := setSnapshotTS(s, val)
if err != nil {
return err
}
return nil
}},
{Scope: ScopeSession, Name: TiDBOptAggPushDown, Value: BoolToOnOff(DefOptAggPushDown), Type: TypeBool, skipInit: true, SetSession: func(s *SessionVars, val string) error {
s.AllowAggPushDown = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptBCJ, Value: BoolToOnOff(DefOptBCJ), Type: TypeBool, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
if TiDBOptOn(normalizedValue) && vars.AllowBatchCop == 0 {
return normalizedValue, ErrWrongValueForVar.GenWithStackByArgs(TiDBOptBCJ, "'true' while tidb_allow_batch_cop is 0, please active batch cop at first.")
}
return normalizedValue, nil
}, SetSession: func(s *SessionVars, val string) error {
s.AllowBCJ = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBOptDistinctAggPushDown, Value: BoolToOnOff(config.GetGlobalConfig().Performance.DistinctAggPushDown), skipInit: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.AllowDistinctAggPushDown = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBOptWriteRowID, Value: BoolToOnOff(DefOptWriteRowID), skipInit: true, SetSession: func(s *SessionVars, val string) error {
s.AllowWriteRowID = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBuildStatsConcurrency, skipInit: true, Value: strconv.Itoa(DefBuildStatsConcurrency)},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptCartesianBCJ, Value: strconv.Itoa(DefOptCartesianBCJ), Type: TypeInt, MinValue: 0, MaxValue: 2, SetSession: func(s *SessionVars, val string) error {
s.AllowCartesianBCJ = tidbOptInt(val, DefOptCartesianBCJ)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptMPPOuterJoinFixedBuildSide, Value: BoolToOnOff(DefOptMPPOuterJoinFixedBuildSide), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.MPPOuterJoinFixedBuildSide = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBAutoAnalyzeRatio, Value: strconv.FormatFloat(DefAutoAnalyzeRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64},
{Scope: ScopeGlobal, Name: TiDBAutoAnalyzeStartTime, Value: DefAutoAnalyzeStartTime, Type: TypeTime},
{Scope: ScopeGlobal, Name: TiDBAutoAnalyzeEndTime, Value: DefAutoAnalyzeEndTime, Type: TypeTime},
{Scope: ScopeSession, Name: TiDBChecksumTableConcurrency, skipInit: true, Value: strconv.Itoa(DefChecksumTableConcurrency)},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBExecutorConcurrency, Value: strconv.Itoa(DefExecutorConcurrency), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
s.ExecutorConcurrency = tidbOptPositiveInt32(val, DefExecutorConcurrency)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBDistSQLScanConcurrency, Value: strconv.Itoa(DefDistSQLScanConcurrency), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
s.distSQLScanConcurrency = tidbOptPositiveInt32(val, DefDistSQLScanConcurrency)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptInSubqToJoinAndAgg, Value: BoolToOnOff(DefOptInSubqToJoinAndAgg), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.SetAllowInSubqToJoinAndAgg(TiDBOptOn(val))
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptPreferRangeScan, Value: BoolToOnOff(DefOptPreferRangeScan), Type: TypeBool, IsHintUpdatable: true, SetSession: func(s *SessionVars, val string) error {
s.SetAllowPreferRangeScan(TiDBOptOn(val))
return nil
}},
{
Scope: ScopeGlobal | ScopeSession, Name: TiDBOptLimitPushDownThreshold, Value: strconv.Itoa(DefOptLimitPushDownThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
s.LimitPushDownThreshold = tidbOptInt64(val, DefOptLimitPushDownThreshold)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptCorrelationThreshold, Value: strconv.FormatFloat(DefOptCorrelationThreshold, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: 1, SetSession: func(s *SessionVars, val string) error {
s.CorrelationThreshold = tidbOptFloat64(val, DefOptCorrelationThreshold)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptEnableCorrelationAdjustment, Value: BoolToOnOff(DefOptEnableCorrelationAdjustment), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.EnableCorrelationAdjustment = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptCorrelationExpFactor, Value: strconv.Itoa(DefOptCorrelationExpFactor), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
s.CorrelationExpFactor = int(tidbOptInt64(val, DefOptCorrelationExpFactor))
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptCPUFactor, Value: strconv.FormatFloat(DefOptCPUFactor, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.CPUFactor = tidbOptFloat64(val, DefOptCPUFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptTiFlashConcurrencyFactor, Value: strconv.FormatFloat(DefOptTiFlashConcurrencyFactor, 'f', -1, 64), skipInit: true, Type: TypeFloat, MinValue: 1, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.CopTiFlashConcurrencyFactor = tidbOptFloat64(val, DefOptTiFlashConcurrencyFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptCopCPUFactor, Value: strconv.FormatFloat(DefOptCopCPUFactor, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.CopCPUFactor = tidbOptFloat64(val, DefOptCopCPUFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptNetworkFactor, Value: strconv.FormatFloat(DefOptNetworkFactor, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.networkFactor = tidbOptFloat64(val, DefOptNetworkFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptScanFactor, Value: strconv.FormatFloat(DefOptScanFactor, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.scanFactor = tidbOptFloat64(val, DefOptScanFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptDescScanFactor, Value: strconv.FormatFloat(DefOptDescScanFactor, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.descScanFactor = tidbOptFloat64(val, DefOptDescScanFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptSeekFactor, Value: strconv.FormatFloat(DefOptSeekFactor, 'f', -1, 64), skipInit: true, Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.seekFactor = tidbOptFloat64(val, DefOptSeekFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptMemoryFactor, Value: strconv.FormatFloat(DefOptMemoryFactor, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.MemoryFactor = tidbOptFloat64(val, DefOptMemoryFactor)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptDiskFactor, Value: strconv.FormatFloat(DefOptDiskFactor, 'f', -1, 64), Type: TypeFloat, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error {
s.DiskFactor = tidbOptFloat64(val, DefOptDiskFactor)
return nil
}},