Changed queries in the way that the resultssets size is checked first.
Authored by: dowolff 2016-05-24
Parent: [r904]
Child: [r906]