1
<datastore-index kind="Environment" ancestor="false">
    <property name="active" direction="asc" />
    <property name="consumed" direction="asc" />
</datastore-index>

<datastore-index kind="Environment" ancestor="false">
    <property name="active" direction="asc" />
    <property name="creationDate" direction="desc" />
</datastore-index>

我有以上两个索引

当我如下查询时,它不起作用,并且说需要新索引。

SELECT * FROM Environment
where active = false and consumed = true and creationDate < '2013-09-22'

GQL 响应如下:

没有找到匹配的索引。此查询的建议索引是:

<datastore-index kind="Environment" ancestor="false">
   <property name="active" direction="asc" />
   <property name="consumed" direction="asc" />
   <property name="creationDate" direction="asc" />
</datastore-index>

我究竟做错了什么?它不应该基于之字形合并工作吗?

4

1 回答 1

1

在查看 zigzag 查询需要哪些索引时,将索引拆分为前缀和后缀非常有用。索引的前缀用于回答等式,而后缀用于回答不等式和排序。

为了执行合并连接,查询中涉及的所有索引的后缀必须匹配,以便排序顺序相同。因此,对于您的查询:

SELECT * FROM Environment where active = false and consumed = true and creationDate < '2013-09-22'

creationDate必须在后缀中;active并且consumed必须在前缀中。

指数:

<datastore-index kind="Environment" ancestor="false">
   <property name="active" direction="asc" />
   <property name="consumed" direction="asc" />
   <property name="creationDate" direction="asc" />
</datastore-index>

如果我们将索引拆分为 和 之间的前缀和后缀,就可以满足这个consumed要求creationDate。但是,您也可以使用两个单独的索引来满足这一点:

<datastore-index kind="Environment" ancestor="false">
   <property name="active" direction="asc" />
   <property name="creationDate" direction="asc" />
</datastore-index>

<datastore-index kind="Environment" ancestor="false">
   <property name="consumed" direction="asc" />
   <property name="creationDate" direction="asc" />
</datastore-index>

在这种情况下,后缀将包含creationDate,前缀将分别是activeconsumed。请注意,在这种情况下,两个索引中的后缀如何匹配,这是执行 zigzag 合并连接的要求。

对于您当前拥有的索引,无法回答查询,因为

<datastore-index kind="Environment" ancestor="false">
    <property name="active" direction="asc" />
    <property name="consumed" direction="asc" />
</datastore-index>

没有creationDate作为后缀。

于 2015-10-14T06:13:27.037 回答