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

add pattern replace #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add pattern replace #47

wants to merge 1 commit into from

Conversation

gywndi
Copy link
Contributor

@gywndi gywndi commented Jun 26, 2019

Hi~

Currently, characters are not substituted correctly in the lower case.

select * from test where a = 3*3
=> select * from test where a = ?*3

select * from test where a = ''''
=> select * from test where a = ??

First, I inserted a space character before and after the arithmetic operation code between the numbers to recognize the pattern correctly.

select * from test where a = 3*3
=> select * from test where a = 3 * 3
=> select * from test where a = ? * ?

Second, I have added code to replace from several question mark to single one

select * from test where a = ''''
=> select * from test where a = ??
=> select * from test where a = ?

Depending on the incoming parameters, the same query may be converted to two different fingerprints, so we want to fix it.

Thanks.
Chan.

Copy link
Contributor

@percona-csalguero percona-csalguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thanks for sending this patch. I like the fix but it affects how handling signs between quotes work.
Check:

--- FAIL: TestFingerprintDashesInNames (0.00s)
Error Trace:    query_test.go:564
Error:          Not equal:
expected: "select benchmark(?, pow(rand(), rand())), ? from `-hj-7d6-shdj5-7jd-kf-g988h-`.`-aaahj-7d6-shdj5-7&^%$jd-kf-g988h-9+4-5*6ab-`"
actual  : "select benchmark(?, pow(rand(), rand())), ? from `-hj-7d6-shdj5 - 7jd-kf-g988h-`.`-aaahj-7d6-shdj5 - 7&^%$jd-kf-g988h-9 + 4-5 * 6ab-`"
Test:           TestFingerprintDashesInNames

@gywndi
Copy link
Contributor Author

gywndi commented Jul 3, 2019

Ok, then it'd be better replace some pattern first and make fingerprint.
ex)

select /* my comment */ * from `mydb+1`.`tab-001` where x = 1*1 and x2 = 'mydb+1';

## step 1
select %s * from %s.%s where x = 1*1 and x2 = ?;

## step 2
select %s * from %s.%s where x = 1 * 1 and x2 = ?;

## step 3
select %s * from %s.%s where x = ? * ? and x2 = ?;

## step 4
select /* my comment */ * from `mydb+1`.`tab-001` where x = ? * ? and x2 = ?;

What do you think about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants