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

Regex match when replace pattern and negate_match_pattern flag are set but no replacement #1075

Open
kartt opened this issue Jun 29, 2017 · 2 comments
Assignees

Comments

@kartt
Copy link

kartt commented Jun 29, 2017

I'm not sure if this is a bug.
I'm facing a problem wherein the query_rule is getting matched but replace_pattern is not getting applied.

Steps to reproduce:

Add query_rule as follows
insert into mysql_query_rules(rule_id,active,match_pattern,negate_match_pattern,replace_pattern,apply) values (1, 1, '^select .* from test_table where id =.*', 1, 'select "RANDOM STUFF"', 1);

Now, my understanding is that

  • Query select * from test_table where id = 1 will match the "match_pattern" of the rule. But since "negate_match_pattern" flag is set, the query will not match the rule. So, the query will return 1 row from test_table. This is working as per my understanding and stats_mysql_query_rules.hits for the rule remains unchanged.

  • But, query select * from test_table where 1 = 1 and id = 1 will not match the "match_pattern" of the rule. To my understanding, since "negate_match_pattern" flag is set, the query will match the rule and the query result should be "RANDOM STUFF". But, I'm getting one data row from mysql instead of "RANDOM STUFF" even though stats_mysql_query_rules.hits for the rule gets incremented.

ProxySQL version - 1.3.4-15-gf70037c

Am I doing some mistake or "replace_pattern" and "negate_match_pattern" won't work together?
Any help is very much appreciated.

Thanks.

@renecannao renecannao self-assigned this Jul 31, 2017
@renecannao
Copy link
Contributor

Hi @kartt . This is not a bug, but needs to be documented.

The replaces works replacing the match_pattern with replace_pattern . Since match_pattern doesn't match, no replace happens.
In other words, if you use negate_match_pattern , the match+replace can't work.
This is expected, but need to be documented.

Thanks

@himanshutecstub
Copy link

himanshutecstub commented Dec 7, 2020

Hello
I use proxysql 2.5 with same problem
select hostgroup,username,count_star,digest_text,digest from stats_mysql_query_digest where digest_text like '%myproduct_url%';
Where some query not match with host group i set in query rule.
My rule is INSERT INTO mysql_query_rules (rule_id,active,match_digest,destination_hostgroup,apply) VALUES(3,1,'.*(myproduct_url(.*))',5,1);
but in below query is run from other host group
delete from myproduct_url where (queue_id=?)
After update rule check result after below query LOAD MYSQL QUERY RULES TO RUNTIME;SAVE MYSQL QUERY RULES TO DISK;SELECT * FROM stats_mysql_query_digest_reset;
Also check with add digest in query_rule but not apply

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

No branches or pull requests

3 participants