views:

694

answers:

3

Since Google App Engine doesn't permit joins, does this mean that I have to take all of the tables in my web app and figure out a way of combining them into a single huge table?

+2  A: 

Combining it to one big table is always an option, but it results unnecessarily large and redundant tables most of the time, thus it will make your app slow and hard to maintain.

You can also emulate a join, by iterating through the results of a query, and running a second query for each result found for the first query. If you have the SQL query

SELECT a.x FROM b INNER JOIN a ON a.y=b.y;

you can emulate this with something like this:

for b in db.GqlQuery("SELECT * FROM b"):
  for a in db.GqlQuery("SELECT * FROM a WHERE y=:1", b.y):
    print a.x
pts
App Engine uses GQL which has a very basic subset of SQL syntax. I'm not 100% sure but I believe your SQL example would not work.
Chris Collins
Yes, GQL is less powerful than SQL, but powerful enough so my example will work. See http://code.google.com/appengine/docs/python/datastore/gqlreference.html
pts
A: 

Switching from a relational database to the App Engine Datastore requires a paradigm shift for developers when modeling their data. Take a look here to get a better idea. This will require you to think more up front about how to fit your problem into the constraints the datastore imposes, but if you can then you are guaranteed that it will run quickly and scale.

TomS
+2  A: 

Just because you don't have joins implemented by the DBMS doesn't mean you can't have multiple tables. In App Engine, these are called 'entity types', and you can have as many of them as you want.

Generally, you need to denormalize your data in order to avoid the need for frequent joins. In the few situations where they're inevitable, you can use other techniques, like doing the join in user code.

Nick Johnson