From 18157452b51f93d2e3a613b9731aff4e094d959b Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Fri, 22 Apr 2022 20:02:49 +0000 Subject: [PATCH] sql: fix "no user specified" errors in statement bundles A regression was introduced in #71246 that caused errors when running internal queries to populate files in statement bundles. As a result, critical information was missing from the `env.sql`, `schema.sql`, and `stats*.sql` files. This commit fixes the issue by using the internal executor factory to create an internal executor with the current session's session data. Fixes #80396 Release note: None --- pkg/sql/explain_bundle_test.go | 27 ++++++++++++++++++--------- pkg/sql/instrumentation.go | 7 +++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/sql/explain_bundle_test.go b/pkg/sql/explain_bundle_test.go index efa0e6d95e35..dceee3f92c33 100644 --- a/pkg/sql/explain_bundle_test.go +++ b/pkg/sql/explain_bundle_test.go @@ -189,16 +189,25 @@ func checkBundle(t *testing.T, text, tableName string, expectedFiles ...string) } files = append(files, f.Name) + r, err := f.Open() + if err != nil { + t.Fatal(err) + } + defer r.Close() + contents, err := ioutil.ReadAll(r) + if err != nil { + t.Fatal(err) + } + + if strings.Contains(string(contents), "-- error") { + t.Errorf( + "expected no errors in %s, file contents:\n%s", + f.Name, + string(contents), + ) + } + if f.Name == "schema.sql" { - r, err := f.Open() - if err != nil { - t.Fatal(err) - } - defer r.Close() - contents, err := ioutil.ReadAll(r) - if err != nil { - t.Fatal(err) - } if !strings.Contains(string(contents), tableName) { t.Errorf( "expected table name to appear in schema.sql. tableName: %s\nfile contents:\n%s", diff --git a/pkg/sql/instrumentation.go b/pkg/sql/instrumentation.go index 7351333f045e..d71f6c36403b 100644 --- a/pkg/sql/instrumentation.go +++ b/pkg/sql/instrumentation.go @@ -321,7 +321,10 @@ func (ih *instrumentationHelper) Finish( var bundle diagnosticsBundle if ih.collectBundle { - ie := p.extendedEvalCtx.ExecCfg.InternalExecutor + ie := p.extendedEvalCtx.ExecCfg.InternalExecutorFactory( + p.EvalContext().Context, + p.SessionData(), + ) phaseTimes := statsCollector.PhaseTimes() if ih.stmtDiagnosticsRecorder.IsExecLatencyConditionMet( ih.diagRequestID, ih.diagRequest, phaseTimes.GetServiceLatencyNoOverhead(), @@ -333,7 +336,7 @@ func (ih *instrumentationHelper) Finish( &queryLevelStats, ) bundle = buildStatementBundle( - ih.origCtx, cfg.DB, ie, &p.curPlan, ob.BuildString(), trace, placeholders, + ih.origCtx, cfg.DB, ie.(*InternalExecutor), &p.curPlan, ob.BuildString(), trace, placeholders, ) bundle.insert(ctx, ih.fingerprint, ast, cfg.StmtDiagnosticsRecorder, ih.diagRequestID) ih.stmtDiagnosticsRecorder.RemoveOngoing(ih.diagRequestID, ih.diagRequest)