WHERE cv.customized_type = 'Issue'
and cv.custom_field_id IN (#{query_cfs.join(',')})
and i.id IN (#{ids.join(',')})
ORDER BY i.id, cv.custom_field_id, cv.id
) cv
ORDER BY i.id, cv.custom_field_id, cv.id
Смотрите сами.
И без сортировки