Skip to content

Commit

Permalink
Merge #89501
Browse files Browse the repository at this point in the history
89501: cli: fix possible crash with debug statement-bundle recreate r=yuzefovich a=yuzefovich

Previously, when using `debug statement-bundle recreate` with
`--placeholder` arguments we could run into an interface conversion
crash if the stats files had a statistic with no `histo_buckets`
attribute. Such situation can occur when the table was empty when those
stats were collected or the column only had NULL values, and the crash
is now fixed.

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed Oct 6, 2022
2 parents 06d3121 + 210c5dd commit b198140
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/cli/statement_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ func getExplainCombinations(
return nil, nil, errors.Wrapf(err, "unable to parse type %s for col %s", typ, col)
}
colType := tree.MustBeStaticallyKnownType(colTypeRef)
if stat["histo_buckets"] == nil {
// There might not be any histogram buckets if the stats were
// collected when the table was empty or all values in the
// column were NULL.
continue
}
buckets := stat["histo_buckets"].([]interface{})
var maxUpperBound tree.Datum
for _, b := range buckets {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
ALTER TABLE public.a INJECT STATISTICS '[
{
"columns": [
"b"
],
"created_at": "2021-06-23 21:17:16.83267",
"distinct_count": 0,
"histo_col_type": "INT8",
"name": "__auto__",
"null_count": 0,
"row_count": 0
},
{
"columns": [
"b"
],
"created_at": "2021-06-23 22:17:16.83267",
"distinct_count": 0,
"histo_col_type": "INT8",
"name": "__auto__",
"null_count": 100,
"row_count": 100
},
{
"columns": [
"a"
Expand Down

0 comments on commit b198140

Please sign in to comment.