Skip to content

Commit

Permalink
opt: fix plan gist decoding of inverted filters
Browse files Browse the repository at this point in the history
Details about inverted filter nodes are not encoded in plan gists. The
explain emitter assumed there were always some details encoded, and
would raise an internal error whenever decoding a plan gist with an
inverted filter. This commit prevents the internal error from occurring.

Fixes #108979

There is no release not because plan gists are an undocumented feature.

Release note: None
  • Loading branch information
mgartner committed Aug 29, 2023
1 parent c1f529b commit 60c5154
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/explain_gist
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions pkg/sql/opt/exec/explain/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 60c5154

Please sign in to comment.