我对之字形合并连接算法有疑问。在文章中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>
之所以给您发送电子邮件,是因为当我在开发和生产环境中尝试这样做时,它不起作用并且需要每个单独的索引。能详细点吗?
最佳答案
App Engine 中的之字形合并联接算法有助于减少所需的索引,方法是组合通过扫描按相同属性排序的单独较小索引得出的结果,以提供这些索引共有的结果。因此,在 google 文档中给出的示例中,owner_id
上的索引在 date(desc)
上有排序顺序,在 size
上有索引具有与 date(desc)
相同的排序顺序。因此,要对这两个属性以及相同的排序顺序日期 (desc) 进行查询,可以避免使用额外的组合索引,因为之字形合并将使用 2 个单独的索引找到结果。
在您的示例中,这 2 个索引不能合并,因为它们未按同一属性排序,因此对于您的查询,您将需要一个相应的索引。我将使用您的数据给出一个虚构的示例,其中可以使用之字形合并连接:
如果你的 2 个索引像上面一样,都是按 hideIt(asc)
排序的,那么如果你有一个关于 voteCount,createdByDate,hideIt
的查询,那么你不需要此组合需要一个额外的索引,而 2 个现有索引将满足您的目的。
关于google-app-engine - Appengine ZigZag Merge Join Algo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17386409/