Skip to content

Commit

Permalink
sql: fix "no user specified" errors in statement bundles
Browse files Browse the repository at this point in the history
A regression was introduced in cockroachdb#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 cockroachdb#80396

Release note: None
  • Loading branch information
mgartner committed Apr 22, 2022
1 parent 2f8938f commit aec2c44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
27 changes: 18 additions & 9 deletions pkg/sql/explain_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions pkg/sql/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,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(),
Expand All @@ -334,7 +337,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)
Expand Down

0 comments on commit aec2c44

Please sign in to comment.