Skip to content

Commit b3d1e3a

Browse files
authored
Merge pull request #154167 from cockroachdb/blathers/backport-release-25.4-154019
release-25.4: sql: add virtual view for inspect errors
2 parents 236bd7c + 4fdd233 commit b3d1e3a

File tree

16 files changed

+258
-190
lines changed

16 files changed

+258
-190
lines changed

pkg/cli/testdata/zip/file-filters/testzip_file_filters

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ debug/cluster_settings_history.txt
55
debug/crdb_internal.cluster_contention_events.txt
66
debug/crdb_internal.cluster_database_privileges.txt
77
debug/crdb_internal.cluster_distsql_flows.txt
8+
debug/crdb_internal.cluster_inspect_errors.txt
89
debug/crdb_internal.cluster_locks.txt
910
debug/crdb_internal.cluster_queries.txt
1011
debug/crdb_internal.cluster_replication_spans.txt
@@ -149,6 +150,7 @@ debug/cluster_settings_history.txt
149150
debug/crdb_internal.cluster_contention_events.txt
150151
debug/crdb_internal.cluster_database_privileges.txt
151152
debug/crdb_internal.cluster_distsql_flows.txt
153+
debug/crdb_internal.cluster_inspect_errors.txt
152154
debug/crdb_internal.cluster_locks.txt
153155
debug/crdb_internal.cluster_queries.txt
154156
debug/crdb_internal.cluster_replication_spans.txt
@@ -300,6 +302,7 @@ debug/cluster_settings_history.txt
300302
debug/crdb_internal.cluster_contention_events.txt
301303
debug/crdb_internal.cluster_database_privileges.txt
302304
debug/crdb_internal.cluster_distsql_flows.txt
305+
debug/crdb_internal.cluster_inspect_errors.txt
303306
debug/crdb_internal.cluster_locks.txt
304307
debug/crdb_internal.cluster_queries.txt
305308
debug/crdb_internal.cluster_replication_spans.txt
@@ -445,6 +448,7 @@ debug/cluster_settings_history.txt
445448
debug/crdb_internal.cluster_contention_events.txt
446449
debug/crdb_internal.cluster_database_privileges.txt
447450
debug/crdb_internal.cluster_distsql_flows.txt
451+
debug/crdb_internal.cluster_inspect_errors.txt
448452
debug/crdb_internal.cluster_locks.txt
449453
debug/crdb_internal.cluster_queries.txt
450454
debug/crdb_internal.cluster_replication_spans.txt
@@ -558,6 +562,7 @@ debug/cluster_settings_history.txt
558562
debug/crdb_internal.cluster_contention_events.txt
559563
debug/crdb_internal.cluster_database_privileges.txt
560564
debug/crdb_internal.cluster_distsql_flows.txt
565+
debug/crdb_internal.cluster_inspect_errors.txt
561566
debug/crdb_internal.cluster_locks.txt
562567
debug/crdb_internal.cluster_queries.txt
563568
debug/crdb_internal.cluster_replication_spans.txt

pkg/cli/zip_table_registry.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ var zipInternalTablesPerCluster = DebugZipTableRegistry{
162162
"crdb_internal.hide_sql_constants(stmt) as stmt",
163163
},
164164
},
165+
"crdb_internal.cluster_inspect_errors": {
166+
nonSensitiveCols: NonSensitiveColumns{
167+
"error_id",
168+
"job_id",
169+
"error_type",
170+
"aost",
171+
"database_id",
172+
"schema_id",
173+
"id",
174+
},
175+
},
165176
"crdb_internal.cluster_locks": {
166177
// `lock_key` column contains the txn lock key, which may contain
167178
// sensitive row-level data.

pkg/cli/zip_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ table_name NOT IN (
8484
'forward_dependencies',
8585
'gossip_network',
8686
'index_columns',
87-
'index_spans',
88-
'kv_builtin_function_comments',
87+
'index_spans',
88+
'kv_builtin_function_comments',
8989
'kv_catalog_comments',
9090
'kv_catalog_descriptor',
9191
'kv_catalog_namespace',

pkg/sql/crdb_internal.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ var crdbInternal = virtualSchema{
231231
catconstants.CrdbInternalFullyQualifiedNamesViewID: crdbInternalFullyQualifiedNamesView,
232232
catconstants.CrdbInternalStoreLivenessSupportFrom: crdbInternalStoreLivenessSupportFromTable,
233233
catconstants.CrdbInternalStoreLivenessSupportFor: crdbInternalStoreLivenessSupportForTable,
234+
catconstants.CrdbInternalClusterInspectErrorsViewID: crdbInternalClusterInspectErrorsView,
234235
},
235236
validWithNoDatabaseContext: true,
236237
}
@@ -9666,3 +9667,24 @@ func populateStoreLivenessSupportResponse(
96669667
}
96679668
return nil
96689669
}
9670+
9671+
// crdb_internal.cluster_inspect_errors is a view to give permission to
9672+
// non-admins to access the system.inspect_errors table
9673+
var crdbInternalClusterInspectErrorsView = virtualSchemaView{
9674+
schema: `
9675+
CREATE VIEW crdb_internal.cluster_inspect_errors AS
9676+
SELECT * FROM system.inspect_errors`,
9677+
resultColumns: colinfo.ResultColumns{
9678+
{Name: "error_id", Typ: types.Uuid},
9679+
{Name: "job_id", Typ: types.Int},
9680+
{Name: "error_type", Typ: types.String},
9681+
{Name: "aost", Typ: types.TimestampTZ},
9682+
{Name: "database_id", Typ: types.Oid},
9683+
{Name: "schema_id", Typ: types.Oid},
9684+
{Name: "id", Typ: types.Oid},
9685+
{Name: "primary_key", Typ: types.String},
9686+
{Name: "details", Typ: types.Jsonb},
9687+
{Name: "crdb_internal_expiration", Typ: types.TimestampTZ},
9688+
},
9689+
comment: `wrapper over system.inspect_errors`,
9690+
}

pkg/sql/logictest/testdata/logic_test/crdb_internal

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,3 +1774,32 @@ SELECT * FROM crdb_internal.create_type_statements WHERE descriptor_id = (('othe
17741774
----
17751775

17761776
subtest end
1777+
1778+
subtest cluster_inspect_errors_view
1779+
1780+
skipif config local-mixed-25.2
1781+
skipif config local-mixed-25.3
1782+
query TT colnames
1783+
SELECT column_name, data_type
1784+
FROM information_schema.columns
1785+
WHERE table_schema = 'crdb_internal' AND table_name = 'cluster_inspect_errors'
1786+
ORDER BY ordinal_position
1787+
----
1788+
column_name data_type
1789+
error_id uuid
1790+
job_id bigint
1791+
error_type text
1792+
aost timestamp with time zone
1793+
database_id oid
1794+
schema_id oid
1795+
id oid
1796+
primary_key text
1797+
details jsonb
1798+
crdb_internal_expiration timestamp with time zone
1799+
1800+
skipif config local-mixed-25.2
1801+
skipif config local-mixed-25.3
1802+
statement ok
1803+
SELECT count(*) FROM crdb_internal.cluster_inspect_errors
1804+
1805+
subtest end

pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor W
149149
111 {"table": {"checks": [{"columnIds": [1], "constraintId": 2, "expr": "k > 0:::INT8", "name": "ck"}], "columns": [{"id": 1, "name": "k", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "v", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "dependedOnBy": [{"columnIds": [1, 2], "id": 112}], "formatVersion": 3, "id": 111, "name": "kv", "nextColumnId": 3, "nextConstraintId": 3, "nextIndexId": 2, "nextMutationId": 1, "parentId": 106, "primaryIndex": {"constraintId": 1, "encodingType": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "keyColumnDirections": ["ASC"], "keyColumnIds": [1], "keyColumnNames": ["k"], "name": "kv_pkey", "partitioning": {}, "sharded": {}, "storeColumnIds": [2], "storeColumnNames": ["v"], "unique": true, "vecConfig": {}, "version": 4}, "privileges": {"ownerProto": "root", "users": [{"privileges": "2", "userProto": "admin", "withGrantOption": "2"}, {"privileges": "2", "userProto": "root", "withGrantOption": "2"}], "version": 3}, "replacementOf": {"time": {}}, "schemaLocked": true, "unexposedParentSchemaId": 107, "version": "7"}}
150150
112 {"table": {"columns": [{"id": 1, "name": "k", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "v", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"defaultExpr": "unique_rowid()", "hidden": true, "id": 3, "name": "rowid", "type": {"family": "IntFamily", "oid": 20, "width": 64}}], "dependsOn": [111], "formatVersion": 3, "id": 112, "indexes": [{"createdExplicitly": true, "foreignKey": {}, "geoConfig": {}, "id": 2, "interleave": {}, "keyColumnDirections": ["ASC"], "keyColumnIds": [2], "keyColumnNames": ["v"], "keySuffixColumnIds": [3], "name": "idx", "partitioning": {}, "sharded": {}, "vecConfig": {}, "version": 4}], "isMaterializedView": true, "name": "mv", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 4, "nextMutationId": 1, "parentId": 106, "primaryIndex": {"constraintId": 1, "encodingType": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "keyColumnDirections": ["ASC"], "keyColumnIds": [3], "keyColumnNames": ["rowid"], "name": "mv_pkey", "partitioning": {}, "sharded": {}, "storeColumnIds": [1, 2], "storeColumnNames": ["k", "v"], "unique": true, "vecConfig": {}, "version": 4}, "privileges": {"ownerProto": "root", "users": [{"privileges": "2", "userProto": "admin", "withGrantOption": "2"}, {"privileges": "2", "userProto": "root", "withGrantOption": "2"}], "version": 3}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 107, "version": "8", "viewQuery": "SELECT k, v FROM db.public.kv"}}
151151
113 {"function": {"functionBody": "SELECT json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(json_remove_path(d, ARRAY['table':::STRING, 'families':::STRING]:::STRING[]), ARRAY['table':::STRING, 'nextFamilyId':::STRING]:::STRING[]), ARRAY['table':::STRING, 'indexes':::STRING, '0':::STRING, 'createdAtNanos':::STRING]:::STRING[]), ARRAY['table':::STRING, 'indexes':::STRING, '1':::STRING, 'createdAtNanos':::STRING]:::STRING[]), ARRAY['table':::STRING, 'indexes':::STRING, '2':::STRING, 'createdAtNanos':::STRING]:::STRING[]), ARRAY['table':::STRING, 'primaryIndex':::STRING, 'createdAtNanos':::STRING]:::STRING[]), ARRAY['table':::STRING, 'createAsOfTime':::STRING]:::STRING[]), ARRAY['table':::STRING, 'modificationTime':::STRING]:::STRING[]), ARRAY['function':::STRING, 'modificationTime':::STRING]:::STRING[]), ARRAY['type':::STRING, 'modificationTime':::STRING]:::STRING[]), ARRAY['schema':::STRING, 'modificationTime':::STRING]:::STRING[]), ARRAY['database':::STRING, 'modificationTime':::STRING]:::STRING[]);", "id": 113, "lang": "SQL", "name": "strip_volatile", "nullInputBehavior": "CALLED_ON_NULL_INPUT", "params": [{"class": "IN", "name": "d", "type": {"family": "JsonFamily", "oid": 3802}}], "parentId": 104, "parentSchemaId": 105, "privileges": {"ownerProto": "root", "users": [{"privileges": "2", "userProto": "admin", "withGrantOption": "2"}, {"privileges": "1048576", "userProto": "public"}, {"privileges": "2", "userProto": "root", "withGrantOption": "2"}], "version": 3}, "returnType": {"type": {"family": "JsonFamily", "oid": 3802}}, "version": "1", "volatility": "STABLE"}}
152-
4294966962 {"table": {"columns": [{"id": 1, "name": "f_table_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 2, "name": "f_table_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 3, "name": "f_table_name", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 4, "name": "f_geometry_column", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 5, "name": "coord_dimension", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 6, "name": "srid", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 7, "name": "type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294966962, "name": "geometry_columns", "nextColumnId": 8, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}, "vecConfig": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 3}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294966964, "version": "1"}}
152+
4294966962 {"table": {"columns": [{"id": 1, "name": "f_table_catalog", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 2, "name": "f_table_schema", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 3, "name": "f_table_name", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 4, "name": "f_geography_column", "nullable": true, "type": {"family": "StringFamily", "oid": 19}}, {"id": 5, "name": "coord_dimension", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 6, "name": "srid", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 7, "name": "type", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294966962, "name": "geography_columns", "nextColumnId": 8, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}, "vecConfig": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 3}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294966963, "version": "1"}}

pkg/sql/logictest/testdata/logic_test/pg_builtins

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -213,42 +213,42 @@ is_updatable b 123 2 28
213213
is_updatable c 123 3 28 false
214214
is_updatable_view a 124 1 0 false
215215
is_updatable_view b 124 2 0 false
216-
pg_class oid 4294967082 1 0 false
217-
pg_class relname 4294967082 2 0 false
218-
pg_class relnamespace 4294967082 3 0 false
219-
pg_class reltype 4294967082 4 0 false
220-
pg_class reloftype 4294967082 5 0 false
221-
pg_class relowner 4294967082 6 0 false
222-
pg_class relam 4294967082 7 0 false
223-
pg_class relfilenode 4294967082 8 0 false
224-
pg_class reltablespace 4294967082 9 0 false
225-
pg_class relpages 4294967082 10 0 false
226-
pg_class reltuples 4294967082 11 0 false
227-
pg_class relallvisible 4294967082 12 0 false
228-
pg_class reltoastrelid 4294967082 13 0 false
229-
pg_class relhasindex 4294967082 14 0 false
230-
pg_class relisshared 4294967082 15 0 false
231-
pg_class relpersistence 4294967082 16 0 false
232-
pg_class relistemp 4294967082 17 0 false
233-
pg_class relkind 4294967082 18 0 false
234-
pg_class relnatts 4294967082 19 0 false
235-
pg_class relchecks 4294967082 20 0 false
236-
pg_class relhasoids 4294967082 21 0 false
237-
pg_class relhaspkey 4294967082 22 0 false
238-
pg_class relhasrules 4294967082 23 0 false
239-
pg_class relhastriggers 4294967082 24 0 false
240-
pg_class relhassubclass 4294967082 25 0 false
241-
pg_class relfrozenxid 4294967082 26 0 false
242-
pg_class relacl 4294967082 27 0 false
243-
pg_class reloptions 4294967082 28 0 false
244-
pg_class relforcerowsecurity 4294967082 29 0 false
245-
pg_class relispartition 4294967082 30 0 false
246-
pg_class relispopulated 4294967082 31 0 false
247-
pg_class relreplident 4294967082 32 0 false
248-
pg_class relrewrite 4294967082 33 0 false
249-
pg_class relrowsecurity 4294967082 34 0 false
250-
pg_class relpartbound 4294967082 35 0 false
251-
pg_class relminmxid 4294967082 36 0 false
216+
pg_class oid 4294967081 1 0 false
217+
pg_class relname 4294967081 2 0 false
218+
pg_class relnamespace 4294967081 3 0 false
219+
pg_class reltype 4294967081 4 0 false
220+
pg_class reloftype 4294967081 5 0 false
221+
pg_class relowner 4294967081 6 0 false
222+
pg_class relam 4294967081 7 0 false
223+
pg_class relfilenode 4294967081 8 0 false
224+
pg_class reltablespace 4294967081 9 0 false
225+
pg_class relpages 4294967081 10 0 false
226+
pg_class reltuples 4294967081 11 0 false
227+
pg_class relallvisible 4294967081 12 0 false
228+
pg_class reltoastrelid 4294967081 13 0 false
229+
pg_class relhasindex 4294967081 14 0 false
230+
pg_class relisshared 4294967081 15 0 false
231+
pg_class relpersistence 4294967081 16 0 false
232+
pg_class relistemp 4294967081 17 0 false
233+
pg_class relkind 4294967081 18 0 false
234+
pg_class relnatts 4294967081 19 0 false
235+
pg_class relchecks 4294967081 20 0 false
236+
pg_class relhasoids 4294967081 21 0 false
237+
pg_class relhaspkey 4294967081 22 0 false
238+
pg_class relhasrules 4294967081 23 0 false
239+
pg_class relhastriggers 4294967081 24 0 false
240+
pg_class relhassubclass 4294967081 25 0 false
241+
pg_class relfrozenxid 4294967081 26 0 false
242+
pg_class relacl 4294967081 27 0 false
243+
pg_class reloptions 4294967081 28 0 false
244+
pg_class relforcerowsecurity 4294967081 29 0 false
245+
pg_class relispartition 4294967081 30 0 false
246+
pg_class relispopulated 4294967081 31 0 false
247+
pg_class relreplident 4294967081 32 0 false
248+
pg_class relrewrite 4294967081 33 0 false
249+
pg_class relrowsecurity 4294967081 34 0 false
250+
pg_class relpartbound 4294967081 35 0 false
251+
pg_class relminmxid 4294967081 36 0 false
252252

253253

254254
# Check that the oid does not exist. If this test fail, change the oid here and in

0 commit comments

Comments
 (0)