infoschema

package
v0.0.0-...-3633c1a Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name      = "INFORMATION_SCHEMA"
	LowerName = "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'")
	// ErrUserDropExists returns for dropping a non-existent user.
	ErrUserDropExists = terror.ClassSchema.New(codeBadUser, "User %s does not exist.")
	// 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")
	// ErrKeyNameDuplicate returns for index duplicate when rename index.
	ErrKeyNameDuplicate = terror.ClassSchema.New(codeKeyNameDuplicate, "Duplicate key name '%s'")
	// ErrKeyNotExists returns for index not exists.
	ErrKeyNotExists = terror.ClassSchema.New(codeKeyNotExists, "Key '%s' doesn't exist in table '%s'")
	// 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")
	// ErrTableNotLockedForWrite returns for write tables when only hold the table read lock.
	ErrTableNotLockedForWrite = terror.ClassSchema.New(codeErrTableNotLockedForWrite, mysql.MySQLErrName[mysql.ErrTableNotLockedForWrite])
	// ErrTableNotLocked returns when session has explicitly lock tables, then visit unlocked table will return this error.
	ErrTableNotLocked = terror.ClassSchema.New(codeErrTableNotLocked, mysql.MySQLErrName[mysql.ErrTableNotLocked])
	// ErrNonuniqTable returns when none unique tables errors.
	ErrNonuniqTable = terror.ClassSchema.New(codeErrTableNotLocked, mysql.MySQLErrName[mysql.ErrNonuniqTable])
	// ErrTableLocked returns when the table was locked by other session.
	ErrTableLocked = terror.ClassSchema.New(codeTableLocked, mysql.MySQLErrName[mysql.ErrTableLocked])
	// ErrAccessDenied return when the user doesn't have the permission to access the table.
	ErrAccessDenied = terror.ClassSchema.New(codeErrAccessDenied, mysql.MySQLErrName[mysql.ErrAccessDenied])
)
View Source
var TableStatsCacheExpiry = 3 * time.Second

TableStatsCacheExpiry is the expiry time for table stats cache.

Functions

func ConvertCharsetCollateToLowerCaseIfNeed

func ConvertCharsetCollateToLowerCaseIfNeed(tbInfo *model.TableInfo)

ConvertCharsetCollateToLowerCaseIfNeed convert the charset / collation of table and its columns to lower case, if the table's version is prior to TableInfoVersion3.

func ConvertOldVersionUTF8ToUTF8MB4IfNeed

func ConvertOldVersionUTF8ToUTF8MB4IfNeed(tbInfo *model.TableInfo)

ConvertOldVersionUTF8ToUTF8MB4IfNeed convert old version UTF8 to UTF8MB4 if config.TreatOldVersionUTF8AsUTF8MB4 is enable.

func DataForAnalyzeStatus

func DataForAnalyzeStatus() (rows [][]types.Datum)

DataForAnalyzeStatus gets all the analyze jobs.

func IsMemoryDB

func IsMemoryDB(dbName string) bool

IsMemoryDB checks if the db is in memory.

func ParseSlowLog

func ParseSlowLog(tz *time.Location, reader *bufio.Reader) ([][]types.Datum, error)

ParseSlowLog exports for testing. TODO: optimize for parse huge log-file.

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime exports for testing.

func RegisterVirtualTable

func RegisterVirtualTable(dbInfo *model.DBInfo, tableFromMeta tableFromMetaFunc)

RegisterVirtualTable register virtual tables to the builder.

Types

type Builder

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

Builder builds a new InfoSchema.

func NewBuilder

func NewBuilder(handle *Handle) *Builder

NewBuilder creates a new Builder with a Handle.

func (*Builder) ApplyDiff

func (b *Builder) ApplyDiff(m *meta.Meta, diff *model.SchemaDiff) ([]int64, error)

ApplyDiff applies SchemaDiff to the new InfoSchema. Return the detail updated table IDs that are produced from SchemaDiff and an error.

func (*Builder) Build

func (b *Builder) Build()

Build sets new InfoSchema to the handle in the Builder.

func (*Builder) InitWithDBInfos

func (b *Builder) InitWithDBInfos(dbInfos []*model.DBInfo, schemaVersion int64) (*Builder, error)

InitWithDBInfos initializes an empty new InfoSchema with a slice of DBInfo and schema version.

func (*Builder) InitWithOldInfoSchema

func (b *Builder) InitWithOldInfoSchema() *Builder

InitWithOldInfoSchema initializes an empty new InfoSchema by copies all the data from old InfoSchema.

type Handle

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

Handle handles information schema, including getting and setting.

func NewHandle

func NewHandle(store kv.Storage) *Handle

NewHandle creates a new Handle.

func (*Handle) EmptyClone

func (h *Handle) EmptyClone() *Handle

EmptyClone creates a new Handle with the same store and memSchema, but the value is not set.

func (*Handle) Get

func (h *Handle) Get() InfoSchema

Get gets information schema from Handle.

func (*Handle) IsValid

func (h *Handle) IsValid() bool

IsValid uses to check whether handle value is valid.

type InfoSchema

type InfoSchema interface {
	SchemaByName(schema model.CIStr) (*model.DBInfo, bool)
	SchemaExists(schema model.CIStr) bool
	TableByName(schema, table model.CIStr) (table.Table, error)
	TableExists(schema, table model.CIStr) bool
	SchemaByID(id int64) (*model.DBInfo, bool)
	SchemaByTable(tableInfo *model.TableInfo) (*model.DBInfo, bool)
	TableByID(id int64) (table.Table, bool)
	AllocByID(id int64) (autoid.Allocator, bool)
	AllSchemaNames() []string
	AllSchemas() []*model.DBInfo
	Clone() (result []*model.DBInfo)
	SchemaTables(schema model.CIStr) []table.Table
	SchemaMetaVersion() int64
	// TableIsView indicates whether the schema.table is a view.
	TableIsView(schema, table model.CIStr) bool
}

InfoSchema is the interface used to retrieve the schema information. It works as a in memory cache and doesn't handle any schema change. InfoSchema is read-only, and the returned value is a copy. TODO: add more methods to retrieve tables and columns.

func MockInfoSchema

func MockInfoSchema(tbList []*model.TableInfo) InfoSchema

MockInfoSchema only serves for test.

type VirtualTable

type VirtualTable struct{}

VirtualTable is a dummy table.Table implementation.

func (*VirtualTable) AddRecord

func (vt *VirtualTable) AddRecord(ctx sessionctx.Context, r []types.Datum, opts ...table.AddRecordOption) (recordID int64, err error)

AddRecord implements table.Table AddRecord interface.

func (*VirtualTable) AllocAutoIncrementValue

func (vt *VirtualTable) AllocAutoIncrementValue(ctx sessionctx.Context) (int64, error)

AllocAutoIncrementValue implements table.Table AllocAutoIncrementValue interface.

func (*VirtualTable) AllocHandle

func (vt *VirtualTable) AllocHandle(ctx sessionctx.Context) (int64, error)

AllocHandle implements table.Table AllocHandle interface.

func (*VirtualTable) Allocator

func (vt *VirtualTable) Allocator(ctx sessionctx.Context) autoid.Allocator

Allocator implements table.Table Allocator interface.

func (*VirtualTable) Cols

func (vt *VirtualTable) Cols() []*table.Column

Cols implements table.Table Cols interface.

func (*VirtualTable) DeletableIndices

func (vt *VirtualTable) DeletableIndices() []table.Index

DeletableIndices implements table.Table DeletableIndices interface.

func (*VirtualTable) FirstKey

func (vt *VirtualTable) FirstKey() kv.Key

FirstKey implements table.Table FirstKey interface.

func (*VirtualTable) GetPhysicalID

func (vt *VirtualTable) GetPhysicalID() int64

GetPhysicalID implements table.Table GetPhysicalID interface.

func (*VirtualTable) IndexPrefix

func (vt *VirtualTable) IndexPrefix() kv.Key

IndexPrefix implements table.Table IndexPrefix interface.

func (*VirtualTable) Indices

func (vt *VirtualTable) Indices() []table.Index

Indices implements table.Table Indices interface.

func (*VirtualTable) IterRecords

func (vt *VirtualTable) IterRecords(ctx sessionctx.Context, startKey kv.Key, cols []*table.Column,
	fn table.RecordIterFunc) error

IterRecords implements table.Table IterRecords interface.

func (*VirtualTable) Meta

func (vt *VirtualTable) Meta() *model.TableInfo

Meta implements table.Table Meta interface.

func (*VirtualTable) RebaseAutoID

func (vt *VirtualTable) RebaseAutoID(ctx sessionctx.Context, newBase int64, isSetStep bool) error

RebaseAutoID implements table.Table RebaseAutoID interface.

func (*VirtualTable) RecordKey

func (vt *VirtualTable) RecordKey(h int64) kv.Key

RecordKey implements table.Table RecordKey interface.

func (*VirtualTable) RecordPrefix

func (vt *VirtualTable) RecordPrefix() kv.Key

RecordPrefix implements table.Table RecordPrefix interface.

func (*VirtualTable) RemoveRecord

func (vt *VirtualTable) RemoveRecord(ctx sessionctx.Context, h int64, r []types.Datum) error

RemoveRecord implements table.Table RemoveRecord interface.

func (*VirtualTable) Row

func (vt *VirtualTable) Row(ctx sessionctx.Context, h int64) ([]types.Datum, error)

Row implements table.Table Row interface.

func (*VirtualTable) RowWithCols

func (vt *VirtualTable) RowWithCols(ctx sessionctx.Context, h int64, cols []*table.Column) ([]types.Datum, error)

RowWithCols implements table.Table RowWithCols interface.

func (*VirtualTable) Seek

func (vt *VirtualTable) Seek(ctx sessionctx.Context, h int64) (int64, bool, error)

Seek implements table.Table Seek interface.

func (*VirtualTable) Type

func (vt *VirtualTable) Type() table.Type

Type implements table.Table Type interface.

func (*VirtualTable) UpdateRecord

func (vt *VirtualTable) UpdateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datum, touched []bool) error

UpdateRecord implements table.Table UpdateRecord interface.

func (*VirtualTable) WritableCols

func (vt *VirtualTable) WritableCols() []*table.Column

WritableCols implements table.Table WritableCols interface.

func (*VirtualTable) WritableIndices

func (vt *VirtualTable) WritableIndices() []table.Index

WritableIndices implements table.Table WritableIndices interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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