Skip to content

Commit

Permalink
Merge #73588
Browse files Browse the repository at this point in the history
73588: cli: bugfixes to debug statement-bundle recreate r=jordanlewis a=jordanlewis

This commit fixes some bugs in the debug statement-bundle recreate
--placeholder command.

1. Some columns don't have a histo_col_type param in the stats, skip
   them
2. Make sure to format string-like datums as bare strings before sending
   as placeholders to the SQL driver, to ensure they can parse.

Release note: None

Co-authored-by: Jordan Lewis <[email protected]>
  • Loading branch information
craig[bot] and jordanlewis committed Dec 10, 2021
2 parents 5509f95 + c64e85d commit 884088d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/cli/statement_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ func getExplainCombinations(
}
evalCtx := tree.MakeTestingEvalContext(cluster.MakeTestingClusterSettings())

fmtCtx := tree.FmtBareStrings

// Map from fully-qualified column name to list of histogram upper_bound
// values with unique bucket attributes.
statsMap := make(map[string][]string)
Expand Down Expand Up @@ -313,9 +315,13 @@ func getExplainCombinations(
statsAge[fqColName] = d.Time

typ := stat["histo_col_type"].(string)
if typ == "" {
fmt.Println("Ignoring column with empty type ", col)
continue
}
colTypeRef, err := parser.GetTypeFromValidSQLSyntax(typ)
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrapf(err, "unable to parse type %s for col %s", typ, col)
}
colType := tree.MustBeStaticallyKnownType(colTypeRef)
buckets := stat["histo_buckets"].([]interface{})
Expand All @@ -332,14 +338,14 @@ func getExplainCombinations(
bucketMap[key] = []string{upperBound}
datum, err := rowenc.ParseDatumStringAs(colType, upperBound, &evalCtx)
if err != nil {
panic(err)
panic("failed parsing datum string as " + datum.String() + " " + err.Error())
}
if maxUpperBound == nil || maxUpperBound.Compare(&evalCtx, datum) < 0 {
maxUpperBound = datum
}
if numRange > 0 {
if prev, ok := datum.Prev(&evalCtx); ok {
bucketMap[key] = append(bucketMap[key], prev.String())
bucketMap[key] = append(bucketMap[key], tree.AsStringWithFlags(prev, fmtCtx))
}
}
}
Expand All @@ -350,7 +356,7 @@ func getExplainCombinations(
// Create a value that's outside of histogram range by incrementing the
// max value that we've seen.
if outside, ok := maxUpperBound.Next(&evalCtx); ok {
colSamples = append(colSamples, outside.String())
colSamples = append(colSamples, tree.AsStringWithFlags(outside, fmtCtx))
}
sort.Strings(colSamples)
statsMap[fqColName] = colSamples
Expand Down

0 comments on commit 884088d

Please sign in to comment.