infoschema

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: GPL-3.0 Imports: 20 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")
	// 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")
)
View Source
var TableStatsCacheExpiry = 3 * time.Second

TableStatsCacheExpiry is the expiry time for table stats cache.

Functions

func IsMemoryDB

func IsMemoryDB(dbName string) bool

IsMemoryDB checks if the db is in memory.

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 detal 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.

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

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.

Jump to

Keyboard shortcuts

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