1

我的应用程序当前定义了所需的所有最佳索引。但慢慢地我开始遭受爆炸索引问题的困扰,所以我想改变我的策略并开始使用“zig-zag”合并,如此所述。

我的实体Contact有 3 个排序顺序:

  • lastModifiedASC

  • fullNameUpperCaseASC + DESC

它有 4 个过滤器:

  • contactProfile

  • contactStatus

  • contactType

  • searchFields(模拟'startsWith...'的不等式查询)

searchFields 是一个特例,因为我用它来模拟像这样的“startswith”

 query = query.filter("searchFields >= ", criteria.getSearchString().toUpperCase());
 query = query.filter("searchFields <= ", criteria.getSearchString().toUpperCase() + "\ufffd");

按照文章中的解释,我需要定义

 (number of filters + 1) * (number of orders) = 5 * 3 = 15.
  • 我的主要问题!

下面的新定义似乎在开发服务器上工作,但不是第一次。第一次应该进行 zigzag 合并的新组合时,开发服务器仍然会抛出 DatastoreNeedIndexException。第二次重复相同的查询,查询运行并返回预期的结果。在对结果进行分页时也会发生这种情况。第一次查询下一页时,抛出异常。重复作品。有人也见过这种行为吗?这是开发服务器问题还是我遗漏了什么?还是这个最初不完整的索引构建可能......例如,当我第一次组合这些过滤器时,开发服务器抱怨它作为索引丢失:

<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactProfile" direction="asc"/>
    <property name="status" direction="asc"/>
    <property name="fullNameUpperCase" direction="desc"/>
</datastore-index>

以下是实体 Contact 的新索引定义:

<!-- SORT ORDERS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="lastModified" direction="desc" />
</datastore-index>
<!-- FILTER: SEARCHFIELDS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="asc" />
    <property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="desc" />
    <property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="lastModified" direction="desc" />
    <property name="searchFields" direction="asc" />
</datastore-index>
<!-- FILTER: CONTACTSTATUS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="asc" />
    <property name="status" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="desc" />
    <property name="status" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="lastModified" direction="desc" />
    <property name="status" direction="asc" />
</datastore-index>
<!-- FILTER: CONTACTTYPE -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="asc" />
    <property name="contactType" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="desc" />
    <property name="contactType" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="lastModified" direction="desc" />
    <property name="contactType" direction="asc" />
</datastore-index>
<!-- FILTER: CONTACTPROFILE -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="asc" />
    <property name="contactProfile" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="desc" />
    <property name="contactProfile" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="lastModified" direction="desc" />
    <property name="contactProfile" direction="asc" />
</datastore-index>
4

1 回答 1

1

在我将排序顺序移动到组合索引中的最后一个属性后,它不起作用的问题得到了解决。

所以例如

<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="asc" />
    <property name="status" direction="asc" />
</datastore-index>

不得不成为。

<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="status" direction="asc" />
    <property name="fullNameUpperCase" direction="asc" />
</datastore-index>

所以最后一个属性是排序顺序。

其次,必须将 seachFields 视为排序顺序,我必须进行组合。索引现在变成 5 个排序顺序:

  • 最后修改的 ASC

  • 全名大写字母 ASC + DESC

  • 搜索字段 ASC + DESC

3个过滤器:

  • 联系方式

  • 联系状态

  • 联系人类型

    (过滤器数量 + 1)*(订单数量)= 4 * 5 = 20 个索引。

这是功能齐全的列表:

<!-- SORT ORDERS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="fullNameUpperCase" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="lastModified" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="searchFields" direction="desc" />
</datastore-index>
<!-- FILTER: CONTACTSTATUS -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="status" direction="asc" />
    <property name="fullNameUpperCase" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="status" direction="asc" />
    <property name="fullNameUpperCase" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="status" direction="asc" />
    <property name="lastModified" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="status" direction="asc" />
    <property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="status" direction="asc" />
    <property name="searchFields" direction="desc" />
</datastore-index>
<!-- FILTER: CONTACTTYPE -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactType" direction="asc" />
    <property name="fullNameUpperCase" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactType" direction="asc" />
    <property name="fullNameUpperCase" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactType" direction="asc" />
    <property name="lastModified" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactType" direction="asc" />
    <property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactType" direction="asc" />
    <property name="searchFields" direction="desc" />
</datastore-index>
<!-- FILTER: CONTACTPROFILE -->
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactProfile" direction="asc" />
    <property name="fullNameUpperCase" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactProfile" direction="asc" />
    <property name="fullNameUpperCase" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactProfile" direction="asc" />
    <property name="lastModified" direction="desc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactProfile" direction="asc" />
    <property name="searchFields" direction="asc" />
</datastore-index>
<datastore-index kind="Contact" ancestor="true" source="manual">
    <property name="contactProfile" direction="asc" />
    <property name="searchFields" direction="desc" />
</datastore-index>

PS:我删除了有关如何将生产环境迁移到新索引的附加问题,如果需要,我将发布一个新问题;

于 2013-03-06T15:13:04.963 回答