FAIMS-554 - fix the query to work on large database on android