File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
ccl/logictestccl/testdata/logic_test Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -1659,4 +1659,29 @@ SELECT * FROM chgme ORDER BY C1;
1659
1659
statement ok
1660
1660
DROP TABLE chgme;
1661
1661
1662
+ # Regression test for issue #151216
1663
+ # Tests that CREATE VIEW with references to crdb_region column in expressions
1664
+ # (but not directly returned) should not trigger validation assertion errors.
1665
+ subtest issue_151216_view_crdb_region_reference
1666
+
1667
+ statement ok
1668
+ CREATE DATABASE bank_151216 PRIMARY REGION "us-east-1" REGIONS "us-east-1", "ca-central-1", "ap-southeast-2" SURVIVE REGION FAILURE;
1669
+
1670
+ statement ok
1671
+ USE bank_151216;
1672
+
1673
+ statement ok
1674
+ CREATE TABLE t1 (c1 INT) LOCALITY REGIONAL BY ROW;
1675
+
1676
+ statement ok
1677
+ CREATE MATERIALIZED VIEW mv1 AS SELECT c1, CASE WHEN crdb_region = 'us-east-1' THEN 'east' ELSE 'other' END AS region_type FROM t1;
1678
+
1679
+ statement ok
1680
+ CREATE VIEW v2 AS SELECT c1, crdb_region = 'us-east-1' AS is_us_east1 FROM t1;
1681
+
1682
+ statement ok
1683
+ SET sql_safe_updates = false;
1684
+ DROP DATABASE bank_151216;
1685
+ SET sql_safe_updates = true
1686
+
1662
1687
subtest end
Original file line number Diff line number Diff line change @@ -121,7 +121,8 @@ func ValidateTableLocalityConfig(
121
121
switch lc := lc .Locality .(type ) {
122
122
case * catpb.LocalityConfig_Global_ :
123
123
if regionEnumIDReferenced {
124
- if ! columnTypesTypeIDs .Contains (regionsEnumID ) {
124
+ // Omit views since they may reference the multi-region enum type of the base table.
125
+ if ! columnTypesTypeIDs .Contains (regionsEnumID ) && ! desc .IsView () {
125
126
return errors .AssertionFailedf (
126
127
"expected no region Enum ID to be referenced by a GLOBAL TABLE: %q" +
127
128
" but found: %d" ,
@@ -233,8 +234,9 @@ func ValidateTableLocalityConfig(
233
234
if regionEnumIDReferenced {
234
235
// It may be the case that the multi-region type descriptor is used
235
236
// as the type of the table column. Validations should only fail if
236
- // that is not the case.
237
- if ! columnTypesTypeIDs .Contains (regionsEnumID ) {
237
+ // that is not the case. We omit views since they may reference the
238
+ // multi-region enum type of the base table.
239
+ if ! columnTypesTypeIDs .Contains (regionsEnumID ) && ! desc .IsView () {
238
240
return errors .AssertionFailedf (
239
241
"expected no region Enum ID to be referenced by a REGIONAL BY TABLE: %q homed in the " +
240
242
"primary region, but found: %d" ,
You can’t perform that action at this time.
0 commit comments