-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
bootstrap.go
3217 lines (2964 loc) · 120 KB
/
bootstrap.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.
// Copyright 2013 The ql Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSES/QL-LICENSE file.
package session
import (
"context"
"encoding/hex"
"fmt"
"os"
osuser "os/user"
"strconv"
"strings"
"time"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/pkg/bindinfo"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/domain/infosync"
"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/owner"
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/terror"
"github.com/pingcap/tidb/pkg/planner/core"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/table/tables"
timertable "github.com/pingcap/tidb/pkg/timer/tablestore"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/dbterror"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/logutil"
utilparser "github.com/pingcap/tidb/pkg/util/parser"
"github.com/pingcap/tidb/pkg/util/sqlescape"
"github.com/pingcap/tidb/pkg/util/sqlexec"
"github.com/pingcap/tidb/pkg/util/timeutil"
"go.etcd.io/etcd/client/v3/concurrency"
"go.uber.org/zap"
)
const (
// CreateUserTable is the SQL statement creates User table in system db.
// WARNING: There are some limitations on altering the schema of mysql.user table.
// Adding columns that are nullable or have default values is permitted.
// But operations like dropping or renaming columns may break the compatibility with BR.
// REFERENCE ISSUE: https://github.com/pingcap/tidb/issues/38785
CreateUserTable = `CREATE TABLE IF NOT EXISTS mysql.user (
Host CHAR(255),
User CHAR(32),
authentication_string TEXT,
plugin CHAR(64),
Select_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Insert_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Update_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Delete_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Drop_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Process_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Grant_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
References_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Show_db_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Super_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_tmp_table_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Lock_tables_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Execute_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Show_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Index_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_user_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Event_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Repl_slave_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Repl_client_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Trigger_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_role_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Drop_role_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Account_locked ENUM('N','Y') NOT NULL DEFAULT 'N',
Shutdown_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Reload_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
FILE_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Config_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_Tablespace_Priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Password_reuse_history smallint unsigned DEFAULT NULL,
Password_reuse_time smallint unsigned DEFAULT NULL,
User_attributes json,
Token_issuer VARCHAR(255),
Password_expired ENUM('N','Y') NOT NULL DEFAULT 'N',
Password_last_changed TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
Password_lifetime SMALLINT UNSIGNED DEFAULT NULL,
PRIMARY KEY (Host, User));`
// CreateGlobalPrivTable is the SQL statement creates Global scope privilege table in system db.
CreateGlobalPrivTable = "CREATE TABLE IF NOT EXISTS mysql.global_priv (" +
"Host CHAR(255) NOT NULL DEFAULT ''," +
"User CHAR(80) NOT NULL DEFAULT ''," +
"Priv LONGTEXT NOT NULL DEFAULT ''," +
"PRIMARY KEY (Host, User)" +
")"
// For `mysql.db`, `mysql.tables_priv` and `mysql.columns_priv` table, we have a slight different
// schema definition with MySQL: columns `DB`/`Table_name`/`Column_name` are defined with case-insensitive
// collation(in MySQL, they are case-sensitive).
// The reason behind this is that when writing those records, MySQL always converts those names into lower case
// while TiDB does not do so in early implementations, which makes some 'GRANT'/'REVOKE' operations case-sensitive.
// In order to fix this, we decide to explicitly set case-insensitive collation for the related columns here, to
// make sure:
// * The 'GRANT'/'REVOKE' could be case-insensitive for new clusters(compatible with MySQL).
// * Keep all behaviors unchanged for upgraded cluster.
// CreateDBPrivTable is the SQL statement creates DB scope privilege table in system db.
CreateDBPrivTable = `CREATE TABLE IF NOT EXISTS mysql.db (
Host CHAR(255),
DB CHAR(64) CHARSET utf8mb4 COLLATE utf8mb4_general_ci,
User CHAR(32),
Select_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Insert_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Update_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Delete_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Drop_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Grant_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
References_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Index_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_tmp_table_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Lock_tables_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Show_view_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Create_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Alter_routine_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Execute_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Event_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
Trigger_priv ENUM('N','Y') NOT NULL DEFAULT 'N',
PRIMARY KEY (Host, DB, User));`
// CreateTablePrivTable is the SQL statement creates table scope privilege table in system db.
CreateTablePrivTable = `CREATE TABLE IF NOT EXISTS mysql.tables_priv (
Host CHAR(255),
DB CHAR(64) CHARSET utf8mb4 COLLATE utf8mb4_general_ci,
User CHAR(32),
Table_name CHAR(64) CHARSET utf8mb4 COLLATE utf8mb4_general_ci,
Grantor CHAR(77),
Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Table_priv SET('Select','Insert','Update','Delete','Create','Drop','Grant','Index','Alter','Create View','Show View','Trigger','References'),
Column_priv SET('Select','Insert','Update','References'),
PRIMARY KEY (Host, DB, User, Table_name));`
// CreateColumnPrivTable is the SQL statement creates column scope privilege table in system db.
CreateColumnPrivTable = `CREATE TABLE IF NOT EXISTS mysql.columns_priv(
Host CHAR(255),
DB CHAR(64) CHARSET utf8mb4 COLLATE utf8mb4_general_ci,
User CHAR(32),
Table_name CHAR(64) CHARSET utf8mb4 COLLATE utf8mb4_general_ci,
Column_name CHAR(64) CHARSET utf8mb4 COLLATE utf8mb4_general_ci,
Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Column_priv SET('Select','Insert','Update','References'),
PRIMARY KEY (Host, DB, User, Table_name, Column_name));`
// CreateGlobalVariablesTable is the SQL statement creates global variable table in system db.
// TODO: MySQL puts GLOBAL_VARIABLES table in INFORMATION_SCHEMA db.
// INFORMATION_SCHEMA is a virtual db in TiDB. So we put this table in system db.
// Maybe we will put it back to INFORMATION_SCHEMA.
CreateGlobalVariablesTable = `CREATE TABLE IF NOT EXISTS mysql.GLOBAL_VARIABLES(
VARIABLE_NAME VARCHAR(64) NOT NULL PRIMARY KEY,
VARIABLE_VALUE VARCHAR(16383) DEFAULT NULL);`
// CreateTiDBTable is the SQL statement creates a table in system db.
// This table is a key-value struct contains some information used by TiDB.
// Currently we only put bootstrapped in it which indicates if the system is already bootstrapped.
CreateTiDBTable = `CREATE TABLE IF NOT EXISTS mysql.tidb(
VARIABLE_NAME VARCHAR(64) NOT NULL PRIMARY KEY,
VARIABLE_VALUE VARCHAR(1024) DEFAULT NULL,
COMMENT VARCHAR(1024));`
// CreateHelpTopic is the SQL statement creates help_topic table in system db.
// See: https://dev.mysql.com/doc/refman/5.5/en/system-database.html#system-database-help-tables
CreateHelpTopic = `CREATE TABLE IF NOT EXISTS mysql.help_topic (
help_topic_id INT(10) UNSIGNED NOT NULL,
name CHAR(64) NOT NULL,
help_category_id SMALLINT(5) UNSIGNED NOT NULL,
description TEXT NOT NULL,
example TEXT NOT NULL,
url TEXT NOT NULL,
PRIMARY KEY (help_topic_id) clustered,
UNIQUE KEY name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='help topics';`
// CreateStatsMetaTable stores the meta of table statistics.
CreateStatsMetaTable = `CREATE TABLE IF NOT EXISTS mysql.stats_meta (
version BIGINT(64) UNSIGNED NOT NULL,
table_id BIGINT(64) NOT NULL,
modify_count BIGINT(64) NOT NULL DEFAULT 0,
count BIGINT(64) UNSIGNED NOT NULL DEFAULT 0,
snapshot BIGINT(64) UNSIGNED NOT NULL DEFAULT 0,
INDEX idx_ver(version),
UNIQUE INDEX tbl(table_id)
);`
// CreateStatsColsTable stores the statistics of table columns.
CreateStatsColsTable = `CREATE TABLE IF NOT EXISTS mysql.stats_histograms (
table_id BIGINT(64) NOT NULL,
is_index TINYINT(2) NOT NULL,
hist_id BIGINT(64) NOT NULL,
distinct_count BIGINT(64) NOT NULL,
null_count BIGINT(64) NOT NULL DEFAULT 0,
tot_col_size BIGINT(64) NOT NULL DEFAULT 0,
modify_count BIGINT(64) NOT NULL DEFAULT 0,
version BIGINT(64) UNSIGNED NOT NULL DEFAULT 0,
cm_sketch BLOB(6291456),
stats_ver BIGINT(64) NOT NULL DEFAULT 0,
flag BIGINT(64) NOT NULL DEFAULT 0,
correlation DOUBLE NOT NULL DEFAULT 0,
last_analyze_pos LONGBLOB DEFAULT NULL,
UNIQUE INDEX tbl(table_id, is_index, hist_id)
);`
// CreateStatsBucketsTable stores the histogram info for every table columns.
CreateStatsBucketsTable = `CREATE TABLE IF NOT EXISTS mysql.stats_buckets (
table_id BIGINT(64) NOT NULL,
is_index TINYINT(2) NOT NULL,
hist_id BIGINT(64) NOT NULL,
bucket_id BIGINT(64) NOT NULL,
count BIGINT(64) NOT NULL,
repeats BIGINT(64) NOT NULL,
upper_bound LONGBLOB NOT NULL,
lower_bound LONGBLOB ,
ndv BIGINT NOT NULL DEFAULT 0,
UNIQUE INDEX tbl(table_id, is_index, hist_id, bucket_id)
);`
// CreateGCDeleteRangeTable stores schemas which can be deleted by DeleteRange.
CreateGCDeleteRangeTable = `CREATE TABLE IF NOT EXISTS mysql.gc_delete_range (
job_id BIGINT NOT NULL COMMENT "the DDL job ID",
element_id BIGINT NOT NULL COMMENT "the schema element ID",
start_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
end_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
ts BIGINT NOT NULL COMMENT "timestamp in uint64",
UNIQUE KEY delete_range_index (job_id, element_id)
);`
// CreateGCDeleteRangeDoneTable stores schemas which are already deleted by DeleteRange.
CreateGCDeleteRangeDoneTable = `CREATE TABLE IF NOT EXISTS mysql.gc_delete_range_done (
job_id BIGINT NOT NULL COMMENT "the DDL job ID",
element_id BIGINT NOT NULL COMMENT "the schema element ID",
start_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
end_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
ts BIGINT NOT NULL COMMENT "timestamp in uint64",
UNIQUE KEY delete_range_done_index (job_id, element_id)
);`
// CreateStatsFeedbackTable stores the feedback info which is used to update stats.
// NOTE: Feedback is deprecated, but we still need to create this table for compatibility.
CreateStatsFeedbackTable = `CREATE TABLE IF NOT EXISTS mysql.stats_feedback (
table_id BIGINT(64) NOT NULL,
is_index TINYINT(2) NOT NULL,
hist_id BIGINT(64) NOT NULL,
feedback BLOB NOT NULL,
INDEX hist(table_id, is_index, hist_id)
);`
// CreateBindInfoTable stores the sql bind info which is used to update globalBindCache.
CreateBindInfoTable = `CREATE TABLE IF NOT EXISTS mysql.bind_info (
original_sql TEXT NOT NULL,
bind_sql TEXT NOT NULL,
default_db TEXT NOT NULL,
status TEXT NOT NULL,
create_time TIMESTAMP(3) NOT NULL,
update_time TIMESTAMP(3) NOT NULL,
charset TEXT NOT NULL,
collation TEXT NOT NULL,
source VARCHAR(10) NOT NULL DEFAULT 'unknown',
sql_digest varchar(64),
plan_digest varchar(64),
INDEX sql_index(original_sql(700),default_db(68)) COMMENT "accelerate the speed when add global binding query",
INDEX time_index(update_time) COMMENT "accelerate the speed when querying with last update time"
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`
// CreateRoleEdgesTable stores the role and user relationship information.
CreateRoleEdgesTable = `CREATE TABLE IF NOT EXISTS mysql.role_edges (
FROM_HOST CHAR(60) COLLATE utf8_bin NOT NULL DEFAULT '',
FROM_USER CHAR(32) COLLATE utf8_bin NOT NULL DEFAULT '',
TO_HOST CHAR(60) COLLATE utf8_bin NOT NULL DEFAULT '',
TO_USER CHAR(32) COLLATE utf8_bin NOT NULL DEFAULT '',
WITH_ADMIN_OPTION ENUM('N','Y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N',
PRIMARY KEY (FROM_HOST,FROM_USER,TO_HOST,TO_USER)
);`
// CreateDefaultRolesTable stores the active roles for a user.
CreateDefaultRolesTable = `CREATE TABLE IF NOT EXISTS mysql.default_roles (
HOST CHAR(60) COLLATE utf8_bin NOT NULL DEFAULT '',
USER CHAR(32) COLLATE utf8_bin NOT NULL DEFAULT '',
DEFAULT_ROLE_HOST CHAR(60) COLLATE utf8_bin NOT NULL DEFAULT '%',
DEFAULT_ROLE_USER CHAR(32) COLLATE utf8_bin NOT NULL DEFAULT '',
PRIMARY KEY (HOST,USER,DEFAULT_ROLE_HOST,DEFAULT_ROLE_USER)
)`
// CreateStatsTopNTable stores topn data of a cmsketch with top n.
CreateStatsTopNTable = `CREATE TABLE IF NOT EXISTS mysql.stats_top_n (
table_id BIGINT(64) NOT NULL,
is_index TINYINT(2) NOT NULL,
hist_id BIGINT(64) NOT NULL,
value LONGBLOB,
count BIGINT(64) UNSIGNED NOT NULL,
INDEX tbl(table_id, is_index, hist_id)
);`
// CreateStatsFMSketchTable stores FMSketch data of a column histogram.
CreateStatsFMSketchTable = `CREATE TABLE IF NOT EXISTS mysql.stats_fm_sketch (
table_id BIGINT(64) NOT NULL,
is_index TINYINT(2) NOT NULL,
hist_id BIGINT(64) NOT NULL,
value LONGBLOB,
INDEX tbl(table_id, is_index, hist_id)
);`
// CreateExprPushdownBlacklist stores the expressions which are not allowed to be pushed down.
CreateExprPushdownBlacklist = `CREATE TABLE IF NOT EXISTS mysql.expr_pushdown_blacklist (
name CHAR(100) NOT NULL,
store_type CHAR(100) NOT NULL DEFAULT 'tikv,tiflash,tidb',
reason VARCHAR(200)
);`
// CreateOptRuleBlacklist stores the list of disabled optimizing operations.
CreateOptRuleBlacklist = `CREATE TABLE IF NOT EXISTS mysql.opt_rule_blacklist (
name CHAR(100) NOT NULL
);`
// CreateStatsExtended stores the registered extended statistics.
CreateStatsExtended = `CREATE TABLE IF NOT EXISTS mysql.stats_extended (
name varchar(32) NOT NULL,
type tinyint(4) NOT NULL,
table_id bigint(64) NOT NULL,
column_ids varchar(32) NOT NULL,
stats blob DEFAULT NULL,
version bigint(64) unsigned NOT NULL,
status tinyint(4) NOT NULL,
PRIMARY KEY(name, table_id),
KEY idx_1 (table_id, status, version),
KEY idx_2 (status, version)
);`
// CreateSchemaIndexUsageTable stores the index usage information.
CreateSchemaIndexUsageTable = `CREATE TABLE IF NOT EXISTS mysql.schema_index_usage (
TABLE_ID bigint(64),
INDEX_ID bigint(21),
QUERY_COUNT bigint(64),
ROWS_SELECTED bigint(64),
LAST_USED_AT timestamp,
PRIMARY KEY(TABLE_ID, INDEX_ID)
);`
// CreateGlobalGrantsTable stores dynamic privs
CreateGlobalGrantsTable = `CREATE TABLE IF NOT EXISTS mysql.global_grants (
USER char(32) NOT NULL DEFAULT '',
HOST char(255) NOT NULL DEFAULT '',
PRIV char(32) NOT NULL DEFAULT '',
WITH_GRANT_OPTION enum('N','Y') NOT NULL DEFAULT 'N',
PRIMARY KEY (USER,HOST,PRIV)
);`
// CreateCapturePlanBaselinesBlacklist stores the baseline capture filter rules.
CreateCapturePlanBaselinesBlacklist = `CREATE TABLE IF NOT EXISTS mysql.capture_plan_baselines_blacklist (
id bigint(64) auto_increment,
filter_type varchar(32) NOT NULL COMMENT "type of the filter, only db, table and frequency supported now",
filter_value varchar(32) NOT NULL,
key idx(filter_type),
primary key(id)
);`
// CreateColumnStatsUsageTable stores the column stats usage information.
CreateColumnStatsUsageTable = `CREATE TABLE IF NOT EXISTS mysql.column_stats_usage (
table_id BIGINT(64) NOT NULL,
column_id BIGINT(64) NOT NULL,
last_used_at TIMESTAMP,
last_analyzed_at TIMESTAMP,
PRIMARY KEY (table_id, column_id) CLUSTERED
);`
// CreateTableCacheMetaTable stores the cached table meta lock information.
CreateTableCacheMetaTable = `CREATE TABLE IF NOT EXISTS mysql.table_cache_meta (
tid bigint(11) NOT NULL DEFAULT 0,
lock_type enum('NONE','READ', 'INTEND', 'WRITE') NOT NULL DEFAULT 'NONE',
lease bigint(20) NOT NULL DEFAULT 0,
oldReadLease bigint(20) NOT NULL DEFAULT 0,
PRIMARY KEY (tid)
);`
// CreateAnalyzeOptionsTable stores the analyze options used by analyze and auto analyze.
CreateAnalyzeOptionsTable = `CREATE TABLE IF NOT EXISTS mysql.analyze_options (
table_id BIGINT(64) NOT NULL,
sample_num BIGINT(64) NOT NULL DEFAULT 0,
sample_rate DOUBLE NOT NULL DEFAULT -1,
buckets BIGINT(64) NOT NULL DEFAULT 0,
topn BIGINT(64) NOT NULL DEFAULT -1,
column_choice enum('DEFAULT','ALL','PREDICATE','LIST') NOT NULL DEFAULT 'DEFAULT',
column_ids TEXT(19372),
PRIMARY KEY (table_id) CLUSTERED
);`
// CreateStatsHistory stores the historical stats.
CreateStatsHistory = `CREATE TABLE IF NOT EXISTS mysql.stats_history (
table_id bigint(64) NOT NULL,
stats_data longblob NOT NULL,
seq_no bigint(64) NOT NULL comment 'sequence number of the gzipped data slice',
version bigint(64) NOT NULL comment 'stats version which corresponding to stats:version in EXPLAIN',
create_time datetime(6) NOT NULL,
UNIQUE KEY table_version_seq (table_id, version, seq_no),
KEY table_create_time (table_id, create_time, seq_no),
KEY idx_create_time (create_time)
);`
// CreateStatsMetaHistory stores the historical meta stats.
CreateStatsMetaHistory = `CREATE TABLE IF NOT EXISTS mysql.stats_meta_history (
table_id bigint(64) NOT NULL,
modify_count bigint(64) NOT NULL,
count bigint(64) NOT NULL,
version bigint(64) NOT NULL comment 'stats version which corresponding to stats:version in EXPLAIN',
source varchar(40) NOT NULL,
create_time datetime(6) NOT NULL,
UNIQUE KEY table_version (table_id, version),
KEY table_create_time (table_id, create_time),
KEY idx_create_time (create_time)
);`
// CreateAnalyzeJobs stores the analyze jobs.
CreateAnalyzeJobs = `CREATE TABLE IF NOT EXISTS mysql.analyze_jobs (
id BIGINT(64) UNSIGNED NOT NULL AUTO_INCREMENT,
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
table_schema CHAR(64) NOT NULL DEFAULT '',
table_name CHAR(64) NOT NULL DEFAULT '',
partition_name CHAR(64) NOT NULL DEFAULT '',
job_info TEXT NOT NULL,
processed_rows BIGINT(64) UNSIGNED NOT NULL DEFAULT 0,
start_time TIMESTAMP,
end_time TIMESTAMP,
state ENUM('pending', 'running', 'finished', 'failed') NOT NULL,
fail_reason TEXT,
instance VARCHAR(512) NOT NULL comment 'address of the TiDB instance executing the analyze job',
process_id BIGINT(64) UNSIGNED comment 'ID of the process executing the analyze job',
PRIMARY KEY (id),
KEY (update_time)
);`
// CreateAdvisoryLocks stores the advisory locks (get_lock, release_lock).
CreateAdvisoryLocks = `CREATE TABLE IF NOT EXISTS mysql.advisory_locks (
lock_name VARCHAR(64) NOT NULL PRIMARY KEY
);`
// CreateMDLView is a view about metadata locks.
CreateMDLView = `CREATE OR REPLACE VIEW mysql.tidb_mdl_view as (
SELECT job_id,
db_name,
table_name,
query,
session_id,
txnstart,
tidb_decode_sql_digests(all_sql_digests, 4096) AS SQL_DIGESTS
FROM information_schema.ddl_jobs,
information_schema.cluster_tidb_trx,
information_schema.cluster_processlist
WHERE (ddl_jobs.state != 'synced' and ddl_jobs.state != 'cancelled')
AND Find_in_set(ddl_jobs.table_id, cluster_tidb_trx.related_table_ids)
AND cluster_tidb_trx.session_id = cluster_processlist.id
);`
// CreatePlanReplayerStatusTable is a table about plan replayer status
CreatePlanReplayerStatusTable = `CREATE TABLE IF NOT EXISTS mysql.plan_replayer_status (
sql_digest VARCHAR(128),
plan_digest VARCHAR(128),
origin_sql TEXT,
token VARCHAR(128),
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fail_reason TEXT,
instance VARCHAR(512) NOT NULL comment 'address of the TiDB instance executing the plan replayer job');`
// CreatePlanReplayerTaskTable is a table about plan replayer capture task
CreatePlanReplayerTaskTable = `CREATE TABLE IF NOT EXISTS mysql.plan_replayer_task (
sql_digest VARCHAR(128) NOT NULL,
plan_digest VARCHAR(128) NOT NULL,
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (sql_digest,plan_digest));`
// CreateStatsTableLocked stores the locked tables
CreateStatsTableLocked = `CREATE TABLE IF NOT EXISTS mysql.stats_table_locked(
table_id bigint(64) NOT NULL,
modify_count bigint(64) NOT NULL DEFAULT 0,
count bigint(64) NOT NULL DEFAULT 0,
version bigint(64) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (table_id));`
// CreatePasswordHistory is a table save history passwd.
CreatePasswordHistory = `CREATE TABLE IF NOT EXISTS mysql.password_history (
Host char(255) NOT NULL DEFAULT '',
User char(32) NOT NULL DEFAULT '',
Password_timestamp timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
Password text,
PRIMARY KEY (Host,User,Password_timestamp )
) COMMENT='Password history for user accounts' `
// CreateTTLTableStatus is a table about TTL job schedule
CreateTTLTableStatus = `CREATE TABLE IF NOT EXISTS mysql.tidb_ttl_table_status (
table_id bigint(64) PRIMARY KEY,
parent_table_id bigint(64),
table_statistics text DEFAULT NULL,
last_job_id varchar(64) DEFAULT NULL,
last_job_start_time timestamp NULL DEFAULT NULL,
last_job_finish_time timestamp NULL DEFAULT NULL,
last_job_ttl_expire timestamp NULL DEFAULT NULL,
last_job_summary text DEFAULT NULL,
current_job_id varchar(64) DEFAULT NULL,
current_job_owner_id varchar(64) DEFAULT NULL,
current_job_owner_addr varchar(256) DEFAULT NULL,
current_job_owner_hb_time timestamp,
current_job_start_time timestamp NULL DEFAULT NULL,
current_job_ttl_expire timestamp NULL DEFAULT NULL,
current_job_state text DEFAULT NULL,
current_job_status varchar(64) DEFAULT NULL,
current_job_status_update_time timestamp NULL DEFAULT NULL);`
// CreateTTLTask is a table about parallel ttl tasks
CreateTTLTask = `CREATE TABLE IF NOT EXISTS mysql.tidb_ttl_task (
job_id varchar(64) NOT NULL,
table_id bigint(64) NOT NULL,
scan_id int NOT NULL,
scan_range_start BLOB,
scan_range_end BLOB,
expire_time timestamp NOT NULL,
owner_id varchar(64) DEFAULT NULL,
owner_addr varchar(64) DEFAULT NULL,
owner_hb_time timestamp DEFAULT NULL,
status varchar(64) DEFAULT 'waiting',
status_update_time timestamp NULL DEFAULT NULL,
state text,
created_time timestamp NOT NULL,
primary key(job_id, scan_id),
key(created_time));`
// CreateTTLJobHistory is a table that stores ttl job's history
CreateTTLJobHistory = `CREATE TABLE IF NOT EXISTS mysql.tidb_ttl_job_history (
job_id varchar(64) PRIMARY KEY,
table_id bigint(64) NOT NULL,
parent_table_id bigint(64) NOT NULL,
table_schema varchar(64) NOT NULL,
table_name varchar(64) NOT NULL,
partition_name varchar(64) DEFAULT NULL,
create_time timestamp NOT NULL,
finish_time timestamp NOT NULL,
ttl_expire timestamp NOT NULL,
summary_text text,
expired_rows bigint(64) DEFAULT NULL,
deleted_rows bigint(64) DEFAULT NULL,
error_delete_rows bigint(64) DEFAULT NULL,
status varchar(64) NOT NULL,
key(table_schema, table_name, create_time),
key(parent_table_id, create_time),
key(create_time)
);`
// CreateGlobalTask is a table about global task.
CreateGlobalTask = `CREATE TABLE IF NOT EXISTS mysql.tidb_global_task (
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
task_key VARCHAR(256) NOT NULL,
type VARCHAR(256) NOT NULL,
dispatcher_id VARCHAR(256),
state VARCHAR(64) NOT NULL,
start_time TIMESTAMP,
state_update_time TIMESTAMP,
meta LONGBLOB,
concurrency INT(11),
step INT(11),
error BLOB,
key(state),
UNIQUE KEY task_key(task_key)
);`
// CreateGlobalTaskHistory is a table about history global task.
CreateGlobalTaskHistory = `CREATE TABLE IF NOT EXISTS mysql.tidb_global_task_history (
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
task_key VARCHAR(256) NOT NULL,
type VARCHAR(256) NOT NULL,
dispatcher_id VARCHAR(256),
state VARCHAR(64) NOT NULL,
start_time TIMESTAMP,
state_update_time TIMESTAMP,
meta LONGBLOB,
concurrency INT(11),
step INT(11),
error BLOB,
key(state),
UNIQUE KEY task_key(task_key)
);`
// CreateDistFrameworkMeta create a system table that distributed task framework use to store meta information
CreateDistFrameworkMeta = `CREATE TABLE IF NOT EXISTS mysql.dist_framework_meta (
host VARCHAR(100) NOT NULL PRIMARY KEY,
role VARCHAR(64),
keyspace_id bigint(8) NOT NULL DEFAULT -1);`
// CreateLoadDataJobs is a table that LOAD DATA uses
CreateLoadDataJobs = `CREATE TABLE IF NOT EXISTS mysql.load_data_jobs (
job_id bigint(64) NOT NULL AUTO_INCREMENT,
expected_status ENUM('running', 'paused', 'canceled') NOT NULL DEFAULT 'running',
create_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
start_time TIMESTAMP(6) NULL DEFAULT NULL,
update_time TIMESTAMP(6) NULL DEFAULT NULL,
end_time TIMESTAMP(6) NULL DEFAULT NULL,
data_source TEXT NOT NULL,
table_schema VARCHAR(64) NOT NULL,
table_name VARCHAR(64) NOT NULL,
import_mode VARCHAR(64) NOT NULL,
create_user VARCHAR(32) NOT NULL,
progress TEXT DEFAULT NULL,
result_message TEXT DEFAULT NULL,
error_message TEXT DEFAULT NULL,
PRIMARY KEY (job_id),
KEY (create_time),
KEY (create_user));`
// CreateRunawayTable stores the query which is identified as runaway or quarantined because of in watch list.
CreateRunawayTable = `CREATE TABLE IF NOT EXISTS mysql.tidb_runaway_queries (
resource_group_name varchar(32) not null,
time TIMESTAMP NOT NULL,
match_type varchar(12) NOT NULL,
action varchar(12) NOT NULL,
original_sql TEXT NOT NULL,
plan_digest TEXT NOT NULL,
tidb_server varchar(512),
INDEX plan_index(plan_digest(64)) COMMENT "accelerate the speed when select runaway query",
INDEX time_index(time) COMMENT "accelerate the speed when querying with active watch"
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`
// CreateRunawayWatchTable stores the condition which is used to check whether query should be quarantined.
CreateRunawayWatchTable = `CREATE TABLE IF NOT EXISTS mysql.tidb_runaway_watch (
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
resource_group_name varchar(32) not null,
start_time datetime(6) NOT NULL,
end_time datetime(6),
watch bigint(10) NOT NULL,
watch_text TEXT NOT NULL,
source varchar(512) NOT NULL,
action bigint(10),
INDEX sql_index(resource_group_name,watch_text(700)) COMMENT "accelerate the speed when select quarantined query",
INDEX time_index(end_time) COMMENT "accelerate the speed when querying with active watch"
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`
// CreateDoneRunawayWatchTable stores the condition which is used to check whether query should be quarantined.
CreateDoneRunawayWatchTable = `CREATE TABLE IF NOT EXISTS mysql.tidb_runaway_watch_done (
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
record_id BIGINT(20) not null,
resource_group_name varchar(32) not null,
start_time datetime(6) NOT NULL,
end_time datetime(6),
watch bigint(10) NOT NULL,
watch_text TEXT NOT NULL,
source varchar(512) NOT NULL,
action bigint(10),
done_time TIMESTAMP(6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`
// CreateImportJobs is a table that IMPORT INTO uses.
CreateImportJobs = `CREATE TABLE IF NOT EXISTS mysql.tidb_import_jobs (
id bigint(64) NOT NULL AUTO_INCREMENT,
create_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
start_time TIMESTAMP(6) NULL DEFAULT NULL,
update_time TIMESTAMP(6) NULL DEFAULT NULL,
end_time TIMESTAMP(6) NULL DEFAULT NULL,
table_schema VARCHAR(64) NOT NULL,
table_name VARCHAR(64) NOT NULL,
table_id bigint(64) NOT NULL,
created_by VARCHAR(300) NOT NULL,
parameters text NOT NULL,
source_file_size bigint(64) NOT NULL,
status VARCHAR(64) NOT NULL,
step VARCHAR(64) NOT NULL,
summary text DEFAULT NULL,
error_message TEXT DEFAULT NULL,
PRIMARY KEY (id),
KEY (created_by),
KEY (status));`
)
// CreateTimers is a table to store all timers for tidb
var CreateTimers = timertable.CreateTimerTableSQL("mysql", "tidb_timers")
// bootstrap initiates system DB for a store.
func bootstrap(s Session) {
startTime := time.Now()
err := InitMDLVariableForBootstrap(s.GetStore())
if err != nil {
logutil.BgLogger().Fatal("init metadata lock error",
zap.Error(err))
}
dom := domain.GetDomain(s)
for {
b, err := checkBootstrapped(s)
if err != nil {
logutil.BgLogger().Fatal("check bootstrap error",
zap.Error(err))
}
// For rolling upgrade, we can't do upgrade only in the owner.
if b {
upgrade(s)
logutil.BgLogger().Info("upgrade successful in bootstrap",
zap.Duration("take time", time.Since(startTime)))
return
}
// To reduce conflict when multiple TiDB-server start at the same time.
// Actually only one server need to do the bootstrap. So we chose DDL owner to do this.
if dom.DDL().OwnerManager().IsOwner() {
doDDLWorks(s)
doDMLWorks(s)
runBootstrapSQLFile = true
logutil.BgLogger().Info("bootstrap successful",
zap.Duration("take time", time.Since(startTime)))
return
}
time.Sleep(200 * time.Millisecond)
}
}
const (
// varTrue is the true value in mysql.TiDB table for boolean columns.
varTrue = "True"
// varFalse is the false value in mysql.TiDB table for boolean columns.
varFalse = "False"
// The variable name in mysql.TiDB table.
// It is used for checking if the store is bootstrapped by any TiDB server.
// If the value is `True`, the store is already bootstrapped by a TiDB server.
bootstrappedVar = "bootstrapped"
// The variable name in mysql.TiDB table.
// It is used for getting the version of the TiDB server which bootstrapped the store.
tidbServerVersionVar = "tidb_server_version"
// The variable name in mysql.tidb table and it will be used when we want to know
// system timezone.
tidbSystemTZ = "system_tz"
// The variable name in mysql.tidb table and it will indicate if the new collations are enabled in the TiDB cluster.
tidbNewCollationEnabled = "new_collation_enabled"
// The variable name in mysql.tidb table and it records the default value of
// mem-quota-query when upgrade from v3.0.x to v4.0.9+.
tidbDefMemoryQuotaQuery = "default_memory_quota_query"
// The variable name in mysql.tidb table and it records the default value of
// oom-action when upgrade from v3.0.x to v4.0.11+.
tidbDefOOMAction = "default_oom_action"
// The variable name in mysql.tidb table and it records the current DDLTableVersion
tidbDDLTableVersion = "ddl_table_version"
// Const for TiDB server version 2.
version2 = 2
version3 = 3
version4 = 4
version5 = 5
version6 = 6
version7 = 7
version8 = 8
version9 = 9
version10 = 10
version11 = 11
version12 = 12
version13 = 13
version14 = 14
version15 = 15
version16 = 16
version17 = 17
version18 = 18
version19 = 19
version20 = 20
version21 = 21
version22 = 22
version23 = 23
version24 = 24
version25 = 25
version26 = 26
version27 = 27
version28 = 28
// version29 is not needed.
version30 = 30
version31 = 31
version32 = 32
version33 = 33
version34 = 34
version35 = 35
version36 = 36
version37 = 37
version38 = 38
// version39 will be redone in version46 so it's skipped here.
// version40 is the version that introduce new collation in TiDB,
// see https://github.com/pingcap/tidb/pull/14574 for more details.
version40 = 40
version41 = 41
// version42 add storeType and reason column in expr_pushdown_blacklist
version42 = 42
// version43 updates global variables related to statement summary.
version43 = 43
// version44 delete tidb_isolation_read_engines from mysql.global_variables to avoid unexpected behavior after upgrade.
version44 = 44
// version45 introduces CONFIG_PRIV for SET CONFIG statements.
version45 = 45
// version46 fix a bug in v3.1.1.
version46 = 46
// version47 add Source to bindings to indicate the way binding created.
version47 = 47
// version48 reset all deprecated concurrency related system-variables if they were all default value.
// version49 introduces mysql.stats_extended table.
// Both version48 and version49 will be redone in version55 and version56 so they're skipped here.
// version50 add mysql.schema_index_usage table.
version50 = 50
// version51 introduces CreateTablespacePriv to mysql.user.
// version51 will be redone in version63 so it's skipped here.
// version52 change mysql.stats_histograms cm_sketch column from blob to blob(6291456)
version52 = 52
// version53 introduce Global variable tidb_enable_strict_double_type_check
version53 = 53
// version54 writes a variable `mem_quota_query` to mysql.tidb if it's a cluster upgraded from v3.0.x to v4.0.9+.
version54 = 54
// version55 fixes the bug that upgradeToVer48 would be missed when upgrading from v4.0 to a new version
version55 = 55
// version56 fixes the bug that upgradeToVer49 would be missed when upgrading from v4.0 to a new version
version56 = 56
// version57 fixes the bug of concurrent create / drop binding
version57 = 57
// version58 add `Repl_client_priv` and `Repl_slave_priv` to `mysql.user`
// version58 will be redone in version64 so it's skipped here.
// version59 add writes a variable `oom-action` to mysql.tidb if it's a cluster upgraded from v3.0.x to v4.0.11+.
version59 = 59
// version60 redesigns `mysql.stats_extended`
version60 = 60
// version61 will be redone in version67
// version62 add column ndv for mysql.stats_buckets.
version62 = 62
// version63 fixes the bug that upgradeToVer51 would be missed when upgrading from v4.0 to a new version
version63 = 63
// version64 is redone upgradeToVer58 after upgradeToVer63, this is to preserve the order of the columns in mysql.user
version64 = 64
// version65 add mysql.stats_fm_sketch table.
version65 = 65
// version66 enables the feature `track_aggregate_memory_usage` by default.
version66 = 66
// version67 restore all SQL bindings.
version67 = 67
// version68 update the global variable 'tidb_enable_clustered_index' from 'off' to 'int_only'.
version68 = 68
// version69 adds mysql.global_grants for DYNAMIC privileges
version69 = 69
// version70 adds mysql.user.plugin to allow multiple authentication plugins
version70 = 70
// version71 forces tidb_multi_statement_mode=OFF when tidb_multi_statement_mode=WARN
// This affects upgrades from v4.0 where the default was WARN.
version71 = 71
// version72 adds snapshot column for mysql.stats_meta
version72 = 72
// version73 adds mysql.capture_plan_baselines_blacklist table
version73 = 73
// version74 changes global variable `tidb_stmt_summary_max_stmt_count` value from 200 to 3000.
version74 = 74
// version75 update mysql.*.host from char(60) to char(255)
version75 = 75
// version76 update mysql.columns_priv from SET('Select','Insert','Update') to SET('Select','Insert','Update','References')
version76 = 76
// version77 adds mysql.column_stats_usage table
version77 = 77
// version78 updates mysql.stats_buckets.lower_bound, mysql.stats_buckets.upper_bound and mysql.stats_histograms.last_analyze_pos from BLOB to LONGBLOB.
version78 = 78
// version79 adds the mysql.table_cache_meta table
version79 = 79
// version80 fixes the issue https://github.com/pingcap/tidb/issues/25422.
// If the TiDB upgrading from the 4.x to a newer version, we keep the tidb_analyze_version to 1.
version80 = 80
// version81 insert "tidb_enable_index_merge|off" to mysql.GLOBAL_VARIABLES if there is no tidb_enable_index_merge.
// This will only happens when we upgrade a cluster before 4.0.0 to 4.0.0+.
version81 = 81
// version82 adds the mysql.analyze_options table
version82 = 82
// version83 adds the tables mysql.stats_history
version83 = 83
// version84 adds the tables mysql.stats_meta_history
version84 = 84
// version85 updates bindings with status 'using' in mysql.bind_info table to 'enabled' status
version85 = 85
// version86 update mysql.tables_priv from SET('Select','Insert','Update') to SET('Select','Insert','Update','References').
version86 = 86
// version87 adds the mysql.analyze_jobs table
version87 = 87
// version88 fixes the issue https://github.com/pingcap/tidb/issues/33650.
version88 = 88
// version89 adds the tables mysql.advisory_locks
version89 = 89
// version90 converts enable-batch-dml, mem-quota-query, query-log-max-len, committer-concurrency, run-auto-analyze, and oom-action to a sysvar
version90 = 90
// version91 converts prepared-plan-cache to sysvars
version91 = 91
// version92 for concurrent ddl.
version92 = 92
// version93 converts oom-use-tmp-storage to a sysvar
version93 = 93
version94 = 94
// version95 add a column `User_attributes` to `mysql.user`
version95 = 95
// version97 sets tidb_opt_range_max_size to 0 when a cluster upgrades from some version lower than v6.4.0 to v6.4.0+.
// It promises the compatibility of building ranges behavior.
version97 = 97
// version98 add a column `Token_issuer` to `mysql.user`
version98 = 98
version99 = 99
// version100 converts server-memory-quota to a sysvar
version100 = 100
// version101 add mysql.plan_replayer_status table
version101 = 101
// version102 add mysql.plan_replayer_task table
version102 = 102
// version103 adds the tables mysql.stats_table_locked
version103 = 103
// version104 add `sql_digest` and `plan_digest` to `bind_info`
version104 = 104
// version105 insert "tidb_cost_model_version|1" to mysql.GLOBAL_VARIABLES if there is no tidb_cost_model_version.
// This will only happens when we upgrade a cluster before 6.0.
version105 = 105
// version106 add mysql.password_history, and Password_reuse_history, Password_reuse_time into mysql.user.
version106 = 106
// version107 add columns related to password expiration into mysql.user
version107 = 107
// version108 adds the table tidb_ttl_table_status
version108 = 108
// version109 sets tidb_enable_gc_aware_memory_track to off when a cluster upgrades from some version lower than v6.5.0.
version109 = 109
// ...
// [version110, version129] is the version range reserved for patches of 6.5.x
// ...
// version110 sets tidb_stats_load_pseudo_timeout to ON when a cluster upgrades from some version lower than v6.5.0.
version110 = 110
// version130 add column source to mysql.stats_meta_history
version130 = 130
// version131 adds the table tidb_ttl_task and tidb_ttl_job_history
version131 = 131
// version132 modifies the view tidb_mdl_view
version132 = 132
// version133 sets tidb_server_memory_limit to "80%"
version133 = 133
// version134 modifies the following global variables default value:
// - foreign_key_checks: off -> on
// - tidb_enable_foreign_key: off -> on
// - tidb_store_batch_size: 0 -> 4
version134 = 134
// version135 sets tidb_opt_advanced_join_hint to off when a cluster upgrades from some version lower than v7.0.
version135 = 135
// version136 prepare the tables for the distributed task.
version136 = 136
// version137 introduces some reserved resource groups
version137 = 137
// version 138 set tidb_enable_null_aware_anti_join to true
version138 = 138
// version 139 creates mysql.load_data_jobs table for LOAD DATA statement
version139 = 139
// version 140 add column task_key to mysql.tidb_global_task
version140 = 140
// version 141
// set the value of `tidb_session_plan_cache_size` to "tidb_prepared_plan_cache_size" if there is no `tidb_session_plan_cache_size`.
// update tidb_load_based_replica_read_threshold from 0 to 4
// This will only happens when we upgrade a cluster before 7.1.
version141 = 141
// version 142 insert "tidb_enable_non_prepared_plan_cache|0" to mysql.GLOBAL_VARIABLES if there is no tidb_enable_non_prepared_plan_cache.
// This will only happens when we upgrade a cluster before 6.5.
version142 = 142
// version 143 add column `error` to `mysql.tidb_global_task` and `mysql.tidb_background_subtask`
version143 = 143
// version 144 turn off `tidb_plan_cache_invalidation_on_fresh_stats`, which is introduced in 7.1-rc,
// if it's upgraded from an existing old version cluster.
version144 = 144
// version 145 to only add a version make we know when we support upgrade state.
version145 = 145
// version 146 add index for mysql.stats_meta_history and mysql.stats_history.
version146 = 146
// ...
// [version147, version166] is the version range reserved for patches of 7.1.x
// ...
// version 167 add column `step` to `mysql.tidb_background_subtask`
version167 = 167
version168 = 168
// version 169
// create table `mysql.tidb_runaway_quarantined_watch` and table `mysql.tidb_runaway_queries`
// to save runaway query records and persist runaway watch at 7.2 version.
// but due to ver171 recreate `mysql.tidb_runaway_watch`,
// no need to create table `mysql.tidb_runaway_quarantined_watch`, so delete it.
version169 = 169
version170 = 170
// version 171
// keep the tidb_server length same as instance in other tables.
version171 = 171
// version 172
// create table `mysql.tidb_runaway_watch` and table `mysql.tidb_runaway_watch_done`
// to persist runaway watch and deletion of runaway watch at 7.3.