Refactor intermediate permission checks
Summary
Currently, the simplest queries like COUNT RECORD
can be awfully slow since for every element (every Record!) a retrieve is done in order to check the permissions. This also happens in queries with subproperties. This is so slow, such that there is a
server variable to disable the check. This however allows leaking confidential data.
Proposed Solution: Get the only distinct permissions directly from SQL.
Since typically many records share the same permissions this should be much slower.