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 6, 2022
1 parent f0372fd commit 80c9d78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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
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,7 @@ function renderExplainPlan(
plan: PlanHashStats,
backToPlanTable: () => void,
): React.ReactElement {
let explainPlan = plan.explain_plan === "" ? "unavailable" : plan.explain_plan;
return (
<div>
<Helmet title="Plan Details" />
Expand All @@ -70,7 +71,7 @@ function renderExplainPlan(
>
All Plans
</Button>
<SqlBox value={plan.explain_plan} size={SqlBoxSize.large} />
<SqlBox value={explainPlan} size={SqlBoxSize.large} />;
</div>
);
}

0 comments on commit 80c9d78

Please sign in to comment.