Skip to content

sql: fix TestTrace flake from statement hints spans#166334

Merged
trunk-io[bot] merged 2 commits intocockroachdb:masterfrom
mw5h:fix-testtrace-166212
Mar 24, 2026
Merged

sql: fix TestTrace flake from statement hints spans#166334
trunk-io[bot] merged 2 commits intocockroachdb:masterfrom
mw5h:fix-testtrace-166212

Conversation

@mw5h
Copy link
Copy Markdown
Contributor

@mw5h mw5h commented Mar 20, 2026

Summary

Fixes a flake in TestTrace caused by the statement hints feature introducing
internal query spans that leak into the session trace.

  • Commit 1: Force distsql=off for statement hint queries
    (CheckForStatementHintsInDB, GetStatementHintsFromDB). These are simple
    point lookups that don't need distributed execution.

  • Commit 2: Add get-plan-hints and prepare stmt to the always-optional
    spans list in TestTrace to handle the case where the hints cache rangefeed
    hasn't initialized yet and the internal query runs.

The root cause: before the StatementHintsCache rangefeed initializes
hintedHashes on a node, every statement falls through to querying
system.statement_hints via the internal executor. This internal query was
being distributed (due to ORDER BY with no stats), producing DistSQL spans
(/cockroach.sql.distsqlrun.DistSQL/SetupFlow) that the test didn't expect
when distsql=off.

Fixes #166212

🤖 Generated with Claude Code

mw5h and others added 2 commits March 20, 2026 12:07
Statement hint queries (`CheckForStatementHintsInDB` and
`GetStatementHintsFromDB`) are simple point lookups on
`system.statement_hints` by hash. These should not incur the overhead
of distributed execution. Force `distsql=off` via a session data
override so the internal executor runs them locally.

Previously, when the statement hints cache rangefeed had not yet
initialized on a node, the cache would fall through to querying the
database. On multi-node clusters, the DistSQL planner could decide to
distribute this internal query (e.g. due to `ORDER BY` with no stats),
producing DistSQL-related trace spans that leaked into the session
trace.

Informs cockroachdb#166212

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `get-plan-hints` and `prepare stmt` to the always-optional spans
list in `TestTrace`. Before the statement hints cache rangefeed
initializes, the cache falls through to a database query whose spans
leak into the session trace and cause unexpected span name mismatches.

Fixes cockroachdb#166212

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io bot commented Mar 20, 2026

😎 Merged successfully - details.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@mw5h mw5h added the backport-26.2.x Flags PRs that need to be backported to 26.2 label Mar 20, 2026
@mw5h mw5h marked this pull request as ready for review March 20, 2026 22:00
@mw5h mw5h requested a review from a team as a code owner March 20, 2026 22:00
@mw5h mw5h requested review from DrewKimball, ZhouXing19 and michae2 and removed request for a team March 20, 2026 22:00
Copy link
Copy Markdown
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm: Thanks!

@michae2 reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on DrewKimball and ZhouXing19).

@trunk-io trunk-io bot merged commit 3d4c30f into cockroachdb:master Mar 24, 2026
40 of 41 checks passed
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Mar 24, 2026

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 #166212: branch-release-26.2.


🦉 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-26.2.x Flags PRs that need to be backported to 26.2 target-release-26.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: TestTrace failed

3 participants