Skip to content

Commit

Permalink
sql: add txn_fingerprint_id to node_statement_statistics
Browse files Browse the repository at this point in the history
This commit adds the `txn_fingerprint_id` column to
`crdb_internal.node_statement_statistics`.

Release note (sql): `txn_fingerprin_id` has been added to
`crdb_internal.node_statement_statistics`. The type of the
column is NULL or STRING.
  • Loading branch information
xinhaoz committed Jul 7, 2022
1 parent 5aee40e commit e0412e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ SELECT * FROM crdb_internal.leases WHERE node_id < 0
----
node_id table_id name parent_id expiration deleted

query ITTTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBBTTT colnames
query ITTTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBBTTTT colnames
SELECT * FROM crdb_internal.node_statement_statistics WHERE node_id < 0
----
node_id application_name flags statement_id key anonymized count first_attempt_count max_retries last_error rows_avg rows_var parse_lat_avg parse_lat_var plan_lat_avg plan_lat_var run_lat_avg run_lat_var service_lat_avg service_lat_var overhead_lat_avg overhead_lat_var bytes_read_avg bytes_read_var rows_read_avg rows_read_var network_bytes_avg network_bytes_var network_msgs_avg network_msgs_var max_mem_usage_avg max_mem_usage_var max_disk_usage_avg max_disk_usage_var contention_time_avg contention_time_var implicit_txn full_scan sample_plan database_name exec_node_ids
node_id application_name flags statement_id key anonymized count first_attempt_count max_retries last_error rows_avg rows_var parse_lat_avg parse_lat_var plan_lat_avg plan_lat_var run_lat_avg run_lat_var service_lat_avg service_lat_var overhead_lat_avg overhead_lat_var bytes_read_avg bytes_read_var rows_read_avg rows_read_var network_bytes_avg network_bytes_var network_msgs_avg network_msgs_var max_mem_usage_avg max_mem_usage_var max_disk_usage_avg max_disk_usage_var contention_time_avg contention_time_var implicit_txn full_scan sample_plan database_name exec_node_ids txn_fingerprint_id

query ITTTIIRRRRRRRRRRRRRRRRRR colnames
SELECT * FROM crdb_internal.node_transaction_statistics WHERE node_id < 0
Expand Down
10 changes: 9 additions & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ CREATE TABLE crdb_internal.node_statement_statistics (
full_scan BOOL NOT NULL,
sample_plan JSONB,
database_name STRING NOT NULL,
exec_node_ids INT[] NOT NULL
exec_node_ids INT[] NOT NULL,
txn_fingerprint_id STRING
)`,
populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error {
hasViewActivityOrViewActivityRedacted, err := p.HasViewActivityOrViewActivityRedactedRole(ctx)
Expand Down Expand Up @@ -1141,6 +1142,12 @@ CREATE TABLE crdb_internal.node_statement_statistics (
}
}

txnFingerprintID := tree.DNull
if stats.Key.TransactionFingerprintID != roachpb.InvalidTransactionFingerprintID {
txnFingerprintID = tree.NewDString(strconv.FormatUint(uint64(stats.Key.TransactionFingerprintID), 10))

}

err := addRow(
tree.NewDInt(tree.DInt(nodeID)), // node_id
tree.NewDString(stats.Key.App), // application_name
Expand Down Expand Up @@ -1183,6 +1190,7 @@ CREATE TABLE crdb_internal.node_statement_statistics (
tree.NewDJSON(samplePlan), // sample_plan
tree.NewDString(stats.Key.Database), // database_name
execNodeIDs, // exec_node_ids
txnFingerprintID, // txn_fingerprint_id
)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ SELECT * FROM crdb_internal.leases WHERE node_id < 0
----
node_id table_id name parent_id expiration deleted

query ITTTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBBTTT colnames
query ITTTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBBTTTT colnames
SELECT * FROM crdb_internal.node_statement_statistics WHERE node_id < 0
----
node_id application_name flags statement_id key anonymized count first_attempt_count max_retries last_error rows_avg rows_var parse_lat_avg parse_lat_var plan_lat_avg plan_lat_var run_lat_avg run_lat_var service_lat_avg service_lat_var overhead_lat_avg overhead_lat_var bytes_read_avg bytes_read_var rows_read_avg rows_read_var network_bytes_avg network_bytes_var network_msgs_avg network_msgs_var max_mem_usage_avg max_mem_usage_var max_disk_usage_avg max_disk_usage_var contention_time_avg contention_time_var implicit_txn full_scan sample_plan database_name exec_node_ids
node_id application_name flags statement_id key anonymized count first_attempt_count max_retries last_error rows_avg rows_var parse_lat_avg parse_lat_var plan_lat_avg plan_lat_var run_lat_avg run_lat_var service_lat_avg service_lat_var overhead_lat_avg overhead_lat_var bytes_read_avg bytes_read_var rows_read_avg rows_read_var network_bytes_avg network_bytes_var network_msgs_avg network_msgs_var max_mem_usage_avg max_mem_usage_var max_disk_usage_avg max_disk_usage_var contention_time_avg contention_time_var implicit_txn full_scan sample_plan database_name exec_node_ids txn_fingerprint_id

query ITTTIIRRRRRRRRRRRRRRRRRR colnames
SELECT * FROM crdb_internal.node_transaction_statistics WHERE node_id < 0
Expand Down
6 changes: 4 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/create_statements
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,8 @@ CREATE TABLE crdb_internal.node_statement_statistics (
full_scan BOOL NOT NULL,
sample_plan JSONB NULL,
database_name STRING NOT NULL,
exec_node_ids INT8[] NOT NULL
exec_node_ids INT8[] NOT NULL,
txn_fingerprint_id STRING NULL
) CREATE TABLE crdb_internal.node_statement_statistics (
node_id INT8 NOT NULL,
application_name STRING NOT NULL,
Expand Down Expand Up @@ -1053,7 +1054,8 @@ CREATE TABLE crdb_internal.node_statement_statistics (
full_scan BOOL NOT NULL,
sample_plan JSONB NULL,
database_name STRING NOT NULL,
exec_node_ids INT8[] NOT NULL
exec_node_ids INT8[] NOT NULL,
txn_fingerprint_id STRING NULL
) {} {}
CREATE TABLE crdb_internal.node_transaction_statistics (
node_id INT8 NOT NULL,
Expand Down

0 comments on commit e0412e0

Please sign in to comment.