Skip to content

Commit

Permalink
opt/testcat: fix hidden columns in opt tester
Browse files Browse the repository at this point in the history
This commit makes two related fixes to the way hidden columns are handled
in the test catalog:
* Columns declared using `NOT VISIBLE` are now defined as hidden instead
  of visible.
* The implicit type for a table now includes only visible columns.

Informs #133331

Release note: None
  • Loading branch information
DrewKimball committed Oct 25, 2024
1 parent 3bab131 commit 277bc21
Show file tree
Hide file tree
Showing 5 changed files with 610 additions and 454 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/opt/memo/testdata/stats/scan
Original file line number Diff line number Diff line change
Expand Up @@ -2601,10 +2601,10 @@ build
SELECT * FROM a_check_hash WHERE crdb_internal_a_shard_8 > 6
----
project
├── columns: i:1(int!null) crdb_internal_a_shard_8:2(int4!null) j:3(int)
├── columns: i:1(int!null) j:3(int)
├── stats: [rows=125]
├── key: (1)
├── fd: (1,2)-->(3), (1)-->(2)
├── fd: (1)-->(3)
└── select
├── columns: i:1(int!null) crdb_internal_a_shard_8:2(int4!null) j:3(int) crdb_internal_mvcc_timestamp:4(decimal) tableoid:5(oid)
├── stats: [rows=125, distinct(2)=1, null(2)=0]
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/opt/testutils/testcat/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ func (tt *Table) addColumn(def *tree.ColumnTableDef) {
kind = cat.DeleteOnly
visibility = cat.Inaccessible
}
if def.Hidden && visibility == cat.Visible {
visibility = cat.Hidden
}

var defaultExpr, computedExpr, onUpdateExpr, generatedAsIdentitySequenceOption *string
if def.DefaultExpr.Expr != nil {
Expand Down
33 changes: 33 additions & 0 deletions pkg/sql/opt/testutils/testcat/testdata/table
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,36 @@ TABLE t76994
│ └── WHERE b < 0
└── UNIQUE WITHOUT INDEX (a)
└── WHERE b > 0

# Table implicit types should not include hidden columns.
exec-ddl
CREATE TABLE hidden_columns (
a INT,
b INT NOT VISIBLE,
c INT
)
----

build
SELECT ROW(1, 2)::hidden_columns;
----
project
├── columns: row:1(tuple{int AS a, int AS c}!null)
├── cardinality: [1 - 1]
├── immutable
├── stats: [rows=1]
├── cost: 0.05
├── key: ()
├── fd: ()-->(1)
├── prune: (1)
├── values
│ ├── cardinality: [1 - 1]
│ ├── stats: [rows=1]
│ ├── cost: 0.02
│ ├── key: ()
│ └── tuple [type=tuple]
└── projections
└── cast: RECORD [as=row:1, type=tuple{int AS a, int AS c}, immutable]
└── tuple [type=tuple{int, int}]
├── const: 1 [type=int]
└── const: 2 [type=int]
4 changes: 2 additions & 2 deletions pkg/sql/opt/testutils/testcat/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (tc *Catalog) ResolveType(
labels := make([]string, 0, tab.ColumnCount())
for i, n := 0, tab.ColumnCount(); i < n; i++ {
col := tab.Column(i)
if col.Kind() == cat.Ordinary {
if col.Kind() == cat.Ordinary && col.Visibility() == cat.Visible {
contents = append(contents, col.DatumType())
labels = append(labels, string(col.ColName()))
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (tc *Catalog) ResolveTypeByOID(ctx context.Context, typID oid.Oid) (*types.
labels := make([]string, 0, tab.ColumnCount())
for i, n := 0, tab.ColumnCount(); i < n; i++ {
col := tab.Column(i)
if col.Kind() == cat.Ordinary {
if col.Kind() == cat.Ordinary && col.Visibility() == cat.Visible {
contents = append(contents, col.DatumType())
labels = append(labels, string(col.ColName()))
}
Expand Down
Loading

0 comments on commit 277bc21

Please sign in to comment.