Hi Christian,

Thanks for the explanation. So functions never use indices are the moment?

/Andy

On Sat, Dec 10, 2011 at 11:02 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Andy,

yes, it should give the same error. I only have tried the latest 7.1
snapshot, which returns errors for both of the queries. The
performance may be suboptimal here, as the equality predicate in the
function cannot be optimized for index access (this is because the
incoming nodes may relate to a database instance that has no attribute
index). This may be changed in future by choosing the best evaluation
plan at runtime.

Hope this helps,
Christian


On Sat, Dec 10, 2011 at 11:55 PM, Andy Bunce <bunce.andy@gmail.com> wrote:
> Hi
> with the  factbook.xml database open in the 7.0.2 gui
>
> declare function local:linkto($id as xs:string){
>   let $d:=//city
>   let $a:=$d[@id=$id]
>   return $a
> };
> local:linkto("f0_1461")
>
> Gives the "no context item for root" error on the //city line, but
>
> declare function local:linkto($id as xs:string){
>   let $a:=//city[@id=$id]
>   return $a
> };
> local:linkto("f0_1461")
>
> Works fine. Should it give the same error?
> If it should, and I try to pass the nodes into the function then the
> relative performance is not good at all.
> declare function local:linkto2($id as xs:string,$nodes as node()*){
>  let $c:=$nodes[@id=$id]
>  let $n:=name($c[1])
>  return <a href="/fb/{$n}/{$id}">
>  {$c/name/string()}
>  </a>
> };
>
> let $caps:=//country/@capital/string()
> for $id in $caps
> return local:linkto2($id,//city)
>
> /Andy