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: foreign key relationships should encode columns, not indexes #37255
Comments
Whoops, I forgot that I already filed a very similar issue to this one: #36859. Nevertheless, I'm going to close that one and replace with this one, as this one has the benefit of a couple more weeks of thinking, @lucy-zhang's input, and a concrete proposal. |
I wonder if it would be better to create a new protobuf entirely for the foreign key references, to avoid ambiguity during migration. Relatedly, I think the fact that the So, I think having two new protobufs for reference and back-reference would be ideal, though I can understand reusing the existing one for at least the (forward) reference. |
Great points, I agree with everything you said. |
Another question is what to do when dropping indexes on the referenced columns, if the backreferences aren't tied to specific indexes anymore, and there could be more than one usable index. Presumably, we'd need to enforce the existence of at least one unique index on (some subset of?) the referenced columns. (And if so, would we allow deleting the FK constraint automatically if there's only one such index and Postgres just associates a specific unique index to the foreign key, which can't be dropped without
|
Just of curiosity, when this is done will we allow foreign key relationships between columns of different tables which are unique but don't have the exact index to prove it? For example:
Is there extra work required to deduce that this foreign key could indeed be easily checked and if so should that be tracked elsewhere? |
Yeah, what you're describing (allowing unique indexes regardless of order) is part of the planned work, I think. |
This is done now. |
Currently, foreign key relationships are encoded on
IndexDescriptors
via theForeignKey
andReferencedBy
fields. This encoding has several unfortunate side-effects:I'm starting this issue to centralize any ongoing discussions. I'm assigning it to the Schema changes project, but it's possible that another team will ultimately do the work.
To avoid this situation, we should move the knowledge about foreign keys out of
IndexDescriptor
and intoTableDescriptor
. Further, theForeignKeyReference
protobuf should be changed to encode columns instead of indexes. Here's a proposed diff:Note that the old fields are deprecated and not deleted, because the code for the release that includes this upgrades will have to migrate descriptors from the old format to the new format, while preserving the old format so that mixed-version clusters can still work properly. The release after can delete the code that understands the old format, as well as change the deprecated fields to reserved (empty) ones.
The text was updated successfully, but these errors were encountered: