问题
I have question on zigzag merge join algorithm. In article https://developers.google.com/appengine/articles/indexselection , mentioned
Index(Photo, owner_id, -date),
Index(Photo, size, -date)
can be combine to become
Index(Photo, owner_id, size, -date) ;
My test below:
<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>
Reason I email you because when i try this on dev and production, it does not work and required to have each separate indexes. Can elaborate more ?
回答1:
The zig-zag merge join algorithm in app engine helps to reduce the required indexes by combining the results derived by scanning separate smaller indexes that are sorted by the same property, to give results that are common to these indexes. So in the example given in the google documentation, the index on owner_id
is having a sort order on date(desc)
and the index on size
is having the same sort order of date(desc)
. Hence for doing a query on both these properties together with same sort order date(desc), an additional combined index can be avoided, as zigzag merge will find the results using the 2 separate indexes.
In your example, the 2 indexes cannot be combined as they are not sorted on the same property and hence for your query you will need a corresponding index. I will give a fictious example using your data, where zigzag merge join can be utilised :
If your 2 indexes were like above, that is both sorted by hideIt(asc)
, then if you have a query on voteCount,createdByDate,hideIt
then you dont need an additional index for this combination and the 2 existing indexes will serve your purpose.
来源:https://stackoverflow.com/questions/17386409/appengine-zigzag-merge-join-algo