Improving Sql Performance Using Middleware-Based Query Rewriting