Add indices for all sqlite queries

Addresses #3043.