At the moment I'm using eXist 1.1.1 as an embedded database.

When I try to execute the following xquery it takes more than a minute to execute:

declare namespace cl = "http://www.epo.org/namespaces/epodos/clause/v1.0/";

for $category in collection('/db/clause')/cl:clause-category
return <cl:clause-category xmlns:cl="http://www.epo.org/namespaces/epodos/clause/v1.0/"> {
attribute noOfClauses
{
count(for $clause in collection('/db/clause')/cl:clause
let $categoryref := $clause/cl:clause-categories/cl:ref-category/@ref-id
where $categoryref = $category/@category-id
return $clause/@clause-id)
} ,
$category/@*, $category/* }
</cl:clause-category>


I have defined a range index for all queried paths.

If I perform the same query using xquery exist client it only takes 2 seconds.

I'm using the following code (excerpt) to perform the query

                        existCollection = getCollection(path);
                        XQueryService queryService = (XQueryService) existCollection.getService("XQueryService", "1.0");
                        queryService.setProperty(OutputKeys.INDENT, (this.connnection.isIndentOutput() ? "yes" : "no"));
                        queryService.setProperty(OutputKeys.ENCODING, "UTF-8");
                        ResourceSet result = queryService.query(query); // this takes more than a minute ???


The result BTW is correct.

Kind regards,
Rudolf