explain

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: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePlanGistToRows

func DecodePlanGistToRows(gist string, catalog cat.Catalog) ([]string, error)

DecodePlanGistToRows converts a gist to a logical plan and returns the rows.

func Emit

func Emit(plan *Plan, ob *OutputBuilder, spanFormatFn SpanFormatFn) error

Emit produces the EXPLAIN output against the given OutputBuilder. The OutputBuilder flags are taken into account.

Types

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory implements exec.ExplainFactory. It wraps another factory and forwards all factory calls, while also recording the calls and arguments. The product of the factory is the Plan returned by ConstructPlan, which can be used to access the wrapped plan, as well as a parallel Node tree which can be used to produce EXPLAIN information.

func NewFactory

func NewFactory(wrappedFactory exec.Factory) *Factory

NewFactory creates a new explain factory.

func (*Factory) AnnotateNode

func (f *Factory) AnnotateNode(execNode exec.Node, id exec.ExplainAnnotationID, value interface{})

AnnotateNode is part of the exec.ExplainFactory interface.

func (*Factory) ConstructAlterRangeRelocate

func (f *Factory) ConstructAlterRangeRelocate(
	input exec.Node,
	subjectReplicas tree.RelocateSubject,
	toStoreID tree.TypedExpr,
	fromStoreID tree.TypedExpr,
) (exec.Node, error)

func (*Factory) ConstructAlterTableRelocate

func (f *Factory) ConstructAlterTableRelocate(
	index cat.Index,
	input exec.Node,
	subjectReplicas tree.RelocateSubject,
) (exec.Node, error)

func (*Factory) ConstructAlterTableSplit

func (f *Factory) ConstructAlterTableSplit(
	index cat.Index,
	input exec.Node,
	expiration tree.TypedExpr,
) (exec.Node, error)

func (*Factory) ConstructAlterTableUnsplit

func (f *Factory) ConstructAlterTableUnsplit(
	index cat.Index,
	input exec.Node,
) (exec.Node, error)

func (*Factory) ConstructAlterTableUnsplitAll

func (f *Factory) ConstructAlterTableUnsplitAll(
	index cat.Index,
) (exec.Node, error)

func (*Factory) ConstructApplyJoin

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

func (*Factory) ConstructBuffer

func (f *Factory) ConstructBuffer(
	input exec.Node,
	label string,
) (exec.Node, error)

func (*Factory) ConstructCancelQueries

func (f *Factory) ConstructCancelQueries(
	input exec.Node,
	ifExists bool,
) (exec.Node, error)

func (*Factory) ConstructCancelSessions

func (f *Factory) ConstructCancelSessions(
	input exec.Node,
	ifExists bool,
) (exec.Node, error)

func (*Factory) ConstructControlJobs

func (f *Factory) ConstructControlJobs(
	command tree.JobCommand,
	input exec.Node,
	reason tree.TypedExpr,
) (exec.Node, error)

func (*Factory) ConstructControlSchedules

func (f *Factory) ConstructControlSchedules(
	command tree.ScheduleCommand,
	input exec.Node,
) (exec.Node, error)

func (*Factory) ConstructCreateStatistics

func (f *Factory) ConstructCreateStatistics(
	cs *tree.CreateStats,
) (exec.Node, error)

func (*Factory) ConstructCreateTable

func (f *Factory) ConstructCreateTable(
	schema cat.Schema,
	ct *tree.CreateTable,
) (exec.Node, error)

func (*Factory) ConstructCreateTableAs

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

func (*Factory) ConstructCreateView

func (f *Factory) 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,
) (exec.Node, error)

func (*Factory) ConstructDelete

func (f *Factory) ConstructDelete(
	input exec.Node,
	table cat.Table,
	fetchCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,

	autoCommit bool,
) (exec.Node, error)

func (*Factory) ConstructDeleteRange

func (f *Factory) ConstructDeleteRange(
	table cat.Table,
	needed exec.TableColumnOrdinalSet,
	indexConstraint *constraint.Constraint,

	autoCommit bool,
) (exec.Node, error)

func (*Factory) ConstructDistinct

func (f *Factory) ConstructDistinct(
	input exec.Node,
	distinctCols exec.NodeColumnOrdinalSet,
	orderedCols exec.NodeColumnOrdinalSet,
	reqOrdering exec.OutputOrdering,
	nullsAreDistinct bool,
	errorOnDup string,
) (exec.Node, error)

func (*Factory) ConstructErrorIfRows

func (f *Factory) ConstructErrorIfRows(
	input exec.Node,

	mkErr exec.MkErrFn,
) (exec.Node, error)

func (*Factory) ConstructExplain

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

func (*Factory) ConstructExplainOpt

func (f *Factory) ConstructExplainOpt(
	plan string,
	envOpts exec.ExplainEnvData,
) (exec.Node, error)

func (*Factory) ConstructExport

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

func (*Factory) ConstructFilter

func (f *Factory) ConstructFilter(
	input exec.Node,
	filter tree.TypedExpr,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*Factory) ConstructGroupBy

func (f *Factory) ConstructGroupBy(
	input exec.Node,
	groupCols []exec.NodeColumnOrdinal,

	groupColOrdering colinfo.ColumnOrdering,
	aggregations []exec.AggInfo,

	reqOrdering exec.OutputOrdering,

	groupingOrderType exec.GroupingOrderType,
) (exec.Node, error)

func (*Factory) ConstructHashJoin

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

func (*Factory) ConstructHashSetOp

func (f *Factory) ConstructHashSetOp(
	typ tree.UnionType,
	all bool,
	left exec.Node,
	right exec.Node,
) (exec.Node, error)

func (*Factory) ConstructIndexJoin

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

func (*Factory) ConstructInsert

func (f *Factory) ConstructInsert(
	input exec.Node,
	table cat.Table,
	arbiterIndexes cat.IndexOrdinals,
	arbiterConstraints cat.UniqueOrdinals,
	insertCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checkCols exec.CheckOrdinalSet,

	autoCommit bool,
) (exec.Node, error)

func (*Factory) ConstructInsertFastPath

func (f *Factory) ConstructInsertFastPath(
	rows [][]tree.TypedExpr,
	table cat.Table,
	insertCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checkCols exec.CheckOrdinalSet,
	fkChecks []exec.InsertFastPathFKCheck,

	autoCommit bool,
) (exec.Node, error)

func (*Factory) ConstructInvertedFilter

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

func (*Factory) ConstructInvertedJoin

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

func (*Factory) ConstructLimit

func (f *Factory) ConstructLimit(
	input exec.Node,
	limit tree.TypedExpr,
	offset tree.TypedExpr,
) (exec.Node, error)

func (*Factory) ConstructLookupJoin

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

func (*Factory) ConstructMax1Row

func (f *Factory) ConstructMax1Row(
	input exec.Node,
	errorText string,
) (exec.Node, error)

func (*Factory) ConstructMergeJoin

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

func (*Factory) ConstructOpaque

func (f *Factory) ConstructOpaque(
	metadata opt.OpaqueMetadata,
) (exec.Node, error)

func (*Factory) ConstructOrdinality

func (f *Factory) ConstructOrdinality(
	input exec.Node,
	colName string,
) (exec.Node, error)

func (*Factory) ConstructPlan

func (f *Factory) ConstructPlan(
	root exec.Node,
	subqueries []exec.Subquery,
	cascades []exec.Cascade,
	checks []exec.Node,
	rootRowCount int64,
) (exec.Plan, error)

ConstructPlan is part of the exec.Factory interface.

func (*Factory) ConstructProjectSet

func (f *Factory) ConstructProjectSet(
	input exec.Node,
	exprs tree.TypedExprs,
	zipCols colinfo.ResultColumns,
	numColsPerGen []int,
) (exec.Node, error)

func (*Factory) ConstructRecursiveCTE

func (f *Factory) ConstructRecursiveCTE(
	initial exec.Node,
	fn exec.RecursiveCTEIterationFn,
	label string,
	deduplicate bool,
) (exec.Node, error)

func (*Factory) ConstructRender

func (f *Factory) ConstructRender(
	input exec.Node,
	columns colinfo.ResultColumns,
	exprs tree.TypedExprs,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*Factory) ConstructSaveTable

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

func (*Factory) ConstructScalarGroupBy

func (f *Factory) ConstructScalarGroupBy(
	input exec.Node,
	aggregations []exec.AggInfo,
) (exec.Node, error)

func (*Factory) ConstructScan

func (f *Factory) ConstructScan(
	table cat.Table,
	index cat.Index,
	params exec.ScanParams,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*Factory) ConstructScanBuffer

func (f *Factory) ConstructScanBuffer(
	ref exec.Node,
	label string,
) (exec.Node, error)

func (*Factory) ConstructSequenceSelect

func (f *Factory) ConstructSequenceSelect(
	sequence cat.Sequence,
) (exec.Node, error)

func (*Factory) ConstructSerializingProject

func (f *Factory) ConstructSerializingProject(
	input exec.Node,
	cols []exec.NodeColumnOrdinal,
	colNames []string,
) (exec.Node, error)

func (*Factory) ConstructShowTrace

func (f *Factory) ConstructShowTrace(
	typ tree.ShowTraceType,
	compact bool,
) (exec.Node, error)

func (*Factory) ConstructSimpleProject

func (f *Factory) ConstructSimpleProject(
	input exec.Node,
	cols []exec.NodeColumnOrdinal,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*Factory) ConstructSort

func (f *Factory) ConstructSort(
	input exec.Node,
	ordering exec.OutputOrdering,
	alreadyOrderedPrefix int,
) (exec.Node, error)

func (*Factory) ConstructStreamingSetOp

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

func (*Factory) ConstructTopK

func (f *Factory) ConstructTopK(
	input exec.Node,
	k int64,
	ordering exec.OutputOrdering,
	alreadyOrderedPrefix int,
) (exec.Node, error)

func (*Factory) ConstructUnionAll

func (f *Factory) ConstructUnionAll(
	left exec.Node,
	right exec.Node,
	reqOrdering exec.OutputOrdering,
	hardLimit uint64,
) (exec.Node, error)

func (*Factory) ConstructUpdate

func (f *Factory) ConstructUpdate(
	input exec.Node,
	table cat.Table,
	fetchCols exec.TableColumnOrdinalSet,
	updateCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checks exec.CheckOrdinalSet,
	passthrough colinfo.ResultColumns,

	autoCommit bool,
) (exec.Node, error)

func (*Factory) ConstructUpsert

func (f *Factory) ConstructUpsert(
	input exec.Node,
	table cat.Table,
	arbiterIndexes cat.IndexOrdinals,
	arbiterConstraints cat.UniqueOrdinals,
	canaryCol exec.NodeColumnOrdinal,
	insertCols exec.TableColumnOrdinalSet,
	fetchCols exec.TableColumnOrdinalSet,
	updateCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checks exec.CheckOrdinalSet,

	autoCommit bool,
) (exec.Node, error)

func (*Factory) ConstructValues

func (f *Factory) ConstructValues(
	rows [][]tree.TypedExpr,
	columns colinfo.ResultColumns,
) (exec.Node, error)

func (*Factory) ConstructWindow

func (f *Factory) ConstructWindow(
	input exec.Node,
	window exec.WindowInfo,
) (exec.Node, error)

func (*Factory) ConstructZigzagJoin

func (f *Factory) ConstructZigzagJoin(

	leftTable cat.Table,
	leftIndex cat.Index,

	leftCols exec.TableColumnOrdinalSet,

	leftFixedVals []tree.TypedExpr,

	leftEqCols []exec.TableColumnOrdinal,

	rightTable cat.Table,
	rightIndex cat.Index,

	rightCols exec.TableColumnOrdinalSet,

	rightFixedVals []tree.TypedExpr,

	rightEqCols []exec.TableColumnOrdinal,

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

type Flags

type Flags struct {
	// Verbose indicates that more metadata is shown, and plan columns and
	// ordering are shown.
	Verbose bool
	// ShowTypes indicates that the types of columns are shown.
	// If ShowTypes is true, then Verbose is also true.
	ShowTypes bool
	// If HideValues is true, we hide fields that may contain values from the
	// query (e.g. spans). Used internally for the plan visible in the UI.
	// If HideValues is true, then Verbose must be false.
	HideValues bool
	// If OnlyShape is true, we hide fields that could be different between 2
	// plans that otherwise have exactly the same shape, like estimated row count.
	// This is used for EXPLAIN(SHAPE), which is used for the statement-bundle
	// debug tool.
	OnlyShape bool

	// Redaction control (for testing purposes).
	Redact RedactFlags
}

Flags are modifiers for EXPLAIN (PLAN).

func MakeFlags

func MakeFlags(options *tree.ExplainOptions) Flags

MakeFlags crates Flags from ExplainOptions.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node in a plan tree; records the operation and arguments passed to the factory method and provides access to the corresponding exec.Node (produced by the wrapped factory).

func (*Node) Annotate

func (n *Node) Annotate(id exec.ExplainAnnotationID, value interface{})

Annotate annotates the node with extra information.

func (*Node) Child

func (n *Node) Child(idx int) *Node

Child returns the i-th child.

func (*Node) ChildCount

func (n *Node) ChildCount() int

ChildCount returns the number of children nodes.

func (*Node) Columns

func (n *Node) Columns() colinfo.ResultColumns

Columns returns the ResultColumns for this node.

func (*Node) Ordering

func (n *Node) Ordering() colinfo.ColumnOrdering

Ordering returns the required output ordering for this node; columns correspond to Columns().

func (*Node) WrappedNode

func (n *Node) WrappedNode() exec.Node

WrappedNode returns the corresponding exec.Node produced by the wrapped factory.

type OutputBuilder

type OutputBuilder struct {
	// contains filtered or unexported fields
}

OutputBuilder is used to build the output of an explain tree.

See ExampleOutputBuilder for sample usage.

func NewOutputBuilder

func NewOutputBuilder(flags Flags) *OutputBuilder

NewOutputBuilder creates a new OutputBuilder.

EnterNode / EnterMetaNode and AddField should be used to populate data, after which a Build* method should be used.

func (*OutputBuilder) AddContentionTime

func (ob *OutputBuilder) AddContentionTime(contentionTime time.Duration)

AddContentionTime adds a top-level field for the cumulative contention time.

func (*OutputBuilder) AddDistribution

func (ob *OutputBuilder) AddDistribution(value string)

AddDistribution adds a top-level distribution field. Cannot be called while inside a node.

func (*OutputBuilder) AddExecutionTime

func (ob *OutputBuilder) AddExecutionTime(delta time.Duration)

AddExecutionTime adds a top-level execution time field. Cannot be called while inside a node.

func (*OutputBuilder) AddField

func (ob *OutputBuilder) AddField(key, value string)

AddField adds an information field under the current node.

func (*OutputBuilder) AddKVReadStats

func (ob *OutputBuilder) AddKVReadStats(rows, bytes int64)

AddKVReadStats adds a top-level field for the bytes/rows read from KV.

func (*OutputBuilder) AddKVTime

func (ob *OutputBuilder) AddKVTime(kvTime time.Duration)

AddKVTime adds a top-level field for the cumulative time spent in KV.

func (*OutputBuilder) AddMaxDiskUsage

func (ob *OutputBuilder) AddMaxDiskUsage(bytes int64)

AddMaxDiskUsage adds a top-level field for the sql temporary disk space used by the query. If we're redacting leave this out to keep logic test output independent of disk spilling. Disk spilling is controlled by a metamorphic constant so it may or may not occur randomly so it makes sense to omit this information entirely if we're redacting. Since disk spilling is rare we only include this field is bytes is greater than zero.

func (*OutputBuilder) AddMaxMemUsage

func (ob *OutputBuilder) AddMaxMemUsage(bytes int64)

AddMaxMemUsage adds a top-level field for the memory used by the query.

func (*OutputBuilder) AddNetworkStats

func (ob *OutputBuilder) AddNetworkStats(messages, bytes int64)

AddNetworkStats adds a top-level field for network statistics.

func (*OutputBuilder) AddPlanningTime

func (ob *OutputBuilder) AddPlanningTime(delta time.Duration)

AddPlanningTime adds a top-level planning time field. Cannot be called while inside a node.

func (*OutputBuilder) AddRedactableField

func (ob *OutputBuilder) AddRedactableField(flag RedactFlags, key, value string)

AddRedactableField adds an information field under the current node, hiding the value depending depending on the given redact flag.

func (*OutputBuilder) AddRedactableTopLevelField

func (ob *OutputBuilder) AddRedactableTopLevelField(redactFlag RedactFlags, key, value string)

AddRedactableTopLevelField adds a top-level field, hiding the value depending depending on the given redact flag.

func (*OutputBuilder) AddRegionsStats

func (ob *OutputBuilder) AddRegionsStats(regions []string)

AddRegionsStats adds a top-level field for regions executed on statistics.

func (*OutputBuilder) AddTopLevelField

func (ob *OutputBuilder) AddTopLevelField(key, value string)

AddTopLevelField adds a top-level field. Cannot be called while inside a node.

func (*OutputBuilder) AddVectorized

func (ob *OutputBuilder) AddVectorized(value bool)

AddVectorized adds a top-level vectorized field. Cannot be called while inside a node.

func (*OutputBuilder) Attr

func (ob *OutputBuilder) Attr(key string, value interface{})

Attr adds an information field under the current node.

func (*OutputBuilder) Attrf

func (ob *OutputBuilder) Attrf(key, format string, args ...interface{})

Attrf is a formatter version of Attr.

func (*OutputBuilder) BuildExplainRows

func (ob *OutputBuilder) BuildExplainRows() []tree.Datums

BuildExplainRows builds the output rows for an EXPLAIN (PLAN) statement.

The columns are:

verbose=false:  Tree Field Description
verbose=true:   Tree Level Type Field Description

func (*OutputBuilder) BuildProtoTree

func (ob *OutputBuilder) BuildProtoTree() *roachpb.ExplainTreePlanNode

BuildProtoTree creates a representation of the plan as a tree of roachpb.ExplainTreePlanNodes.

func (*OutputBuilder) BuildString

func (ob *OutputBuilder) BuildString() string

BuildString creates a string representation of the plan information. The output string always ends in a newline.

func (*OutputBuilder) BuildStringRows

func (ob *OutputBuilder) BuildStringRows() []string

BuildStringRows creates a string representation of the plan information and returns it as a list of strings (one for each row). The strings do not end in newline.

func (*OutputBuilder) EnterMetaNode

func (ob *OutputBuilder) EnterMetaNode(name string)

EnterMetaNode is like EnterNode, but the output will always have empty strings for the columns and ordering. This is used for "meta nodes" like "fk-cascade".

func (*OutputBuilder) EnterNode

func (ob *OutputBuilder) EnterNode(
	name string, columns colinfo.ResultColumns, ordering colinfo.ColumnOrdering,
)

EnterNode creates a new node as a child of the current node.

func (*OutputBuilder) Expr

func (ob *OutputBuilder) Expr(key string, expr tree.TypedExpr, varColumns colinfo.ResultColumns)

Expr adds an information field with an expression. The expression's IndexedVars refer to the given columns. If the expression is nil, nothing is emitted.

func (*OutputBuilder) LeaveNode

func (ob *OutputBuilder) LeaveNode()

LeaveNode moves the current node back up the tree by one level.

func (*OutputBuilder) VAttr

func (ob *OutputBuilder) VAttr(key string, value interface{})

VAttr adds an information field under the current node, if the Verbose flag is set.

func (*OutputBuilder) VExpr

func (ob *OutputBuilder) VExpr(key string, expr tree.TypedExpr, varColumns colinfo.ResultColumns)

VExpr is a verbose-only variant of Expr.

type Plan

type Plan struct {
	Root        *Node
	Subqueries  []exec.Subquery
	Cascades    []exec.Cascade
	Checks      []*Node
	WrappedPlan exec.Plan
	Gist        PlanGist
}

Plan is the result of ConstructPlan; provides access to the exec.Plan produced by the wrapped factory.

func DecodePlanGistToPlan

func DecodePlanGistToPlan(s string, cat cat.Catalog) (plan *Plan, retErr error)

DecodePlanGistToPlan constructs an explain.Node tree from a gist.

type PlanGist

type PlanGist struct {
	// contains filtered or unexported fields
}

PlanGist is a compact representation of a logical plan meant to be used as a key and log for different plans used to implement a particular query. A gist doesn't change for the following:

- literal constant values - alias names - grouping column names - constraint values - estimated rows stats

The notion is that the gist is the rough shape of the plan that represents the way the plan operators are put together and what tables and indexes they use.

func (PlanGist) Hash

func (fp PlanGist) Hash() uint64

Hash returns a 64 bit hash of the gist. Note that this is symbolically stable across table/index ids, i.e. indexes from two different databases with different ids but the same name will have the same hash.

func (PlanGist) String

func (fp PlanGist) String() string

String returns the gist bytes as a base64 encoded string.

type PlanGistFactory

type PlanGistFactory struct {
	// contains filtered or unexported fields
}

PlanGistFactory is an exec.Factory that produces a gist by eaves dropping on the exec builder phase of compilation.

func NewPlanGistFactory

func NewPlanGistFactory(wrappedFactory exec.Factory) *PlanGistFactory

NewPlanGistFactory creates a new PlanGistFactory.

func (*PlanGistFactory) ConstructAlterRangeRelocate

func (f *PlanGistFactory) ConstructAlterRangeRelocate(
	input exec.Node,
	subjectReplicas tree.RelocateSubject,
	toStoreID tree.TypedExpr,
	fromStoreID tree.TypedExpr,
) (exec.Node, error)

func (*PlanGistFactory) ConstructAlterTableRelocate

func (f *PlanGistFactory) ConstructAlterTableRelocate(
	index cat.Index,
	input exec.Node,
	subjectReplicas tree.RelocateSubject,
) (exec.Node, error)

func (*PlanGistFactory) ConstructAlterTableSplit

func (f *PlanGistFactory) ConstructAlterTableSplit(
	index cat.Index,
	input exec.Node,
	expiration tree.TypedExpr,
) (exec.Node, error)

func (*PlanGistFactory) ConstructAlterTableUnsplit

func (f *PlanGistFactory) ConstructAlterTableUnsplit(
	index cat.Index,
	input exec.Node,
) (exec.Node, error)

func (*PlanGistFactory) ConstructAlterTableUnsplitAll

func (f *PlanGistFactory) ConstructAlterTableUnsplitAll(
	index cat.Index,
) (exec.Node, error)

func (*PlanGistFactory) ConstructApplyJoin

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

func (*PlanGistFactory) ConstructBuffer

func (f *PlanGistFactory) ConstructBuffer(
	input exec.Node,
	label string,
) (exec.Node, error)

func (*PlanGistFactory) ConstructCancelQueries

func (f *PlanGistFactory) ConstructCancelQueries(
	input exec.Node,
	ifExists bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructCancelSessions

func (f *PlanGistFactory) ConstructCancelSessions(
	input exec.Node,
	ifExists bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructControlJobs

func (f *PlanGistFactory) ConstructControlJobs(
	command tree.JobCommand,
	input exec.Node,
	reason tree.TypedExpr,
) (exec.Node, error)

func (*PlanGistFactory) ConstructControlSchedules

func (f *PlanGistFactory) ConstructControlSchedules(
	command tree.ScheduleCommand,
	input exec.Node,
) (exec.Node, error)

func (*PlanGistFactory) ConstructCreateStatistics

func (f *PlanGistFactory) ConstructCreateStatistics(
	cs *tree.CreateStats,
) (exec.Node, error)

func (*PlanGistFactory) ConstructCreateTable

func (f *PlanGistFactory) ConstructCreateTable(
	schema cat.Schema,
	ct *tree.CreateTable,
) (exec.Node, error)

func (*PlanGistFactory) ConstructCreateTableAs

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

func (*PlanGistFactory) ConstructCreateView

func (f *PlanGistFactory) 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,
) (exec.Node, error)

func (*PlanGistFactory) ConstructDelete

func (f *PlanGistFactory) ConstructDelete(
	input exec.Node,
	table cat.Table,
	fetchCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,

	autoCommit bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructDeleteRange

func (f *PlanGistFactory) ConstructDeleteRange(
	table cat.Table,
	needed exec.TableColumnOrdinalSet,
	indexConstraint *constraint.Constraint,

	autoCommit bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructDistinct

func (f *PlanGistFactory) ConstructDistinct(
	input exec.Node,
	distinctCols exec.NodeColumnOrdinalSet,
	orderedCols exec.NodeColumnOrdinalSet,
	reqOrdering exec.OutputOrdering,
	nullsAreDistinct bool,
	errorOnDup string,
) (exec.Node, error)

func (*PlanGistFactory) ConstructErrorIfRows

func (f *PlanGistFactory) ConstructErrorIfRows(
	input exec.Node,

	mkErr exec.MkErrFn,
) (exec.Node, error)

func (*PlanGistFactory) ConstructExplain

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

func (*PlanGistFactory) ConstructExplainOpt

func (f *PlanGistFactory) ConstructExplainOpt(
	plan string,
	envOpts exec.ExplainEnvData,
) (exec.Node, error)

func (*PlanGistFactory) ConstructExport

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

func (*PlanGistFactory) ConstructFilter

func (f *PlanGistFactory) ConstructFilter(
	input exec.Node,
	filter tree.TypedExpr,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*PlanGistFactory) ConstructGroupBy

func (f *PlanGistFactory) ConstructGroupBy(
	input exec.Node,
	groupCols []exec.NodeColumnOrdinal,

	groupColOrdering colinfo.ColumnOrdering,
	aggregations []exec.AggInfo,

	reqOrdering exec.OutputOrdering,

	groupingOrderType exec.GroupingOrderType,
) (exec.Node, error)

func (*PlanGistFactory) ConstructHashJoin

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

func (*PlanGistFactory) ConstructHashSetOp

func (f *PlanGistFactory) ConstructHashSetOp(
	typ tree.UnionType,
	all bool,
	left exec.Node,
	right exec.Node,
) (exec.Node, error)

func (*PlanGistFactory) ConstructIndexJoin

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

func (*PlanGistFactory) ConstructInsert

func (f *PlanGistFactory) ConstructInsert(
	input exec.Node,
	table cat.Table,
	arbiterIndexes cat.IndexOrdinals,
	arbiterConstraints cat.UniqueOrdinals,
	insertCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checkCols exec.CheckOrdinalSet,

	autoCommit bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructInsertFastPath

func (f *PlanGistFactory) ConstructInsertFastPath(
	rows [][]tree.TypedExpr,
	table cat.Table,
	insertCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checkCols exec.CheckOrdinalSet,
	fkChecks []exec.InsertFastPathFKCheck,

	autoCommit bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructInvertedFilter

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

func (*PlanGistFactory) ConstructInvertedJoin

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

func (*PlanGistFactory) ConstructLimit

func (f *PlanGistFactory) ConstructLimit(
	input exec.Node,
	limit tree.TypedExpr,
	offset tree.TypedExpr,
) (exec.Node, error)

func (*PlanGistFactory) ConstructLookupJoin

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

func (*PlanGistFactory) ConstructMax1Row

func (f *PlanGistFactory) ConstructMax1Row(
	input exec.Node,
	errorText string,
) (exec.Node, error)

func (*PlanGistFactory) ConstructMergeJoin

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

func (*PlanGistFactory) ConstructOpaque

func (f *PlanGistFactory) ConstructOpaque(
	metadata opt.OpaqueMetadata,
) (exec.Node, error)

func (*PlanGistFactory) ConstructOrdinality

func (f *PlanGistFactory) ConstructOrdinality(
	input exec.Node,
	colName string,
) (exec.Node, error)

func (*PlanGistFactory) ConstructPlan

func (f *PlanGistFactory) ConstructPlan(
	root exec.Node,
	subqueries []exec.Subquery,
	cascades []exec.Cascade,
	checks []exec.Node,
	rootRowCount int64,
) (exec.Plan, error)

ConstructPlan delegates to the wrapped factory.

func (*PlanGistFactory) ConstructProjectSet

func (f *PlanGistFactory) ConstructProjectSet(
	input exec.Node,
	exprs tree.TypedExprs,
	zipCols colinfo.ResultColumns,
	numColsPerGen []int,
) (exec.Node, error)

func (*PlanGistFactory) ConstructRecursiveCTE

func (f *PlanGistFactory) ConstructRecursiveCTE(
	initial exec.Node,
	fn exec.RecursiveCTEIterationFn,
	label string,
	deduplicate bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructRender

func (f *PlanGistFactory) ConstructRender(
	input exec.Node,
	columns colinfo.ResultColumns,
	exprs tree.TypedExprs,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*PlanGistFactory) ConstructSaveTable

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

func (*PlanGistFactory) ConstructScalarGroupBy

func (f *PlanGistFactory) ConstructScalarGroupBy(
	input exec.Node,
	aggregations []exec.AggInfo,
) (exec.Node, error)

func (*PlanGistFactory) ConstructScan

func (f *PlanGistFactory) ConstructScan(
	table cat.Table,
	index cat.Index,
	params exec.ScanParams,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*PlanGistFactory) ConstructScanBuffer

func (f *PlanGistFactory) ConstructScanBuffer(
	ref exec.Node,
	label string,
) (exec.Node, error)

func (*PlanGistFactory) ConstructSequenceSelect

func (f *PlanGistFactory) ConstructSequenceSelect(
	sequence cat.Sequence,
) (exec.Node, error)

func (*PlanGistFactory) ConstructSerializingProject

func (f *PlanGistFactory) ConstructSerializingProject(
	input exec.Node,
	cols []exec.NodeColumnOrdinal,
	colNames []string,
) (exec.Node, error)

func (*PlanGistFactory) ConstructShowTrace

func (f *PlanGistFactory) ConstructShowTrace(
	typ tree.ShowTraceType,
	compact bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructSimpleProject

func (f *PlanGistFactory) ConstructSimpleProject(
	input exec.Node,
	cols []exec.NodeColumnOrdinal,
	reqOrdering exec.OutputOrdering,
) (exec.Node, error)

func (*PlanGistFactory) ConstructSort

func (f *PlanGistFactory) ConstructSort(
	input exec.Node,
	ordering exec.OutputOrdering,
	alreadyOrderedPrefix int,
) (exec.Node, error)

func (*PlanGistFactory) ConstructStreamingSetOp

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

func (*PlanGistFactory) ConstructTopK

func (f *PlanGistFactory) ConstructTopK(
	input exec.Node,
	k int64,
	ordering exec.OutputOrdering,
	alreadyOrderedPrefix int,
) (exec.Node, error)

func (*PlanGistFactory) ConstructUnionAll

func (f *PlanGistFactory) ConstructUnionAll(
	left exec.Node,
	right exec.Node,
	reqOrdering exec.OutputOrdering,
	hardLimit uint64,
) (exec.Node, error)

func (*PlanGistFactory) ConstructUpdate

func (f *PlanGistFactory) ConstructUpdate(
	input exec.Node,
	table cat.Table,
	fetchCols exec.TableColumnOrdinalSet,
	updateCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checks exec.CheckOrdinalSet,
	passthrough colinfo.ResultColumns,

	autoCommit bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructUpsert

func (f *PlanGistFactory) ConstructUpsert(
	input exec.Node,
	table cat.Table,
	arbiterIndexes cat.IndexOrdinals,
	arbiterConstraints cat.UniqueOrdinals,
	canaryCol exec.NodeColumnOrdinal,
	insertCols exec.TableColumnOrdinalSet,
	fetchCols exec.TableColumnOrdinalSet,
	updateCols exec.TableColumnOrdinalSet,
	returnCols exec.TableColumnOrdinalSet,
	checks exec.CheckOrdinalSet,

	autoCommit bool,
) (exec.Node, error)

func (*PlanGistFactory) ConstructValues

func (f *PlanGistFactory) ConstructValues(
	rows [][]tree.TypedExpr,
	columns colinfo.ResultColumns,
) (exec.Node, error)

func (*PlanGistFactory) ConstructWindow

func (f *PlanGistFactory) ConstructWindow(
	input exec.Node,
	window exec.WindowInfo,
) (exec.Node, error)

func (*PlanGistFactory) ConstructZigzagJoin

func (f *PlanGistFactory) ConstructZigzagJoin(

	leftTable cat.Table,
	leftIndex cat.Index,

	leftCols exec.TableColumnOrdinalSet,

	leftFixedVals []tree.TypedExpr,

	leftEqCols []exec.TableColumnOrdinal,

	rightTable cat.Table,
	rightIndex cat.Index,

	rightCols exec.TableColumnOrdinalSet,

	rightFixedVals []tree.TypedExpr,

	rightEqCols []exec.TableColumnOrdinal,

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

func (*PlanGistFactory) PlanGist

func (f *PlanGistFactory) PlanGist() PlanGist

PlanGist returns a pointer to a PlanGist.

type RedactFlags

type RedactFlags uint8

RedactFlags control the redacting of various field values. They are used to guarantee deterministic results for testing purposes.

const (
	// RedactDistribution hides the value of the "distribution" field.
	RedactDistribution RedactFlags = (1 << iota)

	// RedactVectorized hides the value of the "vectorized" field.
	RedactVectorized

	// RedactNodes hides cluster nodes involved.
	RedactNodes

	// RedactVolatile hides any values that can vary from one query run to the
	// other, even without changes to the configuration or data distribution (e.g.
	// timings).
	RedactVolatile
)
const (
	// RedactAll has all redact flags set.
	RedactAll RedactFlags = RedactDistribution | RedactVectorized | RedactNodes | RedactVolatile
)

func (RedactFlags) Has

func (f RedactFlags) Has(flag RedactFlags) bool

Has returns true if the receiver has the given flag set.

type SpanFormatFn

type SpanFormatFn func(table cat.Table, index cat.Index, scanParams exec.ScanParams) string

SpanFormatFn is a function used to format spans for EXPLAIN. Only called on non-virtual tables, when there is an index constraint or an inverted constraint.

Jump to

Keyboard shortcuts

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