SQL case indexes

#3329