【问题标题】:postgres - jsonb field with arbitrary json - indexing ok?postgres - 具有任意 json 的 jsonb 字段 - 索引好吗?
【发布时间】:2021-07-20 05:02:10
【问题描述】:

我有一个 postgres 表,我需要在其中存储任意键/值对,其中一些值可能是数组。看到postgres支持JSONB和Array字段类型,正在考虑用JSONB,一直reviewing the JSONB docs on indexing

我想了解的是,如果字段中存储的 json 模式越来越不同,是否可以有效地对该字段进行索引?

例如,假设我有一个表来存储插件数据,并且这些插件将被允许为每个用户存储任意数量的键。

我能否在这个字段中有效地存储数据,并让它的索引表现良好,因为

  • 插件的数量会增加,但可能会是
  • json 字段值将主要是简单的 json 对象,深一层
  • 如果有帮助,我可以完全控制每个插件的 json 架构的外观。

plugin_data

key value(JSONB) plugin_type userId
plugin.one {id:1, test:'two'} one 100
plugin.one {id:32, test:'my title'} one 102
plugin.two {schedule:52, count:5, increment:2} two 200
plugin.three {duration:10s} three 200

【问题讨论】:

    标签: postgresql jsonb


    【解决方案1】:

    是的,you can index 具有 GIN 索引的列。这将加快搜索带有??&?| 的键以及包含运算符@> 以搜索是否包含“子对象”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-10
      • 2018-08-27
      • 1970-01-01
      • 2018-06-25
      • 2017-10-14
      • 1970-01-01
      • 2020-06-01
      • 2020-05-03
      相关资源
      最近更新 更多