Robert,
There's a difference, and I'd expect the expression without the 'where'
to be more efficient. But within a single (unfragmented) doc, it doesn't
matter much because the entire fragment will end up in memory either
way. You could profile the query to see.
But I think there's room for improvement. Here's how I'd write that query:
doc($lookup-uri)/value-list/values[key = $keys]
First, it's almost always more efficient to specify a complete XPath
than to use '//'. Next, turned the for-expression over $keys into a
simple predicate lookup with multiple values. This works because '=' is
a list-comparison operator, and should result in one pass through the
document rather than N passes.
As Geert mentioned, you might also consider using a map
(http://developer.marklogic.com/pubs/4.1/apidocs/map.html).
-- Mike
On 2009-08-03 09:11, Runstein, Robert E. (Contr) (IS) wrote:
Hi,
I have a document that is contains lookup values that are frequently accessed.
When a new document is ingested, I loop through its keys and pull the matching
values from the lookup document.
Is there a difference in performance between this code:
let $lookups := fn:doc($lookup-uri)//values
return
for $key in $keys
return $value := $lookups[key = $key]
And this code?
for $key in $keys
return $value := fn:doc($lookup-uri)//values[key = $key]
Am I correct in thinking that the former is reading in all the values (some of
which may not be used), while the latter just pulls back the values that are
needed?
Bob
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general