One of the first tasks in my new position at Akiban was to create a plugin point within Drizzle for query rewriting.
The first decision to make was where to insert a plugin point for a query rewriter. The parsed representation of a query would seem like a natural thing to pass to a query rewriter plugin since the plugin would not have to implement its own parser then. However, the parsed representation of a query in Drizzle is not the easiest in the world to deal with right now so passing this to a plugin would make developing a rewriting plugin quite difficult. Thus, I made the decision to create the plugin point before parsing occurs.
This means that if a plugin developer wants to do some complex rewriting, they may need to parse the query in their plugin. It may not be ideal but it does make the plugin API for query rewriting quite simple and opens up a lot of interesting opportunities.
Following the lead of other plugin interfaces such as the replication API developed by Jay, I wanted to keep it as simple and easy to understand as possible. With that in mind, here is the entire API for a query rewriting plugin:

Thus, all a plugin developer needs to do is implement the rewrite() function within their plugin. The query is passed by reference as a std::string so a plugin can do whatever it likes to this string and this string will then be passed to the parser in the Drizzle core kernel for parsing.
This interface opens up a lot of possibilties for interesting plugins. For example, one could develop a plugin to analyze a query for common SQL injection patterns or develop a plugin to rewrite a query based on a set of rules. I would be really interested in hearing other ideas people reading this have for plugins using this interface?


blog comments powered by Disqus

Published

01 March 2010

Category

drizzle