Hi
Using Basex 7.0.2 and the factbook.xml database, I observe the following:
declare variable $data:=db:open("factbook");
>
> declare function local:myid1($id){
> $data//*[@id=$id]
> };
> (: get a 1000 ids to test :)
> let $ids:=subsequence($data//@province/string(.),1,1000)
>
> for $s in $ids return local:myid1($s)
>
Takes 30 seconds!
Replacing the final line with
> for $s in $ids return $data//*[@id=$s]
>
The time is 123ms.
/Andy