Skip to content

Commit

Permalink
roachpb/sql/ui: add mean rows written to Statement Details page
Browse files Browse the repository at this point in the history
Resolves #67084

Previously, the Statement Details page did not show the mean rows
written to. We received feedback to surface rows affected.

To address this, we are adding "mean rows written" to non-SELECT
statements. A future PR will also add this new metric to the column
selector on the Statements Overview page.

Release note (ui change): add mean rows written to statement details page
  • Loading branch information
lindseyjin committed Sep 20, 2021
1 parent f7c562b commit d503e34
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 114 deletions.
4 changes: 3 additions & 1 deletion pkg/roachpb/app_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (s *StatementStatistics) Add(other *StatementStatistics) {
s.OverheadLat.Add(other.OverheadLat, s.Count, other.Count)
s.BytesRead.Add(other.BytesRead, s.Count, other.Count)
s.RowsRead.Add(other.RowsRead, s.Count, other.Count)
s.RowsWritten.Add(other.RowsWritten, s.Count, other.Count)
s.Nodes = util.CombineUniqueInt64(s.Nodes, other.Nodes)

s.ExecStats.Add(other.ExecStats)
Expand Down Expand Up @@ -181,7 +182,8 @@ func (s *StatementStatistics) AlmostEqual(other *StatementStatistics, eps float6
s.OverheadLat.AlmostEqual(other.OverheadLat, eps) &&
s.SensitiveInfo.Equal(other.SensitiveInfo) &&
s.BytesRead.AlmostEqual(other.BytesRead, eps) &&
s.RowsRead.AlmostEqual(other.RowsRead, eps)
s.RowsRead.AlmostEqual(other.RowsRead, eps) &&
s.RowsWritten.AlmostEqual(other.RowsWritten, eps)
// s.ExecStats are deliberately ignored since they are subject to sampling
// probability and are not fully deterministic (e.g. the number of network
// messages depends on the range cache state).
Expand Down
277 changes: 164 additions & 113 deletions pkg/roachpb/app_stats.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pkg/roachpb/app_stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ message StatementStatistics {
// RowsRead collects the number of rows read from disk.
optional NumericStat rows_read = 16 [(gogoproto.nullable) = false];

// RowsWritten collects the number of rows written to disk.
optional NumericStat rows_written = 25 [(gogoproto.nullable) = false];

// ExecStats are the execution statistics for this statement. These statistics
// are sampled.
optional ExecStats exec_stats = 21 [(gogoproto.nullable) = false];
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/executor_statement_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (ex *connExecutor) recordStatementSummary(
OverheadLatency: execOverhead,
BytesRead: stats.bytesRead,
RowsRead: stats.rowsRead,
RowsWritten: stats.rowsWritten,
Nodes: getNodesFromPlanner(planner),
StatementType: stmt.AST.StatementType(),
Plan: planner.instrumentation.PlanForStats(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func TestSQLStatsJsonEncoding(t *testing.T) {
"mean": {{.Float}},
"sqDiff": {{.Float}}
},
"rowsWritten": {
"mean": {{.Float}},
"sqDiff": {{.Float}}
},
"nodes": [{{joinInts .IntArray}}]
},
"execution_statistics": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (s *innerStmtStats) jsonFields() jsonFields {
{"ovhLat", (*numericStats)(&s.OverheadLat)},
{"bytesRead", (*numericStats)(&s.BytesRead)},
{"rowsRead", (*numericStats)(&s.RowsRead)},
{"rowsWritten", (*numericStats)(&s.RowsWritten)},
{"nodes", (*int64Array)(&s.Nodes)},
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (s *Container) RecordStatement(
stats.mu.data.OverheadLat.Record(stats.mu.data.Count, value.OverheadLatency)
stats.mu.data.BytesRead.Record(stats.mu.data.Count, float64(value.BytesRead))
stats.mu.data.RowsRead.Record(stats.mu.data.Count, float64(value.RowsRead))
stats.mu.data.RowsWritten.Record(stats.mu.data.Count, float64(value.RowsWritten))
stats.mu.data.LastExecTimestamp = timeutil.Now()
stats.mu.data.Nodes = util.CombineUniqueInt64(stats.mu.data.Nodes, value.Nodes)
// Note that some fields derived from tracing statements (such as
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sqlstats/ssprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ type RecordedStmtStats struct {
OverheadLatency float64
BytesRead int64
RowsRead int64
RowsWritten int64
Nodes []int64
StatementType tree.StatementType
Plan *roachpb.ExplainTreePlanNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
formatNumberForDisplay,
calculateTotalWorkload,
unique,
summarize,
} from "src/util";
import { Loading } from "src/loading";
import { Button } from "src/button";
Expand Down Expand Up @@ -501,6 +502,9 @@ export class StatementDetails extends React.Component<
moment(stats.last_exec_timestamp.seconds.low * 1e3).format(
"MMM DD, YYYY HH:MM",
);
const summary = summarize(statement);
const notSelectStatement = summary.statement !== "select";

return (
<Tabs
defaultActiveKey="1"
Expand Down Expand Up @@ -566,6 +570,19 @@ export class StatementDetails extends React.Component<
{formatNumberForDisplay(stats.bytes_read.mean, Bytes)}
</Text>
</div>
{notSelectStatement && (
<div
className={summaryCardStylesCx("summary--card__item")}
>
<Text>Mean rows written</Text>
<Text>
{formatNumberForDisplay(
stats.rows_written.mean,
formatTwoPlaces,
)}
</Text>
</div>
)}
<div className={summaryCardStylesCx("summary--card__item")}>
<Text>Max memory usage</Text>
<Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const statementStats: Required<IStatementStatistics> = {
mean: 10,
squared_diffs: 1,
},
rows_written: {
mean: 10,
squared_diffs: 1,
},
exec_stats: execStats,
last_exec_timestamp: {
seconds: Long.fromInt(1599670292),
Expand Down
27 changes: 27 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/util/appStats/appStats.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
},
bytes_read: { mean: 0, squared_diffs: 0 },
rows_read: { mean: 0, squared_diffs: 0 },
rows_written: { mean: 0, squared_diffs: 0 },
last_exec_timestamp: {
seconds: Long.fromInt(1599670290),
nanos: 111613000,
Expand Down Expand Up @@ -204,6 +205,10 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
rows_written: {
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
last_exec_timestamp: {
seconds: Long.fromInt(1599670272),
nanos: 111613000,
Expand Down Expand Up @@ -314,6 +319,10 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
rows_written: {
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
last_exec_timestamp: {
seconds: Long.fromInt(1599670192),
nanos: 111613000,
Expand Down Expand Up @@ -418,6 +427,7 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
},
bytes_read: { mean: 0, squared_diffs: 0 },
rows_read: { mean: 0, squared_diffs: 0 },
rows_written: { mean: 0, squared_diffs: 0 },
last_exec_timestamp: {
seconds: Long.fromInt(1599670299),
nanos: 111613000,
Expand Down Expand Up @@ -522,6 +532,7 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
},
bytes_read: { mean: 0, squared_diffs: 0 },
rows_read: { mean: 0, squared_diffs: 0 },
rows_written: { mean: 0, squared_diffs: 0 },
last_exec_timestamp: {
seconds: Long.fromInt(1599670242),
nanos: 111613000,
Expand Down Expand Up @@ -632,6 +643,10 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
rows_written: {
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
last_exec_timestamp: {
seconds: Long.fromInt(1599650292),
nanos: 111613000,
Expand Down Expand Up @@ -742,6 +757,10 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
rows_written: {
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
last_exec_timestamp: {
seconds: Long.fromInt(1599670282),
nanos: 111613000,
Expand Down Expand Up @@ -855,6 +874,10 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
rows_written: {
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
last_exec_timestamp: {
seconds: Long.fromInt(1599670257),
nanos: 111613000,
Expand Down Expand Up @@ -962,6 +985,10 @@ export const statementsWithSameIdButDifferentNodeId: CollectedStatementStatistic
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
rows_written: {
mean: 0.07999999999999999,
squared_diffs: 3.8399999999999994,
},
last_exec_timestamp: {
seconds: Long.fromInt(1599670279),
nanos: 111613000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function randomStats(
overhead_lat: randomStat(),
bytes_read: randomStat(),
rows_read: randomStat(),
rows_written: randomStat(),
sensitive_info: sensitiveInfo || makeSensitiveInfo(null, null),
legacy_last_err: "",
legacy_last_err_redacted: "",
Expand Down
6 changes: 6 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/util/appStats/appStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ export function addStatementStats(
countB,
),
rows_read: aggregateNumericStats(a.rows_read, b.rows_read, countA, countB),
rows_written: aggregateNumericStats(
a.rows_written,
b.rows_written,
countA,
countB,
),
sensitive_info: coalesceSensitiveInfo(a.sensitive_info, b.sensitive_info),
legacy_last_err: "",
legacy_last_err_redacted: "",
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/workspaces/db-console/src/util/appStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export function addStatementStats(
),
bytes_read: addNumericStats(a.bytes_read, b.bytes_read, countA, countB),
rows_read: addNumericStats(a.rows_read, b.rows_read, countA, countB),
rows_written: addNumericStats(a.rows_read, b.rows_read, countA, countB),
sensitive_info: coalesceSensitiveInfo(a.sensitive_info, b.sensitive_info),
legacy_last_err: "",
legacy_last_err_redacted: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ function makeStats(): Required<StatementStatistics> {
sensitive_info: makeEmptySensitiveInfo(),
rows_read: makeStat(),
bytes_read: makeStat(),
rows_written: makeStat(),
exec_stats: makeExecStats(),
sql_type: "DDL",
last_exec_timestamp: {
Expand Down

0 comments on commit d503e34

Please sign in to comment.