有时我们需要去限制从一个查询语所返回的结果的数量,特别是在处理一些大型的图的时候。如下面的例子所示,可以使用limit和tail步骤达成这一目标。在本书稍靠后一些,我们将介绍到coin步骤,这个步骤允许伪随机样本数据被返回。
It is sometimes useful, especially when dealing with large graphs, to limit the amount of data that is
returned from a query. As shown in the examples below, this can be done using the limit and tail
steps. A little later in this book we also introduce the coin step that allows a pseudo random sample
of the data to be returned.
取决于执行的情况,有时这样写查询语句更有效。limit 步骤出现在value之前,从而保持更少的顶点返回。但是执行很有可能会按相同的方式来优化。
Depending upon the implementation, it is probably more efficient to write the query like this, with
limit coming before values to guarantee fewer airports are initially returned but it is also possible
that an implementation would optimize both the same way.
提示:limit提供对range步骤的简写。上面最开始的两个例子也可以写成下面这样。
Note that limit provides a shorthand alternative to range. The first of the two examples above could have been written as follows.
我们也可以通过指定允许运行的最大数量来限制一个遍历。下面的查询限制了最长时间是10 毫秒 这个查询检索的是从Austin到 LHR的航线。在本书稍后内容中,这个查询的各个部分都会详细地解释。在笔者看来,它们做的事相当的清晰。 repeat步骤将在本书“机场之间的最短路径-- repeat步骤介绍”一节中解释。
We can also limit a traversal by specifying a maximum amount of time that it is allowed to run for.
The following query is restricted to a maximum limit of ten milliseconds. The query looks for routes
from Austin (AUS) to London Heathrow (LHR). All the parts of this query are explained in detail
later on in this book but I think what they do is fairly clear. The repeat step is explained in detail in
the "Shortest paths (between airports) - introducing repeat" section.
这是上面的查询句语运行返回的。
Here is what the query above returned when run on my laptop.
如果我们给再给查询10毫秒杀,总计是20毫秒,您会看到更多的航线被发现了。
If we give the query another 10 milliseconds to run, so 20 in total, you can see that a few more routes were found.
浙公网安备 33010602011771号