A computable in a shape gets calculated for every object
on which it is defined, not just the ones that make it
through the filter, but every one. The filter may, in
fact, refer to a computable value, so it must be known
for all objects. This may be inefficient in some cases,
such as the previous example with fetching the posts
with their length and a comparison to average post
length. You can use a WITH
block to factor out some
common computations, give them names and use them later
on in a query. Let's re-write our inefficient query like
this:
The WITH
block is also very convenient if you need to
compare objects in a set to other objects in the same
set, such as "find all posts that have the same title
as another post". The WITH
block makes it easy to
define a copy of the original set to be used later in
comparisons. Try this out: