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

PMM-1989 Fix memory allocation #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ var ReplaceNumbersInWords = false
func Fingerprint(q string) string {
q += " " // need range to run off end of original query
prevWord := ""
f := make([]byte, len(q))
// allocate enough memory to replace (x) with (?+).
f := make([]byte, len(q)+len(q)/3)
fi := 0
pr := rune(0) // previous rune
s := unknown // current state
Expand Down
7 changes: 7 additions & 0 deletions query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ func (s *TestSuite) TestFingerprintBasic(t *C) {
"select sql_small_result sql_cache distinct centro_atividade from est_dia where unidade_id=? and item_id=? and item_id_red=?",
)

q = "insert into foo (a) values(0)"
t.Check(
query.Fingerprint(q),
Equals,
"insert into foo (a) values(?+)",
)

q = "INSERT INTO t (ts) VALUES (NOW())"
t.Check(
query.Fingerprint(q),
Expand Down