Repository navigation
sql: don't drop table constraints after a nullable UNIQUE - #39598
Conversation
Regression test for a non-primary UNIQUE constraint over a nullable column causing all later constraints of a table to be ignored. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TqfshTuYavDY1L2GUsW5YW
A non-primary UNIQUE constraint over a nullable column without NULLS NOT DISTINCT is not a key. Planning exited the whole constraints loop in that case, dropping every later constraint, including a primary key and the NOT NULL it implies. Skip just that constraint instead. Factor the UNIQUE/PRIMARY KEY handling shared by plan_create_table and plan_source_export_desc into plan_unique_constraints. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TqfshTuYavDY1L2GUsW5YW
keys.slt runs in standard mode, where each expected output line is one value, not one row. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TqfshTuYavDY1L2GUsW5YW
aljoscha
left a comment
There was a problem hiding this comment.
looks correct, but I don't know in detail what our constraints (ha!) here are
QA LLM Review (Post Merge)@antiguru — an automated review of commit 1. HIGH -- Re-planning existing tables and source exports changes their persisted RelationDesc, crash-looping environmentd or the source replica on upgrade
Existing items are re-planned from their stored DetailsContrary to the commit message, keys are part of the persist schema. I reproduced both paths by stopping the parent commit's image (
From reading the code, 0dt does not catch this either. In read-only mode only migrated builtin tables are registered ( Suggested fix: keep the desc of existing items stable. Add a catalog migration that removes the |
|
Thanks for catching this. Reverting in #39660. Correction to the description: keys are part of the persist schema. 🤖 Posted by Claude Code |
plan_create_tableandplan_source_export_descexited the whole constraints loop (break 'c) on a non-primaryUNIQUEover a nullable column withoutNULLS NOT DISTINCT. Every later constraint was silently ignored. For example,CREATE TABLE t (a int, b int, UNIQUE (a), PRIMARY KEY (b))lost its primary key and leftbnullable. The fix skips only that constraint. TheUNIQUE/PRIMARY KEYhandling the two functions duplicated now lives in a shared helper.Source purification: Postgres and MySQL always put the primary key first, so existing source exports never lost their PK or its implied NOT NULL. They could lose NOT NULL secondary unique keys that sort after a nullable
UNIQUE(Postgres sorts by constraint OID, MySQL by index name). Those keys come back when the exports are replanned. Keys are not part of the persist schema. SQL Server marks everyUNIQUEasNULLS NOT DISTINCTand was unaffected.Regression test in
test/sqllogictest/keys.slt, added in its own commit ahead of the fix.Closes: SQL-759
🤖 Generated with Claude Code
https://claude.ai/code/session_01TqfshTuYavDY1L2GUsW5YW