Several database performance tweaks