pgplan

package
v0.0.0-...-78c55be Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agg

type Agg struct{ Plan }

func (Agg) Kind

func (Agg) Kind() NodeKind

type Append

type Append struct{ Plan }

Generate the concatenation of the results of sub-plans. Combine the results of the child operations. This can be the result of an explicit UNION ALL statement, or the need for a parent operation to consume the results of two or more children together. https://www.pgmustard.com/docs/explain/append

func (Append) Kind

func (Append) Kind() NodeKind

type BadNode

type BadNode struct{ Plan }

BadNode is returned whenever a plan is not parseable.

func (BadNode) Kind

func (BadNode) Kind() NodeKind

type BitmapAnd

type BitmapAnd struct{ Plan }

func (BitmapAnd) Kind

func (BitmapAnd) Kind() NodeKind

type BitmapHeapScan

type BitmapHeapScan struct{ Plan }

func (BitmapHeapScan) Kind

func (BitmapHeapScan) Kind() NodeKind

type BitmapIndexScan

type BitmapIndexScan struct{ Plan }

func (BitmapIndexScan) Kind

func (BitmapIndexScan) Kind() NodeKind

type BitmapOr

type BitmapOr struct{ Plan }

func (BitmapOr) Kind

func (BitmapOr) Kind() NodeKind

type CteScan

type CteScan struct{ Plan }

func (CteScan) Kind

func (CteScan) Kind() NodeKind

type CustomScan

type CustomScan struct{ Plan }

func (CustomScan) Kind

func (CustomScan) Kind() NodeKind

type ForeignScan

type ForeignScan struct{ Plan }

func (ForeignScan) Kind

func (ForeignScan) Kind() NodeKind

type FunctionScan

type FunctionScan struct{ Plan }

func (FunctionScan) Kind

func (FunctionScan) Kind() NodeKind

type Gather

type Gather struct{ Plan }

func (Gather) Kind

func (Gather) Kind() NodeKind

type GatherMerge

type GatherMerge struct{ Plan }

func (GatherMerge) Kind

func (GatherMerge) Kind() NodeKind

type Group

type Group struct{ Plan }

func (Group) Kind

func (Group) Kind() NodeKind

type Hash

type Hash struct{ Plan }

func (Hash) Kind

func (Hash) Kind() NodeKind

type HashJoin

type HashJoin struct{ Plan }

func (HashJoin) Kind

func (HashJoin) Kind() NodeKind

type IncrementalSort

type IncrementalSort struct{ Plan }

func (IncrementalSort) Kind

func (IncrementalSort) Kind() NodeKind

type IndexOnlyScan

type IndexOnlyScan struct{ Plan }

func (IndexOnlyScan) Kind

func (IndexOnlyScan) Kind() NodeKind

type IndexScan

type IndexScan struct{ Plan }

func (IndexScan) Kind

func (IndexScan) Kind() NodeKind

type Join

type Join struct{ Plan }

func (Join) Kind

func (Join) Kind() NodeKind

type Limit

type Limit struct{ Plan }

func (Limit) Kind

func (Limit) Kind() NodeKind

type LockRows

type LockRows struct{ Plan }

func (LockRows) Kind

func (LockRows) Kind() NodeKind

type Material

type Material struct{ Plan }

func (Material) Kind

func (Material) Kind() NodeKind

type MergeAppend

type MergeAppend struct {
	Plan
	SortKey []string
}

Combines the sorted results of the child operations, in a way that preserves their sort order. Can be used for combining already-sorted rows from table partitions. https://www.pgmustard.com/docs/explain/merge-append

func (MergeAppend) Kind

func (MergeAppend) Kind() NodeKind

type MergeJoin

type MergeJoin struct{ Plan }

func (MergeJoin) Kind

func (MergeJoin) Kind() NodeKind

type ModifyTable

type ModifyTable struct {
	Plan
	Operation    Operation
	RelationName string
	Schema       string
	Alias        string
}

Apply rows produced by subplan(s) to result table(s), by inserting, updating, or deleting.

func (ModifyTable) Kind

func (ModifyTable) Kind() NodeKind

type NamedTuplestoreScan

type NamedTuplestoreScan struct{ Plan }

func (NamedTuplestoreScan) Kind

type NestLoop

type NestLoop struct{ Plan }

func (NestLoop) Kind

func (NestLoop) Kind() NodeKind

type Node

type Node interface {
	Kind() NodeKind
	// Output returns the output columns of the node. The format of each output
	// column depends on the type of node.
	Output() []string
	// Children returns the direct children of the node, or nil if none exist.
	Children() []Node
}

Node is the super-type of all Postgres plan nodes. https://doxygen.postgresql.org/nodes_8h.html#a83ba1e84fa23f6619c3d29036b160919

func ExplainQuery

func ExplainQuery(conn *pgx.Conn, sql string) (Node, error)

ExplainQuery executes an explain query and parses the plan.

func ParseNode

func ParseNode(rawPlan map[string]interface{}) (Node, error)

type NodeKind

type NodeKind string

NodeKind is the top-level node plan type that Postgres plans for executing query. https://www.postgresql.org/docs/13/executor.html

const (
	KindBadNode             NodeKind = "BadNode"
	KindResult              NodeKind = "Result"
	KindProjectSet          NodeKind = "ProjectSet"
	KindModifyTable         NodeKind = "ModifyTable"
	KindAppend              NodeKind = "Append"
	KindMergeAppend         NodeKind = "MergeAppend"
	KindRecursiveUnion      NodeKind = "RecursiveUnion"
	KindBitmapAnd           NodeKind = "BitmapAnd"
	KindBitmapOr            NodeKind = "BitmapOr"
	KindScan                NodeKind = "Scan"
	KindSeqScan             NodeKind = "SeqScan"
	KindSampleScan          NodeKind = "SampleScan"
	KindIndexScan           NodeKind = "IndexScan"
	KindIndexOnlyScan       NodeKind = "IndexOnlyScan"
	KindBitmapIndexScan     NodeKind = "BitmapIndexScan"
	KindBitmapHeapScan      NodeKind = "BitmapHeapScan"
	KindTidScan             NodeKind = "TidScan"
	KindSubqueryScan        NodeKind = "SubqueryScan"
	KindFunctionScan        NodeKind = "FunctionScan"
	KindValuesScan          NodeKind = "ValuesScan"
	KindTableFuncScan       NodeKind = "TableFuncScan"
	KindCteScan             NodeKind = "CteScan"
	KindNamedTuplestoreScan NodeKind = "NamedTuplestoreScan"
	KindWorkTableScan       NodeKind = "WorkTableScan"
	KindForeignScan         NodeKind = "ForeignScan"
	KindCustomScan          NodeKind = "CustomScan"
	KindJoin                NodeKind = "Join"
	KindNestLoop            NodeKind = "NestLoop"
	KindMergeJoin           NodeKind = "MergeJoin"
	KindHashJoin            NodeKind = "HashJoin"
	KindMaterial            NodeKind = "Material"
	KindSort                NodeKind = "Sort"
	KindIncrementalSort     NodeKind = "IncrementalSort"
	KindGroup               NodeKind = "Group"
	KindAgg                 NodeKind = "Agg"
	KindWindowAgg           NodeKind = "WindowAgg"
	KindUnique              NodeKind = "Unique"
	KindGather              NodeKind = "Gather"
	KindGatherMerge         NodeKind = "GatherMerge"
	KindHash                NodeKind = "Hash"
	KindSetOp               NodeKind = "SetOp"
	KindLockRows            NodeKind = "LockRows"
	KindLimit               NodeKind = "Limit"
)

type Operation

type Operation string

Operation for a ModifyTable node.

const (
	OperationInsert Operation = "Insert"
	OperationUpdate Operation = "Update"
	OperationDelete Operation = "Delete"
)

type ParentRelationship

type ParentRelationship string

ParentRelationship describes why this operation needs to be run in order to facilitate the parent operation.

const (
	// Means this node is a top-level node. All nodes with a parent have set
	// relationship that is not none.
	ParentRelationshipNone ParentRelationship = ""
	// Most common: means take in the rows from this operation as input, process
	// them and pass them on.
	ParentRelationshipOuter ParentRelationship = "Outer"
	// Only (but always) on second child of join operations. Means a node is the
	// inner part of a loop.
	ParentRelationshipInner ParentRelationship = "Inner"
	// Member is for all children of Append and ModifyTable nodes.
	ParentRelationshipMember ParentRelationship = "Member"
	// InitPlan is calculations performed before query starts executing.
	ParentRelationshipInitPlan ParentRelationship = "InitPlan"
	// Subquery means the node is a subquery of a parent node. Since Postgres
	// always uses subquery scans to feed subquery data to parent queries, only
	// ever appears on the children of subquery scans.
	ParentRelationshipSubquery ParentRelationship = "Subquery"
	// Like a Subquery, represents a new query, but used when a subquery scan is
	// not necessary.
	ParentRelationshipSubPlan ParentRelationship = "SubPlan"
)

type Plan

type Plan struct {
	// Estimated execution costs for plan (see costsize.c for more info).
	StartupCost float64 // cost expended before fetching any tuples
	TotalCost   float64 // total cost (assuming all tuples fetched)

	// Planner's estimate of result size of this plan step.
	PlanRows  float64 // number of rows plan is expected to emit
	PlanWidth int     // average row width in bytes

	// Information needed for parallel query.
	ParallelAware bool // engage parallel-aware logic?
	ParallelSafe  bool // OK to use as part of parallel plan?

	// Relationship from this node to its parent. Always set for descendant nodes.
	ParentRelationship ParentRelationship

	// How to execute a node. Used for Agg and SetOp nodes.
	Strategy Strategy

	// Custom plan, if any.
	CustomPlanProvider string

	// The column expressions (target list), if any.
	Outs []string

	// Child nodes, if any.
	Nodes []Node
}

All plan nodes "derive" from the Plan structure by having the Plan structure as the first field. This ensures that everything works when nodes are cast to Plan's. (node pointers are frequently cast to Plan* when passed around generically in the executor) https://sourcegraph.com/github.com/postgres/postgres@8facf1ea00b7a0c08c755a0392212b83e04ae28a/-/blob/src/include/nodes/plannodes.h#L110:16

func (Plan) Children

func (p Plan) Children() []Node

func (Plan) Output

func (p Plan) Output() []string

type ProjectSet

type ProjectSet struct{ Plan }

ProjectSet appears when the SELECT or ORDER BY clause of the query. They basically just execute the set-returning function(s) for each tuple until none of the functions return any more records. https://www.postgresql.org/message-id/CAKJS1f9pWUwxaD%2B0kxOOUuwaBcpGQtCKi3DKE8ob_uHN-JTJhw%40mail.gmail.com

func (ProjectSet) Kind

func (ProjectSet) Kind() NodeKind

type RecursiveUnion

type RecursiveUnion struct{ Plan }

func (RecursiveUnion) Kind

func (RecursiveUnion) Kind() NodeKind

type Result

type Result struct{ Plan }

If no outer plan, evaluate a variable-free targetlist. If outer plan, return tuples from outer plan (after a level of projection as shown by targetlist). https://sourcegraph.com/github.com/postgres/postgres@8facf1ea00b7a0c08c755a0392212b83e04ae28a/-/blob/src/include/nodes/plannodes.h#L180:1

func (Result) Kind

func (Result) Kind() NodeKind

type SampleScan

type SampleScan struct{ Plan }

func (SampleScan) Kind

func (SampleScan) Kind() NodeKind

type Scan

type Scan struct{ Plan }

func (Scan) Kind

func (Scan) Kind() NodeKind

type SeqScan

type SeqScan struct{ Plan }

func (SeqScan) Kind

func (SeqScan) Kind() NodeKind

type SetOp

type SetOp struct{ Plan }

func (SetOp) Kind

func (SetOp) Kind() NodeKind

type Sort

type Sort struct {
	Plan
	SortKey []string
}

func (Sort) Kind

func (Sort) Kind() NodeKind

type Strategy

type Strategy string

Strategy determines overall execution strategies for Agg plan nodes and SetOp nodes. https://sourcegraph.com/github.com/postgres/postgres@8facf1ea00b7a0c08c755a0392212b83e04ae28a/-/blob/src/include/nodes/nodes.h?subtree=true#L759:14

const (
	// Simple agg across all input rows.
	StrategyPlain Strategy = "Plain"
	// For grouped agg and SetOp, input must be sorted.
	StrategySorted Strategy = "Sorted"
	// For grouped agg and SetOp, uses internal hashtable.
	StrategyHashed Strategy = "Hashed"
	// Grouped agg, hash and sort both used.
	StrategyMixed Strategy = "Mixed"
	// For unknown aggregates.
	StrategyUnknown Strategy = "???"
)

type SubqueryScan

type SubqueryScan struct{ Plan }

func (SubqueryScan) Kind

func (SubqueryScan) Kind() NodeKind

type TableFuncScan

type TableFuncScan struct{ Plan }

func (TableFuncScan) Kind

func (TableFuncScan) Kind() NodeKind

type TidScan

type TidScan struct{ Plan }

func (TidScan) Kind

func (TidScan) Kind() NodeKind

type Unique

type Unique struct{ Plan }

Unique is a very simple node type that just filters out duplicate tuples from a stream of sorted tuples from its subplan. https://sourcegraph.com/github.com/postgres/postgres@8facf1ea00b7a0c08c755a0392212b83e04ae28a/-/blob/src/include/nodes/plannodes.h?subtree=true#L864:16

func (Unique) Kind

func (Unique) Kind() NodeKind

type ValuesScan

type ValuesScan struct{ Plan }

func (ValuesScan) Kind

func (ValuesScan) Kind() NodeKind

type WindowAgg

type WindowAgg struct{ Plan }

func (WindowAgg) Kind

func (WindowAgg) Kind() NodeKind

type WorkTableScan

type WorkTableScan struct{ Plan }

func (WorkTableScan) Kind

func (WorkTableScan) Kind() NodeKind

Jump to

Keyboard shortcuts

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