session

package
v1.2112.0-pre3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SysVarLowerCaseTableNames = "lower_case_table_names"
)

Variables

This section is empty.

Functions

func WithExecutor

func WithExecutor(e *executor.Executor) contextOption

Types

type Context

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

Context is a database information cache.

Is provides many methods to get database information.

It do lazy load and cache the information if executor provided. Otherwise, it only return from cache.

func NewContext

func NewContext(parent *Context, opts ...contextOption) *Context

NewContext creates a new context.

func NewMockContext

func NewMockContext(e *executor.Executor) *Context

NewMockContext creates a new mock context for unit test.

func (*Context) AddSchema

func (c *Context) AddSchema(name string)

func (*Context) AddSysVar

func (c *Context) AddSysVar(name, value string)

func (*Context) AddTable

func (c *Context) AddTable(schemaName, tableName string, table *TableInfo)

func (*Context) CurrentSchema

func (c *Context) CurrentSchema() string

CurrentSchema return current schema.

func (*Context) DelSchema

func (c *Context) DelSchema(name string)

func (*Context) DelTable

func (c *Context) DelTable(schemaName, tableName string)

func (*Context) GetCollationDatabase

func (c *Context) GetCollationDatabase(stmt *ast.TableName, schemaName string) (string, error)

GetCollationDatabase get collation database.

func (*Context) GetColumnCardinality

func (c *Context) GetColumnCardinality(tn *ast.TableName, columnName string) (int, error)

func (*Context) GetCreateTableStmt

func (c *Context) GetCreateTableStmt(stmt *ast.TableName) (*ast.CreateTableStmt, bool, error)

GetCreateTableStmt get create table stmtNode for db by query; if table not exist, return null.

func (*Context) GetExecutionPlan

func (c *Context) GetExecutionPlan(sql string) ([]*executor.ExplainRecord, error)

GetExecutionPlan get execution plan of SQL.

func (*Context) GetMaxIndexOptionForTable

func (c *Context) GetMaxIndexOptionForTable(stmt *ast.TableName, columnNames []string) (string, error)

GetMaxIndexOptionForTable get max index option column of table.

func (*Context) GetSchema

func (c *Context) GetSchema(schemaName string) (*SchemaInfo, bool)

func (*Context) GetSchemaCharacter

func (c *Context) GetSchemaCharacter(stmt *ast.TableName, schemaName string) (string, error)

GetSchemaCharacter get schema default character.

func (*Context) GetSchemaEngine

func (c *Context) GetSchemaEngine(stmt *ast.TableName, schemaName string) (string, error)

GetSchemaEngine get schema default engine.

func (*Context) GetSchemaName

func (c *Context) GetSchemaName(stmt *ast.TableName) string

GetSchemaName get schema name from AST or current schema.

func (*Context) GetSysVar

func (c *Context) GetSysVar(name string) (string, bool)

func (*Context) GetSystemVariable

func (c *Context) GetSystemVariable(name string) (string, error)

GetSystemVariable get system variable.

func (*Context) GetTable

func (c *Context) GetTable(schemaName, tableName string) (*TableInfo, bool)

func (*Context) GetTableInfo

func (c *Context) GetTableInfo(stmt *ast.TableName) (*TableInfo, bool)

GetTableInfo get table info from context.

func (*Context) GetTableRowCount

func (c *Context) GetTableRowCount(tn *ast.TableName) (int, error)

GetTableRowCount get table row count by show table status.

func (*Context) GetTableSize

func (c *Context) GetTableSize(stmt *ast.TableName) (float64, error)

GetTableSize get table size.

func (*Context) HasLoadSchemas

func (c *Context) HasLoadSchemas() bool

func (*Context) HasLoadTables

func (c *Context) HasLoadTables(schemaName string) (hasLoad bool)

func (*Context) HasSchema

func (c *Context) HasSchema(schemaName string) (has bool)

func (*Context) HasTable

func (c *Context) HasTable(schemaName, tableName string) (has bool)

func (*Context) IsSchemaExist

func (c *Context) IsSchemaExist(schemaName string) (bool, error)

IsSchemaExist check schema is exist or not.

func (*Context) IsTableExist

func (c *Context) IsTableExist(stmt *ast.TableName) (bool, error)

IsTableExist check table is exist or not.

func (*Context) IsTableExistInDatabase

func (c *Context) IsTableExistInDatabase(tn *ast.TableName) (bool, error)

IsTableExistInDatabase check table exist in database. Sometimes, we need explain on SQL, if table not exist, we will get error.

func (*Context) LoadSchemas

func (c *Context) LoadSchemas(schemas []string)

func (*Context) LoadTables

func (c *Context) LoadTables(schemaName string, tablesName []string)

func (*Context) Schemas

func (c *Context) Schemas() map[string]*SchemaInfo

Schemas return all schemas info in current context.

func (*Context) SetCurrentSchema

func (c *Context) SetCurrentSchema(schema string)

func (*Context) SetSchemasLoad

func (c *Context) SetSchemasLoad()

func (*Context) UpdateContext

func (c *Context) UpdateContext(node ast.Node)

type SchemaInfo

type SchemaInfo struct {
	DefaultEngine string

	DefaultCharacter string

	DefaultCollation string

	Tables map[string]*TableInfo
	// contains filtered or unexported fields
}

type TableInfo

type TableInfo struct {
	Size float64

	// OriginalTable save parser object from db by query "show create table ...";
	// using in inspect and generate rollback sql
	OriginalTable *ast.CreateTableStmt

	//
	MergedTable *ast.CreateTableStmt

	// save alter table parse object from input sql;
	AlterTables []*ast.AlterTableStmt
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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