-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: add unique constraints to table descriptor #57502
Conversation
This commit adds unique constraints to the table descriptor. This is currently only implemented for unique constraints that are enforced by a unique index. Unique constraints wihout an index are still not supported. However, this PR lays the groundwork so that UNIQUE WITHOUT INDEX can be supported in future PRs. Release note: None
General question, without having reviewed the code: is there going to be a migration to upgrade old table descriptors to include unique constraints? Otherwise, how will we ensure that all future code can understand descriptors with and without explicit unique constraints listed? |
I'm not 100% sure that will be necessary. If I eventually remove the logic in Either way, I don't think it's necessary for this PR, but I would definitely welcome any advice for how to handle the migration/version issue. EDIT: Thinking about this more, I think some type of migration logic will probably be necessary even if I don't remove that logic in |
What migration logic will be necessary? In other words, what new code will depend on the existence of a For the foreign key representation upgrade, we handled the lack of a framework that could do a long-running migration over all descriptors (see @irfansharif's work #48843) by having all descriptors get upgraded on-demand upon read, in But, I just want to give a heads up that we've had very serious issues in descriptor related code in the past due to this kind of work, because it's so easy to make changes that end up incompatible later unless there is a trusted and correct migration. We have scar tissue here recently from the foreign key issue seen in #57032 (and see the postmortem here: https://cockroachlabs.atlassian.net/wiki/spaces/SCHEMA/pages/1127219391/20.2+Foreign+Key+corruption+postmortem). One of the follow up items from this postmortem was to ensure that we have better, automatic cross-version testing for descriptor format changes. But, we don't have this yet. All of this to say that I just want to make sure we have eyes on this, and unfortunately we may need to move a little more slowly on this upgrade than you would have hoped to ensure that we're confident in the resilience of this kind of migration. We might want to schedule an in-person sync about this with the Schema team. |
There are two cases I see:
Scheduling a meeting sounds good. I can put something on the calendar for next week. |
I've thought about this more, and I think there are more downsides than benefits to this PR. I thought it would make sense to store all unique constraints (both with and without an index) in the same slice for consistency and to improve Postgres compatibility, but I think it adds unnecessary complications:
Given this, I will close this PR, revise it, and reopen with the following changes:
If anyone disagrees with this approach feel free to comment. |
This commit adds unique constraints to the table descriptor. This is
currently only implemented for unique constraints that are enforced by
a unique index. Unique constraints wihout an index are still not supported.
However, this PR lays the groundwork so that
UNIQUE WITHOUT INDEX
canbe supported in future PRs.
Release note: None