sql,hints: improve EXPLAIN output for statement hints#166330
Open
DrewKimball wants to merge 2 commits intocockroachdb:masterfrom
Open
sql,hints: improve EXPLAIN output for statement hints#166330DrewKimball wants to merge 2 commits intocockroachdb:masterfrom
DrewKimball wants to merge 2 commits intocockroachdb:masterfrom
Conversation
Track runtime hint errors (planning fallbacks, session variable failures, validation errors) on the instrumentation helper so that EXPLAIN output correctly reflects which hints were applied vs skipped. The hint model is refactored from a boolean `Enabled` field to an `Err error` field with sentinel errors for disabled and duplicate hints. Runtime errors are stored separately in a `runtimeHintErrors` map to avoid mutating shared hint state across prepared statement executions. Informs: cockroachdb#163878 Release note (sql change): EXPLAIN and EXPLAIN ANALYZE now display statement hint counts as "applied" versus "skipped" rather than a simple total. Hints that fail at runtime (e.g. referencing a non-existent index or an invalid session variable) are correctly reflected as skipped. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
When EXPLAIN (VERBOSE) or EXPLAIN ANALYZE (VERBOSE) is used with statement hints, emit a tree showing each hint's type, details (donor SQL or variable name/value), and skip reason when applicable. Hints are grouped into "applied" and "skipped" sections. Fixes: cockroachdb#163878 Release note (sql change): EXPLAIN (VERBOSE) and EXPLAIN ANALYZE (VERBOSE) now include a detailed tree of statement hints showing each hint's type, configuration (donor SQL or variable name/value), and skip reason when applicable.
Contributor
|
Merging to
|
Member
ZhouXing19
approved these changes
Mar 20, 2026
Collaborator
ZhouXing19
left a comment
There was a problem hiding this comment.
I only have nit comments, and defer the final stamp to Michael.
@ZhouXing19 reviewed 12 files and all commit messages, and made 4 comments.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on DrewKimball and michae2).
pkg/sql/plan_opt.go line 77 at r1 (raw file):
// Do not return the error. If semantic analysis failed, try preparing again // without injected hints. log.Eventf(ctx, "preparing with injected hints failed with: %v", err)
Should we do p.instrumentation.recordHintError() here as well?
pkg/sql/opt/exec/explain/output.go line 350 at r1 (raw file):
} else { skipped := total - applied ob.AddTopLevelField("statement hints", fmt.Sprintf(
Nice addition!
pkg/sql/opt/exec/execbuilder/testdata/statement_hint_builtins line 2295 at r2 (raw file):
statement ok EXECUTE hint_retry_stmt
nit: might be more informative to run it with EXPLAIN ANALYZE (VERBOSE) EXECUTE.
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.
sql: show applied vs total count for statement hints in EXPLAIN
Track runtime hint errors (planning fallbacks, session variable
failures, validation errors) on the instrumentation helper so that
EXPLAIN output correctly reflects which hints were applied vs skipped.
The hint model is refactored from a boolean
Enabledfield to anErr errorfield with sentinel errors for disabled and duplicatehints. Runtime errors are stored separately in a
runtimeHintErrorsmap to avoid mutating shared hint state across prepared statement
executions.
Informs: #163878
Release note (sql change): EXPLAIN and EXPLAIN ANALYZE now display
statement hint counts as "applied" versus "skipped" rather than a
simple total. Hints that fail at runtime (e.g. referencing a
non-existent index or an invalid session variable) are correctly
reflected as skipped.
Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com
sql: add verbose EXPLAIN output for statement hint details
When EXPLAIN (VERBOSE) or EXPLAIN ANALYZE (VERBOSE) is used with
statement hints, emit a tree showing each hint's type, details (donor
SQL or variable name/value), and skip reason when applicable. Hints
are grouped into "applied" and "skipped" sections.
Fixes: #163878
Release note (sql change): EXPLAIN (VERBOSE) and EXPLAIN ANALYZE
(VERBOSE) now include a detailed tree of statement hints showing
each hint's type, configuration (donor SQL or variable name/value),
and skip reason when applicable.