From 92efe7d477f2bf4a4b0296ddadfe390cbb3d0979 Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Fri, 24 Mar 2023 13:39:43 -0500 Subject: [PATCH 1/4] bazci: protect against `nil` target Closes #98861. Epic: none Release note: None --- pkg/cmd/bazci/bazci.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/cmd/bazci/bazci.go b/pkg/cmd/bazci/bazci.go index 64d89916090a..77e8b850554d 100644 --- a/pkg/cmd/bazci/bazci.go +++ b/pkg/cmd/bazci/bazci.go @@ -246,6 +246,9 @@ func (s *monitorBuildServer) handleBuildEvent( func (s *monitorBuildServer) Finalize() error { if s.action == "build" { for _, target := range s.builtTargets { + if target == nil { + continue + } for _, outputGroup := range target.OutputGroup { if outputGroup == nil || outputGroup.Incomplete { continue From 4ae429f3f0e690d3ffe512a25afc1fb1b46d1646 Mon Sep 17 00:00:00 2001 From: Eric Harmeling Date: Fri, 24 Mar 2023 17:31:22 -0400 Subject: [PATCH 2/4] sql: inject stats into TestExecBuild_sql_statistics_persisted testdata Part of https://github.com/cockroachdb/cockroach/issues/99399. This commit replaces the CREATE STATISTICS statements in the TestExecBuild_sql_statistics_persisted testdata with ALTER TABLE ... INJECT STATISTICS and removes the retry directives added to deflake the test in #99447. Epic: none Release note: None --- .../testdata/sql_statistics_persisted | 800 +++++++++++++++--- 1 file changed, 704 insertions(+), 96 deletions(-) diff --git a/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted b/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted index 1d3aad9cc606..3b9c300cdf5d 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted +++ b/pkg/sql/opt/exec/execbuilder/testdata/sql_statistics_persisted @@ -1,9 +1,356 @@ # LogicTest: local +# Ensure we can run ALTER statements on the system.statement_statistics and +# system.transaction_statistics tables. statement ok -CREATE STATISTICS system_statement_stats FROM system.statement_statistics +INSERT INTO system.users VALUES ('node', NULL, true, 3); -query T retry +statement ok +GRANT node TO root; + +statement ok +ALTER TABLE system.statement_statistics INJECT STATISTICS '[ + { + "columns": [ + "aggregated_ts" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "TIMESTAMPTZ", + "null_count": 0, + "row_count": 1000000 + }, + { + "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" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "fingerprint_id", + "transaction_fingerprint_id", + "plan_hash", + "app_name", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "fingerprint_id", + "transaction_fingerprint_id", + "plan_hash", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "fingerprint_id", + "transaction_fingerprint_id", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "fingerprint_id", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "execution_count" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "service_latency" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "cpu_sql_nanos" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "contention_time" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "total_estimated_execution_time" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "p99_latency" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "fingerprint_id" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "BYTES", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "fingerprint_id", + "transaction_fingerprint_id" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "transaction_fingerprint_id" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "BYTES", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "plan_hash" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "BYTES", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "app_name" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "STRING", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "node_id" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "INT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "agg_interval" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "INTERVAL", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "metadata" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "statistics" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "plan" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_transaction_fingerprint_id_shard_8" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "INT4", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "index_recommendations" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "STRING[]", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "execution_count" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "INT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "service_latency" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "cpu_sql_nanos" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "contention_time" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "total_estimated_execution_time" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "p99_latency" + ], + "created_at": "2023-03-24 21:22:03.381873", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + } +]' + +query T EXPLAIN (VERBOSE) SELECT * FROM ((SELECT aggregated_ts, @@ -107,135 +454,135 @@ vectorized: true · • 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 +│ estimated row count: 3,000 │ ├── • 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 +│ │ estimated row count: 2,500 │ │ │ ├── • 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 +│ │ │ estimated row count: 2,000 │ │ │ │ │ ├── • 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 +│ │ │ │ estimated row count: 1,500 │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ estimated row count: 1,000 │ │ │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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) +│ │ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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) +│ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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) +│ │ │ estimated row count: 333,333 (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 +│ │ │ estimated row count: 500 │ │ │ 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 +│ │ │ estimated row count: 500 │ │ │ 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) +│ │ estimated row count: 333,333 (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 +│ │ estimated row count: 500 │ │ 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 +│ │ estimated row count: 500 │ │ 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) +│ estimated row count: 333,333 (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 + │ estimated row count: 500 │ 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 + │ estimated row count: 500 │ 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) + estimated row count: 333,333 (33% of the table; stats collected ago) table: statement_statistics@p99_latency_idx (partial index) spans: /2023-03-21T14:05:00.000001Z- @@ -343,142 +690,403 @@ vectorized: true · • 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 +│ estimated row count: 3,000 │ ├── • 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 +│ │ estimated row count: 2,500 │ │ │ ├── • 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 +│ │ │ estimated row count: 2,000 │ │ │ │ │ ├── • 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 +│ │ │ │ estimated row count: 1,500 │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ estimated row count: 1,000 │ │ │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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) +│ │ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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) +│ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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) +│ │ │ estimated row count: 333,333 (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 +│ │ │ estimated row count: 500 │ │ │ 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 +│ │ │ estimated row count: 500 │ │ │ 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) +│ │ estimated row count: 333,333 (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 +│ │ estimated row count: 500 │ │ 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 +│ │ estimated row count: 500 │ │ 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) +│ estimated row count: 333,333 (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 + │ estimated row count: 500 │ 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 + │ estimated row count: 500 │ 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) + estimated row count: 333,333 (33% of the table; stats collected ago) table: statement_statistics@p99_latency_idx (partial index) spans: /2023-03-21T14:05:00.000001Z- statement ok -CREATE STATISTICS system_transaction_stats FROM system.transaction_statistics +ALTER TABLE system.transaction_statistics INJECT STATISTICS '[ + { + "columns": [ + "aggregated_ts" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "TIMESTAMPTZ", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "fingerprint_id", + "app_name", + "node_id", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "fingerprint_id", + "app_name", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "fingerprint_id", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "execution_count" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "service_latency" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "cpu_sql_nanos" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "contention_time" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "total_estimated_execution_time" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "app_name", + "p99_latency" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "aggregated_ts", + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "fingerprint_id" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "BYTES", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "app_name" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "STRING", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "node_id" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "INT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "agg_interval" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "INTERVAL", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "metadata" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "statistics" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "INT4", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "execution_count" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "INT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "service_latency" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "cpu_sql_nanos" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "contention_time" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "total_estimated_execution_time" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + }, + { + "columns": [ + "p99_latency" + ], + "created_at": "2023-03-24 21:14:26.994348", + "distinct_count": 1000000, + "histo_col_type": "FLOAT8", + "null_count": 0, + "row_count": 1000000 + } +]' -query T retry +query T EXPLAIN (VERBOSE) SELECT * FROM ((SELECT aggregated_ts, @@ -576,135 +1184,135 @@ 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 +│ estimated row count: 3,000 │ ├── • 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 +│ │ estimated row count: 2,500 │ │ │ ├── • 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 +│ │ │ estimated row count: 2,000 │ │ │ │ │ ├── • 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 +│ │ │ │ estimated row count: 1,500 │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ estimated row count: 1,000 │ │ │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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) +│ │ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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) +│ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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) +│ │ │ estimated row count: 333,333 (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 +│ │ │ estimated row count: 500 │ │ │ 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 +│ │ │ estimated row count: 500 │ │ │ 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) +│ │ estimated row count: 333,333 (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 +│ │ estimated row count: 500 │ │ 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 +│ │ estimated row count: 500 │ │ 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) +│ estimated row count: 333,333 (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 + │ estimated row count: 500 │ 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 + │ estimated row count: 500 │ 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) + estimated row count: 333,333 (33% of the table; stats collected ago) table: transaction_statistics@p99_latency_idx (partial index) spans: /2023-03-21T14:05:00.000001Z- @@ -806,134 +1414,134 @@ 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 +│ estimated row count: 3,000 │ ├── • 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 +│ │ estimated row count: 2,500 │ │ │ ├── • 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 +│ │ │ estimated row count: 2,000 │ │ │ │ │ ├── • 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 +│ │ │ │ estimated row count: 1,500 │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ estimated row count: 1,000 │ │ │ │ │ │ │ │ │ ├── • 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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 +│ │ │ │ │ │ estimated row count: 500 │ │ │ │ │ │ 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) +│ │ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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 +│ │ │ │ │ estimated row count: 500 │ │ │ │ │ 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) +│ │ │ │ estimated row count: 333,333 (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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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 +│ │ │ │ estimated row count: 500 │ │ │ │ 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) +│ │ │ estimated row count: 333,333 (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 +│ │ │ estimated row count: 500 │ │ │ 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 +│ │ │ estimated row count: 500 │ │ │ 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) +│ │ estimated row count: 333,333 (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 +│ │ estimated row count: 500 │ │ 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 +│ │ estimated row count: 500 │ │ 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) +│ estimated row count: 333,333 (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 + │ estimated row count: 500 │ 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 + │ estimated row count: 500 │ 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) + estimated row count: 333,333 (33% of the table; stats collected ago) table: transaction_statistics@p99_latency_idx (partial index) spans: /2023-03-21T14:05:00.000001Z- From 2133e6706b213b92ac0398a581e597fe6e9ba3af Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Mon, 27 Mar 2023 14:07:01 +0200 Subject: [PATCH 3/4] serverccl: skip TestServerControllerHTTP under deadlock Release note: None --- pkg/ccl/serverccl/BUILD.bazel | 1 + pkg/ccl/serverccl/server_controller_test.go | 27 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/ccl/serverccl/BUILD.bazel b/pkg/ccl/serverccl/BUILD.bazel index 6d908fb596ea..240025badb29 100644 --- a/pkg/ccl/serverccl/BUILD.bazel +++ b/pkg/ccl/serverccl/BUILD.bazel @@ -74,6 +74,7 @@ go_test( "//pkg/sql/tests", "//pkg/testutils", "//pkg/testutils/serverutils", + "//pkg/testutils/skip", "//pkg/testutils/sqlutils", "//pkg/testutils/testcluster", "//pkg/ts/catalog", diff --git a/pkg/ccl/serverccl/server_controller_test.go b/pkg/ccl/serverccl/server_controller_test.go index 8b73df790a72..3a96bd5eb966 100644 --- a/pkg/ccl/serverccl/server_controller_test.go +++ b/pkg/ccl/serverccl/server_controller_test.go @@ -25,6 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" + "github.com/cockroachdb/cockroach/pkg/testutils/skip" "github.com/cockroachdb/cockroach/pkg/util/httputil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -38,6 +39,8 @@ func TestServerControllerHTTP(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) + skip.UnderDeadlock(t, "test triggers many goroutines, which results in conn timeouts and test failures under deadlock") + ctx := context.Background() s, db, _ := serverutils.StartServer(t, base.TestServerArgs{ @@ -45,12 +48,16 @@ func TestServerControllerHTTP(t *testing.T) { }) defer s.Stopper().Stop(ctx) + t.Logf("waking up HTTP server") + // Retrieve a privileged HTTP client. NB: this also populates // system.web_sessions. aurl := s.AdminURL() client, err := s.GetAdminHTTPClient() require.NoError(t, err) + t.Logf("retrieving web session details") + // Now retrieve the entry in the system tenant's web sessions. row := db.QueryRow(`SELECT id,"hashedSecret",username,"createdAt","expiresAt" FROM system.web_sessions`) var id int64 @@ -59,6 +66,8 @@ func TestServerControllerHTTP(t *testing.T) { var created, expires time.Time require.NoError(t, row.Scan(&id, &secret, &username, &created, &expires)) + t.Logf("waking up a test tenant") + // Create our own test tenant with a known name. _, _, err = s.(*server.TestServer).StartSharedProcessTenant(ctx, base.TestSharedProcessTenantArgs{ @@ -66,6 +75,8 @@ func TestServerControllerHTTP(t *testing.T) { }) require.NoError(t, err) + t.Logf("connecting to the test tenant") + // Get a SQL connection to the test tenant. sqlAddr := s.ServingSQLAddr() db2, err := serverutils.OpenDBConnE(sqlAddr, "cluster:hello/defaultdb", false, s.Stopper()) @@ -76,6 +87,8 @@ func TestServerControllerHTTP(t *testing.T) { // This actually uses the connection. require.NoError(t, db2.Ping()) + t.Logf("creating a test user and session") + // Instantiate the HTTP test username and privileges into the test tenant. _, err = db2.Exec(fmt.Sprintf(`CREATE USER %s`, lexbase.EscapeSQLIdent(username))) require.NoError(t, err) @@ -88,6 +101,8 @@ VALUES($1, $2, $3, $4, $5, (SELECT user_id FROM system.users WHERE username = $3 id, secret, username, created, expires) require.NoError(t, err) + t.Logf("configuring the test connections") + // From this point, we are expecting the ability to access both tenants using // the same cookie jar. // Let's assert this is true by retrieving session lists, asserting @@ -128,6 +143,8 @@ VALUES($1, $2, $3, $4, $5, (SELECT user_id FROM system.users WHERE username = $3 return req } + t.Logf("retrieving session list from system tenant") + // Retrieve the session list for the system tenant. req := newreq() req.Header.Set(server.TenantSelectHeader, catconstants.SystemTenantName) @@ -137,6 +154,8 @@ VALUES($1, $2, $3, $4, $5, (SELECT user_id FROM system.users WHERE username = $3 require.Equal(t, len(body.Sessions), 1) require.Equal(t, body.Sessions[0].ApplicationName, "hello system") + t.Logf("retrieving session list from test tenant") + // Ditto for the test tenant. req = newreq() req.Header.Set(server.TenantSelectHeader, "hello") @@ -146,6 +165,8 @@ VALUES($1, $2, $3, $4, $5, (SELECT user_id FROM system.users WHERE username = $3 require.Equal(t, len(body.Sessions), 1) require.Equal(t, body.Sessions[0].ApplicationName, "hello hello") + t.Logf("retrieving session list from system tenant via cookie") + c := &http.Cookie{ Name: server.TenantSelectCookieName, Value: catconstants.SystemTenantName, @@ -164,6 +185,8 @@ VALUES($1, $2, $3, $4, $5, (SELECT user_id FROM system.users WHERE username = $3 require.Equal(t, len(body.Sessions), 1) require.Equal(t, body.Sessions[0].ApplicationName, "hello system") + t.Logf("retrieving session list from test tenant via cookie") + c.Value = "hello" client.Jar.SetCookies(purl, []*http.Cookie{c}) req = newreq() @@ -173,6 +196,8 @@ VALUES($1, $2, $3, $4, $5, (SELECT user_id FROM system.users WHERE username = $3 require.Equal(t, len(body.Sessions), 1) require.Equal(t, body.Sessions[0].ApplicationName, "hello hello") + t.Logf("retrieving session list from test tenant via cookie and header") + // Finally, do it again with both cookie and header. Verify // that the header wins. req = newreq() @@ -182,6 +207,8 @@ VALUES($1, $2, $3, $4, $5, (SELECT user_id FROM system.users WHERE username = $3 t.Logf("response 5:\n%#v", body) require.Equal(t, len(body.Sessions), 1) require.Equal(t, body.Sessions[0].ApplicationName, "hello system") + + t.Logf("end of test") } // TestServerControllerBadHTTPCookies tests the controller's proxy From 70b1be2d8455e3a579d2c22e28dec2f1ff618354 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Mon, 27 Mar 2023 10:45:49 -0400 Subject: [PATCH 4/4] workload/tpcc: disable check 3.3.2.11 after workload Fixes #99619. Fixes #99594. Fixes #99603. Fixes #99604. This commit disables TPC-C's consistency check 3.3.2.11 after the workload has run. The check asserts a relationship between the number of rows in the "order" table and rows in the "new_order" table. Rows are inserted into these tables transactional by the NewOrder transaction. However, only rows in the "new_order" table are deleted by the Delivery transaction. Consequently, the consistency condition will fail after the first Delivery transaction is run by the workload. See https://github.com/cockroachdb/cockroach/pull/99542#issuecomment-1485227793 for more details. Release note: None --- pkg/workload/tpcc/checks.go | 36 +++++++++++++-------- pkg/workload/tpcc/tpcc.go | 4 +++ pkg/workload/tpccchecks/checks_generator.go | 4 +++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/pkg/workload/tpcc/checks.go b/pkg/workload/tpcc/checks.go index 0fdb7b13002e..875d39280e82 100644 --- a/pkg/workload/tpcc/checks.go +++ b/pkg/workload/tpcc/checks.go @@ -22,25 +22,35 @@ type Check struct { // If asOfSystemTime is non-empty it will be used to perform the check as // a historical query using the provided value as the argument to the // AS OF SYSTEM TIME clause. - Fn func(db *gosql.DB, asOfSystemTime string) error + Fn func(db *gosql.DB, asOfSystemTime string) error + // If true, the check is "expensive" and may take a long time to run. Expensive bool + // If true, the check is only valid immediately after loading the dataset. + // The check may fail if run after the workload. + LoadOnly bool } // AllChecks returns a slice of all of the checks. func AllChecks() []Check { return []Check{ - {"3.3.2.1", check3321, false}, - {"3.3.2.2", check3322, false}, - {"3.3.2.3", check3323, false}, - {"3.3.2.4", check3324, false}, - {"3.3.2.5", check3325, false}, - {"3.3.2.6", check3326, true}, - {"3.3.2.7", check3327, false}, - {"3.3.2.8", check3328, false}, - {"3.3.2.9", check3329, false}, - {"3.3.2.10", check33210, true}, - {"3.3.2.11", check33211, false}, - {"3.3.2.12", check33212, true}, + {"3.3.2.1", check3321, false, false}, + {"3.3.2.2", check3322, false, false}, + {"3.3.2.3", check3323, false, false}, + {"3.3.2.4", check3324, false, false}, + {"3.3.2.5", check3325, false, false}, + {"3.3.2.6", check3326, true, false}, + {"3.3.2.7", check3327, false, false}, + {"3.3.2.8", check3328, false, false}, + {"3.3.2.9", check3329, false, false}, + {"3.3.2.10", check33210, true, false}, + // 3.3.2.11 is LoadOnly. It asserts a relationship between the number of + // rows in the "order" table and rows in the "new_order" table. Rows are + // inserted into these tables transactional by the NewOrder transaction. + // However, only rows in the "new_order" table are deleted by the Delivery + // transaction. Consequently, the consistency condition will fail after the + // first Delivery transaction is run by the workload. + {"3.3.2.11", check33211, false, true}, + {"3.3.2.12", check33212, true, false}, } } diff --git a/pkg/workload/tpcc/tpcc.go b/pkg/workload/tpcc/tpcc.go index 3f82afee8eee..1c18f8ed9315 100644 --- a/pkg/workload/tpcc/tpcc.go +++ b/pkg/workload/tpcc/tpcc.go @@ -513,6 +513,10 @@ func (w *tpcc) Hooks() workload.Hooks { if !w.expensiveChecks && check.Expensive { continue } + if check.LoadOnly { + // TODO(nvanbenschoten): support load-only checks. + continue + } start := timeutil.Now() err := check.Fn(db, "" /* asOfSystemTime */) log.Infof(ctx, `check %s took %s`, check.Name, timeutil.Since(start)) diff --git a/pkg/workload/tpccchecks/checks_generator.go b/pkg/workload/tpccchecks/checks_generator.go index 8648683ae1c1..778d6fd00a5a 100644 --- a/pkg/workload/tpccchecks/checks_generator.go +++ b/pkg/workload/tpccchecks/checks_generator.go @@ -48,6 +48,10 @@ foreground TPC-C workload`, " AS OF SYSTEM TIME CLAUSE for all checks.") checkNames := func() (checkNames []string) { for _, c := range tpcc.AllChecks() { + if c.LoadOnly { + // TODO(nvanbenschoten): support load-only checks. + continue + } checkNames = append(checkNames, c.Name) } return checkNames