title: Can I tune this query to get rid of fn:distinct-values?
body: <p>Can anyone tell me if I can improve this query by getting rid of the <code>fn:distinct-values($d2)</code> expression?</p>
  
  <pre><code>xquery version "1.0-ml";
  declare namespace zespc = "http://www.cendris.nl/postcode";
  declare namespace op = "http://www.nvsp.nl/oplage-mapping";
  
  let $wijk := '665402'
  let $d1 := fn:distinct-values(fn:doc('/data/map/oplage-mapping.xml')//op:map[@wijk_id = $wijk]/@ppc6_id)
  
  let $q1 := cts:element-attribute-range-query(
        xs:QName("op:map"), xs:QName("wijk_id"), "=",
        $wijk)
  
  let $d2 := cts:search(//op:map,$q1)/@ppc6_id
  let $d3 := fn:distinct-values($d2)
  
  return (fn:count($d1), fn:count($d3))
  </code></pre>
  
  <p>Thx,</p>
  
  <p>hugo</p>