fix and tests for #469 (wrong count(*) with permissions)