SQL case indexes

#3329
this is going to be a lot of data...