plancontext

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PlannerVersion

type PlannerVersion = querypb.ExecuteOptions_PlannerVersion

PlannerVersion is an alias here to make the code more readable

func PlannerNameToVersion

func PlannerNameToVersion(s string) (PlannerVersion, bool)

PlannerNameToVersion returns the numerical representation of the planner

type PlanningContext

type PlanningContext struct {
	ReservedVars *sqlparser.ReservedVars
	SemTable     *semantics.SemTable
	VSchema      VSchema

	PlannerVersion querypb.ExecuteOptions_PlannerVersion

	// If we during planning have turned this expression into an argument name,
	// we can continue using the same argument name
	ReservedArguments map[sqlparser.Expr]string

	// VerifyAllFKs tells whether we need verification for all the fk constraints on VTGate.
	// This is required for queries we are running with /*+ SET_VAR(foreign_key_checks=OFF) */
	VerifyAllFKs bool

	// Projected subqueries that have been merged
	MergedSubqueries []*sqlparser.Subquery

	// CurrentPhase keeps track of how far we've gone in the planning process
	// The type should be operators.Phase, but depending on that would lead to circular dependencies
	CurrentPhase int

	// Statement contains the originally parsed statement
	Statement sqlparser.Statement

	// OuterTables contains the tables that are outer to the current query
	// Used to set the nullable flag on the columns
	OuterTables semantics.TableSet
	// contains filtered or unexported fields
}

func CreatePlanningContext added in v0.18.0

func CreatePlanningContext(stmt sqlparser.Statement,
	reservedVars *sqlparser.ReservedVars,
	vschema VSchema,
	version querypb.ExecuteOptions_PlannerVersion,
) (*PlanningContext, error)

CreatePlanningContext initializes a new PlanningContext with the given parameters. It analyzes the SQL statement within the given virtual schema context, handling default keyspace settings and semantic analysis. Returns an error if semantic analysis fails.

func (*PlanningContext) AddJoinPredicates added in v0.18.8

func (ctx *PlanningContext) AddJoinPredicates(joinPred sqlparser.Expr, predicates ...sqlparser.Expr)

AddJoinPredicates associates additional RHS predicates with an existing join predicate. This is used to dynamically adjust the RHS predicates based on evolving join conditions.

func (*PlanningContext) GetReservedArgumentFor added in v0.18.0

func (ctx *PlanningContext) GetReservedArgumentFor(expr sqlparser.Expr) string

GetReservedArgumentFor retrieves a reserved argument name for a given expression. If the expression already has a reserved argument, it returns that name; otherwise, it reserves a new name based on the expression type.

func (*PlanningContext) KeepPredicateInfo added in v0.18.8

func (ctx *PlanningContext) KeepPredicateInfo(other *PlanningContext)

KeepPredicateInfo transfers join predicate information from another context. This is useful when nesting queries, ensuring consistent predicate handling across contexts.

func (*PlanningContext) RewriteDerivedTableExpression added in v0.19.5

func (ctx *PlanningContext) RewriteDerivedTableExpression(expr sqlparser.Expr, tableInfo semantics.TableInfo) sqlparser.Expr

func (*PlanningContext) ShouldSkip added in v0.18.8

func (ctx *PlanningContext) ShouldSkip(expr sqlparser.Expr) bool

ShouldSkip determines if a given expression should be ignored in the SQL output building. It checks against expressions that have been marked to be excluded from further processing.

func (*PlanningContext) SkipJoinPredicates added in v0.18.8

func (ctx *PlanningContext) SkipJoinPredicates(joinPred sqlparser.Expr) error

SkipJoinPredicates marks the predicates related to a specific join predicate as irrelevant for the current planning stage. This is used when a join has been pushed under a route and the original predicate will be used.

func (*PlanningContext) TypeForExpr added in v0.19.5

func (ctx *PlanningContext) TypeForExpr(e sqlparser.Expr) (evalengine.Type, bool)

TypeForExpr returns the type of the given expression, with nullable set if the expression is from an outer table.

type VSchema

type VSchema interface {
	FindTable(tablename sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error)
	FindView(name sqlparser.TableName) sqlparser.SelectStatement
	FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error)
	DefaultKeyspace() (*vindexes.Keyspace, error)
	TargetString() string
	Destination() key.Destination
	TabletType() topodatapb.TabletType
	TargetDestination(qualifier string) (key.Destination, *vindexes.Keyspace, topodatapb.TabletType, error)
	AnyKeyspace() (*vindexes.Keyspace, error)
	FirstSortedKeyspace() (*vindexes.Keyspace, error)
	SysVarSetEnabled() bool
	KeyspaceExists(keyspace string) bool
	AllKeyspace() ([]*vindexes.Keyspace, error)
	FindKeyspace(keyspace string) (*vindexes.Keyspace, error)
	GetSemTable() *semantics.SemTable
	Planner() PlannerVersion
	SetPlannerVersion(pv PlannerVersion)
	ConnCollation() collations.ID
	Environment() *vtenv.Environment

	// ErrorIfShardedF will return an error if the keyspace is sharded,
	// and produce a warning if the vtgate if configured to do so
	ErrorIfShardedF(keyspace *vindexes.Keyspace, warn, errFmt string, params ...any) error

	// WarnUnshardedOnly is used when a feature is only supported in unsharded mode.
	// This will let the user know that they are using something
	// that could become a problem if they move to a sharded keyspace
	WarnUnshardedOnly(format string, params ...any)

	// PlannerWarning records warning created during planning.
	PlannerWarning(message string)

	// ForeignKeyMode returns the foreign_key flag value
	ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error)

	// KeyspaceError returns any error in the keyspace vschema.
	KeyspaceError(keyspace string) error

	GetForeignKeyChecksState() *bool

	// GetVSchema returns the latest cached vindexes.VSchema
	GetVSchema() *vindexes.VSchema

	// GetSrvVschema returns the latest cached vschema.SrvVSchema
	GetSrvVschema() *vschemapb.SrvVSchema

	// FindRoutedShard looks up shard routing rules for a shard
	FindRoutedShard(keyspace, shard string) (string, error)

	// IsShardRoutingEnabled returns true if partial shard routing is enabled
	IsShardRoutingEnabled() bool

	// IsViewsEnabled returns true if Vitess manages the views.
	IsViewsEnabled() bool

	// GetUDV returns user defined value from the variable passed.
	GetUDV(name string) *querypb.BindVariable

	// PlanPrepareStatement plans the prepared statement.
	PlanPrepareStatement(ctx context.Context, query string) (*engine.Plan, sqlparser.Statement, error)

	// ClearPrepareData clears the prepared data from the session.
	ClearPrepareData(stmtName string)

	// GetPrepareData returns the prepared data for the statement from the session.
	GetPrepareData(stmtName string) *vtgatepb.PrepareData

	// StorePrepareData stores the prepared data in the session.
	StorePrepareData(name string, v *vtgatepb.PrepareData)

	// GetAggregateUDFs returns the list of aggregate UDFs.
	GetAggregateUDFs() []string
}

VSchema defines the interface for this package to fetch info about tables.

Jump to

Keyboard shortcuts

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