From b013a6268c7dcd461251d7a2889d2c240ac9791c Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Mon, 16 Nov 2020 13:51:49 -0800 Subject: [PATCH] sql: fix panic when getting support bundle Check for nil `plan.stmt` and AST when finishing the support bundle. Fixes #56705. Release note (bug fix): fixed internal error when collecting a statement diagnostic bundle in some cases where the query hits an error. --- pkg/sql/explain_bundle.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/sql/explain_bundle.go b/pkg/sql/explain_bundle.go index a03beb6a98f1..2ef5b89ff868 100644 --- a/pkg/sql/explain_bundle.go +++ b/pkg/sql/explain_bundle.go @@ -214,7 +214,16 @@ func (b *stmtBundleBuilder) addStatement() { cfg.Simplify = true cfg.Align = tree.PrettyNoAlign cfg.JSONFmt = true - output := cfg.Pretty(b.plan.stmt.AST) + var output string + // If we hit an early error, stmt or stmt.AST might not be initialized yet. + switch { + case b.plan.stmt == nil: + output = "No Statement." + case b.plan.stmt.AST == nil: + output = "No AST." + default: + output = cfg.Pretty(b.plan.stmt.AST) + } if b.placeholders != nil && len(b.placeholders.Values) != 0 { var buf bytes.Buffer