Hi Alex,
  Some responses inline.


On Mon, Jun 20, 2011 at 10:41, Alex-S <[email protected]> wrote:
> Hi Google App Engine team,
>
>
> Lets say I have an Entity with a few properties:
>
> @Entity
> public class Animal{
>
>  private String domain;
>  private String kingdom;
>  private String phylum;
>  private String class;
>  private String order;
>  private String family;
>  private String genus;
>  private String species;
>  private String classifier;
>
>  private Date classifiedDate;
>  private Date dateEntered;
>
>  //getters + setters ...
>
> }
>
> If I want to search on say, domain, kingdom, class and dateEntered
> with equality google docs suggest I don't need an index, but strangely
> on some values - dateEntered = 2007 + any value of the properties I
> get
> DatastoreNeedIndexException but not for  dateEntered = 2006 or 2008. I
> would have expected to get the error for all values where an index was
> not in place or no error at all. Have i done something wrong here?

This is using a merge-join.  Basically it is scanning each single
property index, getting the matching results, and finding the
intersection between them.  In some cases this is very inefficient,
for example this might happen if 2007 has many results that must be
checked against the other indexes.

Defining an index will make this query much faster at read time, but
slightly increase your write cost.


>
> Also is it true that I need to specify an index (ok even auto
> generated) for every query where a sort order is specified?

When multiple properties are used, yes.

>
> so for instance if I want to query on any domain=something ordered by
> classifiedDate descending that's one index:
>    <datastore-index kind="Animal" ancestor="false" >
>        <property name="domain" direction="asc"/>
>        <property name="classifiedDate " direction="desc"/>
>    </datastore-index>
>
> but if I wanted to query on any domain=something and
> kingdom=otherThing ordered by classifiedDate  that would be two
> indexs:

No, IIRC you just need one index in this case.

>   <datastore-index kind="Animal" ancestor="false" >
>        <property name="domain" direction="asc"/>
>        <property name="kingdom" direction="asc"/>
>        <property name="classifiedDate " direction="desc"/>
>    </datastore-index>
>
>   <datastore-index kind="Animal" ancestor="false" >
>        <property name="kingdom" direction="asc"/>
>        <property name="domain" direction="asc"/>
>        <property name="classifiedDate " direction="desc"/>
>    </datastore-index>
>
> because app engine treats property ordering as important?

I don't believe this is currently the case.  However, as I recall
there was some mention that this might be the case in the future --
but I'm not 100% sure about that.


>
> I guess I could always order the query properties myself to ensure no
> index is duplicated and then for small numbers of properties this
> isn't too bad.
>
> If I wanted to optionally search for kingdoms or domains or both
> ordered by classifiedDate   the index definition would be
>    <datastore-index kind="Animal" ancestor="false" >
>        <property name="domain" direction="asc"/>
>        <property name="classifiedDate " direction="desc"/>
>    </datastore-index>
>    <datastore-index kind="Animal" ancestor="false" >
>        <property name="kingdom" direction="asc"/>
>        <property name="classifiedDate " direction="desc"/>
>    </datastore-index>
>  <datastore-index kind="Animal" ancestor="false" >
>        <property name="domain" direction="asc"/>
>        <property name="kingdom" direction="asc"/>
>        <property name="classifiedDate " direction="desc"/>
>    </datastore-index>
>
> But, If I wanted to search on any combination of, say, 3 properties +
> an order field this would be some 8 index definitions,
>
> 5 properties + an order would mean 32 definitions.

Yes, you might need to define a lot of indexes if you're optionally
querying on many combinations of properties.  If they are largely
equality filters you might be able to use list properties to help a
little, but the order introduces some other complexities with that.

Check out the mastering the datastore articles.  They are quite
helpful, though a bit dated.
  http://code.google.com/appengine/articles/datastore/overview.html


Robert



>
> 9 entity properties and order on classifiedDate would be some 512(!!)
> different index definitions. If I wanted ascending as well as
> descending order on classifiedDate  then I have to double that - 1024
> definitions. and if I wanted to order on the query (optionally) as
> dateEntered  ascending or descending instead then thats double again
> -  2048. These seems crazy just to query on 9 difference properties.
> Or have I got it badly wrong?
>
> Can I just create the  4 indexes  :
>     <datastore-index kind="Animal" ancestor="false" >
>        <property name="classifiedDate " direction="desc"/>
>    </datastore-index>
>
>       <datastore-index kind="Animal" ancestor="false" >
>        <property name="classifiedDate " direction="asc"/>
>    </datastore-index>
>
>    <datastore-index kind="Animal" ancestor="false" >
>        <property name="dateEntered " direction="desc"/>
>    </datastore-index>
>
>    <datastore-index kind="Animal" ancestor="false" >
>        <property name="dateEntered " direction="asc"/>
>    </datastore-index>
>
> if I'm doing only equality filters for 9 other fields? Obviously I
> don't care about ordering results which will always be
> ="someEnteredValue".
>
> cheers,
> Alex.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to