Documentation
¶
Overview ¶
Package logicalir contains the experimental logical SQL IR and rewrite evaluation API. It is intentionally independent from the current optimizer.
Index ¶
- func ValidateLogicalQuery(q *LogicalQuery) error
- type Aggregate
- type AnalysisCompleteness
- type AnalysisSnapshot
- type AttemptID
- type AttemptStatus
- type BindingID
- type CatalogSnapshot
- type ColumnBinding
- type ConstantFoldingRule
- type CostComparison
- type CostSnapshot
- type Determinism
- type ExplainSnapshot
- type Expr
- type ExprKind
- type ExpressionChange
- type Filter
- type FilterDiff
- type HeuristicAssessment
- type Join
- type JoinType
- type Knowledge
- type Limit
- type LimitSpec
- type LogicalQuery
- type NullBehavior
- type OrderItem
- type OutputColumn
- type OutputSchema
- type Predicate
- type PredicateAnalysis
- type PredicateCopy
- type PredicateID
- type PredicateMove
- type PredicateOrigin
- type PredicatePushdownRule
- type Project
- type ProjectionExpr
- type ProjectionPruningOptions
- type ProjectionPruningRule
- type PushdownAction
- type PushdownAttempt
- type PushdownDecision
- type PushdownOptions
- type PushdownReason
- type QueryBlock
- type QueryBlockID
- type QueryDiff
- type RecheckPolicy
- type RelationID
- type RelationNode
- type RewriteEvaluation
- type RewriteResult
- type RewriteRule
- type SafetyAssessment
- type SafetyProof
- type SafetyStatus
- type SchemaKnowledge
- type SetOp
- type SetOpType
- type Sort
- type SourceSpan
- type StatisticsSnapshot
- type TableScan
- type TypeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateLogicalQuery ¶
func ValidateLogicalQuery(q *LogicalQuery) error
Types ¶
type Aggregate ¶
type Aggregate struct {
Relation RelationID
Input RelationNode
GroupBy []Expr
Items []ProjectionExpr
}
func (*Aggregate) ID ¶
func (a *Aggregate) ID() RelationID
func (*Aggregate) OutputSchema ¶
func (a *Aggregate) OutputSchema() OutputSchema
type AnalysisCompleteness ¶
type AnalysisCompleteness uint8
const ( CompletenessComplete AnalysisCompleteness = iota CompletenessPartial CompletenessOverflow )
type AnalysisSnapshot ¶
type AnalysisSnapshot struct {
Query *LogicalQuery
Rewrites *RewriteEvaluation
Catalog *CatalogSnapshot
Statistics *StatisticsSnapshot
Explain *ExplainSnapshot
Cost *CostSnapshot
}
func (*AnalysisSnapshot) Clone ¶
func (s *AnalysisSnapshot) Clone() *AnalysisSnapshot
func (*AnalysisSnapshot) Validate ¶
func (s *AnalysisSnapshot) Validate() error
type AttemptStatus ¶
type AttemptStatus uint8
const ( AttemptComplete AttemptStatus = iota AttemptDegraded AttemptFailed )
type CatalogSnapshot ¶
type CatalogSnapshot struct {
Identity string
Relations map[RelationID]OutputSchema
}
type ColumnBinding ¶
type ColumnBinding struct {
ID BindingID
QueryBlock QueryBlockID
Relation RelationID
Column, Alias string
Type TypeInfo
Nullable Knowledge
}
type ConstantFoldingRule ¶
type ConstantFoldingRule struct{}
ConstantFoldingRule is a concrete logical rewrite rule for predicate expressions. It only changes predicate expressions with a provable result.
func (ConstantFoldingRule) Apply ¶
func (ConstantFoldingRule) Apply(q *LogicalQuery) (*RewriteResult, error)
func (ConstantFoldingRule) Match ¶
func (ConstantFoldingRule) Match(q *LogicalQuery) bool
func (ConstantFoldingRule) Name ¶
func (ConstantFoldingRule) Name() string
type CostComparison ¶
type CostSnapshot ¶
type CostSnapshot struct {
Identity string
Comparisons []CostComparison
}
type Determinism ¶
type Determinism uint8
const ( DeterminismUnknown Determinism = iota Deterministic NonDeterministic )
type ExplainSnapshot ¶
type ExplainSnapshot struct {
Identity string
Annotations map[RelationID]string
}
type Expr ¶
type Expr struct {
Kind ExprKind
Name string
Binding *BindingID
Children []Expr
SourceSpan SourceSpan
}
func FoldConstants ¶
FoldConstants folds boolean and simple numeric literal expressions when the result is fully determined by the IR. Unknown expressions are preserved.
type ExpressionChange ¶
type ExpressionChange struct {
PredicateID PredicateID
Before, After Expr
}
type Filter ¶
type Filter struct {
Relation RelationID
Input RelationNode
Predicates []PredicateID
}
func (*Filter) ID ¶
func (f *Filter) ID() RelationID
func (*Filter) OutputSchema ¶
func (f *Filter) OutputSchema() OutputSchema
type FilterDiff ¶
type FilterDiff struct {
Relation RelationID
Predicates []PredicateID
}
type HeuristicAssessment ¶
type Join ¶
type Join struct {
Relation RelationID
Left, Right RelationNode
JoinType JoinType
Conditions []PredicateID
}
func (*Join) ID ¶
func (j *Join) ID() RelationID
func (*Join) OutputSchema ¶
func (j *Join) OutputSchema() OutputSchema
type Limit ¶
type Limit struct {
Relation RelationID
Input RelationNode
Spec LimitSpec
}
func (*Limit) ID ¶
func (l *Limit) ID() RelationID
func (*Limit) OutputSchema ¶
func (l *Limit) OutputSchema() OutputSchema
type LogicalQuery ¶
type LogicalQuery struct {
Root RelationNode
Blocks map[QueryBlockID]*QueryBlock
Predicates map[PredicateID]*Predicate
Bindings map[BindingID]*ColumnBinding
Schema OutputSchema
}
func (*LogicalQuery) CloneForRewrite ¶
func (q *LogicalQuery) CloneForRewrite() *LogicalQuery
type NullBehavior ¶
type NullBehavior uint8
const ( NullBehaviorUnknown NullBehavior = iota NullPropagating NullRejecting )
type OutputColumn ¶
type OutputSchema ¶
type OutputSchema struct {
Knowledge SchemaKnowledge
Columns []OutputColumn
}
type Predicate ¶
type Predicate struct {
ID PredicateID
Expr Expr
Origin PredicateOrigin
Scope QueryBlockID
References []BindingID
Nullability NullBehavior
Determinism Determinism
SourceSpan SourceSpan
}
type PredicateAnalysis ¶
type PredicateAnalysis struct {
Original PredicateID
References []BindingID
Pushable bool
Overflow bool
Completeness AnalysisCompleteness
}
func AnalyzePredicate ¶
func AnalyzePredicate(p *Predicate, maxRefs int) PredicateAnalysis
type PredicateCopy ¶
type PredicateCopy struct {
PredicateID PredicateID
From, To RelationID
Recheck RecheckPolicy
}
type PredicateID ¶
type PredicateID string
type PredicateMove ¶
type PredicateMove struct {
PredicateID PredicateID
From, To RelationID
Recheck RecheckPolicy
}
type PredicateOrigin ¶
type PredicateOrigin uint8
const ( PredicateFromWhere PredicateOrigin = iota PredicateFromJoinOn PredicateFromHaving PredicateGenerated )
type PredicatePushdownRule ¶
type PredicatePushdownRule struct{ Options PushdownOptions }
PredicatePushdownRule adapts the initial pushdown implementation to the general rewrite interface.
func (PredicatePushdownRule) Apply ¶
func (r PredicatePushdownRule) Apply(q *LogicalQuery) (*RewriteResult, error)
func (PredicatePushdownRule) Match ¶
func (r PredicatePushdownRule) Match(q *LogicalQuery) bool
func (PredicatePushdownRule) Name ¶
func (r PredicatePushdownRule) Name() string
type Project ¶
type Project struct {
Relation RelationID
Input RelationNode
Items []ProjectionExpr
}
func (*Project) ID ¶
func (p *Project) ID() RelationID
func (*Project) OutputSchema ¶
func (p *Project) OutputSchema() OutputSchema
type ProjectionExpr ¶
type ProjectionPruningOptions ¶
type ProjectionPruningOptions struct{ Required []BindingID }
type ProjectionPruningRule ¶
type ProjectionPruningRule struct{ Options ProjectionPruningOptions }
func (ProjectionPruningRule) Apply ¶
func (r ProjectionPruningRule) Apply(q *LogicalQuery) (*RewriteResult, error)
func (ProjectionPruningRule) Match ¶
func (r ProjectionPruningRule) Match(q *LogicalQuery) bool
func (ProjectionPruningRule) Name ¶
func (ProjectionPruningRule) Name() string
type PushdownAction ¶
type PushdownAction uint8
const ( PushdownKept PushdownAction = iota PushdownCopied PushdownMoved PushdownPartiallyCopied PushdownRejected PushdownUnknown )
type PushdownAttempt ¶
type PushdownAttempt struct {
ID AttemptID
Strategy string
Base, Candidate *LogicalQuery
Decisions []PushdownDecision
Diff QueryDiff
Safety SafetyAssessment
Heuristic HeuristicAssessment
Cost *CostComparison
Status AttemptStatus
}
func TryPredicatePushdown ¶
func TryPredicatePushdown(base *LogicalQuery, opts PushdownOptions) (*PushdownAttempt, error)
type PushdownDecision ¶
type PushdownDecision struct {
PredicateID PredicateID
FromNode, ToNode RelationID
Action PushdownAction
Reason PushdownReason
Proof string
Confidence float64
Recheck RecheckPolicy
DerivedPredicateID *PredicateID
}
type PushdownOptions ¶
type PushdownReason ¶
type PushdownReason string
const ( ReasonSingleInput PushdownReason = "single_input" ReasonOuterJoinBarrier PushdownReason = "outer_join_barrier" ReasonCrossRelation PushdownReason = "cross_relation" ReasonUnsupported PushdownReason = "unsupported" )
type QueryBlock ¶
type QueryBlock struct {
ID QueryBlockID
From RelationNode
Projection []ProjectionExpr
Predicates []PredicateID
GroupBy []Expr
Having []Expr
OrderBy []OrderItem
Limit *LimitSpec
Distinct bool
SourceSpan SourceSpan
}
type QueryBlockID ¶
type QueryBlockID string
type QueryDiff ¶
type QueryDiff struct {
AddedFilters []FilterDiff
RemovedFilters []FilterDiff
MovedPredicates []PredicateMove
CopiedPredicates []PredicateCopy
Residuals []PredicateID
ChangedExpressions []ExpressionChange
}
func DiffLogicalQueries ¶
func DiffLogicalQueries(base, candidate *LogicalQuery) QueryDiff
DiffLogicalQueries computes the structural filter differences used by rewrite consumers. It intentionally compares logical predicate identities, leaving expression equivalence to the rule that produced the candidate.
type RecheckPolicy ¶
type RecheckPolicy uint8
const ( RecheckNotRequired RecheckPolicy = iota RecheckRequired )
type RelationID ¶
type RelationID string
type RelationNode ¶
type RelationNode interface {
ID() RelationID
OutputSchema() OutputSchema
// contains filtered or unexported methods
}
type RewriteEvaluation ¶
type RewriteEvaluation struct {
Base *LogicalQuery
Attempts []*RewriteResult
Selected *RewriteResult
}
RewriteEvaluation keeps multiple independent candidates for one immutable logical baseline. Selected is only an internal model choice.
func EvaluateRewriteRules ¶
func EvaluateRewriteRules(base *LogicalQuery, rules []RewriteRule) (*RewriteEvaluation, error)
EvaluateRewriteRules evaluates each matching rule against the same base.
type RewriteResult ¶
type RewriteResult struct {
Strategy string
Base *LogicalQuery
Candidate *LogicalQuery
Decisions []PushdownDecision
Diff QueryDiff
Safety SafetyAssessment
Heuristic HeuristicAssessment
Status AttemptStatus
}
RewriteResult is the common result returned by any logical rewrite rule.
type RewriteRule ¶
type RewriteRule interface {
Name() string
Match(*LogicalQuery) bool
Apply(*LogicalQuery) (*RewriteResult, error)
}
RewriteRule describes a semantic transformation over a logical query. Rules produce candidates; selection and execution are deliberately outside this API.
type SafetyAssessment ¶
type SafetyAssessment struct {
Status SafetyStatus
Proofs []SafetyProof
Missing []string
SemanticRisk []string
}
func AssessRewriteSafety ¶
func AssessRewriteSafety(decisions []PushdownDecision) SafetyAssessment
AssessRewriteSafety applies the common conservative gate for executable rewrites. Unknown placements cannot be emitted without an explicit proof.
type SafetyProof ¶
type SafetyProof struct {
PredicateID PredicateID
Rule, Detail string
}
type SafetyStatus ¶
type SafetyStatus uint8
const ( ProvenSafe SafetyStatus = iota ConditionallySafe HeuristicOnly Unsafe Unknown )
type SchemaKnowledge ¶
type SchemaKnowledge uint8
const ( SchemaUnknown SchemaKnowledge = iota SchemaPartial SchemaComplete )
type SetOp ¶
type SetOp struct {
Relation RelationID
Op SetOpType
Inputs []RelationNode
}
func (*SetOp) ID ¶
func (s *SetOp) ID() RelationID
func (*SetOp) OutputSchema ¶
func (s *SetOp) OutputSchema() OutputSchema
type Sort ¶
type Sort struct {
Relation RelationID
Input RelationNode
Items []OrderItem
}
func (*Sort) ID ¶
func (s *Sort) ID() RelationID
func (*Sort) OutputSchema ¶
func (s *Sort) OutputSchema() OutputSchema
type SourceSpan ¶
type SourceSpan struct{ Start, End int }
type StatisticsSnapshot ¶
type StatisticsSnapshot struct {
Identity string
RowCounts map[RelationID]float64
}
type TableScan ¶
type TableScan struct {
Relation RelationID
Schema, Table, Alias string
Output OutputSchema
}
func (*TableScan) ID ¶
func (t *TableScan) ID() RelationID
func (*TableScan) OutputSchema ¶
func (t *TableScan) OutputSchema() OutputSchema