【发布时间】: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