sql: fix "rows written" metrics#167360
Merged
trunk-io[bot] merged 1 commit intocockroachdb:masterfrom Apr 2, 2026
Merged
Conversation
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.
Contributor
|
😎 Merged successfully - details. |
Member
DrewKimball
approved these changes
Apr 2, 2026
Collaborator
DrewKimball
left a comment
There was a problem hiding this comment.
@DrewKimball reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on yuzefovich).
Member
Author
|
TFTR! /trunk merge |
This was referenced Apr 2, 2026
|
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. merge conflict cherry-picking 684c04f to blathers/backport-release-25.4-167360 Backport to branch 25.4.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
planNodefor being amutationPlanNode, but it's actually possible for a singleplanNodeToRowSourcewrapper to wrap multipleplanNodes at once. For example, if we have a mutation in the CTE, then we could havebufferNode -> insertNode -> valuesNode, all handled by a single wrapper. Previously, we would only checkbufferNode, 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.countandsql.statements.index_bytes_written.countmight not be incremented correctly. This is now fixed.