Documentation ¶
Index ¶
- Constants
- Variables
- func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo) (casted types.Datum, err error)
- func CastValues(ctx sessionctx.Context, rec []types.Datum, cols []*Column) (err error)
- func CheckNotNull(cols []*Column, row []types.Datum) error
- func CheckOnce(cols []*Column) error
- func ColDescFieldNames(full bool) []string
- func GetColDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo) (types.Datum, error)
- func GetColOriginDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo) (types.Datum, error)
- func GetZeroValue(col *model.ColumnInfo) types.Datum
- type AddRecordOpt
- type AddRecordOption
- type ColDesc
- type Column
- func (c *Column) CheckNotNull(data types.Datum) error
- func (c *Column) GetTypeDesc() string
- func (c *Column) HandleBadNull(d types.Datum, sc *stmtctx.StatementContext) (types.Datum, error)
- func (c *Column) IsPKHandleColumn(tbInfo *model.TableInfo) bool
- func (c *Column) String() string
- func (c *Column) ToInfo() *model.ColumnInfo
- type CreateIdxOpt
- type CreateIdxOptFunc
- type Index
- type IndexIterator
- type PartitionedTable
- type PhysicalTable
- type RecordIterFunc
- type Slice
- type Table
- type Type
Constants ¶
const ( // DirtyTableAddRow is the constant for dirty table operation type. DirtyTableAddRow = iota // DirtyTableDeleteRow is the constant for dirty table operation type. DirtyTableDeleteRow // DirtyTableTruncate is the constant for dirty table operation type. DirtyTableTruncate )
Variables ¶
var ( // ErrColumnCantNull is used for inserting null to a not null column. ErrColumnCantNull = terror.ClassTable.New(codeColumnCantNull, mysql.MySQLErrName[mysql.ErrBadNull]) // 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 = terror.ClassTable.New(codeNoDefaultValue, mysql.MySQLErrName[mysql.ErrNoDefaultForField]) // ErrIndexOutBound returns for index column offset out of bound. ErrIndexOutBound = terror.ClassTable.New(codeIndexOutBound, "index column offset out of bound") // ErrUnsupportedOp returns for unsupported operation. ErrUnsupportedOp = terror.ClassTable.New(codeUnsupportedOp, "operation not supported") // ErrRowNotFound returns for row not found. ErrRowNotFound = terror.ClassTable.New(codeRowNotFound, "can not find the row") // ErrTableStateCantNone returns for table none state. ErrTableStateCantNone = terror.ClassTable.New(codeTableStateCantNone, "table can not be in none state") // ErrColumnStateCantNone returns for column none state. ErrColumnStateCantNone = terror.ClassTable.New(codeColumnStateCantNone, "column can not be in none state") // ErrColumnStateNonPublic returns for column non-public state. ErrColumnStateNonPublic = terror.ClassTable.New(codeColumnStateNonPublic, "can not use non-public column") // ErrIndexStateCantNone returns for index none state. ErrIndexStateCantNone = terror.ClassTable.New(codeIndexStateCantNone, "index can not be in none state") // ErrInvalidRecordKey returns for invalid record key. ErrInvalidRecordKey = terror.ClassTable.New(codeInvalidRecordKey, "invalid record key") // ErrTruncateWrongValue returns for truncate wrong value for field. ErrTruncateWrongValue = terror.ClassTable.New(codeTruncateWrongValue, "incorrect value") // ErrTruncatedWrongValueForField returns for truncate wrong value for field. ErrTruncatedWrongValueForField = terror.ClassTable.New(codeTruncateWrongValue, mysql.MySQLErrName[mysql.ErrTruncatedWrongValueForField]) // ErrUnknownPartition returns unknown partition error. ErrUnknownPartition = terror.ClassTable.New(codeUnknownPartition, mysql.MySQLErrName[mysql.ErrUnknownPartition]) // ErrNoPartitionForGivenValue returns table has no partition for value. ErrNoPartitionForGivenValue = terror.ClassTable.New(codeNoPartitionForGivenValue, mysql.MySQLErrName[mysql.ErrNoPartitionForGivenValue]) // ErrLockOrActiveTransaction returns when execute unsupported statement in a lock session or an active transaction. ErrLockOrActiveTransaction = terror.ClassTable.New(codeLockOrActiveTransaction, mysql.MySQLErrName[mysql.ErrLockOrActiveTransaction]) )
var MockTableFromMeta func(tableInfo *model.TableInfo) Table
MockTableFromMeta only serves for test.
TableFromMeta builds a table.Table from *model.TableInfo. Currently, it is assigned to tables.TableFromMeta in tidb package's init function.
Functions ¶
func CastValue ¶
func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo) (casted types.Datum, err error)
CastValue casts a value based on column type.
func CastValues ¶
CastValues casts values based on columns type.
func CheckNotNull ¶
CheckNotNull checks if row has nil value set to a column with NotNull flag set.
func ColDescFieldNames ¶
ColDescFieldNames returns the fields name in result set for desc and show columns.
func GetColDefaultValue ¶
func GetColDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo) (types.Datum, error)
GetColDefaultValue gets default value of the column.
func GetColOriginDefaultValue ¶
func GetColOriginDefaultValue(ctx sessionctx.Context, col *model.ColumnInfo) (types.Datum, error)
GetColOriginDefaultValue gets default value of the column from original default value.
func GetZeroValue ¶
func GetZeroValue(col *model.ColumnInfo) types.Datum
GetZeroValue gets zero value for given column type.
Types ¶
type AddRecordOpt ¶
type AddRecordOpt struct { CreateIdxOpt IsUpdate bool }
AddRecordOpt contains the options will be used when adding a record.
type AddRecordOption ¶
type AddRecordOption interface {
ApplyOn(*AddRecordOpt)
}
AddRecordOption is defined for the AddRecord() method of the Table interface.
var IsUpdate AddRecordOption = isUpdate{}
IsUpdate is a defined value for AddRecordOptFunc.
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 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 ¶
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 ast.ExprNode }
Column provides meta data describing a table column.
func FindCols ¶
FindCols finds columns in cols by names. If pkIsHandle is false and name is ExtraHandleName, the extra handle column will be added.
func FindOnUpdateCols ¶
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 ¶
CheckNotNull checks if nil value set to a column with NotNull flag is set.
func (*Column) GetTypeDesc ¶
GetTypeDesc gets the description for column type.
func (*Column) HandleBadNull ¶
HandleBadNull handles the bad null error. If BadNullAsWarning is true, it will append the error as a warning, else return the error.
func (*Column) IsPKHandleColumn ¶
IsPKHandleColumn checks if the column is primary key handle column.
func (*Column) ToInfo ¶
func (c *Column) ToInfo() *model.ColumnInfo
ToInfo casts Column to model.ColumnInfo NOTE: DONT modify return value.
type CreateIdxOpt ¶
type CreateIdxOpt struct { SkipHandleCheck bool // If true, skip the handle constraint check. SkipCheck bool // If true, skip all the unique indices constraint check. kv.AssertionProto // If not nil, check assertion. }
CreateIdxOpt contains the options will be used when creating an index.
type CreateIdxOptFunc ¶
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 SkipCheck CreateIdxOptFunc = func(opt *CreateIdxOpt) { opt.SkipCheck = true }
SkipCheck is a defined value of CreateIdxFunc.
var SkipHandleCheck CreateIdxOptFunc = func(opt *CreateIdxOpt) { opt.SkipHandleCheck = true }
SkipHandleCheck is a defined value of CreateIdxFunc.
func WithAssertion ¶
func WithAssertion(x kv.AssertionProto) CreateIdxOptFunc
WithAssertion returns a CreateIdxFunc.
func (CreateIdxOptFunc) ApplyOn ¶
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 ¶
type Index interface { // Meta returns IndexInfo. Meta() *model.IndexInfo // Create supports insert into statement. Create(ctx sessionctx.Context, rm kv.RetrieverMutator, indexedValues []types.Datum, h int64, opts ...CreateIdxOptFunc) (int64, error) // Delete supports delete from statement. Delete(sc *stmtctx.StatementContext, m kv.Mutator, indexedValues []types.Datum, h int64, ss kv.Transaction) error // Drop supports drop table, drop index statements. Drop(rm kv.RetrieverMutator) error // Exist supports check index exists or not. Exist(sc *stmtctx.StatementContext, rm kv.RetrieverMutator, indexedValues []types.Datum, h int64) (bool, int64, error) // GenIndexKey generates an index key. GenIndexKey(sc *stmtctx.StatementContext, indexedValues []types.Datum, h int64, 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 ¶
IndexIterator is the interface for iterator of index data on KV store.
type PartitionedTable ¶
type PartitionedTable interface { Table GetPartition(physicalID int64) PhysicalTable GetPartitionByRow(sessionctx.Context, []types.Datum) (Table, 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 ¶
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 ¶
RecordIterFunc is used for low-level record iteration.
type Table ¶
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 int64, cols []*Column) ([]types.Datum, error) // Row returns a row for all columns. Row(ctx sessionctx.Context, h int64) ([]types.Datum, error) // Cols returns the columns of the table which is used in select. Cols() []*Column // WritableCols returns columns of the table in writable states. // Writable states includes Public, WriteOnly, WriteOnlyReorganization. WritableCols() []*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 int64) kv.Key // AddRecord inserts a row which should contain only public columns AddRecord(ctx sessionctx.Context, r []types.Datum, opts ...AddRecordOption) (recordID int64, err error) // UpdateRecord updates a row which should contain only writable columns. UpdateRecord(ctx sessionctx.Context, h int64, currData, newData []types.Datum, touched []bool) error // RemoveRecord removes a row in the table. RemoveRecord(ctx sessionctx.Context, h int64, r []types.Datum) error // AllocAutoIncrementValue allocates an auto_increment value for a new row. AllocAutoIncrementValue(ctx sessionctx.Context) (int64, error) // AllocHandle allocates a handle for a new row. AllocHandle(ctx sessionctx.Context) (int64, error) // Allocator returns Allocator. Allocator(ctx sessionctx.Context) autoid.Allocator // 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) error // Meta returns TableInfo. Meta() *model.TableInfo // Seek returns the handle greater or equal to h. Seek(ctx sessionctx.Context, h int64) (handle int64, found bool, err error) // Type returns the type of table Type() Type }
Table is used to retrieve and modify rows in table.