Skip to content

Commit 1d578a3

Browse files
committed
ui: show whether statement hints were applied in DB console
This commit adds a field to the "plan details" shown for statements in the "statement activity" page of the DB console. The new field indicates whether any statement hints from `system.statement_hints` were applied to the statement. Informs #121502 Release note (sql change): Plan details in the "statement activity" page of the DB console now show whether any hints from `system.statement_hints` werer applied to the statement execution.
1 parent a4e6a42 commit 1d578a3

File tree

13 files changed

+43
-0
lines changed

13 files changed

+43
-0
lines changed

pkg/sql/appstatspb/app_stats.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func (s *StatementStatistics) Add(other *StatementStatistics) {
214214
s.Count += other.Count
215215
s.FailureCount += other.FailureCount
216216
s.GenericCount += other.GenericCount
217+
s.StmtHintsCount += other.StmtHintsCount
217218
}
218219

219220
// AlmostEqual compares two StatementStatistics and their contained NumericStats

pkg/sql/appstatspb/app_stats.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ message StatementStatistics {
138138
// generic_count is the count of executions that used a generic query plan.
139139
optional int64 generic_count = 36 [(gogoproto.nullable) = false];
140140

141+
// stmt_hints_count is the count of executions that applied a hint from the
142+
// system.statement_hints table.
143+
optional int64 stmt_hints_count = 37 [(gogoproto.nullable) = false];
144+
141145
// Note: be sure to update `sql/app_stats.go` when adding/removing fields here!
142146

143147
reserved 13, 14, 17, 18, 19, 20;

pkg/sql/executor_statement_metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func (ex *connExecutor) recordStatementSummary(
225225
FingerprintID: stmtFingerprintID,
226226
QuerySummary: stmt.StmtSummary,
227227
Generic: flags.IsSet(planFlagGeneric),
228+
AppliedStmtHints: len(stmt.Hints) > 0,
228229
DistSQL: flags.ShouldBeDistributed(),
229230
Vec: flags.IsSet(planFlagVectorized),
230231
ImplicitTxn: implicitTxn,

pkg/sql/sqlstats/persistedsqlstats/sqlstatsutil/json_encoding_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestSQLStatsJsonEncoding(t *testing.T) {
5454
"firstAttemptCnt": {{.Int64}},
5555
"failureCount": {{.Int64}},
5656
"genericCount": {{.Int64}},
57+
"stmtHintsCount": {{.Int64}},
5758
"maxRetries": {{.Int64}},
5859
"lastExecAt": "{{stringifyTime .Time}}",
5960
"numRows": {

pkg/sql/sqlstats/persistedsqlstats/sqlstatsutil/json_impl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ func (s *innerStmtStats) jsonFields() jsonFields {
345345
{"lastErrorCode", (*jsonString)(&s.LastErrorCode)},
346346
{"failureCount", (*jsonInt)(&s.FailureCount)},
347347
{"genericCount", (*jsonInt)(&s.GenericCount)},
348+
{"stmtHintsCount", (*jsonInt)(&s.StmtHintsCount)},
348349
{"sqlType", (*jsonString)(&s.SQLType)},
349350
}
350351
}

pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func (s *Container) RecordStatement(ctx context.Context, value *sqlstats.Recorde
8080
if value.Generic {
8181
stats.mu.data.GenericCount++
8282
}
83+
if value.AppliedStmtHints {
84+
stats.mu.data.StmtHintsCount++
85+
}
8386
if value.AutoRetryCount == 0 {
8487
stats.mu.data.FirstAttemptCount++
8588
} else if int64(value.AutoRetryCount) > stats.mu.data.MaxRetries {

pkg/sql/sqlstats/ssmemstorage/ss_mem_writer_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func TestContainer_Add(t *testing.T) {
119119
RowsWritten: 5,
120120
Failed: true,
121121
Generic: true,
122+
AppliedStmtHints: true,
122123
StatementError: errors.New("test error"),
123124
}
124125
require.NoError(t, src.RecordStatement(ctx, stmtStats))
@@ -161,6 +162,7 @@ func TestContainer_Add(t *testing.T) {
161162
RowsWritten: 80,
162163
Failed: true,
163164
Generic: true,
165+
AppliedStmtHints: true,
164166
StatementError: errors.New("test error"),
165167
}
166168
reducedTxnFingerprintID := appstatspb.TransactionFingerprintID(321)
@@ -208,6 +210,7 @@ func verifyStmtStatsMultiple(
208210
require.Equal(t, destStmtStats.mu.data.Count, int64(count))
209211
require.Equal(t, destStmtStats.mu.data.FailureCount, int64(count))
210212
require.Equal(t, destStmtStats.mu.data.GenericCount, int64(count))
213+
require.Equal(t, destStmtStats.mu.data.StmtHintsCount, int64(count))
211214
require.InEpsilon(t, float64(stmtStats.RowsAffected), destStmtStats.mu.data.NumRows.Mean, epsilon)
212215
require.InEpsilon(t, float64(stmtStats.RowsAffected), destStmtStats.mu.data.NumRows.Mean, epsilon)
213216
require.InEpsilon(t, stmtStats.IdleLatencySec, destStmtStats.mu.data.IdleLat.Mean, epsilon)

pkg/sql/sqlstats/ssprovider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type RecordedStmtStats struct {
7171
AutoRetryCount int
7272
Failed bool
7373
Generic bool
74+
AppliedStmtHints bool
7475
AutoRetryReason error
7576
RowsAffected int
7677
IdleLatencySec float64

pkg/ui/workspaces/cluster-ui/src/statementDetails/planDetails/planDetails.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ function ExplainPlan({
193193
label="Generic Query Plan"
194194
value={RenderCount(plan.stats.generic_count, plan.stats.count)}
195195
/>
196+
<SummaryCardItem
197+
label="Statement Hints"
198+
value={RenderCount(plan.stats.stmt_hints_count, plan.stats.count)}
199+
/>
196200
<SummaryCardItem
197201
label="Distributed"
198202
value={RenderCount(

pkg/ui/workspaces/cluster-ui/src/statementDetails/planDetails/plansTable.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const planDetailsColumnLabels = {
3333
avgExecTime: "Average Execution Time",
3434
avgRowsRead: "Average Rows Read",
3535
generic: "Generic Query Plan",
36+
stmtHints: "Statement Hints",
3637
distSQL: "Distributed",
3738
execCount: "Execution Count",
3839
fullScan: "Full Scan",
@@ -163,6 +164,17 @@ export const planDetailsTableTitles: PlanDetailsTableTitleType = {
163164
</Tooltip>
164165
);
165166
},
167+
stmtHints: () => {
168+
return (
169+
<Tooltip
170+
style="tableTitle"
171+
placement="bottom"
172+
content={"If hints from statement_hints were applied."}
173+
>
174+
{planDetailsColumnLabels.stmtHints}
175+
</Tooltip>
176+
);
177+
},
166178
distSQL: () => {
167179
return (
168180
<Tooltip
@@ -380,6 +392,14 @@ export function makeExplainPlanColumns(
380392
sort: (item: PlanHashStats) =>
381393
RenderCount(item.stats.generic_count, item.stats.count),
382394
},
395+
{
396+
name: "stmtHints",
397+
title: planDetailsTableTitles.stmtHints(),
398+
cell: (item: PlanHashStats) =>
399+
RenderCount(item.stats.stmt_hints_count, item.stats.count),
400+
sort: (item: PlanHashStats) =>
401+
RenderCount(item.stats.stmt_hints_count, item.stats.count),
402+
},
383403
{
384404
name: "distSQL",
385405
title: planDetailsTableTitles.distSQL(),

0 commit comments

Comments
 (0)