Skip to content

Commit

Permalink
sql: do not include inaccessible columns in information_schema.columns
Browse files Browse the repository at this point in the history
This commit omits inaccessible columns from the
`information_schema.columns` table. Inaccessible columns are also
excluded in `SHOW COLUMNS` due to its reliance on
`information_schema.columns`.

Fixes #70505

Release note (bug fix): Internal columns created by the system to
support expression indexes are now omitted from the output of `SHOW
COLUMNS` statements and the `information_schema.columns` table.
  • Loading branch information
mgartner committed Dec 29, 2021
1 parent ef133f1 commit e420f0f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sql/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ https://www.postgresql.org/docs/9.5/infoschema-columns.html`,
) error {
dbNameStr := tree.NewDString(db.GetName())
scNameStr := tree.NewDString(scName)
for _, column := range table.PublicColumns() {
for _, column := range table.AccessibleColumns() {
collationCatalog := tree.DNull
collationSchema := tree.DNull
collationName := tree.DNull
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/expression_index
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ CREATE TABLE public.t (
FAMILY fam_0_k_a_b_c_j (k, a, b, c, j)
)

query TTBTTTB colnames
SELECT * FROM [SHOW COLUMNS FROM t] ORDER BY column_name
----
column_name data_type is_nullable column_default generation_expression indices is_hidden
a INT8 true NULL · {primary} false
b INT8 true NULL · {primary} false
c STRING true NULL · {primary} false
comp INT8 true NULL a + 10 {} false
j JSONB true NULL · {primary} false
k INT8 false NULL · {primary,t_a_plus_b_idx,t_lower_c_a_plus_b_idx} false

# Referencing an inaccessible column in a CHECK constraint is not allowed.
statement error column \"crdb_internal_idx_expr\" is inaccessible and cannot be referenced
CREATE TABLE err (a INT, INDEX ((a + 10)), CHECK (crdb_internal_idx_expr > 0))
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -4755,3 +4755,20 @@ SELECT distinct is_identity FROM information_schema.columns
is_identity
NO
YES

statement ok
SET DATABASE = test

# Regression test for #70505. Inaccessible columns should not be included in
# information_schema.columns.
subtest regression_70505

statement ok
CREATE TABLE t70505 (k INT PRIMARY KEY, a INT, b INT, INDEX ((a + b), (a + 10)))

query T rowsort
SELECT column_name FROM information_schema.columns WHERE table_name = 't70505'
----
k
a
b

0 comments on commit e420f0f

Please sign in to comment.