postgresqltestworkload

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgresqltestworkload defines the shared, versioned SQL workload used by PostgreSQL integration tests, offline replay, and physical-plan benchmarks.

Index

Constants

View Source
const DiversityNull = "<NULL>"

DiversityNull is the unambiguous NULL marker used by the SQL result oracle. The deterministic seed never contains this text as a stored value.

Variables

This section is empty.

Functions

func CanonicalMigrationSetupSQL

func CanonicalMigrationSetupSQL() []string

CanonicalMigrationSetupSQL returns deterministic DDL and seed DML for the caller's already selected disposable schema. It neither creates a schema nor changes search_path. Events exercise generated JSON attributes, NULL user IDs, recursive branching and range partition pruning with out-of-range rows.

func DiversitySetupSQL

func DiversitySetupSQL() []string

DiversitySetupSQL returns fresh, deterministic table and seed statements. The caller must first select its explicitly authorized disposable schema. These statements do not create schemas, change search_path, or clean up.

func PhysicalDesignEvaluation

func PhysicalDesignEvaluation(report *analysis.AnalyzeResult) *analysis.EvaluationReport

PhysicalDesignEvaluation resolves exactly one physical comparison, preferring a recommendation's explicit evidence identity over an arbitrary first plan.

func RealStatsMigrationSeedCount

func RealStatsMigrationSeedCount() int

RealStatsMigrationSeedCount is the exact nonempty seed cardinality to assert before running any native EXPLAIN or SELECT contract.

func RealStatsMigrationSetupSQL

func RealStatsMigrationSetupSQL() []string

RealStatsMigrationSetupSQL creates only the original five-column table and deterministic rows in the caller's disposable schema. Unlike the source's NOT NULL predicates, nullable columns also exercise three-valued logic. There is no name column in the source table or any of these 43 SELECTs. Collation C gives the synthetic city labels a reproducible bytewise order. No schema, search_path, clock-derived value, ANALYZE or secondary index is created here; the native harness owns isolation, statistics and index tests.

Types

type CandidateIndex

type CandidateIndex struct {
	Table   string     `yaml:"table" json:"table"`
	Name    string     `yaml:"name" json:"name"`
	Method  string     `yaml:"method" json:"method"`
	Keys    []IndexKey `yaml:"keys" json:"keys"`
	Include []string   `yaml:"include,omitempty" json:"include,omitempty"`
}

CandidateIndex is a value-independent persistent PostgreSQL index design.

func (CandidateIndex) Fingerprint

func (candidate CandidateIndex) Fingerprint() string

Fingerprint returns a stable physical-design identity. JSON struct field order is fixed and no maps participate in the digest.

type CanonicalMigrationContract

type CanonicalMigrationContract struct {
	ID           string     `json:"id"`
	Source       string     `json:"source"`
	SQL          string     `json:"sql"`
	ExpectedRows [][]string `json:"expected_rows"`
	Ordered      bool       `json:"ordered"`
	QueryBlocks  int        `json:"query_blocks"`
	Relations    []string   `json:"relations"`
	NativeNodes  []string   `json:"native_nodes"`
}

CanonicalMigrationContract retains the independent namespace and native operator expectations for a migrated canonical query. Relations includes each physical occurrence (including self joins), never CTE consumer names.

func CanonicalMigrationContracts

func CanonicalMigrationContracts() []CanonicalMigrationContract

CanonicalMigrationContracts returns fresh reviewed SQL/result/plan contracts. The 49 SELECTs preserve the MySQL workload's joins, projection, aggregate, correlation, CTE and window structure. Constants are scaled to small data; HAVING aliases become aggregate expressions, DESC explicitly places NULLs last, and unique tie breakers make peer ordering deterministic. The two MySQL UPDATE/DELETE ORDER BY LIMIT statements are separately rejection-tested. Results were independently enumerated from the seed using relational arithmetic, without calling PostgreSQL or the analyzer. Timestamps use the database/sql time.Time-to-string RFC3339 representation. These small seeds qualify semantics and native structure, not index adoption or performance.

type CaseDefinition

type CaseDefinition struct {
	ID               string           `yaml:"id" json:"id"`
	Title            string           `yaml:"title" json:"title"`
	Tags             []string         `yaml:"tags,omitempty" json:"tags,omitempty"`
	Profiles         []string         `yaml:"profiles" json:"profiles"`
	SQL              string           `yaml:"sql" json:"sql"`
	Tables           []string         `yaml:"tables,omitempty" json:"tables,omitempty"`
	CandidateIndexes []CandidateIndex `yaml:"candidate_indexes,omitempty" json:"candidate_indexes,omitempty"`
	Expected         Expected         `yaml:"expected" json:"expected"`
}

CaseDefinition describes one stable SQL shape and its physical designs.

type CostClass

type CostClass string

CostClass identifies the strength of a canonical case's cost assertion.

const (
	// FormatVersion is the only canonical workload format understood by this
	// test suite.
	FormatVersion = 1

	CostClassCalibrated30Percent  CostClass = "CALIBRATED_30_PERCENT"
	CostClassDirectionAndShape    CostClass = "DIRECTION_AND_SHAPE"
	CostClassLowConfidence        CostClass = "LOW_CONFIDENCE"
	CostClassNotEvaluableStats    CostClass = "NOT_EVALUABLE_STATS"
	CostClassNotEvaluableOp       CostClass = "NOT_EVALUABLE_OPERATOR"
	CostClassNotEvaluableOverflow CostClass = "NOT_EVALUABLE_OVERFLOW"
)

type DiversityCase

type DiversityCase struct {
	ID           string
	Source       string
	SQL          string
	ExpectedRows [][]string
	Ordered      bool
}

DiversityCase is a PostgreSQL adaptation of a MySQL SQL-shape regression. ExpectedRows are independently derived from DiversitySetupSQL, not captured from a database or from the analyzer. Ordered requires exact row order.

func CanonicalMigrationCases

func CanonicalMigrationCases() []DiversityCase

CanonicalMigrationCases supplies the migrated SELECTs to the common native result oracle without modifying the existing canonical workload or Goldens.

func DiversityCases

func DiversityCases() []DiversityCase

DiversityCases returns independent SQL/result assets for offline semantic checks and explicitly opted-in native SELECT/EXPLAIN tests. All SQL is read only. These small data sets qualify result semantics, not performance or native index-selection quality. Every call returns independently owned rows.

type Expected

type Expected struct {
	Recommendation               string    `yaml:"recommendation" json:"recommendation"`
	CostClass                    CostClass `yaml:"cost_class" json:"cost_class"`
	OutputRowsEqual              bool      `yaml:"output_rows_equal" json:"output_rows_equal"`
	NativeCandidateIndexRequired bool      `yaml:"native_candidate_index_required" json:"native_candidate_index_required"`
	NativeCandidateUnusedReason  string    `yaml:"native_candidate_unused_reason,omitempty" json:"native_candidate_unused_reason,omitempty"`
	ReasonCode                   string    `yaml:"reason_code,omitempty" json:"reason_code,omitempty"`
	NativeBaselineRoot           string    `yaml:"native_baseline_root,omitempty" json:"native_baseline_root,omitempty"`
	NoCandidateReason            string    `yaml:"no_candidate_reason,omitempty" json:"no_candidate_reason,omitempty"`
}

Expected holds stable gates that apply across every test layer.

type IndexKey

type IndexKey struct {
	Column    string `yaml:"column" json:"column"`
	Direction string `yaml:"direction" json:"direction"`
	Nulls     string `yaml:"nulls" json:"nulls"`
}

IndexKey preserves PostgreSQL B-tree direction and NULL placement.

type IssueObservation

type IssueObservation struct {
	ID, Rule, Code, Table, Title, Description string
	Severity                                  analysis.Severity
	Targets                                   []analysis.SQLTarget
	IndexSQL                                  []string
}

IssueObservation is the stable subset consumed by PostgreSQL audit fixtures. SQL contains only explicitly available index actions linked to this issue.

func ObserveIssues

func ObserveIssues(report *analysis.AnalyzeResult) ([]IssueObservation, error)

ObserveIssues retains report identities without reconstructing recommendations from advisory text or assigning another issue's action to this issue.

type LiveCaseOutcome

type LiveCaseOutcome struct{ ID, Verdict string }

LiveCaseOutcome records one executed live contract, not an offline prediction.

type LiveOutcome

type LiveOutcome struct {
	ExitCode int
	Notes    string
}

LiveOutcome is a cleanup-gated summary suitable for a batch command exit code.

func SummarizeLiveCases

func SummarizeLiveCases(cases []LiveCaseOutcome, cleaned bool, timingRatio float64) LiveOutcome

SummarizeLiveCases requires nonempty unique all-PASS evidence and successful cleanup. Unknown, missing, failed or blocked verdicts never establish success. A nonfinite timing ratio is omitted rather than reported as a measurement.

type Manifest

type Manifest struct {
	Version int              `yaml:"version" json:"version"`
	Cases   []CaseDefinition `yaml:"cases" json:"cases"`
}

Manifest is the single source of truth shared by PostgreSQL recommendation, cost, replay, and real-database tests.

func Load

func Load(reader io.Reader) (*Manifest, error)

Load strictly decodes and validates a canonical manifest.

func (Manifest) Validate

func (manifest Manifest) Validate() error

Validate checks cross-field invariants that YAML decoding cannot express.

type MySQLLiveScenario

type MySQLLiveScenario struct {
	ID       string
	Input    struct{ SQL string }
	LegacyID string
	Tags     []string
	Contract struct {
		Table                          string
		Columns                        []string
		ExpectedRules, UnexpectedRules []string
		HistoricalVerdict              string
		HistoricalActualRules          []string
		HistoricalReason               string
	}
}

MySQLLiveScenario preserves a historical source contract before PostgreSQL SQL/native-plan adaptation. Historical observations are not current verdicts.

func ReadMySQLLiveScenarios

func ReadMySQLLiveScenarios(path string) ([]MySQLLiveScenario, error)

ReadMySQLLiveScenarios loads the complete retained source assertions used by PostgreSQL migration executors. It neither rewrites SQL nor claims execution.

type MySQLStaticCase

type MySQLStaticCase struct {
	SourceID    string   `json:"source_id"`
	SourceFile  string   `json:"source_file"`
	SQL         string   `json:"sql"`
	Error       string   `json:"error"`
	Kind        string   `json:"kind"`
	QueryBlocks int      `json:"query_blocks"`
	Relations   []string `json:"relations"`
	Rule        string   `json:"rule"`
	Count       int      `json:"count"`
	Family      string   `json:"family"`
	Variant     string   `json:"variant"`
}

MySQLStaticCase retains one source scenario and its reviewed PostgreSQL adaptation. Counts and physical occurrences are independently enumerated SQL contracts, not snapshots of PostgreSQL analyzer output.

func MySQLStaticCases

func MySQLStaticCases() []MySQLStaticCase

MySQLStaticCases returns independently owned copies of all 267 static source scenarios. Invalid SQL is intentional and carries a typed rejection contract.

type RealStatsMigrationCase

type RealStatsMigrationCase struct {
	ID           string     `json:"id"`
	SourceFile   string     `json:"source_file"`
	Source       string     `json:"source"`
	OriginalSQL  string     `json:"original_sql"`
	SQL          string     `json:"sql"`
	ExpectedRows [][]string `json:"-"`
	Ordered      bool       `json:"ordered"`
	IndexColumns []string   `json:"index_columns"`
	NativeNodes  []string   `json:"native_nodes"`
	Adaptation   string     `json:"adaptation"`
}

RealStatsMigrationCase preserves one SELECT and proposed index from the MySQL real-statistics suite. Its oracle concerns relational results, not MySQL cost ratios, PostgreSQL planner adoption, or execution speed.

func RealStatsMigrationCases

func RealStatsMigrationCases() []RealStatsMigrationCase

RealStatsMigrationCases returns isolated SQL contracts with independently computed Go row oracles. The oracle never parses SQL or consumes a database result: explicit predicates, group counters and rational arithmetic operate on the deterministic seed. Numeric AVG values retain 16 decimal places, and timestamps use database/sql's RFC3339 string representation.

Jump to

Keyboard shortcuts

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