[MarkLogic Dev General] Faster alternative to fn:last()
Damon.Feldman at marklogic.com
Fri Jun 22 14:00:55 PDT 2012
Try subsequence($pageSessionLogs, count($pageSessionLogs), 1)
Anything in square brackets is evaluated once for each element of the sequence, so if you profile that you'll see something like "postion()=last()" evaluated many times - it just looks like an array index due to a syntactic sugar.
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Danny Sinang
Sent: Friday, June 22, 2012 4:24 PM
Subject: [MarkLogic Dev General] Faster alternative to fn:last()
I'm trying to get the first and last documents in a sequence. The code goes like this :
let $firstLog := $pageSessionLogs
let $lastLog := $pageSessionLogs[fn:last()]
After doing some timings, it looks like the 2nd line always takes around 30 milliseconds. And since I'm doing this in a loop, the delays add up significantly.
Is there a faster way of getting the last sequence member ?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the General