I wonder whether you might not see an improvement if you accumulate all the values you are searching for and find them all at once:

let $code := (1, 2, 3, ...)
let $items := //it...@code=$code]

not sure whether that fits your application well, but it might perform better. Sometimes I also find that for reasons that are obscure to me, I get better performance using the cts:search/cts:query combination even for expressions that look like they could really be optimized for me - I guess optimizing is a black art, although it seems that ML does keep improving it. If you do that, the element-value-query is what you want...

-Mike


Lee, David wrote:
thanks, I actually do use eq not = ...

-----Original Message-----
From: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Micah
Dubinko
Sent: Tuesday, November 10, 2009 6:41 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Optimize exact match searches
onattributes

David,

I'm guessing the optimizer already does this, but just in case, try using the atomic comparison operator eq instead of =. (The value in $code will never be a sequence, right?)

$root/tree/item[ @code eq $code ]

Even though it goes against conventional wisdom, also try $root//item [ ... ]

You can use xdmp:elapsed-time() to get decent resolution timing data to experiment with what works the fastest.

-m

On Nov 10, 2009, at 3:15 PM, Lee, David wrote:

Suppose I have an XML document with about 50,000 of these small elements <item name="Peritoneum" parent="A01.047.025" code="A01.047.025.600"/>

And an Xquery that does a LOT of this kind of search

            let $item = $root/tree/item[ @code = $code ]
or
            let $item = $root/tree/item[ @parent  = $code ]


These are exact string matches, no fancy terming or wildcards or anything.

Any suggestions on the basic area to look for optimizing this kind of access ? Either using xquery or a setting on the server ? Thanks for any suggestions. So far I've only been able to find things tailored for full text searching (1 letter, 2 letter, word searches etc). I would think direct attribute=value searches could be tagged for efficient indexing. Maybe they are already ? But its starting to slow down when I do about 20 of these in an xquery.

One thought I had was to preprocess the data into more of a tree structure instead of the flat structure it is now ...
   <item >
     <item>
       <item>
   </item>
  </item>

then I can use ancestor axis to search up the tree instead of a flat search ... But if these were already indexed it "should" be a near instant access as a flat structure (???)



----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
d...@epocrates.com
812-482-5224


_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com
http://xqzone.com/mailman/listinfo/general

Reply via email to