-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: columns can only be used in one outgoing foreign key #23580
Comments
cc @BramGruneir |
Example SQL that triggers the error: https://gist.github.com/erichocean/9bc11d8c3ccfdfee6815ad61bb2cd850 |
Copying here for posterity: CREATE TABLE a (
id UUID NOT NULL DEFAULT gen_random_uuid(),
PRIMARY KEY (id)
);
CREATE TABLE aa (
a UUID NOT NULL,
at TIMESTAMPTZ NOT NULL DEFAULT statement_timestamp(),
PRIMARY KEY (a, at),
CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id)
) INTERLEAVE IN PARENT a (a);
CREATE TABLE ab (
a UUID NOT NULL,
at TIMESTAMPTZ NOT NULL DEFAULT statement_timestamp(),
PRIMARY KEY (a, at),
CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id)
) INTERLEAVE IN PARENT a (a);
CREATE TABLE ac (
a UUID NOT NULL,
aa TIMESTAMPTZ,
ab TIMESTAMPTZ,
PRIMARY KEY (a),
CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id),
CONSTRAINT fk_aa FOREIGN KEY (a, aa) REFERENCES aa (a, at),
CONSTRAINT fk_ab FOREIGN KEY (a, ab) REFERENCES ab (a, at)
) INTERLEAVE IN PARENT a (a); Fails with:
Workaround: CREATE TABLE a (
id UUID NOT NULL DEFAULT gen_random_uuid(),
PRIMARY KEY (id)
);
CREATE TABLE aa (
a UUID NOT NULL,
at TIMESTAMPTZ NOT NULL DEFAULT statement_timestamp(),
PRIMARY KEY (a, at),
CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id)
) INTERLEAVE IN PARENT a (a);
CREATE TABLE ab (
a UUID NOT NULL,
at TIMESTAMPTZ NOT NULL DEFAULT statement_timestamp(),
PRIMARY KEY (a, at),
CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id)
) INTERLEAVE IN PARENT a (a);
CREATE TABLE ac (
a UUID NOT NULL,
a1 UUID NOT NULL CHECK (a = a1), -- <====== duplicate 'a' here with a check() statement
aa TIMESTAMPTZ,
ab TIMESTAMPTZ,
PRIMARY KEY (a),
CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id),
CONSTRAINT fk_aa FOREIGN KEY (a, aa) REFERENCES aa (a, at),
CONSTRAINT fk_ab FOREIGN KEY (a1, ab) REFERENCES ab (a, at) -- <====== use the duplicate 'a1' instead in the FK constraint
) INTERLEAVE IN PARENT a (a); |
cc @awoods187 for triage and prioritization |
Just to be clear, this is a known limitation. |
This problem is exacerbated with geo-partitioning where many tables will use the same partition key. for example, if I have |
This is very annoying. |
@dt @BramGruneir can we schedule some time to sit together and hash out an analysis of this situation. We need to learn:
Once we have hashed this out, we will be able to more confidently and clearly react to user expectations. |
Meeting notes from today
[1] really we would also have ran into this issue with multiple indexes on the same group of columns but different orderings. This is a reasonable / realistic scenario even without geo-partitioning. Course of action:
|
Hi, As per the discussion above, it seems like it's been discussed to lift the limitations with the FK. Any idea when you are planning to do this change. I'm having a similar table as described in [1] and I'm facing the issue which is addressed in [1]. I'm using the latest version of cockroachdb I really appreciate your comments on this. Also please let me know if there are any other ways to avoid this as changing the DB schema is not a valid solution for me [1] #23580 (comment) Thanks |
This came up again when thinking about upgrading from a single-region to multi-region with Movr. cc @RaduBerinde we will want to address this after we plan foreign key cascades |
This is actually going to be fixed in 20.1! 🎉 This is a duplicate of #38850. |
Wonderful!
…On Fri, Mar 27, 2020 at 11:06 AM Jordan Lewis ***@***.***> wrote:
Closed #23580 <#23580>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23580 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMKDOIMV4QA5DFPKEKA64DRJS6IJANCNFSM4EUJOLOA>
.
|
From @erichocean on gitter:
@erichocean could you comment here and add the SQL statements you have used to (attempt to) create your schema?
The text was updated successfully, but these errors were encountered: