session

package
v1.2210.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MPL-2.0 Imports: 9 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 NewMockContextForTestLowerCaseTableNameClose added in v1.2202.0

func NewMockContextForTestLowerCaseTableNameClose(e *executor.Executor) *Context

func NewMockContextForTestLowerCaseTableNameOpen added in v1.2202.0

func NewMockContextForTestLowerCaseTableNameOpen(e *executor.Executor) *Context

func (*Context) AddSystemVariable added in v1.2202.0

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

func (*Context) CurrentSchema

func (c *Context) CurrentSchema() string

CurrentSchema return current schema.

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) GetHistorySQLInfo added in v1.2201.0

func (c *Context) GetHistorySQLInfo() *HistorySQLInfo

func (*Context) GetMaxIndexOptionForTable

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

GetMaxIndexOptionForTable get max index option column of table.

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

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

GetSystemVariable get system variable.

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) IsLowerCaseTableName added in v1.2207.0

func (c *Context) IsLowerCaseTableName() 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) 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) UpdateContext

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

type HistorySQLInfo added in v1.2201.0

type HistorySQLInfo struct {
	HasDML bool
	HasDDL bool
}

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