← Back to Pull requests

feat(schema): retrofit storage_parameters onto existing partition children #160

Merged
tthayer merged 4 files (268 lines) on Jul 31, 2026 21:33 UTC
View on GitHub
tthayer tthayer commented on Jul 31, 2026 21:27 UTC
Author

What was broken

PR #159 (v0.12.2) made storage_parameters reach partition children at creation
time
. Nothing retrofitted children that already existed.

Which strategy that actually mattered for:

  • Tenant-list partitions (partitioned = true) — the real problem. They never

  • roll over. A child created before the model declared the option keeps the default
    forever, silently.
  • KSUID and date partitions self-heal: retention rolls old children out and new ones

  • are created with the declared WITH (...).

    The change

    At the end of Migrations():

    if isPartitionedParent(desc) && desc.GetStorageParameters() != nil {
        children, err := readPartitionChildStorageParameters(ctx, db, desc)
        ...
        rv = append(rv, partitionChildAlters(desc, children, maxPartitionChildStorageParamAlters)...)
    }
    

    Three deliberate properties:

    1. Emitted last. The consumer (c1 pkg/postgres/xpgdb/schema.go) breaks out of a
    table's statement loop on the first 55P03 lock_timeout. Putting child ALTERs last
    means a contended tenant partition can only cost other child ALTERs — never the
    column-adds and index statements ahead of them.
    2. Capped at 50 per run (maxPartitionChildStorageParamAlters), ordered by child
    name.
    Bounds lock churn on a many-tenant table — each ALTER TABLE ... SET (...)
    takes a brief ACCESS EXCLUSIVE lock. Self-advancing: converged children render
    nothing, so the next run's first 50 are the next 50 that actually drift.
    3. Diff-driven. Reuses the existing per-key diff via a new
    storageParams2alterTable(desc, tableName, existingParams); storageParams2alter
    is now a one-line wrapper, so TestStorageParams2alter is unchanged and still
    passes. No blanket re-SET, no churn on already-correct children.

    Also folds the duplicated reloptions key=value parsing into a shared
    parseReloptions used by both the parent and the new child reader. The new
    pg_inherits reader mirrors the existing readStorageParameters shape (same goqu
    parameterization, same nspname = 'public' scoping).

    Only costs an extra catalog query when the model is a partitioned parent and
    declares storage parameters. Migrations still early-returns CreateSchema when the
    table does not exist, so the retrofit block never runs on a fresh table.

    Tests

    pgdb/v1/schema_sql_test.go — TestPartitionChildAlters: 120 drifted children
    truncate to exactly 50 in name order (first is parent_000, last parent_049); a
    converged set emits nothing; a descriptor with no declaration emits nothing.

    example/models/food/v1/food_test.go — TestPartitionChildStorageParamRetrofit
    simulates the real case end to end against a live Postgres: create the tenant-list
    partitioned Pasta table (declares fillfactor: 90) plus three tenant children,
    assert Migrations emits nothing while they are converged, then
    ALTER TABLE <child> RESET (fillfactor) on one of the three to look like a
    pre-declaration child. Asserts exactly that child is retrofitted, applies the ALTER,
    verifies fillfactor = 90 landed, and asserts a third Migrations call emits nothing.

    Negative test confirmed: with the retrofit block disabled,
    TestPartitionChildStorageParamRetrofit fails with "[]" should have 1 item(s), but
    has 0 / only the stale child should be retrofitted
    . The test genuinely guards the
    behaviour rather than passing vacuously.

    Residual limitation

    execReconcile in the consumer notes that a 55P03 skip is "not self-healing
    in-process" — it retries only on the next EnsureSchema, i.e. a redeploy. So a large
    retrofit converges across deploys rather than within one: at 50/run, a 5,000-tenant
    table needs ~100 deploys. Related: because the consumer abandons the remainder of a
    table's statements on the first lock_timeout, a perpetually contended child head-of-line
    blocks the children after it in name order for that run. Both are inherent to the
    consumer's break-on-lock_timeout semantics, and both are strictly better than the status
    quo, where nothing converged at all. maxPartitionChildStorageParamAlters is the knob
    if the deploy count ever matters.

    Linear: IGA-3716

    Note: the ticket's "route lock behaviour through reconcileLockTimeout / 55P03"
    criterion required no code here — that machinery lives in the consumer, not this
    library.

    🤖 Generated with Claude Code

    Diff: 268 lines (+263 / -5) across 4 files Reviewer: None requested Review duration: 5m
    All Vouch review confidence checks passed
    Residual risk 0.43 = Change Risk (0.63) × (1 − Review Confidence (0.32)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 268 lines diff across 4 files
    0.63
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 76% · Reviewer familiarity: 10%
    32%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.335
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Rapid Merge rapid_merge
    0.100
    Real PR Conversation Timeline
    1 comments
    "Review active on #160"
    general weight: 0.35
    Reviewers
    None requested
    Assignees
    tthayer tthayer
    Labels
    risk: medium confidence: 32.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 62.9% (MEDIUM) · Higher = larger blast radius
    62.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 32.1% · Lower = rushed or shallow review
    32.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 42.7% · Moderate risk
    42.7%