An API for query rewrites. It may be a special rewrite plugin or part of the storage engine or some other API. Preferably it should not force plugin to parse or work with the sql string, but it may provide a DOM-like representation of the query and let the plugin to manipulate the tree nodes. Perhaps this needs the "Abstract Query Tree" task to be done first.