Skip to content

Commit 9b30515

Browse files
committed
opt,testcat: allow defining the region column explicitly in opt tests
This commit adds support for explicitly defining the `crdb_region` column for REGIONAL BY ROW tables in optimizer tests. This will allow testing scenarios like a computed region column. Epic: None Release note: None
1 parent dfd17d1 commit 9b30515

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

pkg/sql/opt/testutils/testcat/create_table.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,27 @@ func (tc *Catalog) CreateTable(stmt *tree.CreateTable) *Table {
115115
// so use type STRING instead.
116116
oid := types.String.Oid()
117117

118-
evalCtx := eval.MakeTestingEvalContext(cluster.MakeTestingClusterSettings())
119-
crdbRegionDef :=
120-
multiregion.RegionalByRowDefaultColDef(
121-
oid,
122-
multiregion.RegionalByRowGatewayRegionDefaultExpr(oid),
123-
multiregion.MaybeRegionalByRowOnUpdateExpr(&evalCtx, oid),
124-
)
125-
crdbRegionDef.Type = types.String
126-
stmt.Defs = append(stmt.Defs, crdbRegionDef)
118+
// Add a region column only if one doesn't already exist.
119+
hasRegionCol := false
120+
for _, def := range stmt.Defs {
121+
if colDef, ok := def.(*tree.ColumnTableDef); ok {
122+
if colDef.Name == tree.RegionalByRowRegionDefaultColName {
123+
hasRegionCol = true
124+
break
125+
}
126+
}
127+
}
128+
if !hasRegionCol {
129+
evalCtx := eval.MakeTestingEvalContext(cluster.MakeTestingClusterSettings())
130+
crdbRegionDef :=
131+
multiregion.RegionalByRowDefaultColDef(
132+
oid,
133+
multiregion.RegionalByRowGatewayRegionDefaultExpr(oid),
134+
multiregion.MaybeRegionalByRowOnUpdateExpr(&evalCtx, oid),
135+
)
136+
crdbRegionDef.Type = types.String
137+
stmt.Defs = append(stmt.Defs, crdbRegionDef)
138+
}
127139
tab.implicitRBRIndexElem =
128140
&tree.IndexElem{
129141
Column: tree.RegionalByRowRegionDefaultColName,

0 commit comments

Comments
 (0)