optimize count queries to ignore optional binding patterns