Skip to content

Commit c70da75

Browse files
michae2DrewKimball
authored andcommitted
sql: fix hint injection for EXPLAIN ANALYZE
Fixes: #161264 Release note (bug fix): Fix a bug in which inline-hints rewrite rules created with `information_schema.crdb_rewrite_inline_hints` were not correctly applied to statements run with `EXPLAIN ANALYZE`. This bug was introduced in version v26.1.0-alpha.2 and is now fixed.
1 parent 5e5112d commit c70da75

File tree

3 files changed

+845
-14
lines changed

3 files changed

+845
-14
lines changed

pkg/sql/conn_executor_exec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ func (ex *connExecutor) execStmtInOpenState(
531531
// Strip off the explain node to execute the inner statement.
532532
stmt.AST = e.Statement
533533
ast = e.Statement
534+
if e2, ok := stmt.ASTWithInjectedHints.(*tree.ExplainAnalyze); ok {
535+
stmt.ASTWithInjectedHints = e2.Statement
536+
}
534537
// TODO(radu): should we trim the "EXPLAIN ANALYZE (DEBUG)" part from
535538
// stmt.SQL?
536539

@@ -1433,6 +1436,9 @@ func (ex *connExecutor) execStmtInOpenStateWithPausablePortal(
14331436
// Strip off the explain node to execute the inner statement.
14341437
vars.stmt.AST = e.Statement
14351438
vars.ast = e.Statement
1439+
if e2, ok := vars.stmt.ASTWithInjectedHints.(*tree.ExplainAnalyze); ok {
1440+
vars.stmt.ASTWithInjectedHints = e2.Statement
1441+
}
14361442
// TODO(radu): should we trim the "EXPLAIN ANALYZE (DEBUG)" part from
14371443
// stmt.SQL?
14381444

0 commit comments

Comments
 (0)