2013-03-05 40 views
1

我的應用程序當前定義了所有需要的最佳索引。但是慢慢地,我開始受到爆炸性索引問題的困擾,所以我想切換我的策略並開始使用「zig-zag」合併,如解釋here移動到ZIG ZAG合併與最佳索引

我的實體Contact有3個排序順序:

  • lastModified ASC

  • fullNameUpperCase 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> 

回答

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

  • fullNameUpperCase ASC + DESC

  • searchFields ASC + DESC

3過濾器:

  • contactProfile

  • contactStatus

  • contactType

    (+ 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:我刪除了有關如何遷移生產環境,以新的索引其他問題,我將張貼在需要的情況下,一個新的問題;

+0

嘿,你能讓我知道你是如何將生產環境遷移到新的指數的? – morpheus 2013-09-23 18:42:20

+0

@morpheus只需添加曲折合併所需的索引,等待它們構建。稍後,您可以使用「appcfg vacuum_indexes」刪除舊的未使用的索引 – koma 2013-09-24 09:01:48