开发者

Why is there no unique constraint in Google Appengine?

I have seen many articles and questions about how to implement a unique constraint in appengine, but I actually didn't found any explanation about why this feature is not presen开发者_开发知识库t.

If appengine developers considered it would be better not to implement such a feature, i believe they had good reasons, but i'd be interested in understanding why they decided so.

Was this decision guided by performance concerns? Why?

Any detailed explanation about this would be greatly appreciated.


As that post linked here http://code.google.com/p/googleappengine/issues/detail?id=178#c14 says, the distributed nature of datastore makes it difficult to enforce a unique constraint. If two app instances simultaneously try to create an entity, each with a property that should be unique, the only way to enforce this would require some kind of coordination throughout all machines in the datastore.

Imagine a room of 26 people each with a piece of paper, say with a table of pets and their owners. Each person controls every pet with a different letter of the alphabet, e.g. person 1 does everything starting with the letter A, person 2 does all the things starting with the letter B, and so on.

If you wanted to make sure that a pet named mittens was the only mittens in the entire datastore, this is easy because only one person in the room will be involved, and they will be able to check their piece of paper to make sure that mittens isn't already there.

If you wanted to require that owners must be unique too, you can imagine that every time someone wants to write an entry in their table, they need to check with /every single other person/ to make sure that nobody else has that owner name used. This is the fundamental reason that app engine's datastore does not allow uniqueness constraints on anything except entity keys. It would simply not be possible to do it when the datastore contains thousands of servers.

Hopefully you can see why this limitation exists, and hopefully my late-night typing isn't too difficult to read :D


You can see a response from Google on adding unique constraints on their issue list for GAE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜