From c0d95d78ad29f422695e649b089cda75d6edef44 Mon Sep 17 00:00:00 2001 From: Eric Harmeling Date: Wed, 22 Mar 2023 14:42:09 +0000 Subject: [PATCH] sql: add computed columns to crdb_internal persisted sql stats views Follows #99042, #99148. This commit adds the following computed columns to both crdb_internal.statement_statistics_persisted and crdb_internal.transaction_statistics_persisted views: -execution_count -service_latency -cpu_sql_nanos -contention_time -total_estimated_execution_time -p99_latency These computed columns are indexed in the system tables from which these views are created. Epic: None Release note: The crdb_internal.statement_statistics_persisted and crdb_internal.transaction_statistics_persisted views now include computed columns, to optimize the performance of frequently-queried expressions. --- pkg/sql/crdb_internal.go | 28 +- .../testdata/logic_test/crdb_internal_catalog | 4 +- .../testdata/sql_statistics_persisted | 569 ++++++++++++++---- 3 files changed, 492 insertions(+), 109 deletions(-) diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index bbd873c2bacf..bb2468142a84 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -6393,7 +6393,13 @@ CREATE VIEW crdb_internal.statement_statistics_persisted AS statistics, plan, index_recommendations, - indexes_usage + indexes_usage, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency FROM system.statement_statistics`, resultColumns: colinfo.ResultColumns{ @@ -6409,6 +6415,12 @@ CREATE VIEW crdb_internal.statement_statistics_persisted AS {Name: "plan", Typ: types.Jsonb}, {Name: "index_recommendations", Typ: types.StringArray}, {Name: "indexes_usage", Typ: types.Jsonb}, + {Name: "execution_count", Typ: types.Int}, + {Name: "service_latency", Typ: types.Float}, + {Name: "cpu_sql_nanos", Typ: types.Float}, + {Name: "contention_time", Typ: types.Float}, + {Name: "total_estimated_execution_time", Typ: types.Float}, + {Name: "p99_latency", Typ: types.Float}, }, } @@ -6623,7 +6635,13 @@ CREATE VIEW crdb_internal.transaction_statistics_persisted AS node_id, agg_interval, metadata, - statistics + statistics, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency FROM system.transaction_statistics`, resultColumns: colinfo.ResultColumns{ @@ -6634,6 +6652,12 @@ CREATE VIEW crdb_internal.transaction_statistics_persisted AS {Name: "agg_interval", Typ: types.Interval}, {Name: "metadata", Typ: types.Jsonb}, {Name: "statistics", Typ: types.Jsonb}, + {Name: "execution_count", Typ: types.Int}, + {Name: "service_latency", Typ: types.Float}, + {Name: "cpu_sql_nanos", Typ: types.Float}, + {Name: "contention_time", Typ: types.Float}, + {Name: "total_estimated_execution_time", Typ: types.Float}, + {Name: "p99_latency", Typ: types.Float}, }, } diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog b/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog index 488469ac5749..d6443804824d 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog @@ -404,7 +404,7 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor 4294967221 {"table": {"columns": [{"id": 1, "name": "database_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "grantee", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "privilege_type", "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "is_grantable", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967221, "indexes": [{"foreignKey": {}, "geoConfig": {}, "id": 2, "interleave": {}, "keyColumnDirections": ["ASC"], "keyColumnIds": [1], "keyColumnNames": ["database_name"], "name": "cluster_database_privileges_database_name_idx", "partitioning": {}, "sharded": {}, "storeColumnIds": [2, 3, 4], "storeColumnNames": ["grantee", "privilege_type", "is_grantable"], "version": 3}], "name": "cluster_database_privileges", "nextColumnId": 5, "nextConstraintId": 2, "nextIndexId": 3, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} 4294967222 {"table": {"columns": [{"id": 1, "name": "id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "database_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "schema_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "obj_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "error", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967222, "name": "invalid_objects", "nextColumnId": 6, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} 4294967223 {"table": {"columns": [{"id": 1, "name": "zone_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "subzone_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 3, "name": "target", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "range_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "database_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "schema_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "table_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "index_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 9, "name": "partition_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 10, "name": "raw_config_yaml", "type": {"family": "StringFamily", "oid": 25}}, {"id": 11, "name": "raw_config_sql", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 12, "name": "raw_config_protobuf", "type": {"family": "BytesFamily", "oid": 17}}, {"id": 13, "name": "full_config_yaml", "type": {"family": "StringFamily", "oid": 25}}, {"id": 14, "name": "full_config_sql", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967223, "name": "zones", "nextColumnId": 15, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} -4294967224 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "nullable": true, "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "app_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "node_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 5, "name": "agg_interval", "nullable": true, "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}, {"id": 6, "name": "metadata", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 7, "name": "statistics", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}], "formatVersion": 3, "id": 4294967224, "name": "transaction_statistics_persisted", "nextColumnId": 8, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1", "viewQuery": "SELECT aggregated_ts, fingerprint_id, app_name, node_id, agg_interval, metadata, statistics FROM system.transaction_statistics"}} +4294967224 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "nullable": true, "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "app_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "node_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 5, "name": "agg_interval", "nullable": true, "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}, {"id": 6, "name": "metadata", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 7, "name": "statistics", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 8, "name": "execution_count", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 9, "name": "service_latency", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 10, "name": "cpu_sql_nanos", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 11, "name": "contention_time", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 12, "name": "total_estimated_execution_time", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 13, "name": "p99_latency", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}], "formatVersion": 3, "id": 4294967224, "name": "transaction_statistics_persisted", "nextColumnId": 14, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1", "viewQuery": "SELECT aggregated_ts, fingerprint_id, app_name, node_id, agg_interval, metadata, statistics, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency FROM system.transaction_statistics"}} 4294967225 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "nullable": true, "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "app_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "metadata", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 5, "name": "statistics", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 6, "name": "aggregation_interval", "nullable": true, "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}], "formatVersion": 3, "id": 4294967225, "name": "transaction_statistics", "nextColumnId": 7, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1", "viewQuery": "SELECT aggregated_ts, fingerprint_id, app_name, max(metadata), crdb_internal.merge_transaction_stats(array_agg(statistics)), aggregation_interval FROM (SELECT aggregated_ts, fingerprint_id, app_name, metadata, statistics, aggregation_interval FROM crdb_internal.cluster_transaction_statistics UNION ALL SELECT aggregated_ts, fingerprint_id, app_name, metadata, statistics, agg_interval FROM system.transaction_statistics) GROUP BY aggregated_ts, fingerprint_id, app_name, aggregation_interval"}} 4294967226 {"table": {"columns": [{"id": 1, "name": "node_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "application_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "key", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 4, "name": "statement_ids", "nullable": true, "type": {"arrayContents": {"family": "StringFamily", "oid": 25}, "arrayElemType": "StringFamily", "family": "ArrayFamily", "oid": 1009}}, {"id": 5, "name": "count", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 6, "name": "max_retries", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 7, "name": "service_lat_avg", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 8, "name": "service_lat_var", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 9, "name": "retry_lat_avg", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 10, "name": "retry_lat_var", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 11, "name": "commit_lat_avg", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 12, "name": "commit_lat_var", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 13, "name": "idle_lat_avg", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 14, "name": "idle_lat_var", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 15, "name": "rows_read_avg", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 16, "name": "rows_read_var", "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 17, "name": "network_bytes_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 18, "name": "network_bytes_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 19, "name": "network_msgs_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 20, "name": "network_msgs_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 21, "name": "max_mem_usage_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 22, "name": "max_mem_usage_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 23, "name": "max_disk_usage_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 24, "name": "max_disk_usage_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 25, "name": "contention_time_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 26, "name": "contention_time_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 27, "name": "cpu_sql_nanos_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 28, "name": "cpu_sql_nanos_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 29, "name": "mvcc_step_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 30, "name": "mvcc_step_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 31, "name": "mvcc_step_internal_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 32, "name": "mvcc_step_internal_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 33, "name": "mvcc_seek_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 34, "name": "mvcc_seek_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 35, "name": "mvcc_seek_internal_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 36, "name": "mvcc_seek_internal_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 37, "name": "mvcc_block_bytes_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 38, "name": "mvcc_block_bytes_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 39, "name": "mvcc_block_bytes_in_cache_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 40, "name": "mvcc_block_bytes_in_cache_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 41, "name": "mvcc_key_bytes_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 42, "name": "mvcc_key_bytes_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 43, "name": "mvcc_value_bytes_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 44, "name": "mvcc_value_bytes_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 45, "name": "mvcc_point_count_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 46, "name": "mvcc_point_count_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 47, "name": "mvcc_points_covered_by_range_tombstones_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 48, "name": "mvcc_points_covered_by_range_tombstones_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 49, "name": "mvcc_range_key_count_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 50, "name": "mvcc_range_key_count_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 51, "name": "mvcc_range_key_contained_points_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 52, "name": "mvcc_range_key_contained_points_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 53, "name": "mvcc_range_key_skipped_points_avg", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 54, "name": "mvcc_range_key_skipped_points_var", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}], "formatVersion": 3, "id": 4294967226, "name": "node_transaction_statistics", "nextColumnId": 55, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} 4294967227 {"table": {"columns": [{"id": 1, "name": "table_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "table_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "estimated_row_count", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}], "formatVersion": 3, "id": 4294967227, "name": "table_row_statistics", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} @@ -412,7 +412,7 @@ SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor 4294967229 {"table": {"columns": [{"id": 1, "name": "descriptor_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "start_key", "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "end_key", "type": {"family": "BytesFamily", "oid": 17}}], "formatVersion": 3, "id": 4294967229, "indexes": [{"foreignKey": {}, "geoConfig": {}, "id": 2, "interleave": {}, "keyColumnDirections": ["ASC"], "keyColumnIds": [1], "keyColumnNames": ["descriptor_id"], "name": "table_spans_descriptor_id_idx", "partitioning": {}, "sharded": {}, "storeColumnIds": [2, 3], "storeColumnNames": ["start_key", "end_key"], "version": 3}], "name": "table_spans", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 3, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} 4294967230 {"table": {"columns": [{"id": 1, "name": "descriptor_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "descriptor_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "index_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 4, "name": "index_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "index_type", "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "is_unique", "type": {"oid": 16}}, {"id": 7, "name": "is_inverted", "type": {"oid": 16}}, {"id": 8, "name": "is_sharded", "type": {"oid": 16}}, {"id": 9, "name": "is_visible", "type": {"oid": 16}}, {"id": 10, "name": "shard_bucket_count", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 11, "name": "created_at", "nullable": true, "type": {"family": "TimestampFamily", "oid": 1114}}, {"id": 12, "name": "create_statement", "type": {"family": "StringFamily", "oid": 25}}], "formatVersion": 3, "id": 4294967230, "name": "table_indexes", "nextColumnId": 13, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} 4294967231 {"table": {"columns": [{"id": 1, "name": "descriptor_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "descriptor_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "column_id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 4, "name": "column_name", "type": {"family": "StringFamily", "oid": 25}}, {"id": 5, "name": "column_type", "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "nullable", "type": {"oid": 16}}, {"id": 7, "name": "default_expr", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "hidden", "type": {"oid": 16}}], "formatVersion": 3, "id": 4294967231, "name": "table_columns", "nextColumnId": 9, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} -4294967232 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "nullable": true, "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "transaction_fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 4, "name": "plan_hash", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 5, "name": "app_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "node_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 7, "name": "agg_interval", "nullable": true, "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}, {"id": 8, "name": "metadata", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 9, "name": "statistics", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 10, "name": "plan", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 11, "name": "index_recommendations", "nullable": true, "type": {"arrayContents": {"family": "StringFamily", "oid": 25}, "arrayElemType": "StringFamily", "family": "ArrayFamily", "oid": 1009}}, {"id": 12, "name": "indexes_usage", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}], "formatVersion": 3, "id": 4294967232, "name": "statement_statistics_persisted", "nextColumnId": 13, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1", "viewQuery": "SELECT aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, agg_interval, metadata, statistics, plan, index_recommendations, indexes_usage FROM system.statement_statistics"}} +4294967232 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "nullable": true, "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "transaction_fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 4, "name": "plan_hash", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 5, "name": "app_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "node_id", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 7, "name": "agg_interval", "nullable": true, "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}, {"id": 8, "name": "metadata", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 9, "name": "statistics", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 10, "name": "plan", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 11, "name": "index_recommendations", "nullable": true, "type": {"arrayContents": {"family": "StringFamily", "oid": 25}, "arrayElemType": "StringFamily", "family": "ArrayFamily", "oid": 1009}}, {"id": 12, "name": "indexes_usage", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 13, "name": "execution_count", "nullable": true, "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 14, "name": "service_latency", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 15, "name": "cpu_sql_nanos", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 16, "name": "contention_time", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 17, "name": "total_estimated_execution_time", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}, {"id": 18, "name": "p99_latency", "nullable": true, "type": {"family": "FloatFamily", "oid": 701, "width": 64}}], "formatVersion": 3, "id": 4294967232, "name": "statement_statistics_persisted", "nextColumnId": 19, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1", "viewQuery": "SELECT aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, agg_interval, metadata, statistics, plan, index_recommendations, indexes_usage, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency FROM system.statement_statistics"}} 4294967233 {"table": {"columns": [{"id": 1, "name": "aggregated_ts", "nullable": true, "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 2, "name": "fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 3, "name": "transaction_fingerprint_id", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 4, "name": "plan_hash", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}, {"id": 5, "name": "app_name", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "metadata", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 7, "name": "statistics", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 8, "name": "sampled_plan", "nullable": true, "type": {"family": "JsonFamily", "oid": 3802}}, {"id": 9, "name": "aggregation_interval", "nullable": true, "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}, {"id": 10, "name": "index_recommendations", "nullable": true, "type": {"arrayContents": {"family": "StringFamily", "oid": 25}, "arrayElemType": "StringFamily", "family": "ArrayFamily", "oid": 1009}}], "formatVersion": 3, "id": 4294967233, "name": "statement_statistics", "nextColumnId": 11, "nextConstraintId": 1, "nextMutationId": 1, "primaryIndex": {"foreignKey": {}, "geoConfig": {}, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1", "viewQuery": "SELECT aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, max(metadata) AS metadata, crdb_internal.merge_statement_stats(array_agg(DISTINCT statistics)), max(sampled_plan), aggregation_interval, array_remove(array_cat_agg(index_recommendations), NULL) AS index_recommendations FROM (SELECT aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, metadata, statistics, sampled_plan, aggregation_interval, index_recommendations FROM crdb_internal.cluster_statement_statistics UNION ALL SELECT aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, metadata, statistics, plan, agg_interval, index_recommendations FROM system.statement_statistics) GROUP BY aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, aggregation_interval"}} 4294967234 {"table": {"columns": [{"id": 1, "name": "variable", "type": {"family": "StringFamily", "oid": 25}}, {"id": 2, "name": "value", "type": {"family": "StringFamily", "oid": 25}}, {"id": 3, "name": "hidden", "type": {"oid": 16}}], "formatVersion": 3, "id": 4294967234, "name": "session_variables", "nextColumnId": 4, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} 4294967235 {"table": {"columns": [{"id": 1, "name": "span_idx", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "message_idx", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 3, "name": "timestamp", "type": {"family": "TimestampTZFamily", "oid": 1184}}, {"id": 4, "name": "duration", "nullable": true, "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}, {"id": 5, "name": "operation", "nullable": true, "type": {"family": "StringFamily", "oid": 25}}, {"id": 6, "name": "loc", "type": {"family": "StringFamily", "oid": 25}}, {"id": 7, "name": "tag", "type": {"family": "StringFamily", "oid": 25}}, {"id": 8, "name": "message", "type": {"family": "StringFamily", "oid": 25}}, {"id": 9, "name": "age", "type": {"family": "IntervalFamily", "intervalDurationField": {}, "oid": 1186}}], "formatVersion": 3, "id": 4294967235, "name": "session_trace", "nextColumnId": 10, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "primaryIndex": {"constraintId": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "partitioning": {}, "sharded": {}}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "public"}], "version": 2}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 4294967295, "version": "1"}} diff --git a/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted b/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted index c78e3321e8ad..25dd68533007 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted +++ b/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted @@ -1,114 +1,243 @@ # LogicTest: local -query T -EXPLAIN (VERBOSE) -SELECT - aggregated_ts, - fingerprint_id, - transaction_fingerprint_id, - plan_hash, - app_name, - node_id, - agg_interval, - metadata, - statistics, - plan, - index_recommendations, - indexes_usage -FROM - system.statement_statistics ----- - distribution: local - vectorized: true -· - • render - │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, agg_interval, metadata, statistics, plan, index_recommendations, indexes_usage) - │ render indexes_usage: (statistics->'statistics')->'indexes' - │ render aggregated_ts: aggregated_ts - │ render fingerprint_id: fingerprint_id - │ render transaction_fingerprint_id: transaction_fingerprint_id - │ render plan_hash: plan_hash - │ render app_name: app_name - │ render node_id: node_id - │ render agg_interval: agg_interval - │ render metadata: metadata - │ render statistics: statistics - │ render plan: plan - │ render index_recommendations: index_recommendations - │ - └── • scan - columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, agg_interval, metadata, statistics, plan, index_recommendations) - estimated row count: 1,000 (missing stats) - table: statement_statistics@primary - spans: FULL SCAN - -query T -EXPLAIN (VERBOSE) -SELECT * FROM crdb_internal.statement_statistics_persisted ----- - distribution: local - vectorized: true -· - • render - │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, agg_interval, metadata, statistics, plan, index_recommendations, indexes_usage) - │ render indexes_usage: (statistics->'statistics')->'indexes' - │ render aggregated_ts: aggregated_ts - │ render fingerprint_id: fingerprint_id - │ render transaction_fingerprint_id: transaction_fingerprint_id - │ render plan_hash: plan_hash - │ render app_name: app_name - │ render node_id: node_id - │ render agg_interval: agg_interval - │ render metadata: metadata - │ render statistics: statistics - │ render plan: plan - │ render index_recommendations: index_recommendations - │ - └── • scan - columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, agg_interval, metadata, statistics, plan, index_recommendations) - estimated row count: 1,000 (missing stats) - table: statement_statistics@primary - spans: FULL SCAN +statement ok +CREATE STATISTICS system_statement_stats FROM system.statement_statistics query T EXPLAIN (VERBOSE) -SELECT +SELECT * FROM ((SELECT aggregated_ts, fingerprint_id, + transaction_fingerprint_id, app_name, - node_id, - agg_interval, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, metadata, statistics -FROM - system.transaction_statistics ----- - distribution: local - vectorized: true -· - • scan - columns: (aggregated_ts, fingerprint_id, app_name, node_id, agg_interval, metadata, statistics) - estimated row count: 1,000 (missing stats) - table: transaction_statistics@primary - spans: FULL SCAN - -query T -EXPLAIN (VERBOSE) -SELECT * FROM crdb_internal.transaction_statistics_persisted +FROM system.statement_statistics +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY execution_count DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + transaction_fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM system.statement_statistics +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY service_latency DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + transaction_fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM system.statement_statistics +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY cpu_sql_nanos DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + transaction_fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM system.statement_statistics +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY contention_time DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + transaction_fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM system.statement_statistics +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY total_estimated_execution_time DESC LIMIT 500) + UNION (SELECT + aggregated_ts, + fingerprint_id, + transaction_fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM system.statement_statistics +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY p99_latency DESC LIMIT 500)) ---- - distribution: local - vectorized: true +distribution: local +vectorized: true · - • scan - columns: (aggregated_ts, fingerprint_id, app_name, node_id, agg_interval, metadata, statistics) - estimated row count: 1,000 (missing stats) - table: transaction_statistics@primary - spans: FULL SCAN - - - -statement ok -CREATE STATISTICS system_statement_stats FROM system.statement_statistics +• union +│ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ estimated row count: 2 +│ +├── • union +│ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ estimated row count: 2 +│ │ +│ ├── • union +│ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ estimated row count: 1 +│ │ │ +│ │ ├── • union +│ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ estimated row count: 1 +│ │ │ │ +│ │ │ ├── • union +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ │ estimated row count: 1 +│ │ │ │ │ +│ │ │ │ ├── • index join +│ │ │ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ │ │ estimated row count: 0 +│ │ │ │ │ │ table: statement_statistics@primary +│ │ │ │ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id +│ │ │ │ │ │ +│ │ │ │ │ └── • top-k +│ │ │ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, execution_count) +│ │ │ │ │ │ ordering: -execution_count +│ │ │ │ │ │ estimated row count: 0 +│ │ │ │ │ │ order: -execution_count +│ │ │ │ │ │ k: 500 +│ │ │ │ │ │ +│ │ │ │ │ └── • scan +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, execution_count) +│ │ │ │ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ │ │ │ table: statement_statistics@execution_count_idx (partial index) +│ │ │ │ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ │ │ │ +│ │ │ │ └── • index join +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ │ estimated row count: 0 +│ │ │ │ │ table: statement_statistics@primary +│ │ │ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id +│ │ │ │ │ +│ │ │ │ └── • top-k +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, service_latency) +│ │ │ │ │ ordering: -service_latency +│ │ │ │ │ estimated row count: 0 +│ │ │ │ │ order: -service_latency +│ │ │ │ │ k: 500 +│ │ │ │ │ +│ │ │ │ └── • scan +│ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, service_latency) +│ │ │ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ │ │ table: statement_statistics@service_latency_idx (partial index) +│ │ │ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ │ │ +│ │ │ └── • index join +│ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ estimated row count: 0 +│ │ │ │ table: statement_statistics@primary +│ │ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id +│ │ │ │ +│ │ │ └── • top-k +│ │ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, cpu_sql_nanos) +│ │ │ │ ordering: -cpu_sql_nanos +│ │ │ │ estimated row count: 0 +│ │ │ │ order: -cpu_sql_nanos +│ │ │ │ k: 500 +│ │ │ │ +│ │ │ └── • scan +│ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, cpu_sql_nanos) +│ │ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ │ table: statement_statistics@cpu_sql_nanos_idx (partial index) +│ │ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ │ +│ │ └── • index join +│ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ estimated row count: 0 +│ │ │ table: statement_statistics@primary +│ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id +│ │ │ +│ │ └── • top-k +│ │ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, contention_time) +│ │ │ ordering: -contention_time +│ │ │ estimated row count: 0 +│ │ │ order: -contention_time +│ │ │ k: 500 +│ │ │ +│ │ └── • scan +│ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, contention_time) +│ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ table: statement_statistics@contention_time_idx (partial index) +│ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ +│ └── • index join +│ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ estimated row count: 0 +│ │ table: statement_statistics@primary +│ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id +│ │ +│ └── • top-k +│ │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, total_estimated_execution_time) +│ │ ordering: -total_estimated_execution_time +│ │ estimated row count: 0 +│ │ order: -total_estimated_execution_time +│ │ k: 500 +│ │ +│ └── • scan +│ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, total_estimated_execution_time) +│ estimated row count: 0 (33% of the table; stats collected ago) +│ table: statement_statistics@total_estimated_execution_time_idx (partial index) +│ spans: /2023-03-21T14:05:00.000001Z- +│ +└── • index join + │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) + │ estimated row count: 0 + │ table: statement_statistics@primary + │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id + │ + └── • top-k + │ columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, p99_latency) + │ ordering: -p99_latency + │ estimated row count: 0 + │ order: -p99_latency + │ k: 500 + │ + └── • scan + columns: (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8, p99_latency) + estimated row count: 0 (33% of the table; stats collected ago) + table: statement_statistics@p99_latency_idx (partial index) + spans: /2023-03-21T14:05:00.000001Z- query T EXPLAIN (VERBOSE) @@ -125,7 +254,7 @@ SELECT * FROM ((SELECT p99_latency, metadata, statistics -FROM system.statement_statistics +FROM crdb_internal.statement_statistics_persisted WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') ORDER BY execution_count DESC LIMIT 500) UNION (SELECT @@ -141,7 +270,7 @@ UNION (SELECT p99_latency, metadata, statistics -FROM system.statement_statistics +FROM crdb_internal.statement_statistics_persisted WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') ORDER BY service_latency DESC LIMIT 500) UNION (SELECT @@ -157,7 +286,7 @@ UNION (SELECT p99_latency, metadata, statistics -FROM system.statement_statistics +FROM crdb_internal.statement_statistics_persisted WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') ORDER BY cpu_sql_nanos DESC LIMIT 500) UNION (SELECT @@ -173,7 +302,7 @@ UNION (SELECT p99_latency, metadata, statistics -FROM system.statement_statistics +FROM crdb_internal.statement_statistics_persisted WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') ORDER BY contention_time DESC LIMIT 500) UNION (SELECT @@ -189,7 +318,7 @@ UNION (SELECT p99_latency, metadata, statistics -FROM system.statement_statistics +FROM crdb_internal.statement_statistics_persisted WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') ORDER BY total_estimated_execution_time DESC LIMIT 500) UNION (SELECT @@ -205,7 +334,7 @@ ORDER BY total_estimated_execution_time DESC LIMIT 500) p99_latency, metadata, statistics -FROM system.statement_statistics +FROM crdb_internal.statement_statistics_persisted WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') ORDER BY p99_latency DESC LIMIT 500)) ---- @@ -578,3 +707,233 @@ vectorized: true estimated row count: 0 (33% of the table; stats collected ago) table: transaction_statistics@p99_latency_idx (partial index) spans: /2023-03-21T14:05:00.000001Z- + +query T +EXPLAIN (VERBOSE) +SELECT * FROM ((SELECT + aggregated_ts, + fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM crdb_internal.transaction_statistics_persisted +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY execution_count DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM crdb_internal.transaction_statistics_persisted +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY service_latency DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM crdb_internal.transaction_statistics_persisted +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY cpu_sql_nanos DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM crdb_internal.transaction_statistics_persisted +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ - INTERVAL '1 hour') +ORDER BY contention_time DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM crdb_internal.transaction_statistics_persisted +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ- INTERVAL '1 hour') +ORDER BY total_estimated_execution_time DESC LIMIT 500) +UNION (SELECT + aggregated_ts, + fingerprint_id, + app_name, + execution_count, + service_latency, + cpu_sql_nanos, + contention_time, + total_estimated_execution_time, + p99_latency, + metadata, + statistics +FROM crdb_internal.transaction_statistics_persisted +WHERE app_name NOT LIKE '$ internal%' AND aggregated_ts > ('2023-03-21 15:05'::TIMESTAMPTZ- INTERVAL '1 hour') +ORDER BY p99_latency DESC LIMIT 500)) +---- +distribution: local +vectorized: true +· +• union +│ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ estimated row count: 2 +│ +├── • union +│ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ estimated row count: 2 +│ │ +│ ├── • union +│ │ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ estimated row count: 1 +│ │ │ +│ │ ├── • union +│ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ estimated row count: 1 +│ │ │ │ +│ │ │ ├── • union +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ │ estimated row count: 1 +│ │ │ │ │ +│ │ │ │ ├── • index join +│ │ │ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ │ │ estimated row count: 0 +│ │ │ │ │ │ table: transaction_statistics@primary +│ │ │ │ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, aggregated_ts, fingerprint_id, app_name, node_id +│ │ │ │ │ │ +│ │ │ │ │ └── • top-k +│ │ │ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, execution_count) +│ │ │ │ │ │ ordering: -execution_count +│ │ │ │ │ │ estimated row count: 0 +│ │ │ │ │ │ order: -execution_count +│ │ │ │ │ │ k: 500 +│ │ │ │ │ │ +│ │ │ │ │ └── • scan +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, execution_count) +│ │ │ │ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ │ │ │ table: transaction_statistics@execution_count_idx (partial index) +│ │ │ │ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ │ │ │ +│ │ │ │ └── • index join +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ │ estimated row count: 0 +│ │ │ │ │ table: transaction_statistics@primary +│ │ │ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, aggregated_ts, fingerprint_id, app_name, node_id +│ │ │ │ │ +│ │ │ │ └── • top-k +│ │ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, service_latency) +│ │ │ │ │ ordering: -service_latency +│ │ │ │ │ estimated row count: 0 +│ │ │ │ │ order: -service_latency +│ │ │ │ │ k: 500 +│ │ │ │ │ +│ │ │ │ └── • scan +│ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, service_latency) +│ │ │ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ │ │ table: transaction_statistics@service_latency_idx (partial index) +│ │ │ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ │ │ +│ │ │ └── • index join +│ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ │ estimated row count: 0 +│ │ │ │ table: transaction_statistics@primary +│ │ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, aggregated_ts, fingerprint_id, app_name, node_id +│ │ │ │ +│ │ │ └── • top-k +│ │ │ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, cpu_sql_nanos) +│ │ │ │ ordering: -cpu_sql_nanos +│ │ │ │ estimated row count: 0 +│ │ │ │ order: -cpu_sql_nanos +│ │ │ │ k: 500 +│ │ │ │ +│ │ │ └── • scan +│ │ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, cpu_sql_nanos) +│ │ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ │ table: transaction_statistics@cpu_sql_nanos_idx (partial index) +│ │ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ │ +│ │ └── • index join +│ │ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ │ estimated row count: 0 +│ │ │ table: transaction_statistics@primary +│ │ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, aggregated_ts, fingerprint_id, app_name, node_id +│ │ │ +│ │ └── • top-k +│ │ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, contention_time) +│ │ │ ordering: -contention_time +│ │ │ estimated row count: 0 +│ │ │ order: -contention_time +│ │ │ k: 500 +│ │ │ +│ │ └── • scan +│ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, contention_time) +│ │ estimated row count: 0 (33% of the table; stats collected ago) +│ │ table: transaction_statistics@contention_time_idx (partial index) +│ │ spans: /2023-03-21T14:05:00.000001Z- +│ │ +│ └── • index join +│ │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) +│ │ estimated row count: 0 +│ │ table: transaction_statistics@primary +│ │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, aggregated_ts, fingerprint_id, app_name, node_id +│ │ +│ └── • top-k +│ │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, total_estimated_execution_time) +│ │ ordering: -total_estimated_execution_time +│ │ estimated row count: 0 +│ │ order: -total_estimated_execution_time +│ │ k: 500 +│ │ +│ └── • scan +│ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, total_estimated_execution_time) +│ estimated row count: 0 (33% of the table; stats collected ago) +│ table: transaction_statistics@total_estimated_execution_time_idx (partial index) +│ spans: /2023-03-21T14:05:00.000001Z- +│ +└── • index join + │ columns: (aggregated_ts, fingerprint_id, app_name, execution_count, service_latency, cpu_sql_nanos, contention_time, total_estimated_execution_time, p99_latency, metadata, statistics) + │ estimated row count: 0 + │ table: transaction_statistics@primary + │ key columns: crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, aggregated_ts, fingerprint_id, app_name, node_id + │ + └── • top-k + │ columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, p99_latency) + │ ordering: -p99_latency + │ estimated row count: 0 + │ order: -p99_latency + │ k: 500 + │ + └── • scan + columns: (aggregated_ts, fingerprint_id, app_name, node_id, crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8, p99_latency) + estimated row count: 0 (33% of the table; stats collected ago) + table: transaction_statistics@p99_latency_idx (partial index) + spans: /2023-03-21T14:05:00.000001Z-