equiv

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package equiv implements a build-time DIFFERENTIAL equivalence gate for the optional-filters feature. Given a canonical query (with N optional equality clauses) and the 2^N constant-folded variants produced by the analyzer, it proves each variant equivalent to the canonical query by EXECUTING BOTH against a fresh in-process modernc SQLite seeded with a small deterministic dataset and asserting identical result rows.

This is differential (empirical) equivalence, NOT formal/SMT equivalence: it demonstrates the variant and the canonical agree on the seeded sample (which is chosen to cover NULL/non-NULL and boundary values for the filtered columns), and catches the realistic fold bugs (a dropped predicate, a wrong comparison operator, an off-by-one boundary). It does not prove equivalence over all possible databases. The seed is fully deterministic — no randomness — so a pass or failure is reproducible and the build is stable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mismatch

type Mismatch struct {
	Mask      int
	Trial     string
	Canonical []string
	Variant   []string
}

Mismatch records a single divergence between a variant and the canonical query.

type Param

type Param struct {
	// Name is the SQL named-param name (without the leading "@"), e.g. "min_age".
	Name string
	// Column is the filtered column the param compares against, e.g. "age". Used to
	// pick boundary trial values from the seeded data.
	Column string
	// GoType is the resolved Go scalar type, used to choose representative trial
	// values ("string" vs integer vs float).
	GoType string
}

Param is one optional equality-filter param.

type Report

type Report struct {
	Mismatches []Mismatch
}

Report is the result of Check: a (possibly empty) list of mismatches.

func Check

func Check(ctx context.Context, catalog *model.Catalog, spec Spec) (*Report, error)

Check runs the differential equivalence gate for spec against catalog. It opens a fresh in-memory SQLite, loads the catalog DDL, seeds a deterministic sample dataset, then for each variant runs canonical-vs-variant over a set of trial param values and records any divergence. A non-nil error means the check could not be performed (e.g. a SQL prepare error); rows differing is reported via the Report, not the error.

func (*Report) OK

func (r *Report) OK() bool

OK reports whether every variant matched the canonical query on every trial.

func (*Report) String

func (r *Report) String() string

String renders the mismatches for diagnostics.

type Spec

type Spec struct {
	// CanonicalSQL is the original query with all N optional clauses present, using
	// @name-style named params for the optional filters (and any required params).
	CanonicalSQL string
	// Optional lists the optional equality-filter params, in bit order: bit i of a
	// variant Mask corresponds to Optional[i].
	Optional []Param
	// Variants are the constant-folded variants, one per subset of Optional.
	Variants []Variant
}

Spec is the input to Check: a canonical query plus its folded variants and the optional params they fold over.

type Variant

type Variant struct {
	// Mask identifies the subset of Optional present in this variant.
	Mask int
	// SQL is the folded statement referencing only the present optional params.
	SQL string
	// Present are the names (matching Param.Name) of the optional params kept in
	// this variant, in bind order.
	Present []string
}

Variant is one constant-folded SQL variant.

Jump to

Keyboard shortcuts

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