Documentation
¶
Overview ¶
Package explain decodes and safely executes PostgreSQL JSON EXPLAIN. Its NativePlan is PostgreSQL-specific and is never used as a common planner IR.
Index ¶
Constants ¶
const ExplainPrefix = "EXPLAIN (FORMAT JSON, VERBOSE TRUE, SETTINGS TRUE, COSTS TRUE) "
ExplainPrefix is the only EXPLAIN form executed by the library. It omits ANALYZE so SELECT and DML statements are planned but never executed.
Variables ¶
This section is empty.
Functions ¶
func Summarize ¶
func Summarize(plan *NativePlan) *analysis.NativeExplainSummary
Summarize projects a PostgreSQL NativePlan into the public display DTO. It does not feed rules or cost evaluation.
Types ¶
type NativePlan ¶
type NativePlan struct {
Version string
Settings []PlannerSetting
Root *PlanNode
RawJSON []byte
}
NativePlan is the complete PostgreSQL decoder output.
type NativeValue ¶
NativeValue distinguishes an absent attribute from an explicit zero or an invalid value. Consumers must check Valid before using Value. Present is true for malformed values (including JSON null); invalid values retain zero Value. Extraction never coerces numeric strings or changes the decoded plan.
type PlanNode ¶
type PlanNode struct {
Path string
NodeType string
ParentRelationship string
JoinType string
Operation string
RelationOID uint32
Schema string
Relation string
Alias string
IndexName string
ScanDirection string
StartupCost float64
TotalCost float64
PlanRows int64
PlanWidth int64
ParallelAware bool
Known bool
Conditions []Condition
SortKeys []SortKey
Children []*PlanNode
NativeAttrs map[string]json.RawMessage
}
PlanNode is one PostgreSQL-native plan node. Unknown nodes remain intact and are marked Known=false instead of being mapped to a familiar operator.
func (*PlanNode) Runtime ¶
func (node *PlanNode) Runtime() RuntimeStats
Runtime extracts independent, presence-aware fields from NativeAttrs without requiring ANALYZE, performing I/O, or mutating the caller's decoded plan. A malformed optional attribute invalidates only that attribute.
type PlannerSetting ¶
PlannerSetting is one setting reported diagnostically by EXPLAIN SETTINGS.
type RuntimeStats ¶
type RuntimeStats struct {
ActualRows NativeValue[float64]
ActualLoops NativeValue[uint64]
ActualTotalTime NativeValue[float64]
RowsRemovedByFilter NativeValue[float64]
RowsRemovedByIndexRecheck NativeValue[float64]
LossyHeapBlocks NativeValue[uint64]
ExactHeapBlocks NativeValue[uint64]
SortMethod NativeValue[string]
SortSpaceType NativeValue[string]
SortSpaceUsed NativeValue[uint64]
HashBatches NativeValue[uint64]
HashAggBatches NativeValue[uint64]
DiskUsage NativeValue[uint64]
TempReadBlocks NativeValue[uint64]
TempWrittenBlocks NativeValue[uint64]
PlanRows NativeValue[float64]
Strategy NativeValue[string]
InnerUnique NativeValue[bool]
RowsRemovedByJoinFilter NativeValue[float64]
HeapFetches NativeValue[uint64]
WorkersPlanned NativeValue[uint64]
WorkersLaunched NativeValue[uint64]
LocalHitBlocks NativeValue[uint64]
LocalReadBlocks NativeValue[uint64]
}
RuntimeStats is a typed view of node-level PostgreSQL 16/17 EXPLAIN evidence. ActualRows, row-removal counts, and ActualTotalTime (milliseconds) are averages per execution loop. PostgreSQL may round row averages. Block counts are accumulated counters; batch counts and space usage (kB) are node-reported measurements, not per-loop averages. None should be multiplied by loops. Temp block counts include children and alone cannot establish that this node spilled. Worker-only and Incremental Sort group statistics are not projected into node-level fields. PlanRows, Strategy, and InnerUnique retain planning context for runtime checks.
func (RuntimeStats) Executed ¶
func (stats RuntimeStats) Executed() bool
Executed reports whether valid, positive Actual Loops prove node execution. A missing or malformed Actual Rows value does not negate other runtime facts.