Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roachpb/sql/ui: add mean rows written to Statement Details page #70377

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -515,6 +516,10 @@ export class StatementDetails extends React.Component<
<span className={cx("tooltip-info")}>unavailable</span>
</Tooltip>
);
const summary = summarize(statement);
const showRowsWritten =
stats.sql_type === "TypeDML" && summary.statement !== "select";

return (
<Tabs
defaultActiveKey="1"
Expand Down Expand Up @@ -583,6 +588,19 @@ export class StatementDetails extends React.Component<
)}
{unavailableTooltip}
</div>
{showRowsWritten && (
<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>
{statementSampled && (
Expand Down Expand Up @@ -831,6 +849,11 @@ export class StatementDetails extends React.Component<
bar: genericBarChart(stats.bytes_read, stats.count, Bytes),
format: Bytes,
},
{
name: "Rows Written",
value: stats.rows_written,
bar: genericBarChart(stats.rows_written, stats.count),
},
{
name: "Network Bytes Sent",
value: stats.exec_stats.network_bytes,
Expand All @@ -843,9 +866,10 @@ export class StatementDetails extends React.Component<
},
].filter(function(r) {
if (
r.name === "Network Bytes Sent" &&
r.value &&
r.value.mean === 0
(r.name === "Network Bytes Sent" &&
r.value &&
r.value.mean === 0) ||
(r.name === "Rows Written" && !showRowsWritten)
) {
// Omit if empty.
return false;
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: 2,
squared_diffs: 0.005,
},
exec_stats: execStats,
last_exec_timestamp: {
seconds: Long.fromInt(1599670292),
Expand Down
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: 1, 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: 1,
squared_diffs: 0.2,
},
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.01999999999999999,
squared_diffs: 1.899,
},
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: 1, 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: 1, 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.19999,
squared_diffs: 0,
},
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: 1,
squared_diffs: 0,
},
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: 1,
squared_diffs: 0,
},
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: 1,
squared_diffs: 0,
},
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.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function randomStats(sensitiveInfo?: ISensitiveInfo): StatementStatistics {
overhead_lat: randomStat(),
bytes_read: randomStat(),
rows_read: randomStat(),
rows_written: randomStat(),
sensitive_info: sensitiveInfo || makeSensitiveInfo(null, null),
exec_stats: randomExecStats(),
sql_type: "DDL",
Expand Down
6 changes: 6 additions & 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,12 @@ 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_written,
b.rows_written,
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