AppEngine数据存储区:字节分片vs数据存储区。

I require a property with a short sequence of bytes but I don't need an index on the property. The datastore.ByteString property type is meant for short sequences of bytes and is indexed whereas the normal []byte property is meant for longer sequences of bytes and is not indexed.

I'm compelled to use []byte because I don't need the index and it'll save me the extra write-cost but is it better that I use datastore.ByteString because it's meant for short values? Are there any benefits to doing so?

The type datastore.ByteString is really just a regular []byte slice, see its declaration:

type ByteString []byte

The difference is that if you have a property of type ByteString, AppEngine will try to index it by default. Since datastore index entires have limited length, the length of a ByteString value can only be max 1500 bytes to be indexable.

ByteString also doesn't have any additional methods which would add some benefit besides the indexability.

If you don't plan to index your property, simply use a []byte. If you plan to index it because you want to search / filter by it, then you must use ByteString. This can be useful if for example you want to store hashes of some content (e.g. a file), and you want to search for a file based on its content hash. In this case a ByteString makes perfect sense and is most compact (compared to an alternative where you would store the hash as a string being the hexadecimal representation).

Note that even if you use ByteString, you can still make the property unindexed by using tags, e.g.:

type MyEntity struct {
    Something datastore.ByteString `datastore:"something,noindex"`
}