Skip to content

Commit

Permalink
server: update sort of sql stats to new computed columns
Browse files Browse the repository at this point in the history
Part of cockroachdb#98624
To take advantage of the actual indexes created on the new
persisted views, we need to use the computed columns.
This PR updates the sort by column to use the new columns
instead.

Release note: None
  • Loading branch information
maryliag committed Mar 23, 2023
1 parent da20f04 commit 2c81026
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/server/combined_statement_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ FROM crdb_internal.%s_statistics_persisted

// Common stmt and txn columns to sort on.
const (
sortSvcLatDesc = `(statistics -> 'statistics' -> 'svcLat' ->> 'mean')::FLOAT DESC`
sortCPUTimeDesc = `(statistics -> 'statistics' -> 'execution_statistics' -> 'cpuSQLNanos' ->> 'mean')::FLOAT DESC`
sortExecCountDesc = `(statistics -> 'statistics' ->> 'cnt')::INT DESC`
sortContentionTimeDesc = `(statistics -> 'execution_statistics' -> 'contentionTime' ->> 'mean')::FLOAT DESC`
sortPCTRuntimeDesc = `((statistics -> 'statistics' -> 'svcLat' ->> 'mean')::FLOAT *
(statistics -> 'statistics' ->> 'cnt')::FLOAT) DESC`
sortSvcLatDesc = `service_latency DESC`
sortCPUTimeDesc = `cpu_sql_nanos DESC`
sortExecCountDesc = `execution_count DESC`
sortContentionTimeDesc = `contention_time DESC`
sortPCTRuntimeDesc = `total_estimated_execution_time DESC`
sortP99Desc = `p99_latency DESC`
)

func getStmtColumnFromSortOption(sort serverpb.StatsSortOptions) string {
Expand All @@ -225,7 +225,7 @@ func getStmtColumnFromSortOption(sort serverpb.StatsSortOptions) string {
case serverpb.StatsSortOptions_EXECUTION_COUNT:
return sortExecCountDesc
case serverpb.StatsSortOptions_P99_STMTS_ONLY:
return `(statistics -> 'statistics' -> 'latencyInfo' ->> 'p99')::FLOAT DESC`
return sortP99Desc
case serverpb.StatsSortOptions_CONTENTION_TIME:
return sortContentionTimeDesc
default:
Expand Down

0 comments on commit 2c81026

Please sign in to comment.