A little late on this thread, but I think I can explain why the initial
predicate change (removing "/") didn't make much difference.

"/" in a predicate is interpreted as "root of the tree containing the
context node." That's true in both 1.0 and 1.0-ml. When a context node is
not defined, "/" throws an error in 1.0 but it's shorthand for
collection() in 1.0-ml.

To illustrate:

count(collection()),     (: number of docs in database :)
count(/),                (: number of docs in database, in 1.0-ml :)
collection()[1]/count(/) (: evaluates to 1 :)

$some-element/(/) is another (peculiar) way of writing root($some-element)

So you don't have to worry about "/" selecting all docs in the database
when inside a predicate that filters a node sequence. In fact, it looks
like you don't *ever* have to worry about "/" selecting all documents
inside a predicate:

xquery version "1.0-ml";
("foo","bar")[/]


For me this yields what you'd expect in 1.0:

(err:XPTY0020) Context item is not a node



Evan



On 5/7/11 10:41 AM, "Jakob Fix" <[email protected]> wrote:

>Hi Geert, thanks for your quick answer.
>
>indeed the [/xx] predicate was not very clever! unfortunately, neither
>[xx] nor [./xx] changed anything remarkably:
>
>.main:  
>18     $the_agreements/eoi:agreement[eoi:jurisdictions/eoi:jurisdiction
>= $one_jurisdiction_code]      107     43      1864521 98      4285062
>.main:  18     eoi:jurisdictions/eoi:jurisdiction =
>$one_jurisdiction_code 335552  35      1520765 55      2420541
>.main:  18     eoi:jurisdictions/eoi:jurisdiction      335552  21      899776  
>21      899776
>
>all in all it takes more than 4 seconds, so i'm sure there's something
>that can be tweaked. ;-)
>
>cheers,
>Jakob.
>
>
>
>
>On Sat, May 7, 2011 at 15:52, Geert Josten <[email protected]>
>wrote:
>> 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
>>
>_______________________________________________
>General mailing list
>[email protected]
>http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to