Database Rewrite Complete and Optimized