# Query rewrite  on VERSION() function

**URL:** <https://forums.percona.com/t/query-rewrite-on-version-function/6968>\
**Category:** Percona Server for MySQL 5.7\
**Created:** [April 16, 2019, 9:23am UTC](https://forums.percona.com/t/query-rewrite-on-version-function/6968 "2019-04-16T09:23:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stofa.kenida](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@stofa.kenida](https://forums.percona.com/u/stofa.kenida)\
**Post date:** [April 16, 2019, 9:23am UTC](https://forums.percona.com/t/query-rewrite-on-version-function/6968/1 "2019-04-16T09:23:37Z")

</div>

Hi There,

By using the query rewrite plugin in 5.7.25-28-log Percona Server (GPL), Release 28, Revision c335905 version, i saw tha following strange behaviour.

Below are the steps excuted :

1. Load and enable the plugin :

mysql -S /var/lib/mysql57-25/mysql.sock \< /usr/local/Percona-Server-5.7.25/share/install\_rewriter.sql

1. Load two patterns in query\_rewrite.rewrite\_rules table

insert into rewrite\_rules ( pattern,replacement) values (‘SELECT version()’,‘select '5.6.81-4-log'’);

insert into rewrite\_rules ( pattern,replacement) values (‘SELECT PASSWORD('pippo')’,‘select '5.6.81-4-log'’);

1. Load the rules in memory :

CALL query\_rewrite.flush\_rewrite\_rules();

When i execute the following query and the uppercase is used for version() function, it seems that the pattern in not matched :

mysql\> select version();  
±--------------+  
| 5.6.81-40-log |  
±--------------+  
| 5.6.81-40-log |  
±--------------+  
1 row in set, 1 warning (0.00 sec)

mysql\> select VERSION();  
±--------------+  
| VERSION() |  
±--------------+  
| 5.7.25-28-log |  
±--------------+

By doing the same query but using the second pattern :

mysql\> select password(‘pippo’);  
±-------------+  
| 5.6.81-4-log |  
±-------------+  
| 5.6.81-4-log |  
±-------------+  
1 row in set, 1 warning (0.00 sec)

mysql\> select PASSWORD(‘pippo’);  
±-------------+  
| 5.6.81-4-log |  
±-------------+  
| 5.6.81-4-log |  
±-------------+  
1 row in set, 1 warning (0.00 sec)

The result is as expected. The rule is hit and the query is rewritten.

My question is why only by using version() call funtion , the rule is escaped and works only if the exact matching between the query and the pattern in rewrite\_rules table.

Thanks

Stofa.

---

<div class="post-metadata">

**Author:** ![stofa.kenida](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@stofa.kenida](https://forums.percona.com/u/stofa.kenida)\
**Post date:** [April 17, 2019, 7:46am UTC](https://forums.percona.com/t/query-rewrite-on-version-function/6968/2 "2019-04-17T07:46:41Z")

</div>

Hi,

Is someone has an idea about this issue?

Thanks.
