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

atownsen at wiley.co.uk atownsen at wiley.co.uk
Fri Oct 22 12:19:08 PDT 2004




Hi Darin,

Yes I had tried fn:item-at() and it is treated exactly the same as [ ] .  I
imagine that all the short-hand notation gets normalized by the parser
before any real processing is done.
|+----------------------+------------------------------------------------|
||   "McBeath, Darin W. |                                                |
||   (ELS)"             |           To:        "'atownsen at wiley.co.uk '" |
||   <D.McBeath at elsevier|   <atownsen at wiley.co.uk>,                      |
||   .com>              |   "'general-bounces at xqzone.marklogic.com '"    |
||                      |   <general-bounces at xqzone.marklogic.com>,      |
||   10/22/04 06:06 PM  |   "'general at xqzone.marklogic.com '"            |
||                      |   <general at xqzone.marklogic.com>               |
||                      |           cc:                                  |
||                      |           Subject:        RE: [XQZone General] |
||                      |   Performance of index (position) access and   |
||                      |   g        etting to preceding nodes           |
|+----------------------+------------------------------------------------|







oops, ignore my previous comment ... didn't read far enough down your note.

You may want to try the item-at xpath function but I would have thought []
would have normalized to that.

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






More information about the General mailing list