explain

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package explain turns a server's JSON query plan into something readable.

It knows nothing about tview and nothing about a connection: bytes in, a tree and then lines out. What it deliberately does not know is the plan's schema.

MySQL and MariaDB disagree about that schema, and both change it between versions — MariaDB nests a sort under "read_sorted_file" and a group under "temporary_table", MySQL under "ordering_operation" and "grouping_operation", and neither list is fixed. So the walk is generic: an object's scalar fields are that step's attributes and its object and array fields are its children. What appears on screen is then what the server said, rather than what this package assumed it would say.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(n *Node, width int) string

Render draws the plan as a tree, wrapped to fit width.

Fitting is the whole point rather than a nicety. The reason EXPLAIN is hard to read in a grid is that it is a dozen narrow columns spread sideways, and a tree that overflows has reinvented the problem in a different shape — so nothing here is allowed to reach past the width it was given.

Types

type Attr

type Attr struct {
	Key   string
	Value string
}

Attr is one scalar field of a step.

type Node

type Node struct {
	// Name is the key the server nested this step under — "query_block",
	// "filesort", "table" — or the table's own name where it has one, since
	// "table" says less than "dv_x_books".
	Name string
	// Attrs are the step's scalar fields, in the order they are worth reading
	// rather than the order they arrived.
	Attrs    []Attr
	Children []*Node
	// Warnings name what will make this step slow, in the words a DBA would
	// use rather than the server's.
	Warnings []string
	// contains filtered or unexported fields
}

Node is one step of a plan.

func Parse

func Parse(data []byte) (*Node, error)

Parse reads a plan from EXPLAIN FORMAT=JSON.

func (*Node) Attr

func (n *Node) Attr(key string) string

Attr returns a field's value, or "" when the step has no such field.

Jump to

Keyboard shortcuts

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