schemas

package
v0.0.0-...-d224df5 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name = "INFORMATION_SCHEMA"
)

Information Schema Name.

Variables

View Source
var (
	// ErrDatabaseDropExists returns for dropping a non-existent database.
	ErrDatabaseDropExists = terror.ClassSchema.New(codeDBDropExists, "Can't drop database '%s'; database doesn't exist")
	// ErrDatabaseNotExists returns for database not exists.
	ErrDatabaseNotExists = terror.ClassSchema.New(codeDatabaseNotExists, "Unknown database '%s'")
	// ErrTableNotExists returns for table not exists.
	ErrTableNotExists = terror.ClassSchema.New(codeTableNotExists, "Table '%s.%s' doesn't exist")
	// ErrColumnNotExists returns for column not exists.
	ErrColumnNotExists = terror.ClassSchema.New(codeColumnNotExists, "Unknown column '%s' in '%s'")
	// ErrForeignKeyNotMatch returns for foreign key not match.
	ErrForeignKeyNotMatch = terror.ClassSchema.New(codeWrongFkDef, "Incorrect foreign key definition for '%s': Key reference and table reference don't match")
	// ErrCannotAddForeign returns for foreign key exists.
	ErrCannotAddForeign = terror.ClassSchema.New(codeCannotAddForeign, "Cannot add foreign key constraint")
	// ErrForeignKeyNotExists returns for foreign key not exists.
	ErrForeignKeyNotExists = terror.ClassSchema.New(codeForeignKeyNotExists, "Can't DROP '%s'; check that column/key exists")
	// ErrDatabaseExists returns for database already exists.
	ErrDatabaseExists = terror.ClassSchema.New(codeDatabaseExists, "Can't create database '%s'; database exists")
	// ErrTableExists returns for table already exists.
	ErrTableExists = terror.ClassSchema.New(codeTableExists, "Table '%s' already exists")
	// ErrTableDropExists returns for dropping a non-existent table.
	ErrTableDropExists = terror.ClassSchema.New(codeBadTable, "Unknown table '%s'")
	// ErrColumnExists returns for column already exists.
	ErrColumnExists = terror.ClassSchema.New(codeColumnExists, "Duplicate column name '%s'")
	// ErrIndexExists returns for index already exists.
	ErrIndexExists = terror.ClassSchema.New(codeIndexExists, "Duplicate Index")
	// ErrMultiplePriKey returns for multiple primary keys.
	ErrMultiplePriKey = terror.ClassSchema.New(codeMultiplePriKey, "Multiple primary key defined")
	// ErrTooManyKeyParts returns for too many key parts.
	ErrTooManyKeyParts = terror.ClassSchema.New(codeTooManyKeyParts, "Too many key parts specified; max %d parts allowed")
)
View Source
var (

	// 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")
)
View Source
var MockTableFromMeta func(tableInfo *model.TableInfo) Table

MockTableFromMeta only serves for test.

Functions

func CastValue

func CastValue(ctx context.Context, val types.Datum, col *model.ColumnInfo) (casted types.Datum, err error)

CastValue casts a value based on column type.

func CastValues

func CastValues(ctx context.Context, rec []types.Datum, cols []*Column, ignoreErr bool) (err error)

CastValues casts values based on columns type.

func CheckNotNull

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

func CheckOnce(cols []*Column) error

CheckOnce checks if there are duplicated column names in cols.

func ColDescFieldNames

func ColDescFieldNames(full bool) []string

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

func GetColDefaultValue

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

GetColDefaultValue gets default value of the column.

func GetColOriginDefaultValue

func GetColOriginDefaultValue(ctx context.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 Allocator

type Allocator interface {
	// Alloc allocs the next autoID for table with tableID.
	// It gets a batch of autoIDs at a time. So it does not need to access storage for each call.
	Alloc(tableID int64) (int64, error)
	// Rebase rebases the autoID base for table with tableID and the new base value.
	// If allocIDs is true, it will allocate some IDs and save to the cache.
	// If allocIDs is false, it will not allocate IDs.
	Rebase(tableID, newBase int64, allocIDs bool) error
	// NextGlobalAutoID returns the next global autoID.
	NextGlobalAutoID(tableID int64) (int64, error)
}

Allocator is an auto increment id generator. Just keep id unique actually.

type ColDesc

type ColDesc struct {
	Field        string
	Type         string
	Collation    string
	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

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 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 FindCols

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

FindCols finds columns in cols by names.

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) error

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

func (*Column) GetTypeDesc

func (c *Column) GetTypeDesc() string

GetTypeDesc gets the description for column type.

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 Database

type Database interface {
	Name() string

	GetTable(name string) (Table, error)

	ListTables() []Table

	DropTable(name string) error

	ListTableName() []string
}

type Index

type Index interface {
	// Meta returns IndexInfo.
	Meta() *model.IndexInfo
	// Create supports insert into statement.
	//Create(ctx context.Context, rm kv.RetrieverMutator,
	//	indexedValues []types.Datum, h int64) (int64, error)
	//// Delete supports delete from statement.
	//Delete(m kv.Mutator, indexedValues []types.Datum, h int64) error
	//// Drop supports drop table, drop index statements.
	//Drop(rm kv.RetrieverMutator) error
	//// Exist supports check index exists or not.
	//Exist(rm kv.RetrieverMutator, indexedValues []types.Datum, h int64) (bool, int64, error)
	//// GenIndexKey generates an index key.
	//GenIndexKey(indexedValues []types.Datum, h int64) (key []byte, distinct bool, err error)
	//// Seek supports where clause.
	//Seek(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.
	FetchValues(row []types.Datum) (columns []types.Datum, err error)
}

Index is the interface for index data on KV storebytes.

type IndexIterator

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

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

type InfoSchema

type InfoSchema interface {
	SchemaByName(schema model.CIStr) (*model.DBInfo, bool)

	SchemaExists(schema model.CIStr) bool

	TableByName(schema, table model.CIStr) (Table, error)

	TableExists(schema, table model.CIStr) bool

	AllSchemaNames() []string

	AllSchemas() []*model.DBInfo

	Clone() (result []*model.DBInfo)

	SchemaTables(schema model.CIStr) []Table

	//获取数据库对象
	GetSchemaByName(schemaName string) (Database, error)

	//判断数据库是否存在
	GetSchemaExist(schemaName string) bool

	GetTableByName(schema string, tableName string) (Table, error)

	GetTableExist(schemaName string, tableName string) bool

	SchemaByID(id int64) (*model.DBInfo, bool)

	TableByID(id int64) (Table, bool)

	AllocByID(id int64) (Allocator, bool)

	SchemaMetaVersion() int64
}

启动时加载

type PerformanceSchemas

type PerformanceSchemas interface {
}

type Table

type Table interface {

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

	TableName() string

	TableId() uint64

	SpaceId() uint32

	ColNums() int

	RowIter() (basic.RowIterator, error)

	GetBtree(indexName string) basic.Tree

	CheckFieldName(fieldName string) bool

	GetAllColumns() []*tuple.FormColumnsWrapper

	GetTableTupleMeta() tuple.TableTuple

	//获取索引
	GetIndex(indexName string) basic.Index

	// 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
}

Table is used to retrieve and modify rows in table.

type TupleLRUCache

type TupleLRUCache interface {

	//lru 中设置spaceId,pageNo
	Set(databaseName string, tableName string, table Table) error

	Get(databaseName string, tableName string) (Table, error)

	Remove(databaseName string, tableName string) bool

	// Has returns true if the key exists in the cache.
	Has(databaseName string, tableName string) bool

	Len() uint32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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