diff --git a/pkg/sql/opt/exec/execbuilder/testdata/explain_gist b/pkg/sql/opt/exec/execbuilder/testdata/explain_gist index 0aaf5aa0d65d..8da59387f74b 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/explain_gist +++ b/pkg/sql/opt/exec/execbuilder/testdata/explain_gist @@ -171,3 +171,21 @@ SELECT crdb_internal.decode_plan_gist('AgGSARIAAwlAsJ8BE5IBAhcGFg==') table: ?@? spans: 1+ spans limit + +# Regression test for #108979. Correctly decode inverted filters. +query T nosort +SELECT crdb_internal.decode_plan_gist('AgGwAgQAgQIAAgAEBQITsAICAxgGDA==') +---- +• top-k +│ order +│ +└── • filter + │ + └── • index join + │ table: ?@? + │ + └── • inverted filter + │ + └── • scan + table: ?@? + spans: 1+ spans diff --git a/pkg/sql/opt/exec/explain/emit.go b/pkg/sql/opt/exec/explain/emit.go index 6702102c13da..b24520ed5194 100644 --- a/pkg/sql/opt/exec/explain/emit.go +++ b/pkg/sql/opt/exec/explain/emit.go @@ -780,8 +780,12 @@ func (e *emitter) emitNodeAttributes(n *Node) error { case invertedFilterOp: a := n.args.(*invertedFilterArgs) - ob.Attr("inverted column", a.Input.Columns()[a.InvColumn].Name) - ob.Attr("num spans", len(a.InvFilter.SpansToRead)) + if a.InvColumn != 0 { + ob.Attr("inverted column", a.Input.Columns()[a.InvColumn].Name) + } + if a.InvFilter != nil && len(a.InvFilter.SpansToRead) > 0 { + ob.Attr("num spans", len(a.InvFilter.SpansToRead)) + } case invertedJoinOp: a := n.args.(*invertedJoinArgs)