Skip to content

Commit

Permalink
Merge #109044
Browse files Browse the repository at this point in the history
109044: sqlstats: ignore EXPLAIN stmts on insights r=maryliag a=maryliag

Previously, it was possible to get Insights for a `EXPLAIN` statement, which didn't make sense.
This commit adds `EXPLAIN` to the list of statement types to be ignored during insights detection.

Fixes #88366

Release note: None

Co-authored-by: maryliag <[email protected]>
  • Loading branch information
craig[bot] and maryliag committed Aug 19, 2023
2 parents 9bb614c + d0f8f93 commit 9fcc5c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/sqlstats/insights/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func isFailed(s *Statement) bool {
return s.Status == Statement_Failed
}

var prefixesToIgnore = []string{"SET "}
var prefixesToIgnore = []string{"SET ", "EXPLAIN "}

// shouldIgnoreStatement returns true if we don't want to analyze the statement.
func shouldIgnoreStatement(s *Statement) bool {
Expand Down
14 changes: 11 additions & 3 deletions pkg/sql/sqlstats/insights/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,26 @@ func TestRegistry(t *testing.T) {
LatencyInSeconds: 2,
Query: "SELECT * FROM users",
}
statementIgnored := &Statement{
statementIgnoredSet := &Statement{
ID: clusterunique.IDFromBytes([]byte("dddddddddddddddddddddddddddddddd")),
FingerprintID: appstatspb.StmtFingerprintID(101),
LatencyInSeconds: 2,
Query: "SET vectorize = '_'",
}
statementIgnoredExplain := &Statement{
ID: clusterunique.IDFromBytes([]byte("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")),
FingerprintID: appstatspb.StmtFingerprintID(102),
LatencyInSeconds: 2,
Query: "EXPLAIN SELECT * FROM users",
}

st := cluster.MakeTestingClusterSettings()
LatencyThreshold.Override(ctx, &st.SV, 1*time.Second)
store := newStore(st)
registry := newRegistry(st, &latencyThresholdDetector{st: st}, store)
registry.ObserveStatement(session.ID, statementNotIgnored)
registry.ObserveStatement(session.ID, statementIgnored)
registry.ObserveStatement(session.ID, statementIgnoredSet)
registry.ObserveStatement(session.ID, statementIgnoredExplain)
registry.ObserveTransaction(session.ID, transaction)

expected := []*Insight{
Expand All @@ -336,7 +343,8 @@ func TestRegistry(t *testing.T) {
Transaction: transaction,
Statements: []*Statement{
newStmtWithProblemAndCauses(statementNotIgnored, Problem_SlowExecution, nil),
statementIgnored,
statementIgnoredSet,
statementIgnoredExplain,
},
},
}
Expand Down

0 comments on commit 9fcc5c8

Please sign in to comment.