Skip to content

Commit

Permalink
Merge #82763
Browse files Browse the repository at this point in the history
82763: tree: fix a possible bug in simple statement visitor r=ajwerner a=rafiss

The error from this visitor was never being returned.

This required a change to one usage of it when creating views, since the
old implementation would encounter errors when initializing virtual
table views.

Release note (bug fix): Views are no longer allowed to reference types
that are defined in different databases. Even though this was allowed
at view-creation time before, it would cause errors, since
cross-database type references are not supported.

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Jun 15, 2022
2 parents 1f6c94c + 10a054b commit 880b9fa
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ howdy hello false
exec-sql
INSERT INTO d.expr VALUES ('hi')
----
pq: failed to satisfy CHECK constraint (x < 'hi':::public.greeting)
pq: failed to satisfy CHECK constraint (x < 'hi':::d.public.greeting)

# We should be able to use the restored types to create new tables.
exec-sql
Expand Down
52 changes: 26 additions & 26 deletions pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/ccl/logictestccl/testdata/logic_test/auto_rehoming
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SHOW CREATE TABLE db.rbr
db.public.rbr CREATE TABLE public.rbr (
p INT8 NOT NULL,
s STRING NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region ON UPDATE rehome_row()::public.crdb_internal_region,
crdb_region db.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::db.public.crdb_internal_region ON UPDATE rehome_row()::db.public.crdb_internal_region,
CONSTRAINT rbr_pkey PRIMARY KEY (p ASC)
) LOCALITY REGIONAL BY ROW

Expand All @@ -38,6 +38,6 @@ SHOW CREATE TABLE db.rbr_altered
----
db.public.rbr_altered CREATE TABLE public.rbr_altered (
p INT8 NOT NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region ON UPDATE rehome_row()::public.crdb_internal_region,
crdb_region db.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::db.public.crdb_internal_region ON UPDATE rehome_row()::db.public.crdb_internal_region,
CONSTRAINT rbr_altered_pkey PRIMARY KEY (p ASC)
) LOCALITY REGIONAL BY ROW
8 changes: 4 additions & 4 deletions pkg/ccl/logictestccl/testdata/logic_test/multi_region
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ SELECT create_statement from [SHOW CREATE TABLE t_as]
create_statement
CREATE TABLE public.t_as (
i INT8 NULL,
crdb_region public.crdb_internal_region NULL,
crdb_region mr-create-table-as.public.crdb_internal_region NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t_as_pkey PRIMARY KEY (rowid ASC)
) LOCALITY REGIONAL BY TABLE IN PRIMARY REGION
Expand All @@ -1512,7 +1512,7 @@ SELECT create_statement from [SHOW CREATE TABLE t_as]
create_statement
CREATE TABLE public.t_as (
i INT8 NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-create-table-as.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-create-table-as.public.crdb_internal_region,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t_as_pkey PRIMARY KEY (rowid ASC)
) LOCALITY REGIONAL BY ROW AS crdb_region
Expand Down Expand Up @@ -1555,7 +1555,7 @@ SELECT create_statement from [SHOW CREATE TABLE t_as]
create_statement
CREATE TABLE public.t_as (
i INT8 NOT NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-create-table-as.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-create-table-as.public.crdb_internal_region,
CONSTRAINT t_as_pkey PRIMARY KEY (i ASC)
) LOCALITY REGIONAL BY ROW AS crdb_region

Expand All @@ -1565,7 +1565,7 @@ SELECT create_statement from [SHOW CREATE TABLE t]
create_statement
CREATE TABLE public.t (
i INT8 NOT NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-create-table-as.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-create-table-as.public.crdb_internal_region,
CONSTRAINT t_pkey PRIMARY KEY (i ASC)
) LOCALITY REGIONAL BY ROW

Expand Down
16 changes: 8 additions & 8 deletions pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-1.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-1.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down Expand Up @@ -299,7 +299,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-2.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-2.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down Expand Up @@ -517,7 +517,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-1.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-1.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down Expand Up @@ -672,7 +672,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-2.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-2.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down Expand Up @@ -854,7 +854,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-1.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-1.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down Expand Up @@ -983,7 +983,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-2.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-2.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down Expand Up @@ -1116,7 +1116,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-2.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-2.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down Expand Up @@ -1279,7 +1279,7 @@ regional_by_row_table CREATE TABLE public.regional_by_row_table (
a INT8 NOT NULL,
b INT8 NOT NULL,
j JSONB NULL,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
crdb_region mr-backup-2.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-backup-2.public.crdb_internal_region,
CONSTRAINT regional_by_row_table_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_table_a_idx (a ASC),
UNIQUE INDEX regional_by_row_table_b_key (b ASC),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ SHOW CREATE TABLE regional_by_row_as
regional_by_row_as CREATE TABLE public.regional_by_row_as (
pk INT8 NOT NULL,
i INT8 NULL,
cr public.crdb_internal_region NOT NULL DEFAULT 'ca-central-1':::public.crdb_internal_region,
crdb_region public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::public.crdb_internal_region,
cr mr-zone-configs.public.crdb_internal_region NOT NULL DEFAULT 'ca-central-1':::mr-zone-configs.public.crdb_internal_region,
crdb_region mr-zone-configs.public.crdb_internal_region NOT VISIBLE NOT NULL DEFAULT default_to_database_primary_region(gateway_region())::mr-zone-configs.public.crdb_internal_region,
CONSTRAINT regional_by_row_as_pkey PRIMARY KEY (pk ASC),
INDEX regional_by_row_as_i_idx (i ASC),
FAMILY fam_0_cr_pk_i (cr, pk, i, crdb_region)
Expand Down
Loading

0 comments on commit 880b9fa

Please sign in to comment.