massive SQL performance improvements