【问题标题】:Appengine ZigZag Merge Join AlgoAppengine ZigZag 合并加入算法
【发布时间】:2013-06-30 01:56:37
【问题描述】:

我对 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>

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

【问题讨论】:

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


    【解决方案1】:

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

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

    如果您的 2 个索引与上面一样,都按 hideIt(asc) 排序,那么如果您对 voteCount,createdByDate,hideIt 有查询,那么您不需要针对此组合的附加索引,并且 2 个现有索引将满足您的目的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      相关资源
      最近更新 更多