[SORT] Use first non-empty result to detect if sort is required

Closes #8226