From fb77d5dbc3cf02f83f87ddb0a76cdff5c1cf86da Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Wed, 24 Jul 2019 22:27:06 -0400 Subject: [PATCH] opt: add catalog test with FKs Add `EXPLAIN (OPT, CATALOG)` tests with foreign keys, which show the current problem with inbound references. Release note: None --- pkg/sql/opt/exec/execbuilder/testdata/catalog | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/sql/opt/exec/execbuilder/testdata/catalog b/pkg/sql/opt/exec/execbuilder/testdata/catalog index 4ef317aba38f..635a03c85d96 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/catalog +++ b/pkg/sql/opt/exec/execbuilder/testdata/catalog @@ -80,3 +80,48 @@ TABLE uvwxy ├── u int not null └── v int not null scan uvwxy + +# Test foreign keys. +statement ok +CREATE TABLE parent (p INT, q INT, r INT, other INT, PRIMARY KEY (p, q, r)) + +statement ok +CREATE TABLE child ( + c INT PRIMARY KEY, + p INT, q INT, r INT, + CONSTRAINT fk FOREIGN KEY (p,q,r) REFERENCES parent(p,q,r) MATCH FULL +) + +query T +EXPLAIN (OPT, CATALOG) SELECT * from child +---- +TABLE child + ├── c int not null + ├── p int + ├── q int + ├── r int + ├── INDEX primary + │ └── c int not null + ├── INDEX child_auto_index_fk + │ ├── p int + │ ├── q int + │ ├── r int + │ └── c int not null + └── CONSTRAINT fk FOREIGN KEY test.public.child (p, q, r) REFERENCES test.public.parent (p, q, r) MATCH FULL +scan child + +# TODO(lucy/jordan/radu): the inbound foreign key reference is borked. +query T +EXPLAIN (OPT, CATALOG) SELECT * from parent +---- +TABLE parent + ├── p int not null + ├── q int not null + ├── r int not null + ├── other int + ├── INDEX primary + │ ├── p int not null + │ ├── q int not null + │ └── r int not null + └── REFERENCED BY CONSTRAINT FOREIGN KEY test.public.child () REFERENCES test.public.parent () +scan parent