How long (max characters) can a datastore entity key_name be? Is it bad to haver very long key_names?

隐身守侯 提交于 2019-11-29 05:30:42

There's no hard maximum - the maximum length of a key name is the maximum length of a key, less some overhead, and keys can get pretty long.

It is bad to have very long key names, however: Apart from storing and retrieving it, every index entry contains the key name it's referring to, so longer key names mean higher indexing overhead. If you want to ensure uniqueness over a large text, your best option is to make the key name the MD5 or SHA1 sum of the input, which ensures both uniqueness and a short(-ish) key name.

actually, key names are limited to 500 characters just like string property values. see e.g. Key.to_path(), which calls ValidateString():

http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/api/datastore_types.py#413

which defaults max_len to _MAX_STRING_LENGTH, which is 500:

http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/api/datastore_types.py#87

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!