Tweaks to SQL indexing and statement caching