explain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package explain provides SQL EXPLAIN plan analysis. It connects to a live database to run EXPLAIN on queries and detect performance issues like sequential scans and high-cost operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*PlanAnalyzer)

Option configures a PlanAnalyzer.

func WithAllowDML

func WithAllowDML() Option

WithAllowDML permits EXPLAIN on INSERT/UPDATE/DELETE statements. It is OFF by default: only SELECT/WITH are explained, because feeding DML to a prod database — even under plain EXPLAIN — is a footgun (and EXPLAIN ANALYZE would execute it). When enabled, DML EXPLAINs still run inside a transaction that is always rolled back (see analyzePostgres/analyzeMySQL), so nothing is committed regardless.

type PlanAnalyzer

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

PlanAnalyzer runs EXPLAIN on queries against a live database.

func New

func New(db *sql.DB, dialect string, opts ...Option) (*PlanAnalyzer, error)

New creates a PlanAnalyzer for the given database connection. dialect must be "postgres" or "mysql".

func (*PlanAnalyzer) Analyze

func (p *PlanAnalyzer) Analyze(ctx context.Context, query string) (*Result, error)

Analyze runs EXPLAIN on the given query and returns detected issues. The query is validated (see validate) and the EXPLAIN is run inside an always-rolled-back transaction, so a query passed here cannot mutate the target database.

type Result

type Result struct {
	Query   string
	RawPlan string
	Issues  []analyzer.Result
}

Result holds the parsed EXPLAIN output and any detected issues.

Jump to

Keyboard shortcuts

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