README
¶
PostgreSQL integration and fixture workflow
The canonical workload, index recommendation tests, native plan snapshots and
HypoPG coverage are documented in
docs/postgresql/postgresql_test_plan.md.
PostgreSQL integration is opt-in and must target a disposable database. Set SQL_GUNYU_POSTGRES_TEST_DSN in the invoking shell; never commit or print its value. Every mutating test/tool creates a named disposable schema and removes it with t.Cleanup or an equivalent deferred cleanup.
Set SQL_GUNYU_POSTGRES_EXPECT_MAJOR to 16 or 17 when running a fixed-major
job; the connected tests fail if that major does not match the server.
Pure connected tests use the postgresql_integration build tag and are excluded
from ordinary go test ./.... make test-postgresql runs only the read-only
catalog and native EXPLAIN smoke. make test-postgresql-matrix runs the
version-wide connected suite and finishes with a separate catalog audit that
fails if any sql_gunyu_* schema or idx_pg_* index remains.
Destructive tests accept loopback and Unix-socket DSNs by default. A remote
target is rejected unless it is separately authorized with
SQL_GUNYU_POSTGRES_ALLOW_REMOTE_DDL=1; use that override only for an
explicitly disposable remote database. Mutating harnesses also require an
explicit database name and a sql_gunyu_* schema.
As with the MySQL test layout, reusable Go helpers live under
internal/postgresqltestenv and internal/postgresqltestworkload.
tests/postgresql/workloads contains only the canonical manifest and reviewed,
versioned fixture data; cross-module PostgreSQL integration tests live directly
under tests/postgresql.
The canonical manifest, safety helpers, and bulk-loader schema contract run offline:
go test ./internal/postgresqltestworkload ./internal/postgresqltestenv \
./tests/postgresql/bulkload -count=1
The optimizer suite executes all 49 PG-IDX-* recommendation cases. The
canonical workload contains 112 SQL cases, including 45 PostgreSQL-specific
syntax cases. make test-postgresql-fixtures checks the version, inventory,
and native plan evidence in the recorded PG17.10 fixture.
TestCanonicalPostgreSQLSyntaxPlansOnRealServer explains the 45 syntax cases
on the configured major. Setup uses a transaction and rollback. A catalog
audit confirms cleanup.
SQL diversity and complete MySQL source inventory
PostgreSQL test files and top-level test names describe the behavior under test,
without migration or MySQLMigration prefixes. Parser, catalog, EXPLAIN,
diagnostics, Agent lifecycle, reports and HypoPG tests live beside their owning
packages. Mixed Agent tests are split by catalog evidence, plan evidence,
preflight, language, request and report behavior. Source case IDs remain intact.
The source_coverage/ directory stores source-to-test evidence mappings; it is not a
separate test layer or a database schema migration directory. The
test-postgresql-source-coverage Make targets validate that inventory and its active
HypoPG scope. Experimental model tests are maintained on dev/pg_cost_model.
The source coverage inventory covers all 483 MySQL scenario IDs, all 51 MySQL
canonical workload IDs, and all top-level Go tests under pkg/mysql and
tests/mysql outside the tests/mysql/workloads/results archive. Each new
source test needs a reviewed entry with a reason for any open gap or scope
boundary. Each entry in
tests/postgresql/source_coverage/*.json records its
source identity, disposition, PostgreSQL evidence and the assertions that the
evidence establishes. capability_gap remains open and is counted separately
from covered cases. out_of_scope records a reviewed boundary for internal
optimizer costs, optimization caches or workload design. Partial PostgreSQL
evidence can still be linked to those source entries. The inventory gate fails
on missing or duplicate sources, unrecognized classifications, missing
rationale and invalid evidence. PostgreSQL what-if behavior has its own
HypoPG regression assertions.
The reviewed SQL corpora include 267 adapted static scenarios, 49 canonical SELECTs and the earlier 24 semantic counterexamples. The static scenarios now run through both the optimizer and the public Agent, with exact diagnostic counts where an equivalent rule exists, query-block ownership, physical relation occurrences, EN/ZH messages, stable output and no executable advice. MySQL-only syntax and diagnostic behavior have explicit reasons in the ledger. The separate corpora leave the existing 112-case PostgreSQL canonical workload and the versioned native plan input available.
The SELECT integration harness seeds ten tables with 66 synthetic rows, including three event partitions, nullable keys, JSON and a stored generated column. It verifies exact seed counts and catalog properties, runs ANALYZE, then compares the complete SELECT output with independent row oracles. The 73 SELECT/EXPLAIN cases and the event-catalog contract passed PostgreSQL 16.3 on November 10, 2026. A second harness adapts 138 of the 142 MySQL live scenarios (the remaining four use MySQL FORCE INDEX), seeds its own commerce relations, and verifies native SQL and reviewed index-before/after result equivalence. All 138 passed on the same server. Neither harness treats an empty positive query or a native cost reduction as proof of runtime improvement.
A third corpus preserves all 43 SQL subcases from MySQL's real-statistics
integration test, including exact source SQL and index columns. It seeds 3,760
deterministic rows, including NULLs, duplicate projections, HAVING boundaries
and ordering ties. An independent Go oracle verifies the full result before
and after each reviewed index. All 43 passed PostgreSQL 16.3 in the earlier
run. Those 43 SQL subcases are tracked under source_coverage/sql_cases/. The
parent MySQL test's numeric calibration of an internal model is outside the
HypoPG scope.
These harnesses require an explicitly disposable database. Their schemas must be absent before setup. Setup and reviewed index DDL stay inside transactions; cleanup failures fail the tests, and separate connections audit schema absence. Slow SSH transport can be accommodated by running named subtests in sequential batches; the original statement and cleanup timeouts are not increased.
# Offline PostgreSQL behavior tests and source coverage validation.
make test-postgresql-source-coverage
# Earlier focused 24-case regression suite.
make test-postgresql-diversity
# Set the disposable DSN and actual expected major (16 or 17) first.
make test-postgresql-source-coverage-live
The JSON source coverage inventory records remaining open coverage. The historical
execution report on codex/postgresql-migration-archive
records the commands and server versions of earlier runs.
The pinned multi-architecture Docker Official Image targets are listed below. Their manifests have been checked to resolve; that is not a substitute for running the real matrix and committing reviewed replay evidence:
| Profile | Patch evidence | Image |
|---|---|---|
postgresql/16/v1 |
PostgreSQL 16.14 | postgres:16-bookworm@sha256:92620daddcd947f8d5ab5ba66e848702fe443d87fed30c4cea8e389fd78dfc55 |
postgresql/17/v1 |
PostgreSQL 17.10 | postgres:17-bookworm@sha256:4f736ae292687621d4dbe0d499ffd024a36bd2ee7d8ca6f2ccd4c800f047b394 |
The scheduled workflow also checks floating postgres:16-bookworm and postgres:17-bookworm tags for new patch behavior; floating results do not rewrite committed fixtures or block offline tests.
Run tests
After starting a dedicated PostgreSQL 16 or 17 instance and exporting the DSN:
make test-postgresql # read-only catalog and EXPLAIN smoke
make test-postgresql-matrix # connected native SQL and diagnostics matrix
Set SQL_GUNYU_POSTGRES_EXPECT_MAJOR to the expected major. The smoke target
checks connection, version, catalog identity, and native EXPLAIN. The matrix
adds Agent integration, the native syntax and SQL diversity tests, and an
independent residue audit.
The default connected path does not use HypoPG. Run its focused suite with:
make test-postgresql-no-hypopg
This verifies that the default and explicit HypoPGDisabled configurations
skip what-if and still retain diagnostics, catalog snapshots, the native plan
and advisory index candidates. It also checks that analysis creates no
physical indexes. Run make test-postgresql-whatif for offline HypoPG
coverage and make test-postgresql-hypopg on a disposable database with the
extension installed.
To rebuild the reviewed large canonical schema, use the separately armed
destructive loader. It creates type-correct PostgreSQL columns, ordinary and
UNLOGGED tables, range partitions, an identity table, and a loopback
postgres_fdw Foreign Table:
SQL_GUNYU_POSTGRES_REBUILD_BULK=1 \
go run ./tests/postgresql/bulkload -major 17 -schema sql_gunyu_bulk
The normal PostgreSQL DSN and expected-major variables are required. The
loader drops and recreates only the explicitly selected sql_gunyu_* schema
and its matching managed foreign server. It disables background autovacuum for
the deterministic fixture, performs controlled VACUUM (ANALYZE), and leaves
pg_unanalyzed_orders deliberately without statistics.
Run the strict HypoPG acceptance target against an explicitly disposable database with HypoPG installed and callable. Set the expected major to match the target.
The active MySQL-to-PostgreSQL migration focuses on HypoPG. Run
make test-postgresql-source-coverage for the source ledger, shared contracts, PG
analysis packages and native HypoPG provider. Open migration gaps remain in
the source ledger. Experimental model tests run on dev/pg_cost_model.
make test-postgresql-source-coverage-live first runs strict HypoPG acceptance, then
the seeded SQL semantics and cleanup tests. An unavailable extension must fail
this run, without substituting internal model results.
SQL_GUNYU_POSTGRES_EXPECT_MAJOR=16 make test-postgresql-hypopg
# For a separate PostgreSQL 17 target, set its DSN and expected major, then run:
SQL_GUNYU_POSTGRES_EXPECT_MAJOR=17 make test-postgresql-hypopg
The local target uses SQL_GUNYU_POSTGRES_TEST_DSN for the extension probe and
the Agent, so there is no separate HypoPG DSN. Make rejects a missing DSN
or major. A configured target with an unavailable extension or a wrong major
fails before fixture setup.
make test-postgresql-hypopg runs both the same-session provider test and the
public Agent in Required mode. The Agent checks adopted and unused indexes,
independent and combined scenarios, and distinct action IDs for indexes with
the same name in different schemas. It checks planning identity drift and
reuses the same physical backend to check that a candidate EXPLAIN failure
leaves no hypothetical index behind. Both the test schema and physical-index
residue are audited.
The same target checks the ordered B-tree key and INCLUDE definition after a public report round trip. It also checks LEFT JOIN and self-join ownership, inner-only hypothetical index use in correlated scalar subqueries, and separate whole-query costs for each single index and a combination that uses both indexes.
Single-table acceptance compares narrow, covering, and reordered equality keys
as three distinct designs. The budget case asserts eight individual comparisons
and two pairs, preserves the ninth design with NOT_EVALUATED and
SEARCH_INCOMPLETE, and checks its reason after re-rendering the stored
report in Chinese. Both cases verify cleanup on the reused session.
The attribution suite inspects the native candidate plans as well as public JSON. It checks independent self-join layouts, lookup and two range-key orders on the inner side of a LEFT JOIN, and inner-only hypothetical adoption in correlated scalar subqueries. Identical physical designs originating in two query blocks retain both sources and share one individual evaluation. The suite compares each public native access path, physical relation, and index identity against the observed EXPLAIN and submissions for that scenario.
The complex-query suite checks inline CTE consumers, direct derived projections, same-table UNION ALL branches, and same-named tables in distinct schemas. It asserts exact keys, INCLUDE columns, source references after a JSON round trip, and the executed HypoPG submissions. Materialization, grouping, LIMIT, expression projections and ambiguous references preserve the original native plan. A UNION ALL over nine layouts of the same table exercises the default budget of eight singles and two pairs. The candidate records distinguish SQL branches after branch reordering and preserve the reason when a pruned branch leaves a duplicate alias unresolved. The cross-schema pair asserts two submissions and one adopted action.
make test-postgresql-hypopg-missing uses a disposable database where the
extension is absent. It checks the typed Required error and Preferred
degradation with the original native plan and candidates. The fixed PG16/17
CI jobs run this target before installing the extension, then run
make test-postgresql-source-coverage-live, which includes strict HypoPG
acceptance. These targets reject skipped tests and missing test executions.
The workflow runs on the schedule, on manual dispatch, and for pull requests
that touch PostgreSQL analysis, test infrastructure, or shared report code.
TestAgentHypoPGPredicateAttribution is required by the strict HypoPG gate.
It checks one- and two-sided self-join expressions, partial OR explanations,
served residual predicates, set-branch ambiguity and alias shadowing. JSON
round trips retain predicate source branches and operand positions, and
English/Chinese requests retain the same native scan and ordinary-key facts.
A three-branch index candidate retains all source operands. The fixture audits
its physical indexes and the reused backend before dropping its schema.
TestAgentHypoPGRequestBoundaries is also mandatory. It uses a new NOLOGIN role
(with schema/column/table grants), an unanalyzed table, and real EXPLAIN lock
waits to distinguish namespace denial, statistics denial, DML denial, caller
cancellation, request deadline and server statement timeout. The harness requires
permission to create/drop its disposable role as well as its schema, verifies the
effective role, and audits role removal. Permission repair retries the failed
metadata read. Missing-statistics notices survive native failures in English and
Chinese. A distinct DML assignment verifies that analysis never executes DML;
UPDATE FROM retains WRITE/READ ownership. Required and Preferred modes retain
one successful native comparison after cancellation, with one unattempted design,
exactly two HypoPG EXPLAINs and one hypothetical creation. Cleanup and subsequent
requests are checked. Server 57014 is classified as query cancellation, without
claiming that every occurrence was caused by statement timeout.
Directories
¶
| Path | Synopsis |
|---|---|
|
Command bulkload destructively rebuilds an explicitly selected PostgreSQL test schema with deterministic, type-rich canonical data.
|
Command bulkload destructively rebuilds an explicitly selected PostgreSQL test schema with deterministic, type-rich canonical data. |