Hi Jakob, I suspect the predicate. You have xx[/yy], but /yy isn't restricted to descendants of xx. Instead /yy always starts at the root, even in predicates. To be more precise, you could read that as [doc()/yy], and because in MarkLogic Server doc() returns a list of *all* documents, /yy is evaluated against the entire database..
Adding a period in front of /yy should help. Your line would become: let $these_agreements := $the_agreements/*[./eoi:jurisdictions/eoi:jurisdiction eq $one_jurisdiction_code] Kind regards, Geert -----Oorspronkelijk bericht----- Van: [email protected] [mailto:[email protected]] Namens Jakob Fix Verzonden: zaterdag 7 mei 2011 17:12 Aan: General Mark Logic Developer Discussion Onderwerp: [MarkLogic Dev General] slow query/profiler question hi, I'm trying to optimize a query that runs several seconds instead of subseconds. the number of documents in the database is very small (~4000), and the documents themselves are in the sub-1K range. running the profiler on the code below shows that an inordinate amount of time is spent in this line let $these_agreements := $the_agreements/*[/eoi:jurisdictions/eoi:jurisdiction eq $one_jurisdiction_code] (btw, replacing the * with eoi:agreement which is the only root element doesn't change a thing.) profiler output (first three lines, sorted by shallow us): .main: 18 $the_agreements/eoi:agreement[/eoi:jurisdictions/eoi:jurisdiction eq $one_jurisdiction_code] 107 71 1802951 98 2482631 .main: 18 /eoi:jurisdictions/eoi:jurisdiction 335552 23 588809 23 588809 .main: 18 /eoi:jurisdictions/eoi:jurisdiction eq $one_jurisdiction_code 335552 3.6 90871 27 679680 i've created an element range index for the eoi:jurisdiction element in order to speed things up, but the result is the same. so apparently that's not the right thing. i would be grateful for a hint as to how make this query quicker. thanks, Jakob. xquery version "1.0-ml"; declare namespace eoi = "http://www.oecd.org/eoi"; import module namespace functx = "http://www.functx.com" at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy"; let $the_agreements := collection('http://www.eoi-portal.org/agreements') let $code := "DE" let $related_jurisdictions := functx:value-except( fn:collection('http://www.eoi-portal.org/agreements') /*[eoi:jurisdictions/eoi:jurisdiction eq $code]/eoi:jurisdictions/eoi:jurisdiction, ($code) ) for $one_jurisdiction_code in $related_jurisdictions (: all agreements between the two jurisdictions :) let $these_agreements := $the_agreements/*[/eoi:jurisdictions/eoi:jurisdiction eq $one_jurisdiction_code] let $is_inforce := boolean($these_agreements/eoi:enforced/text()) let $is_ratified := boolean($these_agreements/eoi:ratified/text()) let $is_signed := boolean($these_agreements/eoi:signed/text()) return ( $one_jurisdiction_code, $is_inforce, $is_ratified, $is_signed ) _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
