That one takes 0.038 secs, slightly faster than the 0.04 other XPath one.

But I'm really more interested in why the cts version performs better.

From: breinhol...@ldschurch.org
To: general@developer.marklogic.com
Date: Thu, 12 May 2011 10:43:39 -0600
Subject: Re: [MarkLogic Dev General] Why is cts:search so much faster than 
XPath?



You might try the moving the @key reference out of the filter like this:        
         fn:collection()/resource-bundle/resource/@key[. eq 
$key]/..[fn:lang($lang-code)] Putting the attribute name in the filter 
sometimes doesn’t allow the XPath to use an index for the query.  Moving it to 
the path statement does. The query looks a little more awkward but it usually 
performs better. Try it. - Keith From: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] On Behalf Of 
seme...@hotmail.com
Sent: Thursday, May 12, 2011 10:30 AM
To: general@developer.marklogic.com
Subject: Re: [MarkLogic Dev General] Why is cts:search so much faster than 
XPath? Here are some queries that are similar to the code I was talking about. 

XPath (0.04 secs)
xquery version '1.0-ml';
let $key := "mykey"
let $lang-code := "spa"

return
fn:collection()/resource-bundle/resource
    [@key = $key]
    [fn:lang($lang-code)]


cts (0.015 sec)
xquery version '1.0-ml';
let $key := "mykey"
let $lang-code := "spa"

return
cts:search(fn:collection()/resource-bundle/resource, 
cts:element-attribute-value-query(xs:QName("resource"), xs:QName("key"), $key, 
"exact"))
    [fn:lang($lang-code)]

The expression that takes the most time in the XPath version is "@key = $key". 
What I'm curious about is just what cts does so differently that the XPath 
engine doesn't, because I am noticing quite a disparity between them given the 
same data and same queries effectively (which is ok, I don't have an XPath 
problem, just wondering why the difference).

-Ryan


> From: kelly.stir...@marklogic.com
> To: general@developer.marklogic.com
> Date: Thu, 12 May 2011 08:59:13 -0700
> Subject: [MarkLogic Dev General] Why is cts:search so much faster than XPath?
> 
> Equivalent XPath and cts:search expressions should perform the same. Can you 
> share an example, and what version you are using?
> 
> If they are equivalent and there is a performance difference, then there may 
> be a bug.
> 
> Kelly
> 
> Message: 5
> Date: Thu, 12 May 2011 09:05:16 -0600
> From: "seme...@hotmail.com" <seme...@hotmail.com>
> Subject: [MarkLogic Dev General] Why is cts:search so much faster than
> XPath?
> To: <general@developer.marklogic.com>
> Message-ID: <snt121-w423bd38403eb7f1aded8d5b7...@phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> 
> I wrote awhile ago that I thought it was usually best to use search:search 
> for full text searching, cts:search for node selection out of the db, and 
> XPath for node selection within a document. I just ran into a situation that 
> doing the same query for nodes in the DB using cts:search was 6 times faster 
> than using XPath. 
> 
> So what is it about cts:search that makes it so fast? I assume that there are 
> optimizations under the covers, but how is cts:search able to gain from the 
> optimizations but XPath is not? Just curious.
> 
> -Ryan
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general



 NOTICE: This email message is for the sole use of the intended recipient(s) 
and may contain confidential and privileged information. Any unauthorized 
review, use, disclosure or distribution is prohibited. If you are not the 
intended recipient, please contact the sender by reply email and destroy all 
copies of the original message.



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

Reply via email to