Skip to content

verdict: say a parent's SET TABLESPACE moved no existing partition - #698

Open
Kiran01bm wants to merge 1 commit into
mainfrom
kiran01bm/pd212-tablespace-parent-verdict
Open

Kiran01bm wants to merge 1 commit into
mainfrom
kiran01bm/pd212-tablespace-parent-verdict

Conversation

@Kiran01bm

Copy link
Copy Markdown
Collaborator

The verdict for a partitioned table's SET TABLESPACE now carries partition_default_tablespace and says that no existing partition or index was moved.

Why

On an ordinary table, SET TABLESPACE moves the table's data to another storage location. On a partitioned table it only records where partitions created later will go; every existing partition stays where it was. pg-sprite reported both as a plain "executed", so an operator or a host reading the verdict could think the data had moved when it had not.

What

  • planner.Decision gains PartitionDefaultTablespace (not in the plan report). It is set only for a partitioned parent on the native route.
  • verdict.Verdict gains partition_default_tablespace (quoted identifier, omitted when empty).
  • describeParentTablespace sets it on the executed verdict and adds to the detail: the parent now records the tablespace for partitions created later, and no existing partition or index was moved.
  • No format bump: the verdict has no format_version, and the plan report is unchanged.
  • Docs: docs/schemabot-integration.md and the partitioned-parent SET TABLESPACE row in docs/capabilities.md and pkg/capabilities/capabilities.yaml.
  • Tests:
    • The parent integration test asserts the field and that partition events_2024 stays in its tablespace (reltablespace = 0). It fails without the change.
    • A new control test runs a forced SET TABLESPACE on a plain table, which moves the table and carries no field.
    • A unit test checks the detail wording.

Before / after

events is partitioned and has partition events_2024; the run sets its tablespace to archive.

input: pg-sprite migrate --alter "ALTER TABLE events SET TABLESPACE archive"

Before
  server       ──▶ parent records "archive" for future partitions;
                   events_2024 stays in the default tablespace
  verdict      ──▶ executed (nothing says events_2024 did not move)

After
  server       ──▶ same: events_2024 stays in the default tablespace
  verdict      ──▶ executed,
                   partition_default_tablespace: "archive",
                   detail: "... no existing partition or index was moved"

A partitioned parent's SET TABLESPACE only sets the default for later
partitions; "executed" alone read as if the table moved.
@Kiran01bm
Kiran01bm marked this pull request as ready for review December 2, 2026 05:23
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-02T05:23:21.675143Z
We couldn’t complete this review. Comment @codex review to try again.
19679f7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@aparajon

aparajon commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

🤖 Review 1/2 (correctness) of 19679f7: 1 blocking, 1 non-blocking.

Inspected the whole change at 19679f7a08acdbc1eca3c7b13cf21024c4b468f1: the planner decision that carries the tablespace (planner.go#L567-L575, set at #L1989-L1991), the new renderer (parent_tablespace.go#L18-L29) and its one call site (migrate.go#L812), the verdict field (verdict.go#L729-L738), the docs and capabilities rows, and the tests. I read the paths that can build an executed verdict for a native statement (dispatch and execute in pkg/migrate/migrate.go) to see which of them reach the new call.

CI at the time of posting: unit tests (no Docker; docs guards), test (PostgreSQL 14), test (PostgreSQL 16) and test (PostgreSQL 17) are red, and in each log the one failing test is the same (finding 1), which this PR causes; build, lint, smoke, Supabase compatibility, test (PostgreSQL 18, schemachange), the aws-boundary and security checks are green; test (PostgreSQL 15) and test (PostgreSQL 18, other packages) were still running, and I expect them to fail the same way, since the cause is not version-specific.

The change is correct as written. The field is set only when the planner routed a SET TABLESPACE native for a partitioned parent, so a refused statement and a heap's move (copy-and-swap) never carry it; the renderer sets it after the statement committed, so a failed run never says a default was recorded; Sanitize quotes the name as the statement spelled it. Execution is untouched: no executor, budget or lock path changes.

Invariants (docs/invariants.md): ST-7 (the executor runs exactly the statement that was gated) and LK-2 (every strong lock is bounded) are upheld, since the statement still runs as written under the brief budgets and only the report changes. No entry governs verdict wording, and this is not a rule that every engine holds, so nothing is established or weakened.

Blocking

  1. make test-own-server does not list the new test, so TestOwnServerTargetRunsEveryTestThatSkipsOnTheSharedServer fails in the unit job and in every PostgreSQL leg that runs it. The new TestMigrateForcedSetTablespaceOnAnOrdinaryTableCarriesNoPartitionDefault (migrate_set_tablespace_integration_test.go#L72-L73) calls testutil.SkipOnSharedServer, which makes the Makefile's -run list in Makefile#L78 the only gate that runs it; the completeness test at own_server_test.go#L38 holds that list to the callers and finds 13 callers against 12 listed. Fix: add TestMigrateForcedSetTablespaceOnAnOrdinaryTableCarriesNoPartitionDefault to the alternation on that line (the package ./internal/cli is already named). Until then the merge is blocked by CI, and once the list is fixed the test also actually runs on the own-server gate, where I cannot say whether the forced run passes: it needs a live server and I did not run it.
Failing test, from the CI run at 19679f7 (not run here)

The test is the one already in the repository; the job log of unit tests (no Docker; docs guards) (and the test (PostgreSQL 14) and test (PostgreSQL 16) jobs) reports:

--- FAIL: TestOwnServerTargetRunsEveryTestThatSkipsOnTheSharedServer (2.39s)
    own_server_test.go:38:
        Error:      	Not equal:
        Messages:   	make test-own-server must -run exactly the tests that call testutil.SkipOnSharedServer
        -([]string) (len=13) {
        +([]string) (len=12) {
        -(string) (len=72) "TestMigrateForcedSetTablespaceOnAnOrdinaryTableCarriesNoPartitionDefault",

The diff that clears it:

-...|TestMigrateSetTablespaceOnAPartitionedParentMovesNoPartition|...
+...|TestMigrateForcedSetTablespaceOnAnOrdinaryTableCarriesNoPartitionDefault|TestMigrateSetTablespaceOnAPartitionedParentMovesNoPartition|...

Non-blocking

  1. The renderer's no-op branch has no direct test. The doc on describeParentTablespace promises that it "leaves v unchanged when it set none", and the unit test (parent_tablespace_test.go) only runs a plan that sets one. That branch is reached for every other executed native statement, and it is checked only by the new forced-heap control test, which runs only on the own-server gate (finding 1) and needs a live server. A mutant that sets the field or appends the detail for any plan with a decision would survive the unit job. A three-line test at the unit layer pins it. Reasoned from the code, not run.
Test case: a plan with no tablespace decision leaves the verdict alone (not run)
func TestDescribeParentTablespaceLeavesAnOrdinaryVerdictAlone(t *testing.T) {
	plan, err := planner.Classify("ALTER TABLE app.events ADD COLUMN note text",
		planner.Facts{Storage: planner.StorageHeap})
	require.NoError(t, err)
	v := verdict.Verdict{Outcome: verdict.OutcomeExecuted, Detail: "committed within budgets"}

	describeParentTablespace(&v, plan)

	assert.Empty(t, v.PartitionDefaultTablespace)
	assert.Equal(t, "committed within budgets", v.Detail)
}

I did not run it: the PR's own unit job shows pkg/migrate building, and the test compiles against the same planner.Classify call the PR's test uses.

Verified

  • Read the diff end to end and the two surrounding paths: dispatch (migrate.go#L500-L526) passes rs.Plan to execute on both the native and the forced copy-and-swap route, so the forced heap run in the control test carries a plan whose decision has no PartitionDefaultTablespace, and a parent's native run carries one that does. RunDesired never produces a SET TABLESPACE, so the one call site covers the field's only producer.
  • Read the planner side: classifySetTablespace returns a native route for a partitioned parent only (classifyParentTablespace), and StorageHeap or StorageUnread always route to copy-and-swap, so the facts.Storage == StoragePartitionedParent half of the new condition at planner.go#L1989 is redundant with the route check beside it; the route check alone decides. Harmless, and it reads as intent.
  • PartitionDefaultTablespace is json:"-" on Decision, so the plan report's shape is unchanged, as the PR says. make check-capabilities passed in the unit job: the yaml row and docs/capabilities.md agree.
  • The one-statement claim in the renderer's comment (the loop returns at the first decision) matches PostgreSQL as I know it, which rejects a second SET TABLESPACE subcommand in one ALTER TABLE; I did not run it against a server.
  • I ran no test: the new integration tests need a live PostgreSQL and a tablespace directory, and I do not run containers in this review.
  • Mutation table, by reading and against CI (unit passes everything except the completeness test):
Mutant Caught by
remove the call at migrate.go#L812 TestMigrateSetTablespaceOnAPartitionedParentMovesNoPartition (own-server gate only)
drop d.Route == RouteNative at planner.go#L1989 TestClassifySetTablespaceOnAPartitionedParentRefusesATablespaceItCannotName (its new assert.Empty on the refused cases)
drop facts.Storage == StoragePartitionedParent at planner.go#L1989 equivalent: the route check already excludes a heap
drop Sanitize at parent_tablespace.go#L23 TestDescribeParentTablespaceSaysNoExistingPartitionMoved ("Archive" vs Archive)
reword or drop the appended detail the same unit test, which asserts the whole string
set the field or detail for every plan survives the unit job; only the forced-heap control test on the own-server gate catches it (non-blocking 1)

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon

aparajon commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

🤖 Review 2/2 (OSS adoption and integration) of 19679f7: 0 blocking, 2 non-blocking. The PR-wide count is 1 blocking (the red test-own-server list in 1/2).

Read the change from two seats: a host such as SchemaBot that decodes the verdict JSON and records what an apply did, and an operator or contributor who reads the verdict's detail and the docs to decide what to do next. The surface that matters is one new optional JSON field, partition_default_tablespace, and one added sentence in detail.

Non-blocking

  1. The detail sends the operator to a move pg-sprite itself refuses. The sentence ends "each stays in the tablespace it was in until a SET TABLESPACE on it moves it" (parent_tablespace.go#L24-L26), and the docs say the same ("moving an existing partition is a SET TABLESPACE on that partition", schemabot-integration.md#L1181). A SET TABLESPACE on a partition is the rewrite-scale move, which the dry run reports as unavailable (TestMigrateDryRunKeepsSetTablespaceOnAPartitionOnTheRewritePath) and the capabilities row calls it "a rewrite refused as in the SET TABLESPACE row" (capabilities.md#L286); the verdict an operator reads does not say so. An operator who follows the detail literally meets a refusal on the next command. Either end the sentence at "no existing partition or index was moved", or add that pg-sprite does not carry the move of a partition, in the verdict and in the integration bullet. I did not run the partition's statement; this is from the dry-run test and the row.

  2. A host sees the distinction only after the apply, and has to unquote the name. Decision.PartitionDefaultTablespace is json:"-" (planner.go#L575), so the plan report a host shows at review time reads metadata-only and no more; the field appears first on the executed verdict. That is a coherent choice and the integration bullet states it ("The plan report does not carry it"), but a host that wants the review comment to say "no existing partition will move" has only the metadata-only reason to key on, and could say so in the bullet. Separately, the field holds the identifier already quoted ("archive", "My""ts" for an embedded quote), which suits the other quoted names in the verdict but means a host that stores the bare name has to unquote it; the bullet says "quoted" without saying that the doubling rule applies. One sentence for each closes both.

What reads well for adopters

  • The PR body states the before and after for one concrete statement (events with events_2024, SET TABLESPACE archive), and the integration test pins exactly that: the field, the unchanged filenodes and tablespaces of every partition, the parent's recorded default, and a partition created afterwards landing in the new tablespace.
  • The new field follows the shape of its siblings (already_detached, already_not_null): optional, omitted when empty, documented in the integration guide's contract list, the capabilities row and the Go doc, and the capabilities page regenerates cleanly (make check-capabilities passed in CI).
  • The forced-heap control test makes the field's meaning checkable from the other side: the same statement on a table with a heap moves it and carries no field. That contrast is what lets a host treat "field present" as "recorded a default, moved nothing" rather than as "was a SET TABLESPACE".
  • No format bump: an older host that ignores the unknown field still sees the same outcome and executed_sql, so nothing breaks for an importer who does not read it.

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon aparajon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Stamping with comments: 1 blocking, 3 non-blocking (see the review comments above). The blocking one is the red test-own-server list: the new test needs adding to the -run list in the Makefile so the unit job and the PostgreSQL legs go green.

This stamp was left by Claude Code (claude-sonnet-5-5).

@JashLal

JashLal commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

🤖 One CI blocker on 19679f7.

The new forced plain-table control calls SkipOnSharedServer, but this diff does not register it in make test-own-server's -run list. GitHub currently reports failed unit checks, five PostgreSQL jobs and all-green. The prior review traced the job failure to the test-list completeness guard. Register the test and rerun the matrix so the forced heap path is actually exercised. New control CI diagnosis

The full diff carries the planner's native partitioned-parent decision into the executed verdict and uses identifier quoting at the output boundary. The parent integration assertions check existing storage before and after, while the new control checks the heap move and omitted field.

Review based on the full GitHub diff, PR discussion and reported checks. Builderbot and inline review threads were unavailable. I did not run tests locally.

@JashLal JashLal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Approved by Jash’s AI agent after reviewing 19679f7. The findings and verification limits in the review comment still apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants