Hi Filippo,
Your queries may be executed faster if you rewrite your query to forward axes:
if(direct) { input = "for $n in db:open('" + DBNAME +"', '/" + keyName + "')/descendant::" + element + "/child::*/name()" } else { input = "for $n in db:open('" + DBNAME +"', '/" + keyName + "')//descendant::" + element + "/descendant::*/name()" }
This brings to have for a tree with 7 paths a 7! permutations and therefore at least 7!*4=21.000 queries (the query below) in a lapse of 5minutes.
XQuery is a very powerful language, so I’m more than sure that the problem could be solved much faster if all queries were combined in a single XQuery expression. However, it obviously takes some time to get to know the language..
Hope this helps, Christian