fix min/max discovery to use indexes if defined