Move count query to AbstractDatabaseDialect