title: XQuery/Xpath optimization: query different parts of the same document
body: <p>Let's say we have XML files with different parts: <code>title</code>, <code>description</code>, <code>text</code>, <code>note</code>.</p>
  <pre><code>&lt;book&gt;
      &lt;title&gt;Some title&lt;/title&gt;
      &lt;description&gt;Some description&lt;/description&gt;
      &lt;text&gt;Some texte&lt;/text&gt;
      &lt;note&gt;Some note&lt;/note&gt;
  &lt;/book&gt;
  </code></pre>
  <p>Let's say we want to be able to query in these different parts. This can be done by different approaches.</p>
  <p>For exemple, we want to query only in <code>title</code> and <code>note</code>.</p>
  <p><strong>approach 1</strong> (basic verbose version)</p>
  <pre><code>for $result in (
      collection(&quot;path_to_my_collection&quot;)//title[ft:query(., &quot;'word_to_search'&quot;)]
      , 
      collection(&quot;path_to_my_collection&quot;)//note[ft:query(., &quot;'word_to_search'&quot;)]
      ) 
  </code></pre>
  <p><strong>approach 2</strong> (take this one from <a href="https://stackoverflow.com/questions/4079565/xpath-selecting-multiple-elements-with-predicates">here</a>)</p>
  <pre><code>for $result in collection(&quot;path_to_my_collection&quot;)//(title | note)[ft:query(., &quot;'word_to_search'&quot;)]
  </code></pre>
  <p><strong>approach 3</strong> (this one seems to be advised by the <a href="http://exist-db.org/exist/apps/doc/tuning.xml#multiple-collections" rel="nofollow noreferrer">documentation</a> )</p>
  <pre><code>let $docs_and_parts :=
      for $parts in (collection(&quot;path_to_my_collection&quot;)//title, collection(&quot;path_to_my_collection&quot;)//note) 
      return 
          $parts
          
  for $result in $docs_and_parts[ft:query(., &quot;'word_to_search'&quot;)]
  </code></pre>
  <p>After reading the <a href="http://exist-db.org/exist/apps/doc/tuning.xml" rel="nofollow noreferrer">XQuery optimization technic</a>, <strong>I'm wondering which one of these approaches is more efficient/fast for execution in large collections with many (more than 100) files?</strong></p>