I accidentally sent the message prematurely.

In case #2, I simply search for the values and save the result into the map (the exact same result I now realize):
              "lowerValue" : data($context//packagedElement[@xmi:id=$currID]/ownedAttribute[@xmi:id=$propList[2 + $mult]]/lowerValue/[@value]),
              "upperValue" : data($context//packagedElement[@xmi:id=$currID]/ownedAttribute[@xmi:id=$propList[2 + $mult]]/upperValue/[@value])
Total Time: 19.98 ms

I see that I am performing the same query twice the amount of times in case #1, but I'm failing to see how this exponentially increases the time complexity.
Any explanation or reference to reading material to help me understand this situation would be greatly appreciated.

Thanks,

Jordan Castillo

On Mon, Jul 8, 2019 at 6:40 AM Jordan Castillo <jordantcastillo1992@gmail.com> wrote:
Hello BaseX Staff,

Question regarding why the time complexity of my query is dramatically different in these 2 situations. I'm building a map inside a function that is called many times, and this function receives an ID and then has to retrieve some values to store inside the map.



In case #1, I check if the values exists first, otherwise I store '()':
"lowerValue" : if (exists($context//packagedElement[@xmi:id=$currID]/ownedAttribute[@xmi:id=$propList[2 + $mult]]/lowerValue[@value]))
                             then data($context//packagedElement[@xmi:id=$currID]/ownedAttribute[@xmi:id=$propList[2 + $mult]]/lowerValue/[@value])
                             else (),
              "upperValue" : if (exists($context//packagedElement[@xmi:id=$currID]/ownedAttribute[@xmi:id=$propList[2 + $mult]]/upperValue[@value]))
                             then data($context//packagedElement[@xmi:id=$currID]/ownedAttribute[@xmi:id=$propList[2 + $mult]]/upperValue/[@value])
                             else ()
Total Time: 1526.0
In case #2: