On Sun, 2020-08-23 at 14:05 -0700, Bill Osmond wrote:
Indeed I have, with no positive results unfortunately. I'm now testing to see if having multiple return statements (as in Liam's queries) helps, although the results so far are basically the same.
I tried to make clear what was going on, using explit returns, The syntax of a FLWOR expression allows either form: for $sock in /drawer/socks, $shoe in /tray/shoes is the same as for $sock in /drawer/socks for $shoe in /tray/shoes and constructs every possible (sock, shoe) pair.
However, for $sock in /drawer/socks return for $shoe in /tray/shoes return some_expression($sock, $shoe) maybe makes clearer that some_exoression() will be called count(/drawer/socks) * count(/tray/shoes) times.
the way to speed this up is likely to construct many fewer tuples, using grouping or windowing to process the inner part of your query.
Liam