Documentation
¶
Overview ¶
Package sqlgen generates random-but-valid SQL queries over a described schema, for differential testing (#288). Generation is fully determined by the seed — a failing seed IS the repro — and is weighted toward the shapes that have historically produced distributed-mode divergence: aggregate-free GROUP BY (#163/#166), DISTINCT (#163), expressions in the SELECT list past a shuffle (#169/#273), and scalar-subquery thresholds in HAVING (#272).
The generator builds a structured Query first and renders SQL from it, so a failure can be shrunk structurally (see Shrink) instead of by text mutation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
Column is one generatable column. Lits are rendered SQL literals drawn from the column's actual domain; columns with no Lits appear in select lists and GROUP BY but never in predicates.
type Edge ¶
Edge is a joinable equality between two tables (FK pairs in practice — arbitrary column pairs explode row counts without exercising anything new).
type Gen ¶
type Gen struct {
// contains filtered or unexported fields
}
Gen is a seeded query generator.
type Query ¶
type Query struct {
Distinct bool
Select []string // rendered select items (aggregates already aliased)
Tables []string // FROM chain: Tables[0] base, rest joined via On
On []string // join conditions; On[i] joins Tables[i+1]
Where []string // conjuncts
GroupBy []string
Having string
OrderBy []string
Limit int
Offset int
// LimitZero renders `LIMIT 0`. Zero is how Limit spells "no LIMIT", so
// the one value with a rule of its own needed a field of its own (#487).
LimitZero bool
}
Query is a structured query: rendered clause fragments plus enough structure for Shrink to remove parts and keep the query valid.
func Shrink ¶
Shrink reduces q to a smaller query for which fails still returns true (fails = "still reproduces the divergence"). It repeatedly tries structural removals — LIMIT, ORDER BY, HAVING, DISTINCT, individual WHERE conjuncts, individual select/GROUP BY items, and unreferenced trailing joins — accepting any removal that keeps the failure, until a full pass removes nothing. The result is the minimal repro to report.