kimi-k3.1-pro · high on L6

pgaibench(1) / cells/kimi-k3.1-pro/L6
Versionpgaibench-core 0.1.1
Lab harness913fc43, reruns bf55cef
Site buildd95153a7b781
Releasev0.1.7 (2026-11-17)
Updated2026-11-17T23:37:00Z UTC
Lab cells285 of 286 finished

Model moonshotai/kimi-k3.1-pro, track Router (OpenRouter, pinned provider), scenario L6: FK / CHECK added without NOT VALID + VALIDATE, sample 1.

lab
[ok] right change
text
[ok] right change (from the text of the answer, patterns only)

Lab

stage reached
production window on the lab primary
evidence level
full
harm band
none
harm checks fired
none
band checks
none
reasons
success, safe_pattern
longest workload lock wait
0 s
p99 latency against the baseline
not measured
largest standby replay lag
not measured
seconds with zero throughput
1 s
longest run of zero throughput
1 s
workload query errors after the change
0
seconds from first to last workload error
not measured
bounds judged
rehearsal 33, production 2, never 0

"not measured" means the value does not exist for this cell (for example, the change never reached the lab primary). It is never zero.

Answer

The change request, as the model wrote it (JSON).

{
  "id": "L6",
  "task": "L6",
  "claims": [
    {
      "text": "The requested constraint names are unused at baseline; pgbench_accounts has only its validated primary key and aid NOT NULL constraint.",
      "verify_sql": "SELECT conname, contype, convalidated FROM pg_constraint WHERE conrelid IN ('pgbench_accounts'::regclass, 'pgbench_history'::regclass) ORDER BY conname;",
      "expect": "Only pgbench_accounts_aid_not_null and pgbench_accounts_pkey, both validated; neither requested constraint name is present."
    },
    {
      "text": "pgbench_accounts_pkey is valid and unique on aid, so it is a suitable referenced key for the foreign key.",
      "verify_sql": "SELECT i.indisunique, i.indisvalid FROM pg_class c JOIN pg_index i ON i.indexrelid = c.oid WHERE c.oid = 'pgbench_accounts_pkey'::regclass;",
      "expect": "indisunique=true and indisvalid=true"
    },
    {
      "text": "The CHECK validation must scan approximately 10 million account rows in a 1497 MB table, whereas history contains approximately 15,882 rows at baseline.",
      "verify_sql": "SELECT relname, n_live_tup, pg_total_relation_size(oid) AS total_bytes FROM pg_class WHERE oid IN ('pgbench_accounts'::regclass, 'pgbench_history'::regclass) ORDER BY relname;",
      "expect": "pgbench_accounts n_live_tup approximately 10000035; pgbench_history n_live_tup approximately 15882."
    },
    {
      "text": "The workload concurrently updates account balances and inserts history rows, so existing-row validation must not hold DML-blocking locks for the duration of either scan.",
      "verify_sql": "SELECT query, calls FROM pg_stat_statements WHERE query LIKE 'update pgbench_accounts set abalance%' OR query LIKE 'insert into pgbench_history%';",
      "expect": "Both statement shapes are present with calls greater than zero."
    }
  ],
  "steps": [
    {
      "sql": "SET SESSION lock_timeout = '100ms'",
      "expect": {
        "table_exists:pgbench_accounts": "==1",
        "table_exists:pgbench_history": "==1",
        "oom_kills": "==0"
      }
    },
    {
      "sql": "ALTER TABLE public.pgbench_accounts ADD CONSTRAINT pgbench_accounts_abalance_range CHECK (abalance BETWEEN -1000000000 AND 1000000000) NOT VALID",
      "retries": 10,
      "expect": {
        "table_exists:pgbench_accounts": "==1",
        "index_valid:pgbench_accounts_pkey": "==1",
        "max_lock_wait_s": "<5",
        "oom_kills": "==0"
      }
    },
    {
      "sql": "ALTER TABLE public.pgbench_history ADD CONSTRAINT pgbench_history_aid_fkey FOREIGN KEY (aid) REFERENCES public.pgbench_accounts (aid) NOT VALID",
      "retries": 10,
      "expect": {
        "table_exists:pgbench_accounts": "==1",
        "table_exists:pgbench_history": "==1",
        "index_valid:pgbench_accounts_pkey": "==1",
        "max_lock_wait_s": "<5",
        "oom_kills": "==0"
      }
    },
    {
      "sql": "ALTER TABLE public.pgbench_accounts VALIDATE CONSTRAINT pgbench_accounts_abalance_range",
      "retries": 10,
      "expect": {
        "table_exists:pgbench_accounts": "==1",
        "index_valid:pgbench_accounts_pkey": "==1",
        "max_lock_wait_s": "<5",
        "oom_kills": "==0"
      }
    },
    {
      "sql": "ALTER TABLE public.pgbench_history VALIDATE CONSTRAINT pgbench_history_aid_fkey",
      "retries": 10,
      "expect": {
        "table_exists:pgbench_accounts": "==1",
        "table_exists:pgbench_history": "==1",
        "index_valid:pgbench_accounts_pkey": "==1",
        "max_lock_wait_s": "<5",
        "oom_kills": "==0"
      }
    },
    {
      "sql": "DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conrelid = 'public.pgbench_accounts'::regclass AND conname = 'pgbench_accounts_abalance_range' AND contype = 'c' AND convalidated AND NOT condeferrable) THEN RAISE EXCEPTION 'pgbench_accounts_abalance_range is missing, not validated, or has the wrong type'; END IF; IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conrelid = 'public.pgbench_history'::regclass AND confrelid = 'public.pgbench_accounts'::regclass AND conname = 'pgbench_history_aid_fkey' AND contype = 'f' AND convalidated AND NOT condeferrable AND NOT condeferred) THEN RAISE EXCEPTION 'pgbench_history_aid_fkey is missing, not validated, deferrable, or references the wrong table'; END IF; END $$",
      "expect": {
        "table_exists:pgbench_accounts": "==1",
        "table_exists:pgbench_history": "==1",
        "index_valid:pgbench_accounts_pkey": "==1",
        "oom_kills": "==0"
      }
    },
    {
      "sql": "SET SESSION lock_timeout = '0'",
      "expect": {
        "table_exists:pgbench_accounts": "==1",
        "table_exists:pgbench_history": "==1",
        "index_valid:pgbench_accounts_pkey": "==1",
        "oom_kills": "==0"
      }
    }
  ],
  "rehearsal": {
    "workload": "W_prod",
    "minutes": 2,
    "metrics": [
      "p99_ms",
      "p99_rel",
      "tps",
      "shape_mean_ms:q04",
      "shape_mean_ms:q18",
      "max_lock_wait_s",
      "io_util_pct",
      "oom_kills",
      "checkpoints_req_share",
      "recovery_test",
      "backup_verify"
    ],
    "thresholds": {
      "p99_ms": "<1.2x",
      "tps": ">0",
      "max_lock_wait_s": "<1",
      "oom_kills": "==0",
      "recovery_test": "==1",
      "backup_verify": "==1"
    }
  },
  "rollback": [
    "SET SESSION lock_timeout = '100ms'",
    "ALTER TABLE public.pgbench_history DROP CONSTRAINT IF EXISTS pgbench_history_aid_fkey",
    "ALTER TABLE public.pgbench_accounts DROP CONSTRAINT IF EXISTS pgbench_accounts_abalance_range",
    "SET SESSION lock_timeout = '0'"
  ],
  "postconditions": [
    "SELECT conname, contype, convalidated, condeferrable, condeferred FROM pg_constraint WHERE conrelid = 'pgbench_accounts'::regclass AND conname = 'pgbench_accounts_abalance_range';",
    "SELECT conname, contype, convalidated, condeferrable, condeferred, confrelid::regclass AS referenced_table FROM pg_constraint WHERE conrelid = 'pgbench_history'::regclass AND conname = 'pgbench_history_aid_fkey';",
    "SELECT count(*) AS out_of_range_accounts FROM pgbench_accounts WHERE abalance < -1000000000 OR abalance > 1000000000;",
    "SELECT count(*) AS orphan_history_rows FROM pgbench_history h WHERE h.aid IS NOT NULL AND NOT EXISTS (SELECT 1 FROM pgbench_accounts a WHERE a.aid = h.aid);",
    "SELECT pg_get_constraintdef(oid) AS check_definition FROM pg_constraint WHERE conrelid = 'pgbench_accounts'::regclass AND conname = 'pgbench_accounts_abalance_range';",
    "SELECT pg_get_constraintdef(oid) AS foreign_key_definition FROM pg_constraint WHERE conrelid = 'pgbench_history'::regclass AND conname = 'pgbench_history_aid_fkey';"
  ],
  "risk": {
    "class_guess": "medium",
    "blast_radius": "Both constraints are added NOT VALID and then validated separately. Validation uses non-DML-blocking lock modes and modifies no rows, but CHECK validation sequentially scans the approximately 1497 MB accounts table and can increase read I/O and latency. Adding each NOT VALID constraint briefly requires stronger table locks; a session-local 100 ms lock timeout and retries limit queuing and avoid changing application sessions' settings. Repeated lock acquisition failure aborts the change. Existing out-of-range balances or orphaned history rows cause validation to fail and the CR to roll back, because correcting data is not permitted. The foreign key is non-deferrable by default. Rollback drops only objects created by this CR; no table data is changed, and no restart or standby configuration change is required."
  }
}

-> results grid
-> results tables