cockroach: github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo Index | Files

package colinfo

import "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"

Package colinfo contains type information and related structures for dealing with columns returned from sql operations.

Index

Package Files

col_type_info.go column_resolver.go column_type_properties.go data_source.go doc.go ordering.go result_columns.go system_columns.go

Constants

const MVCCTimestampColumnID = math.MaxUint32

MVCCTimestampColumnID is the ColumnID of the MVCC timesatmp column. Future system columns will have ID's that decrement from this value.

const MVCCTimestampColumnName = "crdb_internal_mvcc_timestamp"

MVCCTimestampColumnName is the name of the MVCC timestamp system column.

const TableOIDColumnID = MVCCTimestampColumnID - 1

TableOIDColumnID is the ID of the tableoid system column.

Variables

var AllSystemColumnDescs = []descpb.ColumnDescriptor{
    MVCCTimestampColumnDesc,
    TableOIDColumnDesc,
}

AllSystemColumnDescs contains all registered system columns.

var AlterTableRelocateColumns = ResultColumns{
    {Name: "key", Typ: types.Bytes},
    {Name: "pretty", Typ: types.String},
}

AlterTableRelocateColumns are the result columns of an ALTER TABLE/INDEX .. EXPERIMENTAL_RELOCATE statement.

var AlterTableScatterColumns = ResultColumns{
    {Name: "key", Typ: types.Bytes},
    {Name: "pretty", Typ: types.String},
}

AlterTableScatterColumns are the result columns of an ALTER TABLE/INDEX .. SCATTER statement.

var AlterTableSplitColumns = ResultColumns{
    {Name: "key", Typ: types.Bytes},
    {Name: "pretty", Typ: types.String},
    {Name: "split_enforced_until", Typ: types.Timestamp},
}

AlterTableSplitColumns are the result columns of an ALTER TABLE/INDEX .. SPLIT AT statement.

var AlterTableUnsplitColumns = ResultColumns{
    {Name: "key", Typ: types.Bytes},
    {Name: "pretty", Typ: types.String},
}

AlterTableUnsplitColumns are the result columns of an ALTER TABLE/INDEX .. UNSPLIT statement.

var ExplainAnalyzeDebugColumns = ResultColumns{
    {Name: "text", Typ: types.String},
}

ExplainAnalyzeDebugColumns are the result columns of an EXPLAIN ANALYZE (DEBUG) statement.

var ExplainDistSQLColumns = ResultColumns{
    {Name: "automatic", Typ: types.Bool},
    {Name: "url", Typ: types.String},
    {Name: "json", Typ: types.String, Hidden: true},
}

ExplainDistSQLColumns are the result columns of an EXPLAIN (DISTSQL) statement.

var ExplainOptColumns = ResultColumns{
    {Name: "text", Typ: types.String},
}

ExplainOptColumns are the result columns of an EXPLAIN (OPT) statement.

var ExplainPlanColumns = ResultColumns{

    {Name: "tree", Typ: types.String},

    {Name: "field", Typ: types.String},

    {Name: "description", Typ: types.String},
}

ExplainPlanColumns are the result columns of an EXPLAIN (PLAN) ... statement.

var ExplainPlanVerboseColumns = ResultColumns{

    {Name: "tree", Typ: types.String},

    {Name: "level", Typ: types.Int, Hidden: true},

    {Name: "node_type", Typ: types.String, Hidden: true},

    {Name: "field", Typ: types.String},

    {Name: "description", Typ: types.String},

    {Name: "columns", Typ: types.String},

    {Name: "ordering", Typ: types.String},
}

ExplainPlanVerboseColumns are the result columns of an EXPLAIN (PLAN, ...) ... statement when a flag like VERBOSE or TYPES is passed.

var ExplainVecColumns = ResultColumns{
    {Name: "text", Typ: types.String},
}

ExplainVecColumns are the result columns of an EXPLAIN (VEC) statement.

var ExportColumns = ResultColumns{
    {Name: "filename", Typ: types.String},
    {Name: "rows", Typ: types.Int},
    {Name: "bytes", Typ: types.Int},
}

ExportColumns are the result columns of an EXPORT statement.

var MVCCTimestampColumnDesc = descpb.ColumnDescriptor{
    Name:             MVCCTimestampColumnName,
    Type:             MVCCTimestampColumnType,
    Hidden:           true,
    Nullable:         true,
    SystemColumnKind: descpb.SystemColumnKind_MVCCTIMESTAMP,
    ID:               MVCCTimestampColumnID,
}

MVCCTimestampColumnDesc is a column descriptor for the MVCC system column.

var MVCCTimestampColumnType = types.Decimal

MVCCTimestampColumnType is the type of the MVCC timestamp system column.

var ScrubColumns = ResultColumns{
    {Name: "job_uuid", Typ: types.Uuid},
    {Name: "error_type", Typ: types.String},
    {Name: "database", Typ: types.String},
    {Name: "table", Typ: types.String},
    {Name: "primary_key", Typ: types.String},
    {Name: "timestamp", Typ: types.Timestamp},
    {Name: "repaired", Typ: types.Bool},
    {Name: "details", Typ: types.Jsonb},
}

ScrubColumns are the result columns of a SCRUB statement.

var SequenceSelectColumns = ResultColumns{
    {Name: `last_value`, Typ: types.Int},
    {Name: `log_cnt`, Typ: types.Int},
    {Name: `is_called`, Typ: types.Bool},
}

SequenceSelectColumns are the result columns of a sequence data source.

var ShowCompactTraceColumns = ResultColumns{
    {Name: "age", Typ: types.Interval},
    {Name: "message", Typ: types.String},
    {Name: "tag", Typ: types.String},
    {Name: "operation", Typ: types.String},
}

ShowCompactTraceColumns are the result columns of a SHOW COMPACT [KV] TRACE statement.

var ShowFingerprintsColumns = ResultColumns{
    {Name: "index_name", Typ: types.String},
    {Name: "fingerprint", Typ: types.String},
}

ShowFingerprintsColumns are the result columns of a SHOW EXPERIMENTAL_FINGERPRINTS statement.

var ShowLastQueryStatisticsColumns = ResultColumns{
    {Name: "parse_latency", Typ: types.Interval},
    {Name: "plan_latency", Typ: types.Interval},
    {Name: "exec_latency", Typ: types.Interval},
    {Name: "service_latency", Typ: types.Interval},
}

ShowLastQueryStatisticsColumns are the columns of a SHOW LAST QUERY STATISTICS statement.

var ShowReplicaTraceColumns = ResultColumns{
    {Name: "timestamp", Typ: types.TimestampTZ},
    {Name: "node_id", Typ: types.Int},
    {Name: "store_id", Typ: types.Int},
    {Name: "replica_id", Typ: types.Int},
}

ShowReplicaTraceColumns are the result columns of a SHOW EXPERIMENTAL_REPLICA TRACE statement.

var ShowSyntaxColumns = ResultColumns{
    {Name: "field", Typ: types.String},
    {Name: "message", Typ: types.String},
}

ShowSyntaxColumns are the columns of a SHOW SYNTAX statement.

var ShowTraceColumns = ResultColumns{
    {Name: "timestamp", Typ: types.TimestampTZ},
    {Name: "age", Typ: types.Interval},
    {Name: "message", Typ: types.String},
    {Name: "tag", Typ: types.String},
    {Name: "location", Typ: types.String},
    {Name: "operation", Typ: types.String},
    {Name: "span", Typ: types.Int},
}

ShowTraceColumns are the result columns of a SHOW [KV] TRACE statement.

var TableOIDColumnDesc = descpb.ColumnDescriptor{
    Name:             "tableoid",
    Type:             types.Oid,
    Hidden:           true,
    Nullable:         true,
    SystemColumnKind: descpb.SystemColumnKind_TABLEOID,
    ID:               TableOIDColumnID,
}

TableOIDColumnDesc is a column descriptor for the tableoid column.

func AdjustValueToColumnType Uses

func AdjustValueToColumnType(
    typ *types.T, inVal tree.Datum, name *string,
) (outVal tree.Datum, err error)

AdjustValueToColumnType checks that the width (for strings, byte arrays, and bit strings), precision (time), shape/srid (for geospatial types) and scale (for decimals) of the value fits the specified column type.

In case of decimals, it can truncate fractional digits in the input value in order to fit the target column. If the input value fits the target column, it is returned unchanged. If the input value can be truncated to fit, then a truncated copy is returned. Otherwise, an error is returned.

In the case of time, it can truncate fractional digits of time datums to its relevant rounding for the given type definition.

In the case of geospatial types, it will check whether the SRID and Shape in the datum matches the type definition.

This method is used by INSERT and UPDATE.

func CheckDatumTypeFitsColumnType Uses

func CheckDatumTypeFitsColumnType(col *descpb.ColumnDescriptor, typ *types.T) error

CheckDatumTypeFitsColumnType verifies that a given scalar value type is valid to be stored in a column of the given column type.

For the purpose of this analysis, column type aliases are not considered to be different (eg. TEXT and VARCHAR will fit the same scalar type String).

This is used by the UPDATE, INSERT and UPSERT code.

func ColumnTypeIsIndexable Uses

func ColumnTypeIsIndexable(t *types.T) bool

ColumnTypeIsIndexable returns whether the type t is valid as an indexed column.

func ColumnTypeIsInvertedIndexable Uses

func ColumnTypeIsInvertedIndexable(t *types.T) bool

ColumnTypeIsInvertedIndexable returns whether the type t is valid to be indexed using an inverted index.

func CompareDatums Uses

func CompareDatums(ordering ColumnOrdering, evalCtx *tree.EvalContext, lhs, rhs tree.Datums) int

CompareDatums compares two datum rows according to a column ordering. Returns:

- 0 if lhs and rhs are equal on the ordering columns;
- less than 0 if lhs comes first;
- greater than 0 if rhs comes first.

func GetColumnTypes Uses

func GetColumnTypes(desc catalog.TableDescriptor, columnIDs []descpb.ColumnID) ([]*types.T, error)

GetColumnTypes returns the types of the columns with the given IDs.

func GetSystemColumnDescriptorFromID Uses

func GetSystemColumnDescriptorFromID(colID descpb.ColumnID) (*descpb.ColumnDescriptor, error)

GetSystemColumnDescriptorFromID returns a column descriptor corresponding to the system column referred to by the input column ID.

func GetSystemColumnKindFromColumnID Uses

func GetSystemColumnKindFromColumnID(colID descpb.ColumnID) descpb.SystemColumnKind

GetSystemColumnKindFromColumnID returns the kind of system column that colID refers to.

func GetTraceAgeColumnIdx Uses

func GetTraceAgeColumnIdx(compact bool) int

GetTraceAgeColumnIdx retrieves the index of the age column depending on whether the compact format is used.

func HasCompositeKeyEncoding Uses

func HasCompositeKeyEncoding(typ *types.T) bool

HasCompositeKeyEncoding returns true if key columns of the given kind can have a composite encoding. For such types, it can be decided on a case-by-base basis whether a given Datum requires the composite encoding.

As an example of a composite encoding, collated string key columns are encoded partly as a key and partly as a value. The key part is the collation key, so that different strings that collate equal cannot both be used as keys. The value part is the usual UTF-8 encoding of the string, stored so that it can be recovered later for inspection/display.

func IsColIDSystemColumn Uses

func IsColIDSystemColumn(colID descpb.ColumnID) bool

IsColIDSystemColumn returns whether a column ID refers to a system column.

func IsSystemColumnName Uses

func IsSystemColumnName(name string) bool

IsSystemColumnName returns whether or not a name is a reserved system column name.

func MustBeValueEncoded Uses

func MustBeValueEncoded(semanticType *types.T) bool

MustBeValueEncoded returns true if columns of the given kind can only be value encoded.

func NewUndefinedColumnError Uses

func NewUndefinedColumnError(name string) error

NewUndefinedColumnError creates an error that represents a missing database column.

func ProcessTargetColumns Uses

func ProcessTargetColumns(
    tableDesc catalog.TableDescriptor, nameList tree.NameList, ensureColumns, allowMutations bool,
) ([]descpb.ColumnDescriptor, error)

ProcessTargetColumns returns the column descriptors identified by the given name list. It also checks that a given column name is only listed once. If no column names are given (special case for INSERT) and ensureColumns is set, the descriptors for all visible columns are returned. If allowMutations is set, even columns undergoing mutations are added.

func ValidateColumnDefType Uses

func ValidateColumnDefType(t *types.T) error

ValidateColumnDefType returns an error if the type of a column definition is not valid. It is checked when a column is created or altered.

type ColTypeInfo Uses

type ColTypeInfo struct {
    // contains filtered or unexported fields
}

ColTypeInfo is a type that allows multiple representations of column type information (to avoid conversions and allocations).

func ColTypeInfoFromColDescs Uses

func ColTypeInfoFromColDescs(colDescs []descpb.ColumnDescriptor) ColTypeInfo

ColTypeInfoFromColDescs creates a ColTypeInfo from []ColumnDescriptor.

func ColTypeInfoFromColTypes Uses

func ColTypeInfoFromColTypes(colTypes []*types.T) ColTypeInfo

ColTypeInfoFromColTypes creates a ColTypeInfo from []ColumnType.

func ColTypeInfoFromResCols Uses

func ColTypeInfoFromResCols(resCols ResultColumns) ColTypeInfo

ColTypeInfoFromResCols creates a ColTypeInfo from ResultColumns.

func (ColTypeInfo) NumColumns Uses

func (ti ColTypeInfo) NumColumns() int

NumColumns returns the number of columns in the type.

func (ColTypeInfo) Type Uses

func (ti ColTypeInfo) Type(idx int) *types.T

Type returns the datum type of the i-th column.

type ColumnOrderInfo Uses

type ColumnOrderInfo struct {
    ColIdx    int
    Direction encoding.Direction
}

ColumnOrderInfo describes a column (as an index) and a desired order direction.

type ColumnOrdering Uses

type ColumnOrdering []ColumnOrderInfo

ColumnOrdering is used to describe a desired column ordering. For example,

[]ColumnOrderInfo{ {3, encoding.Descending}, {1, encoding.Ascending} }

represents an ordering first by column 3 (descending), then by column 1 (ascending).

var NoOrdering ColumnOrdering

NoOrdering is used to indicate an empty ColumnOrdering.

func (ColumnOrdering) String Uses

func (ordering ColumnOrdering) String(columns ResultColumns) string

type ColumnResolver Uses

type ColumnResolver struct {
    Source *DataSourceInfo

    // ResolverState is modified in-place by the implementation of the
    // tree.ColumnItemResolver interface in resolver.go.
    ResolverState struct {
        ColIdx int
    }
}

ColumnResolver is a utility struct to be used when resolving column names to point to one of the data sources and one of the column IDs in that data source.

func (*ColumnResolver) FindSourceMatchingName Uses

func (r *ColumnResolver) FindSourceMatchingName(
    ctx context.Context, tn tree.TableName,
) (
    res tree.NumResolutionResults,
    prefix *tree.TableName,
    srcMeta tree.ColumnSourceMeta,
    err error,
)

FindSourceMatchingName is part of the tree.ColumnItemResolver interface.

func (*ColumnResolver) FindSourceProvidingColumn Uses

func (r *ColumnResolver) FindSourceProvidingColumn(
    ctx context.Context, col tree.Name,
) (prefix *tree.TableName, srcMeta tree.ColumnSourceMeta, colHint int, err error)

FindSourceProvidingColumn is part of the tree.ColumnItemResolver interface.

func (*ColumnResolver) Resolve Uses

func (r *ColumnResolver) Resolve(
    ctx context.Context,
    prefix *tree.TableName,
    srcMeta tree.ColumnSourceMeta,
    colHint int,
    col tree.Name,
) (tree.ColumnResolutionResult, error)

Resolve is part of the tree.ColumnItemResolver interface.

type DataSourceInfo Uses

type DataSourceInfo struct {
    // SourceColumns match the plan.Columns() 1-to-1. However the column
    // names might be different if the statement renames them using AS.
    SourceColumns ResultColumns

    // SourceAlias indicates to which table the source columns belong.
    // This often corresponds to the original table names for each column but
    // might be different if the statement renames them using AS.
    SourceAlias tree.TableName
}

DataSourceInfo provides column metadata for exactly one data source.

func NewSourceInfoForSingleTable Uses

func NewSourceInfoForSingleTable(tn tree.TableName, columns ResultColumns) *DataSourceInfo

NewSourceInfoForSingleTable creates a simple DataSourceInfo which maps the same tableAlias to all columns.

func (*DataSourceInfo) NodeFormatter Uses

func (src *DataSourceInfo) NodeFormatter(colIdx int) tree.NodeFormatter

NodeFormatter returns a tree.NodeFormatter that, when formatted, represents the object at the input column index.

func (*DataSourceInfo) String Uses

func (src *DataSourceInfo) String() string

type ResultColumn Uses

type ResultColumn struct {
    Name string
    Typ  *types.T

    // If set, this is an implicit column; used internally.
    Hidden bool

    // TableID/PGAttributeNum identify the source of the column, if it is a simple
    // reference to a column of a base table (or view). If it is not a simple
    // reference, these fields are zeroes.
    TableID        descpb.ID // OID of column's source table (pg_attribute.attrelid).
    PGAttributeNum uint32    // Column's number in source table (pg_attribute.attnum).
}

ResultColumn contains the name and type of a SQL "cell".

func (ResultColumn) GetTypeModifier Uses

func (r ResultColumn) GetTypeModifier() int32

GetTypeModifier returns the type modifier for this column. If it is not set, it defaults to returning -1.

type ResultColumns Uses

type ResultColumns []ResultColumn

ResultColumns is the type used throughout the sql module to describe the column types of a table.

func ResultColumnsFromColDescPtrs Uses

func ResultColumnsFromColDescPtrs(
    tableID descpb.ID, colDescs []*descpb.ColumnDescriptor,
) ResultColumns

ResultColumnsFromColDescPtrs converts []*descpb.ColumnDescriptor to []ResultColumn.

func ResultColumnsFromColDescs Uses

func ResultColumnsFromColDescs(
    tableID descpb.ID, colDescs []descpb.ColumnDescriptor,
) ResultColumns

ResultColumnsFromColDescs converts []descpb.ColumnDescriptor to []ResultColumn.

func (ResultColumns) NodeFormatter Uses

func (r ResultColumns) NodeFormatter(colIdx int) tree.NodeFormatter

NodeFormatter returns a tree.NodeFormatter that, when formatted, represents the column at the input column index.

func (ResultColumns) String Uses

func (r ResultColumns) String(printTypes bool, showHidden bool) string

String formats result columns to a string. The column types are printed if printTypes is true. The hidden property is printed if showHidden is true.

func (ResultColumns) TypesEqual Uses

func (r ResultColumns) TypesEqual(other ResultColumns) bool

TypesEqual returns whether the length and types of r matches other. If a type in other is NULL, it is considered equal.

Package colinfo imports 18 packages (graph) and is imported by 19 packages. Updated 2020-10-19. Refresh now. Tools for package owners.