Skip to content

Commit

Permalink
server: fix total latency time on sql stats call
Browse files Browse the repository at this point in the history
For the top activity tables, we have a column `execution_total_cluster_seconds`
with the total latency of all executions of that period.
This value is important because the top activity table have
up to 500 rows per aggregated timestamp, so if we add all
latencies from it, we won't have the total, only the total of the top.
We then have a column that has that total of that hour which is
based on the main table.
Previously, when making a request to the top activity table
we were returning only of of those values as the total, which
works as expected if your select is in a single aggregation period.
The majority of requests won't be this way, so we need to add the values
from all aggregated period selects.

This commit update the query for the total select to get
one value from each aggregated_ts and then adding those.

Part Of CRDB-34884

Release note (bug fix): Fix value used for the total runtime on sql stats,
which was using the wrong value previously, causing the UI to display values
with more than 100%.
  • Loading branch information
maryliag committed Jan 8, 2024
1 parent 43eb6b1 commit 8e1324d
Show file tree
Hide file tree
Showing 2 changed files with 475 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/server/combined_statement_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,9 @@ FROM %s %s`, table, whereClauseOldestDate), args...)

createActivityTableQuery := func(table string) string {
return fmt.Sprintf(`
SELECT COALESCE(
execution_total_cluster_seconds,
0)
FROM %s %s LIMIT 1`, table, whereClause)
SELECT COALESCE(sum(total_latency), 0) from (SELECT aggregated_ts,
max(execution_total_cluster_seconds) as total_latency
FROM %s %s GROUP BY aggregated_ts) %s`, table, whereClause, testingKnobs.GetAOSTClause())
}

createStatsTableQuery := func(table string) string {
Expand Down
Loading

0 comments on commit 8e1324d

Please sign in to comment.