plan

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plan reads PostgreSQL EXPLAIN output in JSON or text form.

Index

Constants

View Source
const (
	High   = "HIGH"
	Medium = "MEDIUM"
	Low    = "LOW"
)

Severity levels.

Variables

This section is empty.

Functions

func Label

func Label(node *Node) string

Label names a node the way a person would read it.

Types

type Comparison

type Comparison struct {
	BeforeMS      float64   `json:"before_ms"`
	AfterMS       float64   `json:"after_ms"`
	ChangePercent float64   `json:"change_percent"`
	Fixed         []Finding `json:"fixed"`
	New           []Finding `json:"new"`
	Remaining     []Finding `json:"remaining"`
	Notes         []string  `json:"notes"`
}

Comparison shows what changed between two runs of a query.

func Compare

func Compare(before, after *Plan) Comparison

Compare checks two plans of the same query, such as before and after adding an index.

type Finding

type Finding struct {
	ID       string  `json:"id"`
	Severity string  `json:"severity"`
	Node     string  `json:"node"`
	Message  string  `json:"message"`
	Fix      string  `json:"fix"`
	ImpactMS float64 `json:"impact_ms"`
}

Finding is one thing to look at. A plan shows symptoms, so fixes are candidates to test.

type Hot

type Hot struct {
	Node    string  `json:"node"`
	SelfMS  float64 `json:"self_ms"`
	Percent float64 `json:"percent"`
}

Hot is a node and the time spent in it, leaving out its children.

type Node

type Node struct {
	Type            string  `json:"Node Type"`
	Relation        string  `json:"Relation Name"`
	Alias           string  `json:"Alias"`
	Index           string  `json:"Index Name"`
	Filter          string  `json:"Filter"`
	PlanRows        float64 `json:"Plan Rows"`
	ActualRows      float64 `json:"Actual Rows"`
	Loops           float64 `json:"Actual Loops"`
	TotalTime       float64 `json:"Actual Total Time"`
	RemovedByFilter float64 `json:"Rows Removed by Filter"`
	RemovedByJoin   float64 `json:"Rows Removed by Join Filter"`
	RemovedByCheck  float64 `json:"Rows Removed by Index Recheck"`
	SortMethod      string  `json:"Sort Method"`
	SortSpaceType   string  `json:"Sort Space Type"`
	SortSpaceKB     float64 `json:"Sort Space Used"`
	HashBatches     float64 `json:"Hash Batches"`
	PeakMemoryKB    float64 `json:"Peak Memory Usage"`
	WorkersPlanned  float64 `json:"Workers Planned"`
	WorkersLaunched float64 `json:"Workers Launched"`
	HeapFetches     float64 `json:"Heap Fetches"`
	LossyBlocks     float64 `json:"Lossy Heap Blocks"`
	SharedRead      float64 `json:"Shared Read Blocks"`
	Children        []*Node `json:"Plans"`
	Analyzed        bool    `json:"-"`
}

Node is one step of a plan. Times, rows and removed rows are per loop, as Postgres reports them.

type Plan

type Plan struct {
	Root       *Node
	PlanningMS float64
	ExecMS     float64
	JITMS      float64
	HasBuffers bool
	Format     string
}

Plan is one whole EXPLAIN result.

func Parse

func Parse(input string) (*Plan, error)

Parse accepts EXPLAIN JSON, auto_explain JSON or EXPLAIN text.

type Review

type Review struct {
	Analyzed    bool      `json:"analyzed"`
	ExecutionMS float64   `json:"execution_ms"`
	PlanningMS  float64   `json:"planning_ms"`
	Hottest     []Hot     `json:"hottest"`
	Findings    []Finding `json:"findings"`
	Notes       []string  `json:"notes"`
}

Review is the result for one plan.

func Analyze

func Analyze(plan *Plan) Review

Analyze turns a plan into ranked findings.

Jump to

Keyboard shortcuts

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