Skip to content

PMM-1989: fix panic #27

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

Closed
wants to merge 8 commits into from
Closed
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
9 changes: 5 additions & 4 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const (
inMySQLCode // /*! MySQL-specific code */
)

var stateName map[byte]string = map[byte]string{
var stateName = map[byte]string{
0: "unknown",
1: "inWord",
2: "inNumber",
Expand All @@ -119,7 +119,7 @@ var stateName map[byte]string = map[byte]string{
}

// Debug prints very verbose tracing information to STDOUT.
var Debug bool = false
var Debug = true

// ReplaceNumbersInWords enables replacing numbers in words. For example:
// `SELECT c FROM org235.t` -> `SELECT c FROM org?.t`. For more examples
Expand All @@ -131,14 +131,15 @@ var ReplaceNumbersInWords = false
// - Collapse whitespace
// - Remove comments
// - Lowercase everything
// Additional trasnformations are performed which change the syntax of the
// Additional transformations are performed which change the syntax of the
// original query without affecting its performance characteristics. For
// example, "ORDER BY col ASC" is the same as "ORDER BY col", so "ASC" in the
// fingerprint is removed.
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
15 changes: 15 additions & 0 deletions query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ func TestFingerprintBasic(t *testing.T) {
query.Fingerprint(q),
)

// Fingerprint Insert into tables;
q = "insert into t3 values(2);"
assert.Equal(
t,
"insert into t3 values(?+);",
query.Fingerprint(q),
)

// Fingerprint /* -- comment */ SELECT (bug 1174956)
q = "/* -- S++ SU ABORTABLE -- spd_user: rspadim */SELECT SQL_SMALL_RESULT SQL_CACHE DISTINCT centro_atividade FROM est_dia WHERE unidade_id=1001 AND item_id=67 AND item_id_red=573"
assert.Equal(
Expand All @@ -237,6 +245,13 @@ func TestFingerprintBasic(t *testing.T) {
query.Fingerprint(q),
)

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

q = "INSERT INTO t (ts) VALUES (NOW())"
assert.Equal(
t,
Expand Down