Skip to content

Commit 1c74e4d

Browse files
committed
explain: fix decoding plan gist with CALL stmts
Previously we'd hit a nil pointer error when trying to print `Proc` argument when it is `nil`. The problem is that it is stored as `*tree.RoutineExpr`, and `(*tree.RoutineExpr)(nil)` is different from `(tree.TypedExpr)(nil)` that we check for (and short-circuit on) in the `Expr` call. I have an idea for how we could've caught this, but it'll be done in a separate commit. Release note (bug fix): CockroachDB would previously encounter an internal error when decoding plan gists of the plans with CALL statements. The bug has been present since 23.2 version and is now fixed.
1 parent 82e0600 commit 1c74e4d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/sql/opt/exec/execbuilder/testdata/explain_gist

+6
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,9 @@ query T
202202
SELECT crdb_internal.decode_external_plan_gist('Aifvzn5p':::STRING)
203203
----
204204
• create view
205+
206+
# Regression test for hitting an internal error on CALL expressions (#143211).
207+
query T nosort
208+
SELECT crdb_internal.decode_external_plan_gist('Aj0=':::STRING)
209+
----
210+
• call

pkg/sql/opt/exec/explain/emit.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,14 @@ func (e *emitter) emitNodeAttributes(n *Node) error {
10151015

10161016
case callOp:
10171017
a := n.args.(*callArgs)
1018-
ob.Expr("procedure", a.Proc, nil /* columns */)
1018+
if a.Proc != nil {
1019+
// Unlike other expressions, we store Proc as *tree.RoutineExpr, so
1020+
// the nil value in Proc is different from the nil value that is
1021+
// checked in Expr:
1022+
// (*tree.RoutineExpr)(nil) vs (tree.TypedExpr)(nil)
1023+
// so we need an explicit nil check.
1024+
ob.Expr("procedure", a.Proc, nil /* columns */)
1025+
}
10191026

10201027
case simpleProjectOp,
10211028
serializingProjectOp,

0 commit comments

Comments
 (0)