Where the open source database community meets: Use code PERCONA75 and secure your spot for Percona Live.  Register

Query Rewrite plugin can harm performance

May 10, 2016
Author
Vadim Tkachenko
Share this Post:

In this blog post, we’ll discuss how the Query Rewrite plugin can harm performance.

MySQL 5.7 comes with Query Rewrite plugin, which allows you to modify queries coming to the server. (You can view the details here: https://dev.mysql.com/doc/refman/5.7/en/rewriter-query-rewrite-plugin.html.)

It is based on the audit plugin API, and unfortunately it suffers from serious scalability issues (which seems to be the case for all API-based audit plugins).

I want to share the results for sysbench OLTP RO with and without the query rewrite plugin — but with one very simple rewrite rule, which doesn’t affect any queries. This is the rule from the documentation:

There are results for both cases:

Query Rewrite plugin can harm performance

As you can see, the server with the Query Rewrite plugin can’t scale after 100 threads.

When we look at the PMP profile, it shows the following:

So clearly it’s related to a mutex acquired in the audit plugin API code. I filed a bug (https://bugs.mysql.com/bug.php?id=81298), but it’s discouraging to see that while the InnoDB code is constantly being improved for better scaling, other parts of the server can still suffer from global mutexes.

0 0 votes
Article Rating
Subscribe
Notify of
guest

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mark Callaghan
10 years ago

Replication features also suffered from plugin mutex contention.

Joro Kodinov
10 years ago

Vadim, would you mind sharing the machine details and the sysbench options ? Seems like a pretty big box you’ve got there …

Fadi El-Eter (itoctopus)

Hi Vadim,

I personally have never heard of the Query Rewrite Plugin before. Would it be possible to provide an example on where this plugin would be helpful (or can you provide a link)? The example you provided above doesn’t really highlight the need of such a plugin.

Justin Swanhart
10 years ago

A good use would be for Shard-Query. The server intercepts the SQL, passes it to the rewrite layer, the rewrite layer rewrites the SQL as a CALL shard_query.sq_helper(…) call, and that returns a resultset to the client. This is basically functionally equivalent to the MySQL proxy LUA script.

Tim G
8 years ago

It might be useful for others to know that this is resolved now 🙂

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved