GAE 存储密钥与 StringID
在 Google App Engine 数据存储中存储键比字符串有优势吗?
例如:
class Model(ndb.Model):
user_key = ndb.KeyProperty()
VS
class Model(ndb.Model):
user_id = ndb.StringProperty()
- 为什么要存储 Key 而不是 StringID?难道只是为了方便吗?
- 哪个使用的存储空间更少?
- 哪个查询速度更快?
Are there advantages to storing Keys over String in Google App Engine datastore.
For example:
class Model(ndb.Model):
user_key = ndb.KeyProperty()
VS
class Model(ndb.Model):
user_id = ndb.StringProperty()
- Why would you want to store a Key instead of the StringID? Is it only for convenience?
- Which uses less storage space?
- Which is faster to query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用实体组(祖先), KeyProperty 将支持这一点。存储 id 时,除非您存储的 id 模型是实体组根,否则您需要存储足够的信息来重建完整密钥。
KeyProperty 将占用更多空间,因为它存储附加数据,但在检索其他实体时使用起来可能更方便。查询速度应该是可比的。
If you're using entity groups (ancestors), the KeyProperty will support that. When storing the id, unless the model who's id you're storing is the entity group root, you'll need to store enough info reconstruct the full key.
The KeyProperty will take more space, since it is storing additional data, but it may be more convenient to use when retrieving the other entity. Query speed should be comparable.