我的應用程序當前定義了所有需要的最佳索引。但是慢慢地,我開始受到爆炸性索引問題的困擾,所以我想切換我的策略並開始使用「zig-zag」合併,如解釋here。移動到ZIG ZAG合併與最佳索引
我的實體Contact
有3個排序順序:
lastModified
ASCfullNameUpperCase
ASC + 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.
- 我的主要問題!:
下新的定義似乎開發服務器,但不是第一次上工作。第一次它應該做新的曲折合併的組合,devserver仍然拋出DatastoreNeedIndexException。第二次重複相同的查詢,查詢運行並返回預期結果。分頁瀏覽結果時也會發生這種情況。我第一次查詢下一頁時,拋出異常。重複作品。有人也看到過這種行爲嗎?這是devserver問題還是我錯過了什麼?或者,這種索引建立起初可能是不完整的,例如,在devserver抱怨,這是缺少作爲索引我第一次結合這些過濾器:
<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>
下面是實體聯繫新的索引定義:
<!-- 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>
嘿,你能讓我知道你是如何將生產環境遷移到新的指數的? – morpheus 2013-09-23 18:42:20
@morpheus只需添加曲折合併所需的索引,等待它們構建。稍後,您可以使用「appcfg vacuum_indexes」刪除舊的未使用的索引 – koma 2013-09-24 09:01:48