Is the XTQL pipeline operator lazy?

Copying a question from @/mmer on the Clojurians Slack:

With the XTQL, I am slightly puzzled by the threaded forms using the from function. If you build up a set of functions that in effect make up the parts of the query, does this rely on a lazy model to know what to pass down the threaded functions. It looks rather strange when compared with a sub query as in that case the sub query probably fires first and then the outer query, but in the threaded forms I have seen it does not seem to apply that way, or am I missing something?

Answer:

The -> “pipeline” operator in the Clojure XTQL syntax is not really the same as the Clojure threading macro at all (it’s not actually a macro) - and therefore it isn’t lazy. XTDB optimizes the query globally and (currently) compiles a single execution plan, so the pipeline isn’t evaluated/interpreted separately from the rest of the query or anything like that.

It looks rather strange when compared with a sub query as in that case the sub query probably fires first and then the outer query,

Actually thanks to “subquery decorrelation” a lot of subqueries can be translated into joins, which execute more efficiently, so you can’t make any assumptions about how the final execution works looking at the query isolation (and in this sense XTQL is very much like SQL, with query plans you can EXPLAIN).

Hope that helps!