Appengine ZigZag Merge加入Algo

时间:2013-06-30 01:56:38

标签: google-app-engine google-cloud-datastore

我对zigzag合并连接算法有疑问。在文章https://developers.google.com/appengine/articles/indexselection中提到了

Index(Photo, owner_id, -date), 
Index(Photo, size, -date)

可以合并成为

Index(Photo, owner_id, size, -date) ;

我的测试如下:

  <datastore-index kind="KindTest1" ancestor="false" source="auto">
        <property name="hideIt" direction="asc"/>
        <property name="voteCount" direction="desc"/>
    </datastore-index>

    <datastore-index kind="KindTest1" ancestor="false" source="auto">
        <property name="hideIt" direction="asc"/>
        <property name="createdByDate" direction="asc"/>
    </datastore-index>

can these 2 indexes combine to become,

    <datastore-index kind="KindTest1" ancestor="false" source="auto">
        <property name="hideIt" direction="asc"/>
        <property name="createdByDate" direction="asc"/>
        <property name="voteCount" direction="desc"/>
    </datastore-index>

原因我给你发电子邮件是因为当我在开发和生产上尝试这个时,它不起作用并且需要有每个单独的索引。可以详细说明吗?

1 个答案:

答案 0 :(得分:4)

应用引擎中的Z字形合并连接算法通过组合扫描由相同属性排序的单独较小索引得到的结果,有助于减少所需索引,从而提供这些索引共有的结果。因此,在google文档中给出的示例中,owner_id上的索引在date(desc)上排序顺序,size上的索引具有与date(desc)相同的排序顺序。因此,对于这两个属性以及相同的排序顺序日期(desc)进行查询,可以避免额外的组合索引,因为之字形合并将使用2个单独的索引查找结果。

在您的示例中,2个索引无法组合,因为它们未在同一属性上排序,因此对于您的查询,您将需要相应的索引。我将使用您的数据给出一个虚构的示例,其中可以使用zigzag merge join:

         

         

如果您的2个索引如上所述,那么它们都按hideIt(asc)排序,那么如果您对voteCount,createdByDate,hideIt进行查询,那么您不需要为此组合添加额外索引,并且2个现有索引将为你的目的服务。