Repository navigation
fix: dump and diff the ROWS estimate of set-returning functions (#702) - #706
Conversation
pg_proc.prorows was never inspected, so a function created with ROWS 1 was dumped without it (replaying with the default of 1000) and a change to the estimate produced no plan. Read proretset/prorows in GetFunctionsForSchema, keep the estimate on ir.Function when it differs from the default (as pg_dump does), emit ROWS n after PARALLEL in CREATE OR REPLACE FUNCTION, and compare it in the function equality checks so a change triggers CREATE OR REPLACE. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
[Medium impact] This PR appears safe to merge. SummaryPreserves custom
Reviews (1) · Last reviewed commit: "fix: dump and diff the ROWS estimate of ..." · Reviewed by Greptile |
There was a problem hiding this comment.
🟡 Changes recommended
A ROWS-only change uses CREATE OR REPLACE without preserving a nondefault COST, causing an existing COST 5 to reset to 100.
1 open issue
1 file not reviewed
ir/queries/queries.sql.go: Generated file
What changed in this PR
Adds support for preserving and comparing set-returning function ROWS estimates in pgschema, addressing #702 while leaving COST support outside this PR’s scope.
Changes:
- Reads row estimates from PostgreSQL and stores nondefault values in the function representation.
- Emits
ROWSin function DDL and detects estimate changes during comparison. - Extends the existing function migration fixture to cover changing the default estimate to
ROWS 1.
| File | Description |
|---|---|
internal/diff/function.go |
Emits and compares function row estimates. |
ir/inspector.go |
Captures nondefault estimates during inspection. |
ir/ir.go |
Adds the function Rows field. |
ir/queries/queries.sql |
Queries set-returning status and row estimates. |
ir/queries/queries.sql.go |
Updates generated query fields and scanning. |
testdata/diff/create_function/alter_function_same_signature/old.sql |
Adds a function with the default estimate. |
testdata/diff/create_function/alter_function_same_signature/new.sql |
Sets the desired estimate to ROWS 1. |
testdata/diff/create_function/alter_function_same_signature/diff.sql |
Adds expected function replacement DDL. |
testdata/diff/create_function/alter_function_same_signature/plan.json |
Updates the fingerprint and planned steps. |
testdata/diff/create_function/alter_function_same_signature/plan.sql |
Adds the planned row-estimate change. |
testdata/diff/create_function/alter_function_same_signature/plan.txt |
Updates the readable plan and modification count. |
Review effort: Balanced
A ROWS-only change now goes through the ALTER FUNCTION attribute path like LEAKPROOF and PARALLEL, so the body is not re-sent and attributes pgschema does not track (such as COST) are left untouched. Dropping the estimate emits ROWS 1000, the default. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new ROWS emission leaves four golden files for the existing get_actor dependency fixture outdated, causing the full diff and plan/apply suites to fail despite passing scoped tests.
1 open issue
1 resolved since last review
1 file not reviewed
ir/queries/queries.sql.go: Generated file
Review effort: Balanced
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>


Summary
pg_proc.prorowswas never inspected, so theROWS nplanner estimate on a set-returning function was dropped on dump (replaying with the default of 1000) and a change to it produced an empty plan.GetFunctionsForSchemanow readsproretsetandprorows;ir.FunctiongainsRows, kept only when it differs from the default (same rule as pg_dump: skip0and1000).CREATE OR REPLACE FUNCTIONemitsROWS nafter thePARALLELclause.functionsEqual,functionsEqualExceptAttributesandfunctionsEqualExceptCommentcompareRows, so a changed estimate is applied withCREATE OR REPLACE.Note: the issue says
COSTis already handled, butprocostis not inspected either. Left out of this PR to keep it scoped to ROWS.Fixes #702
Test plan
Folded into
testdata/diff/create_function/alter_function_same_signature: aRETURNS TABLEfunction with the default estimate inold.sqlandROWS 1innew.sql, expecting aCREATE OR REPLACE ... ROWS 1. The integration test's idempotency check confirms the estimate round-trips through the inspector.🤖 Generated with Claude Code