Skip to content

Commit

Permalink
sql: add statement_id to crdb_internal.node_statement_statistics
Browse files Browse the repository at this point in the history
Currently, crdb_internal.node_transaction_statistics uses the
statement_ids column to reference statements in
crdb_internal.node_statement_statistics. However, the statement
statistics view does not have column that shows statement id.

This commit introduce a new statement_id column in the statement
statistics view.

Release note (sql change): crdb_internal.node_statement_statistics
 now stores statement_id.
  • Loading branch information
Azhng committed Apr 22, 2021
1 parent 5d75621 commit 59ce286
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
18 changes: 10 additions & 8 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ CREATE TABLE crdb_internal.node_statement_statistics (
node_id INT NOT NULL,
application_name STRING NOT NULL,
flags STRING NOT NULL,
statement_id STRING NOT NULL,
key STRING NOT NULL,
anonymized STRING,
count INT NOT NULL,
Expand Down Expand Up @@ -941,14 +942,15 @@ CREATE TABLE crdb_internal.node_statement_statistics (
flags = "!" + flags
}
err := addRow(
tree.NewDInt(tree.DInt(nodeID)), // node_id
tree.NewDString(appName), // application_name
tree.NewDString(flags), // flags
tree.NewDString(stmtKey.anonymizedStmt), // key
anonymized, // anonymized
tree.NewDInt(tree.DInt(s.mu.data.Count)), // count
tree.NewDInt(tree.DInt(s.mu.data.FirstAttemptCount)), // first_attempt_count
tree.NewDInt(tree.DInt(s.mu.data.MaxRetries)), // max_retries
tree.NewDInt(tree.DInt(nodeID)), // node_id
tree.NewDString(appName), // application_name
tree.NewDString(flags), // flags
tree.NewDString(strconv.FormatUint(uint64(stmtID), 10)), // statement_id
tree.NewDString(stmtKey.anonymizedStmt), // key
anonymized, // anonymized
tree.NewDInt(tree.DInt(s.mu.data.Count)), // count
tree.NewDInt(tree.DInt(s.mu.data.FirstAttemptCount)), // first_attempt_count
tree.NewDInt(tree.DInt(s.mu.data.MaxRetries)), // max_retries
errString, // last_error
tree.NewDFloat(tree.DFloat(s.mu.data.NumRows.Mean)), // rows_avg
tree.NewDFloat(tree.DFloat(s.mu.data.NumRows.GetVariance(s.mu.data.Count))), // rows_var
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 @@ -154,10 +154,10 @@ SELECT * FROM crdb_internal.leases WHERE node_id < 0
----
node_id table_id name parent_id expiration deleted

query ITTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBB colnames
query ITTTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBB colnames
SELECT * FROM crdb_internal.node_statement_statistics WHERE node_id < 0
----
node_id application_name flags 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
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

query ITTTIIRRRRRRRRRRRRRRRRRR colnames
SELECT * FROM crdb_internal.node_transaction_statistics WHERE node_id < 0
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ SELECT * FROM crdb_internal.leases WHERE node_id < 0
----
node_id table_id name parent_id expiration deleted

query ITTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBB colnames
query ITTTTTIIITRRRRRRRRRRRRRRRRRRRRRRRRRRBB colnames
SELECT * FROM crdb_internal.node_statement_statistics WHERE node_id < 0
----
node_id application_name flags 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
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

query ITTTIIRRRRRRRRRRRRRRRRRR colnames
SELECT * FROM crdb_internal.node_transaction_statistics WHERE node_id < 0
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/create_statements
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ CREATE TABLE crdb_internal.node_statement_statistics (
node_id INT8 NOT NULL,
application_name STRING NOT NULL,
flags STRING NOT NULL,
statement_id STRING NOT NULL,
key STRING NOT NULL,
anonymized STRING NULL,
count INT8 NOT NULL,
Expand Down Expand Up @@ -699,6 +700,7 @@ CREATE TABLE crdb_internal.node_statement_statistics (
node_id INT8 NOT NULL,
application_name STRING NOT NULL,
flags STRING NOT NULL,
statement_id STRING NOT NULL,
key STRING NOT NULL,
anonymized STRING NULL,
count INT8 NOT NULL,
Expand Down

0 comments on commit 59ce286

Please sign in to comment.