Bug #57459 Query Rewrite Plugin Interface
Submitted: 14 Oct 2010 16:24 Modified: 10 Oct 2014 12:17
Reporter: Padraig O'Sullivan (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Parser Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, parser, rewrite

[14 Oct 2010 16:24] Padraig O'Sullivan
I have a patch with a new plugin point for query rewriting that I'd like to have considered. It allows someone to develop a plugin which can modify the text of a query before it is parsed.

A very simple explanation of my use-case is to transform a query with joins into a query on virtual tables that contains no joins. I need this transformation to be transparent to the user who can submit their original queries as before. 

One other possible use-case which I had thought of is to implement a scheme for preventing SQL injection as a query rewriting plugin. This
occured to me when reading this paper - http://www.springerlink.com/content/j2efhxbrf83xmd5g/ The proxy described in the paper could be implemented as a rewriting plugin. Not sure if its a real use-case but its just me thinking out loud.

I have a branch on launchpad with my work in it:


I picked this point for the plugin as its much easier for me to parse the query myself than to work with the parse tree produced by MySQL.

I'm willing to work on revising this plugin if needed. If I can get some documentation or pointers on how to understand better the MySQL parse tree, I can work on changing the plugin interface to instead take the parse tree as a parameter instead of the raw query string.

How to repeat:
This is a feature request so there is no steps needed to repeat.
[15 Oct 2010 16:03] Padraig O'Sullivan
I proposed my branch for merging on Launchpad this morning:


Any feedback would be appreciated.
[19 Oct 2010 9:38] Lenz Grimmer
Thanks for your contribution! I've verified and approved your SCA, so from an administrative point of view, your patch is ready for inclusion. Now it's in the hands of our engineers to comment on your code.
[9 Oct 2014 22:21] Rick James
How does this compare with "Query Rewrite plugin" in 5.7?
[10 Oct 2014 12:17] Martin Hansson
This patch has been included as-is. I guess "closed" is the proper status. :-)
[3 Oct 2019 18:15] Paul DuBois
Posted by developer:
Fixed in 5.7.6.

The contributed code was originally submitted as is, but subsequent development rewrote just about everything.

Thanks to Padraig O'Sullivan for the related code contribution.