duanfa2014 2016-08-15 12:47
浏览 11
已采纳

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?

  • 写回答

1条回答 默认 最新

  • duanjia7607 2016-08-15 13:02
    关注

    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"`
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置