Skip to content

Commit

Permalink
server, ui: handle null plan gist in getStatementDetailsPerPlanHash
Browse files Browse the repository at this point in the history
This commit adds a new function that handles null plan gists in
`getStatementDetailsPerPlanHash`. The commit also adds some logic
to hide null plan gists in the Statement Details page.

Fixes #82095.

For more details, see #82095 (comment).

Release note: None
  • Loading branch information
ericharmeling committed Jun 4, 2022
1 parent 0312440 commit 3ef327d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 0 additions & 1 deletion docs/generated/redact_safe.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pkg/streaming/api.go | `StreamID`
pkg/util/hlc/timestamp.go | `ClockTimestamp`
pkg/util/hlc/timestamp.go | `LegacyTimestamp`
pkg/util/hlc/timestamp.go | `Timestamp`
vendor/github.com/cockroachdb/pebble/internal/humanize/humanize.go | `FormattedString`
pkg/util/log/redact.go | `reflect.TypeOf(123)`
pkg/util/log/redact.go | `reflect.TypeOf(Channel(0))`
pkg/util/log/redact.go | `reflect.TypeOf(complex128(0))`
Expand Down
7 changes: 5 additions & 2 deletions pkg/server/combined_statement_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,11 @@ func getStatementDetailsPerPlanHash(
if planHash, err = sqlstatsutil.DatumToUint64(row[0]); err != nil {
return nil, serverError(ctx, err)
}
planGist := string(tree.MustBeDString(row[1]))
explainPlan := getExplainPlanFromGist(ctx, ie, planGist)
planGist := string(tree.MustBeDStringOrDNull(row[1]))
var explainPlan string
if planGist != "" {
explainPlan = getExplainPlanFromGist(ctx, ie, planGist)
}

var metadata roachpb.CollectedStatementStatistics
var aggregatedMetadata roachpb.AggregatedStatementMetadata
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sem/tree/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ go_library(
"//pkg/util/timeutil/pgdate",
"//pkg/util/uint128",
"//pkg/util/uuid",
"@com_github_cockroachdb_apd//:apd",
"@com_github_cockroachdb_apd_v3//:apd",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact",
Expand Down
12 changes: 11 additions & 1 deletion pkg/sql/sem/tree/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"unicode/utf8"
"unsafe"

"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/apd"
"github.com/cockroachdb/cockroach/pkg/geo"
"github.com/cockroachdb/cockroach/pkg/sql/lex"
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
Expand Down Expand Up @@ -1220,6 +1220,16 @@ func MustBeDString(e Expr) DString {
return i
}

// MustBeDStringOrDNull attempts to retrieve a DString or DNull from an Expr, panicking if the
// assertion fails.
func MustBeDStringOrDNull(e Expr) DString {
i, ok := AsDString(e)
if !ok && e != DNull {
panic(errors.AssertionFailedf("expected *DString or DNull, found %T", e))
}
return i
}

// ResolvedType implements the TypedExpr interface.
func (*DString) ResolvedType() *types.T {
return types.String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ function renderExplainPlan(
plan: PlanHashStats,
backToPlanTable: () => void,
): React.ReactElement {
let planBox;
if (plan.explain_plan === "") {
planBox = <SqlBox value={"unavailable"} />;
} else {
planBox = <SqlBox value={plan.explain_plan} size={SqlBoxSize.large} />;
}
return (
<div>
<Helmet title="Plan Details" />
Expand All @@ -70,7 +76,7 @@ function renderExplainPlan(
>
All Plans
</Button>
<SqlBox value={plan.explain_plan} size={SqlBoxSize.large} />
{planBox}
</div>
);
}

0 comments on commit 3ef327d

Please sign in to comment.