Indexes don't work the same way they do in relational databases. If you can
fetch a value with a query, that likely means an index exists on that
property. In a relational database, when an index is not present, the
database will do a full table scan.

A fetch by Key is always fast. Have you considered storing multiple games
inside a single Game instance? Or simply storing the data you need both in
the Game instances? If you want to cut down on request latency, do as many
by key gets as possible. Don't try to approach the modeling from a
normalization perspective. How many entities are you retrieving? And have
you tried looking at what's happening via AppStats yet (
http://code.google.com/appengine/docs/java/tools/appstats.html)?

On Fri, Apr 30, 2010 at 1:54 AM, Philip Tucker <[email protected]> wrote:

> I've got a Game object that includes two PlayerGameState objects. Both
> are persistence-capable. My query fetches all PlayerGameState objects
> for a particular user, then I get the associated game and other
> player. The initial fetch is always fast, and the entire operation is
> generally lass than a second. But periodically, maybe 5 of the time,
> it takes much longer, from 5-20 seconds. It's not fetching the
> PlayerGameState objects that's slow, it's accessing
> PlagerGameState.game and Game.playerStates.
>
> I shouldn't need to add an index on the keys, should I? I'd like to
> fetch the Game objects directly but as far as I can tell we can't
> query on a joined table; ie, I can't do something like "select from
> Game, PlayerGameState join on PlayerGameState.game where
> PlayerGameState.userKey == userKeyParam".
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class Game {
>  @PrimaryKey
>  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>  private Key key;
>
>  @Persistent(mappedBy = "game")
>  @Element(dependent = "true")
>  private List<PlayerGameState> playerStates;
>
>  ...
> }
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class PlayerGameState {
>  @SuppressWarnings("unused")
>  @PrimaryKey
>  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>  private Key key;
>
>  @Persistent
>  private Key userKey;
>
>  @Persistent
>  private Game game;
>
>  ...
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>


-- 
Ikai Lan
Developer Relations, Google App Engine
Twitter: http://twitter.com/ikai
Delicious: http://delicious.com/ikailan

----------------
Google App Engine links:
Blog: http://googleappengine.blogspot.com
Twitter: http://twitter.com/app_engine
Reddit: http://www.reddit.com/r/appengine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" 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-java?hl=en.

Reply via email to