Slow tf:getLastModified

Is there any way to get list of modified-in-period roots really fast?
If I use this query, it lasts more than 20 seconds.
Number of roots is about 250000.
There is index defined on Kzadeva/Kspis/@idZadeva.
Kzadeva schema definition is quite complex; many subelements with many attributes.

My xml query:
[b]declare namespace xs=“XML Schema
declare namespace tf=“
declare namespace ns1=“
declare namespace ns2=“
declare namespace brw=“

let $changeDateFrom := xs:dateTime(“2011-05-03T00:00:00.000+02:00”)
let $changeDateTo := xs:dateTime(“2011-05-06T23:59:59.999+02:00”)

let $myCases:= for $case in input()/ns1:Kzadeva
let $lastModified := tf:getLastModified(root($case))
where $lastModified >= $changeDateFrom and $lastModified <= $changeDateTo
return $case/ns1:Kspis/@ns2:idZadeva

return element brw:RData
attribute brw:all { count($myCases) }

I think you are confusing the Xquery parser by nesting the getLastModified in a “for loop”.
A structure like the one below claims to be using indexing when I use “Explain”, but I haven’t tested performance in a 250K instance scenario :wink:

let $startdate:=xs:dateTime(“2011-05-10T13:54:00.999+02:00”)
let $enddate:=xs:dateTime(“2011-05-10T13:56:00.999+02:00”)
for $q in input()/testNode
where tf:getLastModified($q) > $start and tf:getLastModified($q) < $enddate
return $q