Skip to content

Commit

Permalink
Merge pull request #95079 from yuzefovich/backport22.2-94949
Browse files Browse the repository at this point in the history
release-22.2: sql: propagate the settings properly into the stmt bundle builder
  • Loading branch information
yuzefovich authored Jan 11, 2023
2 parents e535ace + efdaece commit 9108927
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions pkg/sql/explain_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ func buildStatementBundle(
trace tracingpb.Recording,
placeholders *tree.PlaceholderInfo,
queryErr, payloadErr, commErr error,
sv *settings.Values,
) diagnosticsBundle {
if plan == nil {
return diagnosticsBundle{collectionErr: errors.AssertionFailedf("execution terminated early")}
}
b := makeStmtBundleBuilder(db, ie, stmtRawSQL, plan, trace, placeholders)
b := makeStmtBundleBuilder(db, ie, stmtRawSQL, plan, trace, placeholders, sv)

b.addStatement()
b.addOptPlans()
Expand Down Expand Up @@ -194,6 +195,7 @@ type stmtBundleBuilder struct {
plan *planTop
trace tracingpb.Recording
placeholders *tree.PlaceholderInfo
sv *settings.Values

z memzipper.Zipper
}
Expand All @@ -205,9 +207,10 @@ func makeStmtBundleBuilder(
plan *planTop,
trace tracingpb.Recording,
placeholders *tree.PlaceholderInfo,
sv *settings.Values,
) stmtBundleBuilder {
b := stmtBundleBuilder{
db: db, ie: ie, stmt: stmt, plan: plan, trace: trace, placeholders: placeholders,
db: db, ie: ie, stmt: stmt, plan: plan, trace: trace, placeholders: placeholders, sv: sv,
}
b.buildPrettyStatement()
b.z.Init()
Expand Down Expand Up @@ -364,7 +367,7 @@ func (b *stmtBundleBuilder) addEnv(ctx context.Context) {
fmt.Fprintf(&buf, "\n")

// Show the values of session variables that can impact planning decisions.
if err := c.PrintSessionSettings(&buf); err != nil {
if err := c.PrintSessionSettings(&buf, b.sv); err != nil {
fmt.Fprintf(&buf, "-- error getting session settings: %v\n", err)
}

Expand Down Expand Up @@ -565,7 +568,7 @@ func (c *stmtEnvCollector) PrintVersion(w io.Writer) error {

// PrintSessionSettings appends information about session settings that can
// impact planning decisions.
func (c *stmtEnvCollector) PrintSessionSettings(w io.Writer) error {
func (c *stmtEnvCollector) PrintSessionSettings(w io.Writer, sv *settings.Values) error {
// Cluster setting encoded default value to session setting value conversion
// functions.
boolToOnOff := func(boolStr string) string {
Expand Down Expand Up @@ -666,7 +669,7 @@ func (c *stmtEnvCollector) PrintSessionSettings(w io.Writer) error {
if s.clusterSetting == nil {
if ok, v, _ := getSessionVar(s.sessionSetting, true); ok {
if v.GlobalDefault != nil {
def = v.GlobalDefault(nil /* *settings.Values */)
def = v.GlobalDefault(sv)
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (ih *instrumentationHelper) Finish(
}
bundle = buildStatementBundle(
ih.origCtx, cfg.DB, ie.(*InternalExecutor), stmtRawSQL, &p.curPlan, ob.BuildString(), trace,
placeholders, res.Err(), payloadErr, retErr,
placeholders, res.Err(), payloadErr, retErr, &p.extendedEvalCtx.Settings.SV,
)
bundle.insert(
ctx, ih.fingerprint, ast, cfg.StmtDiagnosticsRecorder, ih.diagRequestID, ih.diagRequest,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt_exec_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ func (ef *execFactory) showEnv(plan string, envOpts exec.ExplainEnvData) (exec.N
out.writef("")
// Show the values of any non-default session variables that can impact
// planning decisions.
if err := c.PrintSessionSettings(&out.buf); err != nil {
if err := c.PrintSessionSettings(&out.buf, &ef.planner.extendedEvalCtx.Settings.SV); err != nil {
return nil, err
}

Expand Down

0 comments on commit 9108927

Please sign in to comment.