xdmp:plan( $expression as item()*, [$maximum as xs:double?] ) as element()
Returns an XML element recording information about how the given expression will be processed by the index. The information is a structured representation of the information provided in the error log when query trace is enabled. The query will be processed up to the point of getting an estimate of the number of fragments returned by the index.
http://marklogic.com/xdmp/privileges/xdmp-plan
The output from xdmp:plan
will vary depending on various index
settings.
Running an xdmp:plan
on a search is similar to running an
xdmp:estimate
on a search, but it returns a report on the
search instead of just an estimate. As part of the report, the
qry:result
element includes the estimate.
If the search expression argument cannot be run in the
plan because it is not partially searchable, then an
XDMP-UNSEARCHABLE
exception is returned as part of the
xdmp:plan
output.
If you are running a search using the search API
(for example, search:search
), use the
option <return-plan>true</return-plan>
in your
search API options node.
xquery version "1.0-ml"; xdmp:plan(cts:search(fn:doc(),cts:word-query("cat"))) => <qry:query-plan xmlns:qry="http://marklogic.com/cts/query"> <qry:expr-trace>xdmp:eval("xquery version &quot;1.0-ml&quot;;& #10;&#10;xdmp:plan(cts:search...", (), <options xmlns="xdmp:eval"><database>8855151527276563827</database> <isolation>different-tra...</options>) </qry:expr-trace> <qry:info-trace>Analyzing path for search: fn:doc()</qry:info-trace> <qry:info-trace>Step 1 is searchable: fn:doc()</qry:info-trace> <qry:info-trace>Path is fully searchable.</qry:info-trace> <qry:info-trace>Gathering constraints.</qry:info-trace> <qry:word-trace text="cat"> <qry:key>12545744176132597186</qry:key> </qry:word-trace> <qry:info-trace>Search query contributed 1 constraint: cts:word-query("cat", ("lang=en"), 1) </qry:info-trace> <qry:partial-plan> <qry:term-query weight="1"> <qry:key>12545744176132597186</qry:key> <qry:annotation>word("cat")</qry:annotation> </qry:term-query> </qry:partial-plan> <qry:info-trace>Executing search.</qry:info-trace> <qry:final-plan> <qry:and-query> <qry:term-query weight="1"> <qry:key>12545744176132597186</qry:key> <qry:annotation>word("cat")</qry:annotation> </qry:term-query> </qry:and-query> </qry:final-plan> <qry:info-trace>Selected 1 fragment to filter</qry:info-trace> <qry:result estimate="1"/> </qry:query-plan>
xquery version "1.0-ml" ; xdmp:plan( cts:search(/document, cts:word-query("cut?", ("unstemmed", "wildcarded") ) ) ) (: The <qry:expansion-trace> element indicates that a lexicon expansion occurred on the wildcarded query (word searches, three character searches and a codepoint lexicon are enabled in the database configuration for wildcard queries). The <qry:expansion> element shows what term(s) the lexicon expansion found. In this case, "cut?" expands to "cute". :) => <qry:query-plan xmlns:qry="http://marklogic.com/cts/query"> <qry:info-trace>Analyzing path for search: fn:collection()/document </qry:info-trace> <qry:info-trace>Step 1 is searchable: fn:collection()</qry:info-trace> <qry:info-trace>Step 2 is searchable: document</qry:info-trace> <qry:info-trace>Path is fully searchable.</qry:info-trace> <qry:info-trace>Gathering constraints.</qry:info-trace> <qry:expansion-trace type="full" elapsed-time="PT0.000381S" text="cut?" counts="1"> <qry:interval lowerbound="CUT" upperbound="C??"/> <qry:interval lowerbound="cUT" upperbound="c??"/> <qry:interval lowerbound="}UT" upperbound="???"/> <qry:expansion text="cute"/> </qry:expansion-trace> <qry:word-trace text="cute"> <qry:key>16588943567160478160</qry:key> </qry:word-trace> <qry:info-trace>Search query contributed 1 constraint: cts:word-query("cut?", ("unstemmed","wildcarded","lang=en"), 1) </qry:info-trace> <qry:partial-plan> <qry:term-query weight="1"> <qry:key>16588943567160478160</qry:key> <qry:annotation>word("cute")</qry:annotation> </qry:term-query> </qry:partial-plan> <qry:info-trace>Executing search.</qry:info-trace> <qry:final-plan> <qry:and-query> <qry:or-two-queries> <qry:term-query weight="0"> <qry:key>3998944933214536873</qry:key> <qry:annotation>doc-root(element(document),doc-kind(document)) </qry:annotation> </qry:term-query> <qry:term-query weight="0"> <qry:key>13616698357625443361</qry:key> <qry:annotation>link-child(descendant(doc-root(element(document), doc-kind(document)) )) </qry:annotation> </qry:term-query> </qry:or-two-queries> <qry:term-query weight="1"> <qry:key>16588943567160478160</qry:key> <qry:annotation>word("cute")</qry:annotation> </qry:term-query> </qry:and-query> </qry:final-plan> <qry:info-trace>Selected 1 fragment to filter</qry:info-trace> <qry:result estimate="1"/> </qry:query-plan>