Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

What is the maximum number of characters that can be used to define the key_name of a datastore entity?

Is it bad to have very long key_names?

For example: Lets say we use key_names of a 170 characters, which is the length of a Twitter message 140 plus 10 numeric characters for latitude and 10 for longtitude and 10 for a timestamp.

(Reasoning of such a key_name: So by using such a key_name we can easily and quickly be sure of no duplicate postings, since the same message should not come from the same place and time more than once.)

like image 658
b_dev Avatar asked Apr 01 '10 01:04

b_dev


People also ask

What is an entity in Datastore?

Data objects in Datastore are known as entities. An entity has one or more named properties, each of which can have one or more values. Entities of the same kind do not need to have the same properties, and an entity's values for a given property do not all need to be of the same data type.

How do I remove all entities from datastore?

Open "Datastore Admin" for your application and enable Admin. Then all of your entities will be listed with check boxes. You can simply select the unwanted entites and delete them. Save this answer.

What is data store in Google App Engine?

Datastore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. Datastore features include: Atomic transactions. Datastore can execute a set of operations where either all succeed, or none occur.


2 Answers

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

like image 77
ryan Avatar answered Oct 31 '22 00:10

ryan


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.

like image 20
Nick Johnson Avatar answered Oct 30 '22 23:10

Nick Johnson