0

I always catch myself with this problem with Google App Engine: should I repeat data that is stored in other entities or should I make associations? What should I analyze to make this decision?

I won't use this information on searches, so it's not the "GAE join problem", it's a matter of co$t.

Right now, I have something like this rugged example:

public class GameResult
{
    private int points;
    private int duration;
    ...
}

public class Player
{
    private string name;
    private GameResult lastGameResult;

    List<int> lastGamesPoints;
}

Somehow I need to know the punctuation of the last 5 games and that's the only information I need, that is, I don't need to know other stuff about GameResult of past games. I could have this List of ints or I could have a OneToMany association of GameResults.

Roberto
  • 11,557
  • 16
  • 54
  • 68

1 Answers1

0

It really depends on your real usage and bottleneck. If you don't need to modify these data, duplicate them to different entities will be a good idea. Especially while you need to fetch these "last five results" (an query with order_by). If you use the one-to-many relation model, that mean you need to cost some CPU hour to index them first. Then you need to pay extra CPU hour on query these results. I don't think it is a good idea. Another way to do it will be use a ListProperty to store the last five GameResult entities. It implies that you can retrieve these entities with their keys which will be faster than query.

For more information, there are some great posts to read! Relational vs Non-Relational Data Modeling - what's the difference & How to think in data stores instead of databases?

Community
  • 1
  • 1
lucemia
  • 6,349
  • 5
  • 42
  • 75
  • Thank you very much. I don't need to modify these data. My example is unhappy: would you change anything in your answer if I tell you that I don't want to index the results (order_by)? See, in my real application I have a OneToMany association with GameResult that is not frequently used. But I also have a OneToMany association with an attribute from GameResult (points) that is used all the time. I'm replicating data here so I won't need to fetch a list of GameResults all the time. I'll check ListProperty and the links now. – Roberto Jul 19 '11 at 18:49
  • 1
    Base on you explanation, since you don't need to modify these data, and you need the last five scores all the time, I will recommend you to store the score directly in the Player entity! – lucemia Jul 20 '11 at 00:45