pgexplain

package
v0.11.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package pgexplain provides tools for Postgres explain processing.

Index

Constants

View Source
const (
	Limit           NodeType = "Limit"
	Append                   = "Append"
	Sort                     = "Sort"
	NestedLoop               = "Nested Loop"
	MergeJoin                = "Merge Join"
	Hash                     = "Hash"
	HashJoin                 = "Hash Join"
	Aggregate                = "Aggregate"
	Hashaggregate            = "Hashaggregate"
	SequenceScan             = "Seq Scan"
	IndexScan                = "Index Scan"
	IndexOnlyScan            = "Index Only Scan"
	BitmapHeapScan           = "Bitmap Heap Scan"
	BitmapIndexScan          = "Bitmap Index Scan"
	CTEScan                  = "CTE Scan"
	FunctionScan             = "Function Scan"
	SubqueryScan             = "Subquery Scan"
	ValuesScan               = "Values Scan"
	ModifyTable              = "Modify Table"
)
View Source
const (
	Byte = 1 << (iota * 10)
	KiByte
	MiByte
	GiByte
	TiByte
	PiByte
	EiByte
)

IEC Sizes. kibis of bits.

View Source
const (
	IByte = 1
	KByte = IByte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
	PByte = TByte * 1000
	EByte = PByte * 1000
)

SI Sizes.

Variables

This section is empty.

Functions

func Bytes

func Bytes(s uint64, f string) string

Bytes produces a human readable representation of an SI size. Bytes(82854982) -> 83 MB

func IBytes

func IBytes(s uint64, f string) string

IBytes produces a human readable representation of an IEC size. IBytes(82854982) -> 79 MiB

Types

type EstimateDirection

type EstimateDirection string
const (
	Over  EstimateDirection = "Over"
	Under                   = "Under"
)

type Explain

type Explain struct {
	Plan     Plan      `json:"Plan"`
	Triggers []Trigger `json:"Triggers"`

	QueryIdentifier uint64            `json:"Query Identifier"`
	Settings        map[string]string `json:"Settings"`
	PlanningTime    float64           `json:"Planning Time"`
	ExecutionTime   float64           `json:"Execution Time"`
	TotalTime       float64

	TotalCost float64

	// Buffers.
	SharedHitBlocks     uint64
	SharedDirtiedBlocks uint64
	SharedReadBlocks    uint64
	SharedWrittenBlocks uint64
	LocalHitBlocks      uint64
	LocalReadBlocks     uint64
	LocalDirtiedBlocks  uint64
	LocalWrittenBlocks  uint64
	TempReadBlocks      uint64
	TempWrittenBlocks   uint64

	// IO timing.
	IOReadTime  *float64
	IOWriteTime *float64

	ActualRows      uint64
	MaxRows         uint64
	MaxCost         float64
	MaxDuration     float64
	ContainsSeqScan bool
}

func NewExplain

func NewExplain(explainJSON string) (*Explain, error)

Explain Processing.

func (*Explain) RenderPlanText

func (ex *Explain) RenderPlanText() string

func (*Explain) RenderStats

func (ex *Explain) RenderStats() string

type NodeType

type NodeType string

type Plan

type Plan struct {
	Plans []Plan `json:"Plans"`

	// Buffers.
	SharedHitBlocks     uint64 `json:"Shared Hit Blocks"`
	SharedReadBlocks    uint64 `json:"Shared Read Blocks"`
	SharedDirtiedBlocks uint64 `json:"Shared Dirtied Blocks"`
	SharedWrittenBlocks uint64 `json:"Shared Written Blocks"`
	LocalHitBlocks      uint64 `json:"Local Hit Blocks"`
	LocalReadBlocks     uint64 `json:"Local Read Blocks"`
	LocalDirtiedBlocks  uint64 `json:"Local Dirtied Blocks"`
	LocalWrittenBlocks  uint64 `json:"Local Written Blocks"`
	TempReadBlocks      uint64 `json:"Temp Read Blocks"`
	TempWrittenBlocks   uint64 `json:"Temp Written Blocks"`

	// IO timing.
	IOReadTime  *float64 `json:"I/O Read Time,omitempty"`  // ms
	IOWriteTime *float64 `json:"I/O Write Time,omitempty"` // ms

	// Actual.
	ActualLoops       uint64  `json:"Actual Loops"`
	ActualRows        uint64  `json:"Actual Rows"`
	ActualStartupTime float64 `json:"Actual Startup Time"`
	ActualTotalTime   float64 `json:"Actual Total Time"`

	// Estimates.
	PlanRows    uint64  `json:"Plan Rows"`
	PlanWidth   uint64  `json:"Plan Width"`
	StartupCost float64 `json:"Startup Cost"`
	TotalCost   float64 `json:"Total Cost"`

	// WAL.
	WALRecords uint64 `json:"WAL Records,omitempty"`
	WALFPI     uint64 `json:"WAL FPI,omitempty"`
	WALBytes   uint64 `json:"WAL Bytes,omitempty"`

	// General.
	Alias                     string   `json:"Alias"`
	CteName                   string   `json:"CTE Name"`
	Filter                    string   `json:"Filter"`
	FunctionName              string   `json:"Function Name"`
	GroupKey                  []string `json:"Group Key"`
	HashBatches               uint64   `json:"Hash Batches"`
	HashBuckets               uint64   `json:"Hash Buckets"`
	HashCondition             string   `json:"Hash Cond"`
	HeapFetches               uint64   `json:"Heap Fetches"`
	IndexCondition            string   `json:"Index Cond"`
	IndexName                 string   `json:"Index Name"`
	MergeCondition            string   `json:"Merge Cond"`
	JoinType                  string   `json:"Join Type"`
	NodeType                  NodeType `json:"Node Type"`
	Operation                 string   `json:"Operation"`
	OriginalHashBatches       uint64   `json:"Original Hash Batches"`
	OriginalHashBuckets       uint64   `json:"Original Hash Buckets"`
	Output                    []string `json:"Output"`
	ParallelAware             bool     `json:"Parallel Aware"`
	ParentRelationship        string   `json:"Parent Relationship"`
	PeakMemoryUsage           uint64   `json:"Peak Memory Usage"` // kB
	RelationName              string   `json:"Relation Name"`
	RowsRemovedByFilter       uint64   `json:"Rows Removed by Filter"`
	RowsRemovedByIndexRecheck uint64   `json:"Rows Removed by Index Recheck"`
	ScanDirection             string   `json:"Scan Direction"`
	Schema                    string   `json:"Schema"`
	SortKey                   []string `json:"Sort Key"`
	SortMethod                string   `json:"Sort Method"`
	SortSpaceType             string   `json:"Sort Space Type"`
	SortSpaceUsed             uint64   `json:"Sort Space Used"` // kB
	Strategy                  string   `json:"Strategy"`
	SubplanName               string   `json:"Subplan Name"`
	WorkersLaunched           uint     `json:"Workers Launched"`
	WorkersPlanned            uint     `json:"Workers Planned"`

	// Calculated params.
	ActualCost                  float64
	ActualDuration              float64
	Costliest                   bool
	Largest                     bool
	PlannerRowEstimateDirection EstimateDirection
	PlannerRowEstimateFactor    float64
	Slowest                     bool
}

type Tip

type Tip struct {
	Code        string `yaml:"code"`
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	DetailsUrl  string `yaml:"detailsUrl"`
}

type Trigger

type Trigger struct {
	Name           string  `json:"Trigger Name"`
	ConstraintName string  `json:"Constraint Name"`
	Relation       string  `json:"Relation"`
	Time           float64 `json:"Time"`
	Calls          uint64  `json:"Calls"`
}

Trigger describes triggers in the explain output.

Jump to

Keyboard shortcuts

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