speed improvements for databases with many tables