{"modulePath":"github.com/maxid/cockroach","version":"v0.0.0-20150829011420-8273b2922c55","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  \"desc\" 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 desc 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 forseeable 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\nAPI\n\n\t  TODO(pmattis): Describe sql/driver.{Request,Response}?\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/server.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\n## Constants\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// SystemDB is the descriptor for the system database.\n\tSystemDB = DatabaseDescriptor{\n\t\tName: \"system\",\n\t\tID:   systemDatabaseID,\n\n\t\tPrivileges: NewPrivilegeDescriptor(security.RootUser,\n\t\t\tSystemAllowedPrivileges[systemDatabaseID]),\n\t}\n\n\t// NamespaceTable is the descriptor for the namespace table.\n\tNamespaceTable = createSystemTable(namespaceTableID, namespaceTableSchema)\n\n\t// DescriptorTable is the descriptor for the descriptor table.\n\tDescriptorTable = createSystemTable(descriptorTableID, descriptorTableSchema)\n\n\t// UsersTable is the descriptor for the users table.\n\tUsersTable = createSystemTable(usersTableID, usersTableSchema)\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\t\t\t// contains filtered or unexported fields\n\t}\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: \"STRING\",\n\t7: \"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\"STRING\":    6,\n\t\"BYTES\":     7,\n}\n```\n\n```go\nvar (\n\tErrInvalidLengthPrivilege = fmt.Errorf(\"proto: negative length found during unmarshaling\")\n)\n```\n\n```go\nvar (\n\tErrInvalidLengthServer = fmt.Errorf(\"proto: negative length found during unmarshaling\")\n)\n```\n\n```go\nvar (\n\tErrInvalidLengthStructured = fmt.Errorf(\"proto: negative length found during unmarshaling\")\n)\n```\n\n```go\nvar ErrMissingPrimaryKey = errors.New(\"table must contain a primary key\")\n```\nErrMissingPrimaryKey exported to the sql package.\n\n## Functions\n\n```go\nfunc GetInitialSystemValues() []proto.KeyValue\n```\nGetInitialSystemValues returns a list of key/value pairs. They are written at cluster bootstrap time (see storage/node.go:BootstrapCLuster).\n\n```go\nfunc IsSystemID(id ID) bool\n```\nIsSystemID returns true if this ID is reserved for system objects.\n\n```go\nfunc MakeColumnKey(colID ColumnID, primaryKey []byte) proto.Key\n```\nMakeColumnKey returns the key for the column in the given row.\n\n```go\nfunc MakeDescMetadataKey(descID ID) proto.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) proto.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## 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}\n```\n\n```go\nfunc (m *ColumnDescriptor) GetID() ColumnID\n```\n\n```go\nfunc (m *ColumnDescriptor) GetName() string\n```\n\n```go\nfunc (m *ColumnDescriptor) GetNullable() bool\n```\n\n```go\nfunc (m *ColumnDescriptor) GetType() ColumnType\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 (m *ColumnType) GetKind() ColumnType_Kind\n```\n\n```go\nfunc (m *ColumnType) GetPrecision() int32\n```\n\n```go\nfunc (m *ColumnType) GetWidth() int32\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_STRING    ColumnType_Kind = 6\n\tColumnType_BYTES     ColumnType_Kind = 7\n)\n```\n\n```go\nfunc (x ColumnType_Kind) Enum() *ColumnType_Kind\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 (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 ID uint32\n```\nID is a custom type for {Database,Table}Descriptor IDs.\n\n```go\nconst (\n\t// MaxReservedDescID is the maximum reserved descriptor ID.\n\t// All objects with ID \u003c= MaxReservedDescID are system object\n\t// with special rules.\n\tMaxReservedDescID ID = keys.MaxReservedDescID\n\t// RootNamespaceID is the ID of the root namespace.\n\tRootNamespaceID ID = 0\n)\n```\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:\"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,5,rep,name=column_ids,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\tImplicitColumnIDs []ColumnID `protobuf:\"varint,6,rep,name=implicit_column_ids,casttype=ColumnID\" json:\"implicit_column_ids,omitempty\"`\n}\n```\n\n```go\nfunc (m *IndexDescriptor) GetColumnIDs() []ColumnID\n```\n\n```go\nfunc (m *IndexDescriptor) GetColumnNames() []string\n```\n\n```go\nfunc (m *IndexDescriptor) GetID() IndexID\n```\n\n```go\nfunc (m *IndexDescriptor) GetImplicitColumnIDs() []ColumnID\n```\n\n```go\nfunc (m *IndexDescriptor) GetName() string\n```\n\n```go\nfunc (m *IndexDescriptor) GetUnique() bool\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 IndexID uint32\n```\nIndexID is a custom type for IndexDescriptor IDs.\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 (m *PrivilegeDescriptor) GetUsers() []*UserPrivileges\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, error)\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 Server struct {\n\t// contains filtered or unexported fields\n}\n```\nA Server provides an HTTP server endpoint serving the SQL API. It accepts either JSON or serialized protobuf content types.\n\n```go\nfunc NewServer(ctx *base.Context, db *client.DB) *Server\n```\nNewServer allocates and returns a new Server.\n\n```go\nfunc (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)\n```\nServeHTTP serves the SQL API by treating the request URL path as the method, the request body as the arguments, and sets the response body as the method reply. The request body is unmarshalled into arguments based on the Content-Type request header. Protobuf and JSON-encoded requests are supported. The response body is encoded according to the request's Accept header, or if not present, in the same format as the request's incoming Content-Type header.\n\n```go\ntype Session struct {\n\tDatabase string `protobuf:\"bytes,1,opt,name=database\" json:\"database\"`\n\tSyntax   int32  `protobuf:\"varint,2,opt,name=syntax\" json:\"syntax\"`\n\t// Open transaction.\n\tTxn *cockroach_proto1.Transaction `protobuf:\"bytes,3,opt,name=txn\" json:\"txn,omitempty\"`\n}\n```\n\n```go\nfunc (m *Session) GetDatabase() string\n```\n\n```go\nfunc (m *Session) GetSyntax() int32\n```\n\n```go\nfunc (m *Session) GetTxn() *cockroach_proto1.Transaction\n```\n\n```go\nfunc (m *Session) Marshal() (data []byte, err error)\n```\n\n```go\nfunc (m *Session) MarshalTo(data []byte) (int, error)\n```\n\n```go\nfunc (*Session) ProtoMessage()\n```\n\n```go\nfunc (m *Session) Reset()\n```\n\n```go\nfunc (m *Session) Size() (n int)\n```\n\n```go\nfunc (m *Session) String() string\n```\n\n```go\nfunc (m *Session) Unmarshal(data []byte) error\n```\n\n```go\ntype TableDescriptor struct {\n\tName string `protobuf:\"bytes,1,opt,name=name\" json:\"name\"`\n\t// The alias for the table. This is only used during query\n\t// processing and not stored persistently.\n\tAlias   string             `protobuf:\"bytes,2,opt,name=alias\" json:\"alias\"`\n\tID      ID                 `protobuf:\"varint,3,opt,name=id,casttype=ID\" json:\"id\"`\n\tColumns []ColumnDescriptor `protobuf:\"bytes,4,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,5,opt,name=next_column_id,casttype=ColumnID\" json:\"next_column_id\"`\n\tPrimaryIndex IndexDescriptor `protobuf:\"bytes,6,opt,name=primary_index\" json:\"primary_index\"`\n\t// indexes are all the secondary indexes.\n\tIndexes []IndexDescriptor `protobuf:\"bytes,7,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,8,opt,name=next_index_id,casttype=IndexID\" json:\"next_index_id\"`\n\tPrivileges  *PrivilegeDescriptor `protobuf:\"bytes,9,opt,name=privileges\" json:\"privileges,omitempty\"`\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) AllocateIDs() error\n```\nAllocateIDs allocates column and index ids for any column or index which has an ID of 0.\n\n```go\nfunc (desc *TableDescriptor) FindColumnByID(id ColumnID) (*ColumnDescriptor, error)\n```\nFindColumnByID finds the column with specified ID.\n\n```go\nfunc (desc *TableDescriptor) FindColumnByName(name string) (*ColumnDescriptor, error)\n```\nFindColumnByName finds the column with specified name.\n\n```go\nfunc (desc *TableDescriptor) FindIndexByName(name string) (*IndexDescriptor, error)\n```\nFindIndexByName finds the index with specified name.\n\n```go\nfunc (m *TableDescriptor) GetAlias() string\n```\n\n```go\nfunc (m *TableDescriptor) GetColumns() []ColumnDescriptor\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) 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) GetPrimaryIndex() IndexDescriptor\n```\n\n```go\nfunc (m *TableDescriptor) GetPrivileges() *PrivilegeDescriptor\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\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 (m *UserPrivileges) GetPrivileges() uint32\n```\n\n```go\nfunc (m *UserPrivileges) GetUser() string\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/maxid/cockroach/sql","name":"sql","synopsis":"Package sql provides the user-facing API for access to a Cockroach datastore.","isRedistributable":true}
