{"modulePath":"github.com/phobos182/cockroach","version":"v0.0.0-20160330191133-bf013fd33fc2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sql\n\nPackage sql provides the user-facing API for access to a Cockroach datastore. As the name suggests, the API is based around SQL, the same SQL you find in traditional RDMBS systems like Oracle, MySQL or Postgres. The core Cockroach system implements a distributed, transactional, monolithic sorted key-value map. The sql package builds on top of this core system adding parsing, query planning and query execution as well as defining the privilege model.\n\n### Databases and Tables {#hdr-Databases_and_Tables}\n\nThe two primary objects are databases and tables. A database is a namespace which holds a series of tables. Conceptually, a database can be viewed like a directory in a filesystem plus some additional metadata (privileges). A table is like a file on steroids: containing a structured layout of rows and columns along with secondary indexes.\n\nLike a directory, a database has a name and metadata. The metadata is defined by the DatabaseDescriptor:\n\n\tmessage DatabaseDescriptor {\n\t  optional string name;\n\t  optional uint32 id;\n\t  optional PrivilegeDescriptor privileges;\n\t}\n\nSimilarly, tables have a TableDescriptor:\n\n\tmessage TableDescriptor {\n\t  optional string name;\n\t  optional uint32 id;\n\t  repeated ColumnDescriptor columns;\n\t  optional IndexDescriptor primary_index;\n\t  repeated IndexDescriptor indexes;\n\t  optional PrivilegeDescriptor privileges;\n\t}\n\nBoth the database ID and the table ID are allocate from the same \"ID space\" and IDs are never reused.\n\nThe namespace in which databases and tables exist contains only two levels: the root level contains databases and the database level contains tables. The \"system.namespace\" and \"system.descriptor\" tables implement the mapping from database/table name to ID and from ID to descriptor:\n\n\tCREATE TABLE system.namespace (\n\t  \"parentID\" INT,\n\t  \"name\"     CHAR,\n\t  \"id\"       INT,\n\t  PRIMARY KEY (parentID, name)\n\t);\n\n\tCREATE TABLE system.descriptor (\n\t  \"id\"         INT PRIMARY KEY,\n\t  \"descriptor\" BLOB\n\t);\n\nThe reserved ID of 0 is used for the \"root\" of the namespace in which the databases reside. In order to lookup the ID of a database given its name, the system effectively does a query like:\n\n\tSELECT id FROM system.namespace WHERE parentID = 0 AND name = \u003cdatabase-name\u003e\n\nAnd given a database/table ID, the system looks up the descriptor using a query like:\n\n\tSELECT descriptor FROM system.descriptor WHERE id = \u003cID\u003e\n\n### Primary Key Addressing {#hdr-Primary_Key_Addressing}\n\nAll of the SQL data stored in tables is mapped down to keys and values. This mapping is referred to as key addressing. All tables have a primary key, whether explicitly listed in the schema or automatically generated. Note that a primary key is unrelated to the core Cockroach key-value functionality and is instead referring to the primary key for a SQL table.\n\nThe primary key consists of one or more non-NULL columns from the table. For a given row of the table, the columns for the primary key are encoded into a single string using the routines in util/encoding. These routines allow for the encoding of NULL values, integers, floating pointer numbers and strings in such a way that lexicographic ordering of the encoded strings corresponds to the same ordering of the unencoded data. Using \"system.namespace\" as an example, the primary key columns would be encoded as:\n\n\t/parentID/name\n\n\\[Note that \"/\" is being used to disambiguate the components of the key. The actual encodings do not use \"/\"].\n\nBefore being stored in the monolothic key-value space, the encoded primary key columns are prefixed with the table ID and an ID indicating that the key corresponds to the primary index:\n\n\t/TableID/PrimaryIndexID/parentID/name\n\nThe column data associated with a row in a table is stored within the primary index which is the index associated with the primary key. Every column has a unique ID (that is local to the table). The value for a column is stored at the key:\n\n\t/TableID/PrimaryIndexID/parentID/name/ColumnID -\u003e Value\n\nA column containing a NULL value is not stored in the monolithic map. In order to detect rows which only contain NULL values in non-primary key columns, every row has a sentinel key indicating its existence. The sentinel key is simply the primary index key:\n\n\t/TableID/PrimaryIndexID/parentID/name -\u003e NULL\n\nAs an optimization, columns that are part of the primary key are not stored separately as their data can be decoded from the sentinel value.\n\n### Secondary Indexes {#hdr-Secondary_Indexes}\n\nDespite not being a formal part of SQL, secondary indexes are one of its most powerful features. Secondary indexes are a level of indirection that allow quick lookup of a row using something other than the primary key. As an example, we can imagine creating a secondary index on the \"system.namespace\" table:\n\n\tCREATE INDEX name ON system.namespace (name);\n\nThis would create a \"name\" index composed solely of the \"name\" column. The key addressing for this non-unique index looks like:\n\n\t/TableId/SecondaryIndexID/name/parentID -\u003e NULL\n\nNotice that while the index is on \"name\", the key contains both \"name\" and \"parentID\". This is done to ensure that each row for a table has a unique key for the non-unique index. In general, for a non-unique index we encoded the index's columns followed by any primary key columns that have not already been mentioned. This effectively transforms any non-unique index into a unique index.\n\nLet's suppose that we had instead defined the index as:\n\n\tCREATE UNIQUE INDEX name ON system.namespace (name, id);\n\nThe key addressing for a unique index looks like:\n\n\t/TableID/SecondaryID/name/ID -\u003e /parentID\n\nUnique index keys are defined like this so that a conditional put operation can fail if that key already exists for another row, thereby enforcing the uniqueness constraint. The value for a unique index is composed of any primary key columns that are not part of the index (\"parentID\" in this example).\n\n### Query Planning and Execution {#hdr-Query_Planning_and_Execution}\n\nQuery planning is the system which takes a parsed SQL statement (described by an abstract syntax tree) and creates an execution plan which is itself a tree consisting of a set of scan, join, group, sort and projection operations. For the bulk of SQL statements, query planning is straightforward: the complexity lies in SELECT.\n\nAt one end of the performance spectrum, an implementation of SELECT can be straightforward: do a full scan of the (joined) tables in the FROM clause, filter rows based on the WHERE clause, group the resulting rows based on the GROUP BY clause, filter those rows using the HAVING clause, sort using the ORDER BY clause. There are a number of steps, but they all have well defined semantics and are mostly just an exercise in software engineering: retrieve the rows as quickly as possible and then send them through the pipeline of filtering, grouping, filtering and sorting.\n\nAt the other end of the performance spectrum, query planners attempt to take advantage of secondary indexes to limit the data retrieved, make joining of data between two tables easier and faster and to avoid the need to sort data by retrieving it in a sorted or partially sorted form. The details of how we implement this are in flux and will continue to be in flux for the foreseeable future. This section is intended to provide a high-level overview of a few of the techniques involved.\n\nAfter parsing a SELECT query, the query planner performs semantic analysis to verify the queries correctness and to resolve names within the query to actual objects within the system. Let's consider the query:\n\n\tSELECT id FROM system.namespace WHERE parentID = 0 AND name = 'test'\n\nThis query would look up the ID of the database named \"test\". The query planner needs to resolve the \"system.namespace\" qualified name in the FROM clause to the appropriate TableDescriptor. It also needs to resolve the \"id\", \"parentID\" and \"name\" column references to the appropriate column descriptions with the \"system.namespace\" TableDescriptor. Lastly, as part of semantic analysis, the query planner verifies that the expressions in the select targets and the WHERE clause are valid (e.g. the WHERE clause evaluates to a boolean).\n\nFrom that starting point, the query planner then analyzes the GROUP BY and ORDER BY clauses, adding \"hidden\" targets for expressions used in those clauses that are not explicit targets of the query. In our example without a GROUP BY or ORDER BY clause we move straight to the next step: index selection. Index selection is the stage where the query planner selects the best index to scan and selects the start and end keys to use for scanning the index. Depending on the query, the query planner might even select multiple ranges to scan from an index or multiple ranges from different indexes.\n\nHow does the query planner decide which index to use and which range of the index to scan? We currently use a restricted form of value propagation in oder to determine the range of possible values for columns referenced in the WHERE clause. Using this range information, each index is examined to determine if it is a potential candidate and ranked according to its specificity. In addition to ranking indexes by the column value range information, they are ranked by how well they match the sorting required by the ORDER BY clause. Back to the example above, the range information would determine that:\n\n\tparentID \u003e= 0 AND parentID \u003c= 0 AND name \u003e= 'test' and name \u003c= 'test\n\nNotice that each column has a start and end value associated with it. Since there is only a single index on the \"system.namespace\" table, it is always selected. The start key is computed using the range information as:\n\n\t/system.descriptor/primary/0/test\n\nThe end key is computed as:\n\n\t/system.descriptor/primary/0/tesu\n\nThe \"tesu\" suffix is not a typo: the end key is computed as the \"prefix end key\" for the key \"/TableID/PrimaryIndexId/0/test\". This is done by incrementing the final byte of the key such that \"t\" becomes \"u\".\n\nOur example query thus only scans two key-value pairs:\n\n\t  /system.descriptor/primary/0/test    -\u003e NULL\n\t  /system.descriptor/primary/0/test/id -\u003e \u003cID\u003e\n\n\t\tPackage sql is a generated protocol buffer package.\n\n\t\tIt is generated from these files:\n\t\t\tcockroach/sql/privilege.proto\n\t\t\tcockroach/sql/structured.proto\n\n\t\tIt has these top-level messages:\n\t\t\tUserPrivileges\n\t\t\tPrivilegeDescriptor\n\t\t\tColumnType\n\t\t\tColumnDescriptor\n\t\t\tIndexDescriptor\n\t\t\tDescriptorMutation\n\t\t\tTableDescriptor\n\t\t\tDatabaseDescriptor\n\t\t\tDescriptor\n\n## Constants\n\n```go\nconst (\n\n\t// CodeUniquenessConstraintViolationError represents violations of uniqueness\n\t// constraints.\n\tCodeUniquenessConstraintViolationError string = \"23505\"\n\t// CodeTransactionAbortedError signals that the user tried to execute a\n\t// statement in the context of a SQL txn that's already aborted.\n\tCodeTransactionAbortedError string = \"25P02\"\n\t// CodeInternalError represents all internal cockroach errors, plus acts\n\t// as a catch-all for random errors for which we haven't implemented the\n\t// appropriate error code.\n\tCodeInternalError string = \"XX000\"\n\n\t// CodeRetriableError signals to the user that the SQL txn entered the\n\t// RESTART_WAIT state and that a RESTART statement should be issued.\n\tCodeRetriableError string = \"CR000\"\n\t// CodeTransactionCommittedError signals that the SQL txn is in the\n\t// COMMIT_WAIT state and a COMMIT statement should be issued.\n\tCodeTransactionCommittedError string = \"CR001\"\n)\n```\n\n```go\nconst (\n\t// PrimaryKeyIndexName is the name of the index for the primary key.\n\tPrimaryKeyIndexName = \"primary\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// LeaseDuration is the mean duration a lease will be acquired for. The\n\t// actual duration is jittered in the range\n\t// [0.75,1.25]*LeaseDuration. Exported for testing purposes only.\n\tLeaseDuration = 5 * time.Minute\n\t// MinLeaseDuration is the minimum duration a lease will have remaining upon\n\t// acquisition. Exported for testing purposes only.\n\tMinLeaseDuration = time.Minute\n)\n```\n\n```go\nvar (\n\tErrInvalidLengthPrivilege = fmt.Errorf(\"proto: negative length found during unmarshaling\")\n\tErrIntOverflowPrivilege   = fmt.Errorf(\"proto: integer overflow\")\n)\n```\n\n```go\nvar (\n\tErrInvalidLengthStructured = fmt.Errorf(\"proto: negative length found during unmarshaling\")\n\tErrIntOverflowStructured   = fmt.Errorf(\"proto: integer overflow\")\n)\n```\n\n```go\nvar (\n\n\t// SystemAllowedPrivileges describes the privileges allowed for each\n\t// system object. No user may have more than those privileges, and\n\t// the root user must have exactly those privileges.\n\t// CREATE|DROP|ALL should always be denied.\n\tSystemAllowedPrivileges = map[ID]privilege.List{\n\t\tkeys.SystemDatabaseID:  privilege.ReadData,\n\t\tkeys.NamespaceTableID:  privilege.ReadData,\n\t\tkeys.DescriptorTableID: privilege.ReadData,\n\t\tkeys.UsersTableID:      privilege.ReadWriteData,\n\t\tkeys.ZonesTableID:      privilege.ReadWriteData,\n\t\tkeys.LeaseTableID:      privilege.ReadWriteData,\n\t\tkeys.RangeEventTableID: privilege.ReadWriteData,\n\t\tkeys.UITableID:         privilege.ReadWriteData,\n\t}\n\n\t// NumSystemDescriptors should be set to the number of system descriptors\n\t// above (SystemDB and each system table). This is used by tests which need\n\t// to know the number of system descriptors intended for installation; it starts at\n\t// 1 for the SystemDB descriptor created above, and is incremented by every\n\t// call to createSystemTable().\n\tNumSystemDescriptors = 1\n)\n```\n\n```go\nvar ColumnType_Kind_name = map[int32]string{\n\t0: \"BOOL\",\n\t1: \"INT\",\n\t2: \"FLOAT\",\n\t3: \"DECIMAL\",\n\t4: \"DATE\",\n\t5: \"TIMESTAMP\",\n\t6: \"INTERVAL\",\n\t7: \"STRING\",\n\t8: \"BYTES\",\n}\n```\n\n```go\nvar ColumnType_Kind_value = map[string]int32{\n\t\"BOOL\":      0,\n\t\"INT\":       1,\n\t\"FLOAT\":     2,\n\t\"DECIMAL\":   3,\n\t\"DATE\":      4,\n\t\"TIMESTAMP\": 5,\n\t\"INTERVAL\":  6,\n\t\"STRING\":    7,\n\t\"BYTES\":     8,\n}\n```\n\n```go\nvar DescriptorMutation_Direction_name = map[int32]string{\n\t0: \"NONE\",\n\t1: \"ADD\",\n\t2: \"DROP\",\n}\n```\n\n```go\nvar DescriptorMutation_Direction_value = map[string]int32{\n\t\"NONE\": 0,\n\t\"ADD\":  1,\n\t\"DROP\": 2,\n}\n```\n\n```go\nvar DescriptorMutation_State_name = map[int32]string{\n\t0: \"UNKNOWN\",\n\t1: \"DELETE_ONLY\",\n\t2: \"WRITE_ONLY\",\n}\n```\n\n```go\nvar DescriptorMutation_State_value = map[string]int32{\n\t\"UNKNOWN\":     0,\n\t\"DELETE_ONLY\": 1,\n\t\"WRITE_ONLY\":  2,\n}\n```\n\n```go\nvar IndexDescriptor_Direction_name = map[int32]string{\n\t0: \"ASC\",\n\t1: \"DESC\",\n}\n```\n\n```go\nvar IndexDescriptor_Direction_value = map[string]int32{\n\t\"ASC\":  0,\n\t\"DESC\": 1,\n}\n```\n\n## Functions\n\n```go\nfunc AddEventLogToMetadataSchema(schema *MetadataSchema)\n```\nAddEventLogToMetadataSchema adds the event log table to the supplied MetadataSchema.\n\n```go\nfunc GetZoneConfig(cfg config.SystemConfig, id uint32) (*config.ZoneConfig, error)\n```\nGetZoneConfig returns the zone config for the object with 'id'.\n\n```go\nfunc MakeDescMetadataKey(descID ID) roachpb.Key\n```\nMakeDescMetadataKey returns the key for the descriptor.\n\n```go\nfunc MakeIndexKeyPrefix(tableID ID, indexID IndexID) []byte\n```\nMakeIndexKeyPrefix returns the key prefix used for the index's data.\n\n```go\nfunc MakeNameMetadataKey(parentID ID, name string) roachpb.Key\n```\nMakeNameMetadataKey returns the key for the name. Pass name == \"\" in order to generate the prefix key to use to scan over all of the names for the specified parentID.\n\n```go\nfunc MakeZoneKey(id ID) roachpb.Key\n```\nMakeZoneKey returns the key for 'id's entry in the system.zones table.\n\n```go\nfunc NormalizeName(name string) string\n```\nNormalizeName normalizes to lowercase and Unicode Normalization Form C (NFC).\n\n```go\nfunc SetKVBatchSize(val int64) func()\n```\nSetKVBatchSize changes the kvFetcher batch size, and returns a function that restores it.\n\n```go\nfunc TestDisableAsyncSchemaChangeExec() func()\n```\nTestDisableAsyncSchemaChangeExec is used in tests to disable the asynchronous execution of schema changes.\n\n```go\nfunc TestDisableSyncSchemaChangeExec() func()\n```\nTestDisableSyncSchemaChangeExec is used in tests to disable the synchronous execution of schema changes, so that the asynchronous schema changer can run the schema changes.\n\n```go\nfunc TestDisableTableLeases() func()\n```\nTestDisableTableLeases disables table leases and returns a function that can be used to enable it.\n\n## Types\n\n```go\ntype ColumnDescriptor struct {\n\tName     string     `protobuf:\"bytes,1,opt,name=name\" json:\"name\"`\n\tID       ColumnID   `protobuf:\"varint,2,opt,name=id,casttype=ColumnID\" json:\"id\"`\n\tType     ColumnType `protobuf:\"bytes,3,opt,name=type\" json:\"type\"`\n\tNullable bool       `protobuf:\"varint,4,opt,name=nullable\" json:\"nullable\"`\n\t// Default expression to use to populate the column on insert if no\n\t// value is provided.\n\tDefaultExpr *string `protobuf:\"bytes,5,opt,name=default_expr,json=defaultExpr\" json:\"default_expr,omitempty\"`\n\tHidden      bool    `protobuf:\"varint,6,opt,name=hidden\" json:\"hidden\"`\n}\n```\n\n```go\nfunc (*ColumnDescriptor) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *ColumnDescriptor) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *ColumnDescriptor) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*ColumnDescriptor) ProtoMessage()\n```\n\n```go\nfunc (m *ColumnDescriptor) Reset()\n```\n\n```go\nfunc (m *ColumnDescriptor) Size() (n int)\n```\n\n```go\nfunc (m *ColumnDescriptor) String() string\n```\n\n```go\nfunc (m *ColumnDescriptor) Unmarshal(data []byte) error\n```\n\n```go\ntype ColumnID uint32\n```\nColumnID is a custom type for ColumnDescriptor IDs.\n\n```go\ntype ColumnType struct {\n\tKind ColumnType_Kind `protobuf:\"varint,1,opt,name=kind,enum=cockroach.sql.ColumnType_Kind\" json:\"kind\"`\n\t// BIT, INT, FLOAT, DECIMAL, CHAR and BINARY\n\tWidth int32 `protobuf:\"varint,2,opt,name=width\" json:\"width\"`\n\t// FLOAT and DECIMAL.\n\tPrecision int32 `protobuf:\"varint,3,opt,name=precision\" json:\"precision\"`\n}\n```\n\n```go\nfunc (*ColumnType) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *ColumnType) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *ColumnType) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*ColumnType) ProtoMessage()\n```\n\n```go\nfunc (m *ColumnType) Reset()\n```\n\n```go\nfunc (c *ColumnType) SQLString() string\n```\nSQLString returns the SQL string corresponding to the type.\n\n```go\nfunc (m *ColumnType) Size() (n int)\n```\n\n```go\nfunc (m *ColumnType) String() string\n```\n\n```go\nfunc (m *ColumnType) Unmarshal(data []byte) error\n```\n\n```go\ntype ColumnType_Kind int32\n```\nThese mirror the types supported by the sql/parser. See sql/parser/types.go.\n\n```go\nconst (\n\tColumnType_BOOL      ColumnType_Kind = 0\n\tColumnType_INT       ColumnType_Kind = 1\n\tColumnType_FLOAT     ColumnType_Kind = 2\n\tColumnType_DECIMAL   ColumnType_Kind = 3\n\tColumnType_DATE      ColumnType_Kind = 4\n\tColumnType_TIMESTAMP ColumnType_Kind = 5\n\tColumnType_INTERVAL  ColumnType_Kind = 6\n\tColumnType_STRING    ColumnType_Kind = 7\n\tColumnType_BYTES     ColumnType_Kind = 8\n)\n```\n\n```go\nfunc (x ColumnType_Kind) Enum() *ColumnType_Kind\n```\n\n```go\nfunc (ColumnType_Kind) EnumDescriptor() ([]byte, []int)\n```\n\n```go\nfunc (x ColumnType_Kind) String() string\n```\n\n```go\nfunc (x *ColumnType_Kind) UnmarshalJSON(data []byte) error\n```\n\n```go\ntype DatabaseDescriptor struct {\n\tName       string               `protobuf:\"bytes,1,opt,name=name\" json:\"name\"`\n\tID         ID                   `protobuf:\"varint,2,opt,name=id,casttype=ID\" json:\"id\"`\n\tPrivileges *PrivilegeDescriptor `protobuf:\"bytes,3,opt,name=privileges\" json:\"privileges,omitempty\"`\n}\n```\nDatabaseDescriptor represents a namespace (aka database) and is stored in a structured metadata key. The DatabaseDescriptor has a globally-unique ID shared with the TableDescriptor ID. Permissions are applied to all tables in the namespace.\n\n```go\nfunc (*DatabaseDescriptor) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *DatabaseDescriptor) GetID() ID\n```\n\n```go\nfunc (m *DatabaseDescriptor) GetName() string\n```\n\n```go\nfunc (m *DatabaseDescriptor) GetPrivileges() *PrivilegeDescriptor\n```\n\n```go\nfunc (m *DatabaseDescriptor) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *DatabaseDescriptor) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*DatabaseDescriptor) ProtoMessage()\n```\n\n```go\nfunc (m *DatabaseDescriptor) Reset()\n```\n\n```go\nfunc (desc *DatabaseDescriptor) SetID(id ID)\n```\nSetID implements the descriptorProto interface.\n\n```go\nfunc (desc *DatabaseDescriptor) SetName(name string)\n```\nSetName implements the descriptorProto interface.\n\n```go\nfunc (m *DatabaseDescriptor) Size() (n int)\n```\n\n```go\nfunc (m *DatabaseDescriptor) String() string\n```\n\n```go\nfunc (desc *DatabaseDescriptor) TypeName() string\n```\nTypeName returns the plain type of this descriptor.\n\n```go\nfunc (m *DatabaseDescriptor) Unmarshal(data []byte) error\n```\n\n```go\nfunc (desc *DatabaseDescriptor) Validate() error\n```\nValidate validates that the database descriptor is well formed. Checks include validate the database name, and verifying that there is at least one read and write user.\n\n```go\ntype Descriptor struct {\n\t// Types that are valid to be assigned to Union:\n\t//\t*Descriptor_Table\n\t//\t*Descriptor_Database\n\tUnion isDescriptor_Union `protobuf_oneof:\"union\"`\n}\n```\nDescriptor is a union type holding either a table or database descriptor.\n\n```go\nfunc (*Descriptor) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *Descriptor) GetDatabase() *DatabaseDescriptor\n```\n\n```go\nfunc (desc *Descriptor) GetID() ID\n```\nGetID returns the ID of the descriptor.\n\n```go\nfunc (desc *Descriptor) GetName() string\n```\nGetName returns the Name of the descriptor.\n\n```go\nfunc (m *Descriptor) GetTable() *TableDescriptor\n```\n\n```go\nfunc (m *Descriptor) GetUnion() isDescriptor_Union\n```\n\n```go\nfunc (m *Descriptor) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *Descriptor) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*Descriptor) ProtoMessage()\n```\n\n```go\nfunc (m *Descriptor) Reset()\n```\n\n```go\nfunc (m *Descriptor) Size() (n int)\n```\n\n```go\nfunc (m *Descriptor) String() string\n```\n\n```go\nfunc (m *Descriptor) Unmarshal(data []byte) error\n```\n\n```go\nfunc (*Descriptor) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})\n```\nXXX\\_OneofFuncs is for the internal use of the proto package.\n\n```go\ntype DescriptorMutation struct {\n\t// Types that are valid to be assigned to Descriptor_:\n\t//\t*DescriptorMutation_Column\n\t//\t*DescriptorMutation_Index\n\tDescriptor_ isDescriptorMutation_Descriptor_ `protobuf_oneof:\"descriptor\"`\n\tState       DescriptorMutation_State         `protobuf:\"varint,3,opt,name=state,enum=cockroach.sql.DescriptorMutation_State\" json:\"state\"`\n\tDirection   DescriptorMutation_Direction     `protobuf:\"varint,4,opt,name=direction,enum=cockroach.sql.DescriptorMutation_Direction\" json:\"direction\"`\n\t// The mutation id used to group mutations that should be applied together.\n\t// This is used for situations like creating a unique column, which\n\t// involve adding two mutations: one for the column, and another for the\n\t// unique constraint index.\n\tMutationID MutationID `protobuf:\"varint,5,opt,name=mutation_id,json=mutationId,casttype=MutationID\" json:\"mutation_id\"`\n}\n```\nA 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.\n\n```go\nfunc (*DescriptorMutation) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *DescriptorMutation) GetColumn() *ColumnDescriptor\n```\n\n```go\nfunc (m *DescriptorMutation) GetDescriptor_() isDescriptorMutation_Descriptor_\n```\n\n```go\nfunc (m *DescriptorMutation) GetIndex() *IndexDescriptor\n```\n\n```go\nfunc (m *DescriptorMutation) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *DescriptorMutation) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*DescriptorMutation) ProtoMessage()\n```\n\n```go\nfunc (m *DescriptorMutation) Reset()\n```\n\n```go\nfunc (m *DescriptorMutation) Size() (n int)\n```\n\n```go\nfunc (m *DescriptorMutation) String() string\n```\n\n```go\nfunc (m *DescriptorMutation) Unmarshal(data []byte) error\n```\n\n```go\nfunc (*DescriptorMutation) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})\n```\nXXX\\_OneofFuncs is for the internal use of the proto package.\n\n```go\ntype DescriptorMutation_Column struct {\n\tColumn *ColumnDescriptor `protobuf:\"bytes,1,opt,name=column,oneof\"`\n}\n```\n\n```go\nfunc (m *DescriptorMutation_Column) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (m *DescriptorMutation_Column) Size() (n int)\n```\n\n```go\ntype DescriptorMutation_Direction int32\n```\nDirection of mutation.\n\n```go\nconst (\n\t// Not used.\n\tDescriptorMutation_NONE DescriptorMutation_Direction = 0\n\t// Descriptor is being added.\n\tDescriptorMutation_ADD DescriptorMutation_Direction = 1\n\t// Descriptor is being dropped.\n\tDescriptorMutation_DROP DescriptorMutation_Direction = 2\n)\n```\n\n```go\nfunc (x DescriptorMutation_Direction) Enum() *DescriptorMutation_Direction\n```\n\n```go\nfunc (DescriptorMutation_Direction) EnumDescriptor() ([]byte, []int)\n```\n\n```go\nfunc (x DescriptorMutation_Direction) String() string\n```\n\n```go\nfunc (x *DescriptorMutation_Direction) UnmarshalJSON(data []byte) error\n```\n\n```go\ntype DescriptorMutation_Index struct {\n\tIndex *IndexDescriptor `protobuf:\"bytes,2,opt,name=index,oneof\"`\n}\n```\n\n```go\nfunc (m *DescriptorMutation_Index) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (m *DescriptorMutation_Index) Size() (n int)\n```\n\n```go\ntype DescriptorMutation_State int32\n```\nA 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.\n\n```go\nconst (\n\t// Not used.\n\tDescriptorMutation_UNKNOWN DescriptorMutation_State = 0\n\t// Operations can use this invisible descriptor to implicitly\n\t// delete entries.\n\t// Column: A descriptor in this state is invisible to\n\t// INSERT and UPDATE. DELETE must delete a column in this state.\n\t// Index: A descriptor in this state is invisible to an INSERT.\n\t// UPDATE must delete the old value of the index but doesn't write\n\t// the new value. DELETE must delete the index.\n\t//\n\t// When deleting a descriptor, all descriptor related data\n\t// (column or index data) can only be mass deleted once\n\t// all the nodes have transitioned to the DELETE_ONLY state.\n\tDescriptorMutation_DELETE_ONLY DescriptorMutation_State = 1\n\t// Operations can use this invisible descriptor to implicitly\n\t// write and delete entries.\n\t// Column: INSERT will populate this column with the default\n\t// value. UPDATE ignores this descriptor. DELETE must delete\n\t// the column.\n\t// Index: INSERT, UPDATE and DELETE treat this index like any\n\t// other index.\n\t//\n\t// When adding a descriptor, all descriptor related data\n\t// (column default or index data) can only be backfilled once\n\t// all nodes have transitioned into the WRITE_ONLY state.\n\tDescriptorMutation_WRITE_ONLY DescriptorMutation_State = 2\n)\n```\n\n```go\nfunc (x DescriptorMutation_State) Enum() *DescriptorMutation_State\n```\n\n```go\nfunc (DescriptorMutation_State) EnumDescriptor() ([]byte, []int)\n```\n\n```go\nfunc (x DescriptorMutation_State) String() string\n```\n\n```go\nfunc (x *DescriptorMutation_State) UnmarshalJSON(data []byte) error\n```\n\n```go\ntype DescriptorStatus int\n```\nDescriptorStatus is the status for a descriptor.\n\n```go\nconst (\n\n\t// DescriptorAbsent for a descriptor that doesn't exist.\n\tDescriptorAbsent DescriptorStatus\n\t// DescriptorIncomplete for a descriptor that is a part of a\n\t// schema change, and is still being processed.\n\tDescriptorIncomplete\n\t// DescriptorActive for a descriptor that is completely active\n\t// for read/write and delete operations.\n\tDescriptorActive\n)\n```\n\n```go\ntype DescriptorVersion uint32\n```\nDescriptorVersion is a custom type for TableDescriptor Versions.\n\n```go\ntype Descriptor_Database struct {\n\tDatabase *DatabaseDescriptor `protobuf:\"bytes,2,opt,name=database,oneof\"`\n}\n```\n\n```go\nfunc (m *Descriptor_Database) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (m *Descriptor_Database) Size() (n int)\n```\n\n```go\ntype Descriptor_Table struct {\n\tTable *TableDescriptor `protobuf:\"bytes,1,opt,name=table,oneof\"`\n}\n```\n\n```go\nfunc (m *Descriptor_Table) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (m *Descriptor_Table) Size() (n int)\n```\n\n```go\ntype EventLogType string\n```\nEventLogType represents an event type that can be recorded in the event log.\n\n```go\nconst (\n\t// EventLogCreateDatabase is recorded when a database is created.\n\tEventLogCreateDatabase EventLogType = \"create_database\"\n\t// EventLogDropDatabase is recorded when a database is dropped.\n\tEventLogDropDatabase EventLogType = \"drop_database\"\n\t// EventLogCreateTable is recorded when a table is created.\n\tEventLogCreateTable EventLogType = \"create_table\"\n\t// EventLogDropTable is recorded when a table is dropped.\n\tEventLogDropTable EventLogType = \"drop_table\"\n\t// EventLogNodeJoin is recorded when a node joins the cluster.\n\tEventLogNodeJoin EventLogType = \"node_join\"\n\t// EventLogNodeRestart is recorded when an existing node rejoins the cluster\n\t// after being offline.\n\tEventLogNodeRestart EventLogType = \"node_restart\"\n)\n```\n\n```go\ntype EventLogger struct {\n\tInternalExecutor\n}\n```\nAn EventLogger exposes methods used to record events to the event table.\n\n```go\nfunc MakeEventLogger(leaseMgr *LeaseManager) EventLogger\n```\nMakeEventLogger constructs a new EventLogger. A LeaseManager is required in order to correctly execute SQL statements.\n\n```go\nfunc (ev EventLogger) InsertEventRecord(txn *client.Txn, eventType EventLogType, targetID, reportingID int32, info interface{}) *roachpb.Error\n```\nInsertEventRecord inserts a single event into the event log as part of the provided transaction.\n\n```go\ntype Executor struct {\n\t// contains filtered or unexported fields\n}\n```\nAn Executor executes SQL statements. Executor is thread-safe.\n\n```go\nfunc NewExecutor(ctx ExecutorContext, stopper *stop.Stopper, registry *metric.Registry) *Executor\n```\nNewExecutor creates an Executor and registers a callback on the system config.\n\n```go\nfunc (e *Executor) ExecuteStatements(\n\tctx context.Context, session *Session, stmts string,\n\tparams []parser.Datum) StatementResults\n```\nExecuteStatements executes the given statement(s) and returns a response. On error, the returned integer is an HTTP error code.\n\n```go\nfunc (e *Executor) Prepare(ctx context.Context, query string, session *Session, args parser.MapArgs) (\n\t[]ResultColumn, *roachpb.Error)\n```\nPrepare returns the result types of the given statement. Args may be a partially populated val args map. Prepare will populate the missing val args. The column result types are returned (or nil if there are no results).\n\n```go\nfunc (e *Executor) Registry() *metric.Registry\n```\nRegistry returns a registry with the metrics tracked by this executor, which can be used to access its stats or be added to another registry.\n\n```go\nfunc (e *Executor) SetNodeID(nodeID roachpb.NodeID)\n```\nSetNodeID sets the node ID for the SQL server. This method must be called before actually using the Executor.\n\n```go\ntype ExecutorContext struct {\n\tDB           *client.DB\n\tGossip       *gossip.Gossip\n\tLeaseManager *LeaseManager\n\tClock        *hlc.Clock\n\n\tTestingKnobs *ExecutorTestingKnobs\n}\n```\nAn ExecutorContext encompasses the auxiliary objects and configuration required to create an executor. All fields holding a pointer or an interface are required to create a Executor; the rest will have sane defaults set if omitted.\n\n```go\ntype ExecutorTestingKnobs struct {\n\t// WaitForGossipUpdate causes metadata-mutating operations to wait\n\t// for the new metadata to back-propagate through gossip.\n\tWaitForGossipUpdate bool\n\n\t// CheckStmtStringChange causes Executor.execStmtsInCurrentTxn to verify\n\t// that executed statements are not modified during execution.\n\tCheckStmtStringChange bool\n\n\t// FixTxnPriority causes transaction priority values to be hardcoded (for\n\t// each priority level) to avoid the randomness in the normal generation.\n\tFixTxnPriority bool\n}\n```\nExecutorTestingKnobs is part of the context used to control parts of the system during testing.\n\n```go\ntype FormatVersion uint32\n```\nFormatVersion is a custom type for TableDescriptor versions of the sql to key:value mapping.\n\n```go\nconst (\n\n\t// BaseFormatVersion corresponds to the encoding described in\n\t// https://www.cockroachlabs.com/blog/sql-in-cockroachdb-mapping-table-data-to-key-value-storage/.\n\tBaseFormatVersion FormatVersion\n)\n```\n\n```go\nfunc (i FormatVersion) String() string\n```\n\n```go\ntype ID uint32\n```\nID is a custom type for {Database,Table}Descriptor IDs.\n\n```go\ntype IndexDescriptor struct {\n\tName   string  `protobuf:\"bytes,1,opt,name=name\" json:\"name\"`\n\tID     IndexID `protobuf:\"varint,2,opt,name=id,casttype=IndexID\" json:\"id\"`\n\tUnique bool    `protobuf:\"varint,3,opt,name=unique\" json:\"unique\"`\n\t// An ordered list of column names of which the index is comprised. This list\n\t// parallels the column_ids list. If duplicating the storage of the column\n\t// names here proves to be prohibitive, we could clear this field before\n\t// saving and reconstruct it after loading.\n\tColumnNames []string `protobuf:\"bytes,4,rep,name=column_names,json=columnNames\" json:\"column_names,omitempty\"`\n\t// Parallel with column_names - the sort direction of each column.\n\tColumnDirections []IndexDescriptor_Direction `protobuf:\"varint,8,rep,name=column_directions,json=columnDirections,enum=cockroach.sql.IndexDescriptor_Direction\" json:\"column_directions,omitempty\"`\n\t// An ordered list of column names which the index stores in\n\t// addition to the columns which are explicitly part of the index.\n\tStoreColumnNames []string `protobuf:\"bytes,5,rep,name=store_column_names,json=storeColumnNames\" json:\"store_column_names,omitempty\"`\n\t// An ordered list of column ids of which the index is comprised. This list\n\t// parallels the column_names list.\n\tColumnIDs []ColumnID `protobuf:\"varint,6,rep,name=column_ids,json=columnIds,casttype=ColumnID\" json:\"column_ids,omitempty\"`\n\t// An ordered list of implicit column ids associated with the index. For\n\t// non-unique indexes, these columns will be appended to the key. For unique\n\t// indexes these columns will be stored in the value. The extra column IDs is\n\t// computed as PrimaryIndex.column_ids - column_ids. For the primary index\n\t// the list will be empty.\n\t// The distinction about whether the columns are written in the key or the value\n\t// comes because we want to always do writes using a single operation - this\n\t// way for unique indexes we can do a conditional put on the key.\n\tImplicitColumnIDs []ColumnID `protobuf:\"varint,7,rep,name=implicit_column_ids,json=implicitColumnIds,casttype=ColumnID\" json:\"implicit_column_ids,omitempty\"`\n}\n```\n\n```go\nfunc (*IndexDescriptor) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *IndexDescriptor) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *IndexDescriptor) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*IndexDescriptor) ProtoMessage()\n```\n\n```go\nfunc (m *IndexDescriptor) Reset()\n```\n\n```go\nfunc (m *IndexDescriptor) Size() (n int)\n```\n\n```go\nfunc (m *IndexDescriptor) String() string\n```\n\n```go\nfunc (m *IndexDescriptor) Unmarshal(data []byte) error\n```\n\n```go\ntype IndexDescriptor_Direction int32\n```\nThe direction of a column in the index.\n\n```go\nconst (\n\tIndexDescriptor_ASC  IndexDescriptor_Direction = 0\n\tIndexDescriptor_DESC IndexDescriptor_Direction = 1\n)\n```\n\n```go\nfunc (x IndexDescriptor_Direction) Enum() *IndexDescriptor_Direction\n```\n\n```go\nfunc (IndexDescriptor_Direction) EnumDescriptor() ([]byte, []int)\n```\n\n```go\nfunc (x IndexDescriptor_Direction) String() string\n```\n\n```go\nfunc (x *IndexDescriptor_Direction) UnmarshalJSON(data []byte) error\n```\n\n```go\ntype IndexID uint32\n```\nIndexID is a custom type for IndexDescriptor IDs.\n\n```go\ntype InternalExecutor struct {\n\tLeaseManager *LeaseManager\n}\n```\nInternalExecutor can be used internally by cockroach to execute SQL statements without needing to open a SQL connection. InternalExecutor assumes that the caller has access to a cockroach KV client to handle connection and transaction management.\n\n```go\nfunc (ie InternalExecutor) ExecuteStatementInTransaction(\n\ttxn *client.Txn, statement string, params ...interface{},\n) (int, *roachpb.Error)\n```\nExecuteStatementInTransaction executes the supplied SQL statement as part of the supplied transaction. Statements are currently executed as the root user.\n\n```go\nfunc (ie InternalExecutor) GetTableSpan(user string, txn *client.Txn, dbName, tableName string) (roachpb.Span, *roachpb.Error)\n```\nGetTableSpan gets the key span for a SQL table, including any indices.\n\n```go\ntype LeaseManager struct {\n\tLeaseStore\n\t// contains filtered or unexported fields\n}\n```\nLeaseManager manages acquiring and releasing per-table leases. Exported only for testing.\n\n```go\nfunc NewLeaseManager(nodeID uint32, db client.DB, clock *hlc.Clock) *LeaseManager\n```\nNewLeaseManager creates a new LeaseManager.\n\n```go\nfunc (m *LeaseManager) Acquire(txn *client.Txn, tableID ID, version DescriptorVersion) (*LeaseState, *roachpb.Error)\n```\nAcquire acquires a read lease for the specified table ID. If version is non-zero the lease is grabbed for the specified version. Otherwise it is grabbed for the most recent version of the descriptor that the lease manager knows about.\n\n```go\nfunc (m *LeaseManager) RefreshLeases(s *stop.Stopper, db *client.DB, gossip *gossip.Gossip)\n```\nRefreshLeases starts a goroutine that refreshes the lease manager leases for tables received in the latest system configuration via gossip.\n\n```go\nfunc (m *LeaseManager) Release(lease *LeaseState) error\n```\nRelease releases a previously acquired read lease.\n\n```go\ntype LeaseState struct {\n\tTableDescriptor\n\t// contains filtered or unexported fields\n}\n```\nLeaseState holds the state for a lease. Exported only for testing.\n\n```go\nfunc (s *LeaseState) Expiration() time.Time\n```\nExpiration returns the expiration time of the lease.\n\n```go\nfunc (s *LeaseState) Refcount() int\n```\nRefcount returns the reference count of the lease.\n\n```go\nfunc (s *LeaseState) String() string\n```\n\n```go\ntype LeaseStore struct {\n\t// contains filtered or unexported fields\n}\n```\nLeaseStore implements the operations for acquiring and releasing leases and publishing a new version of a descriptor. Exported only for testing.\n\n```go\nfunc (s LeaseStore) Acquire(txn *client.Txn, tableID ID, minVersion DescriptorVersion) (*LeaseState, *roachpb.Error)\n```\nAcquire a lease on the most recent version of a table descriptor.\n\n```go\nfunc (s LeaseStore) Publish(tableID ID, update func(*TableDescriptor) error) *roachpb.Error\n```\nPublish a new version of a table descriptor. The update closure may be called multiple times if retries occur: make sure it does not have side effects.\n\n```go\nfunc (s LeaseStore) Release(lease *LeaseState) error\n```\nRelease a previously acquired table descriptor lease.\n\n```go\ntype MetadataSchema struct {\n\t// contains filtered or unexported fields\n}\n```\nMetadataSchema is used to construct the initial sql schema for a new CockroachDB cluster being bootstrapped. Tables and databases must be installed on the underlying persistent storage before a cockroach store can start running correctly, thus requiring this special initialization.\n\n```go\nfunc MakeMetadataSchema() MetadataSchema\n```\nMakeMetadataSchema constructs a new MetadataSchema value which constructs the \"system\" database.\n\n```go\nfunc (ms *MetadataSchema) AddDescriptor(parentID ID, desc descriptorProto)\n```\nAddDescriptor adds a new descriptor to the system schema. Used only for SystemConfig tables and databases. Prefer AddTable for most uses.\n\n```go\nfunc (ms *MetadataSchema) AddTable(id ID, definition string, privileges privilege.List)\n```\nAddTable adds a new table to the system database.\n\n```go\nfunc (ms MetadataSchema) DescriptorCount() int\n```\nDescriptorCount returns the number of descriptors that will be created by this schema. This value is needed to automate certain tests.\n\n```go\nfunc (ms MetadataSchema) GetInitialValues() []roachpb.KeyValue\n```\nGetInitialValues returns the set of initial K/V values which should be added to a bootstrapping CockroachDB cluster in order to create the tables contained in the schema.\n\n```go\nfunc (ms MetadataSchema) MaxTableID() ID\n```\nMaxTableID returns the highest table ID of any system table. This value is needed to automate certain tests.\n\n```go\nfunc (ms MetadataSchema) TableCount() int\n```\nTableCount returns the number of non-system config tables in the system database. This value is needed to automate certain tests.\n\n```go\ntype MutationID uint32\n```\nMutationID is custom type for TableDescriptor mutations.\n\n```go\ntype PrivilegeDescriptor struct {\n\tUsers []*UserPrivileges `protobuf:\"bytes,1,rep,name=users\" json:\"users,omitempty\"`\n}\n```\nPrivilegeDescriptor describes a list of users and attached privileges. The list should be sorted by user for fast access.\n\n```go\nfunc NewDefaultPrivilegeDescriptor() *PrivilegeDescriptor\n```\nNewDefaultPrivilegeDescriptor returns a privilege descriptor with ALL privileges for the root user.\n\n```go\nfunc NewPrivilegeDescriptor(user string, priv privilege.List) *PrivilegeDescriptor\n```\nNewPrivilegeDescriptor returns a privilege descriptor for the given user with the specified list of privileges.\n\n```go\nfunc (p *PrivilegeDescriptor) CheckPrivilege(user string, priv privilege.Kind) bool\n```\nCheckPrivilege returns true if 'user' has 'privilege' on this descriptor.\n\n```go\nfunc (*PrivilegeDescriptor) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (p *PrivilegeDescriptor) Grant(user string, privList privilege.List)\n```\nGrant adds new privileges to this descriptor for a given list of users. TODO(marc): if all privileges other than ALL are set, should we collapse them into ALL?\n\n```go\nfunc (m *PrivilegeDescriptor) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *PrivilegeDescriptor) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*PrivilegeDescriptor) ProtoMessage()\n```\n\n```go\nfunc (m *PrivilegeDescriptor) Reset()\n```\n\n```go\nfunc (p *PrivilegeDescriptor) Revoke(user string, privList privilege.List)\n```\nRevoke removes privileges from this descriptor for a given list of users.\n\n```go\nfunc (p *PrivilegeDescriptor) Show() []UserPrivilegeString\n```\nShow returns the list of {username, privileges} sorted by username. 'privileges' is a string of comma-separated sorted privilege names.\n\n```go\nfunc (m *PrivilegeDescriptor) Size() (n int)\n```\n\n```go\nfunc (m *PrivilegeDescriptor) String() string\n```\n\n```go\nfunc (m *PrivilegeDescriptor) Unmarshal(data []byte) error\n```\n\n```go\nfunc (p *PrivilegeDescriptor) Validate(id ID) error\n```\nValidate is called when writing a database or table descriptor. It takes the descriptor ID which is used to determine if it belongs to a system descriptor, in which case the maximum set of allowed privileges is looked up and applied.\n\n```go\ntype Result struct {\n\tPErr *roachpb.Error\n\t// The type of statement that the result is for.\n\tType parser.StatementType\n\t// The tag of the statement that the result is for.\n\tPGTag string\n\t// RowsAffected will be populated if the statement type is \"RowsAffected\".\n\tRowsAffected int\n\t// Columns will be populated if the statement type is \"Rows\". It will contain\n\t// the names and types of the columns returned in the result set in the order\n\t// specified in the SQL statement. The number of columns will equal the number\n\t// of values in each Row.\n\tColumns []ResultColumn\n\t// Rows will be populated if the statement type is \"Rows\". It will contain\n\t// the result set of the result.\n\t// TODO(nvanbenschoten): Can this be streamed from the planNode?\n\tRows []ResultRow\n}\n```\nResult corresponds to the execution of a single SQL statement.\n\n```go\ntype ResultColumn struct {\n\tName string\n\tTyp  parser.Datum\n\t// contains filtered or unexported fields\n}\n```\nResultColumn contains the name and type of a SQL \"cell\".\n\n```go\ntype ResultList []Result\n```\nResultList represents a list of results for a list of SQL statements. There is one result object per SQL statement in the request.\n\n```go\ntype ResultRow struct {\n\tValues []parser.Datum\n}\n```\nResultRow is a collection of values representing a row in a result.\n\n```go\ntype SchemaChangeManager struct {\n\t// contains filtered or unexported fields\n}\n```\nSchemaChangeManager processes pending schema changes seen in gossip updates. Most schema changes are executed synchronously by the node that created the schema change. If the node dies while processing the schema change this manager acts as a backup execution mechanism.\n\n```go\nfunc NewSchemaChangeManager(db client.DB, gossip *gossip.Gossip, leaseMgr *LeaseManager) *SchemaChangeManager\n```\nNewSchemaChangeManager returns a new SchemaChangeManager.\n\n```go\nfunc (s *SchemaChangeManager) Start(stopper *stop.Stopper)\n```\nStart starts a goroutine that runs outstanding schema changes for tables received in the latest system configuration via gossip.\n\n```go\ntype SchemaChanger struct {\n\t// contains filtered or unexported fields\n}\n```\nSchemaChanger is used to change the schema on a table.\n\n```go\nfunc NewSchemaChangerForTesting(\n\ttableID ID, mutationID MutationID, nodeID roachpb.NodeID, db client.DB, leaseMgr *LeaseManager,\n) SchemaChanger\n```\nNewSchemaChangerForTesting only for tests.\n\n```go\nfunc (sc *SchemaChanger) AcquireLease() (TableDescriptor_SchemaChangeLease, *roachpb.Error)\n```\nAcquireLease acquires a schema change lease on the table if an unexpired lease doesn't exist. It returns the lease.\n\n```go\nfunc (sc *SchemaChanger) ExtendLease(\n\texistingLease TableDescriptor_SchemaChangeLease,\n) (TableDescriptor_SchemaChangeLease, *roachpb.Error)\n```\nExtendLease for the current leaser.\n\n```go\nfunc (sc *SchemaChanger) IsDone() (bool, error)\n```\nIsDone returns true if the work scheduled for the schema changer is complete.\n\n```go\nfunc (sc *SchemaChanger) MaybeIncrementVersion() *roachpb.Error\n```\nMaybeIncrementVersion increments the version if needed.\n\n```go\nfunc (sc *SchemaChanger) ReleaseLease(lease TableDescriptor_SchemaChangeLease) error\n```\nReleaseLease the table lease if it is the one registered with the table descriptor.\n\n```go\nfunc (sc *SchemaChanger) RunStateMachineBeforeBackfill() error\n```\nRunStateMachineBeforeBackfill moves the state machine forward and wait to ensure that all nodes are seeing the latest version of the table.\n\n```go\ntype Session struct {\n\tDatabase string\n\tUser     string\n\tSyntax   int32\n\n\t// Info about the open transaction (if any).\n\tTxnState txnState\n\n\tTimezone              isSessionTimezone\n\tDefaultIsolationLevel roachpb.IsolationType\n\tTrace                 trace.Trace\n\t// contains filtered or unexported fields\n}\n```\nSession contains the state of a SQL client connection. Create instances using NewSession().\n\n```go\nfunc NewSession(args SessionArgs, e *Executor, remote net.Addr) *Session\n```\nNewSession creates and initializes new Session object. remote can be nil.\n\n```go\nfunc (s *Session) Finish()\n```\nFinish releases resources held by the Session.\n\n```go\ntype SessionArgs struct {\n\tDatabase string\n\tUser     string\n}\n```\nSessionArgs contains arguments for creating a new Session with NewSession().\n\n```go\ntype SessionLocation struct {\n\tLocation string\n}\n```\nSessionLocation ...\n\n```go\ntype SessionOffset struct {\n\tOffset int64\n}\n```\nSessionOffset ...\n\n```go\ntype StatementResults struct {\n\tResultList\n\t// Indicates that after parsing, the request contained 0 non-empty statements.\n\tEmpty bool\n}\n```\nStatementResults represents a list of results from running a batch of SQL statements, plus some meta info about the batch.\n\n```go\ntype TableDescriptor struct {\n\tName string `protobuf:\"bytes,1,opt,name=name\" json:\"name\"`\n\tID   ID     `protobuf:\"varint,3,opt,name=id,casttype=ID\" json:\"id\"`\n\t// ID of the parent database.\n\tParentID ID `protobuf:\"varint,4,opt,name=parent_id,json=parentId,casttype=ID\" json:\"parent_id\"`\n\t// Monotonically increasing version of the table descriptor.\n\t//\n\t// Invariants:\n\t// 1. not more than two subsequent versions of the table\n\t// descriptor can be leased. This is to make the system\n\t// easy to reason about, by permiting mutation state\n\t// changes (reflected in the next version), only when the existing\n\t// state (reflected in the current version) is present on all\n\t// outstanding unexpired leases.\n\t// 2. A schema change command (ALTER, RENAME, etc) never directly\n\t// increments the version. This allows the command to execute without\n\t// waiting for the entire cluster to converge to a single version\n\t// preventing weird deadlock situations. For instance, a transaction\n\t// with a schema change command might use a descriptor lease that is\n\t// at version: v - 1, and therefore deadlock when it tries to wait\n\t// for version: v, in the process of incrementing it to v + 1.\n\t// Therefore, a schema change command never increments the version,\n\t// and instead, sets the up_version boolean to notify the schema\n\t// changer execution engine that runs a future transaction to\n\t// increment the version.\n\t//\n\t// The schema change commands must therefore make *safe* modifications\n\t// to the table descriptor, such as scheduling long running schema\n\t// changes through mutations for future execution, or making simple\n\t// schema changes like RENAME that only modify the table descriptor in a\n\t// single transaction.\n\t//\n\t// Multiple schema changes in the same transaction set up_version.\n\t// The actual schema change execution that follows a schema change\n\t// command sees the up_version boolean set, and increments the\n\t// table version after ensuring that there are no unexpired leases\n\t// for version - 1. The schema change execution must increment\n\t// the version before executing future state changes, to ensure\n\t// that the scheduled mutations made by the original commands are\n\t// visible on all leases. Multiple schema change mutations can be\n\t// grouped together on a particular version increment.\n\t//\n\t// If schema change commands are safe to run without incrementing\n\t// the version, why do it later on? We increment the version\n\t// to ensure that all the nodes renew their leases with the new version\n\t// and get to see what the schema change command has done quickly.\n\tVersion DescriptorVersion `protobuf:\"varint,5,opt,name=version,casttype=DescriptorVersion\" json:\"version\"`\n\t// See comment above.\n\tUpVersion bool `protobuf:\"varint,6,opt,name=up_version,json=upVersion\" json:\"up_version\"`\n\t// Last modification time of the table descriptor.\n\tModificationTime cockroach_roachpb1.Timestamp `protobuf:\"bytes,7,opt,name=modification_time,json=modificationTime\" json:\"modification_time\"`\n\tColumns          []ColumnDescriptor           `protobuf:\"bytes,8,rep,name=columns\" json:\"columns\"`\n\t// next_column_id is used to ensure that deleted column ids are not reused.\n\tNextColumnID ColumnID        `protobuf:\"varint,9,opt,name=next_column_id,json=nextColumnId,casttype=ColumnID\" json:\"next_column_id\"`\n\tPrimaryIndex IndexDescriptor `protobuf:\"bytes,10,opt,name=primary_index,json=primaryIndex\" json:\"primary_index\"`\n\t// indexes are all the secondary indexes.\n\tIndexes []IndexDescriptor `protobuf:\"bytes,11,rep,name=indexes\" json:\"indexes\"`\n\t// next_index_id is used to ensure that deleted index ids are not reused.\n\tNextIndexID IndexID              `protobuf:\"varint,12,opt,name=next_index_id,json=nextIndexId,casttype=IndexID\" json:\"next_index_id\"`\n\tPrivileges  *PrivilegeDescriptor `protobuf:\"bytes,13,opt,name=privileges\" json:\"privileges,omitempty\"`\n\t// Columns or indexes being added or deleted in a FIFO order.\n\tMutations []DescriptorMutation               `protobuf:\"bytes,14,rep,name=mutations\" json:\"mutations\"`\n\tLease     *TableDescriptor_SchemaChangeLease `protobuf:\"bytes,15,opt,name=lease\" json:\"lease,omitempty\"`\n\t// An id for the next group of mutations to be applied together.\n\tNextMutationID MutationID `protobuf:\"varint,16,opt,name=next_mutation_id,json=nextMutationId,casttype=MutationID\" json:\"next_mutation_id\"`\n\t// format_version declares which sql to key:value mapping is being used to\n\t// represent the data in this table.\n\tFormatVersion FormatVersion `protobuf:\"varint,17,opt,name=format_version,json=formatVersion,casttype=FormatVersion\" json:\"format_version\"`\n}\n```\nA TableDescriptor represents a table 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.\n\n```go\nfunc (desc *TableDescriptor) AddColumn(col ColumnDescriptor)\n```\nAddColumn adds a column to the table.\n\n```go\nfunc (desc *TableDescriptor) AddIndex(idx IndexDescriptor, primary bool) error\n```\nAddIndex adds an index to the table.\n\n```go\nfunc (desc *TableDescriptor) AllocateIDs() error\n```\nAllocateIDs allocates column and index ids for any column or index which has an ID of 0.\n\n```go\nfunc (*TableDescriptor) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (desc *TableDescriptor) FindActiveColumnByName(name string) (ColumnDescriptor, error)\n```\nFindActiveColumnByName finds an active column with the specified name.\n\n```go\nfunc (desc *TableDescriptor) FindColumnByID(id ColumnID) (*ColumnDescriptor, error)\n```\nFindColumnByID finds the active column with specified ID.\n\n```go\nfunc (desc *TableDescriptor) FindColumnByName(name string) (DescriptorStatus, int, error)\n```\nFindColumnByName finds the column with the specified name. It returns DescriptorStatus for the column, and an index into either the columns (status == DescriptorActive) or mutations (status == DescriptorIncomplete).\n\n```go\nfunc (desc *TableDescriptor) FindIndexByID(id IndexID) (*IndexDescriptor, error)\n```\nFindIndexByID finds the active index with specified ID.\n\n```go\nfunc (desc *TableDescriptor) FindIndexByName(name string) (DescriptorStatus, int, error)\n```\nFindIndexByName finds the index with the specified name. It returns DescriptorStatus for the index, and an index into either the indexes (status == DescriptorActive) or mutations (status == DescriptorIncomplete).\n\n```go\nfunc (m *TableDescriptor) GetColumns() []ColumnDescriptor\n```\n\n```go\nfunc (m *TableDescriptor) GetFormatVersion() FormatVersion\n```\n\n```go\nfunc (m *TableDescriptor) GetID() ID\n```\n\n```go\nfunc (m *TableDescriptor) GetIndexes() []IndexDescriptor\n```\n\n```go\nfunc (m *TableDescriptor) GetLease() *TableDescriptor_SchemaChangeLease\n```\n\n```go\nfunc (m *TableDescriptor) GetModificationTime() cockroach_roachpb1.Timestamp\n```\n\n```go\nfunc (m *TableDescriptor) GetMutations() []DescriptorMutation\n```\n\n```go\nfunc (m *TableDescriptor) GetName() string\n```\n\n```go\nfunc (m *TableDescriptor) GetNextColumnID() ColumnID\n```\n\n```go\nfunc (m *TableDescriptor) GetNextIndexID() IndexID\n```\n\n```go\nfunc (m *TableDescriptor) GetNextMutationID() MutationID\n```\n\n```go\nfunc (m *TableDescriptor) GetParentID() ID\n```\n\n```go\nfunc (m *TableDescriptor) GetPrimaryIndex() IndexDescriptor\n```\n\n```go\nfunc (m *TableDescriptor) GetPrivileges() *PrivilegeDescriptor\n```\n\n```go\nfunc (m *TableDescriptor) GetUpVersion() bool\n```\n\n```go\nfunc (m *TableDescriptor) GetVersion() DescriptorVersion\n```\n\n```go\nfunc (m *TableDescriptor) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *TableDescriptor) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*TableDescriptor) ProtoMessage()\n```\n\n```go\nfunc (m *TableDescriptor) Reset()\n```\n\n```go\nfunc (desc *TableDescriptor) SetID(id ID)\n```\nSetID implements the descriptorProto interface.\n\n```go\nfunc (desc *TableDescriptor) SetName(name string)\n```\nSetName implements the descriptorProto interface.\n\n```go\nfunc (m *TableDescriptor) Size() (n int)\n```\n\n```go\nfunc (m *TableDescriptor) String() string\n```\n\n```go\nfunc (desc *TableDescriptor) TypeName() string\n```\nTypeName returns the plain type of this descriptor.\n\n```go\nfunc (m *TableDescriptor) Unmarshal(data []byte) error\n```\n\n```go\nfunc (desc *TableDescriptor) Validate() error\n```\nValidate validates that the table descriptor is well formed. Checks include validating the table, column and index names, verifying that column names and index names are unique and verifying that column IDs and index IDs are consistent.\n\n```go\nfunc (desc *TableDescriptor) VisibleColumns() []ColumnDescriptor\n```\nVisibleColumns returns all non hidden columns.\n\n```go\ntype TableDescriptor_SchemaChangeLease struct {\n\tNodeID github_com_cockroachdb_cockroach_roachpb.NodeID `protobuf:\"varint,1,opt,name=node_id,json=nodeId,casttype=github.com/cockroachdb/cockroach/roachpb.NodeID\" json:\"node_id\"`\n\t// Nanoseconds since the Unix epoch.\n\tExpirationTime int64 `protobuf:\"varint,2,opt,name=expiration_time,json=expirationTime\" json:\"expiration_time\"`\n}\n```\nThe 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.\n\n```go\nfunc (*TableDescriptor_SchemaChangeLease) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *TableDescriptor_SchemaChangeLease) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *TableDescriptor_SchemaChangeLease) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*TableDescriptor_SchemaChangeLease) ProtoMessage()\n```\n\n```go\nfunc (m *TableDescriptor_SchemaChangeLease) Reset()\n```\n\n```go\nfunc (m *TableDescriptor_SchemaChangeLease) Size() (n int)\n```\n\n```go\nfunc (m *TableDescriptor_SchemaChangeLease) String() string\n```\n\n```go\nfunc (m *TableDescriptor_SchemaChangeLease) Unmarshal(data []byte) error\n```\n\n```go\ntype TxnStateEnum int\n```\nTxnStateEnum represents the state of a SQL txn.\n\n```go\nconst (\n\t// No txn is in scope. Either there never was one, or it got committed/rolled back.\n\tNoTxn TxnStateEnum = iota\n\t// A txn is in scope.\n\tOpen\n\t// The txn has encoutered a (non-retriable) error.\n\t// Statements will be rejected until a COMMIT/ROLLBACK is seen.\n\tAborted\n\t// The txn has encoutered a retriable error.\n\t// Statements will be rejected until a RESTART_TRANSACTION is seen.\n\tRestartWait\n\t// The KV txn has been committed successfully through a RELEASE.\n\t// Statements are rejected until a COMMIT is seen.\n\tCommitWait\n)\n```\n\n```go\nfunc (i TxnStateEnum) String() string\n```\n\n```go\ntype UserPrivilegeString struct {\n\tUser       string\n\tPrivileges string\n}\n```\nUserPrivilegeString is a pair of strings describing the privileges for a given user.\n\n```go\ntype UserPrivileges struct {\n\tUser string `protobuf:\"bytes,1,opt,name=user\" json:\"user\"`\n\t// privileges is a bitfield of 1\u003c\u003cPrivilege values.\n\tPrivileges uint32 `protobuf:\"varint,2,opt,name=privileges\" json:\"privileges\"`\n}\n```\nUserPrivileges describes the list of privileges available for a given user.\n\n```go\nfunc (*UserPrivileges) Descriptor() ([]byte, []int)\n```\n\n```go\nfunc (m *UserPrivileges) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *UserPrivileges) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*UserPrivileges) ProtoMessage()\n```\n\n```go\nfunc (m *UserPrivileges) Reset()\n```\n\n```go\nfunc (m *UserPrivileges) Size() (n int)\n```\n\n```go\nfunc (m *UserPrivileges) String() string\n```\n\n```go\nfunc (m *UserPrivileges) Unmarshal(data []byte) error\n```\n\n","path":"github.com/phobos182/cockroach/sql","name":"sql","synopsis":"Package sql provides the user-facing API for access to a Cockroach datastore.","isRedistributable":true}
