To expand on David's suggestion a bit, running this:

xdmp:estimate(
  cts:search(
    /book,
    cts:and-query((
      cts:element-value-query(xs:QName("title"),"New Book"),
      cts:element-value-query(xs:QName("price"),"100"),
      cts:directory-query("/localhost/")
    )))
)

and this:

fn:count(
  cts:uris(
    '',
    (),
    cts:and-query((
      cts:element-value-query(xs:QName("title"),"New Book"),
      cts:element-value-query(xs:QName("price"),"100"),
      cts:directory-query("/localhost/")
    )))
)

will both give results based on index resolution. (Understanding the Search 
Process<https://docs.marklogic.com/guide/performance/unfiltered#id_13165>) The 
query passed to cts:uris()<https://docs.marklogic.com/cts:uris#query> is always 
evaluated unfiltered. At a glance, it looks like the only way that 
xdmp:estimate<https://docs.marklogic.com/xdmp:estimate> might give you 
inaccurate results is based on the first parameter to cts:search(), the /book. 
If you changed that to fn:doc(), then the two queries above would be equivalent 
but I'd expect xdmp:estimate() to run a lot faster. (I believe the universal 
index will make the rest of the query accurate; someone please correct me if 
I'm wrong.)

--
Dave Cassel
Vanguard Technical Manager
MarkLogic Corporation<http://www.marklogic.com/>
Cell:  +1-484-798-8720


From: David Ennis <[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Tuesday, March 11, 2014 at 4:33 AM
To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Reg:Performance comparison for cts:search 
and cts:uris

Hi.

Do you need the exact number?  If not, then the solution with the best 
performance is actually xdmp:estimate.  This uses indexes and is not only 
bazillions of times faster, but does not require the memory you need in your 
samples.  You can find documentation about the differences of fn:count and 
xdmp:estimate on MarkLogic's website and decide which is better for which use.

As for you example, fn:count always counts what it is given.  for your example, 
it is likely faster because cts-uris gives back less information and everything 
it gives back is in an index.  the search may very well be reading abd 
returning every result.  larger result and possibly more disk reads (And 
unpacking the packed data).

Kind Regards,
David Ennis


On 11 March 2014 10:25, priya dharshni 
<[email protected]<mailto:[email protected]>> wrote:
Hi,

  We are having millions of records in db.Now i want to query the entire 
database based on few filters.For example,

i am having  "/test/book1.xml","/test/book2.xml","/test/book3.xml" ... 
"/test/bookn.xml"


<book>
  <title>New Book</title>
  <Author>Auth X</Author>
  <price>100</price>
</book>


 Now i have to fetch the count of uris whose title is "New Book" and 
price=100.I tried with cts:search and cts:uris which gives me the same result. 
But i would like to know on performance side which is the best approach.

count(cts:search(/book,cts:and-query((cts:element-value-query(xs:QName("title"),"New
 Book"),cts:element-value-query(xs:QName("price"),"100")
      ,cts:directory-query("/localhost/")
      )))
)
count(cts:uris('',(),cts:and-query((cts:element-value-query(xs:QName("title"),"New
 Book"),cts:element-value-query(xs:QName("price"),"100")
      ,cts:directory-query("/localhost/")
      )))
)
In profiling i found the number expression executed for cts:uris is less.Please 
suggest which is the best approach when we apply the 
cts:document-query,cts:and-query .



_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general


_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to