Restore safeguard for using the `iterate over sort index` case and avoid
it while using limiting at the same time. Fixes LP #1236790.

This effectively reverts b4b4930d27784e74a70d27c58040544efce643d5.