tables

package
v0.0.0-...-a8c23e6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: GPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocHandle

func AllocHandle(ctx context.Context, sctx sessionctx.Context, t table.Table) (kv.Handle, error)

AllocHandle allocate a new handle. A statement could reserve some ID in the statement context, try those ones first.

func BuildFieldTypesForIndexColumns

func BuildFieldTypesForIndexColumns(idxInfo *model.IndexInfo, tblInfo *model.TableInfo) []*types.FieldType

BuildFieldTypesForIndexColumns builds the index columns field types.

func BuildRowcodecColInfoForIndexColumns

func BuildRowcodecColInfoForIndexColumns(idxInfo *model.IndexInfo, tblInfo *model.TableInfo) []rowcodec.ColInfo

BuildRowcodecColInfoForIndexColumns builds []rowcodec.ColInfo for the given index. The result can be used for decoding index key-values.

func BuildTableScanFromInfos

func BuildTableScanFromInfos(tableInfo *model.TableInfo, columnInfos []*model.ColumnInfo) *tipb.TableScan

BuildTableScanFromInfos build tipb.TableScan with *model.TableInfo and *model.ColumnInfo.

func CanSkip

func CanSkip(info *model.TableInfo, col *table.Column, value *types.Datum) bool

CanSkip is for these cases, we can skip the columns in encoded row: 1. the column is included in primary key; 2. the column's default value is null, and the value equals to that but has no origin default; 3. the column is virtual generated.

func ClearAddRecordCtx

func ClearAddRecordCtx(ctx sessionctx.Context)

ClearAddRecordCtx remove `CommonAddRecordCtx` from session context

func DecodeRawRowData

func DecodeRawRowData(ctx sessionctx.Context, meta *model.TableInfo, h kv.Handle, cols []*table.Column,
	value []byte) ([]types.Datum, map[int64]types.Datum, error)

DecodeRawRowData decodes raw row data into a datum slice and a (columnID:columnValue) map.

func FindChangingCol

func FindChangingCol(cols []*table.Column, idxInfo *model.IndexInfo) *table.Column

FindChangingCol finds the changing column in idxInfo.

func FindIndexByColName

func FindIndexByColName(t table.Table, name string) table.Index

FindIndexByColName returns a public table index containing only one column named `name`.

func FindPartitionByName

func FindPartitionByName(meta *model.TableInfo, parName string) (int64, error)

FindPartitionByName finds partition in table meta by name.

func FindPrimaryIndex

func FindPrimaryIndex(tblInfo *model.TableInfo) *model.IndexInfo

FindPrimaryIndex uses to find primary index in tableInfo.

func GetChangingColVal

func GetChangingColVal(ctx sessionctx.Context, cols []*table.Column, col *table.Column, rowMap map[int64]types.Datum, defaultVals []types.Datum) (_ types.Datum, isDefaultVal bool, err error)

GetChangingColVal gets the changing column value when executing "modify/change column" statement. For statement like update-where, it will fetch the old row out and insert it into kv again. Since update statement can see the writable columns, it is responsible for the casting relative column / get the fault value here. old row : a-b-[nil] new row : a-b-[a'/default] Thus the writable new row is corresponding to Write-Only constraints.

func GetColDefaultValue

func GetColDefaultValue(ctx sessionctx.Context, col *table.Column, defaultVals []types.Datum) (
	colVal types.Datum, err error)

GetColDefaultValue gets a column default value. The defaultVals is used to avoid calculating the default value multiple times.

func GetWritableIndexByName

func GetWritableIndexByName(idxName string, t table.Table) table.Index

GetWritableIndexByName gets the index meta from the table by the index name.

func IsIndexWritable

func IsIndexWritable(idx table.Index) bool

IsIndexWritable check whether the index is writable.

func IterRecords

func IterRecords(t table.Table, ctx sessionctx.Context, cols []*table.Column,
	fn table.RecordIterFunc) error

IterRecords iterates records in the table and calls fn.

func MockTableFromMeta

func MockTableFromMeta(tblInfo *model.TableInfo) table.Table

MockTableFromMeta only serves for test.

func NeedRestoredData

func NeedRestoredData(idxCols []*model.IndexColumn, colInfos []*model.ColumnInfo) bool

NeedRestoredData checks whether the index columns needs restored data.

func NewIndex

func NewIndex(physicalID int64, tblInfo *model.TableInfo, indexInfo *model.IndexInfo) table.Index

NewIndex builds a new Index object.

func NewListPartitionLocationHelper

func NewListPartitionLocationHelper() *listPartitionLocationHelper

NewListPartitionLocationHelper returns a new listPartitionLocationHelper.

func NewPartitionTableWithGivenSets

func NewPartitionTableWithGivenSets(tbl table.PartitionedTable, partitions map[int64]struct{}) table.PartitionedTable

NewPartitionTableWithGivenSets creates a new partition table from a partition table.

func OverflowShardBits

func OverflowShardBits(recordID int64, shardRowIDBits uint64, typeBitsLength uint64, reservedSignBit bool) bool

OverflowShardBits checks whether the recordID overflow `1<<(typeBitsLength-shardRowIDBits-1) -1`.

func PartitionRecordKey

func PartitionRecordKey(pid int64, handle int64) kv.Key

PartitionRecordKey is exported for test.

func PrimaryPrefixColumnIDs

func PrimaryPrefixColumnIDs(tbl *model.TableInfo) (prefixCols []int64)

PrimaryPrefixColumnIDs get prefix column ids in primary key.

func RowWithCols

func RowWithCols(t table.Table, ctx sessionctx.Context, h kv.Handle, cols []*table.Column) ([]types.Datum, error)

RowWithCols is used to get the corresponding column datum values with the given handle.

func SetAddRecordCtx

func SetAddRecordCtx(ctx sessionctx.Context, r *CommonAddRecordCtx)

SetAddRecordCtx set a CommonAddRecordCtx to session context

func TableFromMeta

func TableFromMeta(allocs autoid.Allocators, tblInfo *model.TableInfo) (table.Table, error)

TableFromMeta creates a Table instance from model.TableInfo.

func TempTableFromMeta

func TempTableFromMeta(tblInfo *model.TableInfo) tableutil.TempTable

TempTableFromMeta builds a TempTable from model.TableInfo.

func TryAppendCommonHandleRowcodecColInfos

func TryAppendCommonHandleRowcodecColInfos(colInfo []rowcodec.ColInfo, tblInfo *model.TableInfo) []rowcodec.ColInfo

TryAppendCommonHandleRowcodecColInfos tries to append common handle columns to `colInfo`.

func TryGetCommonPkColumnIds

func TryGetCommonPkColumnIds(tbl *model.TableInfo) []int64

TryGetCommonPkColumnIds get the IDs of primary key column if the table has common handle.

func TryGetCommonPkColumns

func TryGetCommonPkColumns(tbl table.Table) []*table.Column

TryGetCommonPkColumns get the primary key columns if the table has common handle.

func TryGetHandleRestoredDataWrapper

func TryGetHandleRestoredDataWrapper(t table.Table, row []types.Datum, rowMap map[int64]types.Datum, idx *model.IndexInfo) []types.Datum

TryGetHandleRestoredDataWrapper tries to get the restored data for handle if needed. The argument can be a slice or a map.

Types

type CommonAddRecordCtx

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

CommonAddRecordCtx is used in `AddRecord` to avoid memory malloc for some temp slices. This is useful in lightning parse row data to key-values pairs. This can gain upto 5% performance improvement in lightning's local mode.

func NewCommonAddRecordCtx

func NewCommonAddRecordCtx(size int) *CommonAddRecordCtx

NewCommonAddRecordCtx create a context used for `AddRecord`

type ForListColumnPruning

type ForListColumnPruning struct {
	ExprCol *expression.Column
	// contains filtered or unexported fields
}

ForListColumnPruning is used for list columns partition pruning.

func (*ForListColumnPruning) LocatePartition

LocatePartition locates partition by the column value

func (*ForListColumnPruning) LocateRanges

LocateRanges locates partition ranges by the column range

type ForListPruning

type ForListPruning struct {
	// LocateExpr uses to locate list partition by row.
	LocateExpr expression.Expression
	// PruneExpr uses to prune list partition in partition pruner.
	PruneExpr expression.Expression
	// PruneExprCols is the columns of PruneExpr, it has removed the duplicate columns.
	PruneExprCols []*expression.Column

	// For list columns partition pruning
	ColPrunes []*ForListColumnPruning
	// contains filtered or unexported fields
}

ForListPruning is used for list partition pruning.

func (*ForListPruning) LocatePartition

func (lp *ForListPruning) LocatePartition(value int64, isNull bool) int

LocatePartition locates partition by the column value

type ForRangeColumnsPruning

type ForRangeColumnsPruning struct {
	LessThan []expression.Expression
	MaxValue bool
}

ForRangeColumnsPruning is used for range partition pruning.

type ForRangePruning

type ForRangePruning struct {
	LessThan []int64
	MaxValue bool
	Unsigned bool
}

ForRangePruning is used for range partition pruning.

func (*ForRangePruning) Compare

func (lt *ForRangePruning) Compare(ith int, v int64, unsigned bool) int

Compare is to be used in the binary search to locate partition

type ListPartitionGroup

type ListPartitionGroup struct {
	// Such as: list columns (a,b) (partition p0 values in ((1,5),(1,6)));
	// For the column a which value is 1, the ListPartitionGroup is:
	// ListPartitionGroup {
	//     PartIdx: 0,            // 0 is the partition p0 index in all partitions.
	//     GroupIdxs: []int{0,1}, // p0 has 2 value group: (1,5) and (1,6), and they both contain the column a where value is 1;
	// }                          // the value of GroupIdxs `0,1` is the index of the value group that contain the column a which value is 1.
	PartIdx   int
	GroupIdxs []int
}

ListPartitionGroup indicate the group index of the column value in a partition.

type ListPartitionLocation

type ListPartitionLocation []ListPartitionGroup

ListPartitionLocation indicate the partition location for the column value in list columns partition. Here is an example: Suppose the list columns partition is: list columns (a,b) (partition p0 values in ((1,5),(1,6)), partition p1 values in ((1,7),(9,9))); How to express the location of the column a which value is 1? For the column a which value is 1, both partition p0 and p1 contain the column a which value is 1. In partition p0, both value group0 (1,5) and group1 (1,6) are contain the column a which value is 1. In partition p1, value group0 (1,7) contains the column a which value is 1. So, the ListPartitionLocation of column a which value is 1 is:

[]ListPartitionGroup{
	{
		PartIdx: 0,               // `0` is the partition p0 index in all partitions.
		GroupIdxs: []int{0, 1}    // `0,1` is the index of the value group0, group1.
	},
	{
		PartIdx: 1,               // `1` is the partition p1 index in all partitions.
		GroupIdxs: []int{0}       // `0` is the index of the value group0.
	},
}

func (ListPartitionLocation) IsEmpty

func (ps ListPartitionLocation) IsEmpty() bool

IsEmpty returns true if the ListPartitionLocation is empty.

type PartitionExpr

type PartitionExpr struct {
	// UpperBounds: (x < y1); (x < y2); (x < y3), used by locatePartition.
	UpperBounds []expression.Expression
	// OrigExpr is the partition expression ast used in point get.
	OrigExpr ast.ExprNode
	// Expr is the hash partition expression.
	Expr expression.Expression
	// Used in the range pruning process.
	*ForRangePruning
	// Used in the range column pruning process.
	*ForRangeColumnsPruning
	// ColOffset is the offsets of partition columns.
	ColumnOffset []int
	// InValues: x in (1,2); x in (3,4); x in (5,6), used for list partition.
	InValues []expression.Expression
	*ForListPruning
}

PartitionExpr is the partition definition expressions.

type TableCommon

type TableCommon struct {
	Columns                         []*table.Column
	PublicColumns                   []*table.Column
	VisibleColumns                  []*table.Column
	HiddenColumns                   []*table.Column
	WritableColumns                 []*table.Column
	FullHiddenColsAndVisibleColumns []*table.Column
	// contains filtered or unexported fields
}

TableCommon is shared by both Table and partition.

func (*TableCommon) AddRecord

func (t *TableCommon) AddRecord(sctx sessionctx.Context, r []types.Datum, opts ...table.AddRecordOption) (recordID kv.Handle, err error)

AddRecord implements table.Table AddRecord interface.

func (*TableCommon) Allocators

func (t *TableCommon) Allocators(ctx sessionctx.Context) autoid.Allocators

Allocators implements table.Table Allocators interface.

func (*TableCommon) Cols

func (t *TableCommon) Cols() []*table.Column

Cols implements table.Table Cols interface.

func (*TableCommon) DeletableCols

func (t *TableCommon) DeletableCols() []*table.Column

DeletableCols implements table DeletableCols interface.

func (*TableCommon) FullHiddenColsAndVisibleCols

func (t *TableCommon) FullHiddenColsAndVisibleCols() []*table.Column

FullHiddenColsAndVisibleCols implements table FullHiddenColsAndVisibleCols interface.

func (*TableCommon) GetPhysicalID

func (t *TableCommon) GetPhysicalID() int64

GetPhysicalID implements table.Table GetPhysicalID interface.

func (*TableCommon) GetSequenceCommon

func (t *TableCommon) GetSequenceCommon() *sequenceCommon

GetSequenceCommon is used in test to get sequenceCommon.

func (*TableCommon) GetSequenceID

func (t *TableCommon) GetSequenceID() int64

GetSequenceID implements util.SequenceTable GetSequenceID interface.

func (*TableCommon) GetSequenceNextVal

func (t *TableCommon) GetSequenceNextVal(ctx interface{}, dbName, seqName string) (nextVal int64, err error)

GetSequenceNextVal implements util.SequenceTable GetSequenceNextVal interface. Caching the sequence value in table, we can easily be notified with the cache empty, and write the binlogInfo in table level rather than in allocator.

func (*TableCommon) HiddenCols

func (t *TableCommon) HiddenCols() []*table.Column

HiddenCols implements table.Table HiddenCols interface.

func (*TableCommon) Indices

func (t *TableCommon) Indices() []table.Index

Indices implements table.Table Indices interface.

func (*TableCommon) Meta

func (t *TableCommon) Meta() *model.TableInfo

Meta implements table.Table Meta interface.

func (*TableCommon) RecordKey

func (t *TableCommon) RecordKey(h kv.Handle) kv.Key

RecordKey implements table.Table interface.

func (*TableCommon) RecordPrefix

func (t *TableCommon) RecordPrefix() kv.Key

RecordPrefix implements table.Table interface.

func (*TableCommon) RemoveRecord

func (t *TableCommon) RemoveRecord(ctx sessionctx.Context, h kv.Handle, r []types.Datum) error

RemoveRecord implements table.Table RemoveRecord interface.

func (*TableCommon) SetSequenceVal

func (t *TableCommon) SetSequenceVal(ctx interface{}, newVal int64, dbName, seqName string) (int64, bool, error)

SetSequenceVal implements util.SequenceTable SetSequenceVal interface. The returned bool indicates the newVal is already under the base.

func (*TableCommon) Type

func (t *TableCommon) Type() table.Type

Type implements table.Table Type interface.

func (*TableCommon) UpdateRecord

func (t *TableCommon) UpdateRecord(ctx context.Context, sctx sessionctx.Context, h kv.Handle, oldData, newData []types.Datum, touched []bool) error

UpdateRecord implements table.Table UpdateRecord interface. `touched` means which columns are really modified, used for secondary indices. Length of `oldData` and `newData` equals to length of `t.WritableCols()`.

func (*TableCommon) VisibleCols

func (t *TableCommon) VisibleCols() []*table.Column

VisibleCols implements table.Table VisibleCols interface.

func (*TableCommon) WritableCols

func (t *TableCommon) WritableCols() []*table.Column

WritableCols implements table WritableCols interface.

type TemporaryTable

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

TemporaryTable is used to store transaction-specific or session-specific information for global / local temporary tables. For example, stats and autoID should have their own copies of data, instead of being shared by all sessions.

func (*TemporaryTable) GetAutoIDAllocator

func (t *TemporaryTable) GetAutoIDAllocator() autoid.Allocator

GetAutoIDAllocator is implemented from TempTable.GetAutoIDAllocator.

func (*TemporaryTable) GetMeta

func (t *TemporaryTable) GetMeta() *model.TableInfo

GetMeta gets the table meta.

func (*TemporaryTable) GetModified

func (t *TemporaryTable) GetModified() bool

GetModified is implemented from TempTable.GetModified.

func (*TemporaryTable) GetSize

func (t *TemporaryTable) GetSize() int64

GetSize gets the table size.

func (*TemporaryTable) GetStats

func (t *TemporaryTable) GetStats() interface{}

GetStats is implemented from TempTable.GetStats.

func (*TemporaryTable) SetModified

func (t *TemporaryTable) SetModified(modified bool)

SetModified is implemented from TempTable.SetModified.

func (*TemporaryTable) SetSize

func (t *TemporaryTable) SetSize(v int64)

SetSize sets the table size.

Jump to

Keyboard shortcuts

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