简体   繁体   中英

In cts:search using fn:doc() vs specific node in query

In below 2 queries how big the difference will be in performance.

Option 1-

cts:search(fn:doc(),
  cts:and-query((
    cts:collection-query('xyz'),
    cts:element-value-query(xs:QName('test'),'12344')
  ))
)

Option 2- specific node

cts:search(/root-node,
  cts:and-query((
    cts:collection-query('xyz'),
    cts:element-value-query(xs:QName('test'),'12344')
  ))
)

PS: there are many other collections in DB.

Please guide me. Which one is better to use and how does it work in Marklogic?

It's difficult to know what the difference is without knowing the size of your database and how many of the documents have the /root-node , and how many docs match the other query criteria.

If the query criteria with the collection and the element-value are specific enough that the /root-node criteria are not necessary, then it may be easier and more performant to go with the first.

You can see the difference in the generated query plans by wrapping the search with xdmp:plan() to see what the query criteria looks like. Applying that path expression for the first parameter will include some additional term-query criteria to target the documents that have root-node as the root element of the document that will looks something like this:

<qry:or-two-queries>
  <qry:term-query weight="0">
    <qry:key>2975665039653361017</qry:key>
    <qry:annotation>doc-root(element(root-node),doc-kind(document))</qry:annotation>
  </qry:term-query>
  <qry:term-query weight="0">
    <qry:key>6481445092305598577</qry:key>
    <qry:annotation>link-child(descendant(doc-root(element(root-node),doc-kind(document))))</qry:annotation>
  </qry:term-query>
</qry:or-two-queries>

I suspect that you probably won't see a huge difference between those two queries, but it's always best to test and measure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM