tidb: github.com/pingcap/tidb/table Index | Files | Directories

package table

import "github.com/pingcap/tidb/table"


Package Files

column.go index.go table.go


var (
    // ErrColumnCantNull is used for inserting null to a not null column.
    ErrColumnCantNull = dbterror.ClassTable.NewStd(mysql.ErrBadNull)
    // ErrUnknownColumn is returned when accessing an unknown column.
    ErrUnknownColumn = dbterror.ClassTable.NewStd(mysql.ErrBadField)

    // ErrNoDefaultValue is used when insert a row, the column value is not given, and the column has not null flag
    // and it doesn't have a default value.
    ErrNoDefaultValue = dbterror.ClassTable.NewStd(mysql.ErrNoDefaultForField)
    // ErrIndexOutBound returns for index column offset out of bound.
    ErrIndexOutBound = dbterror.ClassTable.NewStd(mysql.ErrIndexOutBound)
    // ErrUnsupportedOp returns for unsupported operation.
    ErrUnsupportedOp = dbterror.ClassTable.NewStd(mysql.ErrUnsupportedOp)
    // ErrRowNotFound returns for row not found.
    ErrRowNotFound = dbterror.ClassTable.NewStd(mysql.ErrRowNotFound)
    // ErrTableStateCantNone returns for table none state.
    ErrTableStateCantNone = dbterror.ClassTable.NewStd(mysql.ErrTableStateCantNone)
    // ErrColumnStateCantNone returns for column none state.
    ErrColumnStateCantNone = dbterror.ClassTable.NewStd(mysql.ErrColumnStateCantNone)
    // ErrColumnStateNonPublic returns for column non-public state.
    ErrColumnStateNonPublic = dbterror.ClassTable.NewStd(mysql.ErrColumnStateNonPublic)
    // ErrIndexStateCantNone returns for index none state.
    ErrIndexStateCantNone = dbterror.ClassTable.NewStd(mysql.ErrIndexStateCantNone)
    // ErrInvalidRecordKey returns for invalid record key.
    ErrInvalidRecordKey = dbterror.ClassTable.NewStd(mysql.ErrInvalidRecordKey)
    // ErrTruncatedWrongValueForField returns for truncate wrong value for field.
    ErrTruncatedWrongValueForField = dbterror.ClassTable.NewStd(mysql.ErrTruncatedWrongValueForField)
    // ErrUnknownPartition returns unknown partition error.
    ErrUnknownPartition = dbterror.ClassTable.NewStd(mysql.ErrUnknownPartition)
    // ErrNoPartitionForGivenValue returns table has no partition for value.
    ErrNoPartitionForGivenValue = dbterror.ClassTable.NewStd(mysql.ErrNoPartitionForGivenValue)
    // ErrLockOrActiveTransaction returns when execute unsupported statement in a lock session or an active transaction.
    ErrLockOrActiveTransaction = dbterror.ClassTable.NewStd(mysql.ErrLockOrActiveTransaction)
    // ErrSequenceHasRunOut returns when sequence has run out.
    ErrSequenceHasRunOut = dbterror.ClassTable.NewStd(mysql.ErrSequenceRunOut)
    // ErrRowDoesNotMatchGivenPartitionSet returns when the destination partition conflict with the partition selection.
    ErrRowDoesNotMatchGivenPartitionSet = dbterror.ClassTable.NewStd(mysql.ErrRowDoesNotMatchGivenPartitionSet)
var MockTableFromMeta func(tableInfo *model.TableInfo) Table

MockTableFromMeta only serves for test.

var TableFromMeta func(allocators autoid.Allocators, tblInfo *model.TableInfo) (Table, error)

TableFromMeta builds a table.Table from *model.TableInfo. Currently, it is assigned to tables.TableFromMeta in tidb package's init function.

func AllocAutoIncrementValue Uses

func AllocAutoIncrementValue(ctx context.Context, t Table, sctx sessionctx.Context) (int64, error)

AllocAutoIncrementValue allocates an auto_increment value for a new row.

func AllocBatchAutoIncrementValue Uses

func AllocBatchAutoIncrementValue(ctx context.Context, t Table, sctx sessionctx.Context, N int) (firstID int64, increment int64, err error)

AllocBatchAutoIncrementValue allocates batch auto_increment value for rows, returning firstID, increment and err. The caller can derive the autoID by adding increment to firstID for N-1 times.

func CastValue Uses

func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo, returnOverflow, forceIgnoreTruncate bool) (casted types.Datum, err error)

CastValue casts a value based on column type. If forceIgnoreTruncate is true, truncated errors will be ignored. If returnOverflow is true, don't handle overflow errors in this function. It's safe now and it's the same as the behavior of select statement. Set it to true only in FillVirtualColumnValue and UnionScanExec.Next() If the handle of err is changed latter, the behavior of forceIgnoreTruncate also need to change. TODO: change the third arg to TypeField. Not pass ColumnInfo.

func CheckNotNull Uses

func CheckNotNull(cols []*Column, row []types.Datum) error

CheckNotNull checks if row has nil value set to a column with NotNull flag set.

func CheckOnce Uses

func CheckOnce(cols []*Column) error

CheckOnce checks if there are duplicated column names in cols.

func ColDescFieldNames Uses

func ColDescFieldNames(full bool) []string

ColDescFieldNames returns the fields name in result set for desc and show columns.

func EvalColDefaultExpr Uses

func EvalColDefaultExpr(ctx sessionctx.Context, col *model.ColumnInfo, defaultExpr ast.ExprNode) (types.Datum, error)

EvalColDefaultExpr eval default expr node to explicit default value.

func GetColDefaultValue Uses

func GetColDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo) (types.Datum, error)

GetColDefaultValue gets default value of the column.

func GetColOriginDefaultValue Uses

func GetColOriginDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo) (types.Datum, error)

GetColOriginDefaultValue gets default value of the column from original default value.

func GetZeroValue Uses

func GetZeroValue(col *model.ColumnInfo) types.Datum

GetZeroValue gets zero value for given column type.

func OptionalFsp Uses

func OptionalFsp(fieldType *types.FieldType) string

OptionalFsp convert a FieldType.Decimal to string.

type AddRecordOpt Uses

type AddRecordOpt struct {
    IsUpdate      bool
    ReserveAutoID int

AddRecordOpt contains the options will be used when adding a record.

type AddRecordOption Uses

type AddRecordOption interface {

AddRecordOption is defined for the AddRecord() method of the Table interface.

var IsUpdate AddRecordOption = isUpdate{}

IsUpdate is a defined value for AddRecordOptFunc.

type ColDesc Uses

type ColDesc struct {
    Field string
    Type  string
    // Charset is nil if the column doesn't have a charset, or a string indicating the charset name.
    Charset interface{}
    // Collation is nil if the column doesn't have a collation, or a string indicating the collation name.
    Collation    interface{}
    Null         string
    Key          string
    DefaultValue interface{}
    Extra        string
    Privileges   string
    Comment      string

ColDesc describes column information like MySQL desc and show columns do.

func NewColDesc Uses

func NewColDesc(col *Column) *ColDesc

NewColDesc returns a new ColDesc for a column.

type Column Uses

type Column struct {
    // If this column is a generated column, the expression will be stored here.
    GeneratedExpr ast.ExprNode
    // If this column has default expr value, this expression will be stored here.
    DefaultExpr ast.ExprNode

Column provides meta data describing a table column.

func FindCol Uses

func FindCol(cols []*Column, name string) *Column

FindCol finds column in cols by name.

func FindCols Uses

func FindCols(cols []*Column, names []string, pkIsHandle bool) ([]*Column, string)

FindCols finds columns in cols by names. If pkIsHandle is false and name is ExtraHandleName, the extra handle column will be added. If any columns don't match, return nil and the first missing column's name

func FindOnUpdateCols Uses

func FindOnUpdateCols(cols []*Column) []*Column

FindOnUpdateCols finds columns which have OnUpdateNow flag.

func ToColumn Uses

func ToColumn(col *model.ColumnInfo) *Column

ToColumn converts a *model.ColumnInfo to *Column.

func (*Column) CheckNotNull Uses

func (c *Column) CheckNotNull(data *types.Datum) error

CheckNotNull checks if nil value set to a column with NotNull flag is set.

func (*Column) HandleBadNull Uses

func (c *Column) HandleBadNull(d *types.Datum, sc *stmtctx.StatementContext) error

HandleBadNull handles the bad null error. If BadNullAsWarning is true, it will append the error as a warning, else return the error.

func (*Column) IsCommonHandleColumn Uses

func (c *Column) IsCommonHandleColumn(tbInfo *model.TableInfo) bool

IsCommonHandleColumn checks if the column is common handle column.

func (*Column) IsPKHandleColumn Uses

func (c *Column) IsPKHandleColumn(tbInfo *model.TableInfo) bool

IsPKHandleColumn checks if the column is primary key handle column.

func (*Column) String Uses

func (c *Column) String() string

String implements fmt.Stringer interface.

func (*Column) ToInfo Uses

func (c *Column) ToInfo() *model.ColumnInfo

ToInfo casts Column to model.ColumnInfo NOTE: DONT modify return value.

type CreateIdxOpt Uses

type CreateIdxOpt struct {
    Ctx             context.Context
    SkipHandleCheck bool // If true, skip the handle constraint check.
    Untouched       bool // If true, the index key/value is no need to commit.

CreateIdxOpt contains the options will be used when creating an index.

type CreateIdxOptFunc Uses

type CreateIdxOptFunc func(*CreateIdxOpt)

CreateIdxOptFunc is defined for the Create() method of Index interface. Here is a blog post about how to use this pattern: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

var IndexIsUntouched CreateIdxOptFunc = func(opt *CreateIdxOpt) {
    opt.Untouched = true

IndexIsUntouched uses to indicate the index kv is untouched.

var SkipHandleCheck CreateIdxOptFunc = func(opt *CreateIdxOpt) {
    opt.SkipHandleCheck = true

SkipHandleCheck is a defined value of CreateIdxFunc.

func WithCtx Uses

func WithCtx(ctx context.Context) CreateIdxOptFunc

WithCtx returns a CreateIdxFunc. This option is used to pass context.Context.

func (CreateIdxOptFunc) ApplyOn Uses

func (f CreateIdxOptFunc) ApplyOn(opt *AddRecordOpt)

ApplyOn implements the AddRecordOption interface, so any CreateIdxOptFunc can be passed as the optional argument to the table.AddRecord method.

type Index Uses

type Index interface {
    // Meta returns IndexInfo.
    Meta() *model.IndexInfo
    // Create supports insert into statement.
    Create(ctx sessionctx.Context, us kv.UnionStore, indexedValues []types.Datum, h kv.Handle, opts ...CreateIdxOptFunc) (kv.Handle, error)
    // Delete supports delete from statement.
    Delete(sc *stmtctx.StatementContext, us kv.UnionStore, indexedValues []types.Datum, h kv.Handle) error
    // Drop supports drop table, drop index statements.
    Drop(us kv.UnionStore) error
    // Exist supports check index exists or not.
    Exist(sc *stmtctx.StatementContext, us kv.UnionStore, indexedValues []types.Datum, h kv.Handle) (bool, kv.Handle, error)
    // GenIndexKey generates an index key.
    GenIndexKey(sc *stmtctx.StatementContext, indexedValues []types.Datum, h kv.Handle, buf []byte) (key []byte, distinct bool, err error)
    // Seek supports where clause.
    Seek(sc *stmtctx.StatementContext, r kv.Retriever, indexedValues []types.Datum) (iter IndexIterator, hit bool, err error)
    // SeekFirst supports aggregate min and ascend order by.
    SeekFirst(r kv.Retriever) (iter IndexIterator, err error)
    // FetchValues fetched index column values in a row.
    // Param columns is a reused buffer, if it is not nil, FetchValues will fill the index values in it,
    // and return the buffer, if it is nil, FetchValues will allocate the buffer instead.
    FetchValues(row []types.Datum, columns []types.Datum) ([]types.Datum, error)

Index is the interface for index data on KV store.

type IndexIterator Uses

type IndexIterator interface {
    Next() (k []types.Datum, h kv.Handle, err error)

IndexIterator is the interface for iterator of index data on KV store.

type PartitionedTable Uses

type PartitionedTable interface {
    GetPartition(physicalID int64) PhysicalTable
    GetPartitionByRow(sessionctx.Context, []types.Datum) (PhysicalTable, error)

PartitionedTable is a Table, and it has a GetPartition() method. GetPartition() gets the partition from a partition table by a physical table ID,

type PhysicalTable Uses

type PhysicalTable interface {
    GetPhysicalID() int64

PhysicalTable is an abstraction for two kinds of table representation: partition or non-partitioned table. PhysicalID is a ID that can be used to construct a key ranges, all the data in the key range belongs to the corresponding PhysicalTable. For a non-partitioned table, its PhysicalID equals to its TableID; For a partition of a partitioned table, its PhysicalID is the partition's ID.

type RecordIterFunc Uses

type RecordIterFunc func(h kv.Handle, rec []types.Datum, cols []*Column) (more bool, err error)

RecordIterFunc is used for low-level record iteration.

type Table Uses

type Table interface {
    // IterRecords iterates records in the table and calls fn.
    IterRecords(ctx sessionctx.Context, startKey kv.Key, cols []*Column, fn RecordIterFunc) error

    // RowWithCols returns a row that contains the given cols.
    RowWithCols(ctx sessionctx.Context, h kv.Handle, cols []*Column) ([]types.Datum, error)

    // Row returns a row for all columns.
    Row(ctx sessionctx.Context, h kv.Handle) ([]types.Datum, error)

    // Cols returns the columns of the table which is used in select, including hidden columns.
    Cols() []*Column

    // VisibleCols returns the columns of the table which is used in select, excluding hidden columns.
    VisibleCols() []*Column

    // HiddenCols returns the hidden columns of the table.
    HiddenCols() []*Column

    // WritableCols returns columns of the table in writable states.
    // Writable states includes Public, WriteOnly, WriteOnlyReorganization.
    WritableCols() []*Column

    // FullHiddenColsAndVisibleCols returns hidden columns in all states and unhidden columns in public states.
    FullHiddenColsAndVisibleCols() []*Column

    // Indices returns the indices of the table.
    Indices() []Index

    // WritableIndices returns write-only and public indices of the table.
    WritableIndices() []Index

    // DeletableIndices returns delete-only, write-only and public indices of the table.
    DeletableIndices() []Index

    // RecordPrefix returns the record key prefix.
    RecordPrefix() kv.Key

    // IndexPrefix returns the index key prefix.
    IndexPrefix() kv.Key

    // FirstKey returns the first key.
    FirstKey() kv.Key

    // RecordKey returns the key in KV storage for the row.
    RecordKey(h kv.Handle) kv.Key

    // AddRecord inserts a row which should contain only public columns
    AddRecord(ctx sessionctx.Context, r []types.Datum, opts ...AddRecordOption) (recordID kv.Handle, err error)

    // UpdateRecord updates a row which should contain only writable columns.
    UpdateRecord(ctx context.Context, sctx sessionctx.Context, h kv.Handle, currData, newData []types.Datum, touched []bool) error

    // RemoveRecord removes a row in the table.
    RemoveRecord(ctx sessionctx.Context, h kv.Handle, r []types.Datum) error

    // Allocators returns all allocators.
    Allocators(ctx sessionctx.Context) autoid.Allocators

    // RebaseAutoID rebases the auto_increment ID base.
    // If allocIDs is true, it will allocate some IDs and save to the cache.
    // If allocIDs is false, it will not allocate IDs.
    RebaseAutoID(ctx sessionctx.Context, newBase int64, allocIDs bool, tp autoid.AllocatorType) error

    // Meta returns TableInfo.
    Meta() *model.TableInfo

    // Seek returns the handle greater or equal to h.
    Seek(ctx sessionctx.Context, h kv.Handle) (handle kv.Handle, found bool, err error)

    // Type returns the type of table
    Type() Type

Table is used to retrieve and modify rows in table.

type Type Uses

type Type int16

Type , the type of table, store data in different ways.

const (
    // NormalTable , store data in tikv, mocktikv and so on.
    NormalTable Type = iota
    // VirtualTable , store no data, just extract data from the memory struct.
    // ClusterTable , contain the `VirtualTable` in the all cluster tidb nodes.

func (Type) IsClusterTable Uses

func (tp Type) IsClusterTable() bool

IsClusterTable checks whether the table is a cluster table type.

func (Type) IsNormalTable Uses

func (tp Type) IsNormalTable() bool

IsNormalTable checks whether the table is a normal table type.

func (Type) IsVirtualTable Uses

func (tp Type) IsVirtualTable() bool

IsVirtualTable checks whether the table is a virtual table type.

type WithReserveAutoIDHint Uses

type WithReserveAutoIDHint int

WithReserveAutoIDHint tells the AddRecord operation to reserve a batch of auto ID in the stmtctx.

func (WithReserveAutoIDHint) ApplyOn Uses

func (n WithReserveAutoIDHint) ApplyOn(opt *AddRecordOpt)

ApplyOn implements the AddRecordOption interface.



Package table imports 28 packages (graph) and is imported by 501 packages. Updated 2020-11-24. Refresh now. Tools for package owners.