Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: fix performance regression due to increased hash allocations #55214

Merged
merged 2 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/generated/http/full.md
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ information about the resources on a node used by that table.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| key | [StatementsResponse.ExtendedStatementStatisticsKey](#cockroach.server.serverpb.StatementsResponse-cockroach.server.serverpb.StatementsResponse.ExtendedStatementStatisticsKey) | | |
| id | [string](#cockroach.server.serverpb.StatementsResponse-string) | | |
| id | [uint64](#cockroach.server.serverpb.StatementsResponse-uint64) | | |
| stats | [cockroach.sql.StatementStatistics](#cockroach.server.serverpb.StatementsResponse-cockroach.sql.StatementStatistics) | | |


Expand Down
22 changes: 14 additions & 8 deletions pkg/roachpb/app_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,34 @@
package roachpb

import (
"fmt"
"hash/fnv"
"math"

"github.com/cockroachdb/cockroach/pkg/util"
)

// StmtID is the type of a Statement ID.
type StmtID string
type StmtID uint64

// ConstructStatementID constructs an ID by hashing an anonymized query, it's
// failure status, and if it was part of an implicit txn. At the time of writing,
// these are the axis' we use to bucket queries for stats collection
// (see stmtKey).
func ConstructStatementID(anonymizedStmt string, failed bool, implicitTxn bool) StmtID {
h := fnv.New128()
h.Write([]byte(anonymizedStmt))
fnv := util.MakeFNV64()
for _, c := range anonymizedStmt {
fnv.Add(uint64(c))
}
if failed {
h.Write([]byte("failed"))
fnv.Add('F')
} else {
fnv.Add('S')
}
if implicitTxn {
h.Write([]byte("implicit_txn"))
fnv.Add('I')
} else {
fnv.Add('E')
}
return StmtID(fmt.Sprintf("%x", h.Sum(nil)))
return StmtID(fnv.Sum())
}

// GetVariance retrieves the variance of the values.
Expand Down
167 changes: 95 additions & 72 deletions pkg/roachpb/app_stats.pb.go

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

Loading