Skip to content
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: support foreign key references to/from virtual columns #59671

Open
RaduBerinde opened this issue Feb 1, 2021 · 3 comments
Open

sql: support foreign key references to/from virtual columns #59671

RaduBerinde opened this issue Feb 1, 2021 · 3 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@RaduBerinde
Copy link
Member

RaduBerinde commented Feb 1, 2021

Jira issue: CRDB-3260

@RaduBerinde RaduBerinde added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Feb 1, 2021
@RaduBerinde
Copy link
Member Author

Fixing #46672 is a prerequisite (or they should be fixed together).

RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue Feb 1, 2021
Disallow FK references to or from virtual columns. Note that there is
no big reason why we couldn't support them other than some extra work
and testing surface; this is tracked by cockroachdb#59671.

Informs cockroachdb#57608.

Release note: None
craig bot pushed a commit that referenced this issue Feb 4, 2021
59675: sql: disallow virtual columns in FK references r=RaduBerinde a=RaduBerinde

Disallow FK references to or from virtual columns. Note that there is
no big reason why we couldn't support them other than some extra work
and testing surface; this is tracked by #59671.

Informs #57608.

Release note: None

59800: roachprod: extend error reporting for DNS sync r=rail a=rail

Related to #58905

In some cases `roachprod sync` fails updating the crdb.io DNS entries
without giving enough information about the failure. It looks like the
root cause may be the file format passed to the `gcloud dns` command.

Added extra information in the error message in order to get a better
picture when it happens again.

Release note: None

Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
Co-authored-by: Rail Aliiev <rail@cockroachlabs.com>
@jlinder jlinder added the T-sql-queries SQL Queries Team label Jun 16, 2021
@github-actions
Copy link

github-actions bot commented Sep 5, 2023

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@spilchen
Copy link
Contributor

spilchen commented Jun 3, 2024

Removing the blocking code is straight forward. However, validating the constraint has issues. This fails when the virtual column is in parent or in the child. Here are two repro scenarios (both of these assume the blocking code is removed):

  1. Virtual column in the parent
create table t1 (
  c1 int not null primary key, 
  c21 int not null, 
  c22 int not null, 
  c28 int not null as (c21 + c22) virtual, 
  unique (c28)
);
create table t2 (
  c28 int not null, 
  unique (c28), 
  foreign key (c28) references t1(c28)
);
insert into t1(c1,c21,c22) values (0,0,0);
insert into t2 values (0);
# ERROR: internal error: scanned virtual column depends on non-scanned column. 
  1. Virtual column in the child
create table parent (
  a int8 not null, 
  b int8 null primary key
);
create table vchild (
  a int8 not null primary key, 
  computed_col int8 as (a) virtual, 
  foreign key(computed_col) references parent(b)
);
insert into parent values (0,0);
insert into vchild values (0);
update parent set b=10 where b=0;
# ERROR: internal error: scanned virtual column depends on non-scanned column. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

4 participants