-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathstructured.proto
1562 lines (1376 loc) · 74.9 KB
/
structured.proto
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.
// Cannot be proto3 because we use nullable primitives.
syntax = "proto2";
package cockroach.sql.sqlbase;
option go_package = "descpb";
import "config/zonepb/zone.proto";
import "util/hlc/timestamp.proto";
import "sql/catalog/catpb/catalog.proto";
import "sql/catalog/catpb/privilege.proto";
import "sql/schemachanger/scpb/scpb.proto";
import "sql/types/types.proto";
import "geo/geoindex/config.proto";
import "gogoproto/gogo.proto";
enum ConstraintValidity {
// The constraint is valid for all rows.
Validated = 0;
// The constraint has not yet been validated for all rows (and will not be
// validated until VALIDATE CONSTRAINT is used).
Unvalidated = 1;
// The constraint was just added, but the validation for existing rows is not
// yet complete. If validation fails, the constraint will be dropped.
Validating = 2;
// The constraint is being dropped in the schema changer.
Dropping = 3;
}
// ForeignKeyReference is deprecated, replaced by ForeignKeyConstraint in v19.2
// (though it is still possible for table descriptors on disk to have
// ForeignKeyReferences).
//
// It is still used to describe interleavings (see
// IndexDescriptor.InterleavedBy), for which it is a poor choice: only the Table
// and Index fields are used, and the interleaving has nothing to do with
// traditional foreign key references.
message ForeignKeyReference {
option (gogoproto.equal) = true;
// Match is the algorithm used to compare composite keys.
enum Match {
option (gogoproto.goproto_enum_stringer) = false;
SIMPLE = 0;
FULL = 1;
PARTIAL = 2; // Note: not actually supported, but we reserve the value for future use.
}
optional uint32 table = 1 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ID"];
optional uint32 index = 2 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID"];
optional string name = 3 [(gogoproto.nullable) = false];
optional ConstraintValidity validity = 4 [(gogoproto.nullable) = false];
// If this FK only uses a prefix of the columns in its index, we record how
// many to avoid spuriously counting the additional cols as used by this FK.
optional int32 shared_prefix_len = 5 [(gogoproto.nullable) = false];
optional cockroach.sql.catalog.catpb.ForeignKeyAction on_delete = 6 [(gogoproto.nullable) = false];
optional cockroach.sql.catalog.catpb.ForeignKeyAction on_update = 7 [(gogoproto.nullable) = false];
// This is only important for composite keys. For all prior matches before
// the addition of this value, MATCH SIMPLE will be used.
optional Match match = 8 [(gogoproto.nullable) = false];
}
// ForeignKeyConstraint is the new (as of 19.2 and VersionTopLevelForeignKeys)
// representation for foreign keys. It's stored on the TableDescriptor and is
// designed to be agnostic to which indexes are available on both the origin
// and referenced tables, so that the optimizer can have full freedom to choose
// the best possible index to satisfy constraint checks at runtime.
message ForeignKeyConstraint {
option (gogoproto.equal) = true;
optional uint32 origin_table_id = 1 [(gogoproto.nullable) = false,
(gogoproto.customname) = "OriginTableID",
(gogoproto.casttype) = "ID"];
repeated uint32 origin_column_ids = 2 [(gogoproto.customname) = "OriginColumnIDs",
(gogoproto.casttype) = "ColumnID"];
repeated uint32 referenced_column_ids = 3 [(gogoproto.customname) = "ReferencedColumnIDs",
(gogoproto.casttype) = "ColumnID"];
optional uint32 referenced_table_id = 4 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ReferencedTableID",
(gogoproto.casttype) = "ID"];
optional string name = 5 [(gogoproto.nullable) = false];
optional ConstraintValidity validity = 6 [(gogoproto.nullable) = false];
optional cockroach.sql.catalog.catpb.ForeignKeyAction on_delete = 7 [(gogoproto.nullable) = false];
optional cockroach.sql.catalog.catpb.ForeignKeyAction on_update = 8 [(gogoproto.nullable) = false];
// This is only important for composite keys. For all prior matches before
// the addition of this value, MATCH SIMPLE will be used.
optional ForeignKeyReference.Match match = 9 [(gogoproto.nullable) = false];
// These fields were used for foreign keys until 20.1.
reserved 10, 11, 12, 13;
// Used within the table descriptor to uniquely identify individual
// constraints.
optional uint32 constraint_id = 14 [(gogoproto.customname) = "ConstraintID",
(gogoproto.casttype) = "ConstraintID", (gogoproto.nullable) = false];
}
// UniqueWithoutIndexConstraint is the representation of a unique constraint
// that is not enforced by an index. It is stored on the TableDescriptor.
message UniqueWithoutIndexConstraint {
option (gogoproto.equal) = true;
optional uint32 table_id = 1 [(gogoproto.nullable) = false,
(gogoproto.customname) = "TableID",
(gogoproto.casttype) = "ID"];
repeated uint32 column_ids = 2 [(gogoproto.customname) = "ColumnIDs",
(gogoproto.casttype) = "ColumnID"];
optional string name = 3 [(gogoproto.nullable) = false];
optional ConstraintValidity validity = 4 [(gogoproto.nullable) = false];
// Predicate, if it's not empty, indicates that the constraint is a partial
// unique constraint with Predicate as the expression. Columns are referred to
// in the expression by their name.
optional string predicate = 5 [(gogoproto.nullable) = false];
// Used within the table descriptor to uniquely identify individual
// constraints.
optional uint32 constraint_id = 6 [(gogoproto.customname) = "ConstraintID",
(gogoproto.casttype) = "ConstraintID", (gogoproto.nullable) = false];
}
message ColumnDescriptor {
option (gogoproto.equal) = true;
optional string name = 1 [(gogoproto.nullable) = false];
optional uint32 id = 2 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ID",
(gogoproto.casttype) = "ColumnID"];
optional sql.sem.types.T type = 3;
optional bool nullable = 4 [(gogoproto.nullable) = false];
reserved 8;
// Default expression to use to populate the column on insert if no
// value is provided. Note that it is not correct to use DefaultExpr
// as output to display to a user. User defined types within DefaultExpr
// have been serialized in a internal format. Instead, use one of the
// schemaexpr.FormatExpr* functions.
optional string default_expr = 5;
reserved 9;
// On update expression to use to populate the column on update if no
// value is provided. Note that it is not correct to use OnUpdateExpr
// as output to display to a user. User defined types within OnUpdateExpr
// have been serialized in a internal format. Instead, use one of the
// schemaexpr.FormatExpr* functions.
optional string on_update_expr = 18;
// A hidden column does not appear in star expansion, but can be referenced in
// queries and can be viewed when inspecting a table via SHOW CREATE TABLE. A
// column cannot be both hidden and inaccessible.
optional bool hidden = 6 [(gogoproto.nullable) = false];
// An inaccessible column does not appear in star expansion and cannot be
// referenced in queries. It cannot be viewed when inspecting a table via SHOW
// CREATE TABLE and is not shown as an attribute of its table in
// pg_catalog.pg_attribute. A column cannot be both hidden and inaccessible.
optional bool inaccessible = 17 [(gogoproto.nullable) = false];
// GeneratedAsIdentityType is an enum that represents how the creation of the
// column is associated with the GENERATED ... AS IDENTITY syntax.
// If the column is created with GENERATED ALWAYS AS IDENTITY syntax,
// GeneratedAsIdentityType for this column will be set to GENERATED_ALWAYS.
// If the column is created with GENERATED BY DEFAULT AS IDENTITY syntax,
// GeneratedAsIdentityType for this column will be set to GENERATED_BY_DEFAULT.
// If the column is created without using GENERATED ... AS IDENTITY syntax,
// GeneratedAsIdentityType for this column will be set to the default
// NOT_IDENTITY_COLUMN.
optional cockroach.sql.catalog.catpb.GeneratedAsIdentityType generated_as_identity_type = 19 [(gogoproto.nullable) = false];
// Expression to specify the sequence option for a `GENERATED AS IDENTITY`
// column.
optional string generated_as_identity_sequence_option = 20;
reserved 7;
// Ids of sequences used in this column's DEFAULT and ON UPDATE expressions,
// in calls to nextval().
repeated uint32 uses_sequence_ids = 10 [(gogoproto.casttype) = "ID"];
// Ids of sequences that the column owns.
repeated uint32 owns_sequence_ids = 12 [(gogoproto.casttype) = "ID"];
// Expression to use to compute the value of this column if this is a
// computed column. Note that it is not correct to use ComputeExpr
// as output to display to a user. User defined types within ComputeExpr
// have been serialized in a internal format. Instead, use one of the
// schemaexpr.FormatExpr* functions.
optional string compute_expr = 11;
// A computed column can be stored or virtual.
// Virtual can only be true if there is a compute expression.
optional bool virtual = 16 [(gogoproto.nullable) = false];
// PGAttributeNum must be accessed through the accessor, since it is set
// lazily, it is incorrect to access it directly.
// PGAttributeNum represents a column's number in catalog tables.
// This only differs from ID when the Column order is swapped or
// the ColumnDescriptor must be remade while remaining visual ordering.
// This does not exist in TableDescriptors pre 20.2.
optional uint32 pg_attribute_num = 13 [(gogoproto.nullable) = false,
(gogoproto.customname) = "PGAttributeNum",
(gogoproto.casttype) = "PGAttributeNum"];
// Used to indicate column is used and dropped for ALTER COLUMN TYPE mutation.
optional bool alter_column_type_in_progress = 14 [(gogoproto.nullable) = false];
// SystemColumnKind represents what kind of system column this column
// descriptor represents, if any.
optional cockroach.sql.catalog.catpb.SystemColumnKind system_column_kind = 15 [(gogoproto.nullable) = false];
}
// ColumnFamilyDescriptor is set of columns stored together in one kv entry.
// For more information, look at `docs/tech-notes/encoding.md#value-encoding`.
message ColumnFamilyDescriptor {
option (gogoproto.equal) = true;
optional string name = 1 [(gogoproto.nullable) = false];
// Column family 0 is *always* included in k/v pairs for a row. This makes
// sure that rows will all NULL values still have a k/v pair. When performing
// optimizations involving column families, ensure that column family 0
// is scanned if the row may have nulls.
optional uint32 id = 2 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ID", (gogoproto.casttype) = "FamilyID"];
// A list of column names of which the family is comprised. This list
// parallels the column_ids list. If duplicating the storage of the column
// names here proves to be prohibitive, we could clear this field before
// saving and reconstruct it after loading.
repeated string column_names = 3;
// A list of column ids of which the family is comprised. This list parallels
// the column_names list.
repeated uint32 column_ids = 4 [(gogoproto.customname) = "ColumnIDs",
(gogoproto.casttype) = "ColumnID"];
// If nonzero, the column involved in the single column optimization.
//
// Families store columns in a ValueType_TUPLE as repeated <columnID><data>
// entries. As a space optimization and for backward compatibility, a single
// column is written without the column id prefix. Because more columns could
// be added, it would be ambiguous which column was stored when read back in,
// so this field supplies it.
optional uint32 default_column_id = 5 [(gogoproto.nullable) = false,
(gogoproto.customname) = "DefaultColumnID", (gogoproto.casttype) = "ColumnID"];
}
// InterleaveDescriptor represents an index (either primary or secondary) that
// is interleaved into another table's data.
//
// Example:
// Table 1 -> /a/b
// Table 2 -> /a/b/c
// Table 3 -> /a/b/c/d
//
// There are two components (table 2 is the parent and table 1 is the
// grandparent) with shared lengths 2 and 1.
message InterleaveDescriptor {
option (gogoproto.equal) = true;
message Ancestor {
option (gogoproto.equal) = true;
// TableID is the ID of the table being interleaved into.
optional uint32 table_id = 1 [(gogoproto.nullable) = false,
(gogoproto.customname) = "TableID", (gogoproto.casttype) = "ID"];
// IndexID is the ID of the parent index being interleaved into.
optional uint32 index_id = 2 [(gogoproto.nullable) = false,
(gogoproto.customname) = "IndexID", (gogoproto.casttype) = "IndexID"];
// SharedPrefixLen is how many fields are shared between a parent and child
// being interleaved, excluding any fields shared between parent and
// grandparent. Thus, the sum of SharedPrefixLens in the components of an
// InterleaveDescriptor is never more than the number of fields in the index
// being interleaved.
// In cockroach 1.0, this value did not exist and thus a check for > 0
// must be performed prior to its use.
optional uint32 shared_prefix_len = 3 [(gogoproto.nullable) = false,
(gogoproto.customname) = "SharedPrefixLen"];
}
// Ancestors contains the nesting of interleaves in the order they appear in
// an encoded key. This means they are always in the far-to-near ancestor
// order (e.g. grand-grand-parent, grand-parent, parent).
repeated Ancestor ancestors = 1 [(gogoproto.nullable) = false];
}
// IndexDescriptor describes an index (primary or secondary).
//
// Sample field values on the following table:
//
// CREATE TABLE t (
// k1 INT NOT NULL, // column ID: 1
// k2 INT NOT NULL, // column ID: 2
// u INT NULL, // column ID: 3
// v INT NULL, // column ID: 4
// w INT NULL, // column ID: 5
// CONSTRAINT "primary" PRIMARY KEY (k1, k2),
// INDEX k1v (k1, v) STORING (w),
// FAMILY "primary" (k1, k2, u, v, w)
// )
//
// Primary index:
// name: primary
// id: 1
// unique: true
// key_column_names: k1, k2
// key_column_directions: ASC, ASC
// key_column_ids: 1, 2 // k1, k2
//
// [old STORING encoding] Index k1v (k1, v) STORING (w):
// name: k1v
// id: 2
// unique: false
// key_column_names: k1, v
// key_column_directions: ASC, ASC
// store_column_names: w
// key_column_ids: 1, 4 // k1, v
// key_suffix_column_ids: 2, 5 // k2, w
//
// [new STORING encoding] Index k1v (k1, v) STORING (w):
// name: k1v
// id: 2
// unique: false
// key_column_names: k1, v
// key_column_directions: ASC, ASC
// store_column_names: w
// key_column_ids: 1, 4 // k1, v
// key_suffix_column_ids: 2 // k2
// store_column_ids: 5 // w
message IndexDescriptor {
option (gogoproto.equal) = true;
// The direction of a column in the index.
enum Direction {
ASC = 0;
DESC = 1;
}
// The type of the index.
enum Type {
FORWARD = 0;
INVERTED = 1;
}
// InvertedIndexColumnKind is the kind of the inverted index that we're
// building on a particular column. The reason this needs to be stored is that
// we need to be able to check that the "opclass" passed into an inverted
// index declaration (for example, gin_trgm_ops) is compatible with the
// datatype of a particular column (gin_tgrm_ops is only valid on text). A
// future reason is that it's possible to desire having more than one type of
// inverted index on a particular datatype - for example, you might want to
// create a "stemming" inverted index on text. And without this extra kind, it
// wouldn't be possible to distinguish a text inverted index that uses
// trigrams, vs a text inverted index that uses stemming.
enum InvertedIndexColumnKind {
// DEFAULT is the default kind of inverted index column. JSON, Array, and
// geo inverted indexes all are DEFAULT, though prior to 22.2 they had no
// kind at all.
DEFAULT = 0;
// TRIGRAM is the trigram kind of inverted index column. It's only valid on
// text columns.
TRIGRAM = 1;
}
optional string name = 1 [(gogoproto.nullable) = false];
optional uint32 id = 2 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ID", (gogoproto.casttype) = "IndexID"];
optional bool unique = 3 [(gogoproto.nullable) = false];
optional uint32 version = 18 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexDescriptorVersion"];
// An ordered list of column names of which the index is comprised; these
// columns do not include any additional stored columns (which are in
// stored_column_names). This list parallels the key_column_ids list.
//
// If the index is an inverted index, the last column in the list is
// inverted and all others are not.
//
// Note: if duplicating the storage of the column names here proves to be
// prohibitive, we could clear this field before saving and reconstruct it
// after loading.
repeated string key_column_names = 4;
// The sort direction of each column in key_column_names.
repeated Direction key_column_directions = 8;
// An ordered list of column names which the index stores in addition to the
// columns which are explicitly part of the index (STORING clause).
repeated string store_column_names = 5;
// An ordered list of opclasses that parallels each of the inverted columns
// in the index. n.b.: currently, there can only be a single inverted column
// in an index, so this list will always be of size 0 or 1.
repeated InvertedIndexColumnKind inverted_column_kinds = 27;
// An ordered list of column IDs of which the index key is comprised. This
// list parallels the key_column_names list and does not include any
// additional stored columns. If the index is an inverted index, the last
// column in the list is inverted and all others are not.
repeated uint32 key_column_ids = 6 [(gogoproto.customname) = "KeyColumnIDs",
(gogoproto.casttype) = "ColumnID"];
// An ordered list of IDs for the additional columns associated with the
// index:
// - implicit columns, which are all the primary key columns that are not
// already part of the index, in other words
// PrimaryIndex.key_column_ids - key_column_ids.
// - stored columns (the columns in store_column_names) if this index uses the
// old STORING encoding (key-encoded data).
//
// Only used for secondary indexes.
// For non-unique indexes, these columns are appended to the key.
// For unique indexes, these columns are stored in the value (unless the key
// contains a NULL value: then the extra columns are appended to the key to
// unique-ify it).
// This distinction exists because we want to be able to insert an entry using
// a single conditional put on the key.
repeated uint32 key_suffix_column_ids = 7 [(gogoproto.customname) = "KeySuffixColumnIDs",
(gogoproto.casttype) = "ColumnID"];
// An ordered list of column IDs that parallels store_column_names if this
// index uses the new STORING encoding (value-encoded data, always in the KV
// value).
repeated uint32 store_column_ids = 14
[(gogoproto.customname) = "StoreColumnIDs", (gogoproto.casttype) = "ColumnID"];
// CompositeColumnIDs contains an ordered list of IDs of columns that appear
// in the index and have a composite encoding. Includes IDs from both
// key_column_ids and key_suffix_column_ids.
repeated uint32 composite_column_ids = 13
[(gogoproto.customname) = "CompositeColumnIDs", (gogoproto.casttype) = "ColumnID"];
// ForeignKey and ReferencedBy are deprecated and not stored from 19.2 onward.
optional ForeignKeyReference foreign_key = 9 [(gogoproto.nullable) = false, deprecated = true];
repeated ForeignKeyReference referenced_by = 10 [(gogoproto.nullable) = false, deprecated = true];
// Interleave, if it's not the zero value, describes how this index's data is
// interleaved into another index's data.
optional InterleaveDescriptor interleave = 11 [(gogoproto.nullable) = false, deprecated = true];
// InterleavedBy contains a reference to every table/index that is interleaved
// into this one.
//
// Note that any of these indexes can themselves be interleaved by other
// tables but this list contains only those for which this index is a direct
// interleave parent.
//
// Only the Table and Index fields of the ForeignKeyReference are used. And
// despite the message used here, interleavings don't have to have
// corresponding foreign key references (and whether they do or not is
// irrelevant for this field).
repeated ForeignKeyReference interleaved_by = 12 [(gogoproto.nullable) = false, deprecated = true];
// Partitioning, if it's not the zero value, describes how this index's data
// is partitioned into spans of keys each addressable by zone configs.
optional cockroach.sql.catalog.catpb.PartitioningDescriptor partitioning = 15 [(gogoproto.nullable) = false];
// Type is the type of index, inverted or forward.
optional Type type = 16 [(gogoproto.nullable)=false];
// CreatedExplicitly specifies whether this index was created explicitly
// (i.e. via 'CREATE INDEX' statement).
optional bool created_explicitly = 17 [(gogoproto.nullable) = false];
// EncodingType represents what sort of k/v encoding is used to store this descriptor on disk.
// As of now, this includes the existing secondary index encoding, or the primary index encoding.
// N.B. This field is only recognized on secondary indexes.
optional uint32 encoding_type = 19
[(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexDescriptorEncodingType"];
// Sharded, if it's not the zero value, describes how this index is sharded.
optional cockroach.sql.catalog.catpb.ShardedDescriptor sharded = 20 [(gogoproto.nullable) = false];
// Disabled is used by the DROP PRIMARY KEY command to mark
// that this index is disabled for further use.
optional bool disabled = 21 [(gogoproto.nullable) = false];
// GeoConfig, if it's not the zero value, describes configuration for
// this geospatial inverted index.
optional geo.geoindex.Config geo_config = 22 [(gogoproto.nullable) = false];
// Predicate, if it's not empty, indicates that the index is a partial index
// with Predicate as the expression. If Predicate is empty, the index is not
// a partial index. Columns are referred to in the expression by their name.
// TODO(mgartner): Update the comment to explain that columns are referenced
// by their ID once #49766 is addressed.
optional string predicate = 23 [(gogoproto.nullable) = false];
// UseDeletePreservingEncoding, if true, causes the index to be encoded with
// an additional bit that indicates whether or not the value has been deleted.
// Index key-values that are deleted in this way are not actually deleted, but
// remain in the index with a value which has the delete bit set to true.
//
// The encoding with the additional delete bit was chosen over a separate
// index encoding type because there would have to be a separate type for each
// encoding that we already have for indexes. The alternative would get harder
// to maintain if we added more index encodings in the future.
//
// This is necessary to preserve the delete history for the MVCC-compatible
// index backfiller
// docs/RFCS/20211004_incremental_index_backfiller.md#new-index-encoding-for-deletions-vs-mvcc
//
// We only use the delete preserving encoding if the index is
// writable. Otherwise, we may preserve a delete when in DELETE_ONLY but never
// see a subsequent write that replaces it. This a problem for the
// MVCC-compatible index backfiller which merges entries from a
// delete-preserving index into a newly-added index. A delete preserved in
// DELETE_ONLY could result in a value being erroneously deleted during the
// merge process. While we could filter such deletes, the filtering would
// require more data being stored in each deleted entry and further complicate
// the merge process. See #75720 for further details.
optional bool use_delete_preserving_encoding = 24 [(gogoproto.nullable) = false];
// CreatedAtNanos, if non-zero, represents an approximate time at which the
// index was created.
optional int64 created_at_nanos = 25 [(gogoproto.nullable) = false];
// Used within the table descriptor to uniquely identify individual
// constraints, which is only set for primary keys and unique secondary
// indexes.
optional uint32 constraint_id = 26 [(gogoproto.customname) = "ConstraintID",
(gogoproto.casttype) = "ConstraintID", (gogoproto.nullable) = false];
// Next ID: 28
}
// ConstraintToUpdate represents a constraint to be added to the table and
// validated for existing rows. More generally, in the future, when we support
// adding constraints that are unvalidated for existing rows and can be
// validated later using VALIDATE CONSTRAINT, this mutation will also represent
// either adding an unvalidated constraint or validating an existing constraint.
//
// This mutation effects changes only in the backfill step of the schema
// changer: First, a new version of the table descriptor with the constraint
// added is published, after all columns being added have been backfilled. After
// waiting for the constraint to be enforced for writes on all nodes, the
// constraint is then validated for all existing rows. This ensures that
// constraints added to columns that are being added are correctly enforced
// before the column becomes public.
message ConstraintToUpdate {
option (gogoproto.equal) = true;
enum ConstraintType {
CHECK = 0;
FOREIGN_KEY = 1;
// NOT NULL constraints being added are represented by a dummy check
// constraint so that a multi-state schema change, including a bulk
// validation step, can occur. The check field contains the dummy
// constraint.
NOT_NULL = 2;
UNIQUE_WITHOUT_INDEX = 3;
}
required ConstraintType constraint_type = 1 [(gogoproto.nullable) = false];
required string name = 2 [(gogoproto.nullable) = false];
optional TableDescriptor.CheckConstraint check = 3 [(gogoproto.nullable) = false];
// All fields past 3 haven't been persisted before 19.2.
optional ForeignKeyConstraint foreign_key = 4 [(gogoproto.nullable) = false];
reserved 5;
optional uint32 not_null_column = 6 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ColumnID"];
optional UniqueWithoutIndexConstraint unique_without_index_constraint = 7 [(gogoproto.nullable) = false];
}
// PrimaryKeySwap is a mutation corresponding to the atomic swap phase
// during a primary key change where old versions of indexes are exchanged for
// updated versions, and the table's new primary key is written into the descriptor.
message PrimaryKeySwap {
option (gogoproto.equal) = true;
// old_primary_index_id is the ID of the old primary index for the table.
optional uint32 old_primary_index_id = 4 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID"];
// new_primary_index_id is the ID of the new primary index for the table.
optional uint32 new_primary_index_id = 1 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID"];
// old_indexes and new_indexes are lists of IndexID's where the i'th index in old_indexes will be
// swapped out with the i'th index in new_indexes.
repeated uint32 old_indexes = 2 [(gogoproto.casttype) = "IndexID"];
repeated uint32 new_indexes = 3 [(gogoproto.casttype) = "IndexID"];
// new_primary_index_name is the name of the primary key when added as a
// new constraint to a table without a primary key. In other cases, it is
// the empty string.
optional string new_primary_index_name = 5 [(gogoproto.nullable) = false];
message LocalityConfigSwap {
option (gogoproto.equal) = true;
optional cockroach.sql.catalog.catpb.LocalityConfig old_locality_config = 1 [(gogoproto.nullable) = false];
optional cockroach.sql.catalog.catpb.LocalityConfig new_locality_config = 2 [(gogoproto.nullable) = false];
// NewRegionalByRowColumnID is set when we are creating a new column for a
// REGIONAL BY ROW table. It is used by NewRegionalByRowColumnDefaultExpr
// to identify the column we may have to change DefaultExpr for.
optional uint32 new_regional_by_row_column_id = 3 [(gogoproto.casttype) = "ColumnID", (gogoproto.customname) = "NewRegionalByRowColumnID"];
// NewRegionalByRowColumnDefaultExpr is the default expression to set when a
// REGIONAL BY ROW involving a new crdb_region column is required.
// This is required so that the backfill uses a well-known value, but after
// the backfill is complete we can set it to use the gateway_region.
//
// This must be set at mutation creation time, as the schema changer loses
// context on what the database is. The default expression should be already
// serialized in the same internal format as default_expr on the
// ColumnDescriptor.
optional string new_regional_by_row_column_default_expr = 4;
}
// LocalityConfigSwap is set for ALTER TABLE SET LOCALITY when the command
// requires PK changes. If set, additional zone configurations are set to
// match the new locality config.
optional LocalityConfigSwap locality_config_swap = 6;
}
// ModifyRowLevelTTL is a mutation corresponding to adding or dropping a TTL
// from a table. This accompanies an ADD or DROP column.
message ModifyRowLevelTTL {
option (gogoproto.equal) = true;
optional cockroach.sql.catalog.catpb.RowLevelTTL row_level_ttl = 1 [(gogoproto.customname) = "RowLevelTTL"];
}
// ComputedColumnSwap is a mutation corresponding to the atomic swap phase
// where Column a' that is computed using Column a is swapped to replace
// Column a while Column a becomes computed using a'.
message ComputedColumnSwap {
option (gogoproto.equal) = true;
optional uint32 new_column_id = 1 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ColumnID"];
optional uint32 old_column_id = 2 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ColumnID"];
// inverse_expr is the expression used to compute values for the old column
// once it is swapped for the new column.
optional string inverse_expr = 3 [(gogoproto.nullable) = false];
}
// MaterializedViewRefresh is a mutation corresponding to a request to
// refresh a materialized view. The mutation operates by backfilling the
// result of the view query into the indexes specified by the mutation.
message MaterializedViewRefresh {
option (gogoproto.equal) = true;
// NewPrimaryIndex is the new primary index of the view to backfill into.
// NewPrimaryIndex and NewIndexes below are copies of the existing indexes on
// the view, but with different ID's.
optional IndexDescriptor new_primary_index = 1 [(gogoproto.nullable) = false];
// NewIndexes are the new set of indexes to backfill the view into.
repeated IndexDescriptor new_indexes = 2 [(gogoproto.nullable) = false];
// AsOf is the timestamp to perform the view query at.
optional util.hlc.Timestamp as_of = 3 [(gogoproto.nullable) = false];
// ShouldBackfill indicates whether or not the schema changer should backfill
// the query into the new indexes. This can be false if the `WITH NO DATA` flag
// was specified for the `REFRESH MATERIALIZED VIEW` statement. `WITH NO DATA`
// indicates that the user just wants the space used by the view to be reclaimed.
optional bool should_backfill = 4 [(gogoproto.nullable) = false];
}
// A DescriptorMutation represents a column or an index that
// has either been added or dropped and hasn't yet transitioned
// into a stable state: completely backfilled and visible, or
// completely deleted. A table descriptor in the middle of a
// schema change will have a DescriptorMutation FIFO queue
// containing each column/index descriptor being added or dropped.
// Mutations for constraints work differently from columns and
// indexes; see the documentation for ConstraintToUpdate.
message DescriptorMutation {
option (gogoproto.equal) = true;
oneof descriptor {
ColumnDescriptor column = 1;
IndexDescriptor index = 2;
ConstraintToUpdate constraint = 8;
PrimaryKeySwap primaryKeySwap = 9;
ComputedColumnSwap computedColumnSwap = 10;
MaterializedViewRefresh materializedViewRefresh = 11;
ModifyRowLevelTTL modify_row_level_ttl = 12 [(gogoproto.customname)="ModifyRowLevelTTL"];
}
// A descriptor within a mutation is unavailable for reads, writes
// and deletes. It is only available for implicit (internal to
// the database) writes and deletes depending on the state of the mutation.
enum State {
// Not used.
UNKNOWN = 0;
// Operations can use this invisible descriptor to implicitly
// delete entries.
// Column: A descriptor in this state is invisible to
// INSERT and UPDATE. DELETE must delete a column in this state.
// Index: A descriptor in this state is invisible to an INSERT.
// UPDATE must delete the old value of the index but doesn't write
// the new value. DELETE must delete the index.
//
// When deleting a descriptor, all descriptor related data
// (column or index data) can only be mass deleted once
// all the nodes have transitioned to the DELETE_ONLY state.
DELETE_ONLY = 1;
// Operations can use this invisible descriptor to implicitly
// write and delete entries.
// Column: INSERT will populate this column with the default
// value. UPDATE ignores this descriptor. DELETE must delete
// the column.
// Index: INSERT, UPDATE and DELETE treat this index like any
// other index.
//
// When adding a descriptor, all descriptor related data
// (column default or index data) can only be backfilled once
// all nodes have transitioned into the DELETE_AND_WRITE_ONLY state.
DELETE_AND_WRITE_ONLY = 2;
// Operations other than non-transactional backfilling must not
// use this descriptor.
//
// Column: Columns do not use this state. A column descriptor in
// this state is a programming error.
//
// Index: A descriptor in this state is invisible to an INSERT,
// UPDATE, and DELETE.
//
// TODO(ssd): This is currently unused and is being added to
// facilitate the new temporary-index-based backfilling process.
BACKFILLING = 3;
// Operations can use this invisible descriptor to implicitly
// write and delete entries. This is used by the MVCC-compatible
// index backfiller to ensure that unique indexes do not produce
// erroneous conflicts.
//
// Columns: Columns do not use this state. A column descriptor in
// this state is a programming error.
//
// Index: INSERT, UPDATE and DELETE treat this index like a
// DELETE_AND_WRITE_ONLY index, but use Put in instead of CPut or
// InitPut, effectively ignoring unique constraints.
MERGING = 4;
}
optional State state = 3 [(gogoproto.nullable) = false];
// Direction of mutation.
enum Direction {
// Not used.
NONE = 0;
// Descriptor is being added.
ADD = 1;
// Descriptor is being dropped.
DROP = 2;
}
optional Direction direction = 4 [(gogoproto.nullable) = false];
// The mutation id used to group mutations that should be applied together.
// This is used for situations like creating a unique column, which
// involve adding two mutations: one for the column, and another for the
// unique constraint index.
optional uint32 mutation_id = 5 [(gogoproto.nullable) = false,
(gogoproto.customname) = "MutationID", (gogoproto.casttype) = "MutationID"];
reserved 6;
// Indicates that this mutation is a rollback.
optional bool rollback = 7 [(gogoproto.nullable) = false];
}
// A table descriptor is named through a name map stored in the
// system.namespace table: a map from {parent_id, table_name} -> id.
// This name map can be cached for performance on a node in the cluster
// making reassigning a name complicated. In particular, since a
// name cannot be withdrawn across a cluster in a transaction at
// timestamp T, we have to worry about the following:
//
// 1. A table is dropped at T, and the name and descriptor are still
// cached and used by transactions at timestamps >= T.
// 2. A table is renamed from foo to bar at T, and both names foo and bar
// can be used by transactions at timestamps >= T.
// 3. A name foo is reassigned from one table to another at T, and the name
// foo can reference two different tables at timestamps >= T.
//
// The system ensures that a name can be resolved only to a single
// descriptor at a timestamp thereby permitting 1 and 2, but not 3
// (the name references two tables).
//
// The transaction at T is followed by a time period when names no longer
// a part of the namespace are drained from the system. Once the old name
// is drained from the system another transaction at timestamp S is
// executed to release the name for future use. The interval from T to S
// is called the name drain interval: If the T transaction is removing
// the name foo then, at timestamps above S, foo can no longer be resolved.
//
// Consider a transaction at T in which name B is dropped, a new name C is
// created. Name C is viable as soon as the transaction commits.
// When the transaction at S commits, the name B is released for reuse.
//
// The transaction at S runs through the schema changer, with the system
// returning a response to the client initiating transaction T only after
// transaction at S is committed. So effectively the SQL transaction once
// it returns can be followed by SQL transactions that do not observe
// old name mappings.
//
// Note: an exception to this is #19925 which needs to be fixed.
//
// In order for transaction at S to act properly the system.namespace
// table entry for an old name references the descriptor who was the
// prior owner of the name requiring draining.
//
// Before T: B -> Desc B
//
// After T and before S: B -> Desc B, C -> Desc C
//
// After S: C -> Desc C
//
// Between T and S the name B is drained and the system is unable
// to assign it to another descriptor.
//
// BEGIN;
// RENAME foo TO bar;
// CREATE foo;
//
// will fail because CREATE foo is executed at T.
//
// RENAME foo TO bar;
// CREATE foo;
//
// will succeed because the RENAME returns after S and CREATE foo is
// executed after S.
//
// The above scheme suffers from the problem that a transaction can observe
// the partial effect of a committed transaction during the drain interval.
// For instance during the drain interval a transaction can see the correct
// assignment for C, and the old assignments for B.
//
message NameInfo {
option (gogoproto.equal) = true;
// The database that the table belonged to before the rename (tables can be
// renamed from one db to another).
optional uint32 parent_id = 1 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ParentID", (gogoproto.casttype) = "ID"];
// The schemaID of the schema the table belongs to before the rename/drop.
// Required to correctly identify which namespace entry to reclaim.
optional uint32 parent_schema_id = 3 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ParentSchemaID", (gogoproto.casttype) = "ID"];
optional string name = 2 [(gogoproto.nullable) = false];
}
// State indicates whether a descriptor is public (i.e., normally visible,
// resolvable, etc.) or in some other state subject to restrictions.
// A non-public table descriptor cannot be leased.
// A schema changer observing DROP set will truncate the table and delete the
// descriptor.
// It is illegal to transition DROP to any other state.
enum DescriptorState {
// Descriptor is visible and can be leased.
PUBLIC = 0;
// Descriptor is being added.
ADD = 1;
// Descriptor is being dropped.
DROP = 2;
// Descriptor is offline (e.g. for bulk-ingestion). See offline_reason.
OFFLINE = 3;
}
// A TableDescriptor represents a table or view and is stored in a
// structured metadata key. The TableDescriptor has a globally-unique ID,
// while its member {Column,Index}Descriptors have locally-unique IDs.
message TableDescriptor {
option (gogoproto.equal) = true;
// Needed for the descriptorProto interface.
option (gogoproto.goproto_getters) = true;
// The following 5 fields: name, id, version, modification_time, and
// draining_names are metadata fields required by all descriptors to be
// leasable. The reason that they do not exist in a message of their own is
// to ease the migration burden as not all descriptors initially had all of
// these fields but many had some.
//
// TODO(postamar): remove draining_names from this comment in 22.2
// The table name. It should be normalized using NormalizeName() before
// comparing it.
optional string name = 1 [(gogoproto.nullable) = false];
optional uint32 id = 3 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"];
// Monotonically increasing version of the table descriptor.
//
// The design maintains two invariants:
// 1. Two safe versions: A transaction at a particular timestamp is
// allowed to use one of two versions of a table descriptor:
// the one that would be read from the store at that timestamp,
// and the one behind it in version.
// 2. Two leased versions: There can be valid leases on at most the 2
// latest versions of a table in the cluster at any time. New leases
// are only granted on the latest version.
//
// The database must maintain correctness in light of there being two
// versions of a descriptor that can be used.
//
// Multiple schema change mutations can be grouped together on a
// particular version increment.
optional uint64 version = 5 [(gogoproto.nullable) = false, (gogoproto.casttype) = "DescriptorVersion"];
// Last modification time of the table descriptor.
// Starting in 19.2 this field's value may sometime be zero-valued in which
// case the MVCC timestamp of the row containing the value should be used to
// populate it. This dance allows us to avoid observing the commit timestamp
// for transactions which increment the descriptor version.
// Encoded TableDescriptor structs should not be stored directly but rather
// should live inside of a Descriptor. The Descriptor.Table() method takes an
// hlc timestamp to ensure that this field is set properly when extracted from
// a Descriptor.
optional util.hlc.Timestamp modification_time = 7 [(gogoproto.nullable) = false];
// A list of draining names. The draining name entries are drained from
// the cluster wide name caches by incrementing the version for this
// descriptor and ensuring that there are no leases on prior
// versions of the descriptor. This field is then cleared and the version
// of the descriptor incremented.
//
// TODO(postamar): remove draining_names field in 22.2
repeated NameInfo draining_names = 21 [deprecated = true, (gogoproto.nullable) = false];
// ID of the parent database.
optional uint32 parent_id = 4 [(gogoproto.nullable) = false,
(gogoproto.customname) = "ParentID", (gogoproto.casttype) = "ID"];
// ID of the parent schema. For backwards compatibility, 0 means the table is
// scoped under the public physical schema (id 29). Because of this backward
// compatibility issue, this field should not be accessed directly or through
// the generated getter. Instead, use GetParentSchemaID() which is defined in
// structured.go.
optional uint32 unexposed_parent_schema_id = 40 [(gogoproto.nullable) = false,
(gogoproto.customname) = "UnexposedParentSchemaID", (gogoproto.casttype) = "ID"];
reserved 6;
repeated ColumnDescriptor columns = 8 [(gogoproto.nullable) = false];
// next_column_id is used to ensure that deleted column ids are not reused.
optional uint32 next_column_id = 9 [(gogoproto.nullable) = false,
(gogoproto.customname) = "NextColumnID", (gogoproto.casttype) = "ColumnID"];
// families holds information about the column families of this table.
// This list has at least length 1, in which case all columns are stored in the same family.
// families is stored in sorted order by family ID.
repeated ColumnFamilyDescriptor families = 22 [(gogoproto.nullable) = false];
// next_family_id is used to ensure that deleted family ids are not reused.
optional uint32 next_family_id = 23 [(gogoproto.nullable) = false,
(gogoproto.customname) = "NextFamilyID", (gogoproto.casttype) = "FamilyID"];
optional IndexDescriptor primary_index = 10 [(gogoproto.nullable) = false];
// indexes are all the secondary indexes.
repeated IndexDescriptor indexes = 11 [(gogoproto.nullable) = false];
// next_index_id is used to ensure that deleted index ids are not reused.
optional uint32 next_index_id = 12 [(gogoproto.nullable) = false,
(gogoproto.customname) = "NextIndexID", (gogoproto.casttype) = "IndexID"];
optional PrivilegeDescriptor privileges = 13;
// Columns or indexes being added or deleted in a FIFO order.
repeated DescriptorMutation mutations = 14 [(gogoproto.nullable) = false];
// The schema update lease. A single goroutine across a cockroach cluster
// can own it, and will execute pending schema changes for this table.
// Since the execution of a pending schema change is through transactions,
// it is legal for more than one goroutine to attempt to execute it. This
// lease reduces write contention on the schema change.
message SchemaChangeLease {
option (gogoproto.equal) = true;
optional uint32 node_id = 1 [(gogoproto.nullable) = false,
(gogoproto.customname) = "NodeID",
(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.NodeID"];
// Nanoseconds since the Unix epoch.
optional int64 expiration_time = 2 [(gogoproto.nullable) = false];
}
optional SchemaChangeLease lease = 15 [deprecated = true];
// An id for the next group of mutations to be applied together.
optional uint32 next_mutation_id = 16 [(gogoproto.nullable) = false,
(gogoproto.customname) = "NextMutationID", (gogoproto.casttype) = "MutationID"];
// format_version declares which sql to key:value mapping is being used to
// represent the data in this table.
optional uint32 format_version = 17 [(gogoproto.nullable) = false,
(gogoproto.casttype) = "FormatVersion"];
reserved 18;
optional DescriptorState state = 19 [(gogoproto.nullable) = false];
optional string offline_reason = 38 [(gogoproto.nullable) = false];
message CheckConstraint {
option (gogoproto.equal) = true;
// Expr is the expression that this check constraint represents.
// Note that it is not correct to use Expr as output to display
// to a user. User defined types within Expr have been serialized
// in a internal format. Instead, use one of the schemaexpr.FormatExpr*
// functions.
optional string expr = 1 [(gogoproto.nullable) = false];
optional string name = 2 [(gogoproto.nullable) = false];
optional ConstraintValidity validity = 3 [(gogoproto.nullable) = false];
reserved 4;
// An ordered list of column IDs used by the check constraint.
repeated uint32 column_ids = 5 [(gogoproto.customname) = "ColumnIDs",
(gogoproto.casttype) = "ColumnID"];
optional bool is_non_null_constraint = 6 [(gogoproto.nullable) = false];
// Hidden is set to true for hash-sharded column check constraints.
// Previously, this field was used to hide these constraints in the output
// of SHOW CREATE TABLE. We no longer them in order to make the output to be
// round-trippable, but we still set this field for now. See #68031.
optional bool hidden = 7 [(gogoproto.nullable) = false];
// Used within the table descriptor to uniquely identify individual
// constraints.
optional uint32 constraint_id = 8 [(gogoproto.customname) = "ConstraintID",
(gogoproto.casttype) = "ConstraintID", (gogoproto.nullable) = false];
}
repeated CheckConstraint checks = 20;
// The TableDescriptor is used for views in addition to tables. Views
// use mostly the same fields as tables, but need to track the actual
// query from the view definition as well.
//
// For now we only track a string representation of the query. This prevents
// us from easily supporting things like renames of the dependencies of a
// view. Eventually we'll want to switch to a semantic encoding of the query
// that relies on IDs rather than names so that we can support renames of
// fields relied on by the query, as Postgres does.
//
// Note: The presence of this field is used to determine whether or not
// a TableDescriptor represents a view.
optional string view_query = 24 [(gogoproto.nullable) = false];
// IsMaterializedView indicates whether this view is materialized or not.