Skip to content

Commit

Permalink
Merge pull request #98684 from ericharmeling/backport22.2-98261
Browse files Browse the repository at this point in the history
release-22.2: sql: add crdb_internal views for system statistics tables
  • Loading branch information
ericharmeling authored Mar 16, 2023
2 parents 0389939 + cc29fe0 commit 8699c74
Show file tree
Hide file tree
Showing 12 changed files with 649 additions and 480 deletions.
150 changes: 76 additions & 74 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -22,80 +22,82 @@ DROP DATABASE crdb_internal
query TTTTIT
SHOW TABLES FROM crdb_internal
----
crdb_internal active_range_feeds table admin NULL NULL
crdb_internal backward_dependencies table admin NULL NULL
crdb_internal builtin_functions table admin NULL NULL
crdb_internal cluster_contended_indexes view admin NULL NULL
crdb_internal cluster_contended_keys view admin NULL NULL
crdb_internal cluster_contended_tables view admin NULL NULL
crdb_internal cluster_contention_events table admin NULL NULL
crdb_internal cluster_database_privileges table admin NULL NULL
crdb_internal cluster_distsql_flows table admin NULL NULL
crdb_internal cluster_execution_insights table admin NULL NULL
crdb_internal cluster_inflight_traces table admin NULL NULL
crdb_internal cluster_locks table admin NULL NULL
crdb_internal cluster_queries table admin NULL NULL
crdb_internal cluster_sessions table admin NULL NULL
crdb_internal cluster_settings table admin NULL NULL
crdb_internal cluster_statement_statistics table admin NULL NULL
crdb_internal cluster_transaction_statistics table admin NULL NULL
crdb_internal cluster_transactions table admin NULL NULL
crdb_internal create_function_statements table admin NULL NULL
crdb_internal create_schema_statements table admin NULL NULL
crdb_internal create_statements table admin NULL NULL
crdb_internal create_type_statements table admin NULL NULL
crdb_internal cross_db_references table admin NULL NULL
crdb_internal databases table admin NULL NULL
crdb_internal default_privileges table admin NULL NULL
crdb_internal feature_usage table admin NULL NULL
crdb_internal forward_dependencies table admin NULL NULL
crdb_internal gossip_alerts table admin NULL NULL
crdb_internal gossip_liveness table admin NULL NULL
crdb_internal gossip_network table admin NULL NULL
crdb_internal gossip_nodes table admin NULL NULL
crdb_internal index_columns table admin NULL NULL
crdb_internal index_usage_statistics table admin NULL NULL
crdb_internal invalid_objects table admin NULL NULL
crdb_internal jobs table admin NULL NULL
crdb_internal kv_node_liveness table admin NULL NULL
crdb_internal kv_node_status table admin NULL NULL
crdb_internal kv_store_status table admin NULL NULL
crdb_internal leases table admin NULL NULL
crdb_internal lost_descriptors_with_data table admin NULL NULL
crdb_internal node_build_info table admin NULL NULL
crdb_internal node_contention_events table admin NULL NULL
crdb_internal node_distsql_flows table admin NULL NULL
crdb_internal node_execution_insights table admin NULL NULL
crdb_internal node_inflight_trace_spans table admin NULL NULL
crdb_internal node_memory_monitors table admin NULL NULL
crdb_internal node_metrics table admin NULL NULL
crdb_internal node_queries table admin NULL NULL
crdb_internal node_runtime_info table admin NULL NULL
crdb_internal node_sessions table admin NULL NULL
crdb_internal node_statement_statistics table admin NULL NULL
crdb_internal node_transaction_statistics table admin NULL NULL
crdb_internal node_transactions table admin NULL NULL
crdb_internal node_txn_stats table admin NULL NULL
crdb_internal partitions table admin NULL NULL
crdb_internal pg_catalog_table_is_implemented table admin NULL NULL
crdb_internal predefined_comments table admin NULL NULL
crdb_internal ranges view admin NULL NULL
crdb_internal ranges_no_leases table admin NULL NULL
crdb_internal regions table admin NULL NULL
crdb_internal schema_changes table admin NULL NULL
crdb_internal session_trace table admin NULL NULL
crdb_internal session_variables table admin NULL NULL
crdb_internal statement_statistics view admin NULL NULL
crdb_internal statement_statistics_v22_1 view admin NULL NULL
crdb_internal super_regions table admin NULL NULL
crdb_internal table_columns table admin NULL NULL
crdb_internal table_indexes table admin NULL NULL
crdb_internal table_row_statistics table admin NULL NULL
crdb_internal tables table admin NULL NULL
crdb_internal tenant_usage_details view admin NULL NULL
crdb_internal transaction_contention_events table admin NULL NULL
crdb_internal transaction_statistics view admin NULL NULL
crdb_internal zones table admin NULL NULL
crdb_internal active_range_feeds table admin NULL NULL
crdb_internal backward_dependencies table admin NULL NULL
crdb_internal builtin_functions table admin NULL NULL
crdb_internal cluster_contended_indexes view admin NULL NULL
crdb_internal cluster_contended_keys view admin NULL NULL
crdb_internal cluster_contended_tables view admin NULL NULL
crdb_internal cluster_contention_events table admin NULL NULL
crdb_internal cluster_database_privileges table admin NULL NULL
crdb_internal cluster_distsql_flows table admin NULL NULL
crdb_internal cluster_execution_insights table admin NULL NULL
crdb_internal cluster_inflight_traces table admin NULL NULL
crdb_internal cluster_locks table admin NULL NULL
crdb_internal cluster_queries table admin NULL NULL
crdb_internal cluster_sessions table admin NULL NULL
crdb_internal cluster_settings table admin NULL NULL
crdb_internal cluster_statement_statistics table admin NULL NULL
crdb_internal cluster_transaction_statistics table admin NULL NULL
crdb_internal cluster_transactions table admin NULL NULL
crdb_internal create_function_statements table admin NULL NULL
crdb_internal create_schema_statements table admin NULL NULL
crdb_internal create_statements table admin NULL NULL
crdb_internal create_type_statements table admin NULL NULL
crdb_internal cross_db_references table admin NULL NULL
crdb_internal databases table admin NULL NULL
crdb_internal default_privileges table admin NULL NULL
crdb_internal feature_usage table admin NULL NULL
crdb_internal forward_dependencies table admin NULL NULL
crdb_internal gossip_alerts table admin NULL NULL
crdb_internal gossip_liveness table admin NULL NULL
crdb_internal gossip_network table admin NULL NULL
crdb_internal gossip_nodes table admin NULL NULL
crdb_internal index_columns table admin NULL NULL
crdb_internal index_usage_statistics table admin NULL NULL
crdb_internal invalid_objects table admin NULL NULL
crdb_internal jobs table admin NULL NULL
crdb_internal kv_node_liveness table admin NULL NULL
crdb_internal kv_node_status table admin NULL NULL
crdb_internal kv_store_status table admin NULL NULL
crdb_internal leases table admin NULL NULL
crdb_internal lost_descriptors_with_data table admin NULL NULL
crdb_internal node_build_info table admin NULL NULL
crdb_internal node_contention_events table admin NULL NULL
crdb_internal node_distsql_flows table admin NULL NULL
crdb_internal node_execution_insights table admin NULL NULL
crdb_internal node_inflight_trace_spans table admin NULL NULL
crdb_internal node_memory_monitors table admin NULL NULL
crdb_internal node_metrics table admin NULL NULL
crdb_internal node_queries table admin NULL NULL
crdb_internal node_runtime_info table admin NULL NULL
crdb_internal node_sessions table admin NULL NULL
crdb_internal node_statement_statistics table admin NULL NULL
crdb_internal node_transaction_statistics table admin NULL NULL
crdb_internal node_transactions table admin NULL NULL
crdb_internal node_txn_stats table admin NULL NULL
crdb_internal partitions table admin NULL NULL
crdb_internal pg_catalog_table_is_implemented table admin NULL NULL
crdb_internal predefined_comments table admin NULL NULL
crdb_internal ranges view admin NULL NULL
crdb_internal ranges_no_leases table admin NULL NULL
crdb_internal regions table admin NULL NULL
crdb_internal schema_changes table admin NULL NULL
crdb_internal session_trace table admin NULL NULL
crdb_internal session_variables table admin NULL NULL
crdb_internal statement_statistics view admin NULL NULL
crdb_internal statement_statistics_persisted view admin NULL NULL
crdb_internal statement_statistics_v22_1 view admin NULL NULL
crdb_internal super_regions table admin NULL NULL
crdb_internal table_columns table admin NULL NULL
crdb_internal table_indexes table admin NULL NULL
crdb_internal table_row_statistics table admin NULL NULL
crdb_internal tables table admin NULL NULL
crdb_internal tenant_usage_details view admin NULL NULL
crdb_internal transaction_contention_events table admin NULL NULL
crdb_internal transaction_statistics view admin NULL NULL
crdb_internal transaction_statistics_persisted view admin NULL NULL
crdb_internal zones table admin 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 @@ -90,8 +90,10 @@ table_name NOT IN (
'cluster_statement_statistics',
'cluster_transaction_statistics',
'statement_statistics',
'statement_statistics_persisted',
'statement_statistics_v22_1',
'transaction_statistics',
'transaction_statistics_persisted',
'tenant_usage_details',
'pg_catalog_table_is_implemented'
)
Expand Down
64 changes: 64 additions & 0 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ var crdbInternal = virtualSchema{
catconstants.CrdbInternalSessionTraceTableID: crdbInternalSessionTraceTable,
catconstants.CrdbInternalSessionVariablesTableID: crdbInternalSessionVariablesTable,
catconstants.CrdbInternalStmtStatsTableID: crdbInternalStmtStatsView,
catconstants.CrdbInternalStmtStatsPersistedTableID: crdbInternalStmtStatsPersistedView,
catconstants.CrdbInternalStmtStatsV22_1TableID: crdbInternalStmtStatsViewV22_1,
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 @@ -5794,6 +5796,41 @@ 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,
index_recommendations
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},
{Name: "index_recommendations", Typ: types.StringArray},
},
}

// Copy of crdb_internal.statement_statistics for previous versions during upgrade.
// See crdb_internal.statement_statistics for more details.
var crdbInternalStmtStatsViewV22_1 = virtualSchemaView{
Expand Down Expand Up @@ -6054,6 +6091,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 8699c74

Please sign in to comment.