Skip to content

Commit 89f5c67

Browse files
committed
sql: add index_bytes_written metric
Add new `sql.statements.index_bytes_written.count` metric that counts the number of primary and secondary index bytes modified by SQL statements. Epic: AOP-30 Release note (sql change): Added sql.statements.index_bytes_written.count metric that counts the number of primary and secondary index bytes modified by SQL statements.
1 parent 30e5c2a commit 89f5c67

22 files changed

+143
-13
lines changed

docs/generated/metrics/metrics.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8969,6 +8969,22 @@ layers:
89698969
unit: BYTES
89708970
aggregation: AVG
89718971
derivative: NON_NEGATIVE_DERIVATIVE
8972+
- name: sql.statements.index_bytes_written.count
8973+
exported_name: sql_statements_index_bytes_written_count
8974+
description: Number of primary and secondary index bytes modified by SQL statements
8975+
y_axis_label: SQL Statements
8976+
type: COUNTER
8977+
unit: BYTES
8978+
aggregation: AVG
8979+
derivative: NON_NEGATIVE_DERIVATIVE
8980+
- name: sql.statements.index_bytes_written.count.internal
8981+
exported_name: sql_statements_index_bytes_written_count_internal
8982+
description: Number of primary and secondary index bytes modified by SQL statements (internal queries)
8983+
y_axis_label: SQL Internal Statements
8984+
type: COUNTER
8985+
unit: BYTES
8986+
aggregation: AVG
8987+
derivative: NON_NEGATIVE_DERIVATIVE
89728988
- name: sql.statements.index_rows_written.count
89738989
exported_name: sql_statements_index_rows_written_count
89748990
description: Number of primary and secondary index rows modified by SQL statements

pkg/roachprod/opentelemetry/cockroachdb_metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,8 @@ var cockroachdbMetrics = map[string]string{
18781878
"sql_statements_bytes_read_count_internal": "sql.statements.bytes_read.count.internal",
18791879
"sql_statements_index_rows_written_count": "sql.statements.index_rows_written.count",
18801880
"sql_statements_index_rows_written_count_internal": "sql.statements.index_rows_written.count.internal",
1881+
"sql_statements_index_bytes_written_count": "sql.statements.index_bytes_written.count",
1882+
"sql_statements_index_bytes_written_count_internal": "sql.statements.index_bytes_written.count.internal",
18811883
"sql_stats_activity_update_latency": "sql.stats.activity.update.latency",
18821884
"sql_stats_activity_update_latency_bucket": "sql.stats.activity.update.latency.bucket",
18831885
"sql_stats_activity_update_latency_count": "sql.stats.activity.update.latency.count",

pkg/sql/conn_executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ func makeMetrics(internal bool, sv *settings.Values) Metrics {
628628
StatementRowsRead: metric.NewCounter(getMetricMeta(MetaStatementRowsRead, internal)),
629629
StatementBytesRead: metric.NewCounter(getMetricMeta(MetaStatementBytesRead, internal)),
630630
StatementIndexRowsWritten: metric.NewCounter(getMetricMeta(MetaStatementIndexRowsWritten, internal)),
631+
StatementIndexBytesWritten: metric.NewCounter(getMetricMeta(MetaStatementIndexBytesWritten, internal)),
631632
},
632633
StartedStatementCounters: makeStartedStatementCounters(internal),
633634
ExecutedStatementCounters: makeExecutedStatementCounters(internal),

pkg/sql/conn_executor_exec.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,10 +3279,10 @@ func (ex *connExecutor) makeExecPlan(
32793279

32803280
// topLevelQueryStats returns some basic statistics about the run of the query.
32813281
type topLevelQueryStats struct {
3282-
// bytesRead is the number of bytes read from primary and secondary indexes.
3283-
bytesRead int64
32843282
// rowsRead is the number of rows read from primary and secondary indexes.
32853283
rowsRead int64
3284+
// bytesRead is the number of bytes read from primary and secondary indexes.
3285+
bytesRead int64
32863286
// rowsWritten is the number of rows written to the primary index. It does not
32873287
// include rows written to secondary indexes.
32883288
// NB: There is an asymmetry between rowsRead and rowsWritten - rowsRead
@@ -3293,6 +3293,9 @@ type topLevelQueryStats struct {
32933293
// indexRowsWritten is the number of rows written to primary and secondary
32943294
// indexes. It is always >= rowsWritten.
32953295
indexRowsWritten int64
3296+
// indexBytesWritten is the number of bytes written to primary and secondary
3297+
// indexes.
3298+
indexBytesWritten int64
32963299
// networkEgressEstimate is an estimate for the number of bytes sent to the
32973300
// client. It is used for estimating the number of RUs consumed by a query.
32983301
networkEgressEstimate int64
@@ -3306,6 +3309,7 @@ func (s *topLevelQueryStats) add(other *topLevelQueryStats) {
33063309
s.bytesRead += other.bytesRead
33073310
s.rowsRead += other.rowsRead
33083311
s.rowsWritten += other.rowsWritten
3312+
s.indexBytesWritten += other.indexBytesWritten
33093313
s.indexRowsWritten += other.indexRowsWritten
33103314
s.networkEgressEstimate += other.networkEgressEstimate
33113315
s.clientTime += other.clientTime

pkg/sql/delete.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ func (d *deleteNode) indexRowsWritten() int64 {
263263
return d.run.td.indexRowsWritten
264264
}
265265

266+
func (d *deleteNode) indexBytesWritten() int64 {
267+
// No bytes counted as written for a deletion.
268+
return 0
269+
}
270+
266271
func (d *deleteNode) enableAutoCommit() {
267272
d.run.td.enableAutoCommit()
268273
}

pkg/sql/delete_range.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func (d *deleteRangeNode) indexRowsWritten() int64 {
8989
return int64(d.rowCount)
9090
}
9191

92+
func (d *deleteRangeNode) indexBytesWritten() int64 {
93+
// No bytes counted as written for a deletion.
94+
return 0
95+
}
96+
9297
// startExec implements the planNode interface.
9398
func (d *deleteRangeNode) startExec(params runParams) error {
9499
if err := params.p.cancelChecker.Check(); err != nil {

pkg/sql/delete_swap.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ func (d *deleteSwapNode) indexRowsWritten() int64 {
147147
return d.run.td.indexRowsWritten
148148
}
149149

150+
func (d *deleteSwapNode) indexBytesWritten() int64 {
151+
// No bytes counted as written for a deletion.
152+
return 0
153+
}
154+
150155
func (d *deleteSwapNode) enableAutoCommit() {
151156
d.run.td.enableAutoCommit()
152157
}

pkg/sql/distsql_running.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,7 @@ func (r *DistSQLReceiver) pushMeta(meta *execinfrapb.ProducerMetadata) execinfra
16071607
r.stats.rowsRead += meta.Metrics.RowsRead
16081608
r.stats.rowsWritten += meta.Metrics.RowsWritten
16091609
r.stats.indexRowsWritten += meta.Metrics.IndexRowsWritten
1610+
r.stats.indexBytesWritten += meta.Metrics.IndexBytesWritten
16101611

16111612
if sm, ok := r.scanStageEstimateMap[meta.Metrics.StageID]; ok {
16121613
sm.rowsRead += uint64(meta.Metrics.RowsRead)

pkg/sql/exec_util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,12 @@ var (
15321532
Measurement: "SQL Statements",
15331533
Unit: metric.Unit_COUNT,
15341534
}
1535+
MetaStatementIndexBytesWritten = metric.Metadata{
1536+
Name: "sql.statements.index_bytes_written.count",
1537+
Help: "Number of primary and secondary index bytes modified by SQL statements",
1538+
Measurement: "SQL Statements",
1539+
Unit: metric.Unit_BYTES,
1540+
}
15351541
)
15361542

15371543
func getMetricMeta(meta metric.Metadata, internal bool) metric.Metadata {

pkg/sql/execinfrapb/data.proto

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,17 @@ message RemoteProducerMetadata {
345345
// IndexRowsWritten is the number of primary and secondary index rows
346346
// modified while executing a statement. It is always >= RowsWritten.
347347
optional int64 index_rows_written = 5 [(gogoproto.nullable) = false];
348+
// IndexBytesWritten is the number of primary and secondary index bytes
349+
// modified while executing a statement.
350+
optional int64 index_bytes_written = 6 [(gogoproto.nullable) = false];
348351
// Stage identifier that produced these metrics. This is used to aggregate
349352
// row counts across distributed table reader processors for misestimate
350353
// logging. Note that other disk-reading processors (index and lookup joins,
351354
// inverted joins, zigzag joins) do not set this field. This is safe because
352355
// we enumerate physical plan stages starting at 1, so the default value of
353356
// 0 isn't conflated with any actual plan stage.
354357
optional int32 stage_id = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "StageID"];
355-
// NEXT ID: 6
358+
// NEXT ID: 7
356359
}
357360
oneof value {
358361
RangeInfos range_info = 1;
@@ -367,7 +370,7 @@ message RemoteProducerMetadata {
367370
TracingAggregatorEvents tracing_aggregator_events= 12;
368371
}
369372
reserved 6, 10;
370-
// NEXT ID: 14
373+
// NEXT ID: 13
371374
}
372375

373376
// DistSQLDrainingInfo represents the DistSQL draining state that gets gossiped

0 commit comments

Comments
 (0)