Documentation
¶
Overview ¶
Package ql bridges native measure execution into QL batch consumers.
Index ¶
- Variables
- func ExecutionClockCalls() uint64
- func ExecutionNow() time.Time
- func MergeNativeAggregate(ctx context.Context, plan *NativeAggregatePlan, open NativeAggregateSource) (_ vectorized.PullOperator, err error)
- func RawIterator(ctx context.Context, source vectorized.PullOperator) (executor.MIterator, error)
- func RetainBatchView(ctx context.Context, batch *vectorized.RecordBatch, indices []int) (*vectorized.RecordBatch, error)
- func SetExecutionClockForTest(func() time.Time) func()
- func SetSortExecutionHookForTest(func(context.Context, SortStats) error) func()
- func ValidateDistinct(plan *RawPlan) error
- func WithFullSort(ctx context.Context) context.Context
- func WrapAggregate(ctx context.Context, source vectorized.PullOperator, plan *AggregatePlan) (_ vectorized.PullOperator, err error)
- func WrapExpressions(ctx context.Context, source vectorized.PullOperator, plan *ExpressionPlan) (_ vectorized.PullOperator, err error)
- func WrapFilter(ctx context.Context, source vectorized.PullOperator, predicate *Expression) (_ vectorized.PullOperator, err error)
- func WrapRaw(ctx context.Context, source vectorized.PullOperator, plan *RawPlan) (vectorized.PullOperator, error)
- func WrapSort(ctx context.Context, source vectorized.PullOperator, plan *SortPlan) (_ vectorized.PullOperator, err error)
- type AggregateCall
- type AggregateExecutionCounters
- type AggregateFunction
- type AggregateOutput
- type AggregatePlan
- type AggregateStats
- type DistinctExecutionCounters
- type Expression
- type ExpressionOutput
- type ExpressionPlan
- type ExpressionScalar
- type ExpressionStats
- type ExpressionType
- type FilterStats
- type HavingPlan
- type MillisRange
- type NativeAggregateExecutionCounters
- type NativeAggregateLeaf
- type NativeAggregatePlan
- type NativeAggregateSource
- type NativeAggregateStats
- type NativeScan
- type RawExecutionCounters
- type RawPlan
- type Slot
- type SlotID
- type SortExecutionCounters
- type SortKey
- type SortPlan
- type SortStats
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidExpression = errors.New("invalid QL expression")
ErrInvalidExpression identifies an invalid expression or an expression value error.
Functions ¶
func ExecutionClockCalls ¶
func ExecutionClockCalls() uint64
ExecutionClockCalls is unavailable outside instrumented test builds.
func ExecutionNow ¶
ExecutionNow captures the clock used by one QL execution.
func MergeNativeAggregate ¶
func MergeNativeAggregate(ctx context.Context, plan *NativeAggregatePlan, open NativeAggregateSource) (_ vectorized.PullOperator, err error)
MergeNativeAggregate executes leaves sequentially and owns each opened source. All leaves finish before any final SQL group is emitted.
func RawIterator ¶
func RawIterator(ctx context.Context, source vectorized.PullOperator) (executor.MIterator, error)
RawIterator materializes the existing measure response only at final egress. It initializes source and takes its Close ownership; native pagination is not reapplied.
func RetainBatchView ¶
func RetainBatchView(ctx context.Context, batch *vectorized.RecordBatch, indices []int) (*vectorized.RecordBatch, error)
RetainBatchView snapshots selected columns for use after the source advances or closes. Repeated indices share one immutable copied column. ReleaseOwners releases the view's budget. NativeScan otherwise lends batches only until the next pull or Close.
func SetExecutionClockForTest ¶
SetExecutionClockForTest requires an instrumented test build.
func SetSortExecutionHookForTest ¶
SetSortExecutionHookForTest requires an instrumented test build.
func ValidateDistinct ¶
ValidateDistinct rejects unsupported visible key types before execution.
func WithFullSort ¶
WithFullSort leaves production execution unchanged.
func WrapAggregate ¶
func WrapAggregate(ctx context.Context, source vectorized.PullOperator, plan *AggregatePlan) (_ vectorized.PullOperator, err error)
WrapAggregate takes source ownership, including on construction failure. It consumes every active input row before emitting synthesized groups, without native identity metadata.
func WrapExpressions ¶
func WrapExpressions(ctx context.Context, source vectorized.PullOperator, plan *ExpressionPlan) (_ vectorized.PullOperator, err error)
WrapExpressions owns source on every return path and lends projected batches until the next pull.
func WrapFilter ¶
func WrapFilter(ctx context.Context, source vectorized.PullOperator, predicate *Expression) (_ vectorized.PullOperator, err error)
WrapFilter owns source on every return path and lends its columns with a narrowed physical selection. Only TRUE passes; FALSE and NULL do not pass.
func WrapRaw ¶
func WrapRaw(ctx context.Context, source vectorized.PullOperator, plan *RawPlan) (vectorized.PullOperator, error)
WrapRaw takes ownership of source, including on failure, and resolves projection indices once. Its output lends immutable source columns until the next pull or Close.
func WrapSort ¶
func WrapSort(ctx context.Context, source vectorized.PullOperator, plan *SortPlan) (_ vectorized.PullOperator, err error)
WrapSort takes ownership of source on every return path and resolves typed keys once. Returned batches borrow only the operator's owned candidates until the next pull or Close.
Types ¶
type AggregateCall ¶
type AggregateCall struct {
Source vectorized.ColumnDef
Function AggregateFunction
Decimal bool
DecimalScale uint8
}
AggregateCall describes one aggregate input independently of output aliases.
type AggregateExecutionCounters ¶
type AggregateExecutionCounters struct {
Executions uint64
InputRows uint64
Groups uint64
GroupCapacity uint64
KeyBytes uint64
KeyCapacity uint64
StateBytes uint64
StateCapacity uint64
StateLanes uint64
ReservedBytes uint64
ReleasedBytes uint64
LiveBytes int64
}
AggregateExecutionCounters records cumulative local aggregate work and retained capacity at successful scan completion. Capacity deltas divided by Executions describe each execution; memory counters cover all lifecycle paths. Production builds return zero counters.
func AggregateExecutionStats ¶
func AggregateExecutionStats() AggregateExecutionCounters
AggregateExecutionStats returns zero counters in production builds.
type AggregateFunction ¶
type AggregateFunction uint8
AggregateFunction identifies an aggregate over one named scalar column.
const ( AggregateCount AggregateFunction = iota AggregateSum AggregateMin AggregateMax AggregateAvg AggregateCountDistinct )
Aggregate functions use SQL non-null counting and empty-input semantics.
type AggregateOutput ¶
type AggregateOutput struct {
Column vectorized.ColumnDef
Index int
IsGroup bool
Timestamp bool // Timestamp requests timestamp-tag encoding at final egress.
}
AggregateOutput names one selected grouping key or aggregate call.
type AggregatePlan ¶
type AggregatePlan struct {
GroupExpressions *ExpressionPlan
TimeBucketWidth string // Resolved existing native width; empty means no bucket.
GroupBy []vectorized.ColumnDef
Calls []AggregateCall
Outputs []AggregateOutput
TimeBucketIndex int // GroupBy index of the bucket key when TimeBucketWidth is nonempty.
}
AggregatePlan is an immutable recipe for complete local aggregation.
type AggregateStats ¶
type AggregateStats struct {
InputRows uint64
Groups uint64
GroupCapacity uint64
KeyBytes uint64
KeyCapacity uint64
StateBytes uint64 // Used fixed-width state bytes for actual groups.
StateCapacity uint64 // Reserved fixed-width state capacity in bytes.
StateLanes uint64
DistinctKeys uint64 // Retained (group, value) pairs across distinct states.
DistinctKeyBytes uint64 // Used encoded distinct key bytes.
DistinctKeyCapacity uint64 // Reserved distinct indexes, key arenas and scratch bytes.
}
AggregateStats separates retained group keys and fixed-width state from native input residency.
func AggregateStatistics ¶
func AggregateStatistics(source vectorized.PullOperator) (AggregateStats, bool)
AggregateStatistics returns the structural state of a local aggregate, including after Close.
func DistinctStatistics ¶
func DistinctStatistics(source vectorized.PullOperator) (AggregateStats, bool)
DistinctStatistics returns visible-tuple grouping state independently of aggregation.
type DistinctExecutionCounters ¶
type DistinctExecutionCounters struct {
Executions uint64
InputRows uint64
Groups uint64
GroupCapacity uint64
KeyBytes uint64
KeyCapacity uint64
StateBytes uint64
StateCapacity uint64
StateLanes uint64
ReservedBytes uint64
ReleasedBytes uint64
LiveBytes int64
}
DistinctExecutionCounters records cumulative visible-tuple deduplication work and retained capacity at successful scan completion. Capacity deltas divided by Executions describe each execution; memory counters cover all lifecycle paths. Production builds return zero counters.
func DistinctExecutionStats ¶
func DistinctExecutionStats() DistinctExecutionCounters
DistinctExecutionStats returns zero counters in production builds.
type Expression ¶
type Expression struct {
Op string
Args []*Expression
Source vectorized.ColumnDef
Literal ExpressionScalar
Type ExpressionType
Scale uint8
}
Expression is an immutable, schema-resolved expression recipe. Op is literal, column, cast, case, simple_case, coalesce, +, -, *, /, %, negate, positive, =, !=, <, <=, >, >=, and, or, not, is_null, is_not_null, in, not_in, contains or not_contains. Cast Type names the target. CASE arguments are condition/value pairs followed by ELSE; simple_case prepends the comparison value. IN and NOT IN accept compact literal STRING arrays in RHS arguments; their elements are membership values, while the left operand remains scalar.
func ResolveExpression ¶
func ResolveExpression(expression *Expression) (*Expression, error)
ResolveExpression validates and deep-copies an expression, assigning every node a type. It never evaluates values: invalid casts in an unreachable branch remain unreachable.
func ResolvePredicate ¶
func ResolvePredicate(expression *Expression) (*Expression, error)
ResolvePredicate validates and deep-copies a boolean expression. Untyped NULL becomes BOOLEAN NULL without evaluating its value.
type ExpressionOutput ¶
type ExpressionOutput struct {
Expr *Expression
Column vectorized.ColumnDef
}
ExpressionOutput pairs an expression with its existing response column identity.
type ExpressionPlan ¶
type ExpressionPlan struct {
Outputs []ExpressionOutput
}
ExpressionPlan projects typed expressions while retaining native row metadata.
type ExpressionScalar ¶
type ExpressionScalar struct {
String string
Bytes []byte
Ints []int64
Strings []string
Decimal decimal.Int128
Int64 int64
Float64 float64
Bool bool
Null bool
}
ExpressionScalar holds one typed literal; Expression.Type selects its payload.
type ExpressionStats ¶
type ExpressionStats struct {
Executions uint64
Batches uint64
InputRows uint64
KeyEvaluations uint64 // Active rows requested by actual computed-key root invocations.
KeyRootCalls uint64 // Actual key-root calls, including cached scalar applications.
OutputRows uint64
VectorRows uint64
ScalarEvaluations uint64
ArmRows uint64
LaterArmRows uint64
BufferBytes uint64
FullColumnAllocations uint64
ReservedBytes uint64
ReleasedBytes uint64
LiveBytes int64
}
ExpressionStats counts typed expression work and allocations. InputRows and OutputRows count active physical rows; VectorRows counts eligible rows per nonconstant kernel. ArmRows counts selected CASE values and eligible COALESCE arguments; LaterArmRows excludes each conditional's first value/argument. ScalarEvaluations counts non-leaf constant kernels evaluated once per operator. BufferBytes and FullColumnAllocations count allocated vector capacity, not variable payloads. Production process-wide counters are disabled; per-operator statistics remain available.
func ExpressionExecutionStats ¶
func ExpressionExecutionStats() ExpressionStats
ExpressionExecutionStats returns zero counters in production builds.
func ExpressionStatistics ¶
func ExpressionStatistics(operator vectorized.PullOperator) (ExpressionStats, bool)
ExpressionStatistics returns expression work and memory statistics for operator.
func GroupExpressionExecutionStats ¶
func GroupExpressionExecutionStats() ExpressionStats
GroupExpressionExecutionStats returns zero counters in production builds.
type ExpressionType ¶
type ExpressionType uint8
ExpressionType distinguishes SQL values without assigning new wire types.
const ( ExpressionNull ExpressionType = iota ExpressionInt ExpressionFloat ExpressionBool ExpressionString ExpressionBytes ExpressionTimestamp ExpressionIntArray ExpressionStringArray ExpressionDecimal )
Expression types include local booleans and nanosecond UTC timestamps.
type FilterStats ¶
type FilterStats struct {
Executions uint64
Batches uint64
InputRows uint64
OutputRows uint64
TrueRows uint64
FalseRows uint64
UnknownRows uint64
CopiedBytes uint64
SelectionBytes uint64
ReservedBytes uint64
ReleasedBytes uint64
LiveBytes int64
}
FilterStats counts examined active rows, their SQL truth values, and filter memory. CopiedBytes is structurally zero because filter output borrows the input column objects. Unit tests and kernel benchmark identity checks verify that invariant; it is not independently measured copy telemetry. It excludes charged typed decoding scratch at the protobuf input boundary. SelectionBytes counts allocated selection capacity. Reservations include compiled expression state and scratch. Process-wide counters are disabled in production builds.
func FilterExecutionStats ¶
func FilterExecutionStats() FilterStats
FilterExecutionStats returns zero counters in production builds.
func FilterStatistics ¶
func FilterStatistics(operator vectorized.PullOperator) (FilterStats, bool)
FilterStatistics returns filter work and memory statistics for operator.
func HavingExecutionStats ¶
func HavingExecutionStats() FilterStats
HavingExecutionStats returns zero counters in production builds.
func HavingStatistics ¶
func HavingStatistics(operator vectorized.PullOperator) (FilterStats, bool)
HavingStatistics returns completed-group filter statistics, including after Close.
type HavingPlan ¶
type HavingPlan struct {
Predicate *Expression
Outputs []Slot
}
HavingPlan filters completed aggregate groups and then projects visible slots. Outputs must explicitly select the visible result; nil is rejected, while an empty non-nil slice selects no visible values.
type MillisRange ¶
type MillisRange struct{ Begin, End int64 }
MillisRange is a half-open timestamp interval in Unix milliseconds.
type NativeAggregateExecutionCounters ¶
type NativeAggregateExecutionCounters struct {
Executions uint64
Branches uint64
InputRows uint64
Groups uint64
GroupCapacity uint64
KeyBytes uint64
KeyCapacity uint64
StateBytes uint64
StateCapacity uint64
StateLanes uint64
MergeVisits uint64
ReservedBytes uint64
ReleasedBytes uint64
LiveBytes int64
}
NativeAggregateExecutionCounters records successful keyed merge executions. Memory counters cover successful and failed lifecycles; production builds return zero.
func NativeAggregateExecutionStats ¶
func NativeAggregateExecutionStats() NativeAggregateExecutionCounters
NativeAggregateExecutionStats returns zero when query instrumentation is disabled.
type NativeAggregateLeaf ¶
type NativeAggregateLeaf struct {
Request *measurev1.QueryRequest
Source vectorized.ColumnDef
Function AggregateFunction
}
NativeAggregateLeaf is one finalized native aggregate over an original source column.
type NativeAggregatePlan ¶
type NativeAggregatePlan struct {
Aggregate *AggregatePlan
Leaves []NativeAggregateLeaf
MaxCount int64
MaxGroups uint64 // Zero permits every group that fits in the memory budget.
}
NativeAggregatePlan combines native leaves using the complete grouping tuple. MaxCount is a planner-proven upper bound on non-null values in each group.
type NativeAggregateSource ¶
type NativeAggregateSource func(context.Context, NativeAggregateLeaf) (vectorized.PullOperator, error)
NativeAggregateSource opens one native leaf using the query's shared memory tracker.
type NativeAggregateStats ¶
type NativeAggregateStats struct {
Branches uint64
InputRows uint64
Groups uint64
GroupCapacity uint64
KeyBytes uint64
KeyCapacity uint64
StateBytes uint64 // Includes two bytes of branch-presence flags per source/group.
StateCapacity uint64
StateLanes uint64 // Fixed-width eight-byte lanes, excluding presence flags.
MergeVisits uint64
}
NativeAggregateStats describes keyed merge work and retained capacity.
func NativeAggregateStatistics ¶
func NativeAggregateStatistics(source vectorized.PullOperator) (NativeAggregateStats, bool)
NativeAggregateStatistics reports keyed merge work, including after Close.
type NativeScan ¶
type NativeScan struct {
// contains filtered or unexported fields
}
NativeScan consumes native batches without constructing intermediate protobuf rows. The source owns the schema and lends each batch until the next pull or Close; NativeScan forwards that ownership contract and transfers cleanup to the final egress pipeline.
func NewNativeScan ¶
func NewNativeScan(source vectorized.PullOperator) *NativeScan
NewNativeScan takes ownership of source.
func (*NativeScan) Close ¶
func (s *NativeScan) Close() error
Close releases the native source and its reservations.
func (*NativeScan) Init ¶
func (s *NativeScan) Init(ctx context.Context) error
Init initializes the native source.
func (*NativeScan) NextBatch ¶
func (s *NativeScan) NextBatch(ctx context.Context) (*vectorized.RecordBatch, error)
NextBatch consumes the next native batch and observes caller cancellation.
func (*NativeScan) OutputSchema ¶
func (s *NativeScan) OutputSchema() *vectorized.BatchSchema
OutputSchema preserves native output descriptors, including hidden columns.
type RawExecutionCounters ¶
type RawExecutionCounters struct {
ProjectionCalls uint64
FilterInputRows uint64
FilterOutputRows uint64
LimitInputRows uint64
LimitOutputRows uint64
ProjectionCopiedValueBytes uint64
}
RawExecutionCounters records activation and row counts of QL raw operators. Production builds return zero counters; querymetrics builds enable observation.
func RawExecutionStats ¶
func RawExecutionStats() RawExecutionCounters
RawExecutionStats returns zero counters in production builds.
type RawPlan ¶
type RawPlan struct {
NativeAggregate *NativeAggregatePlan
Aggregate *AggregatePlan
Expressions *ExpressionPlan
Filter *Expression
Having *HavingPlan
Sort *SortPlan
Limit *uint32
Slots []Slot
Ranges []MillisRange
Patterns []model.IndexedPattern
Offset uint32
Residual bool
Distinct bool
Ordered bool // Ordered records an explicit ORDER BY requiring complete DISTINCT input.
Empty bool
}
RawPlan is the immutable bound recipe for a complete native measure scan and QL operators.
func (*RawPlan) CanScanSeries ¶
CanScanSeries reports whether a bound QL plan preserves its result when the native source visits complete series instead of merging all timestamps. It proves only counts with nonfallible expressions and a complete final group ordering. Other aggregate functions and unproven shapes retain their ordering.
type Slot ¶
type Slot struct {
Source vectorized.ColumnDef
Output vectorized.ColumnDef
ID SlotID
Nullable bool
Timestamp bool // Timestamp marks an int64 nanosecond value for final timestamp-tag encoding.
}
Slot describes the source and visible response identity of a typed projection.
type SortExecutionCounters ¶
type SortExecutionCounters = SortStats
SortExecutionCounters contains cumulative process work and completion snapshots. Capacity and peak fields sum successful pre-pagination completion snapshots; divide deltas by Executions to describe each execution. LiveBytes is a gauge. Production process-wide counters are disabled.
func SortExecutionStats ¶
func SortExecutionStats() SortExecutionCounters
SortExecutionStats returns zero counters in production builds.
type SortKey ¶
type SortKey struct {
Expr *Expression
Descending bool
NullsFirst bool
}
SortKey defines one typed ordering expression and its resolved null placement. Callers resolve SQL defaults to NullsFirst=false for ASC and true for DESC.
type SortPlan ¶
SortPlan orders completed rows, selects visible outputs, and then paginates. Outputs must be explicit; an empty non-nil slice selects only row metadata. FullSort selects the reference full-sort path even when Limit is finite.
type SortStats ¶
type SortStats struct {
Executions uint64
Batches uint64
InputRows uint64
OutputRows uint64
KeyEvaluations uint64
KeyRootCalls uint64
KeyKernelRows uint64
KeyScalarEvaluations uint64
Comparisons uint64
AcceptedRows uint64
EvictedRows uint64
Candidates uint64
PeakCandidates uint64
CandidateCapacity uint64
PayloadBytes uint64
PayloadCapacity uint64
PeakPayloadBytes uint64
DescriptorBytes uint64
PeakBytes uint64
ReservedBytes uint64
ReleasedBytes uint64
SourcePins uint64
K uint64
LiveBytes int64
FullSort bool
}
SortStats reports actual ordering work, candidate capacity and memory ownership. KeyKernelRows counts eligible rows in nonconstant non-leaf expression kernels. PayloadBytes excludes descriptors; PayloadCapacity reserves twice its size for allocation slack. SourcePins counts retained source owners and stays zero for copied candidates. PeakBytes includes key kernels and the output buffer.
func SortStatistics ¶
func SortStatistics(operator vectorized.PullOperator) (SortStats, bool)
SortStatistics returns ordering statistics through the public operator chain.
Source Files
¶
- aggregate.go
- aggregate_group.go
- aggregate_merge.go
- aggregate_merge_group.go
- aggregate_merge_input.go
- aggregate_merge_metrics.go
- aggregate_merge_metrics_disabled.go
- aggregate_merge_output.go
- aggregate_metrics.go
- aggregate_metrics_disabled.go
- aggregate_output.go
- aggregate_query.go
- aggregate_state.go
- aggregate_value.go
- batch_view.go
- distinct_metrics.go
- distinct_metrics_disabled.go
- distinct_query.go
- execution_clock_disabled.go
- expression.go
- expression_arithmetic.go
- expression_boolean.go
- expression_cast.go
- expression_conditional.go
- expression_contains.go
- expression_input.go
- expression_membership.go
- expression_metrics.go
- expression_metrics_disabled.go
- expression_operator.go
- expression_resolve.go
- expression_time_bucket.go
- filter.go
- filter_metrics.go
- filter_metrics_disabled.go
- filter_query.go
- group_arena.go
- group_expression.go
- group_expression_metrics_disabled.go
- group_metrics.go
- having_metrics.go
- having_query.go
- native_scan.go
- operator_source.go
- projection_query.go
- raw.go
- raw_egress.go
- raw_metrics.go
- raw_metrics_disabled.go
- scan_order.go
- sort.go
- sort_metrics.go
- sort_metrics_disabled.go
- sort_query.go
- sort_value.go