[XQZone General] Performance of index (position) access and g etting to preceding nodes

Matt Corkum m.corkum at elsevier.com
Fri Oct 22 14:30:28 PDT 2004


Darin,

I always found using any index into a list to be dreadfully slow...in 
the items-1 part predicate listed below.

Matt

McBeath, Darin W. (ELS) wrote:

>Just a tought, but did you think of trying the following:
>
>let $items := //items
>for $item at $index in $items
>return
>        if ($index> 1) then
>                (xdmp:path($item),xdmp:path($items[$index - 1]))
>        else
>                xdmp:path($item) 
>
>-----Original Message-----
>From: general-bounces at xqzone.marklogic.com
>To: general at xqzone.marklogic.com
>Sent: 10/22/2004 7:53 AM
>Subject: [XQZone General] Performance of index (position) access and getting
>to preceding nodes
>
>
>
>Hi Folks,
>
>I'm just getting started with CIS after an enjoyable User Conference and
>I
>have a couple of related questions:
>
>Is there an efficient way when processing a sequence to access other
>nodes
>in the sequence?  (especially preceding or next nodes).
>I have tried to use indexed/positional access but this seems to be very
>(very) slow.
>
>For instance, using example queries to illustrate the thought -
>
>XQuery 1:
>for $item at $index in //items
>return
>        xdmp:path($item)
>
>This iterates through, setting the context to each item in //items and
>executes very quickly - as I expected, whereas the following,
>illustrating
>access to the preceding node.......
>
>XQuery 2:
>for $item at $index in //items
>return
>        if ($index> 1) then
>                (xdmp:path($p),xdmp:path($items[$index - 1]))
>        else
>                xdmp:path($p)
>
>... runs very very slowly even for small lists.   XQuery 1 is often
>sub-second while XQuery 2 for 80 items takes about 8 seconds and for 600
>items about a minute, bigger lists just take forever.
>
>It appears to me that it is the access via index/position that is
>slow.  Testing with the following obviously daft query
>
>Query 3:
>let $items := //items
>for $item at $index in $items
>return
>        xdp:path($items[$index])
>
>This takes the same length of time as XQuery 2.
>
>It looks almost like the expressions are being fully re-evaluated, i.e.
>//items[1] .. //items[n] rather than using a previously determined "in
>memory" list. To test this I tried the even dafter XQuery:
>
>XQuery 4:
>let $items := //items
>for $item at $index in $items
>return
>        xdp:path((//items)[$index])
>
>and the timings matched XQuery3, reinforcing my "re-evaluation" thought.
>
>I've tried some other approaches though XQuery scoping seems to stop me
>simply saving a node for later use.
>
>So.....  any thoughts or guidance on:
>
>i) What is going on and why is this form of indexed access so slow?
>ii) Is there an easier (i.e. much faster) way to access other nodes in a
>given sequence while handling that sequence?
>iii) What 'obvious' XQuery technique to this have I clearly yet to
>discover?  :-)
>
>Thanks in advance,
>
>Andy
>
>_______________________________________________
>General mailing list
>General at xqzone.marklogic.com
>http://xqzone.com/mailman/listinfo/general
>_______________________________________________
>General mailing list
>General at xqzone.marklogic.com
>http://xqzone.com/mailman/listinfo/general
>
>  
>

-- 
take care,
Matt Corkum

m.corkum at elsevier.com

6 BullMoose Run
Hopkinton, Ma. 01748

508 625 1067





More information about the General mailing list