queryoptimizer

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("query optimizer plan generation not implemented")

ErrNotImplemented is returned until the optimizer pipeline is fully implemented.

Functions

This section is empty.

Types

type AttributeBinding

type AttributeBinding struct {
	AttributeName string
	AttributeID   int16
	ValueType     forma.ValueType
	Storage       StorageTarget
	Column        *ColumnRef
	Fallback      AttributeFallbackKind
	InsideArray   bool
}

AttributeBinding exposes metadata needed for normalization.

type AttributeCatalog

type AttributeCatalog map[string]AttributeBinding

AttributeCatalog is a lookup map for attributes.

type AttributeFallbackKind

type AttributeFallbackKind string

AttributeFallbackKind describes lossy storage behaviors that require rewrites.

const (
	AttributeFallbackNone            AttributeFallbackKind = "none"
	AttributeFallbackNumericToDouble AttributeFallbackKind = "numeric_to_double"
	AttributeFallbackDateToDouble    AttributeFallbackKind = "date_to_double"
	AttributeFallbackDateToText      AttributeFallbackKind = "date_to_text"
	AttributeFallbackBoolToDouble    AttributeFallbackKind = "bool_to_double"
	AttributeFallbackBoolToText      AttributeFallbackKind = "bool_to_text"
)

type ColumnRef

type ColumnRef struct {
	Name     string
	Type     string
	Encoding string
}

ColumnRef references a concrete hot-column binding.

type FilterNode

type FilterNode struct {
	Logic     LogicOp
	Predicate *Predicate
	Children  []*FilterNode
}

FilterNode preserves the original boolean structure of the request.

type Input

type Input struct {
	SchemaID   int16
	SchemaName string
	Tables     StorageTables
	Filter     *FilterNode
	SortKeys   []SortKey
	Pagination Pagination
}

Input bundles all data required to build a SQL plan.

func NormalizeQuery

func NormalizeQuery(req *forma.QueryRequest, schemaID int16, schemaName string, tables StorageTables, attrs AttributeCatalog, opts NormalizerOptions) (*Input, error)

NormalizeQuery converts a QueryRequest into the optimizer Input IR.

type LogicOp

type LogicOp string

LogicOp represents boolean connectors in normalized filters.

const (
	LogicOpAnd LogicOp = "AND"
	LogicOpOr  LogicOp = "OR"
)

type NormalizerOptions

type NormalizerOptions struct {
	DefaultLimit int
	MaxLimit     int
}

NormalizerOptions controls pagination defaults when requests omit values.

type Optimizer

type Optimizer struct{}

...existing code... Optimizer coordinates plan generation.

func New

func New() *Optimizer

New constructs a new Optimizer instance.

func (*Optimizer) GeneratePlan

func (o *Optimizer) GeneratePlan(ctx context.Context, in *Input) (*Plan, error)

GeneratePlan builds the SQL plan for the provided input.

type Pagination

type Pagination struct {
	Limit  int
	Offset int
}

Pagination captures validated limit/offset.

type PatternKind

type PatternKind string

PatternKind describes LIKE pattern semantics for text predicates.

const (
	PatternKindNone     PatternKind = ""
	PatternKindPrefix   PatternKind = "prefix"
	PatternKindContains PatternKind = "contains"
)

type Plan

type Plan struct {
	SQL      string
	Params   []any
	Explain  PlanExplain
	Metadata any // placeholder for future metadata payloads
}

Plan represents the executable statement plus diagnostics.

type PlanExplain

type PlanExplain struct {
	Driver       string
	MainFilters  []string
	EAVFilters   []string
	SortStrategy string
}

PlanExplain stores human-readable diagnostics for logging.

type Predicate

type Predicate struct {
	AttributeName string
	AttributeID   int16
	ValueType     forma.ValueType
	Operator      PredicateOp
	Value         any
	Storage       StorageTarget
	Column        *ColumnRef
	Pattern       PatternKind
	Fallback      AttributeFallbackKind
	InsideArray   bool
}

Predicate describes a normalized filter expression.

type PredicateOp

type PredicateOp string

PredicateOp enumerates normalized predicate operators.

const (
	PredicateOpEquals      PredicateOp = "="
	PredicateOpNotEquals   PredicateOp = "!="
	PredicateOpGreaterThan PredicateOp = ">"
	PredicateOpGreaterEq   PredicateOp = ">="
	PredicateOpLessThan    PredicateOp = "<"
	PredicateOpLessEq      PredicateOp = "<="
	PredicateOpLike        PredicateOp = "LIKE"
)

Supported predicate operators.

type SortDirection

type SortDirection string

SortDirection enumerates normalized sort orderings.

const (
	SortAsc  SortDirection = "ASC"
	SortDesc SortDirection = "DESC"
)

type SortKey

type SortKey struct {
	AttributeName string
	AttributeID   int16
	ValueType     forma.ValueType
	Direction     SortDirection
	Storage       StorageTarget
	Column        *ColumnRef
	Fallback      AttributeFallbackKind
}

SortKey represents a normalized ordering requirement.

type StorageTables

type StorageTables struct {
	EntityMain string
	EAVData    string
}

StorageTables captures the physical table names passed in from calling layers.

type StorageTarget

type StorageTarget int

StorageTarget indicates whether the attribute lives in the main table or EAV.

const (
	StorageTargetUnknown StorageTarget = iota
	StorageTargetMain
	StorageTargetEAV
)

Jump to

Keyboard shortcuts

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