weight

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package weight turns a normalised engine plan into a verdict: OK, WARN or REFUSE. One cost model serves every engine:

  • the tables of a group form one nested-loop pipeline, so the rows examined by the group are the product of their estimates;
  • the child groups of a group (subqueries, derived tables, compound arms, the inner side of a hash join) add their cost, multiplied by the rows of the group's pipeline when they are correlated;
  • REFUSE when the estimate exceeds explain_rows_refuse, when one full scan reads more than that, or on a cartesian join whose estimate is above explain_rows_warn;
  • WARN when the estimate exceeds explain_rows_warn, on a full scan above it, on a sort or a temporary table above it, on a smaller cartesian join, and, on a production profile, on a full scan of a table whose size the engine does not know.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int

Level is the outcome of the weight check, ordered by severity.

const (
	// OK runs after the usual approval.
	OK Level = iota
	// Warn shows the reasons to the human before the approval.
	Warn
	// Refuse is final: the human loosens the limits to get past it.
	Refuse
)

func (Level) MarshalText

func (l Level) MarshalText() ([]byte, error)

MarshalText makes a Level show as "OK", "WARN" or "REFUSE" in JSON.

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(b []byte) error

UnmarshalText parses the names written by MarshalText.

type Verdict

type Verdict struct {
	Level Level `json:"level"`
	// Reasons explains every finding that raised the level, most severe
	// threshold first in the order found. It is empty for a plain OK.
	Reasons []string `json:"reasons"`
	// Summary is one line for the approval prompt: each table with its
	// access and estimated rows, the sorts and temporary tables, and the
	// estimate, e.g. "big full ~50 000 · sort · est. 50 000 rows examined".
	Summary string `json:"summary"`
	// EstimatedRows is the estimated number of rows examined, saturated at
	// math.MaxInt64. Tables of unknown size count as one row.
	EstimatedRows int64 `json:"estimated_rows"`
}

Verdict is the result of Assess.

func Assess

func Assess(p engine.Plan, l config.Limits, production bool) Verdict

Assess applies the cost model to p. Thresholds of l that are not set (zero or negative) take the defaults for the profile kind, so that a missing limit never disables the check. production turns a full scan of a table of unknown size into a WARN.

Jump to

Keyboard shortcuts

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