table

package
v1.1.0-beta.0...-de36787 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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)

	// ErrWarnNullToNotnull is like ErrColumnCantNull but it's used in LOAD DATA
	ErrWarnNullToNotnull = dbterror.ClassExecutor.NewStd(mysql.ErrWarnNullToNotnull)

	// 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)
	// ErrTempTableFull returns a table is full error, it's used by temporary table now.
	ErrTempTableFull = dbterror.ClassTable.NewStd(mysql.ErrRecordFileFull)
	// ErrOptOnCacheTable returns when exec unsupported opt at cache mode
	ErrOptOnCacheTable = dbterror.ClassDDL.NewStd(mysql.ErrOptOnCacheTable)
	// ErrCheckConstraintViolated return when check constraint is violated.
	ErrCheckConstraintViolated = dbterror.ClassTable.NewStd(mysql.ErrCheckConstraintViolated)
)
View Source
var MockTableFromMeta func(tableInfo *model.TableInfo) Table

MockTableFromMeta only serves for test.

View Source
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.

Functions

func AllocAutoIncrementValue

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

AllocAutoIncrementValue allocates an auto_increment value for a new row.

func AllocBatchAutoIncrementValue

func AllocBatchAutoIncrementValue(ctx context.Context, t Table, sctx sessionctx.Context, N int) (int64, int64, 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 CastColumnValue

func CastColumnValue(ctx expression.BuildContext, val types.Datum, col *model.ColumnInfo, returnErr, forceIgnoreTruncate bool) (casted types.Datum, err error)

CastColumnValue casts a value based on column type with expression BuildContext

func CastValue

func CastValue(sctx variable.SessionVarsProvider, val types.Datum, col *model.ColumnInfo, returnErr, 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 returnErr is true, directly return any conversion errors. 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 CheckNoDefaultValueForInsert

func CheckNoDefaultValueForInsert(sc *stmtctx.StatementContext, col *model.ColumnInfo) error

CheckNoDefaultValueForInsert checks if the column has no default value before insert data. CheckNoDefaultValueForInsert extracts the check logic from getColDefaultValueFromNil, since getColDefaultValueFromNil function is public path and both read/write and other places use it. But CheckNoDefaultValueForInsert logic should only check before insert.

func CheckOnce

func CheckOnce(cols []*Column) error

CheckOnce checks if there are duplicated column names in cols.

func CheckRowConstraint

func CheckRowConstraint(ctx exprctx.EvalContext, constraints []*Constraint, rowToCheck chunk.Row) error

CheckRowConstraint verify row check constraints.

func CheckRowConstraintWithDatum

func CheckRowConstraintWithDatum(ctx exprctx.EvalContext, constraints []*Constraint, row []types.Datum) error

CheckRowConstraintWithDatum verify row check constraints. It is the same with `CheckRowConstraint` but receives a slice of `types.Datum` instead of `chunk.Row`.

func ColDescFieldNames

func ColDescFieldNames(full bool) []string

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

func ContainsAutoIncrementCol

func ContainsAutoIncrementCol(cols []pmodel.CIStr, tblInfo *model.TableInfo) bool

ContainsAutoIncrementCol checks if there is auto-increment col in given cols

func EvalColDefaultExpr

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

EvalColDefaultExpr eval default expr node to explicit default value.

func FillVirtualColumnValue

func FillVirtualColumnValue(virtualRetTypes []*types.FieldType, virtualColumnIndex []int,
	expCols []*expression.Column, colInfos []*model.ColumnInfo, ectx exprctx.BuildContext, req *chunk.Chunk) error

FillVirtualColumnValue will calculate the virtual column value by evaluating generated expression using rows from a chunk, and then fill this value into the chunk.

func GetColDefaultValue

func GetColDefaultValue(ctx expression.BuildContext, col *model.ColumnInfo) (types.Datum, error)

GetColDefaultValue gets default value of the column.

func GetColOriginDefaultValue

func GetColOriginDefaultValue(ctx expression.BuildContext, col *model.ColumnInfo) (types.Datum, error)

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

func GetColOriginDefaultValueWithoutStrictSQLMode

func GetColOriginDefaultValueWithoutStrictSQLMode(ctx expression.BuildContext, col *model.ColumnInfo) (types.Datum, error)

GetColOriginDefaultValueWithoutStrictSQLMode gets default value of the column from original default value with Strict SQL mode.

func GetZeroValue

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

GetZeroValue gets zero value for given column type.

func HasForeignKeyRefAction

func HasForeignKeyRefAction(fkInfos []*model.FKInfo, constraints []*ast.Constraint, checkConstr *ast.Constraint, dependedCols []pmodel.CIStr) error

HasForeignKeyRefAction checks if there is foreign key with referential action in check constraints

func IfCheckConstraintExprBoolType

func IfCheckConstraintExprBoolType(ctx expression.EvalContext, info *model.ConstraintInfo, tableInfo *model.TableInfo) error

IfCheckConstraintExprBoolType checks whether the check expression is bool type

func IsSupportedExpr

func IsSupportedExpr(constr *ast.Constraint) (bool, error)

IsSupportedExpr checks whether the check constraint expression is allowed

func OptionalFsp

func OptionalFsp(fieldType *types.FieldType) string

OptionalFsp convert a FieldType.GetDecimal() to string.

Types

type AddRecordOpt

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

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

func NewAddRecordOpt

func NewAddRecordOpt(opts ...AddRecordOption) *AddRecordOpt

NewAddRecordOpt creates a new AddRecordOpt with options.

func (*AddRecordOpt) Ctx

func (opt *AddRecordOpt) Ctx() context.Context

Ctx returns the go context in the option

func (*AddRecordOpt) DupKeyCheck

func (opt *AddRecordOpt) DupKeyCheck() DupKeyCheckMode

DupKeyCheck returns the DupKeyCheckMode in the option

func (*AddRecordOpt) GetCreateIdxOpt

func (opt *AddRecordOpt) GetCreateIdxOpt() *CreateIdxOpt

GetCreateIdxOpt creates a CreateIdxOpt.

func (*AddRecordOpt) IsUpdate

func (opt *AddRecordOpt) IsUpdate() bool

IsUpdate indicates whether the `AddRecord` operation is in an update statement.

func (*AddRecordOpt) PessimisticLazyDupKeyCheck

func (opt *AddRecordOpt) PessimisticLazyDupKeyCheck() PessimisticLazyDupKeyCheckMode

PessimisticLazyDupKeyCheck returns the PessimisticLazyDupKeyCheckMode in the option

func (*AddRecordOpt) ReserveAutoID

func (opt *AddRecordOpt) ReserveAutoID() int

ReserveAutoID indicates the auto id count that should be reserved.

type AddRecordOption

type AddRecordOption interface {
	// contains filtered or unexported methods
}

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

var IsUpdate AddRecordOption = isUpdate{}

IsUpdate is a defined value for AddRecordOptFunc.

type AllocatorContext

type AllocatorContext = tblctx.AllocatorContext

AllocatorContext is used to provide context for method `table.Allocators`.

type CachedTable

type CachedTable interface {
	Table

	Init(exec sqlexec.SQLExecutor) error

	// TryReadFromCache checks if the cache table is readable.
	TryReadFromCache(ts uint64, leaseDuration time.Duration) (kv.MemBuffer, bool)

	// UpdateLockForRead if you cannot meet the conditions of the read buffer,
	// you need to update the lock information and read the data from the original table
	UpdateLockForRead(ctx context.Context, store kv.Storage, ts uint64, leaseDuration time.Duration)

	// WriteLockAndKeepAlive first obtain the write lock, then it renew the lease to keep the lock alive.
	// 'exit' is a channel to tell the keep alive goroutine to exit.
	// The result is sent to the 'wg' channel.
	WriteLockAndKeepAlive(ctx context.Context, exit chan struct{}, leasePtr *uint64, wg chan error)
}

CachedTable is a Table, and it has a UpdateLockForRead() method UpdateLockForRead() according to the reasons for not meeting the read conditions, update the lock information, And at the same time reload data from the original table.

type ClonableExprNode

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

ClonableExprNode is a wrapper for ast.ExprNode.

func NewClonableExprNode

func NewClonableExprNode(ctor func() ast.ExprNode, internal ast.ExprNode) *ClonableExprNode

NewClonableExprNode creates a ClonableExprNode.

func (*ClonableExprNode) Clone

func (n *ClonableExprNode) Clone() ast.ExprNode

Clone makes a "copy" of internal ast.ExprNode by reconstructing it.

func (*ClonableExprNode) Internal

func (n *ClonableExprNode) Internal() ast.ExprNode

Internal returns the reference of the internal ast.ExprNode. Note: only use this method when you are sure that the internal ast.ExprNode is not modified concurrently.

type ColDesc

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 any
	// Collation is nil if the column doesn't have a collation, or a string indicating the collation name.
	Collation    any
	Null         string
	Key          string
	DefaultValue any
	Extra        string
	Privileges   string
	Comment      string
}

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

func NewColDesc

func NewColDesc(col *Column) *ColDesc

NewColDesc returns a new ColDesc for a column.

type Column

type Column struct {
	*model.ColumnInfo
	// If this column is a generated column, the expression will be stored here.
	GeneratedExpr *ClonableExprNode
	// 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

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

FindCol finds column in cols by name.

func FindColLowerCase

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

FindColLowerCase finds column in cols by name. It assumes the name is lowercase.

func FindCols

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. Please consider FindColumns() first for a better performance.

func FindColumns

func FindColumns(cols []*Column, names []string, pkIsHandle bool) (foundCols []*Column, missingOffset int)

FindColumns finds columns in cols by names with a better performance than FindCols(). It assumes names are lowercase.

func FindOnUpdateCols

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

FindOnUpdateCols finds columns which have OnUpdateNow flag.

func ToColumn

func ToColumn(col *model.ColumnInfo) *Column

ToColumn converts a *model.ColumnInfo to *Column.

func (*Column) CheckNotNull

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

CheckNotNull checks if nil value set to a column with NotNull flag is set. When caller is LOAD DATA, `rowCntInLoadData` should be greater than 0 and it will return a ErrWarnNullToNotnull when error. Otherwise, it will return a ErrColumnCantNull when error.

func (*Column) HandleBadNull

func (c *Column) HandleBadNull(
	ec errctx.Context,
	d *types.Datum,
	rowCntInLoadData uint64) error

HandleBadNull handles the bad null error. When caller is LOAD DATA, `rowCntInLoadData` should be greater than 0 the error is ErrWarnNullToNotnull. Otherwise, the error is ErrColumnCantNull. If BadNullAsWarning is true, it will append the error as a warning, else return the error.

func (*Column) IsCommonHandleColumn

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

IsCommonHandleColumn checks if the column is common handle column.

func (*Column) IsPKHandleColumn

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

IsPKHandleColumn checks if the column is primary key handle column.

func (*Column) String

func (c *Column) String() string

String implements fmt.Stringer interface.

func (*Column) ToInfo

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

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

type ColumnsSizeHelper

type ColumnsSizeHelper struct {
	// NotPruned is a bitset to record the columns that are not pruned.
	// The ith bit is 1 means the ith public column is not pruned.
	NotPruned *bitset.BitSet
	// If the column is pruned, we use the estimated avg size. They are stored by their ordinal in the table.
	// The ith element is the estimated size of the ith pruned public column.
	AvgSizes []float64
	// If the column is not pruned, we use the accurate size. They are stored by their ordinal in the pruned row.
	// The ith element is the position of the ith public column in the pruned row.
	PublicColsLayout []int
}

ColumnsSizeHelper records the column size information. We're updating the total column size and total row size used in table statistics when doing DML. If the column is pruned when doing DML, we can't get the accurate size of the column. So we need the estimated avg size.

  • If the column is not pruned, we can calculate its acurate size by the real data.
  • Otherwise, we use the estimated avg size given by table statistics and field type information.

type CommonMutateOptFunc

type CommonMutateOptFunc func(*commonMutateOpt)

CommonMutateOptFunc is a function to provide common options for mutating a table.

func WithCtx

func WithCtx(ctx context.Context) CommonMutateOptFunc

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

type Constraint

type Constraint struct {
	*model.ConstraintInfo
	ConstraintExpr expression.Expression
}

Constraint provides meta and map dependency describing a table constraint.

func LoadCheckConstraint

func LoadCheckConstraint(tblInfo *model.TableInfo) ([]*Constraint, error)

LoadCheckConstraint load check constraint

func ToConstraint

func ToConstraint(constraintInfo *model.ConstraintInfo, tblInfo *model.TableInfo) (*Constraint, error)

ToConstraint converts model.ConstraintInfo to Constraint

type CreateIdxOpt

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

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

func NewCreateIdxOpt

func NewCreateIdxOpt(opts ...CreateIdxOption) *CreateIdxOpt

NewCreateIdxOpt creates a new CreateIdxOpt.

func (*CreateIdxOpt) Ctx

func (opt *CreateIdxOpt) Ctx() context.Context

Ctx returns the go context in the option

func (*CreateIdxOpt) DupKeyCheck

func (opt *CreateIdxOpt) DupKeyCheck() DupKeyCheckMode

DupKeyCheck returns the DupKeyCheckMode in the option

func (*CreateIdxOpt) FromBackFill

func (opt *CreateIdxOpt) FromBackFill() bool

FromBackFill indicates whether the index is created by DDL backfill worker.

func (*CreateIdxOpt) IgnoreAssertion

func (opt *CreateIdxOpt) IgnoreAssertion() bool

IgnoreAssertion indicates whether to ignore assertion.

func (*CreateIdxOpt) PessimisticLazyDupKeyCheck

func (opt *CreateIdxOpt) PessimisticLazyDupKeyCheck() PessimisticLazyDupKeyCheckMode

PessimisticLazyDupKeyCheck returns the PessimisticLazyDupKeyCheckMode in the option

type CreateIdxOption

type CreateIdxOption interface {
	// contains filtered or unexported methods
}

CreateIdxOption is defined for the Create() method of the Index interface.

var FromBackfill CreateIdxOption = fromBackfill{}

FromBackfill indicates that the index is created by DDL backfill worker. In the backfill-merge process, the index KVs from DML will be redirected to the temp index. On the other hand, the index KVs from DDL backfill worker should never be redirected to the temp index.

var WithIgnoreAssertion CreateIdxOption = withIgnoreAssertion{}

WithIgnoreAssertion uses to indicate the process can ignore assertion.

type DupKeyCheckMode

type DupKeyCheckMode uint8

DupKeyCheckMode indicates how to check the duplicated key when adding/updating a record/index.

const (
	// DupKeyCheckInPlace indicates to check the duplicated key in place, both in the memory buffer and storage.
	DupKeyCheckInPlace DupKeyCheckMode = iota
	// DupKeyCheckLazy indicates to check the duplicated key lazily.
	// It means only checking the duplicated key in the memory buffer and checking keys in storage will be postponed
	// to the subsequence stage such as lock or commit phase.
	DupKeyCheckLazy
	// DupKeyCheckSkip indicates skipping the duplicated key check.
	DupKeyCheckSkip
)

type ExtraPartialRowOption

type ExtraPartialRowOption struct {
	IndexesRowLayout  IndexesLayout
	ColumnsSizeHelper *ColumnsSizeHelper
}

ExtraPartialRowOption is the combined one of IndexesLayout and ColumnSizeOption.

type Index

type Index interface {
	// Meta returns IndexInfo.
	Meta() *model.IndexInfo
	// TableMeta returns TableInfo
	TableMeta() *model.TableInfo
	// Create supports insert into statement.
	Create(ctx MutateContext, txn kv.Transaction, indexedValues []types.Datum, h kv.Handle, handleRestoreData []types.Datum, opts ...CreateIdxOption) (kv.Handle, error)
	// Delete supports delete from statement.
	Delete(ctx MutateContext, txn kv.Transaction, indexedValues []types.Datum, h kv.Handle) error
	// GenIndexKVIter generate index key and value for multi-valued index, use iterator to reduce the memory allocation.
	GenIndexKVIter(ec errctx.Context, loc *time.Location, indexedValue []types.Datum, h kv.Handle, handleRestoreData []types.Datum) IndexKVGenerator
	// Exist supports check index exists or not.
	Exist(ec errctx.Context, loc *time.Location, txn kv.Transaction, indexedValues []types.Datum, h kv.Handle) (bool, kv.Handle, error)
	// GenIndexKey generates an index key. If the index is a multi-valued index, use GenIndexKVIter instead.
	GenIndexKey(ec errctx.Context, loc *time.Location, indexedValues []types.Datum, h kv.Handle, buf []byte) (key []byte, distinct bool, err error)
	// GenIndexValue generates an index value.
	GenIndexValue(ec errctx.Context, loc *time.Location, distinct bool, indexedValues []types.Datum, h kv.Handle, restoredData []types.Datum, buf []byte) ([]byte, 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

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

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

type IndexKVGenerator

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

IndexKVGenerator generates kv for an index. It could be also used for generating multi-value indexes.

func NewMultiValueIndexKVGenerator

func NewMultiValueIndexKVGenerator(
	index Index,
	ec errctx.Context,
	loc *time.Location,
	handle kv.Handle,
	handleRestoredData []types.Datum,
	mvIndexData [][]types.Datum,
) IndexKVGenerator

NewMultiValueIndexKVGenerator creates a new IndexKVGenerator for multi-value indexes.

func NewPlainIndexKVGenerator

func NewPlainIndexKVGenerator(
	index Index,
	ec errctx.Context,
	loc *time.Location,
	handle kv.Handle,
	handleRestoredData []types.Datum,
	idxData []types.Datum,
) IndexKVGenerator

NewPlainIndexKVGenerator creates a new IndexKVGenerator for non multi-value indexes.

func (*IndexKVGenerator) Next

func (iter *IndexKVGenerator) Next(keyBuf, valBuf []byte) ([]byte, []byte, bool, error)

Next returns the next index key and value. For non multi-value indexes, there is only one index kv.

func (*IndexKVGenerator) Valid

func (iter *IndexKVGenerator) Valid() bool

Valid returns true if the generator is not exhausted.

type IndexRowLayoutOption

type IndexRowLayoutOption []int

IndexRowLayoutOption is the option for index row layout. It is used to specify the order of the index columns in the row.

type IndexesLayout

type IndexesLayout map[int64]IndexRowLayoutOption

IndexesLayout is used to specify the layout of the indexes. It's mapping from index ID to the layout of the index.

func (IndexesLayout) GetIndexLayout

func (idx IndexesLayout) GetIndexLayout(idxID int64) IndexRowLayoutOption

GetIndexLayout returns the layout of the specified index.

type MutateContext

type MutateContext = tblctx.MutateContext

MutateContext is used to when mutating a table.

type PartitionedTable

type PartitionedTable interface {
	Table
	GetPartition(physicalID int64) PhysicalTable
	GetPartitionByRow(expression.EvalContext, []types.Datum) (PhysicalTable, error)
	GetPartitionIdxByRow(expression.EvalContext, []types.Datum) (int, error)
	GetAllPartitionIDs() []int64
	GetPartitionColumnIDs() []int64
	GetPartitionColumnNames() []pmodel.CIStr
	CheckForExchangePartition(ctx expression.EvalContext, pi *model.PartitionInfo, r []types.Datum, partID, ntID int64) 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 PessimisticLazyDupKeyCheckMode

type PessimisticLazyDupKeyCheckMode uint8

PessimisticLazyDupKeyCheckMode only takes effect for pessimistic transaction when `DupKeyCheckMode` is set to `DupKeyCheckLazy`. It indicates how to check the duplicated key in store.

const (
	// DupKeyCheckInAcquireLock indicates to check the duplicated key when acquiring the pessimistic lock.
	DupKeyCheckInAcquireLock PessimisticLazyDupKeyCheckMode = iota
	// DupKeyCheckInPrewrite indicates to check the duplicated key in the prewrite step when committing.
	// Please notice that if it is used, the duplicated key error may not be returned immediately after each statement,
	// because the duplicated key is not checked when acquiring the pessimistic lock.
	DupKeyCheckInPrewrite
)

type PhysicalTable

type PhysicalTable interface {
	Table
	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

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

RecordIterFunc is used for low-level record iteration.

type RemoveRecordOpt

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

RemoveRecordOpt contains the options will be used when removing a record.

func NewRemoveRecordOpt

func NewRemoveRecordOpt(opts ...RemoveRecordOption) *RemoveRecordOpt

NewRemoveRecordOpt creates a new RemoveRecordOpt with options.

func (*RemoveRecordOpt) GetColumnSizeOpt

func (opt *RemoveRecordOpt) GetColumnSizeOpt() *ColumnsSizeHelper

GetColumnSizeOpt returns the ColumnSizeOption of the RemoveRecordOpt.

func (*RemoveRecordOpt) GetIndexLayout

func (opt *RemoveRecordOpt) GetIndexLayout(indexID int64) IndexRowLayoutOption

GetIndexLayout returns the IndexRowLayoutOption for the specified index.

func (*RemoveRecordOpt) GetIndexesLayout

func (opt *RemoveRecordOpt) GetIndexesLayout() IndexesLayout

GetIndexesLayout returns the IndexesLayout of the RemoveRecordOpt.

func (*RemoveRecordOpt) HasIndexesLayout

func (opt *RemoveRecordOpt) HasIndexesLayout() bool

HasIndexesLayout returns whether the RemoveRecordOpt has indexes layout.

type RemoveRecordOption

type RemoveRecordOption interface {
	// contains filtered or unexported methods
}

RemoveRecordOption is defined for the RemoveRecord() method of the Table interface.

type Table

type Table interface {

	// Indices returns the indices of the table.
	// The caller must be aware of that not all the returned indices are public.
	Indices() []Index
	DeletableIndices() []Index

	// WritableConstraint returns constraints of the table in writable states.
	WritableConstraint() []*Constraint

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

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

	// UpdateRecord updates a row which should contain only writable columns.
	UpdateRecord(ctx MutateContext, txn kv.Transaction, h kv.Handle, currData, newData []types.Datum, touched []bool, opts ...UpdateRecordOption) error

	// RemoveRecord removes a row in the table.
	RemoveRecord(ctx MutateContext, txn kv.Transaction, h kv.Handle, r []types.Datum, opts ...RemoveRecordOption) error

	// Allocators returns all allocators.
	Allocators(ctx AllocatorContext) autoid.Allocators

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

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

	// GetPartitionedTable returns nil if not partitioned
	GetPartitionedTable() PartitionedTable
	// contains filtered or unexported methods
}

Table is used to retrieve and modify rows in table.

type Type

type Type int16

Type is used to distinguish between different tables that store data in different ways.

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

func (Type) IsClusterTable

func (tp Type) IsClusterTable() bool

IsClusterTable checks whether the table is a cluster table type.

func (Type) IsNormalTable

func (tp Type) IsNormalTable() bool

IsNormalTable checks whether the table is a normal table type.

func (Type) IsVirtualTable

func (tp Type) IsVirtualTable() bool

IsVirtualTable checks whether the table is a virtual table type.

type UpdateRecordOpt

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

UpdateRecordOpt contains the options will be used when updating a record.

func NewUpdateRecordOpt

func NewUpdateRecordOpt(opts ...UpdateRecordOption) *UpdateRecordOpt

NewUpdateRecordOpt creates a new UpdateRecordOpt with options.

func (*UpdateRecordOpt) Ctx

func (opt *UpdateRecordOpt) Ctx() context.Context

Ctx returns the go context in the option

func (*UpdateRecordOpt) DupKeyCheck

func (opt *UpdateRecordOpt) DupKeyCheck() DupKeyCheckMode

DupKeyCheck returns the DupKeyCheckMode in the option

func (*UpdateRecordOpt) GetAddRecordOpt

func (opt *UpdateRecordOpt) GetAddRecordOpt() *AddRecordOpt

GetAddRecordOpt creates a AddRecordOpt.

func (*UpdateRecordOpt) GetCreateIdxOpt

func (opt *UpdateRecordOpt) GetCreateIdxOpt() *CreateIdxOpt

GetCreateIdxOpt creates a CreateIdxOpt.

func (*UpdateRecordOpt) PessimisticLazyDupKeyCheck

func (opt *UpdateRecordOpt) PessimisticLazyDupKeyCheck() PessimisticLazyDupKeyCheckMode

PessimisticLazyDupKeyCheck returns the PessimisticLazyDupKeyCheckMode in the option

func (*UpdateRecordOpt) SkipWriteUntouchedIndices

func (opt *UpdateRecordOpt) SkipWriteUntouchedIndices() bool

SkipWriteUntouchedIndices indicates whether to skip write untouched indices when updating a record.

type UpdateRecordOption

type UpdateRecordOption interface {
	// contains filtered or unexported methods
}

UpdateRecordOption is defined for the UpdateRecord() method of the Table interface.

var SkipWriteUntouchedIndices UpdateRecordOption = skipWriteUntouchedIndices{}

SkipWriteUntouchedIndices is an option to skip write untouched options when updating a record. If there are no later queries in the transaction that need to read the untouched indices, you can use this option to improve performance. However, it is not safe to use it in an explicit txn or the updated table has some foreign key constraints. Because the following read operations in the same txn may not get the correct data with the current implementation. See: - https://github.com/pingcap/tidb/pull/12609 - https://github.com/pingcap/tidb/issues/39419

type WithReserveAutoIDHint

type WithReserveAutoIDHint int

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL