diff --git a/pkg/cli/statement_bundle.go b/pkg/cli/statement_bundle.go index e82fc64fd62f..837c602d12ab 100644 --- a/pkg/cli/statement_bundle.go +++ b/pkg/cli/statement_bundle.go @@ -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 { diff --git a/pkg/cli/testdata/explain-bundle/bundle/stats-defaultdb.public.a.sql b/pkg/cli/testdata/explain-bundle/bundle/stats-defaultdb.public.a.sql index a4c7c0edc552..1476ec8f908c 100644 --- a/pkg/cli/testdata/explain-bundle/bundle/stats-defaultdb.public.a.sql +++ b/pkg/cli/testdata/explain-bundle/bundle/stats-defaultdb.public.a.sql @@ -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"