semantics

package
v0.12.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMultipleTables refers to an error happening when something should be used only for single tables
	ErrMultipleTables = vterrors.Errorf(vtrpcpb.Code_INTERNAL, "[BUG] should only be used for single tables")
)

Functions

func Gen4NotSupportedF

func Gen4NotSupportedF(format string, args ...interface{}) error

Gen4NotSupportedF returns a common error for shortcomings in the gen4 planner

func RewriteDerivedExpression added in v0.12.0

func RewriteDerivedExpression(expr sqlparser.Expr, vt TableInfo) (sqlparser.Expr, error)

RewriteDerivedExpression rewrites all the ColName instances in the supplied expression with the expressions behind the column definition of the derived table SELECT foo FROM (SELECT id+42 as foo FROM user) as t We need `foo` to be translated to `id+42` on the inside of the derived table

Types

type ColumnInfo added in v0.12.0

type ColumnInfo struct {
	Name string
	Type querypb.Type
}

ColumnInfo contains information about columns

type ExprDependencies added in v0.12.0

type ExprDependencies map[sqlparser.Expr]TableSet

ExprDependencies stores the tables that an expression depends on as a map

func (ExprDependencies) Dependencies added in v0.12.0

func (d ExprDependencies) Dependencies(expr sqlparser.Expr) TableSet

Dependencies return the table dependencies of the expression. This method finds table dependencies recursively

type FakeSI added in v0.11.0

type FakeSI struct {
	Tables       map[string]*vindexes.Table
	VindexTables map[string]vindexes.Vindex
}

FakeSI is a fake SchemaInformation for testing

func (*FakeSI) FindTableOrVindex added in v0.11.0

FindTableOrVindex implements the SchemaInformation interface

type ProjError added in v0.12.0

type ProjError struct {
	Inner error
}

ProjError is used to mark an error as something that should only be returned if the planner fails to merge everything down to a single route

func (ProjError) Error added in v0.12.0

func (p ProjError) Error() string

type RealTable added in v0.12.0

type RealTable struct {
	ASTNode *sqlparser.AliasedTableExpr
	Table   *vindexes.Table
	// contains filtered or unexported fields
}

RealTable contains the alias table expr and vindex table

func (*RealTable) GetVindexTable added in v0.12.0

func (r *RealTable) GetVindexTable() *vindexes.Table

GetVindexTable implements the TableInfo interface

func (*RealTable) IsInfSchema added in v0.12.0

func (r *RealTable) IsInfSchema() bool

IsInfSchema implements the TableInfo interface

func (*RealTable) Name added in v0.12.0

func (r *RealTable) Name() (sqlparser.TableName, error)

Name implements the TableInfo interface

type SchemaInformation added in v0.11.0

type SchemaInformation interface {
	FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error)
}

SchemaInformation is used tp provide table information from Vschema.

type SemTable

type SemTable struct {
	Tables []TableInfo
	// ProjectionErr stores the error that we got during the semantic analysis of the SelectExprs.
	// This is only a real error if we are unable to plan the query as a single route
	ProjectionErr error

	// Recursive contains the dependencies from the expression to the actual tables
	// in the query (i.e. not including derived tables). If an expression is a column on a derived table,
	// this map will contain the accumulated dependencies for the column expression inside the derived table
	Recursive ExprDependencies

	// Direct keeps information about the closest dependency for an expression.
	// It does not recurse inside derived tables and the like to find the original dependencies
	Direct ExprDependencies

	Comments    sqlparser.Comments
	SubqueryMap map[*sqlparser.Select][]*subquery
	SubqueryRef map[*sqlparser.Subquery]*subquery

	// ColumnEqualities is used to enable transitive closures
	// if a == b and b == c then a == c
	ColumnEqualities map[columnName][]sqlparser.Expr
	// contains filtered or unexported fields
}

SemTable contains semantic analysis information about the query.

func Analyze added in v0.11.0

func Analyze(statement sqlparser.SelectStatement, currentDb string, si SchemaInformation) (*SemTable, error)

Analyze analyzes the parsed query.

func NewSemTable

func NewSemTable() *SemTable

NewSemTable creates a new empty SemTable

func (*SemTable) AddColumnEquality added in v0.12.0

func (st *SemTable) AddColumnEquality(colName *sqlparser.ColName, expr sqlparser.Expr)

AddColumnEquality adds a relation of the given colName to the ColumnEqualities map

func (*SemTable) AddExprs added in v0.11.0

func (st *SemTable) AddExprs(tbl *sqlparser.AliasedTableExpr, cols sqlparser.SelectExprs)

AddExprs adds new select exprs to the SemTable.

func (*SemTable) CopyDependencies added in v0.12.0

func (st *SemTable) CopyDependencies(from, to sqlparser.Expr)

CopyDependencies copies the dependencies from one expression into the other

func (*SemTable) DirectDeps added in v0.12.0

func (st *SemTable) DirectDeps(expr sqlparser.Expr) TableSet

DirectDeps return the table dependencies of the expression.

func (*SemTable) GetExprAndEqualities added in v0.12.0

func (st *SemTable) GetExprAndEqualities(expr sqlparser.Expr) []sqlparser.Expr

GetExprAndEqualities returns a slice containing the given expression, and it's known equalities if any

func (*SemTable) GetSelectTables added in v0.11.0

func (st *SemTable) GetSelectTables(node *sqlparser.Select) []TableInfo

GetSelectTables returns the table in the select.

func (*SemTable) RecursiveDeps added in v0.12.0

func (st *SemTable) RecursiveDeps(expr sqlparser.Expr) TableSet

RecursiveDeps return the table dependencies of the expression.

func (*SemTable) TableInfoFor added in v0.11.0

func (st *SemTable) TableInfoFor(id TableSet) (TableInfo, error)

TableInfoFor returns the table info for the table set. It should contains only single table.

func (*SemTable) TableInfoForExpr added in v0.12.0

func (st *SemTable) TableInfoForExpr(expr sqlparser.Expr) (TableInfo, error)

TableInfoForExpr returns the table info of the table that this expression depends on. Careful: this only works for expressions that have a single table dependency

func (*SemTable) TableSetFor

func (st *SemTable) TableSetFor(t *sqlparser.AliasedTableExpr) TableSet

TableSetFor returns the bitmask for this particular table

func (*SemTable) TypeFor added in v0.12.0

func (st *SemTable) TypeFor(e sqlparser.Expr) *querypb.Type

TypeFor returns the type of expressions in the query

type TableInfo added in v0.11.0

type TableInfo interface {
	// Name returns the table name
	Name() (sqlparser.TableName, error)

	// GetVindexTable returns the vschema version of this TableInfo
	GetVindexTable() *vindexes.Table

	// IsInfSchema returns true if this table is information_schema
	IsInfSchema() bool
	// contains filtered or unexported methods
}

TableInfo contains information about tables

type TableSet

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

TableSet is how a set of tables is expressed. Tables get unique bits assigned in the order that they are encountered during semantic analysis. This TableSet implementation is optimized for sets of less than 64 tables, but can grow to support an arbitrary large amount of tables.

func MergeTableSets added in v0.12.0

func MergeTableSets(tss ...TableSet) (result TableSet)

MergeTableSets merges all the given TableSet into a single one

func SingleTableSet added in v0.12.0

func SingleTableSet(tableidx int) TableSet

SingleTableSet creates a TableSet that contains only the given table

func TableSetFromIds added in v0.12.0

func TableSetFromIds(tids ...int) (ts TableSet)

func (*TableSet) AddTable added in v0.12.0

func (ts *TableSet) AddTable(tableidx int)

AddTable adds the given table to this set

func (TableSet) Constituents

func (ts TableSet) Constituents() (result []int)

Constituents returns a slice with the indices for all tables in this TableSet

func (TableSet) ForEachTable added in v0.12.0

func (ts TableSet) ForEachTable(callback func(int))

ForEachTable calls the given callback with the indices for all tables in this TableSet

func (TableSet) Format added in v0.12.0

func (ts TableSet) Format(f fmt.State, verb rune)

func (TableSet) IsOverlapping

func (ts TableSet) IsOverlapping(other TableSet) bool

IsOverlapping returns true if at least one table exists in both sets

func (TableSet) IsSolvedBy

func (ts TableSet) IsSolvedBy(other TableSet) bool

IsSolvedBy returns true if all of `ts` is contained in `other`

func (TableSet) Merge

func (ts TableSet) Merge(other TableSet) TableSet

Merge creates a TableSet that contains both inputs

func (*TableSet) MergeInPlace added in v0.12.0

func (ts *TableSet) MergeInPlace(other TableSet)

MergeInPlace merges all the tables in `other` into this TableSet

func (TableSet) NumberOfTables

func (ts TableSet) NumberOfTables() int

NumberOfTables returns the number of bits set

func (TableSet) TableOffset added in v0.11.0

func (ts TableSet) TableOffset() int

TableOffset returns the offset in the Tables array from TableSet

type VindexTable added in v0.12.0

type VindexTable struct {
	Table  TableInfo
	Vindex vindexes.Vindex
}

VindexTable contains a vindexes.Vindex and a TableInfo. The former represents the vindex we are keeping information about, and the latter represents the additional table information (usually a RealTable or an AliasedTable) of our vindex.

func (*VindexTable) GetVindexTable added in v0.12.0

func (v *VindexTable) GetVindexTable() *vindexes.Table

GetVindexTable implements the TableInfo interface

func (*VindexTable) IsInfSchema added in v0.12.0

func (v *VindexTable) IsInfSchema() bool

IsInfSchema implements the TableInfo interface

func (*VindexTable) Name added in v0.12.0

func (v *VindexTable) Name() (sqlparser.TableName, error)

Name implements the TableInfo interface

Jump to

Keyboard shortcuts

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