Skip to content

release-26.1: sql: fix "rows written" metrics#167431

Merged
trunk-io[bot] merged 1 commit intocockroachdb:release-26.1from
yuzefovich:blathers/backport-release-26.1-167360
Apr 8, 2026
Merged

release-26.1: sql: fix "rows written" metrics#167431
trunk-io[bot] merged 1 commit intocockroachdb:release-26.1from
yuzefovich:blathers/backport-release-26.1-167360

Conversation

@yuzefovich
Copy link
Copy Markdown
Member

@yuzefovich yuzefovich commented Apr 2, 2026

Backport 1/1 commits from #167360 on behalf of @yuzefovich.


This commit fixes a bug that was introduced long time ago in 03c09a3. In particular, in that change we began tracking "rows written" for the purposes of the guardrails, and later this information was also added into statement statistics as well as extended to some metrics.

The bug was that we only check the first wrapped planNode for being a mutationPlanNode, but it's actually possible for a single planNodeToRowSource wrapper to wrap multiple planNodes at once. For example, if we have a mutation in the CTE, then we could have bufferNode -> insertNode -> valuesNode, all handled by a single wrapper. Previously, we would only check bufferNode, and since it's not a mutation planNode, we'd emit no "written" metrics.

This commit fixes the issue by traversing the planNode tree until we either reach the first not-wrapped planNode (i.e. it's handled by DistSQL separately) or reach the leaf nodes.

Note that this bug was further hidden by the fact that if we collect execution stats (which we do for stmt bundles and when the txn is sampled), then we wrap each planNode separately, so in those scenarios the behavior was correct.

Epic: None

Release note (bug fix): Previously, if a mutation was executed in a subquery (e.g. as a CTE), the "rows written" metrics like sql.statements.index_rows_written.count and
sql.statements.index_bytes_written.count might not be incremented correctly. This is now fixed.


Release justification: low-risk observability bug fix.

This commit fixes a bug that was introduced long time ago in
03c09a3. In particular, in that change
we began tracking "rows written" for the purposes of the guardrails, and
later this information was also added into statement statistics as well
as extended to some metrics.

The bug was that we only check the first wrapped `planNode` for being
a `mutationPlanNode`, but it's actually possible for a single
`planNodeToRowSource` wrapper to wrap multiple `planNode`s at once. For
example, if we have a mutation in the CTE, then we could have
`bufferNode -> insertNode -> valuesNode`, all handled by a single
wrapper. Previously, we would only check `bufferNode`, and since it's
not a mutation planNode, we'd emit no "written" metrics.

This commit fixes the issue by traversing the planNode tree until we
either reach the first not-wrapped planNode (i.e. it's handled by
DistSQL separately) or reach the leaf nodes.

Note that this bug was further hidden by the fact that if we collect
execution stats (which we do for stmt bundles and when the txn is
sampled), then we wrap each planNode separately, so in those scenarios
the behavior was correct.

Release note (bug fix): Previously, if a mutation was executed in
a subquery (e.g. as a CTE), the "rows written" metrics like
`sql.statements.index_rows_written.count` and
`sql.statements.index_bytes_written.count` might not be incremented
correctly. This is now fixed.
@blathers-crl blathers-crl Bot added blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. labels Apr 2, 2026
@blathers-crl blathers-crl Bot requested a review from DrewKimball April 2, 2026 19:52
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 2, 2026

Thanks for opening a backport.

Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate.

@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented Apr 2, 2026

😎 Merged successfully - details.

@blathers-crl blathers-crl Bot added backport Label PR's that are backports to older release branches T-sql-queries SQL Queries Team labels Apr 2, 2026
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@yuzefovich yuzefovich requested review from mw5h and removed request for DrewKimball April 2, 2026 20:28
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 8, 2026

Detected infrastructure failure on trunk-merge branch (matched: self-hosted runner lost communication with the server). Please resubmit by commenting /trunk merge. (run link)

@yuzefovich
Copy link
Copy Markdown
Member Author

/trunk merge

@trunk-io trunk-io Bot merged commit 34a6739 into cockroachdb:release-26.1 Apr 8, 2026
21 checks passed
@yuzefovich yuzefovich deleted the blathers/backport-release-26.1-167360 branch April 8, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Label PR's that are backports to older release branches blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. T-sql-queries SQL Queries Team target-release-26.1.4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants