cockroach: github.com/cockroachdb/cockroach/pkg/sql/opt/cat Index | Files

package cat

import "github.com/cockroachdb/cockroach/pkg/sql/opt/cat"

Package cat contains interfaces that are used by the query optimizer to avoid including specifics of sqlbase structures in the opt code.

Index

Package Files

catalog.go column.go data_source.go family.go index.go object.go schema.go sequence.go table.go utils.go view.go zone.go

func FindTableColumnByName Uses

func FindTableColumnByName(tab Table, name tree.Name) int

FindTableColumnByName returns the ordinal of the non-mutation column having the given name, if one exists in the given table. Otherwise, it returns -1.

func FormatSequence Uses

func FormatSequence(cat Catalog, seq Sequence, tp treeprinter.Node)

FormatSequence nicely formats a catalog sequence using a treeprinter for debugging and testing.

func FormatTable Uses

func FormatTable(cat Catalog, tab Table, tp treeprinter.Node)

FormatTable nicely formats a catalog table using a treeprinter for debugging and testing.

func FormatView Uses

func FormatView(view View, tp treeprinter.Node)

FormatView nicely formats a catalog view using a treeprinter for debugging and testing.

func FormatZone Uses

func FormatZone(zone Zone, tp treeprinter.Node)

FormatZone nicely formats a catalog zone using a treeprinter for debugging and testing.

func IsMutationColumn Uses

func IsMutationColumn(table Table, ord int) bool

IsMutationColumn is a convenience function that returns true if the column at the given ordinal position is a mutation column.

func IsMutationIndex Uses

func IsMutationIndex(table Table, ord IndexOrdinal) bool

IsMutationIndex is a convenience function that returns true if the index at the given ordinal position is a mutation index.

func ResolveTableIndex Uses

func ResolveTableIndex(
    ctx context.Context, catalog Catalog, flags Flags, name *tree.TableIndexName,
) (Index, DataSourceName, error)

ResolveTableIndex resolves a TableIndexName.

type Catalog Uses

type Catalog interface {
    // ResolveSchema locates a schema with the given name and returns it along
    // with the resolved SchemaName (which has all components filled in).
    // If the SchemaName is empty, returns the current database/schema (if one is
    // set; otherwise returns an error).
    //
    // The resolved SchemaName is the same with the resulting Schema.Name() except
    // that it has the ExplicitCatalog/ExplicitSchema flags set to correspond to
    // the input name. Its use is mainly for cosmetic purposes.
    //
    // If no such schema exists, then ResolveSchema returns an error.
    //
    // NOTE: The returned schema must be immutable after construction, and so can
    // be safely copied or used across goroutines.
    ResolveSchema(ctx context.Context, flags Flags, name *SchemaName) (Schema, SchemaName, error)

    // ResolveDataSource locates a data source with the given name and returns it
    // along with the resolved DataSourceName.
    //
    // The resolved DataSourceName is the same with the resulting
    // DataSource.Name() except that it has the ExplicitCatalog/ExplicitSchema
    // flags set to correspond to the input name. Its use is mainly for cosmetic
    // purposes. For example: the input name might be "t". The fully qualified
    // DataSource.Name() would be "currentdb.public.t"; the returned
    // DataSourceName would have the same fields but would still be formatted as
    // "t".
    //
    // If no such data source exists, then ResolveDataSource returns an error.
    //
    // NOTE: The returned data source must be immutable after construction, and
    // so can be safely copied or used across goroutines.
    ResolveDataSource(
        ctx context.Context, flags Flags, name *DataSourceName,
    ) (DataSource, DataSourceName, error)

    // ResolveDataSourceByID is similar to ResolveDataSource, except that it
    // locates a data source by its StableID. See the comment for StableID for
    // more details.
    //
    // If the table is in the process of being added, returns an
    // "undefined relation" error but also returns isAdding=true.
    //
    // NOTE: The returned data source must be immutable after construction, and
    // so can be safely copied or used across goroutines.
    ResolveDataSourceByID(
        ctx context.Context, flags Flags, id StableID,
    ) (_ DataSource, isAdding bool, _ error)

    // CheckPrivilege verifies that the current user has the given privilege on
    // the given catalog object. If not, then CheckPrivilege returns an error.
    CheckPrivilege(ctx context.Context, o Object, priv privilege.Kind) error

    // CheckAnyPrivilege verifies that the current user has any privilege on
    // the given catalog object. If not, then CheckAnyPrivilege returns an error.
    CheckAnyPrivilege(ctx context.Context, o Object) error

    // HasAdminRole checks that the current user has admin privileges. If yes,
    // returns true. Returns an error if query on the `system.users` table failed
    HasAdminRole(ctx context.Context) (bool, error)

    // RequireAdminRole checks that the current user has admin privileges. If not,
    // returns an error.
    RequireAdminRole(ctx context.Context, action string) error

    // FullyQualifiedName retrieves the fully qualified name of a data source.
    // Note that:
    //  - this call may involve a database operation so it shouldn't be used in
    //    performance sensitive paths;
    //  - the fully qualified name of a data source object can change without the
    //    object itself changing (e.g. when a database is renamed).
    FullyQualifiedName(ctx context.Context, ds DataSource) (DataSourceName, error)
}

Catalog is an interface to a database catalog, exposing only the information needed by the query optimizer.

NOTE: Catalog implementations need not be thread-safe. However, the objects returned by the Resolve methods (schemas and data sources) *must* be immutable after construction, and therefore also thread-safe.

type CheckConstraint Uses

type CheckConstraint struct {
    Constraint string
    Validated  bool
}

CheckConstraint contains the SQL text and the validity status for a check constraint on a table. Check constraints are user-defined restrictions on the content of each row in a table. For example, this check constraint ensures that only values greater than zero can be inserted into the table:

CREATE TABLE a (a INT CHECK (a > 0))

type Column Uses

type Column interface {
    // ColID is the unique, stable identifier for this column within its table.
    // Each new column in the table will be assigned a new ID that is different
    // than every column allocated before or after. This is true even if a column
    // is dropped and then re-added with the same name; the new column will have
    // a different ID. See the comment for StableID for more detail.
    ColID() StableID

    // ColName returns the name of the column.
    ColName() tree.Name

    // DatumType returns the data type of the column.
    DatumType() *types.T

    // ColTypePrecision returns the precision of the column's SQL data type. This
    // is only defined for the Decimal data type and represents the max number of
    // decimal digits in the decimal (including fractional digits). If precision
    // is 0, then the decimal has no max precision.
    ColTypePrecision() int

    // ColTypeWidth returns the width of the column's SQL data type. This has
    // different meanings depending on the data type:
    //
    //   Decimal  : scale
    //   Int      : # bits (16, 32, 64, etc)
    //   Bit Array: # bits
    //   String   : rune count
    //
    // TODO(andyk): Switch calling code to use DatumType.
    ColTypeWidth() int

    // ColTypeStr returns the SQL data type of the column, as a string. Note that
    // this is sometimes different than DatumType().String(), since datum types
    // are a subset of column types.
    ColTypeStr() string

    // IsNullable returns true if the column is nullable.
    IsNullable() bool

    // IsHidden returns true if the column is hidden (e.g., there is always a
    // hidden column called rowid if there is no primary key on the table).
    IsHidden() bool

    // HasDefault returns true if the column has a default value. DefaultExprStr
    // will be set to the SQL expression string in that case.
    HasDefault() bool

    // DefaultExprStr is set to the SQL expression string that describes the
    // column's default value. It is used when the user does not provide a value
    // for the column when inserting a row. Default values cannot depend on other
    // columns.
    DefaultExprStr() string

    // IsComputed returns true if the column is a computed value. ComputedExprStr
    // will be set to the SQL expression string in that case.
    IsComputed() bool

    // ComputedExprStr is set to the SQL expression string that describes the
    // column's computed value. It is always used to provide the column's value
    // when inserting or updating a row. Computed values cannot depend on other
    // computed columns, but they can depend on all other columns, including
    // columns with default values.
    ComputedExprStr() string
}

Column is an interface to a table column, exposing only the information needed by the query optimizer.

type Constraint Uses

type Constraint interface {
    // IsRequired is true if this is a required constraint, or false if this is
    // a prohibited constraint (signified by initial + or - character).
    IsRequired() bool

    // GetKey returns the constraint's string key (to left of =).
    GetKey() string

    // GetValue returns the constraint's string value (to right of =).
    GetValue() string
}

Constraint governs placement of range replicas on nodes. A constraint can either be required or prohibited. A required constraint's key/value pair must match one of the tiers of a node's locality for the range to locate there. A prohibited constraint's key/value pair must *not* match any of the tiers of a node's locality for the range to locate there. For example:

+region=east     Range can only be placed on nodes in region=east locality.
-region=west     Range cannot be placed on nodes in region=west locality.

type ConstraintSet Uses

type ConstraintSet interface {
    // ConstraintCount returns the number of constraints in the set.
    ConstraintCount() int

    // Constraint returns the ith constraint in the set, where
    // i < ConstraintCount.
    Constraint(i int) Constraint
}

ConstraintSet is a set of constraints that apply to a range, restricting which nodes can host that range or stating which nodes are preferred as the leaseholder.

type DataSource Uses

type DataSource interface {
    Object

    // Name returns the unqualified name of the object.
    Name() tree.Name
}

DataSource is an interface to a database object that provides rows, like a table, a view, or a sequence.

type DataSourceName Uses

type DataSourceName = tree.TableName

DataSourceName is an alias for tree.TableName, and is used for views and sequences as well as tables.

func ExpandDataSourceGlob Uses

func ExpandDataSourceGlob(
    ctx context.Context, catalog Catalog, flags Flags, pattern tree.TablePattern,
) ([]DataSourceName, error)

ExpandDataSourceGlob is a utility function that expands a tree.TablePattern into a list of object names.

type Family Uses

type Family interface {
    // ID is the stable identifier for this family that is guaranteed to be
    // unique within the owning table. See the comment for StableID for more
    // detail.
    ID() StableID

    // Name is the name of the family.
    Name() tree.Name

    // Table returns a reference to the table with which this family is
    // associated.
    Table() Table

    // ColumnCount returns the number of columns in the family.
    ColumnCount() int

    // Column returns the ith FamilyColumn within the family, where
    // i < ColumnCount.
    Column(i int) FamilyColumn
}

Family is an interface to a table column family, exposing only the information needed by the query optimizer.

type FamilyColumn Uses

type FamilyColumn struct {
    // Column is a reference to the column returned by Table.Column, given the
    // column ordinal.
    Column

    // Ordinal is the ordinal position of the family column in the table. It is
    // always >= 0 and < Table.ColumnCount.
    Ordinal int
}

FamilyColumn describes a single column that is part of a family definition.

type Flags Uses

type Flags struct {
    // AvoidDescriptorCaches avoids using any cached descriptors (for tables,
    // views, schemas, etc). This is useful in cases where we are running a
    // statement like SHOW and we don't want to get table leases or otherwise
    // pollute the caches.
    AvoidDescriptorCaches bool

    // NoTableStats doesn't retrieve table statistics. This should be used in all
    // cases where we don't need them (like SHOW variants), to avoid polluting the
    // stats cache.
    NoTableStats bool
}

Flags allows controlling aspects of some Catalog operations.

type ForeignKeyConstraint Uses

type ForeignKeyConstraint interface {
    // Name of the foreign key constraint.
    Name() string

    // OriginTableID returns the referencing table's stable identifier.
    OriginTableID() StableID

    // ReferencedTableID returns the referenced table's stable identifier.
    ReferencedTableID() StableID

    // ColumnCount returns the number of column pairs in this FK reference.
    ColumnCount() int

    // OriginColumnOrdinal returns the ith column ordinal (see Table.Column) in
    // the origin (referencing) table. The ID() of originTable must equal
    // OriginTable().
    OriginColumnOrdinal(originTable Table, i int) int

    // ReferencedColumnOrdinal returns the ith column ordinal (see Table.Column)
    // in the referenced table. The ID() of referencedTable must equal
    // ReferencedTable().
    ReferencedColumnOrdinal(referencedTable Table, i int) int

    // Validated is true if the reference is validated (i.e. we know that the
    // existing data satisfies the constraint). It is possible to set up a foreign
    // key constraint on existing tables without validating it, in which case we
    // cannot make any assumptions about the data. An unvalidated constraint still
    // needs to be enforced on new mutations.
    Validated() bool

    // MatchMethod returns the method used for comparing composite foreign keys.
    MatchMethod() tree.CompositeKeyMatchMethod

    // DeleteReferenceAction returns the action to be performed if the foreign key
    // constraint would be violated by a delete.
    DeleteReferenceAction() tree.ReferenceAction

    // UpdateReferenceAction returns the action to be performed if the foreign key
    // constraint would be violated by an update.
    UpdateReferenceAction() tree.ReferenceAction
}

ForeignKeyConstraint represents a foreign key constraint. A foreign key constraint has an origin (or referencing) side and a referenced side. For example:

ALTER TABLE o ADD CONSTRAINT fk FOREIGN KEY (a,b) REFERENCES r(a,b)

Here o is the origin table, r is the referenced table, and we have two pairs of columns: (o.a,r.a) and (o.b,r.b).

type HistogramBucket Uses

type HistogramBucket struct {
    // NumEq is the estimated number of values equal to UpperBound.
    NumEq float64

    // NumRange is the estimated number of values between the upper bound of the
    // previous bucket and UpperBound (both boundaries are exclusive).
    // The first bucket should always have NumRange=0.
    NumRange float64

    // DistinctRange is the estimated number of distinct values between the upper
    // bound of the previous bucket and UpperBound (both boundaries are
    // exclusive).
    DistinctRange float64

    // UpperBound is the upper bound of the bucket.
    UpperBound tree.Datum
}

HistogramBucket contains the data for a single histogram bucket. Note that NumEq, NumRange, and DistinctRange are floats so the statisticsBuilder can apply filters to the histogram.

type Index Uses

type Index interface {
    // ID is the stable identifier for this index that is guaranteed to be
    // unique within the owning table. See the comment for StableID for more
    // detail.
    ID() StableID

    // Name is the name of the index.
    Name() tree.Name

    // Table returns a reference to the table this index is based on.
    Table() Table

    // Ordinal returns the ordinal of this index within the context of its Table.
    // Specifically idx = Table().Index(idx.Ordinal).
    Ordinal() int

    // IsUnique returns true if this index is declared as UNIQUE in the schema.
    IsUnique() bool

    // IsInverted returns true if this is a JSON inverted index.
    IsInverted() bool

    // ColumnCount returns the number of columns in the index. This includes
    // columns that were part of the index definition (including the STORING
    // clause), as well as implicitly added primary key columns.
    ColumnCount() int

    // KeyColumnCount returns the number of columns in the index that are part
    // of its unique key. No two rows in the index will have the same values for
    // those columns (where NULL values are treated as equal). Every index has a
    // set of key columns, regardless of how it was defined, because Cockroach
    // will implicitly add primary key columns to any index which would not
    // otherwise have a key, like when:
    //
    //   1. Index was not declared as UNIQUE.
    //   2. Index was UNIQUE, but one or more columns have NULL values.
    //
    // The second case is subtle, because UNIQUE indexes treat NULL values as if
    // they are *not* equal to one another. For example, this is allowed with a
    // unique (b, c) index, even though it appears there are duplicate rows:
    //
    //   b     c
    //   -------
    //   NULL  1
    //   NULL  1
    //
    // Since keys treat NULL values as if they *are* equal to each other,
    // Cockroach must append the primary key columns in order to ensure this
    // index has a key. If the primary key of this table was column (a), then
    // the key of this secondary index would be (b,c,a).
    //
    // The key columns are always a prefix of the full column list, where
    // KeyColumnCount <= ColumnCount.
    KeyColumnCount() int

    // LaxKeyColumnCount returns the number of columns in the index that are
    // part of its "lax" key. Lax keys follow the same rules as keys (sometimes
    // referred to as "strict" keys), except that NULL values are treated as
    // *not* equal to one another, as in the case for UNIQUE indexes. This means
    // that two rows can appear to have duplicate values when one of those values
    // is NULL. See the KeyColumnCount comment for more details and an example.
    //
    // The lax key columns are always a prefix of the key columns, where
    // LaxKeyColumnCount <= KeyColumnCount. However, it is not required that an
    // index have a separate lax key, in which case LaxKeyColumnCount equals
    // KeyColumnCount. Here are the cases:
    //
    //   PRIMARY KEY                : lax key cols = key cols
    //   INDEX (not unique)         : lax key cols = key cols
    //   UNIQUE INDEX, not-null cols: lax key cols = key cols
    //   UNIQUE INDEX, nullable cols: lax key cols < key cols
    //
    // In the first three cases, all strict key columns (and thus all lax key
    // columns as well) are guaranteed to be encoded in the row's key (as opposed
    // to in its value). Note that the third case, the UNIQUE INDEX columns are
    // sufficient to form a strict key without needing to append the primary key
    // columns (which are stored in the value).
    //
    // For the last case of a UNIQUE INDEX with at least one NULL-able column,
    // only the lax key columns are guaranteed to be encoded in the row's key.
    // The strict key columns (the primary key columns in this case) are only
    // encoded in the row's key when at least one of the lax key columns has a
    // NULL value. Therefore, whether the row's key contains all the strict key
    // columns is data-dependent, not schema-dependent.
    LaxKeyColumnCount() int

    // Column returns the ith IndexColumn within the index definition, where
    // i < ColumnCount.
    Column(i int) IndexColumn

    // Zone returns the zone which constrains placement of the index's range
    // replicas. If the index was not explicitly assigned to a zone, then it
    // inherits the zone of its owning table (which in turn inherits from its
    // owning database or the default zone). In addition, any unspecified zone
    // information will also be inherited.
    //
    // NOTE: This zone always applies to the entire index and never to any
    // particular partition of the index.
    Zone() Zone

    // Span returns the KV span associated with the index.
    Span() roachpb.Span

    // PartitionByListPrefixes returns values that correspond to PARTITION BY LIST
    // values. Specifically, it returns a list of tuples where each tuple contains
    // values for a prefix of index columns (indicating a region of the index).
    // Each tuple corresponds to a configured partition or subpartition.
    //
    // Note: this function decodes and allocates datums; use sparingly.
    //
    // Example:
    //
    // CREATE INDEX idx ON t(region,subregion,val) PARTITION BY LIST (region,subregion) (
    //     PARTITION westcoast VALUES IN (('us', 'seattle'), ('us', 'cali')),
    //     PARTITION us VALUES IN (('us', DEFAULT)),
    //     PARTITION eu VALUES IN (('eu', DEFAULT)),
    //     PARTITION default VALUES IN (DEFAULT)
    // );
    //
    // PartitionByListPrefixes() returns
    //  ('us', 'seattle'),
    //  ('us', 'cali'),
    //  ('us'),
    //  ('eu').
    //
    // The intended use of this function is for index skip scans. Each tuple
    // corresponds to a region of the index that we can constrain further. In the
    // example above: if we have a val=1 filter, instead of a full index scan we
    // can skip most of the data under /us/cali and /us/seattle by scanning spans:
    //   [                 - /us/cali      )
    //   [ /us/cali/1      - /us/cali/1    ]
    //   [ /us/cali\x00    - /us/seattle   )
    //   [ /us/seattle/1   - /us/seattle/1 ]
    //   [ /us/seattle\x00 -               ]
    //
    PartitionByListPrefixes() []tree.Datums
}

Index is an interface to a database index, exposing only the information needed by the query optimizer. Every index is treated as unique by the optimizer. If an index was declared as non-unique, then the system will add implicit columns from the primary key in order to make it unique (and even add an implicit primary key based on a hidden rowid column if a primary key was not explicitly declared).

type IndexColumn Uses

type IndexColumn struct {
    // Column is a reference to the column returned by Table.Column, given the
    // column ordinal.
    Column

    // Ordinal is the ordinal position of the indexed column in the table being
    // indexed. It is always >= 0 and < Table.ColumnCount.
    Ordinal int

    // Descending is true if the index is ordered from greatest to least on
    // this column, rather than least to greatest.
    Descending bool
}

IndexColumn describes a single column that is part of an index definition.

type IndexOrdinal Uses

type IndexOrdinal = int

IndexOrdinal identifies an index (in the context of a Table).

const PrimaryIndex IndexOrdinal = 0

PrimaryIndex selects the primary index of a table when calling the Table.Index method. Every table is guaranteed to have a unique primary index, even if it meant adding a hidden unique rowid column.

type Object Uses

type Object interface {
    // ID is the unique, stable identifier for this object. See the comment for
    // StableID for more detail.
    ID() StableID

    // Equals returns true if this object is identical to the given Object.
    //
    // Two objects are identical if they have the same identifier and there were
    // no changes to schema or table statistics between the times the two objects
    // were resolved.
    //
    // Used for invalidating cached plans.
    Equals(other Object) bool
}

Object is implemented by all objects in the catalog.

type ReplicaConstraints Uses

type ReplicaConstraints interface {
    ConstraintSet

    // ReplicaCount returns the number of replicas that should abide by this set
    // of constraints. If 0, then the constraints apply to all replicas of the
    // range (and there can be only one ReplicaConstraints in the Zone).
    ReplicaCount() int32
}

ReplicaConstraints is a set of constraints that apply to one or more replicas of a range, restricting which nodes can host that range. For example, if a table range has three replicas, then two of the replicas might be pinned to nodes in one region, whereas the third might be pinned to another region.

type Schema Uses

type Schema interface {
    Object

    // Name returns the fully normalized, fully qualified, and fully resolved
    // name of the schema (<db-name>.<schema-name>). The ExplicitCatalog
    // and ExplicitSchema fields will always be true, since all parts of the
    // name are always specified.
    Name() *SchemaName

    // GetDataSourceNames returns the list of names for the data sources that the
    // schema contains.
    GetDataSourceNames(ctx context.Context) ([]DataSourceName, error)
}

Schema is an interface to a database schema, which is a namespace that contains other database objects, like tables and views. Examples of schema are "public" and "crdb_internal".

type SchemaName Uses

type SchemaName = tree.TableNamePrefix

SchemaName is an alias for tree.TableNamePrefix, since it consists of the catalog + schema name.

type Sequence Uses

type Sequence interface {
    DataSource

    // SequenceMarker is a dummy method, included as a safety measure so that
    // every DataSource does not trivially implement Sequence.
    SequenceMarker()
}

Sequence is an interface to a database sequence.

type StableID Uses

type StableID uint64

StableID permanently and uniquely identifies a catalog object (table, view, index, column, etc.) within its scope:

data source StableID: unique within database
index StableID: unique within table
column StableID: unique within table

If a new catalog object is created, it will always be assigned a new StableID that has never, and will never, be reused by a different object in the same scope. This uniqueness guarantee is true even if the new object has the same name and schema as an old (and possibly dropped) object. The StableID will never change as long as the object exists.

Note that while two instances of the same catalog object will always have the same StableID, they can have different schema if the schema has changed over time. See the Version type comments for more details.

For most sqlbase objects, the StableID is the 32-bit descriptor ID. However, this is not always the case. For example, the StableID for virtual tables prepends the database ID, since the same descriptor ID is reused across databases.

type Table Uses

type Table interface {
    DataSource

    // IsVirtualTable returns true if this table is a special system table that
    // constructs its rows "on the fly" when it's queried. An example is the
    // information_schema tables.
    IsVirtualTable() bool

    // IsInterleaved returns true if any of this table's indexes are interleaved
    // with index(es) from other table(s).
    IsInterleaved() bool

    // ColumnCount returns the number of public columns in the table. Public
    // columns are not currently being added or dropped from the table. This
    // method should be used when mutation columns can be ignored (the common
    // case).
    ColumnCount() int

    // WritableColumnCount returns the number of public and write-only columns in
    // the table. Although write-only columns are not visible, any inserts and
    // updates must still set them. WritableColumnCount is always >= ColumnCount.
    WritableColumnCount() int

    // DeletableColumnCount returns the number of public, write-only, and
    // delete- only columns in the table. DeletableColumnCount is always >=
    // WritableColumnCount.
    DeletableColumnCount() int

    // Column returns a Column interface to the column at the ith ordinal
    // position within the table, where i < ColumnCount. Note that the Columns
    // collection includes mutation columns, if present. Mutation columns are in
    // the process of being added or dropped from the table, and may need to have
    // default or computed values set when inserting or updating rows. See this
    // RFC for more details:
    //
    //   cockroachdb/cockroach/docs/RFCS/20151014_online_schema_change.md
    //
    // Writable columns are always situated after public columns, and are followed
    // by deletable columns.
    Column(i int) Column

    // IndexCount returns the number of public indexes defined on this table.
    // Public indexes are not currently being added or dropped from the table.
    // This method should be used when mutation columns can be ignored (the common
    // case). The returned indexes include the primary index, so the count is
    // always >= 1 (except for virtual tables, which have no indexes).
    IndexCount() int

    // WritableIndexCount returns the number of public and write-only indexes
    // defined on this table. Although write-only indexes are not visible, any
    // table mutation operations must still be applied to them. WritableIndexCount
    // is always >= IndexCount.
    WritableIndexCount() int

    // DeletableIndexCount returns the number of public, write-only, and
    // delete-onlyindexes defined on this table. DeletableIndexCount is always
    // >= WritableIndexCount.
    DeletableIndexCount() int

    // Index returns the ith index, where i < DeletableIndexCount. Except for
    // virtual tables, the table's primary index is always the 0th index, and is
    // always present (use cat.PrimaryIndex to select it). The primary index
    // corresponds to the table's primary key. If a primary key was not
    // explicitly specified, then the system implicitly creates one based on a
    // hidden rowid column.
    Index(i IndexOrdinal) Index

    // StatisticCount returns the number of statistics available for the table.
    StatisticCount() int

    // Statistic returns the ith statistic, where i < StatisticCount.
    Statistic(i int) TableStatistic

    // CheckCount returns the number of check constraints present on the table.
    CheckCount() int

    // Check returns the ith check constraint, where i < CheckCount.
    Check(i int) CheckConstraint

    // FamilyCount returns the number of column families present on the table.
    // There is always at least one primary family (always family 0) where columns
    // go if they are not explicitly assigned to another family. The primary
    // family is the first family that was explicitly specified by the user, or
    // is a synthesized family if no families were explicitly specified.
    FamilyCount() int

    // Family returns the interface for the ith column family, where
    // i < FamilyCount.
    Family(i int) Family

    // OutboundForeignKeyCount returns the number of outbound foreign key
    // references (where this is the origin table).
    OutboundForeignKeyCount() int

    // OutboundForeignKeyCount returns the ith outbound foreign key reference.
    OutboundForeignKey(i int) ForeignKeyConstraint

    // InboundForeignKeyCount returns the number of inbound foreign key references
    // (where this is the referenced table).
    InboundForeignKeyCount() int

    // InboundForeignKey returns the ith inbound foreign key reference.
    InboundForeignKey(i int) ForeignKeyConstraint
}

Table is an interface to a database table, exposing only the information needed by the query optimizer.

Both columns and indexes are grouped into three sets: public, write-only, and delete-only. When a column or index is added or dropped, it proceeds through each of the three states as that schema change is incrementally rolled out to the cluster without blocking ongoing queries. In the public state, reads, writes, and deletes are allowed. In the write-only state, only writes and deletes are allowed. Finally, in the delete-only state, only deletes are allowed. Further details about "online schema change" can be found in:

docs/RFCS/20151014_online_schema_change.md

Calling code must take care to use the right collection of columns or indexes. Usually this should be the public collections, since most usages are read-only, but mutation operators generally need to consider non-public columns and indexes.

type TableStatistic Uses

type TableStatistic interface {
    // CreatedAt indicates when the statistic was generated.
    CreatedAt() time.Time

    // ColumnCount is the number of columns the statistic pertains to.
    ColumnCount() int

    // ColumnOrdinal returns the column ordinal (see Table.Column) of the ith
    // column in this statistic, with 0 <= i < ColumnCount.
    ColumnOrdinal(i int) int

    // RowCount returns the estimated number of rows in the table.
    RowCount() uint64

    // DistinctCount returns the estimated number of distinct values on the
    // columns of the statistic. If there are multiple columns, each "value" is a
    // tuple with the values on each column.
    DistinctCount() uint64

    // NullCount returns the estimated number of rows which have a NULL value on
    // any column in the statistic.
    NullCount() uint64

    // Histogram returns a slice of histogram buckets, sorted by UpperBound.
    // It is only used for single-column stats (i.e., when ColumnCount() = 1),
    // and it represents the distribution of values for that column.
    // See HistogramBucket for more details.
    Histogram() []HistogramBucket
}

TableStatistic is an interface to a table statistic. Each statistic is associated with a set of columns.

type View Uses

type View interface {
    DataSource

    // Query returns the SQL text that specifies the SELECT query that constitutes
    // this view.
    Query() string

    // ColumnNameCount returns the number of column names specified in the view.
    // If zero, then the columns are not aliased. Otherwise, it will match the
    // number of columns in the view.
    ColumnNameCount() int

    // ColumnNames returns the name of the column at the ith ordinal position
    // within the view, where i < ColumnNameCount.
    ColumnName(i int) tree.Name

    // IsSystemView returns true if this view is a system view (like
    // crdb_internal.ranges).
    IsSystemView() bool
}

View is an interface to a database view, exposing only the information needed by the query optimizer.

type Zone Uses

type Zone interface {
    // ReplicaConstraintsCount returns the number of replica constraint sets that
    // are part of this zone.
    ReplicaConstraintsCount() int

    // ReplicaConstraints returns the ith set of replica constraints in the zone,
    // where i < ReplicaConstraintsCount.
    ReplicaConstraints(i int) ReplicaConstraints

    // LeasePreferenceCount returns the number of lease preferences that are part
    // of this zone.
    LeasePreferenceCount() int

    // LeasePreference returns the ith lease preference in the zone, where
    // i < LeasePreferenceCount.
    LeasePreference(i int) ConstraintSet
}

Zone is an interface to zone configuration information used by the optimizer. The optimizer prefers indexes with constraints that best match the locality of the gateway node that plans the query.

Package cat imports 12 packages (graph) and is imported by 35 packages. Updated 2019-09-13. Refresh now. Tools for package owners.