Documentation ¶
Overview ¶
Package pir manages the low-level query plan intermediate representation. This is where most of the query plan construction and optimization happens.
Index ¶
- Constants
- type Aggregate
- type Bind
- type CompileError
- type Distinct
- type DummyOutput
- type Env
- type EquiJoin
- type Filter
- type Index
- type IterTable
- type IterValue
- type Limit
- type NoOutput
- type Order
- type OutputIndex
- type OutputPart
- type SizeClass
- type Step
- type Trace
- func (b *Trace) Aggregate(agg vm.Aggregation, groups []expr.Binding) error
- func (b *Trace) Begin(f *expr.Table, e Env) error
- func (b *Trace) Bind(bindings ...[]expr.Binding) error
- func (b *Trace) BindStar() error
- func (b *Trace) Class() SizeClass
- func (b *Trace) Describe(dst io.Writer)
- func (b *Trace) Distinct(exprs []expr.Node) error
- func (b *Trace) DistinctFromBindings(bind []expr.Binding) error
- func (b *Trace) Equals(x *Trace) bool
- func (b *Trace) Final() Step
- func (b *Trace) FinalBindings() []expr.Binding
- func (b *Trace) FinalTypes() []expr.TypeSet
- func (b *Trace) Into(table expr.Node, basepath string)
- func (b *Trace) Iterate(bind *expr.Binding) error
- func (b *Trace) LimitOffset(limit, offset int64) error
- func (b *Trace) Order(cols []expr.Order) error
- func (b *Trace) Rewrite(rw expr.Rewriter)
- func (b *Trace) String() string
- func (b *Trace) Where(e expr.Node) error
- type UnionMap
- type Unpivot
- type UnpivotAtDistinct
Constants ¶
const LargeSize = 10000
LargeSize is the point at which an exact cardinality is considered to be "large" rather than "small"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregate ¶
type Aggregate struct { Agg vm.Aggregation // GroupBy is nil for normal // aggregations, or non-nil // when the aggregation is formed // on multiple columns // // note that the groups form part // of the binding set GroupBy []expr.Binding // NonEmpty, if true, indicates that no results // should be produced when zero rows reach this op NonEmpty bool // contains filtered or unexported fields }
Aggregate is an aggregation operation that produces a new set of bindings
type Bind ¶
type Bind struct {
// contains filtered or unexported fields
}
Bind is a collection of transformations that produce a set of output bindings from the current binding environment
type CompileError ¶
CompileError is an error associated with compiling a particular expression.
type Env ¶
type Env interface { // Schema returns type hints associated // with a particular table expression. // In the event that there is no available // type information, Schema may return nil. Schema(expr.Node) expr.Hint // Index returns the index for the given table // expression. This may return (nil, nil) if // the index for the table is not available. Index(expr.Node) (Index, error) }
Env can be provided in calls to Build to provide additional context for plan optimization purposes.
type Index ¶
type Index interface { // TimeRange returns the inclusive time range // for the given path expression across the // given table. TimeRange(path []string) (min, max date.Time, ok bool) // HasPartition returns true if the index // can be partitioned on the provided field, // or false otherwise. HasPartition(field string) bool }
type IterTable ¶
type IterTable struct { Table *expr.Table Schema expr.Hint Index Index Partitioned bool // OnEqual, if present, indicates that this table // is only iterated for partitions that match // // OnEqual[i] = PARTITION_VALUE(i) // OnEqual []string // contains filtered or unexported fields }
type OutputIndex ¶
type OutputIndex struct { Table expr.Node Basename string // contains filtered or unexported fields }
OutputIndex is a step that takes the "part" field of incoming rows and constructs an index out of them, returning a single row like
{"table": "db.table-XXXXXX"}
type OutputPart ¶
type OutputPart struct { Basename string // contains filtered or unexported fields }
OutputPart writes output rows into a single part and returns a row like
{"part": "path/to/packed-XXXXX.ion.zst"}
type SizeClass ¶
type SizeClass int
SizeClass is one of the output size classifications. See SizeZero, SizeOne, etc.
const ( // SizeZero is the SizeClass // for queries that produce // zero rows of output. SizeZero SizeClass = iota // SizeOne is the SizeClass // for queries that produce // exactly one row of output. SizeOne // SizeExactSmall is the SizeClass // for queries that have an exact // cardinality (due to the presence // of LIMIT, etc.) and the cardinality // is known to be "small" for some // definition of "small" ... SizeExactSmall // SizeColumnCardinality is the SizeClass // for queries that have inexact cardinality // but produce a small-ish number of output // rows due to the presence of a grouping operation. // (Our optimistic assumption is that the cardinality // of most columns in most datasets is lower than LargeSize.) SizeColumnCardinality // SizeExactLarge is the SizeClass // for queries that have an exact // cardinality that is "large." SizeExactLarge // SizeUnknown is the SizeClass // for queries that have unknown output size. SizeUnknown )
type Trace ¶
type Trace struct { // If this trace is not a root trace, // then Parent will be a trace that // has this trace as one of its inputs. Parent *Trace // Replacements are traces that produce // results that are necessary in order // to execute this trace. // The results of input traces // are available to this trace // through the SCALAR_REPLACEMENT(index) // and IN_REPLACEMENT(index) expressions. // The traces in Input may be executed // in any order. Replacements []*Trace // contains filtered or unexported fields }
Trace is a linear sequence of physical plan operators. Traces are arranged in a tree, where each Trace depends on the execution of zero or more children (see Inputs).
func Build ¶
Build walks the provided Query and lowers it into the optimized query IR. If the provided SchemaHint is non-nil, then it will be used to provide additional type information that can be used to type-check and optimize the query.
func Split ¶
Split splits a query plan into a mapping step and a reduction step. The argument to split is destructively edited to become the mapping step, and the returned step is the new reduction step. If the query can't be split (either because it is not profitable or not possible), the returned Builder is the same as the argument.
The mapping step of the query plan can be performed in parallel (on different machines, etc.), and the rows output by the mapping step can be unioned and then passed to the reduction step, which produces the final query results.
NOTE: Split destructively edits the Builder query provided to it, so the scope information yielded by b.Scope() will no longer be accurate. Also, Split will panic if it is called on a query that has already been split.
func (*Trace) Class ¶
Class returns the "size class" of the result of executing the trace. See SizeClass for the definition of each result size class.
func (*Trace) Describe ¶
Describe writes a plain-text representation of b to dst. The output of this representation is purely for diagnostic purposes; it cannot be deserialized back into a trace.
func (*Trace) Distinct ¶
Distinct takes a sets of bindings and produces only distinct sets of output tuples of the given variable bindings
func (*Trace) DistinctFromBindings ¶
func (*Trace) Equals ¶
Equals returns true if b and x would produce the same rows and thus can be substituted for one another.
func (*Trace) Final ¶
Final returns the final step of the query. The caller can use Input to walk the inputs to each step up to the first input step.
func (*Trace) FinalBindings ¶
FinalBindings returns the set of output bindings, or none if they could not be computed
func (*Trace) FinalTypes ¶
FinalTypes returns the computed ion type sets of the output bindings. Each element of the returned slice corresponds with the same index in the return value of Builder.FinalBindings
Note that the return value may be nil if the query does not produce a know (finite) result-set
func (*Trace) Into ¶
Into handles the INTO clause by pushing the appropriate OutputIndex and OutputPart nodes.
func (*Trace) LimitOffset ¶
LimitOffset pushes a limit operation to the stack
type UnionMap ¶
type UnionMap struct { // Inner is the table that needs // to be partitioned into the child // subquery. Inner *IterTable // Child is the sub-query that is // applied to the partitioned table. Child *Trace // PartitionBy is a list of fields // over which the unioning should be partitioned. // PartitionBy[i] corresponds to PARTITION_VALUE(i) // within each step within Child. PartitionBy []string // contains filtered or unexported fields }
UnionMap represents a terminal query Step that unions the results of parallel invocations of the Child subquery operation.
type Unpivot ¶
type Unpivot struct { Ast *expr.Unpivot // The AST node this node was constructed from // contains filtered or unexported fields }
Unpivot represents the UNPIVOT expr AS as AT at statement
type UnpivotAtDistinct ¶
type UnpivotAtDistinct struct { Ast *expr.Unpivot // The AST node this node was constructed from // contains filtered or unexported fields }
UnpivotAtDistinct represents the UNPIVOT expr AT x GROUP BY x statement