当我在数据存储查询中使用 objectify first() 方法时我支付了多少实体

How many entities I pay when I use objectify first() method in datastore queries

我知道对于任何查询,Datastore 定价配额都基于检索到的实体数量。现在,如果我使用 objectify 编写这样或类似的查询:

Car car = ofy().load().type(Car.class).filter("vin >", "123456789").first().now();

我是为查询选择的 vin > 123456789 的任何实体付费,还是仅为我实际检索的第一个实体付费?

关于索引的数据存储文档是这样说的:

  1. Identifies the index corresponding to the query's kind, filter properties, filter operators, and sort orders.
  2. Scans from the beginning of the index to the first entity that meets all of the query's filter conditions.
  3. Continues scanning the index, returning each entity in turn, until it
    • encounters an entity that does not meet the filter conditions, or
    • reaches the end of the index, or
    • has collected the maximum number of results requested by the query.

(source documentation)

由于查询请求的最大结果数为 1,因此您只有一次索引扫描和一次读取,您将为此付费。

请注意索引是有序的,因此这将是一个非常短的索引扫描和一个非常小的操作。

另一方面,您没有在查询中指定顺序。因此,从技术上讲,结果可以是任何符合查询条件的实体。通常您会想要限定范围内的最大或最小值或任何值。由于索引是有序的,您应该根据索引顺序(升序或降序)获取索引中的第一个实体。