marklogic - Can I tune this query to get rid of fn:distinct-values? -


can tell me if can improve query getting rid of fn:distinct-values($d2) expression?

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)) 

thx,

hugo

i not 100% sure goal is, should return equivalent results. need attribute range index, time on op:map/@ppc6_id.

watch out collations, , consider using numeric types if that's appropriate.

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' (: consider using integers instead of strings :) let $q-wijk := cts:element-attribute-range-query(   xs:qname("op:map"), xs:qname("wijk_id"),   '=', $wijk) let $ref-ppc := cts:element-attribute-reference(     xs:qname('op:map'), xs:qname('ppc6_id')) let $values-doc := cts:values(   $ref-ppc, (),   cts:and-query(     (cts:document-query('/data/map/oplage-mapping.xml'),      $q-wijk))) let $values-all := cts:values($ref-ppc, (), $q-wijk) return (count($values-doc), count($values-all)) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -