xquery performance

Hi all,
we have a collection with 18766 very small and simple documents (schema is attached), but this query:

declare namespace xs=“http://www.w3.org/2001/XMLSchema
declare default collation “collation?language=it;strength=secondary”
let $q := for $a in input()/Index[@type=“author” and @tot>0] sort by (./@order ascending)
return $a
let $name := “PIUS”
let $offset := 10
let $termPosition := 0
let $pos := xs:integer(count($q[./@order < $name])) + 1
let $delta1 := min(($pos - $termPosition, count($q)))
let $startPos := min (( max((1, $delta1)),count($q)-$offset+1 ))
let $delta2 := max(($startPos,$pos + $offset -1 - $termPosition ))
let $endPos := max( (min((count($q),$delta2)),$offset) )
return $q[position() >= $startPos and position() <= $endPos]

takes about 15 seconds (and involves 6736 documents).
This is too long! I guess this is not normal and we missed something!

Any kind of tuning suggestion is welcome.
Thanks in advance,

Pam
SchemaIndex.tsd (5.77 KB)

Hi,

probably it’s better that you describe what you want to achieve with this query.

Regards

Harald

Hi, the problem is the same with this query:

declare default collation “collation?language=it;strength=secondary”
for $a in input()/Index[@type=“author” and @tot>0] sort by (./@order ascending)
return $a

It takes about 15 seconds (and involves 6736 documents).

Thanks in advance for your help,

Pam