Attempt to improve performance on SQL queries