Skip to content

sql: display retry count and time for EXPLAIN ANALYZE#142692

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:explain-retries
Mar 14, 2025
Merged

sql: display retry count and time for EXPLAIN ANALYZE#142692
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:explain-retries

Conversation

@DrewKimball
Copy link
Copy Markdown
Collaborator

This commit adds two new top-level fields to the plan output of EXPLAIN ANALYZE displaying the number of transaction retries and cumulative time spent due to the retries. This will help make retries more visible when debugging poor performance via statement bundle.

Fixes #142674

Release note (sql change): EXPLAIN ANALYZE statements now display the number of transaction retries and time spent retrying as part of the plan output.

@DrewKimball DrewKimball requested a review from Copilot March 11, 2025 21:38
@DrewKimball DrewKimball requested a review from a team as a code owner March 11, 2025 21:38
@DrewKimball DrewKimball requested review from rytaft and removed request for a team March 11, 2025 21:38
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds two new top-level fields to the output of EXPLAIN ANALYZE to display the number of transaction retries and the cumulative time spent retrying, making retries more visible during performance debugging. Key changes include:

  • Adding AddRetryCount and AddRetryTime methods to the OutputBuilder.
  • Updating instrumentation logic to record and pass retry count/time.
  • Enhancing tests in output_test.go to verify the new fields, and updating connection executor calls to pass the retry counter.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/sql/opt/exec/explain/output_test.go Added a new test (TestRetryFields) validating retry field output
pkg/sql/opt/exec/explain/output.go Introduced AddRetryCount and AddRetryTime functions
pkg/sql/instrumentation.go Updated instrumentation to capture and emit retry fields
pkg/sql/conn_executor_exec.go Modified function arguments to include autoRetryCounter

Comment on lines +365 to +368
if matches := retryCountRE.FindStringSubmatch(res); len(matches) == 0 {
foundCount = true
}
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) == 0 {
Copy link

Copilot AI Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears the condition is inverted; to verify that the retry count field is present, the check should verify that matches length is greater than 0 (i.e., len(matches) > 0) rather than equal to 0.

Suggested change
if matches := retryCountRE.FindStringSubmatch(res); len(matches) == 0 {
foundCount = true
}
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) == 0 {
if matches := retryCountRE.FindStringSubmatch(res); len(matches) > 0 {
foundCount = true
}
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) > 0 {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think copilot is right 😃

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

if matches := retryCountRE.FindStringSubmatch(res); len(matches) == 0 {
foundCount = true
}
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) == 0 {
Copy link

Copilot AI Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, the condition should check for matches length greater than 0 to correctly detect the presence of the retry time field.

Suggested change
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) == 0 {
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) > 0 {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :lgtm: Let's backport this too.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @copilot-pull-request-reviewer[bot], @DrewKimball, and @rytaft)


-- commits line 12 at r1:
nit: consider mentioning that these fields are only shown when non-zero.


pkg/sql/conn_executor_exec.go line 557 at r1 (raw file):

		&stmt, os.ImplicitTxn.Get(),
		// This goroutine is the only one that can modify
		// txnState.mu.priority, so we don't need to get a mutex here.

nit: adjust the comment to mention autoRetryCounter too.

Comment on lines +365 to +368
if matches := retryCountRE.FindStringSubmatch(res); len(matches) == 0 {
foundCount = true
}
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) == 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think copilot is right 😃

This commit adds two new top-level fields to the plan output of
`EXPLAIN ANALYZE` displaying the number of transaction retries and
cumulative time spent due to the retries. This will help make retries
more visible when debugging poor performance via statement bundle.

Fixes cockroachdb#142674

Release note (sql change): EXPLAIN ANALYZE statements now display the
number of transaction retries and time spent retrying as part of the
plan output, if non-zero.
Copy link
Copy Markdown
Collaborator Author

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @copilot-pull-request-reviewer[bot] and @rytaft)


-- commits line 12 at r1:

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: consider mentioning that these fields are only shown when non-zero.

Done.


pkg/sql/conn_executor_exec.go line 557 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: adjust the comment to mention autoRetryCounter too.

Done.

if matches := retryCountRE.FindStringSubmatch(res); len(matches) == 0 {
foundCount = true
}
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) == 0 {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@DrewKimball DrewKimball added backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.1.x labels Mar 14, 2025
@DrewKimball
Copy link
Copy Markdown
Collaborator Author

TFTR!

bors r=yuzefovich

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 14, 2025

@craig craig bot merged commit 76ca78c into cockroachdb:master Mar 14, 2025
23 of 24 checks passed
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Mar 14, 2025

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #142674: branch-release-24.1, branch-release-24.3, branch-release-25.1.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Mar 14, 2025

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 805d6dc to blathers/backport-release-24.1-142692: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 24.1.x failed. See errors above.


error creating merge commit from 805d6dc to blathers/backport-release-24.3-142692: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 24.3.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.3.x Flags PRs that need to be backported to 24.3 backport-failed v25.2.0-prerelease

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: indicate that the statement was retried in statement bundles

4 participants