Bug 19563: Generation of sort_fields uses incorrect condition