-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
system.go
1593 lines (1509 loc) · 61.7 KB
/
system.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 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package sqlbase
import (
"fmt"
"time"
"github.com/cockroachdb/cockroach/pkg/config/zonepb"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
)
// ShouldSplitAtID determines whether a specific descriptor ID
// should be considered for a split at all. If it is a database
// or a view table descriptor, it should not be considered.
func ShouldSplitAtID(id uint32, rawDesc *roachpb.Value) bool {
var desc Descriptor
if err := rawDesc.GetProto(&desc); err != nil {
return false
}
if dbDesc := desc.GetDatabase(); dbDesc != nil {
return false
}
if tableDesc := desc.Table(rawDesc.Timestamp); tableDesc != nil {
if viewStr := tableDesc.GetViewQuery(); viewStr != "" {
return false
}
}
return true
}
// sql CREATE commands and full schema for each system table.
// These strings are *not* used at runtime, but are checked by the
// `TestSystemTableLiterals` test that compares the table generated by
// evaluating the `CREATE TABLE` statement to the descriptor literal that is
// actually used at runtime.
// These system tables are part of the system config.
const (
NamespaceTableSchema = `
CREATE TABLE system.namespace2 (
"parentID" INT8,
"parentSchemaID" INT8,
name STRING,
id INT8,
PRIMARY KEY ("parentID", "parentSchemaID", name)
);`
DescriptorTableSchema = `
CREATE TABLE system.descriptor (
id INT8 PRIMARY KEY,
descriptor BYTES
);`
UsersTableSchema = `
CREATE TABLE system.users (
username STRING PRIMARY KEY,
"hashedPassword" BYTES,
"isRole" BOOL NOT NULL DEFAULT false
);`
RoleOptionsTableSchema = `
CREATE TABLE system.role_options (
username STRING NOT NULL,
option STRING NOT NULL,
value STRING,
PRIMARY KEY (username, option),
FAMILY "primary" (username, option, value)
)`
// Zone settings per DB/Table.
ZonesTableSchema = `
CREATE TABLE system.zones (
id INT8 PRIMARY KEY,
config BYTES
);`
SettingsTableSchema = `
CREATE TABLE system.settings (
name STRING NOT NULL PRIMARY KEY,
value STRING NOT NULL,
"lastUpdated" TIMESTAMP NOT NULL DEFAULT now(),
"valueType" STRING,
FAMILY (name, value, "lastUpdated", "valueType")
);`
)
// These system tables are not part of the system config.
const (
LeaseTableSchema = `
CREATE TABLE system.lease (
"descID" INT8,
version INT8,
"nodeID" INT8,
expiration TIMESTAMP,
PRIMARY KEY ("descID", version, expiration, "nodeID")
);`
EventLogTableSchema = `
CREATE TABLE system.eventlog (
timestamp TIMESTAMP NOT NULL,
"eventType" STRING NOT NULL,
"targetID" INT8 NOT NULL,
"reportingID" INT8 NOT NULL,
info STRING,
"uniqueID" BYTES DEFAULT uuid_v4(),
PRIMARY KEY (timestamp, "uniqueID")
);`
// rangelog is currently envisioned as a wide table; many different event
// types can be recorded to the table.
RangeEventTableSchema = `
CREATE TABLE system.rangelog (
timestamp TIMESTAMP NOT NULL,
"rangeID" INT8 NOT NULL,
"storeID" INT8 NOT NULL,
"eventType" STRING NOT NULL,
"otherRangeID" INT8,
info STRING,
"uniqueID" INT8 DEFAULT unique_rowid(),
PRIMARY KEY (timestamp, "uniqueID")
);`
UITableSchema = `
CREATE TABLE system.ui (
key STRING PRIMARY KEY,
value BYTES,
"lastUpdated" TIMESTAMP NOT NULL
);`
// Note: this schema is changed in a migration (a progress column is added in
// a separate family).
JobsTableSchema = `
CREATE TABLE system.jobs (
id INT8 DEFAULT unique_rowid() PRIMARY KEY,
status STRING NOT NULL,
created TIMESTAMP NOT NULL DEFAULT now(),
payload BYTES NOT NULL,
progress BYTES,
INDEX (status, created),
FAMILY (id, status, created, payload),
FAMILY progress (progress)
);`
// web_sessions are used to track authenticated user actions over stateless
// connections, such as the cookie-based authentication used by the Admin
// UI.
// Design outlined in /docs/RFCS/web_session_login.rfc
WebSessionsTableSchema = `
CREATE TABLE system.web_sessions (
id INT8 NOT NULL DEFAULT unique_rowid() PRIMARY KEY,
"hashedSecret" BYTES NOT NULL,
username STRING NOT NULL,
"createdAt" TIMESTAMP NOT NULL DEFAULT now(),
"expiresAt" TIMESTAMP NOT NULL,
"revokedAt" TIMESTAMP,
"lastUsedAt" TIMESTAMP NOT NULL DEFAULT now(),
"auditInfo" STRING,
INDEX ("expiresAt"),
INDEX ("createdAt"),
FAMILY (id, "hashedSecret", username, "createdAt", "expiresAt", "revokedAt", "lastUsedAt", "auditInfo")
);`
// table_statistics is used to track statistics collected about individual columns
// or groups of columns from every table in the database. Each row contains the
// number of distinct values of the column group and (optionally) a histogram if there
// is only one column in columnIDs.
//
// Design outlined in /docs/RFCS/20170908_sql_optimizer_statistics.md
TableStatisticsTableSchema = `
CREATE TABLE system.table_statistics (
"tableID" INT8 NOT NULL,
"statisticID" INT8 NOT NULL DEFAULT unique_rowid(),
name STRING,
"columnIDs" INT8[] NOT NULL,
"createdAt" TIMESTAMP NOT NULL DEFAULT now(),
"rowCount" INT8 NOT NULL,
"distinctCount" INT8 NOT NULL,
"nullCount" INT8 NOT NULL,
histogram BYTES,
PRIMARY KEY ("tableID", "statisticID"),
FAMILY ("tableID", "statisticID", name, "columnIDs", "createdAt", "rowCount", "distinctCount", "nullCount", histogram)
);`
// locations are used to map a locality specified by a node to geographic
// latitude, longitude coordinates, specified as degrees.
LocationsTableSchema = `
CREATE TABLE system.locations (
"localityKey" STRING,
"localityValue" STRING,
latitude DECIMAL(18,15) NOT NULL,
longitude DECIMAL(18,15) NOT NULL,
PRIMARY KEY ("localityKey", "localityValue"),
FAMILY ("localityKey", "localityValue", latitude, longitude)
);`
// role_members stores relationships between roles (role->role and role->user).
RoleMembersTableSchema = `
CREATE TABLE system.role_members (
"role" STRING NOT NULL,
"member" STRING NOT NULL,
"isAdmin" BOOL NOT NULL,
PRIMARY KEY ("role", "member"),
INDEX ("role"),
INDEX ("member")
);`
// comments stores comments(database, table, column...).
CommentsTableSchema = `
CREATE TABLE system.comments (
type INT NOT NULL, -- type of object, to distinguish between db, table, column and others
object_id INT NOT NULL, -- object ID, this will be usually db/table desc ID
sub_id INT NOT NULL, -- sub ID for column or indexes inside table, 0 for pure table
comment STRING NOT NULL, -- the comment
PRIMARY KEY (type, object_id, sub_id)
);`
// protected_ts_meta stores a single row of metadata for the protectedts
// subsystem.
ProtectedTimestampsMetaTableSchema = `
CREATE TABLE system.protected_ts_meta (
singleton BOOL NOT NULL PRIMARY KEY DEFAULT (true),
version INT8 NOT NULL,
num_records INT8 NOT NULL,
num_spans INT8 NOT NULL,
total_bytes INT8 NOT NULL,
CONSTRAINT check_singleton CHECK (singleton),
FAMILY "primary" (singleton, version, num_records, num_spans, total_bytes)
);`
ProtectedTimestampsRecordsTableSchema = `
CREATE TABLE system.protected_ts_records (
id UUID NOT NULL PRIMARY KEY,
ts DECIMAL NOT NULL,
meta_type STRING NOT NULL,
meta BYTES,
num_spans INT8 NOT NULL, -- num spans is important to know how to decode spans
spans BYTES NOT NULL,
verified BOOL NOT NULL DEFAULT (false),
FAMILY "primary" (id, ts, meta_type, meta, num_spans, spans, verified)
);`
StatementBundleChunksTableSchema = `
CREATE TABLE system.statement_bundle_chunks (
id INT8 PRIMARY KEY DEFAULT unique_rowid(),
description STRING,
data BYTES NOT NULL,
FAMILY "primary" (id, description, data)
);`
StatementDiagnosticsRequestsTableSchema = `
CREATE TABLE system.statement_diagnostics_requests(
id INT8 DEFAULT unique_rowid() PRIMARY KEY NOT NULL,
completed BOOL NOT NULL DEFAULT FALSE,
statement_fingerprint STRING NOT NULL,
statement_diagnostics_id INT8,
requested_at TIMESTAMPTZ NOT NULL,
INDEX completed_idx (completed, id) STORING (statement_fingerprint),
FAMILY "primary" (id, completed, statement_fingerprint, statement_diagnostics_id, requested_at)
);`
StatementDiagnosticsTableSchema = `
create table system.statement_diagnostics(
id INT8 DEFAULT unique_rowid() PRIMARY KEY NOT NULL,
statement_fingerprint STRING NOT NULL,
statement STRING NOT NULL,
collected_at TIMESTAMPTZ NOT NULL,
trace JSONB,
bundle_chunks INT ARRAY,
error STRING,
FAMILY "primary" (id, statement_fingerprint, statement, collected_at, trace, bundle_chunks, error)
);`
)
func pk(name string) IndexDescriptor {
return IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{name},
ColumnDirections: singleASC,
ColumnIDs: singleID1,
Version: SecondaryIndexFamilyFormatVersion,
}
}
// SystemAllowedPrivileges describes the allowable privilege list for each
// system object. Super users (root and admin) must have exactly the specified privileges,
// other users must not exceed the specified privileges.
var SystemAllowedPrivileges = map[ID]privilege.List{
keys.SystemDatabaseID: privilege.ReadData,
keys.NamespaceTableID: privilege.ReadData,
keys.DeprecatedNamespaceTableID: privilege.ReadData,
keys.DescriptorTableID: privilege.ReadData,
keys.UsersTableID: privilege.ReadWriteData,
keys.RoleOptionsTableID: privilege.ReadWriteData,
keys.ZonesTableID: privilege.ReadWriteData,
// We eventually want to migrate the table to appear read-only to force the
// the use of a validating, logging accessor, so we'll go ahead and tolerate
// read-only privs to make that migration possible later.
keys.SettingsTableID: privilege.ReadWriteData,
keys.LeaseTableID: privilege.ReadWriteData,
keys.EventLogTableID: privilege.ReadWriteData,
keys.RangeEventTableID: privilege.ReadWriteData,
keys.UITableID: privilege.ReadWriteData,
// IMPORTANT: CREATE|DROP|ALL privileges should always be denied or database
// users will be able to modify system tables' schemas at will. CREATE and
// DROP privileges are allowed on the above system tables for backwards
// compatibility reasons only!
keys.JobsTableID: privilege.ReadWriteData,
keys.WebSessionsTableID: privilege.ReadWriteData,
keys.TableStatisticsTableID: privilege.ReadWriteData,
keys.LocationsTableID: privilege.ReadWriteData,
keys.RoleMembersTableID: privilege.ReadWriteData,
keys.CommentsTableID: privilege.ReadWriteData,
keys.ReplicationConstraintStatsTableID: privilege.ReadWriteData,
keys.ReplicationCriticalLocalitiesTableID: privilege.ReadWriteData,
keys.ReplicationStatsTableID: privilege.ReadWriteData,
keys.ReportsMetaTableID: privilege.ReadWriteData,
keys.ProtectedTimestampsMetaTableID: privilege.ReadData,
keys.ProtectedTimestampsRecordsTableID: privilege.ReadData,
keys.StatementBundleChunksTableID: privilege.ReadWriteData,
keys.StatementDiagnosticsRequestsTableID: privilege.ReadWriteData,
keys.StatementDiagnosticsTableID: privilege.ReadWriteData,
}
// Helpers used to make some of the TableDescriptor literals below more concise.
var (
singleASC = []IndexDescriptor_Direction{IndexDescriptor_ASC}
singleID1 = []ColumnID{1}
)
// MakeSystemDatabaseDesc constructs a copy of the system database
// descriptor.
func MakeSystemDatabaseDesc() DatabaseDescriptor {
return DatabaseDescriptor{
Name: "system",
ID: keys.SystemDatabaseID,
// Assign max privileges to root user.
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.SystemDatabaseID]),
}
}
// These system config TableDescriptor literals should match the descriptor
// that would be produced by evaluating one of the above `CREATE TABLE`
// statements. See the `TestSystemTableLiterals` which checks that they do
// indeed match, and has suggestions on writing and maintaining them.
var (
// SystemDB is the descriptor for the system database.
SystemDB = MakeSystemDatabaseDesc()
// NamespaceTableName is "namespace", which is always and forever the
// user-visible name of the system.namespace table. Tautological, but
// important.
NamespaceTableName = "namespace"
// DeprecatedNamespaceTable is the descriptor for the deprecated namespace table.
DeprecatedNamespaceTable = TableDescriptor{
Name: NamespaceTableName,
ID: keys.DeprecatedNamespaceTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "parentID", ID: 1, LogicalColumnID: 1, Type: *types.Int},
{Name: "name", ID: 2, LogicalColumnID: 2, Type: *types.String},
{Name: "id", ID: 3, LogicalColumnID: 3, Type: *types.Int, Nullable: true},
},
NextColumnID: 4,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"parentID", "name"}, ColumnIDs: []ColumnID{1, 2}},
{Name: "fam_3_id", ID: 3, ColumnNames: []string{"id"}, ColumnIDs: []ColumnID{3}, DefaultColumnID: 3},
},
NextFamilyID: 4,
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"parentID", "name"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 2},
Version: SecondaryIndexFamilyFormatVersion,
},
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.DeprecatedNamespaceTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// NamespaceTable is the descriptor for the namespace table. Note that this
// table should only be written to via KV puts, not via the SQL layer. Some
// code assumes that it only has KV entries for column family 4, not the
// "sentinel" column family 0 which would be written by SQL.
//
// Note that the Descriptor.Name of this table is not "namespace", but
// something else. This is because, in 20.1, we moved the representation of
// namespaces to a new place, and for various reasons, we can't have two
// descriptors with the same Name at once.
//
// TODO(solon): in 20.2, we should change the Name of this descriptor
// back to "namespace".
NamespaceTable = TableDescriptor{
Name: "namespace2",
ID: keys.NamespaceTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "parentID", ID: 1, LogicalColumnID: 1, Type: *types.Int},
{Name: "parentSchemaID", ID: 2, LogicalColumnID: 2, Type: *types.Int},
{Name: "name", ID: 3, LogicalColumnID: 3, Type: *types.String},
{Name: "id", ID: 4, LogicalColumnID: 4, Type: *types.Int, Nullable: true},
},
NextColumnID: 5,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"parentID", "parentSchemaID", "name"}, ColumnIDs: []ColumnID{1, 2, 3}},
{Name: "fam_4_id", ID: 4, ColumnNames: []string{"id"}, ColumnIDs: []ColumnID{4}, DefaultColumnID: 4},
},
NextFamilyID: 5,
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"parentID", "parentSchemaID", "name"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 2, 3},
Version: SecondaryIndexFamilyFormatVersion,
},
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.DeprecatedNamespaceTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// DescriptorTable is the descriptor for the descriptor table.
DescriptorTable = TableDescriptor{
Name: "descriptor",
ID: keys.DescriptorTableID,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.DescriptorTableID]),
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "id", ID: 1, LogicalColumnID: 1, Type: *types.Int},
{Name: "descriptor", ID: keys.DescriptorTableDescriptorColID,
LogicalColumnID: keys.DescriptorTableDescriptorColID, Type: *types.Bytes, Nullable: true},
},
NextColumnID: 3,
Families: []ColumnFamilyDescriptor{
// The id of the first col fam is hardcoded in keys.MakeDescMetadataKey().
{Name: "primary", ID: 0, ColumnNames: []string{"id"}, ColumnIDs: singleID1},
{Name: "fam_2_descriptor", ID: keys.DescriptorTableDescriptorColFamID,
ColumnNames: []string{"descriptor"},
ColumnIDs: []ColumnID{keys.DescriptorTableDescriptorColID}, DefaultColumnID: keys.DescriptorTableDescriptorColID},
},
PrimaryIndex: pk("id"),
NextFamilyID: 3,
NextIndexID: 2,
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
falseBoolString = "false"
trueBoolString = "true"
// UsersTable is the descriptor for the users table.
UsersTable = TableDescriptor{
Name: "users",
ID: keys.UsersTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "username", ID: 1, LogicalColumnID: 1, Type: *types.String},
{Name: "hashedPassword", ID: 2, LogicalColumnID: 2, Type: *types.Bytes, Nullable: true},
{Name: "isRole", ID: 3, LogicalColumnID: 3, Type: *types.Bool, DefaultExpr: &falseBoolString},
},
NextColumnID: 4,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"username"}, ColumnIDs: singleID1},
{Name: "fam_2_hashedPassword", ID: 2, ColumnNames: []string{"hashedPassword"}, ColumnIDs: []ColumnID{2}, DefaultColumnID: 2},
{Name: "fam_3_isRole", ID: 3, ColumnNames: []string{"isRole"}, ColumnIDs: []ColumnID{3}, DefaultColumnID: 3},
},
PrimaryIndex: pk("username"),
NextFamilyID: 4,
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.UsersTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// ZonesTable is the descriptor for the zones table.
ZonesTable = TableDescriptor{
Name: "zones",
ID: keys.ZonesTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "id", ID: 1, LogicalColumnID: 1, Type: *types.Int},
{Name: "config", ID: keys.ZonesTableConfigColumnID,
LogicalColumnID: keys.ZonesTableConfigColumnID, Type: *types.Bytes, Nullable: true},
},
NextColumnID: 3,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"id"}, ColumnIDs: singleID1},
{Name: "fam_2_config", ID: keys.ZonesTableConfigColFamID, ColumnNames: []string{"config"},
ColumnIDs: []ColumnID{keys.ZonesTableConfigColumnID}, DefaultColumnID: keys.ZonesTableConfigColumnID},
},
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: keys.ZonesTablePrimaryIndexID,
Unique: true,
ColumnNames: []string{"id"},
ColumnDirections: singleASC,
ColumnIDs: []ColumnID{keys.ZonesTablePrimaryIndexID},
Version: SecondaryIndexFamilyFormatVersion,
},
NextFamilyID: 3,
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.ZonesTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// SettingsTable is the descriptor for the settings table.
// It contains all cluster settings for which a value has been set.
SettingsTable = TableDescriptor{
Name: "settings",
ID: keys.SettingsTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "name", ID: 1, LogicalColumnID: 1, Type: *types.String},
{Name: "value", ID: 2, LogicalColumnID: 2, Type: *types.String},
{Name: "lastUpdated", ID: 3, LogicalColumnID: 3, Type: *types.Timestamp, DefaultExpr: &nowString},
{Name: "valueType", ID: 4, LogicalColumnID: 4, Type: *types.String, Nullable: true},
},
NextColumnID: 5,
Families: []ColumnFamilyDescriptor{
{
Name: "fam_0_name_value_lastUpdated_valueType",
ID: 0,
ColumnNames: []string{"name", "value", "lastUpdated", "valueType"},
ColumnIDs: []ColumnID{1, 2, 3, 4},
},
},
NextFamilyID: 1,
PrimaryIndex: pk("name"),
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.SettingsTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
)
// These system TableDescriptor literals should match the descriptor that
// would be produced by evaluating one of the above `CREATE TABLE` statements
// for system tables that are not system config tables. See the
// `TestSystemTableLiterals` which checks that they do indeed match, and has
// suggestions on writing and maintaining them.
var (
// LeaseTable is the descriptor for the leases table.
LeaseTable = TableDescriptor{
Name: "lease",
ID: keys.LeaseTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "descID", ID: 1, LogicalColumnID: 1, Type: *types.Int},
{Name: "version", ID: 2, LogicalColumnID: 2, Type: *types.Int},
{Name: "nodeID", ID: 3, LogicalColumnID: 3, Type: *types.Int},
{Name: "expiration", ID: 4, LogicalColumnID: 4, Type: *types.Timestamp},
},
NextColumnID: 5,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"descID", "version", "nodeID", "expiration"}, ColumnIDs: []ColumnID{1, 2, 3, 4}},
},
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"descID", "version", "expiration", "nodeID"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC, IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 2, 4, 3},
Version: SecondaryIndexFamilyFormatVersion,
},
NextFamilyID: 1,
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.LeaseTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
uuidV4String = "uuid_v4()"
// EventLogTable is the descriptor for the event log table.
EventLogTable = TableDescriptor{
Name: "eventlog",
ID: keys.EventLogTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "timestamp", ID: 1, LogicalColumnID: 1, Type: *types.Timestamp},
{Name: "eventType", ID: 2, LogicalColumnID: 2, Type: *types.String},
{Name: "targetID", ID: 3, LogicalColumnID: 3, Type: *types.Int},
{Name: "reportingID", ID: 4, LogicalColumnID: 4, Type: *types.Int},
{Name: "info", ID: 5, LogicalColumnID: 5, Type: *types.String, Nullable: true},
{Name: "uniqueID", ID: 6, LogicalColumnID: 6, Type: *types.Bytes, DefaultExpr: &uuidV4String},
},
NextColumnID: 7,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"timestamp", "uniqueID"}, ColumnIDs: []ColumnID{1, 6}},
{Name: "fam_2_eventType", ID: 2, ColumnNames: []string{"eventType"}, ColumnIDs: []ColumnID{2}, DefaultColumnID: 2},
{Name: "fam_3_targetID", ID: 3, ColumnNames: []string{"targetID"}, ColumnIDs: []ColumnID{3}, DefaultColumnID: 3},
{Name: "fam_4_reportingID", ID: 4, ColumnNames: []string{"reportingID"}, ColumnIDs: []ColumnID{4}, DefaultColumnID: 4},
{Name: "fam_5_info", ID: 5, ColumnNames: []string{"info"}, ColumnIDs: []ColumnID{5}, DefaultColumnID: 5},
},
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"timestamp", "uniqueID"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 6},
Version: SecondaryIndexFamilyFormatVersion,
},
NextFamilyID: 6,
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.EventLogTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
uniqueRowIDString = "unique_rowid()"
// RangeEventTable is the descriptor for the range log table.
RangeEventTable = TableDescriptor{
Name: "rangelog",
ID: keys.RangeEventTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "timestamp", ID: 1, LogicalColumnID: 1, Type: *types.Timestamp},
{Name: "rangeID", ID: 2, LogicalColumnID: 2, Type: *types.Int},
{Name: "storeID", ID: 3, LogicalColumnID: 3, Type: *types.Int},
{Name: "eventType", ID: 4, LogicalColumnID: 4, Type: *types.String},
{Name: "otherRangeID", ID: 5, LogicalColumnID: 5, Type: *types.Int, Nullable: true},
{Name: "info", ID: 6, LogicalColumnID: 6, Type: *types.String, Nullable: true},
{Name: "uniqueID", ID: 7, LogicalColumnID: 7, Type: *types.Int, DefaultExpr: &uniqueRowIDString},
},
NextColumnID: 8,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"timestamp", "uniqueID"}, ColumnIDs: []ColumnID{1, 7}},
{Name: "fam_2_rangeID", ID: 2, ColumnNames: []string{"rangeID"}, ColumnIDs: []ColumnID{2}, DefaultColumnID: 2},
{Name: "fam_3_storeID", ID: 3, ColumnNames: []string{"storeID"}, ColumnIDs: []ColumnID{3}, DefaultColumnID: 3},
{Name: "fam_4_eventType", ID: 4, ColumnNames: []string{"eventType"}, ColumnIDs: []ColumnID{4}, DefaultColumnID: 4},
{Name: "fam_5_otherRangeID", ID: 5, ColumnNames: []string{"otherRangeID"}, ColumnIDs: []ColumnID{5}, DefaultColumnID: 5},
{Name: "fam_6_info", ID: 6, ColumnNames: []string{"info"}, ColumnIDs: []ColumnID{6}, DefaultColumnID: 6},
},
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"timestamp", "uniqueID"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 7},
Version: SecondaryIndexFamilyFormatVersion,
},
NextFamilyID: 7,
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.RangeEventTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// UITable is the descriptor for the ui table.
UITable = TableDescriptor{
Name: "ui",
ID: keys.UITableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "key", ID: 1, LogicalColumnID: 1, Type: *types.String},
{Name: "value", ID: 2, LogicalColumnID: 2, Type: *types.Bytes, Nullable: true},
{Name: "lastUpdated", ID: 3, LogicalColumnID: 3, Type: *types.Timestamp},
},
NextColumnID: 4,
Families: []ColumnFamilyDescriptor{
{Name: "primary", ID: 0, ColumnNames: []string{"key"}, ColumnIDs: singleID1},
{Name: "fam_2_value", ID: 2, ColumnNames: []string{"value"}, ColumnIDs: []ColumnID{2}, DefaultColumnID: 2},
{Name: "fam_3_lastUpdated", ID: 3, ColumnNames: []string{"lastUpdated"}, ColumnIDs: []ColumnID{3}, DefaultColumnID: 3},
},
NextFamilyID: 4,
PrimaryIndex: pk("key"),
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.UITableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
nowString = "now():::TIMESTAMP"
// JobsTable is the descriptor for the jobs table.
JobsTable = TableDescriptor{
Name: "jobs",
ID: keys.JobsTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "id", ID: 1, LogicalColumnID: 1, Type: *types.Int, DefaultExpr: &uniqueRowIDString},
{Name: "status", ID: 2, LogicalColumnID: 2, Type: *types.String},
{Name: "created", ID: 3, LogicalColumnID: 3, Type: *types.Timestamp, DefaultExpr: &nowString},
{Name: "payload", ID: 4, LogicalColumnID: 4, Type: *types.Bytes},
{Name: "progress", ID: 5, LogicalColumnID: 5, Type: *types.Bytes, Nullable: true},
},
NextColumnID: 6,
Families: []ColumnFamilyDescriptor{
{
Name: "fam_0_id_status_created_payload",
ID: 0,
ColumnNames: []string{"id", "status", "created", "payload"},
ColumnIDs: []ColumnID{1, 2, 3, 4},
},
{
Name: "progress",
ID: 1,
ColumnNames: []string{"progress"},
ColumnIDs: []ColumnID{5},
DefaultColumnID: 5,
},
},
NextFamilyID: 2,
PrimaryIndex: pk("id"),
Indexes: []IndexDescriptor{
{
Name: "jobs_status_created_idx",
ID: 2,
Unique: false,
ColumnNames: []string{"status", "created"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{2, 3},
ExtraColumnIDs: []ColumnID{1},
Version: SecondaryIndexFamilyFormatVersion,
},
},
NextIndexID: 3,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.JobsTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// WebSessions table to authenticate sessions over stateless connections.
WebSessionsTable = TableDescriptor{
Name: "web_sessions",
ID: keys.WebSessionsTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "id", ID: 1, LogicalColumnID: 1, Type: *types.Int, DefaultExpr: &uniqueRowIDString},
{Name: "hashedSecret", ID: 2, LogicalColumnID: 2, Type: *types.Bytes},
{Name: "username", ID: 3, LogicalColumnID: 3, Type: *types.String},
{Name: "createdAt", ID: 4, LogicalColumnID: 4, Type: *types.Timestamp, DefaultExpr: &nowString},
{Name: "expiresAt", ID: 5, LogicalColumnID: 5, Type: *types.Timestamp},
{Name: "revokedAt", ID: 6, LogicalColumnID: 6, Type: *types.Timestamp, Nullable: true},
{Name: "lastUsedAt", ID: 7, LogicalColumnID: 7, Type: *types.Timestamp, DefaultExpr: &nowString},
{Name: "auditInfo", ID: 8, LogicalColumnID: 8, Type: *types.String, Nullable: true},
},
NextColumnID: 9,
Families: []ColumnFamilyDescriptor{
{
Name: "fam_0_id_hashedSecret_username_createdAt_expiresAt_revokedAt_lastUsedAt_auditInfo",
ID: 0,
ColumnNames: []string{
"id",
"hashedSecret",
"username",
"createdAt",
"expiresAt",
"revokedAt",
"lastUsedAt",
"auditInfo",
},
ColumnIDs: []ColumnID{1, 2, 3, 4, 5, 6, 7, 8},
},
},
NextFamilyID: 1,
PrimaryIndex: pk("id"),
Indexes: []IndexDescriptor{
{
Name: "web_sessions_expiresAt_idx",
ID: 2,
Unique: false,
ColumnNames: []string{"expiresAt"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC},
ColumnIDs: []ColumnID{5},
ExtraColumnIDs: []ColumnID{1},
Version: SecondaryIndexFamilyFormatVersion,
},
{
Name: "web_sessions_createdAt_idx",
ID: 3,
Unique: false,
ColumnNames: []string{"createdAt"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC},
ColumnIDs: []ColumnID{4},
ExtraColumnIDs: []ColumnID{1},
Version: SecondaryIndexFamilyFormatVersion,
},
},
NextIndexID: 4,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.WebSessionsTableID]),
NextMutationID: 1,
FormatVersion: 3,
}
// TableStatistics table to hold statistics about columns and column groups.
TableStatisticsTable = TableDescriptor{
Name: "table_statistics",
ID: keys.TableStatisticsTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "tableID", ID: 1, LogicalColumnID: 1, Type: *types.Int},
{Name: "statisticID", ID: 2, LogicalColumnID: 2, Type: *types.Int, DefaultExpr: &uniqueRowIDString},
{Name: "name", ID: 3, LogicalColumnID: 3, Type: *types.String, Nullable: true},
{Name: "columnIDs", ID: 4, LogicalColumnID: 4, Type: *types.IntArray},
{Name: "createdAt", ID: 5, LogicalColumnID: 5, Type: *types.Timestamp, DefaultExpr: &nowString},
{Name: "rowCount", ID: 6, LogicalColumnID: 6, Type: *types.Int},
{Name: "distinctCount", ID: 7, LogicalColumnID: 7, Type: *types.Int},
{Name: "nullCount", ID: 8, LogicalColumnID: 8, Type: *types.Int},
{Name: "histogram", ID: 9, LogicalColumnID: 9, Type: *types.Bytes, Nullable: true},
},
NextColumnID: 10,
Families: []ColumnFamilyDescriptor{
{
Name: "fam_0_tableID_statisticID_name_columnIDs_createdAt_rowCount_distinctCount_nullCount_histogram",
ID: 0,
ColumnNames: []string{
"tableID",
"statisticID",
"name",
"columnIDs",
"createdAt",
"rowCount",
"distinctCount",
"nullCount",
"histogram",
},
ColumnIDs: []ColumnID{1, 2, 3, 4, 5, 6, 7, 8, 9},
},
},
NextFamilyID: 1,
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"tableID", "statisticID"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 2},
Version: SecondaryIndexFamilyFormatVersion,
},
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.TableStatisticsTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
latLonDecimal = types.MakeDecimal(18, 15)
// LocationsTable is the descriptor for the locations table.
LocationsTable = TableDescriptor{
Name: "locations",
ID: keys.LocationsTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "localityKey", ID: 1, LogicalColumnID: 1, Type: *types.String},
{Name: "localityValue", ID: 2, LogicalColumnID: 2, Type: *types.String},
{Name: "latitude", ID: 3, LogicalColumnID: 3, Type: *latLonDecimal},
{Name: "longitude", ID: 4, LogicalColumnID: 4, Type: *latLonDecimal},
},
NextColumnID: 5,
Families: []ColumnFamilyDescriptor{
{
Name: "fam_0_localityKey_localityValue_latitude_longitude",
ID: 0,
ColumnNames: []string{"localityKey", "localityValue", "latitude", "longitude"},
ColumnIDs: []ColumnID{1, 2, 3, 4},
},
},
NextFamilyID: 1,
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"localityKey", "localityValue"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 2},
Version: SecondaryIndexFamilyFormatVersion,
},
NextIndexID: 2,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.LocationsTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// RoleMembersTable is the descriptor for the role_members table.
RoleMembersTable = TableDescriptor{
Name: "role_members",
ID: keys.RoleMembersTableID,
ParentID: keys.SystemDatabaseID,
UnexposedParentSchemaID: keys.PublicSchemaID,
Version: 1,
Columns: []ColumnDescriptor{
{Name: "role", ID: 1, LogicalColumnID: 1, Type: *types.String},
{Name: "member", ID: 2, LogicalColumnID: 2, Type: *types.String},
{Name: "isAdmin", ID: 3, LogicalColumnID: 3, Type: *types.Bool},
},
NextColumnID: 4,
Families: []ColumnFamilyDescriptor{
{
Name: "primary",
ID: 0,
ColumnNames: []string{"role", "member"},
ColumnIDs: []ColumnID{1, 2},
},
{
Name: "fam_3_isAdmin",
ID: 3,
ColumnNames: []string{"isAdmin"},
ColumnIDs: []ColumnID{3},
DefaultColumnID: 3,
},
},
NextFamilyID: 4,
PrimaryIndex: IndexDescriptor{
Name: "primary",
ID: 1,
Unique: true,
ColumnNames: []string{"role", "member"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC, IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1, 2},
Version: SecondaryIndexFamilyFormatVersion,
},
Indexes: []IndexDescriptor{
{
Name: "role_members_role_idx",
ID: 2,
Unique: false,
ColumnNames: []string{"role"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC},
ColumnIDs: []ColumnID{1},
ExtraColumnIDs: []ColumnID{2},
Version: SecondaryIndexFamilyFormatVersion,
},
{
Name: "role_members_member_idx",
ID: 3,
Unique: false,
ColumnNames: []string{"member"},
ColumnDirections: []IndexDescriptor_Direction{IndexDescriptor_ASC},
ColumnIDs: []ColumnID{2},
ExtraColumnIDs: []ColumnID{1},
Version: SecondaryIndexFamilyFormatVersion,
},
},
NextIndexID: 4,
Privileges: NewCustomSuperuserPrivilegeDescriptor(SystemAllowedPrivileges[keys.RoleMembersTableID]),
FormatVersion: InterleavedFormatVersion,
NextMutationID: 1,
}
// CommentsTable is the descriptor for the comments table.
CommentsTable = TableDescriptor{