exec

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

This exec package is temporarily in the opt directory. Eventually, it will be moved to the sql directory, and we will move other execution-related packages into the sql/exec directory as well. Until then, it's better to keep it here so that developers are not confused as to why we have a top-level exec directory that doesn't actually contain the main body of execution code.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggInfo

type AggInfo struct {
	FuncName   string
	Distinct   bool
	ResultType *types.T
	ArgCols    []NodeColumnOrdinal

	// ConstArgs is the list of any constant arguments to the aggregate,
	// for instance, the separator in string_agg.
	ConstArgs []tree.Datum

	// Filter is the index of the column, if any, which should be used as the
	// FILTER condition for the aggregate. If there is no filter, Filter is -1.
	Filter NodeColumnOrdinal
}

AggInfo represents an aggregation (see ConstructGroupBy).

type ApplyJoinPlanRightSideFn

type ApplyJoinPlanRightSideFn func(ef Factory, leftRow tree.Datums) (Plan, error)

ApplyJoinPlanRightSideFn creates a plan for an iteration of ApplyJoin, given a row produced from the left side. The plan is guaranteed to produce the rightColumns passed to ConstructApplyJoin (in order).

type BuildPlanForExplainFn

type BuildPlanForExplainFn func(f Factory) (Plan, error)

BuildPlanForExplainFn builds an execution plan against the given base factory.

type Cascade

type Cascade struct {
	// FKName is the name of the foreign key constraint.
	FKName string

	// Buffer is the Node returned by ConstructBuffer which stores the input to
	// the mutation. It is nil if the cascade does not require a buffer.
	Buffer Node

	// PlanFn builds the cascade query and creates the plan for it.
	// Note that the generated Plan can in turn contain more cascades (as well as
	// checks, which should run after all cascades are executed).
	//
	// The bufferRef is a reference that can be used with ConstructWithBuffer to
	// read the mutation input. It is conceptually the same as the Buffer field;
	// however, we allow the execution engine to provide a different copy or
	// implementation of the node (e.g. to facilitate early cleanup of the
	// original plan).
	//
	// If the cascade does not require input buffering (Buffer is nil), then
	// bufferRef should be nil and numBufferedRows should be 0.
	//
	// This method does not mutate any captured state; it is ok to call PlanFn
	// methods concurrently (provided that they don't use a single non-thread-safe
	// execFactory).
	PlanFn func(
		ctx context.Context,
		semaCtx *tree.SemaContext,
		evalCtx *tree.EvalContext,
		execFactory Factory,
		bufferRef Node,
		numBufferedRows int,
		allowAutoCommit bool,
	) (Plan, error)
}

Cascade describes a cascading query. The query uses a node created by ConstructBuffer as an input; it should only be triggered if this buffer is not empty.

type CheckOrdinalSet

type CheckOrdinalSet = util.FastIntSet

CheckOrdinalSet contains the ordinal positions of a set of check constraints taken from the opt.Table.Check collection.

type EstimatedStats

type EstimatedStats struct {
	// TableStatsAvailable is true if all the tables involved by this operator
	// (directly or indirectly) had table statistics.
	TableStatsAvailable bool
	// RowCount is the estimated number of rows produced by the operator.
	RowCount float64
	// TableStatsRowCount is set only for scans; it is the estimated total number
	// of rows in the table we are scanning.
	TableStatsRowCount uint64
	// TableStatsCreatedAt is set only for scans; it is the time when the latest
	// table statistics were collected.
	TableStatsCreatedAt time.Time
	// Cost is the estimated cost of the operator. This cost includes the costs of
	// the child operators.
	Cost float64
	// LimitHint is the "soft limit" of the number of result rows that may be
	// required. See physical.Required for details.
	LimitHint float64
}

EstimatedStats contains estimated statistics about a given operator.

type ExecutionStats

type ExecutionStats struct {
	// RowCount is the number of rows produced by the operator.
	RowCount optional.Uint

	// VectorizedBatchCount is the number of vectorized batches produced by the
	// operator.
	VectorizedBatchCount optional.Uint

	KVTime           optional.Duration
	KVContentionTime optional.Duration
	KVBytesRead      optional.Uint
	KVRowsRead       optional.Uint

	StepCount         optional.Uint
	InternalStepCount optional.Uint
	SeekCount         optional.Uint
	InternalSeekCount optional.Uint

	MaxAllocatedMem  optional.Uint
	MaxAllocatedDisk optional.Uint

	// Nodes on which this operator was executed.
	Nodes []string

	// Regions on which this operator was executed.
	// Only being generated on EXPLAIN ANALYZE.
	Regions []string
}

ExecutionStats contain statistics about a given operator gathered from the execution of the query.

TODO(radu): can/should we just use execinfrapb.ComponentStats instead?

type ExplainAnnotationID

type ExplainAnnotationID int

ExplainAnnotationID identifies the type of a node annotation.

const (
	// EstimatedStatsID is an annotation with a *EstimatedStats value.
	EstimatedStatsID ExplainAnnotationID = iota

	// ExecutionStatsID is an annotation with a *ExecutionStats value.
	ExecutionStatsID
)

type ExplainEnvData

type ExplainEnvData struct {
	ShowEnv   bool
	Tables    []tree.TableName
	Sequences []tree.TableName
	Views     []tree.TableName
}

ExplainEnvData represents the data that's going to be displayed in EXPLAIN (env).

type ExplainFactory

type ExplainFactory interface {
	Factory

	// AnnotateNode annotates a constructed Node with extra information.
	AnnotateNode(n Node, id ExplainAnnotationID, value interface{})
}

ExplainFactory is an extension of Factory used when constructing a plan that can be explained. It allows annotation of nodes with extra information.

type Factory

type Factory interface {
	// ConstructPlan creates a plan enclosing the given plan and (optionally)
	// subqueries, cascades, and checks.
	//
	// Subqueries are executed before the root tree, which can refer to subquery
	// results using tree.Subquery nodes.
	//
	// Cascades are executed after the root tree. They can return more cascades
	// and checks which should also be executed.
	//
	// Checks are executed after all cascades have been executed. They don't
	// return results but can generate errors (e.g. foreign key check failures).
	//
	// RootRowCount is the number of rows returned by the root node, negative if
	// the stats weren't available to make a good estimate.
	ConstructPlan(
		root Node,
		subqueries []Subquery,
		cascades []Cascade,
		checks []Node,
		rootRowCount int64,
	) (Plan, error)

	// ConstructScan creates a node for a Scan operation.
	//
	// Scan runs a scan of a specified index of a table, possibly with an index
	// constraint and/or a hard limit.
	ConstructScan(
		table cat.Table,
		index cat.Index,
		params ScanParams,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructValues creates a node for a Values operation.
	ConstructValues(
		rows [][]tree.TypedExpr,
		columns colinfo.ResultColumns,
	) (Node, error)

	// ConstructFilter creates a node for a Filter operation.
	//
	// Filter applies a filter on the results of the given input node.
	ConstructFilter(
		input Node,
		filter tree.TypedExpr,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructInvertedFilter creates a node for a InvertedFilter operation.
	//
	// InvertedFilter applies a span expression on the results of the given input
	// node.
	ConstructInvertedFilter(
		input Node,
		invFilter *inverted.SpanExpression,
		preFiltererExpr tree.TypedExpr,
		preFiltererType *types.T,
		invColumn NodeColumnOrdinal,
	) (Node, error)

	// ConstructSimpleProject creates a node for a SimpleProject operation.
	//
	// SimpleProject applies a "simple" projection on the results of the given input
	// node. A simple projection is one that does not involve new expressions; it's
	// just a reshuffling of columns. This is a more efficient version of
	// ConstructRender.  The colNames argument is optional; if it is nil, the names
	// of the corresponding input columns are kept.
	ConstructSimpleProject(
		input Node,
		cols []NodeColumnOrdinal,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructSerializingProject creates a node for a SerializingProject operation.
	//
	// SerializingProject is similar to SimpleProject, but it allows renaming of
	// columns and forces distributed execution to serialize (merge) any parallel
	// result streams into a single stream before the projection. This allows any
	// required output ordering of the input node to be "materialized", which is
	// important for cases where the projection no longer contains the ordering
	// columns (e.g. SELECT a FROM t ORDER BY b).
	//
	// Typically used as the "root" (top-level) operator to ensure the correct
	// ordering and naming of columns.
	ConstructSerializingProject(
		input Node,
		cols []NodeColumnOrdinal,
		colNames []string,
	) (Node, error)

	// ConstructRender creates a node for a Render operation.
	//
	// Render applies a projection on the results of the given input node. The
	// projection can contain new expressions. The input expression slice will be
	// modified.
	ConstructRender(
		input Node,
		columns colinfo.ResultColumns,
		exprs tree.TypedExprs,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructApplyJoin creates a node for a ApplyJoin operation.
	//
	// ApplyJoin runs an apply join between an input node (the left side of the join)
	// and a RelExpr that has outer columns (the right side of the join) by replacing
	// the outer columns of the right side RelExpr with data from each row of the
	// left side of the join according to the data in leftBoundColMap. The apply join
	// can be any kind of join except for right outer and full outer.
	//
	// To plan the right-hand side, planRightSideFn must be called for each left
	// row. This function generates a plan (using the same factory) that produces
	// the rightColumns (in order).
	//
	// onCond is the join condition.
	ConstructApplyJoin(
		joinType descpb.JoinType,
		left Node,
		rightColumns colinfo.ResultColumns,
		onCond tree.TypedExpr,
		planRightSideFn ApplyJoinPlanRightSideFn,
	) (Node, error)

	// ConstructHashJoin creates a node for a HashJoin operation.
	//
	// HashJoin runs a hash-join between the results of two input nodes.
	//
	// The leftEqColsAreKey/rightEqColsAreKey flags, if set, indicate that the
	// equality columns form a key in the left/right input.
	//
	// The extraOnCond expression can refer to columns from both inputs using
	// IndexedVars (first the left columns, then the right columns).
	ConstructHashJoin(
		joinType descpb.JoinType,
		left Node,
		right Node,
		leftEqCols []NodeColumnOrdinal,
		rightEqCols []NodeColumnOrdinal,
		leftEqColsAreKey bool,
		rightEqColsAreKey bool,
		extraOnCond tree.TypedExpr,
	) (Node, error)

	// ConstructMergeJoin creates a node for a MergeJoin operation.
	//
	// The ON expression can refer to columns from both inputs using IndexedVars
	// (first the left columns, then the right columns). In addition, the i-th
	// column in leftOrdering is constrained to equal the i-th column in
	// rightOrdering. The directions must match between the two orderings.
	ConstructMergeJoin(
		joinType descpb.JoinType,
		left Node,
		right Node,
		onCond tree.TypedExpr,
		leftOrdering colinfo.ColumnOrdering,
		rightOrdering colinfo.ColumnOrdering,
		reqOrdering OutputOrdering,
		leftEqColsAreKey bool,
		rightEqColsAreKey bool,
	) (Node, error)

	// ConstructGroupBy creates a node for a GroupBy operation.
	//
	// GroupBy runs an aggregation. A set of aggregations is performed for each group
	// of values on the groupCols.
	// A row is produced for each set of distinct values on the group columns. The
	// row contains the values of the grouping columns, followed by one value for
	// each aggregation.
	ConstructGroupBy(
		input Node,
		groupCols []NodeColumnOrdinal,

		groupColOrdering colinfo.ColumnOrdering,
		aggregations []AggInfo,

		reqOrdering OutputOrdering,

		groupingOrderType GroupingOrderType,
	) (Node, error)

	// ConstructScalarGroupBy creates a node for a ScalarGroupBy operation.
	//
	// ScalarGroupBy runs a scalar aggregation, i.e.  one which performs a set of
	// aggregations on all the input rows (as a single group) and has exactly one
	// result row (even when there are no input rows). The output row has one value
	// for each aggregation.
	ConstructScalarGroupBy(
		input Node,
		aggregations []AggInfo,
	) (Node, error)

	// ConstructDistinct creates a node for a Distinct operation.
	//
	// Distinct filters out rows such that only the first row is kept for each set of
	// values along the distinct columns. The orderedCols are a subset of
	// distinctCols; the input is required to be ordered along these columns (i.e.
	// all rows with the same values on these columns are a contiguous part of the
	// input). reqOrdering specifies the required output ordering, and if not empty,
	// the input is already ordered according to it.
	ConstructDistinct(
		input Node,
		distinctCols NodeColumnOrdinalSet,
		orderedCols NodeColumnOrdinalSet,
		reqOrdering OutputOrdering,
		nullsAreDistinct bool,
		errorOnDup string,
	) (Node, error)

	// ConstructHashSetOp creates a node for a HashSetOp operation.
	//
	// HashSetOp performs a UNION / INTERSECT / EXCEPT operation (either the ALL or
	// the DISTINCT version). The left and right nodes must have the same number of
	// columns. Note that UNION ALL is special and is implemented by UnionAll.
	//
	// HashSetOp uses a hash table to execute the set operation, and therefore is not
	// guaranteed to maintain any ordering. StreamingSetOp should be used instead if
	// the set operation must maintain an ordering.
	ConstructHashSetOp(
		typ tree.UnionType,
		all bool,
		left Node,
		right Node,
	) (Node, error)

	// ConstructStreamingSetOp creates a node for a StreamingSetOp operation.
	//
	// StreamingSetOp performs a UNION / INTERSECT / EXCEPT operation (either the ALL
	// or the DISTINCT version). The left and right nodes must have the same number
	// of columns. Note that UNION ALL is special and is implemented by UnionAll.
	//
	// ReqOrdering specifies the required output ordering, and it is guaranteed to be
	// a prefix of StreamingOrdering. Both inputs are already ordered according to
	// StreamingOrdering. StreamingOrdering is guaranteed to include all columns
	// produced by this StreamingSetOp. The execution engine is then guaranteed to
	// use a merge join (or streaming DISTINCT for UNION), which is a streaming
	// operation that maintains ordering.
	//
	// HashSetOp should be used instead if both inputs are not ordered.
	ConstructStreamingSetOp(
		typ tree.UnionType,
		all bool,
		left Node,
		right Node,
		streamingOrdering colinfo.ColumnOrdering,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructUnionAll creates a node for a UnionAll operation.
	//
	// UnionAll performs a UNION ALL. The left and right nodes must have the same
	// number of columns.
	//
	// ReqOrdering specifies the required output ordering, and if not empty, both
	// inputs are already ordered according to it. If ReqOrdering is set, the
	// execution engine will use an ordered synchronizer to maintain ordering.
	//
	// If non-zero, HardLimit indicates that this UNION ALL represents a locality
	// optimized search. It instructs the execution engine that it should execute the
	// left node to completion and possibly short-circuit if the limit is reached
	// before executing the right node. The limit is guaranteed but the short-circuit
	// behavior is not.
	ConstructUnionAll(
		left Node,
		right Node,
		reqOrdering OutputOrdering,
		hardLimit uint64,
	) (Node, error)

	// ConstructSort creates a node for a Sort operation.
	//
	// Sort performs a resorting of the rows produced by the input node.
	//
	// When the input is partially sorted we can execute a "segmented" sort. In
	// this case alreadyOrderedPrefix is non-zero and the input is ordered by
	// ordering[:alreadyOrderedPrefix].
	ConstructSort(
		input Node,
		ordering OutputOrdering,
		alreadyOrderedPrefix int,
	) (Node, error)

	// ConstructOrdinality creates a node for a Ordinality operation.
	//
	// Ordinality appends an ordinality column to each row in the input node.
	ConstructOrdinality(
		input Node,
		colName string,
	) (Node, error)

	// ConstructIndexJoin creates a node for a IndexJoin operation.
	//
	// IndexJoin performs an index join. The input contains the primary key (on the
	// columns identified as keyCols).
	//
	// The index join produces the given table columns (in ordinal order).
	ConstructIndexJoin(
		input Node,
		table cat.Table,
		keyCols []NodeColumnOrdinal,
		tableCols TableColumnOrdinalSet,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructLookupJoin creates a node for a LookupJoin operation.
	//
	// LookupJoin performs a lookup join.
	//
	// The eqCols are columns from the input used as keys for the columns of the
	// index (or a prefix of them); eqColsAreKey is set to true if the eqCols form a
	// key in the table (and thus each input row matches with at most one index row);
	// lookupExpr is used instead of eqCols when the lookup condition is more
	// complicated than a simple equality between input columns and index columns
	// (eqColsAreKey will be true in this case if the columns that are part of the
	// simple equality join conditions form a key in the table); if remoteLookupExpr
	// is non-nil, this is a locality optimized lookup join. In this case, lookupExpr
	// contains the lookup join conditions targeting ranges located on local nodes
	// (relative to the gateway region), and remoteLookupExpr contains the lookup
	// join conditions targeting remote nodes; lookupCols are ordinals for the table
	// columns we are retrieving.
	//
	// The node produces the columns in the input and (unless join type is
	// LeftSemiJoin or LeftAntiJoin) the lookupCols, ordered by ordinal. The ON
	// condition can refer to these using IndexedVars.
	ConstructLookupJoin(
		joinType descpb.JoinType,
		input Node,
		table cat.Table,
		index cat.Index,
		eqCols []NodeColumnOrdinal,
		eqColsAreKey bool,
		lookupExpr tree.TypedExpr,
		remoteLookupExpr tree.TypedExpr,
		lookupCols TableColumnOrdinalSet,
		onCond tree.TypedExpr,
		isFirstJoinInPairedJoiner bool,
		isSecondJoinInPairedJoiner bool,
		reqOrdering OutputOrdering,
		locking *tree.LockingItem,
	) (Node, error)

	// ConstructInvertedJoin creates a node for a InvertedJoin operation.
	//
	// InvertedJoin performs a lookup join into an inverted index.
	//
	// invertedExpr is used to find the keys to look up in the index; prefixEqCols
	// are columns from the input used as keys for the non-inverted prefix columns,
	// if the index is a multi-column inverted index; lookupCols are ordinals for the
	// table columns we are retrieving.
	//
	// The node produces the columns in the input and (unless join type is
	// LeftSemiJoin or LeftAntiJoin) the lookupCols, ordered by ordinal. The ON
	// condition can refer to these using IndexedVars. Note that lookupCols
	// includes the inverted column.
	ConstructInvertedJoin(
		joinType descpb.JoinType,
		invertedExpr tree.TypedExpr,
		input Node,
		table cat.Table,
		index cat.Index,
		prefixEqCols []NodeColumnOrdinal,
		lookupCols TableColumnOrdinalSet,
		onCond tree.TypedExpr,
		isFirstJoinInPairedJoiner bool,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructZigzagJoin creates a node for a ZigzagJoin operation.
	//
	// ZigzagJoin performs a zigzag join.
	//
	// Each side of the join has two kinds of columns: fixed columns and equal
	// columns. The fixed columns correspond 1-to-1 to a prefix of the index columns.
	// The fixed columns and the equal columns together also form a prefix of the
	// index columns.
	ConstructZigzagJoin(

		leftTable cat.Table,
		leftIndex cat.Index,

		leftCols TableColumnOrdinalSet,

		leftFixedVals []tree.TypedExpr,

		leftEqCols []TableColumnOrdinal,

		rightTable cat.Table,
		rightIndex cat.Index,

		rightCols TableColumnOrdinalSet,

		rightFixedVals []tree.TypedExpr,

		rightEqCols []TableColumnOrdinal,

		onCond tree.TypedExpr,
		reqOrdering OutputOrdering,
	) (Node, error)

	// ConstructLimit creates a node for a Limit operation.
	//
	// Limit implements LIMIT and/or OFFSET on the results of the given node. If one
	// or the other is not needed, then it is set to nil.
	ConstructLimit(
		input Node,
		limit tree.TypedExpr,
		offset tree.TypedExpr,
	) (Node, error)

	// ConstructTopK creates a node for a TopK operation.
	//
	// TopK implements a TopK sorter that outputs the top K rows from the input
	// according to the ordering.
	ConstructTopK(
		input Node,
		k int64,
		ordering OutputOrdering,
		alreadyOrderedPrefix int,
	) (Node, error)

	// ConstructMax1Row creates a node for a Max1Row operation.
	//
	// Max1Row permits at most one row from the given input node, causing an error
	// with the given text at runtime if the node tries to return more than one row.
	ConstructMax1Row(
		input Node,
		errorText string,
	) (Node, error)

	// ConstructProjectSet creates a node for a ProjectSet operation.
	//
	// ProjectSet performs a lateral cross join between the output of the given node
	// and the functional zip of the given expressions.
	ConstructProjectSet(
		input Node,
		exprs tree.TypedExprs,
		zipCols colinfo.ResultColumns,
		numColsPerGen []int,
	) (Node, error)

	// ConstructWindow creates a node for a Window operation.
	//
	// Window executes a window function over the given node.
	ConstructWindow(
		input Node,
		window WindowInfo,
	) (Node, error)

	// ConstructExplainOpt creates a node for a ExplainOpt operation.
	//
	// Explain implements EXPLAIN (OPT), showing information about the given plan.
	ConstructExplainOpt(
		plan string,
		envOpts ExplainEnvData,
	) (Node, error)

	// ConstructExplain creates a node for a Explain operation.
	//
	// Explain implements EXPLAIN, showing information about the given plan.
	//
	// When the operator is created, it creates an ExplainFactory and calls BuildFn
	// to construct the plan against that factory.
	ConstructExplain(
		options *tree.ExplainOptions,
		stmtType tree.StatementReturnType,
		buildFn BuildPlanForExplainFn,
	) (Node, error)

	// ConstructShowTrace creates a node for a ShowTrace operation.
	//
	// ShowTrace implements a SHOW TRACE FOR SESSION statement.
	ConstructShowTrace(
		typ tree.ShowTraceType,
		compact bool,
	) (Node, error)

	// ConstructInsert creates a node for a Insert operation.
	//
	// Insert implements an INSERT statement (including ON CONFLICT DO NOTHING, but
	// not other ON CONFLICT clauses).
	//
	// The input columns are inserted into a subset of columns in the table, in the
	// same order they're defined. The insertCols set contains the ordinal positions
	// of columns in the table into which values are inserted. All columns are
	// expected to be present except delete-only mutation columns, since those do not
	// need to participate in an insert operation.
	ConstructInsert(
		input Node,
		table cat.Table,
		arbiterIndexes cat.IndexOrdinals,
		arbiterConstraints cat.UniqueOrdinals,
		insertCols TableColumnOrdinalSet,
		returnCols TableColumnOrdinalSet,
		checkCols CheckOrdinalSet,

		autoCommit bool,
	) (Node, error)

	// ConstructInsertFastPath creates a node for a InsertFastPath operation.
	//
	// InsertFastPath implements a special (but very common) case of insert,
	// satisfying the following conditions:
	//  - the input is Values with at most mutations.MaxBatchSize, and there are no
	//    subqueries;
	//  - there are no other mutations in the statement, and the output of the
	//    insert is not processed through side-effecting expressions.
	//  - there are no self-referencing foreign keys;
	//  - all FK checks can be performed using direct lookups into unique indexes.
	//
	// In this case, the foreign-key checks can run before (or even concurrently
	// with) the insert. If they are run before, the insert is allowed to
	// auto-commit.
	ConstructInsertFastPath(
		rows [][]tree.TypedExpr,
		table cat.Table,
		insertCols TableColumnOrdinalSet,
		returnCols TableColumnOrdinalSet,
		checkCols CheckOrdinalSet,
		fkChecks []InsertFastPathFKCheck,

		autoCommit bool,
	) (Node, error)

	// ConstructUpdate creates a node for a Update operation.
	//
	// Update implements an UPDATE statement. The input contains columns that were
	// fetched from the target table, and that provide existing values that can be
	// used to formulate the new encoded value that will be written back to the table
	// (updating any column in a family requires having the values of all other
	// columns). The input also contains computed columns that provide new values for
	// any updated columns.
	//
	// The fetchCols and updateCols sets contain the ordinal positions of the
	// fetch and update columns in the target table. The input must contain those
	// columns in the same order as they appear in the table schema, with the
	// fetch columns first and the update columns second.
	//
	// The passthrough parameter contains all the result columns that are part of
	// the input node that the update node needs to return (passing through from
	// the input). The pass through columns are used to return any column from the
	// FROM tables that are referenced in the RETURNING clause.
	//
	// If allowAutoCommit is set, the operator is allowed to commit the
	// transaction (if appropriate, i.e. if it is in an implicit transaction).
	// This is false if there are multiple mutations in a statement, or the output
	// of the mutation is processed through side-effecting expressions.
	ConstructUpdate(
		input Node,
		table cat.Table,
		fetchCols TableColumnOrdinalSet,
		updateCols TableColumnOrdinalSet,
		returnCols TableColumnOrdinalSet,
		checks CheckOrdinalSet,
		passthrough colinfo.ResultColumns,

		autoCommit bool,
	) (Node, error)

	// ConstructUpsert creates a node for a Upsert operation.
	//
	// Upsert implements an INSERT..ON CONFLICT DO UPDATE or UPSERT statement.
	//
	// For each input row, Upsert will test the canaryCol. If it is null, then it
	// will insert a new row. If not-null, then Upsert will update an existing row.
	// The input is expected to contain the columns to be inserted, followed by the
	// columns containing existing values, and finally the columns containing new
	// values.
	//
	// The length of each group of input columns can be up to the number of
	// columns in the given table. The insertCols, fetchCols, and updateCols sets
	// contain the ordinal positions of the table columns that are involved in
	// the Upsert. For example:
	//
	//   CREATE TABLE abc (a INT PRIMARY KEY, b INT, c INT)
	//   INSERT INTO abc VALUES (10, 20, 30) ON CONFLICT (a) DO UPDATE SET b=25
	//
	//   insertCols = {0, 1, 2}
	//   fetchCols  = {0, 1, 2}
	//   updateCols = {1}
	//
	// The input is expected to first have 3 columns that will be inserted into
	// columns {0, 1, 2} of the table. The next 3 columns contain the existing
	// values of columns {0, 1, 2} of the table. The last column contains the
	// new value for column {1} of the table.
	ConstructUpsert(
		input Node,
		table cat.Table,
		arbiterIndexes cat.IndexOrdinals,
		arbiterConstraints cat.UniqueOrdinals,
		canaryCol NodeColumnOrdinal,
		insertCols TableColumnOrdinalSet,
		fetchCols TableColumnOrdinalSet,
		updateCols TableColumnOrdinalSet,
		returnCols TableColumnOrdinalSet,
		checks CheckOrdinalSet,

		autoCommit bool,
	) (Node, error)

	// ConstructDelete creates a node for a Delete operation.
	//
	// Delete implements a DELETE statement. The input contains columns that were
	// fetched from the target table, and that will be deleted.
	//
	// The fetchCols set contains the ordinal positions of the fetch columns in
	// the target table. The input must contain those columns in the same order
	// as they appear in the table schema.
	ConstructDelete(
		input Node,
		table cat.Table,
		fetchCols TableColumnOrdinalSet,
		returnCols TableColumnOrdinalSet,

		autoCommit bool,
	) (Node, error)

	// ConstructDeleteRange creates a node for a DeleteRange operation.
	//
	// DeleteRange efficiently deletes contiguous rows stored in the given table's
	// primary index. This fast path is only possible when certain conditions hold
	// true:
	//  - there are no secondary indexes;
	//  - the input to the delete is a scan (without limits);
	//  - there are no inbound FKs to the table.
	//
	// See the comment for ConstructScan for descriptions of the needed and
	// indexConstraint parameters, since DeleteRange combines Delete + Scan into a
	// single operator.
	ConstructDeleteRange(
		table cat.Table,
		needed TableColumnOrdinalSet,
		indexConstraint *constraint.Constraint,

		autoCommit bool,
	) (Node, error)

	// ConstructCreateTable creates a node for a CreateTable operation.
	//
	// CreateTable implements a CREATE TABLE statement.
	ConstructCreateTable(
		schema cat.Schema,
		ct *tree.CreateTable,
	) (Node, error)

	// ConstructCreateTableAs creates a node for a CreateTableAs operation.
	//
	// CreateTableAs implements a CREATE TABLE AS statement.
	ConstructCreateTableAs(
		input Node,
		schema cat.Schema,
		ct *tree.CreateTable,
	) (Node, error)

	// ConstructCreateView creates a node for a CreateView operation.
	//
	// CreateView implements a CREATE VIEW statement.
	ConstructCreateView(
		schema cat.Schema,
		viewName *cat.DataSourceName,
		ifNotExists bool,
		replace bool,
		persistence tree.Persistence,
		materialized bool,
		viewQuery string,
		columns colinfo.ResultColumns,
		deps opt.ViewDeps,
		typeDeps opt.ViewTypeDeps,
	) (Node, error)

	// ConstructSequenceSelect creates a node for a SequenceSelect operation.
	//
	// SequenceSelect implements a scan of a sequence as a data source.
	ConstructSequenceSelect(
		sequence cat.Sequence,
	) (Node, error)

	// ConstructSaveTable creates a node for a SaveTable operation.
	//
	// SaveTable passes through all the input rows unchanged, but also creates a
	// table and inserts all the rows into it.
	ConstructSaveTable(
		input Node,
		table *cat.DataSourceName,
		colNames []string,
	) (Node, error)

	// ConstructErrorIfRows creates a node for a ErrorIfRows operation.
	//
	// ErrorIfRows returns no results, but causes an execution error if the input
	// returns any rows.
	ConstructErrorIfRows(
		input Node,

		mkErr MkErrFn,
	) (Node, error)

	// ConstructOpaque creates a node for a Opaque operation.
	//
	// Opaque implements operators that have no relational inputs and which require
	// no specific treatment by the optimizer.
	ConstructOpaque(
		metadata opt.OpaqueMetadata,
	) (Node, error)

	// ConstructAlterTableSplit creates a node for a AlterTableSplit operation.
	//
	// AlterTableSplit implements ALTER TABLE/INDEX SPLIT AT.
	ConstructAlterTableSplit(
		index cat.Index,
		input Node,
		expiration tree.TypedExpr,
	) (Node, error)

	// ConstructAlterTableUnsplit creates a node for a AlterTableUnsplit operation.
	//
	// AlterTableUnsplit implements ALTER TABLE/INDEX UNSPLIT AT.
	ConstructAlterTableUnsplit(
		index cat.Index,
		input Node,
	) (Node, error)

	// ConstructAlterTableUnsplitAll creates a node for a AlterTableUnsplitAll operation.
	//
	// AlterTableUnsplitAll implements ALTER TABLE/INDEX UNSPLIT ALL.
	ConstructAlterTableUnsplitAll(
		index cat.Index,
	) (Node, error)

	// ConstructAlterTableRelocate creates a node for a AlterTableRelocate operation.
	//
	// AlterTableRelocate implements ALTER TABLE/INDEX UNSPLIT AT.
	ConstructAlterTableRelocate(
		index cat.Index,
		input Node,
		subjectReplicas tree.RelocateSubject,
	) (Node, error)

	// ConstructBuffer creates a node for a Buffer operation.
	//
	// Buffer passes through the input rows but also saves them in a buffer, which
	// can be referenced from elsewhere in the query (using ScanBuffer).
	ConstructBuffer(
		input Node,
		label string,
	) (Node, error)

	// ConstructScanBuffer creates a node for a ScanBuffer operation.
	//
	// ScanBuffer refers to a node constructed by Buffer or passed to
	// RecursiveCTEIterationFn.
	ConstructScanBuffer(
		ref Node,
		label string,
	) (Node, error)

	// ConstructRecursiveCTE creates a node for a RecursiveCTE operation.
	//
	// RecursiveCTE executes a recursive CTE:
	//   * the initial plan is run first; the results are emitted and also saved
	//     in a buffer.
	//   * so long as the last buffer is not empty:
	//     - the RecursiveCTEIterationFn is used to create a plan for the
	//       recursive side; a reference to the last buffer is passed to this
	//       function. The returned plan uses this reference with a
	//       ConstructScanBuffer call.
	//     - the plan is executed; the results are emitted and also saved in a new
	//       buffer for the next iteration. If Deduplicate is true, only rows that
	//       haven't been returned yet are emitted and saved.
	ConstructRecursiveCTE(
		initial Node,
		fn RecursiveCTEIterationFn,
		label string,
		deduplicate bool,
	) (Node, error)

	// ConstructControlJobs creates a node for a ControlJobs operation.
	//
	// ControlJobs implements PAUSE/CANCEL/RESUME JOBS.
	ConstructControlJobs(
		command tree.JobCommand,
		input Node,
		reason tree.TypedExpr,
	) (Node, error)

	// ConstructControlSchedules creates a node for a ControlSchedules operation.
	//
	// ControlSchedules implements PAUSE/CANCEL/DROP SCHEDULES.
	ConstructControlSchedules(
		command tree.ScheduleCommand,
		input Node,
	) (Node, error)

	// ConstructCancelQueries creates a node for a CancelQueries operation.
	//
	// CancelQueries implements CANCEL QUERIES.
	ConstructCancelQueries(
		input Node,
		ifExists bool,
	) (Node, error)

	// ConstructCancelSessions creates a node for a CancelSessions operation.
	//
	// CancelSessions implements CANCEL SESSIONS.
	ConstructCancelSessions(
		input Node,
		ifExists bool,
	) (Node, error)

	// ConstructCreateStatistics creates a node for a CreateStatistics operation.
	//
	// CreateStatistics implements CREATE STATISTICS.
	ConstructCreateStatistics(
		cs *tree.CreateStats,
	) (Node, error)

	// ConstructExport creates a node for a Export operation.
	//
	// Export implements EXPORT.
	ConstructExport(
		input Node,
		fileName tree.TypedExpr,
		fileFormat string,
		options []KVOption,
		notNullCols NodeColumnOrdinalSet,
	) (Node, error)

	// ConstructAlterRangeRelocate creates a node for a AlterRangeRelocate operation.
	//
	// AlterTableRelocate implements ALTER RANGE RELOCATE.
	ConstructAlterRangeRelocate(
		input Node,
		subjectReplicas tree.RelocateSubject,
		toStoreID tree.TypedExpr,
		fromStoreID tree.TypedExpr,
	) (Node, error)
}

Factory defines the interface for building an execution plan, which consists of a tree of execution nodes (currently a sql.planNode tree).

The tree is always built bottom-up. The Construct methods either construct leaf nodes, or they take other nodes previously constructed by this same factory as children.

The PlanGistFactory further requires that the factory methods be called in natural tree order, that is, after an operator's children are constructed the next factory method to be called must be the parent of those nodes. The gist's flattened tree representation relies on this to enable the use of a stack to hold children, thus avoiding the complexity of dealing with other tree traversal methods.

The TypedExprs passed to these functions refer to columns of the input node via IndexedVars.

type GroupingOrderType

type GroupingOrderType int

GroupingOrderType is the grouping column order type for group by and distinct operations.

const (
	// NoStreaming means that the grouping columns have no useful order, so a
	// hash aggregator should be used.
	NoStreaming GroupingOrderType = iota
	// PartialStreaming means that the grouping columns are partially ordered, so
	// some optimizations can be done during aggregation.
	PartialStreaming
	// Streaming means that the grouping columns are fully ordered.
	Streaming
)

type InsertFastPathFKCheck

type InsertFastPathFKCheck struct {
	ReferencedTable cat.Table
	ReferencedIndex cat.Index

	// InsertCols contains the FK columns from the origin table, in the order of
	// the ReferencedIndex columns. For each, the value in the array indicates the
	// index of the column in the input table.
	InsertCols []TableColumnOrdinal

	MatchMethod tree.CompositeKeyMatchMethod

	// MkErr is called when a violation is detected (i.e. the index has no entries
	// for a given inserted row). The values passed correspond to InsertCols
	// above.
	MkErr MkErrFn
}

InsertFastPathFKCheck contains information about a foreign key check to be performed by the insert fast-path (see ConstructInsertFastPath). It identifies the index into which we can perform the lookup.

type KVOption

type KVOption struct {
	Key string
	// If there is no value, Value is DNull.
	Value tree.TypedExpr
}

KVOption represents information about a statement option (see tree.KVOptions).

type MkErrFn

type MkErrFn func(tree.Datums) error

MkErrFn is a function that generates an error which includes values from a relevant row.

type Node

type Node interface{}

Node represents a node in the execution tree (currently maps to sql.planNode).

type NodeColumnOrdinal

type NodeColumnOrdinal int32

NodeColumnOrdinal is the 0-based ordinal index of a column produced by a Node. It is used when referring to a column in an input to an operator.

type NodeColumnOrdinalSet

type NodeColumnOrdinalSet = util.FastIntSet

NodeColumnOrdinalSet contains a set of NodeColumnOrdinal values.

type OutputOrdering

type OutputOrdering colinfo.ColumnOrdering

OutputOrdering indicates the required output ordering on a Node that is being created. It refers to the output columns of the node by ordinal.

This ordering is used for distributed execution planning, to know how to merge results from different nodes. For example, scanning a table can be executed as multiple hosts scanning different pieces of the table. When the results from the nodes get merged, we they are merged according to the output ordering.

The node must be able to support this output ordering given its other configuration parameters.

type Plan

type Plan interface{}

Plan represents the plan for a query (currently maps to sql.planTop). For simple queries, the plan is associated with a single Node tree. For queries containing subqueries, the plan is associated with multiple Node trees (see ConstructPlan).

type RecursiveCTEIterationFn

type RecursiveCTEIterationFn func(ef Factory, bufferRef Node) (Plan, error)

RecursiveCTEIterationFn creates a plan for an iteration of WITH RECURSIVE, given the result of the last iteration (as a node created by ConstructBuffer).

type ScanParams

type ScanParams struct {
	// Only columns in this set are scanned and produced.
	NeededCols TableColumnOrdinalSet

	// At most one of IndexConstraint or InvertedConstraint is non-nil, depending
	// on the index type.
	IndexConstraint    *constraint.Constraint
	InvertedConstraint inverted.Spans

	// If non-zero, the scan returns this many rows.
	HardLimit int64

	// If non-zero, the scan may still be required to return up to all its rows
	// (or up to the HardLimit if it is set, but can be optimized under the
	// assumption that only SoftLimit rows will be needed.
	SoftLimit int64

	Reverse bool

	// If true, the scan will scan all spans in parallel. It should only be set to
	// true if there is a known upper bound on the number of rows that will be
	// scanned. It should not be set if there is a hard or soft limit.
	Parallelize bool

	Locking *tree.LockingItem

	EstimatedRowCount float64

	// If true, we are performing a locality optimized search. In order for this
	// to work correctly, the execution engine must create a local DistSQL plan
	// for the main query (subqueries and postqueries need not be local).
	LocalityOptimized bool
}

ScanParams contains all the parameters for a table scan.

type StubFactory

type StubFactory struct{}

StubFactory is a do-nothing implementation of Factory, used for testing.

func (StubFactory) ConstructAlterRangeRelocate

func (StubFactory) ConstructAlterRangeRelocate(
	input Node,
	subjectReplicas tree.RelocateSubject,
	toStoreID tree.TypedExpr,
	fromStoreID tree.TypedExpr,
) (Node, error)

func (StubFactory) ConstructAlterTableRelocate

func (StubFactory) ConstructAlterTableRelocate(
	index cat.Index,
	input Node,
	subjectReplicas tree.RelocateSubject,
) (Node, error)

func (StubFactory) ConstructAlterTableSplit

func (StubFactory) ConstructAlterTableSplit(
	index cat.Index,
	input Node,
	expiration tree.TypedExpr,
) (Node, error)

func (StubFactory) ConstructAlterTableUnsplit

func (StubFactory) ConstructAlterTableUnsplit(
	index cat.Index,
	input Node,
) (Node, error)

func (StubFactory) ConstructAlterTableUnsplitAll

func (StubFactory) ConstructAlterTableUnsplitAll(
	index cat.Index,
) (Node, error)

func (StubFactory) ConstructApplyJoin

func (StubFactory) ConstructApplyJoin(
	joinType descpb.JoinType,
	left Node,
	rightColumns colinfo.ResultColumns,
	onCond tree.TypedExpr,
	planRightSideFn ApplyJoinPlanRightSideFn,
) (Node, error)

func (StubFactory) ConstructBuffer

func (StubFactory) ConstructBuffer(
	input Node,
	label string,
) (Node, error)

func (StubFactory) ConstructCancelQueries

func (StubFactory) ConstructCancelQueries(
	input Node,
	ifExists bool,
) (Node, error)

func (StubFactory) ConstructCancelSessions

func (StubFactory) ConstructCancelSessions(
	input Node,
	ifExists bool,
) (Node, error)

func (StubFactory) ConstructControlJobs

func (StubFactory) ConstructControlJobs(
	command tree.JobCommand,
	input Node,
	reason tree.TypedExpr,
) (Node, error)

func (StubFactory) ConstructControlSchedules

func (StubFactory) ConstructControlSchedules(
	command tree.ScheduleCommand,
	input Node,
) (Node, error)

func (StubFactory) ConstructCreateStatistics

func (StubFactory) ConstructCreateStatistics(
	cs *tree.CreateStats,
) (Node, error)

func (StubFactory) ConstructCreateTable

func (StubFactory) ConstructCreateTable(
	schema cat.Schema,
	ct *tree.CreateTable,
) (Node, error)

func (StubFactory) ConstructCreateTableAs

func (StubFactory) ConstructCreateTableAs(
	input Node,
	schema cat.Schema,
	ct *tree.CreateTable,
) (Node, error)

func (StubFactory) ConstructCreateView

func (StubFactory) ConstructCreateView(
	schema cat.Schema,
	viewName *cat.DataSourceName,
	ifNotExists bool,
	replace bool,
	persistence tree.Persistence,
	materialized bool,
	viewQuery string,
	columns colinfo.ResultColumns,
	deps opt.ViewDeps,
	typeDeps opt.ViewTypeDeps,
) (Node, error)

func (StubFactory) ConstructDelete

func (StubFactory) ConstructDelete(
	input Node,
	table cat.Table,
	fetchCols TableColumnOrdinalSet,
	returnCols TableColumnOrdinalSet,
	autoCommit bool,
) (Node, error)

func (StubFactory) ConstructDeleteRange

func (StubFactory) ConstructDeleteRange(
	table cat.Table,
	needed TableColumnOrdinalSet,
	indexConstraint *constraint.Constraint,
	autoCommit bool,
) (Node, error)

func (StubFactory) ConstructDistinct

func (StubFactory) ConstructDistinct(
	input Node,
	distinctCols NodeColumnOrdinalSet,
	orderedCols NodeColumnOrdinalSet,
	reqOrdering OutputOrdering,
	nullsAreDistinct bool,
	errorOnDup string,
) (Node, error)

func (StubFactory) ConstructErrorIfRows

func (StubFactory) ConstructErrorIfRows(
	input Node,
	mkErr MkErrFn,
) (Node, error)

func (StubFactory) ConstructExplain

func (StubFactory) ConstructExplain(
	options *tree.ExplainOptions,
	stmtType tree.StatementReturnType,
	buildFn BuildPlanForExplainFn,
) (Node, error)

func (StubFactory) ConstructExplainOpt

func (StubFactory) ConstructExplainOpt(
	plan string,
	envOpts ExplainEnvData,
) (Node, error)

func (StubFactory) ConstructExport

func (StubFactory) ConstructExport(
	input Node,
	fileName tree.TypedExpr,
	fileFormat string,
	options []KVOption,
	notNullCols NodeColumnOrdinalSet,
) (Node, error)

func (StubFactory) ConstructFilter

func (StubFactory) ConstructFilter(
	input Node,
	filter tree.TypedExpr,
	reqOrdering OutputOrdering,
) (Node, error)

func (StubFactory) ConstructGroupBy

func (StubFactory) ConstructGroupBy(
	input Node,
	groupCols []NodeColumnOrdinal,
	groupColOrdering colinfo.ColumnOrdering,
	aggregations []AggInfo,
	reqOrdering OutputOrdering,
	groupingOrderType GroupingOrderType,
) (Node, error)

func (StubFactory) ConstructHashJoin

func (StubFactory) ConstructHashJoin(
	joinType descpb.JoinType,
	left Node,
	right Node,
	leftEqCols []NodeColumnOrdinal,
	rightEqCols []NodeColumnOrdinal,
	leftEqColsAreKey bool,
	rightEqColsAreKey bool,
	extraOnCond tree.TypedExpr,
) (Node, error)

func (StubFactory) ConstructHashSetOp

func (StubFactory) ConstructHashSetOp(
	typ tree.UnionType,
	all bool,
	left Node,
	right Node,
) (Node, error)

func (StubFactory) ConstructIndexJoin

func (StubFactory) ConstructIndexJoin(
	input Node,
	table cat.Table,
	keyCols []NodeColumnOrdinal,
	tableCols TableColumnOrdinalSet,
	reqOrdering OutputOrdering,
) (Node, error)

func (StubFactory) ConstructInsert

func (StubFactory) ConstructInsert(
	input Node,
	table cat.Table,
	arbiterIndexes cat.IndexOrdinals,
	arbiterConstraints cat.UniqueOrdinals,
	insertCols TableColumnOrdinalSet,
	returnCols TableColumnOrdinalSet,
	checkCols CheckOrdinalSet,
	autoCommit bool,
) (Node, error)

func (StubFactory) ConstructInsertFastPath

func (StubFactory) ConstructInsertFastPath(
	rows [][]tree.TypedExpr,
	table cat.Table,
	insertCols TableColumnOrdinalSet,
	returnCols TableColumnOrdinalSet,
	checkCols CheckOrdinalSet,
	fkChecks []InsertFastPathFKCheck,
	autoCommit bool,
) (Node, error)

func (StubFactory) ConstructInvertedFilter

func (StubFactory) ConstructInvertedFilter(
	input Node,
	invFilter *inverted.SpanExpression,
	preFiltererExpr tree.TypedExpr,
	preFiltererType *types.T,
	invColumn NodeColumnOrdinal,
) (Node, error)

func (StubFactory) ConstructInvertedJoin

func (StubFactory) ConstructInvertedJoin(
	joinType descpb.JoinType,
	invertedExpr tree.TypedExpr,
	input Node,
	table cat.Table,
	index cat.Index,
	prefixEqCols []NodeColumnOrdinal,
	lookupCols TableColumnOrdinalSet,
	onCond tree.TypedExpr,
	isFirstJoinInPairedJoiner bool,
	reqOrdering OutputOrdering,
) (Node, error)

func (StubFactory) ConstructLimit

func (StubFactory) ConstructLimit(
	input Node,
	limit tree.TypedExpr,
	offset tree.TypedExpr,
) (Node, error)

func (StubFactory) ConstructLookupJoin

func (StubFactory) ConstructLookupJoin(
	joinType descpb.JoinType,
	input Node,
	table cat.Table,
	index cat.Index,
	eqCols []NodeColumnOrdinal,
	eqColsAreKey bool,
	lookupExpr tree.TypedExpr,
	remoteLookupExpr tree.TypedExpr,
	lookupCols TableColumnOrdinalSet,
	onCond tree.TypedExpr,
	isFirstJoinInPairedJoiner bool,
	isSecondJoinInPairedJoiner bool,
	reqOrdering OutputOrdering,
	locking *tree.LockingItem,
) (Node, error)

func (StubFactory) ConstructMax1Row

func (StubFactory) ConstructMax1Row(
	input Node,
	errorText string,
) (Node, error)

func (StubFactory) ConstructMergeJoin

func (StubFactory) ConstructMergeJoin(
	joinType descpb.JoinType,
	left Node,
	right Node,
	onCond tree.TypedExpr,
	leftOrdering colinfo.ColumnOrdering,
	rightOrdering colinfo.ColumnOrdering,
	reqOrdering OutputOrdering,
	leftEqColsAreKey bool,
	rightEqColsAreKey bool,
) (Node, error)

func (StubFactory) ConstructOpaque

func (StubFactory) ConstructOpaque(
	metadata opt.OpaqueMetadata,
) (Node, error)

func (StubFactory) ConstructOrdinality

func (StubFactory) ConstructOrdinality(
	input Node,
	colName string,
) (Node, error)

func (StubFactory) ConstructPlan

func (StubFactory) ConstructPlan(
	root Node,
	subqueries []Subquery,
	cascades []Cascade,
	checks []Node,
	rootRowCount int64,
) (Plan, error)

func (StubFactory) ConstructProjectSet

func (StubFactory) ConstructProjectSet(
	input Node,
	exprs tree.TypedExprs,
	zipCols colinfo.ResultColumns,
	numColsPerGen []int,
) (Node, error)

func (StubFactory) ConstructRecursiveCTE

func (StubFactory) ConstructRecursiveCTE(
	initial Node,
	fn RecursiveCTEIterationFn,
	label string,
	deduplicate bool,
) (Node, error)

func (StubFactory) ConstructRender

func (StubFactory) ConstructRender(
	input Node,
	columns colinfo.ResultColumns,
	exprs tree.TypedExprs,
	reqOrdering OutputOrdering,
) (Node, error)

func (StubFactory) ConstructSaveTable

func (StubFactory) ConstructSaveTable(
	input Node,
	table *cat.DataSourceName,
	colNames []string,
) (Node, error)

func (StubFactory) ConstructScalarGroupBy

func (StubFactory) ConstructScalarGroupBy(
	input Node,
	aggregations []AggInfo,
) (Node, error)

func (StubFactory) ConstructScan

func (StubFactory) ConstructScan(
	table cat.Table,
	index cat.Index,
	params ScanParams,
	reqOrdering OutputOrdering,
) (Node, error)

func (StubFactory) ConstructScanBuffer

func (StubFactory) ConstructScanBuffer(
	ref Node,
	label string,
) (Node, error)

func (StubFactory) ConstructSequenceSelect

func (StubFactory) ConstructSequenceSelect(
	sequence cat.Sequence,
) (Node, error)

func (StubFactory) ConstructSerializingProject

func (StubFactory) ConstructSerializingProject(
	input Node,
	cols []NodeColumnOrdinal,
	colNames []string,
) (Node, error)

func (StubFactory) ConstructShowTrace

func (StubFactory) ConstructShowTrace(
	typ tree.ShowTraceType,
	compact bool,
) (Node, error)

func (StubFactory) ConstructSimpleProject

func (StubFactory) ConstructSimpleProject(
	input Node,
	cols []NodeColumnOrdinal,
	reqOrdering OutputOrdering,
) (Node, error)

func (StubFactory) ConstructSort

func (StubFactory) ConstructSort(
	input Node,
	ordering OutputOrdering,
	alreadyOrderedPrefix int,
) (Node, error)

func (StubFactory) ConstructStreamingSetOp

func (StubFactory) ConstructStreamingSetOp(
	typ tree.UnionType,
	all bool,
	left Node,
	right Node,
	streamingOrdering colinfo.ColumnOrdering,
	reqOrdering OutputOrdering,
) (Node, error)

func (StubFactory) ConstructTopK

func (StubFactory) ConstructTopK(
	input Node,
	k int64,
	ordering OutputOrdering,
	alreadyOrderedPrefix int,
) (Node, error)

func (StubFactory) ConstructUnionAll

func (StubFactory) ConstructUnionAll(
	left Node,
	right Node,
	reqOrdering OutputOrdering,
	hardLimit uint64,
) (Node, error)

func (StubFactory) ConstructUpdate

func (StubFactory) ConstructUpdate(
	input Node,
	table cat.Table,
	fetchCols TableColumnOrdinalSet,
	updateCols TableColumnOrdinalSet,
	returnCols TableColumnOrdinalSet,
	checks CheckOrdinalSet,
	passthrough colinfo.ResultColumns,
	autoCommit bool,
) (Node, error)

func (StubFactory) ConstructUpsert

func (StubFactory) ConstructUpsert(
	input Node,
	table cat.Table,
	arbiterIndexes cat.IndexOrdinals,
	arbiterConstraints cat.UniqueOrdinals,
	canaryCol NodeColumnOrdinal,
	insertCols TableColumnOrdinalSet,
	fetchCols TableColumnOrdinalSet,
	updateCols TableColumnOrdinalSet,
	returnCols TableColumnOrdinalSet,
	checks CheckOrdinalSet,
	autoCommit bool,
) (Node, error)

func (StubFactory) ConstructValues

func (StubFactory) ConstructValues(
	rows [][]tree.TypedExpr,
	columns colinfo.ResultColumns,
) (Node, error)

func (StubFactory) ConstructWindow

func (StubFactory) ConstructWindow(
	input Node,
	window WindowInfo,
) (Node, error)

func (StubFactory) ConstructZigzagJoin

func (StubFactory) ConstructZigzagJoin(
	leftTable cat.Table,
	leftIndex cat.Index,
	leftCols TableColumnOrdinalSet,
	leftFixedVals []tree.TypedExpr,
	leftEqCols []TableColumnOrdinal,
	rightTable cat.Table,
	rightIndex cat.Index,
	rightCols TableColumnOrdinalSet,
	rightFixedVals []tree.TypedExpr,
	rightEqCols []TableColumnOrdinal,
	onCond tree.TypedExpr,
	reqOrdering OutputOrdering,
) (Node, error)

type Subquery

type Subquery struct {
	// ExprNode is a reference to a AST node that can be used for printing the SQL
	// of the subquery (for EXPLAIN).
	ExprNode tree.NodeFormatter
	Mode     SubqueryMode
	// Root is the root Node of the plan for this subquery. This Node returns
	// results as required for the specific Type.
	Root Node
	// RowCount is the estimated number of rows that Root will output, negative
	// if the stats weren't available to make a good estimate.
	RowCount int64
}

Subquery encapsulates information about a subquery that is part of a plan.

type SubqueryMode

type SubqueryMode int

SubqueryMode indicates how the results of the subquery are to be processed.

const (
	// SubqueryExists - the value of the subquery is a boolean: true if the
	// subquery returns any rows, false otherwise.
	SubqueryExists SubqueryMode = iota
	// SubqueryOneRow - the subquery expects at most one row; the result is that
	// row (as a single value or a tuple), or NULL if there were no rows.
	SubqueryOneRow
	// SubqueryAnyRows - the subquery is an argument to ANY. Any number of rows
	// expected; the result is a sorted, distinct tuple of rows (i.e. it has been
	// normalized). As a special case, if there is only one column selected, the
	// result is a tuple of the selected values (instead of a tuple of 1-tuples).
	SubqueryAnyRows
	// SubqueryAllRows - the subquery is an argument to ARRAY. The result is a
	// tuple of rows.
	SubqueryAllRows
)

type TableColumnOrdinal

type TableColumnOrdinal int32

TableColumnOrdinal is the 0-based ordinal index of a cat.Table column. It is used when operations involve a table directly (e.g. scans, index/lookup joins, mutations).

type TableColumnOrdinalSet

type TableColumnOrdinalSet = util.FastIntSet

TableColumnOrdinalSet contains a set of TableColumnOrdinal values.

type WindowInfo

type WindowInfo struct {
	// Cols is the set of columns that are returned from the windowing operator.
	Cols colinfo.ResultColumns

	// Exprs is the list of window function expressions.
	Exprs []*tree.FuncExpr

	// OutputIdxs are the indexes that the various window functions being computed
	// should put their output in.
	OutputIdxs []int

	// ArgIdxs is the list of column ordinals each function takes as arguments,
	// in the same order as Exprs.
	ArgIdxs [][]NodeColumnOrdinal

	// FilterIdxs is the list of column indices to use as filters.
	FilterIdxs []int

	// Partition is the set of input columns to partition on.
	Partition []NodeColumnOrdinal

	// Ordering is the set of input columns to order on.
	Ordering colinfo.ColumnOrdering
}

WindowInfo represents the information about a window function that must be passed through to the execution engine.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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