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 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下