github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sqlbase/structured.proto (about) 1 // Copyright 2015 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 // Cannot be proto3 because we use nullable primitives. 12 syntax = "proto2"; 13 package cockroach.sql.sqlbase; 14 option go_package = "sqlbase"; 15 16 import "util/hlc/timestamp.proto"; 17 import "sql/sqlbase/privilege.proto"; 18 import "sql/types/types.proto"; 19 import "geo/geoindex/config.proto"; 20 import "gogoproto/gogo.proto"; 21 22 enum ConstraintValidity { 23 // The constraint is valid for all rows. 24 Validated = 0; 25 // The constraint has not yet been validated for all rows (and will not be 26 // validated until VALIDATE CONSTRAINT is used). 27 Unvalidated = 1; 28 // The constraint was just added, but the validation for existing rows is not 29 // yet complete. If validation fails, the constraint will be dropped. 30 Validating = 2; 31 // The constraint is being dropped in the schema changer. 32 Dropping = 3; 33 } 34 35 // ForeignKeyReference is deprecated, replaced by ForeignKeyConstraint in v19.2 36 // (though it is still possible for table descriptors on disk to have 37 // ForeignKeyReferences). 38 // 39 // It is still used to describe interleavings (see 40 // IndexDescriptor.InterleavedBy), for which it is a poor choice: only the Table 41 // and Index fields are used, and the interleaving has nothing to do with 42 // traditional foreign key references. 43 message ForeignKeyReference { 44 option (gogoproto.equal) = true; 45 enum Action { 46 option (gogoproto.goproto_enum_stringer) = false; 47 NO_ACTION = 0; 48 RESTRICT = 1; 49 SET_NULL = 2; 50 SET_DEFAULT = 3; 51 CASCADE = 4; 52 } 53 54 // Match is the algorithm used to compare composite keys. 55 enum Match { 56 option (gogoproto.goproto_enum_stringer) = false; 57 SIMPLE = 0; 58 FULL = 1; 59 PARTIAL = 2; // Note: not actually supported, but we reserve the value for future use. 60 } 61 62 optional uint32 table = 1 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ID"]; 63 optional uint32 index = 2 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID"]; 64 optional string name = 3 [(gogoproto.nullable) = false]; 65 optional ConstraintValidity validity = 4 [(gogoproto.nullable) = false]; 66 // If this FK only uses a prefix of the columns in its index, we record how 67 // many to avoid spuriously counting the additional cols as used by this FK. 68 optional int32 shared_prefix_len = 5 [(gogoproto.nullable) = false]; 69 optional Action on_delete = 6 [(gogoproto.nullable) = false]; 70 optional Action on_update = 7 [(gogoproto.nullable) = false]; 71 // This is only important for composite keys. For all prior matches before 72 // the addition of this value, MATCH SIMPLE will be used. 73 optional Match match = 8 [(gogoproto.nullable) = false]; 74 } 75 76 // ForeignKeyConstraint is the new (as of 19.2 and VersionTopLevelForeignKeys) 77 // representation for foreign keys. It's stored on the TableDescriptor and is 78 // designed to be agnostic to which indexes are available on both the origin 79 // and referenced tables, so that the optimizer can have full freedom to choose 80 // the best possible index to satisfy constraint checks at runtime. 81 message ForeignKeyConstraint { 82 option (gogoproto.equal) = true; 83 optional uint32 origin_table_id = 1 [(gogoproto.nullable) = false, 84 (gogoproto.customname) = "OriginTableID", 85 (gogoproto.casttype) = "ID"]; 86 repeated uint32 origin_column_ids = 2 [(gogoproto.customname) = "OriginColumnIDs", 87 (gogoproto.casttype) = "ColumnID"]; 88 repeated uint32 referenced_column_ids = 3 [(gogoproto.customname) = "ReferencedColumnIDs", 89 (gogoproto.casttype) = "ColumnID"]; 90 optional uint32 referenced_table_id = 4 [(gogoproto.nullable) = false, 91 (gogoproto.customname) = "ReferencedTableID", 92 (gogoproto.casttype) = "ID"]; 93 optional string name = 5 [(gogoproto.nullable) = false]; 94 optional ConstraintValidity validity = 6 [(gogoproto.nullable) = false]; 95 optional ForeignKeyReference.Action on_delete = 7 [(gogoproto.nullable) = false]; 96 optional ForeignKeyReference.Action on_update = 8 [(gogoproto.nullable) = false]; 97 // This is only important for composite keys. For all prior matches before 98 // the addition of this value, MATCH SIMPLE will be used. 99 optional ForeignKeyReference.Match match = 9 [(gogoproto.nullable) = false]; 100 101 // LegacyOriginIndex is the ID of the index used for the FK on the origin 102 // table. In versions 19.1 and earlier, foreign keys were represented by 103 // fields on the index that they use. In versions 19.2 and later, we preserve 104 // the semantics of the older FKs which were tied to indexes by specifying 105 // the index as a field on this proto, since the migration process to have 106 // top-level FK fields on the table descriptor requires two releases. 107 // In 20.1, these fields are no longer read, but must continue to be written 108 // to maintain compatibility in mixed 19.2/20.1 clusters. In 20.2 these fields 109 // can _finally_ be removed. 110 // * When using the foreign key constraint, do not read from these fields! * 111 optional uint32 legacy_origin_index = 10 112 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID", deprecated = true]; 113 // LegacyReferencedIndex is the ID of the index used for the FK on the 114 // referenced side. See the comment for LegacyOriginIndex. 115 optional uint32 legacy_referenced_index = 11 116 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID", deprecated = true]; 117 // These fields were used for the 19.1 -> 19.2 foreign key migration. 118 reserved 12, 13; 119 } 120 121 message ColumnDescriptor { 122 option (gogoproto.equal) = true; 123 optional string name = 1 [(gogoproto.nullable) = false]; 124 optional uint32 id = 2 [(gogoproto.nullable) = false, 125 (gogoproto.customname) = "ID", (gogoproto.casttype) = "ColumnID"]; 126 optional sql.sem.types.T type = 3; 127 optional bool nullable = 4 [(gogoproto.nullable) = false]; 128 reserved 8; 129 // Default expression to use to populate the column on insert if no 130 // value is provided. Note that it is not correct to use DefaultExpr 131 // as output to display to a user. User defined types within DefaultExpr 132 // have been serialized in a internal format. Instead, format the result 133 // of DeserializeTableDescExpr. 134 optional string default_expr = 5; 135 reserved 9; 136 optional bool hidden = 6 [(gogoproto.nullable) = false]; 137 reserved 7; 138 // Ids of sequences used in this column's DEFAULT expression, in calls to nextval(). 139 repeated uint32 uses_sequence_ids = 10 [(gogoproto.casttype) = "ID"]; 140 // Ids of sequences that the column owns. 141 repeated uint32 owns_sequence_ids = 12 [(gogoproto.casttype) = "ID"]; 142 // Expression to use to compute the value of this column if this is a 143 // computed column. Note that it is not correct to use ComputeExpr 144 // as output to display to a user. User defined types within ComputeExpr 145 // have been serialized in a internal format. Instead, format the result 146 // of DeserializeTableDescExpr. 147 optional string compute_expr = 11; 148 // LogicalColumnID must be accessed through the accessor, since it is set 149 // lazily, it is incorrect to access it directly. 150 // LogicalColumnID represents a column's number in catalog tables. 151 // This only differs from ID when the Column order is swapped or 152 // the ColumnDescriptor must be remade while remaining visual ordering. 153 // This does not exist in TableDescriptors pre 20.2. 154 optional uint32 logical_id = 13 [(gogoproto.nullable) = false, 155 (gogoproto.customname) = "LogicalColumnID", (gogoproto.casttype) = "ColumnID"]; 156 // Used to indicate column is used and dropped for ALTER COLUMN TYPE mutation. 157 optional bool alter_column_type_in_progress = 14 [(gogoproto.nullable) = false]; 158 } 159 160 // ColumnFamilyDescriptor is set of columns stored together in one kv entry. 161 // For more information, look at `docs/tech-notes/encoding.md#value-encoding`. 162 message ColumnFamilyDescriptor { 163 option (gogoproto.equal) = true; 164 optional string name = 1 [(gogoproto.nullable) = false]; 165 // Column family 0 is *always* included in k/v pairs for a row. This makes 166 // sure that rows will all NULL values still have a k/v pair. When performing 167 // optimizations involving column families, ensure that column family 0 168 // is scanned if the row may have nulls. 169 optional uint32 id = 2 [(gogoproto.nullable) = false, 170 (gogoproto.customname) = "ID", (gogoproto.casttype) = "FamilyID"]; 171 172 // A list of column names of which the family is comprised. This list 173 // parallels the column_ids list. If duplicating the storage of the column 174 // names here proves to be prohibitive, we could clear this field before 175 // saving and reconstruct it after loading. 176 repeated string column_names = 3; 177 // A list of column ids of which the family is comprised. This list parallels 178 // the column_names list. 179 repeated uint32 column_ids = 4 [(gogoproto.customname) = "ColumnIDs", 180 (gogoproto.casttype) = "ColumnID"]; 181 182 // If nonzero, the column involved in the single column optimization. 183 // 184 // Families store columns in a ValueType_TUPLE as repeated <columnID><data> 185 // entries. As a space optimization and for backward compatibility, a single 186 // column is written without the column id prefix. Because more columns could 187 // be added, it would be ambiguous which column was stored when read back in, 188 // so this field supplies it. 189 optional uint32 default_column_id = 5 [(gogoproto.nullable) = false, 190 (gogoproto.customname) = "DefaultColumnID", (gogoproto.casttype) = "ColumnID"]; 191 } 192 193 // InterleaveDescriptor represents an index (either primary or secondary) that 194 // is interleaved into another table's data. 195 // 196 // Example: 197 // Table 1 -> /a/b 198 // Table 2 -> /a/b/c 199 // Table 3 -> /a/b/c/d 200 // 201 // There are two components (table 2 is the parent and table 1 is the 202 // grandparent) with shared lengths 2 and 1. 203 message InterleaveDescriptor { 204 option (gogoproto.equal) = true; 205 message Ancestor { 206 option (gogoproto.equal) = true; 207 // TableID is the ID of the table being interleaved into. 208 optional uint32 table_id = 1 [(gogoproto.nullable) = false, 209 (gogoproto.customname) = "TableID", (gogoproto.casttype) = "ID"]; 210 // IndexID is the ID of the parent index being interleaved into. 211 optional uint32 index_id = 2 [(gogoproto.nullable) = false, 212 (gogoproto.customname) = "IndexID", (gogoproto.casttype) = "IndexID"]; 213 // SharedPrefixLen is how many fields are shared between a parent and child 214 // being interleaved, excluding any fields shared between parent and 215 // grandparent. Thus, the sum of SharedPrefixLens in the components of an 216 // InterleaveDescriptor is never more than the number of fields in the index 217 // being interleaved. 218 // In cockroach 1.0, this value did not exist and thus a check for > 0 219 // must be performed prior to its use. 220 optional uint32 shared_prefix_len = 3 [(gogoproto.nullable) = false, 221 (gogoproto.customname) = "SharedPrefixLen"]; 222 } 223 224 // Ancestors contains the nesting of interleaves in the order they appear in 225 // an encoded key. This means they are always in the far-to-near ancestor 226 // order (e.g. grand-grand-parent, grand-parent, parent). 227 repeated Ancestor ancestors = 1 [(gogoproto.nullable) = false]; 228 } 229 230 // ShardedDescriptor represents an index (either primary or secondary) that is hash 231 // sharded into a user-specified number of buckets. 232 // 233 // As as example, sample field values for the following table: 234 // 235 // CREATE TABLE abc ( 236 // a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT=10, // column id: 1 237 // b BYTES 238 // ); 239 // 240 // Sharded descriptor: 241 // name: "a_shard" 242 // shard_buckets: 10 243 // column_names: ["a"] 244 message ShardedDescriptor { 245 option (gogoproto.equal) = true; 246 247 // IsSharded indicates whether the index in question is a sharded one. 248 optional bool is_sharded = 1 [(gogoproto.nullable) = false]; 249 // Name is the name of the shard column. 250 optional string name = 2 [(gogoproto.nullable) = false]; 251 252 // ShardBuckets indicates the number of shards this index is divided into. 253 optional int32 shard_buckets = 3 [(gogoproto.nullable) = false, 254 (gogoproto.customname) = "ShardBuckets"]; 255 256 // ColumnNames lists the names of the columns used to compute the shard column's 257 // values. 258 repeated string column_names = 4; 259 } 260 261 // PartitioningDescriptor represents the partitioning of an index into spans 262 // of keys addressable by a zone config. The key encoding is unchanged. Each 263 // partition may optionally be itself divided into further partitions, called 264 // subpartitions. 265 message PartitioningDescriptor { 266 option (gogoproto.equal) = true; 267 // List represents a list partitioning, which maps individual tuples to 268 // partitions. 269 message List { 270 option (gogoproto.equal) = true; 271 // Name is the partition name. 272 optional string name = 1 [(gogoproto.nullable) = false]; 273 // Values is an unordered set of the tuples included in this partition. Each 274 // tuple is encoded with the EncDatum value encoding. DEFAULT is encoded as 275 // NOT NULL followed by PartitionDefaultVal encoded as a non-sorting 276 // uvarint. 277 repeated bytes values = 2; 278 // Subpartitioning represents a further partitioning of this list partition. 279 optional PartitioningDescriptor subpartitioning = 3 [(gogoproto.nullable) = false]; 280 } 281 282 // Range represents a range partitioning, which maps ranges of tuples to 283 // partitions by specifying exclusive upper bounds. The range partitions in a 284 // PartitioningDescriptor are required to be sorted by UpperBound. 285 message Range { 286 option (gogoproto.equal) = true; 287 // Name is the partition name. 288 optional string name = 1 [(gogoproto.nullable) = false]; 289 // FromInclusive is the inclusive lower bound of this range partition. It is 290 // encoded with the EncDatum value encoding. MINVALUE and MAXVALUE are 291 // encoded as NOT NULL followed by a PartitionSpecialValCode encoded as a 292 // non-sorting uvarint. 293 optional bytes from_inclusive = 3; 294 // ToExclusive is the exclusive upper bound of this range partition. It is 295 // encoded in the same way as From. 296 optional bytes to_exclusive = 2; 297 } 298 299 // NumColumns is how large of a prefix of the columns in an index are used in 300 // the function mapping column values to partitions. If this is a 301 // subpartition, this is offset to start from the end of the parent 302 // partition's columns. If NumColumns is 0, then there is no partitioning. 303 optional uint32 num_columns = 1 [(gogoproto.nullable) = false]; 304 305 // Exactly one of List or Range is required to be non-empty if NumColumns is 306 // non-zero. 307 repeated List list = 2 [(gogoproto.nullable) = false]; 308 repeated Range range = 3 [(gogoproto.nullable) = false]; 309 } 310 311 // IndexDescriptor describes an index (primary or secondary). 312 // 313 // Sample field values on the following table: 314 // 315 // CREATE TABLE t ( 316 // k1 INT NOT NULL, // column ID: 1 317 // k2 INT NOT NULL, // column ID: 2 318 // u INT NULL, // column ID: 3 319 // v INT NULL, // column ID: 4 320 // w INT NULL, // column ID: 5 321 // CONSTRAINT "primary" PRIMARY KEY (k1, k2), 322 // INDEX k1v (k1, v) STORING (w), 323 // FAMILY "primary" (k1, k2, u, v, w) 324 // ) 325 // 326 // Primary index: 327 // name: primary 328 // id: 1 329 // unique: true 330 // column_names: k1, k2 331 // column_directions: ASC, ASC 332 // column_ids: 1, 2 // k1, k2 333 // 334 // [old STORING encoding] Index k1v (k1, v) STORING (w): 335 // name: k1v 336 // id: 2 337 // unique: false 338 // column_names: k1, v 339 // column_directions: ASC, ASC 340 // store_column_names: w 341 // column_ids: 1, 4 // k1, v 342 // extra_column_ids: 2, 5 // k2, w 343 // 344 // [new STORING encoding] Index k1v (k1, v) STORING (w): 345 // name: k1v 346 // id: 2 347 // unique: false 348 // column_names: k1, v 349 // column_directions: ASC, ASC 350 // store_column_names: w 351 // column_ids: 1, 4 // k1, v 352 // extra_column_ids: 2 // k2 353 // store_column_ids: 5 // w 354 message IndexDescriptor { 355 option (gogoproto.equal) = true; 356 // The direction of a column in the index. 357 enum Direction { 358 ASC = 0; 359 DESC = 1; 360 } 361 362 // The type of the index. 363 enum Type { 364 FORWARD = 0; 365 INVERTED = 1; 366 } 367 368 optional string name = 1 [(gogoproto.nullable) = false]; 369 optional uint32 id = 2 [(gogoproto.nullable) = false, 370 (gogoproto.customname) = "ID", (gogoproto.casttype) = "IndexID"]; 371 optional bool unique = 3 [(gogoproto.nullable) = false]; 372 373 optional uint32 version = 18 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexDescriptorVersion"]; 374 375 // An ordered list of column names of which the index is comprised; these 376 // columns do not include any additional stored columns (which are in 377 // stored_column_names). This list parallels the column_ids list. 378 // 379 // Note: if duplicating the storage of the column names here proves to be 380 // prohibitive, we could clear this field before saving and reconstruct it 381 // after loading. 382 repeated string column_names = 4; 383 384 // The sort direction of each column in column_names. 385 repeated Direction column_directions = 8; 386 387 // An ordered list of column names which the index stores in addition to the 388 // columns which are explicitly part of the index (STORING clause). Only used 389 // for secondary indexes. 390 repeated string store_column_names = 5; 391 392 // An ordered list of column IDs of which the index is comprised. This list 393 // parallels the column_names list and does not include any additional stored 394 // columns. 395 repeated uint32 column_ids = 6 [(gogoproto.customname) = "ColumnIDs", 396 (gogoproto.casttype) = "ColumnID"]; 397 398 // An ordered list of IDs for the additional columns associated with the 399 // index: 400 // - implicit columns, which are all the primary key columns that are not 401 // already part of the index (i.e. PrimaryIndex.column_ids - column_ids). 402 // - stored columns (the columns in store_column_names) if this index uses the 403 // old STORING encoding (key-encoded data). 404 // 405 // Only used for secondary indexes. 406 // For non-unique indexes, these columns are appended to the key. 407 // For unique indexes, these columns are stored in the value (unless the key 408 // contains a NULL value: then the extra columns are appended to the key to 409 // unique-ify it). 410 // This distinction exists because we want to be able to insert an entry using 411 // a single conditional put on the key. 412 repeated uint32 extra_column_ids = 7 [(gogoproto.customname) = "ExtraColumnIDs", 413 (gogoproto.casttype) = "ColumnID"]; 414 415 // An ordered list of column IDs that parallels store_column_names if this 416 // index uses the new STORING encoding (value-encoded data, always in the KV 417 // value). 418 repeated uint32 store_column_ids = 14 419 [(gogoproto.customname) = "StoreColumnIDs", (gogoproto.casttype) = "ColumnID"]; 420 421 // CompositeColumnIDs contains an ordered list of IDs of columns that appear 422 // in the index and have a composite encoding. Includes IDs from both 423 // column_ids and extra_column_ids. 424 repeated uint32 composite_column_ids = 13 425 [(gogoproto.customname) = "CompositeColumnIDs", (gogoproto.casttype) = "ColumnID"]; 426 427 // ForeignKey and ReferencedBy are deprecated and not stored from 19.2 onward. 428 optional ForeignKeyReference foreign_key = 9 [(gogoproto.nullable) = false, deprecated = true]; 429 repeated ForeignKeyReference referenced_by = 10 [(gogoproto.nullable) = false, deprecated = true]; 430 431 // Interleave, if it's not the zero value, describes how this index's data is 432 // interleaved into another index's data. 433 optional InterleaveDescriptor interleave = 11 [(gogoproto.nullable) = false]; 434 435 // InterleavedBy contains a reference to every table/index that is interleaved 436 // into this one. 437 // 438 // Note that any of these indexes can themselves be interleaved by other 439 // tables but this list contains only those for which this index is a direct 440 // interleave parent. 441 // 442 // Only the Table and Index fields of the ForeignKeyReference are used. And 443 // despite the message used here, interleavings don't have to have 444 // corresponding foreign key references (and whether they do or not is 445 // irrelevant for this field). 446 repeated ForeignKeyReference interleaved_by = 12 [(gogoproto.nullable) = false]; 447 448 // Partitioning, if it's not the zero value, describes how this index's data 449 // is partitioned into spans of keys each addressable by zone configs. 450 optional PartitioningDescriptor partitioning = 15 [(gogoproto.nullable) = false]; 451 452 // Type is the type of index, inverted or forward. 453 optional Type type = 16 [(gogoproto.nullable)=false]; 454 455 // CreatedExplicitly specifies whether this index was created explicitly 456 // (i.e. via 'CREATE INDEX' statement). 457 optional bool created_explicitly = 17 [(gogoproto.nullable) = false]; 458 459 // EncodingType represents what sort of k/v encoding is used to store this descriptor on disk. 460 // As of now, this includes the existing secondary index encoding, or the primary index encoding. 461 // N.B. This field is only recognized on secondary indexes. 462 optional uint32 encoding_type = 19 463 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexDescriptorEncodingType"]; 464 465 // Sharded, if it's not the zero value, describes how this index is sharded. 466 optional ShardedDescriptor sharded = 20 [(gogoproto.nullable) = false]; 467 468 // Disabled is used by the DROP PRIMARY KEY command to mark 469 // that this index is disabled for further use. 470 optional bool disabled = 21 [(gogoproto.nullable) = false]; 471 472 // GeoConfig, if it's not the zero value, describes configuration for 473 // this geospatial inverted index. 474 optional geo.geoindex.Config geo_config = 22 [(gogoproto.nullable) = false]; 475 476 // Predicate, if it's not empty, indicates that the index is a partial index 477 // with Predicate as the expression. If Predicate is empty, the index is not 478 // a partial index. Columns are referred to in the expression by their name. 479 // TODO(mgartner): Update the comment to explain that columns are referenced 480 // by their ID once #49766 is addressed. 481 optional string predicate = 23 [(gogoproto.nullable) = false]; 482 } 483 484 // ConstraintToUpdate represents a constraint to be added to the table and 485 // validated for existing rows. More generally, in the future, when we support 486 // adding constraints that are unvalidated for existing rows and can be 487 // validated later using VALIDATE CONSTRAINT, this mutation will also represent 488 // either adding an unvalidated constraint or validating an existing constraint. 489 // 490 // This mutation effects changes only in the backfill step of the schema 491 // changer: First, a new version of the table descriptor with the constraint 492 // added is published, after all columns being added have been backfilled. After 493 // waiting for the constraint to be enforced for writes on all nodes, the 494 // constraint is then validated for all existing rows. This ensures that 495 // constraints added to columns that are being added are correctly enforced 496 // before the column becomes public. 497 message ConstraintToUpdate { 498 option (gogoproto.equal) = true; 499 enum ConstraintType { 500 CHECK = 0; 501 FOREIGN_KEY = 1; 502 // NOT NULL constraints being added are represented by a dummy check 503 // constraint so that a multi-state schema change, including a bulk 504 // validation step, can occur. The check field contains the dummy 505 // constraint. 506 NOT_NULL = 2; 507 } 508 required ConstraintType constraint_type = 1 [(gogoproto.nullable) = false]; 509 required string name = 2 [(gogoproto.nullable) = false]; 510 optional TableDescriptor.CheckConstraint check = 3 [(gogoproto.nullable) = false]; 511 // All fields past 3 haven't been persisted before 19.2. 512 optional ForeignKeyConstraint foreign_key = 4 [(gogoproto.nullable) = false]; 513 reserved 5; 514 optional uint32 not_null_column = 6 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ColumnID"]; 515 } 516 517 // PrimaryKeySwap is a mutation corresponding to the atomic swap phase 518 // during a primary key change where old versions of indexes are exchanged for 519 // updated versions, and the table's new primary key is written into the descriptor. 520 message PrimaryKeySwap { 521 option (gogoproto.equal) = true; 522 // old_primary_index_id is the ID of the old primary index for the table. 523 optional uint32 old_primary_index_id = 4 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID"]; 524 // new_primary_index_id is the ID of the new primary index for the table. 525 optional uint32 new_primary_index_id = 1 [(gogoproto.nullable) = false, (gogoproto.casttype) = "IndexID"]; 526 // old_indexes and new_indexes are lists of IndexID's where the i'th index in old_indexes will be 527 // swapped out with the i'th index in new_indexes. 528 repeated uint32 old_indexes = 2 [(gogoproto.casttype) = "IndexID"]; 529 repeated uint32 new_indexes = 3 [(gogoproto.casttype) = "IndexID"]; 530 } 531 532 // ComputedColumnSwap is a mutation corresponding to the atomic swap phase 533 // where Column a' that is computed using Column a is swapped to replace 534 // Column a while Column a becomes computed using a'. 535 message ComputedColumnSwap { 536 option (gogoproto.equal) = true; 537 optional uint32 new_column_id = 1 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ColumnID"]; 538 optional uint32 old_column_id = 2 [(gogoproto.nullable) = false, (gogoproto.casttype) = "ColumnID"]; 539 } 540 541 // A DescriptorMutation represents a column or an index that 542 // has either been added or dropped and hasn't yet transitioned 543 // into a stable state: completely backfilled and visible, or 544 // completely deleted. A table descriptor in the middle of a 545 // schema change will have a DescriptorMutation FIFO queue 546 // containing each column/index descriptor being added or dropped. 547 // Mutations for constraints work differently from columns and 548 // indexes; see the documentation for ConstraintToUpdate. 549 message DescriptorMutation { 550 option (gogoproto.equal) = true; 551 oneof descriptor { 552 ColumnDescriptor column = 1; 553 IndexDescriptor index = 2; 554 ConstraintToUpdate constraint = 8; 555 PrimaryKeySwap primaryKeySwap = 9; 556 ComputedColumnSwap computedColumnSwap = 10; 557 } 558 // A descriptor within a mutation is unavailable for reads, writes 559 // and deletes. It is only available for implicit (internal to 560 // the database) writes and deletes depending on the state of the mutation. 561 enum State { 562 // Not used. 563 UNKNOWN = 0; 564 // Operations can use this invisible descriptor to implicitly 565 // delete entries. 566 // Column: A descriptor in this state is invisible to 567 // INSERT and UPDATE. DELETE must delete a column in this state. 568 // Index: A descriptor in this state is invisible to an INSERT. 569 // UPDATE must delete the old value of the index but doesn't write 570 // the new value. DELETE must delete the index. 571 // 572 // When deleting a descriptor, all descriptor related data 573 // (column or index data) can only be mass deleted once 574 // all the nodes have transitioned to the DELETE_ONLY state. 575 DELETE_ONLY = 1; 576 // Operations can use this invisible descriptor to implicitly 577 // write and delete entries. 578 // Column: INSERT will populate this column with the default 579 // value. UPDATE ignores this descriptor. DELETE must delete 580 // the column. 581 // Index: INSERT, UPDATE and DELETE treat this index like any 582 // other index. 583 // 584 // When adding a descriptor, all descriptor related data 585 // (column default or index data) can only be backfilled once 586 // all nodes have transitioned into the DELETE_AND_WRITE_ONLY state. 587 DELETE_AND_WRITE_ONLY = 2; 588 } 589 optional State state = 3 [(gogoproto.nullable) = false]; 590 591 // Direction of mutation. 592 enum Direction { 593 // Not used. 594 NONE = 0; 595 // Descriptor is being added. 596 ADD = 1; 597 // Descriptor is being dropped. 598 DROP = 2; 599 } 600 optional Direction direction = 4 [(gogoproto.nullable) = false]; 601 602 // The mutation id used to group mutations that should be applied together. 603 // This is used for situations like creating a unique column, which 604 // involve adding two mutations: one for the column, and another for the 605 // unique constraint index. 606 optional uint32 mutation_id = 5 [(gogoproto.nullable) = false, 607 (gogoproto.customname) = "MutationID", (gogoproto.casttype) = "MutationID"]; 608 reserved 6; 609 610 // Indicates that this mutation is a rollback. 611 optional bool rollback = 7 [(gogoproto.nullable) = false]; 612 } 613 614 // A TableDescriptor represents a table or view and is stored in a 615 // structured metadata key. The TableDescriptor has a globally-unique ID, 616 // while its member {Column,Index}Descriptors have locally-unique IDs. 617 message TableDescriptor { 618 option (gogoproto.equal) = true; 619 // Needed for the descriptorProto interface. 620 option (gogoproto.goproto_getters) = true; 621 622 // The table name. It should be normalized using NormalizeName() before 623 // comparing it. 624 optional string name = 1 [(gogoproto.nullable) = false]; 625 optional uint32 id = 3 [(gogoproto.nullable) = false, 626 (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"]; 627 // ID of the parent database. 628 optional uint32 parent_id = 4 [(gogoproto.nullable) = false, 629 (gogoproto.customname) = "ParentID", (gogoproto.casttype) = "ID"]; 630 // ID of the parent schema. For backwards compatibility, 0 means the table is 631 // scoped under the public physical schema (id 29). Because of this backward 632 // compatibility issue, this field should not be accessed directly or through 633 // the generated getter. Instead, use GetParentSchemaID() which is defined in 634 // structured.go. 635 optional uint32 unexposed_parent_schema_id = 40 [(gogoproto.nullable) = false, 636 (gogoproto.customname) = "UnexposedParentSchemaID", (gogoproto.casttype) = "ID"]; 637 // Monotonically increasing version of the table descriptor. 638 // 639 // The design maintains two invariants: 640 // 1. Two safe versions: A transaction at a particular timestamp is 641 // allowed to use one of two versions of a table descriptor: 642 // the one that would be read from the store at that timestamp, 643 // and the one behind it in version. 644 // 2. Two leased versions: There can be valid leases on at most the 2 645 // latest versions of a table in the cluster at any time. New leases 646 // are only granted on the latest version. 647 // 648 // The database must maintain correctness in light of there being two 649 // versions of a descriptor that can be used. 650 // 651 // Multiple schema change mutations can be grouped together on a 652 // particular version increment. 653 optional uint32 version = 5 [(gogoproto.nullable) = false, (gogoproto.casttype) = "DescriptorVersion"]; 654 655 reserved 6; 656 657 // Last modification time of the table descriptor. 658 // Starting in 19.2 this field's value may sometime be zero-valued in which 659 // case the MVCC timestamp of the row containing the value should be used to 660 // populate it. This dance allows us to avoid observing the commit timestamp 661 // for transactions which increment the descriptor version. 662 // Encoded TableDescriptor structs should not be stored directly but rather 663 // should live inside of a Descriptor. The Descriptor.Table() method takes an 664 // hlc timestamp to ensure that this field is set properly when extracted from 665 // a Descriptor. 666 optional util.hlc.Timestamp modification_time = 7 [(gogoproto.nullable) = false]; 667 repeated ColumnDescriptor columns = 8 [(gogoproto.nullable) = false]; 668 // next_column_id is used to ensure that deleted column ids are not reused. 669 optional uint32 next_column_id = 9 [(gogoproto.nullable) = false, 670 (gogoproto.customname) = "NextColumnID", (gogoproto.casttype) = "ColumnID"]; 671 // families holds information about the column families of this table. 672 // This list has at least length 1, in which case all columns are stored in the same family. 673 // families is stored in sorted order by family ID. 674 repeated ColumnFamilyDescriptor families = 22 [(gogoproto.nullable) = false]; 675 // next_family_id is used to ensure that deleted family ids are not reused. 676 optional uint32 next_family_id = 23 [(gogoproto.nullable) = false, 677 (gogoproto.customname) = "NextFamilyID", (gogoproto.casttype) = "FamilyID"]; 678 optional IndexDescriptor primary_index = 10 [(gogoproto.nullable) = false]; 679 // indexes are all the secondary indexes. 680 repeated IndexDescriptor indexes = 11 [(gogoproto.nullable) = false]; 681 // next_index_id is used to ensure that deleted index ids are not reused. 682 optional uint32 next_index_id = 12 [(gogoproto.nullable) = false, 683 (gogoproto.customname) = "NextIndexID", (gogoproto.casttype) = "IndexID"]; 684 optional PrivilegeDescriptor privileges = 13; 685 // Columns or indexes being added or deleted in a FIFO order. 686 repeated DescriptorMutation mutations = 14 [(gogoproto.nullable) = false]; 687 // The schema update lease. A single goroutine across a cockroach cluster 688 // can own it, and will execute pending schema changes for this table. 689 // Since the execution of a pending schema change is through transactions, 690 // it is legal for more than one goroutine to attempt to execute it. This 691 // lease reduces write contention on the schema change. 692 message SchemaChangeLease { 693 option (gogoproto.equal) = true; 694 optional uint32 node_id = 1 [(gogoproto.nullable) = false, 695 (gogoproto.customname) = "NodeID", 696 (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.NodeID"]; 697 // Nanoseconds since the Unix epoch. 698 optional int64 expiration_time = 2 [(gogoproto.nullable) = false]; 699 } 700 optional SchemaChangeLease lease = 15 [deprecated = true]; 701 // An id for the next group of mutations to be applied together. 702 optional uint32 next_mutation_id = 16 [(gogoproto.nullable) = false, 703 (gogoproto.customname) = "NextMutationID", (gogoproto.casttype) = "MutationID"]; 704 705 // format_version declares which sql to key:value mapping is being used to 706 // represent the data in this table. 707 optional uint32 format_version = 17 [(gogoproto.nullable) = false, 708 (gogoproto.casttype) = "FormatVersion"]; 709 710 reserved 18; 711 712 // State is set if this TableDescriptor is in the process of being added or deleted. 713 // A non-public table descriptor cannot be leased. 714 // A schema changer observing DROP set will truncate the table and delete the 715 // descriptor. 716 // It is illegal to transition DROP to any other state. 717 enum State { 718 // Not used. 719 PUBLIC = 0; 720 // Descriptor is being added. 721 ADD = 1; 722 // Descriptor is being dropped. 723 DROP = 2; 724 // Descriptor is offline (e.g. for bulk-ingestion). See offline_reason. 725 OFFLINE = 3; 726 } 727 optional State state = 19 [(gogoproto.nullable) = false]; 728 optional string offline_reason = 38 [(gogoproto.nullable) = false]; 729 730 message CheckConstraint { 731 option (gogoproto.equal) = true; 732 // Expr is the expression that this check constraint represents. 733 // Note that it is not correct to use Expr as output to display 734 // to a user. User defined types within Expr have been serialized 735 // in a internal format. Instead, format the result of 736 // DeserializeTableDescExpr. 737 optional string expr = 1 [(gogoproto.nullable) = false]; 738 optional string name = 2 [(gogoproto.nullable) = false]; 739 optional ConstraintValidity validity = 3 [(gogoproto.nullable) = false]; 740 reserved 4; 741 // An ordered list of column IDs used by the check constraint. 742 repeated uint32 column_ids = 5 [(gogoproto.customname) = "ColumnIDs", 743 (gogoproto.casttype) = "ColumnID"]; 744 optional bool is_non_null_constraint = 6 [(gogoproto.nullable) = false]; 745 // Whether the check constraint should show up in the result of a `SHOW CREATE 746 // TABLE..` statement. 747 optional bool hidden = 7 [(gogoproto.nullable) = false]; 748 } 749 750 repeated CheckConstraint checks = 20; 751 752 // A table descriptor is named through a name map stored in the 753 // system.namespace table: a map from {parent_id, table_name} -> id. 754 // This name map can be cached for performance on a node in the cluster 755 // making reassigning a name complicated. In particular, since a 756 // name cannot be withdrawn across a cluster in a transaction at 757 // timestamp T, we have to worry about the following: 758 // 759 // 1. A table is dropped at T, and the name and descriptor are still 760 // cached and used by transactions at timestamps >= T. 761 // 2. A table is renamed from foo to bar at T, and both names foo and bar 762 // can be used by transactions at timestamps >= T. 763 // 3. A name foo is reassigned from one table to another at T, and the name 764 // foo can reference two different tables at timestamps >= T. 765 // 766 // The system ensures that a name can be resolved only to a single 767 // descriptor at a timestamp thereby permitting 1 and 2, but not 3 768 // (the name references two tables). 769 // 770 // The transaction at T is followed by a time period when names no longer 771 // a part of the namespace are drained from the system. Once the old name 772 // is drained from the system another transaction at timestamp S is 773 // executed to release the name for future use. The interval from T to S 774 // is called the name drain interval: If the T transaction is removing 775 // the name foo then, at timestamps above S, foo can no longer be resolved. 776 // 777 // Consider a transaction at T in which name B is dropped, a new name C is 778 // created. Name C is viable as soon as the transaction commits. 779 // When the transaction at S commits, the name B is released for reuse. 780 // 781 // The transaction at S runs through the schema changer, with the system 782 // returning a response to the client initiating transaction T only after 783 // transaction at S is committed. So effectively the SQL transaction once 784 // it returns can be followed by SQL transactions that do not observe 785 // old name mappings. 786 // 787 // Note: an exception to this is #19925 which needs to be fixed. 788 // 789 // In order for transaction at S to act properly the system.namespace 790 // table entry for an old name references the descriptor who was the 791 // prior owner of the name requiring draining. 792 // 793 // Before T: B -> Desc B 794 // 795 // After T and before S: B -> Desc B, C -> Desc C 796 // 797 // After S: C -> Desc C 798 // 799 // Between T and S the name B is drained and the system is unable 800 // to assign it to another descriptor. 801 // 802 // BEGIN; 803 // RENAME foo TO bar; 804 // CREATE foo; 805 // 806 // will fail because CREATE foo is executed at T. 807 // 808 // RENAME foo TO bar; 809 // CREATE foo; 810 // 811 // will succeed because the RENAME returns after S and CREATE foo is 812 // executed after S. 813 // 814 // The above scheme suffers from the problem that a transaction can observe 815 // the partial effect of a committed transaction during the drain interval. 816 // For instance during the drain interval a transaction can see the correct 817 // assignment for C, and the old assignments for B. 818 // 819 message NameInfo { 820 option (gogoproto.equal) = true; 821 // The database that the table belonged to before the rename (tables can be 822 // renamed from one db to another). 823 optional uint32 parent_id = 1 [(gogoproto.nullable) = false, 824 (gogoproto.customname) = "ParentID", (gogoproto.casttype) = "ID"]; 825 // The schemaID of the schema the table belongs to before the rename/drop. 826 // Required to correctly identify which namespace entry to reclaim. 827 optional uint32 parent_schema_id = 3 [(gogoproto.nullable) = false, 828 (gogoproto.customname) = "ParentSchemaID", (gogoproto.casttype) = "ID"]; 829 optional string name = 2 [(gogoproto.nullable) = false]; 830 } 831 832 // A list of draining names. The draining name entries are drained from 833 // the cluster wide name caches by incrementing the version for this 834 // descriptor and ensuring that there are no leases on prior 835 // versions of the descriptor. This field is then cleared and the version 836 // of the descriptor incremented. 837 repeated NameInfo draining_names = 21 [(gogoproto.nullable) = false]; 838 839 // The TableDescriptor is used for views in addition to tables. Views 840 // use mostly the same fields as tables, but need to track the actual 841 // query from the view definition as well. 842 // 843 // For now we only track a string representation of the query. This prevents 844 // us from easily supporting things like renames of the dependencies of a 845 // view. Eventually we'll want to switch to a semantic encoding of the query 846 // that relies on IDs rather than names so that we can support renames of 847 // fields relied on by the query, as Postgres does. 848 // 849 // Note: The presence of this field is used to determine whether or not 850 // a TableDescriptor represents a view. 851 optional string view_query = 24 [(gogoproto.nullable) = false]; 852 853 // The IDs of all relations that this depends on. 854 // Only ever populated if this descriptor is for a view. 855 repeated uint32 dependsOn = 25 [(gogoproto.customname) = "DependsOn", 856 (gogoproto.casttype) = "ID"]; 857 858 message Reference { 859 option (gogoproto.equal) = true; 860 // The ID of the relation that depends on this one. 861 optional uint32 id = 1 [(gogoproto.nullable) = false, 862 (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"]; 863 // If applicable, the ID of this table's index that is referenced by the 864 // dependent relation. 865 optional uint32 index_id = 2 [(gogoproto.nullable) = false, 866 (gogoproto.customname) = "IndexID", (gogoproto.casttype) = "IndexID"]; 867 // The IDs of this table's columns that are referenced by the dependent 868 // relation. 869 repeated uint32 column_ids = 3 [(gogoproto.customname) = "ColumnIDs", 870 (gogoproto.casttype) = "ColumnID"]; 871 } 872 873 // All references to this table/view from other views and sequences in the system, 874 // tracked down to the column/index so that we can restrict changes to them while 875 // they're still being referred to. 876 repeated Reference dependedOnBy = 26 [(gogoproto.nullable) = false, 877 (gogoproto.customname) = "DependedOnBy"]; 878 879 message MutationJob { 880 option (gogoproto.equal) = true; 881 // The mutation id of this mutation job. 882 optional uint32 mutation_id = 1 [(gogoproto.nullable) = false, 883 (gogoproto.customname) = "MutationID", (gogoproto.casttype) = "MutationID"]; 884 885 // The job id for a mutation job is the id in the system.jobs table of the 886 // schema change job executing the mutation referenced by mutation_id. 887 optional int64 job_id = 2 [(gogoproto.nullable) = false, 888 (gogoproto.customname) = "JobID"]; 889 } 890 891 // Mutation jobs queued for execution in a FIFO order. Remains synchronized 892 // with the mutations list. 893 repeated MutationJob mutationJobs = 27 [(gogoproto.nullable) = false]; 894 895 message SequenceOpts { 896 option (gogoproto.equal) = true; 897 // How much to increment the sequence by when nextval() is called. 898 optional int64 increment = 1 [(gogoproto.nullable) = false]; 899 // Minimum value of the sequence. 900 optional int64 min_value = 2 [(gogoproto.nullable) = false]; 901 // Maximum value of the sequence. 902 optional int64 max_value = 3 [(gogoproto.nullable) = false]; 903 // Start value of the sequence. 904 optional int64 start = 4 [(gogoproto.nullable) = false]; 905 // Whether the sequence is virtual. 906 optional bool virtual = 5 [(gogoproto.nullable) = false]; 907 908 message SequenceOwner { 909 option (gogoproto.equal) = true; 910 // Sequence Owner's Column ID 911 optional uint32 owner_column_id = 1 [(gogoproto.nullable) = false, 912 (gogoproto.customname) = "OwnerColumnID", 913 (gogoproto.casttype) = "ColumnID"]; 914 // Sequence Owner's Table ID 915 optional uint32 owner_table_id = 2 [(gogoproto.nullable) = false, 916 (gogoproto.customname) = "OwnerTableID", 917 (gogoproto.casttype) = "ID"]; 918 } 919 920 optional SequenceOwner sequence_owner = 6 [(gogoproto.nullable) = false]; 921 } 922 923 // The presence of sequence_opts indicates that this descriptor is for a sequence. 924 optional SequenceOpts sequence_opts = 28; 925 926 // The drop time is set when a table is truncated or dropped, 927 // based on the current time in nanoseconds since the epoch. 928 // Use this timestamp + GC TTL to start deleting the table's 929 // contents. 930 // 931 // TODO(vivek): Replace with the ModificationTime. This has been 932 // added only for migration purposes. 933 optional int64 drop_time = 29 [(gogoproto.nullable) = false]; 934 935 message Replacement { 936 option (gogoproto.equal) = true; 937 optional uint32 id = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"]; 938 // Time is just used for debugging purposes. It is not used in business 939 // logic. It is an HLC rather than just wall time only for historical 940 // reasons. Prior to 20.1 it was populated with the commit timestamp of the 941 // transaction which created this replacement. In 20.1 and after it is 942 // populated with the read timestamp at which the descriptor being 943 // replaced was read. 944 optional util.hlc.Timestamp time = 2 [(gogoproto.nullable) = false]; 945 } 946 947 // ReplacementOf tracks prior IDs by which this table went -- e.g. when 948 // TRUNCATE creates a replacement of a table and swaps it in for the the old 949 // one, it should note on the new table the ID of the table it replaced. This 950 // can be used when trying to track a table's history across truncatations. 951 optional Replacement replacement_of = 30 [(gogoproto.nullable) = false]; 952 953 // AuditMode indicates which auditing actions to take when this table is used. 954 enum AuditMode { 955 DISABLED = 0; 956 READWRITE = 1; 957 } 958 optional AuditMode audit_mode = 31 [(gogoproto.nullable) = false]; 959 960 // The job id for a drop job is the id in the system.jobs table of the 961 // dropping of this table. 962 optional int64 drop_job_id = 32 [(gogoproto.nullable) = false, (gogoproto.customname) = "DropJobID"]; 963 964 message GCDescriptorMutation { 965 option (gogoproto.equal) = true; 966 optional int64 index_id = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "IndexID", 967 (gogoproto.casttype) = "IndexID"]; 968 969 optional int64 drop_time = 2 [(gogoproto.nullable) = false, deprecated = true]; 970 971 // The job id for a mutation job is the id in the system.jobs table of the 972 // schema change job executing the mutation referenced by mutation_id. 973 optional int64 job_id = 3 [(gogoproto.nullable) = false, 974 (gogoproto.customname) = "JobID", deprecated = true]; 975 } 976 977 // The schema elements that have been dropped and whose underlying 978 // data needs to be gc-ed. These schema elements have already transitioned 979 // through the drop state machine when they were in the above mutations 980 // list, and can be safely deleted. The names for these schema elements 981 // can be reused. This list is separate because mutations can 982 // lie in this list for a long time (gc deadline) and should not block 983 // the execution of other schema changes on the table. 984 // 985 // TODO(vivekmenezes): This is currently only used by the non-interleaved drop 986 // index case. Also use for dropped interleaved indexes and columns. 987 repeated GCDescriptorMutation gc_mutations = 33 [(gogoproto.nullable) = false, 988 (gogoproto.customname) = "GCMutations"]; 989 990 optional string create_query = 34 [(gogoproto.nullable) = false]; 991 992 // Starting in 19.2 CreateAsOfTime is initialized to zero for the first 993 // version of a table and is populated from the MVCC timestamp of the read 994 // like ModificationTime. See Descriptor.Table(). 995 // CreateAsOfSystemTime is used for CREATE TABLE ... AS ... and was 996 // added in 19.1. 997 optional util.hlc.Timestamp create_as_of_time = 35 [(gogoproto.nullable) = false]; 998 999 // outbound_fks contains all foreign key constraints that have this table as 1000 // the origin table. 1001 repeated ForeignKeyConstraint outbound_fks = 36 [(gogoproto.nullable) = false, (gogoproto.customname) = "OutboundFKs"]; 1002 // inbound_fks contains all foreign key constraints that have this table as 1003 // the referenced table. 1004 repeated ForeignKeyConstraint inbound_fks = 37 [(gogoproto.nullable) = false, (gogoproto.customname) = "InboundFKs"]; 1005 1006 // Temporary table support will be added to CRDB starting from 20.1. The temporary 1007 // flag is set to true for all temporary tables. All table descriptors created 1008 // before 20.1 refer to persistent tables, so lack of the flag being set implies 1009 // the table is persistent. 1010 optional bool temporary = 39 [(gogoproto.nullable) = false]; 1011 } 1012 1013 // DatabaseDescriptor represents a namespace (aka database) and is stored 1014 // in a structured metadata key. The DatabaseDescriptor has a globally-unique ID 1015 // shared with other Descriptors. 1016 // Permissions are applied to all tables in the namespace. 1017 message DatabaseDescriptor { 1018 option (gogoproto.equal) = true; 1019 // Needed for the descriptorProto interface. 1020 option (gogoproto.goproto_getters) = true; 1021 1022 optional string name = 1 [(gogoproto.nullable) = false]; 1023 optional uint32 id = 2 [(gogoproto.nullable) = false, 1024 (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"]; 1025 optional PrivilegeDescriptor privileges = 3; 1026 } 1027 1028 // TypeDescriptor represents a user defined type and is stored in a structured 1029 // metadata key. The TypeDescriptor has a globally-unique ID shared with other 1030 // Descriptors. 1031 message TypeDescriptor { 1032 option (gogoproto.equal) = true; 1033 // Needed for the descriptorProto interface. 1034 option (gogoproto.goproto_getters) = true; 1035 1036 // Fields that are shared among all kinds of user defined types. 1037 1038 // parent_id represents the ID of the database that this type resides in. 1039 optional uint32 parent_id = 1 1040 [(gogoproto.nullable) = false, (gogoproto.customname) = "ParentID", (gogoproto.casttype) = "ID"]; 1041 1042 // parent_schema_id represents the ID of the schema that this type resides in. 1043 optional uint32 parent_schema_id = 2 1044 [(gogoproto.nullable) = false, (gogoproto.customname) = "ParentSchemaID", (gogoproto.casttype) = "ID"]; 1045 1046 // name is the current name of this user defined type. 1047 optional string name = 3 [(gogoproto.nullable) = false]; 1048 1049 // id is the globally unique ID for this type. 1050 optional uint32 id = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"]; 1051 1052 // array_type_id is the globally unique ID for the implicitly created array 1053 // type for this type. It is only set when the type descriptor points to a 1054 // non-array type. 1055 optional uint32 array_type_id = 8 1056 [(gogoproto.nullable) = false, (gogoproto.customname) = "ArrayTypeID", (gogoproto.casttype) = "ID"]; 1057 1058 // Represents the kind of type that this type descriptor represents. 1059 enum Kind { 1060 // Represents a user defined enum type. 1061 ENUM = 0; 1062 // Represents a user defined type that is just an alias for another type. 1063 // As of now, it is used only internally. 1064 ALIAS = 1; 1065 // Add more entries as we support more user defined types. 1066 } 1067 optional Kind kind = 5 [(gogoproto.nullable) = false]; 1068 1069 // The fields below are used only when this type is an ENUM type. 1070 1071 // EnumMember represents a value in an enum. 1072 message EnumMember { 1073 option (gogoproto.equal) = true; 1074 optional bytes physical_representation = 1; 1075 optional string logical_representation = 2 [(gogoproto.nullable) = false]; 1076 // TODO (rohany): Add the state here. 1077 } 1078 // enum_members is the set of values in an enum. 1079 repeated EnumMember enum_members = 6 [(gogoproto.nullable) = false]; 1080 1081 // The fields below are used only when this type is an ALIAS type. 1082 1083 // alias is the types.T that this descriptor is an alias for. 1084 optional sql.sem.types.T alias = 7; 1085 1086 // TODO (rohany): Do we need a draining names like the table descriptor? 1087 } 1088 1089 // SchemaDescriptor represents a physical schema and is stored in a structured 1090 // metadata key. 1091 message SchemaDescriptor { 1092 option (gogoproto.equal) = true; 1093 // Needed for the descriptorProto interface. 1094 option (gogoproto.goproto_getters) = true; 1095 1096 // parent_id refers to the database the schema is in. 1097 optional uint32 parent_id = 1 1098 [(gogoproto.nullable) = false, (gogoproto.customname) = "ParentID", (gogoproto.casttype) = "ID"]; 1099 1100 // name is the name of the schema. 1101 optional string name = 2 [(gogoproto.nullable) = false]; 1102 1103 // id is the schema ID, globally unique across all descriptors. 1104 optional uint32 id = 3 1105 [(gogoproto.nullable) = false, (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"]; 1106 1107 // privileges contains the privileges for the schema. 1108 optional PrivilegeDescriptor privileges = 4; 1109 } 1110 1111 // Descriptor is a union type for descriptors for tables, schemas, databases, 1112 // and types. 1113 message Descriptor { 1114 option (gogoproto.equal) = true; 1115 oneof union { 1116 TableDescriptor table = 1; 1117 DatabaseDescriptor database = 2; 1118 TypeDescriptor type = 3; 1119 SchemaDescriptor schema = 4; 1120 } 1121 }