0

我有一个关于为什么 Google App Engine 的数据存储区使用密钥和 ID 的问题。来自关系数据库背景,我正在将实体与行进行比较,那么为什么在存储实体时需要一个键(这是一个自动生成的长字符串)和一个 ID(可以手动或自动输入)?这似乎是对识别记录的巨大空间浪费。我再次对这种类型的数据库不熟悉,所以我可能会遗漏一些东西。

4

2 回答 2

1

Key design is a critical part of efficient Datastore operations. The keys are what are stored in the built-in and custom indexes and when you are querying, you can ask to have only keys returned (in Python: keys_only=True). A keys-only query costs a fraction of a regular query, both in $$ and to a lesser extent in time, and has very low deserialization overhead.

So, if you have useful/interesting things stored in your key id's, you can perform keys-only queries and get back lots of useful data in a hurry and very cheaply.

Note that this extends into parent keys and namespaces, which are all part of the key and therefore additional places you can "store" useful data and retrieve all of it with keys-only queries.

It's an important optimization to understand and a big part of our overall design.

于 2013-03-27T14:46:56.710 回答
0

基本上,密钥是由两条信息构成的:

  • 实体类型(在Objectify中是对象的类)
  • 实体的 ID/名称

因此,对于给定的实体类型,key 和 id 完全相同。

如果您自己不指定 ID,则会生成一个随机 ID,并根据该随机 ID 创建密钥。

于 2013-03-27T04:31:31.620 回答