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]> 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]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to