Skip to content

Commit

Permalink
release-22.1: sql: add crdb_internal views for system statistics tables
Browse files Browse the repository at this point in the history
Backport of commit 4557dd0 (cockroachdb#98261).

This commit adds two new crdb_internal views:

- crdb_internal.statement_statistics_persisted, which surfaces the
system.statement_statistics table
- crdb_internal.transaction_statistics_persisted, which surfaces the
system.transaction_statistics table

Epic: none

Release note: Added two views to the crdb_internal catalog:
crdb_internal.statement_statistics_persisted, which surfaces data in
the persisted system.statement_statistics table, and
crdb_internal.transaction_statistics_persisted, which surfaces the
system.transaction_statistics table.
  • Loading branch information
ericharmeling committed Apr 25, 2023
1 parent 5c0078b commit e39fed9
Show file tree
Hide file tree
Showing 12 changed files with 1,823 additions and 8,298 deletions.
142 changes: 72 additions & 70 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -33,76 +33,78 @@ DROP DATABASE crdb_internal
query TTTTIT
SHOW TABLES FROM crdb_internal
----
crdb_internal active_range_feeds table NULL NULL NULL
crdb_internal backward_dependencies table NULL NULL NULL
crdb_internal builtin_functions table NULL NULL NULL
crdb_internal cluster_contended_indexes view NULL NULL NULL
crdb_internal cluster_contended_keys view NULL NULL NULL
crdb_internal cluster_contended_tables view NULL NULL NULL
crdb_internal cluster_contention_events table NULL NULL NULL
crdb_internal cluster_database_privileges table NULL NULL NULL
crdb_internal cluster_distsql_flows table NULL NULL NULL
crdb_internal cluster_inflight_traces table NULL NULL NULL
crdb_internal cluster_locks table NULL NULL NULL
crdb_internal cluster_queries table NULL NULL NULL
crdb_internal cluster_sessions table NULL NULL NULL
crdb_internal cluster_settings table NULL NULL NULL
crdb_internal cluster_statement_statistics table NULL NULL NULL
crdb_internal cluster_transaction_statistics table NULL NULL NULL
crdb_internal cluster_transactions table NULL NULL NULL
crdb_internal create_schema_statements table NULL NULL NULL
crdb_internal create_statements table NULL NULL NULL
crdb_internal create_type_statements table NULL NULL NULL
crdb_internal cross_db_references table NULL NULL NULL
crdb_internal databases table NULL NULL NULL
crdb_internal default_privileges table NULL NULL NULL
crdb_internal feature_usage table NULL NULL NULL
crdb_internal forward_dependencies table NULL NULL NULL
crdb_internal gossip_alerts table NULL NULL NULL
crdb_internal gossip_liveness table NULL NULL NULL
crdb_internal gossip_network table NULL NULL NULL
crdb_internal gossip_nodes table NULL NULL NULL
crdb_internal index_columns table NULL NULL NULL
crdb_internal index_usage_statistics table NULL NULL NULL
crdb_internal invalid_objects table NULL NULL NULL
crdb_internal jobs table NULL NULL NULL
crdb_internal kv_node_liveness table NULL NULL NULL
crdb_internal kv_node_status table NULL NULL NULL
crdb_internal kv_store_status table NULL NULL NULL
crdb_internal leases table NULL NULL NULL
crdb_internal lost_descriptors_with_data table NULL NULL NULL
crdb_internal node_build_info table NULL NULL NULL
crdb_internal node_contention_events table NULL NULL NULL
crdb_internal node_distsql_flows table NULL NULL NULL
crdb_internal node_inflight_trace_spans table NULL NULL NULL
crdb_internal node_memory_monitors table NULL NULL NULL
crdb_internal node_metrics table NULL NULL NULL
crdb_internal node_queries table NULL NULL NULL
crdb_internal node_runtime_info table NULL NULL NULL
crdb_internal node_sessions table NULL NULL NULL
crdb_internal node_statement_statistics table NULL NULL NULL
crdb_internal node_transaction_statistics table NULL NULL NULL
crdb_internal node_transactions table NULL NULL NULL
crdb_internal node_txn_stats table NULL NULL NULL
crdb_internal partitions table NULL NULL NULL
crdb_internal pg_catalog_table_is_implemented table NULL NULL NULL
crdb_internal predefined_comments table NULL NULL NULL
crdb_internal ranges view NULL NULL NULL
crdb_internal ranges_no_leases table NULL NULL NULL
crdb_internal regions table NULL NULL NULL
crdb_internal schema_changes table NULL NULL NULL
crdb_internal session_trace table NULL NULL NULL
crdb_internal session_variables table NULL NULL NULL
crdb_internal statement_statistics view NULL NULL NULL
crdb_internal super_regions table NULL NULL NULL
crdb_internal table_columns table NULL NULL NULL
crdb_internal table_indexes table NULL NULL NULL
crdb_internal table_row_statistics table NULL NULL NULL
crdb_internal tables table NULL NULL NULL
crdb_internal tenant_usage_details view NULL NULL NULL
crdb_internal transaction_contention_events table NULL NULL NULL
crdb_internal transaction_statistics view NULL NULL NULL
crdb_internal zones table NULL NULL NULL
crdb_internal active_range_feeds table NULL NULL NULL
crdb_internal backward_dependencies table NULL NULL NULL
crdb_internal builtin_functions table NULL NULL NULL
crdb_internal cluster_contended_indexes view NULL NULL NULL
crdb_internal cluster_contended_keys view NULL NULL NULL
crdb_internal cluster_contended_tables view NULL NULL NULL
crdb_internal cluster_contention_events table NULL NULL NULL
crdb_internal cluster_database_privileges table NULL NULL NULL
crdb_internal cluster_distsql_flows table NULL NULL NULL
crdb_internal cluster_inflight_traces table NULL NULL NULL
crdb_internal cluster_locks table NULL NULL NULL
crdb_internal cluster_queries table NULL NULL NULL
crdb_internal cluster_sessions table NULL NULL NULL
crdb_internal cluster_settings table NULL NULL NULL
crdb_internal cluster_statement_statistics table NULL NULL NULL
crdb_internal cluster_transaction_statistics table NULL NULL NULL
crdb_internal cluster_transactions table NULL NULL NULL
crdb_internal create_schema_statements table NULL NULL NULL
crdb_internal create_statements table NULL NULL NULL
crdb_internal create_type_statements table NULL NULL NULL
crdb_internal cross_db_references table NULL NULL NULL
crdb_internal databases table NULL NULL NULL
crdb_internal default_privileges table NULL NULL NULL
crdb_internal feature_usage table NULL NULL NULL
crdb_internal forward_dependencies table NULL NULL NULL
crdb_internal gossip_alerts table NULL NULL NULL
crdb_internal gossip_liveness table NULL NULL NULL
crdb_internal gossip_network table NULL NULL NULL
crdb_internal gossip_nodes table NULL NULL NULL
crdb_internal index_columns table NULL NULL NULL
crdb_internal index_usage_statistics table NULL NULL NULL
crdb_internal invalid_objects table NULL NULL NULL
crdb_internal jobs table NULL NULL NULL
crdb_internal kv_node_liveness table NULL NULL NULL
crdb_internal kv_node_status table NULL NULL NULL
crdb_internal kv_store_status table NULL NULL NULL
crdb_internal leases table NULL NULL NULL
crdb_internal lost_descriptors_with_data table NULL NULL NULL
crdb_internal node_build_info table NULL NULL NULL
crdb_internal node_contention_events table NULL NULL NULL
crdb_internal node_distsql_flows table NULL NULL NULL
crdb_internal node_inflight_trace_spans table NULL NULL NULL
crdb_internal node_memory_monitors table NULL NULL NULL
crdb_internal node_metrics table NULL NULL NULL
crdb_internal node_queries table NULL NULL NULL
crdb_internal node_runtime_info table NULL NULL NULL
crdb_internal node_sessions table NULL NULL NULL
crdb_internal node_statement_statistics table NULL NULL NULL
crdb_internal node_transaction_statistics table NULL NULL NULL
crdb_internal node_transactions table NULL NULL NULL
crdb_internal node_txn_stats table NULL NULL NULL
crdb_internal partitions table NULL NULL NULL
crdb_internal pg_catalog_table_is_implemented table NULL NULL NULL
crdb_internal predefined_comments table NULL NULL NULL
crdb_internal ranges view NULL NULL NULL
crdb_internal ranges_no_leases table NULL NULL NULL
crdb_internal regions table NULL NULL NULL
crdb_internal schema_changes table NULL NULL NULL
crdb_internal session_trace table NULL NULL NULL
crdb_internal session_variables table NULL NULL NULL
crdb_internal statement_statistics view NULL NULL NULL
crdb_internal statement_statistics_persisted view NULL NULL NULL
crdb_internal super_regions table NULL NULL NULL
crdb_internal table_columns table NULL NULL NULL
crdb_internal table_indexes table NULL NULL NULL
crdb_internal table_row_statistics table NULL NULL NULL
crdb_internal tables table NULL NULL NULL
crdb_internal tenant_usage_details view NULL NULL NULL
crdb_internal transaction_contention_events table NULL NULL NULL
crdb_internal transaction_statistics view NULL NULL NULL
crdb_internal transaction_statistics_persisted view NULL NULL NULL
crdb_internal zones table NULL NULL NULL

statement ok
CREATE DATABASE testdb; CREATE TABLE testdb.foo(x INT)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ table_name NOT IN (
'session_variables',
'tables',
'cluster_statement_statistics',
'statement_statistics_persisted',
'cluster_transaction_statistics',
'statement_statistics',
'transaction_statistics_persisted',
'transaction_statistics',
'tenant_usage_details',
'pg_catalog_table_is_implemented'
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/catalog/catconstants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ const (
CrdbInternalSessionTraceTableID
CrdbInternalSessionVariablesTableID
CrdbInternalStmtStatsTableID
CrdbInternalStmtStatsPersistedTableID
CrdbInternalTableColumnsTableID
CrdbInternalTableIndexesTableID
CrdbInternalTablesTableID
CrdbInternalTablesTableLastStatsID
CrdbInternalTransactionStatsTableID
CrdbInternalTxnStatsTableID
CrdbInternalTxnStatsPersistedTableID
CrdbInternalZonesTableID
CrdbInternalInvalidDescriptorsTableID
CrdbInternalClusterDatabasePrivilegesTableID
Expand Down
62 changes: 62 additions & 0 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ var crdbInternal = virtualSchema{
catconstants.CrdbInternalSessionTraceTableID: crdbInternalSessionTraceTable,
catconstants.CrdbInternalSessionVariablesTableID: crdbInternalSessionVariablesTable,
catconstants.CrdbInternalStmtStatsTableID: crdbInternalStmtStatsView,
catconstants.CrdbInternalStmtStatsPersistedTableID: crdbInternalStmtStatsPersistedView,
catconstants.CrdbInternalTableColumnsTableID: crdbInternalTableColumnsTable,
catconstants.CrdbInternalTableIndexesTableID: crdbInternalTableIndexesTable,
catconstants.CrdbInternalTablesTableLastStatsID: crdbInternalTablesTableLastStats,
catconstants.CrdbInternalTablesTableID: crdbInternalTablesTable,
catconstants.CrdbInternalClusterTxnStatsTableID: crdbInternalClusterTxnStatsTable,
catconstants.CrdbInternalTxnStatsTableID: crdbInternalTxnStatsView,
catconstants.CrdbInternalTxnStatsPersistedTableID: crdbInternalTxnStatsPersistedView,
catconstants.CrdbInternalTransactionStatsTableID: crdbInternalTransactionStatisticsTable,
catconstants.CrdbInternalZonesTableID: crdbInternalZonesTable,
catconstants.CrdbInternalInvalidDescriptorsTableID: crdbInternalInvalidDescriptorsTable,
Expand Down Expand Up @@ -5522,6 +5524,39 @@ GROUP BY
},
}

// crdb_internal.statement_statistics_persisted view selects persisted statement
// statistics from the system table. This view is primarily used to query statement
// stats info by date range.
var crdbInternalStmtStatsPersistedView = virtualSchemaView{
schema: `
CREATE VIEW crdb_internal.statement_statistics_persisted AS
SELECT
aggregated_ts,
fingerprint_id,
transaction_fingerprint_id,
plan_hash,
app_name,
node_id,
agg_interval,
metadata,
statistics,
plan
FROM
system.statement_statistics`,
resultColumns: colinfo.ResultColumns{
{Name: "aggregated_ts", Typ: types.TimestampTZ},
{Name: "fingerprint_id", Typ: types.Bytes},
{Name: "transaction_fingerprint_id", Typ: types.Bytes},
{Name: "plan_hash", Typ: types.Bytes},
{Name: "app_name", Typ: types.String},
{Name: "node_id", Typ: types.Int},
{Name: "agg_interval", Typ: types.Interval},
{Name: "metadata", Typ: types.Jsonb},
{Name: "statistics", Typ: types.Jsonb},
{Name: "plan", Typ: types.Jsonb},
},
}

var crdbInternalActiveRangeFeedsTable = virtualSchemaTable{
comment: `node-level table listing all currently running range feeds`,
schema: `
Expand Down Expand Up @@ -5719,6 +5754,33 @@ GROUP BY
},
}

// crdb_internal.transaction_statistics_persisted view selects persisted transaction
// statistics from the system table. This view is primarily used to query transaction
// stats info by date range.
var crdbInternalTxnStatsPersistedView = virtualSchemaView{
schema: `
CREATE VIEW crdb_internal.transaction_statistics_persisted AS
SELECT
aggregated_ts,
fingerprint_id,
app_name,
node_id,
agg_interval,
metadata,
statistics
FROM
system.transaction_statistics`,
resultColumns: colinfo.ResultColumns{
{Name: "aggregated_ts", Typ: types.TimestampTZ},
{Name: "fingerprint_id", Typ: types.Bytes},
{Name: "app_name", Typ: types.String},
{Name: "node_id", Typ: types.Int},
{Name: "agg_interval", Typ: types.Interval},
{Name: "metadata", Typ: types.Jsonb},
{Name: "statistics", Typ: types.Jsonb},
},
}

// crdbInternalTenantUsageDetailsView, exposes system ranges.
var crdbInternalTenantUsageDetailsView = virtualSchemaView{
schema: `
Expand Down
Loading

0 comments on commit e39fed9

Please sign in to comment.