Skip to content

Commit

Permalink
sql: add plan gist to sampled query telemetry log
Browse files Browse the repository at this point in the history
Partially resolves: #71328

This change adds a plan gist field to the sampled query telemetry log.
The plan gist is written as a base64 encoded string.

Release note (sql change): The sampled query telemetry log now includes
a plan gist field. The plan gist field provides a compact representation
of a logical plan for the sampled query, the field is written as a
base64 encoded string.
  • Loading branch information
Thomas Hardy committed Jun 17, 2022
1 parent 2d4acbc commit 30b6d2f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,7 @@ contains common SQL event/execution details.
| `SkippedQueries` | skipped_queries indicate how many SQL statements were not considered for sampling prior to this one. If the field is omitted, or its value is zero, this indicates that no statement was omitted since the last event. | no |
| `CostEstimate` | Cost of the query as estimated by the optimizer. | no |
| `Distribution` | The distribution of the DistSQL query plan (local, full, or partial). | no |
| `PlanGist` | The query's plan gist bytes as a base64 encoded string. | no |


#### Common fields
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/exec_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func (p *planner) maybeLogStatementInternal(
SkippedQueries: skippedQueries,
CostEstimate: p.curPlan.instrumentation.costEstimate,
Distribution: p.curPlan.instrumentation.distribution.String(),
PlanGist: p.curPlan.instrumentation.planGist.String(),
}})
} else {
telemetryMetrics.incSkippedQueryCount()
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/telemetry_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ func TestTelemetryLogging(t *testing.T) {
if !distRe.MatchString(e.Message) {
t.Errorf("expected to find Distribution but none was found")
}
// Match plan gist on any non-empty string value.
planGist := regexp.MustCompile("\"PlanGist\":(\"\\S+\")")
if !planGist.MatchString(e.Message) {
t.Errorf("expected to find PlanGist but none was found in: %s", e.Message)
}
for _, eTag := range tc.expectedUnredactedTags {
for _, tag := range strings.Split(e.Tags, ",") {
kv := strings.Split(tag, "=")
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/log/eventpb/json_encode_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/util/log/eventpb/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ message SampledQuery {

// The distribution of the DistSQL query plan (local, full, or partial).
string distribution = 6 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""];

// The query's plan gist bytes as a base64 encoded string.
string plan_gist = 7 [(gogoproto.jsontag) = ',omitempty', (gogoproto.moretags) = "redact:\"nonsensitive\""];
}

// CapturedIndexUsageStats
Expand Down

0 comments on commit 30b6d2f

Please sign in to comment.