Finding the correct index to use per query