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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号