我想要索引index
的JSONB
字段。GIN
在这个领域内,我有一个array
of objects
。确切地说,这就是它的外观(object
用三个点缩短第二个):
[
{
"tags": ["student work", "fast apply"],
"intensity": [
{
"shift": "fulltime",
"period": "hours",
"duration": "9"
},
{
"shift": "parttime",
"period": "hours",
"duration": "4"
}
]
},
{ ... }
]
这就是我在WHERE
子句中过滤此表的方式:
items.intensity @? '$[*] ? (@.tags == "student work" || @.tags == "undefined" || @.tags.size() == 0) ? (@.intensity[*].shift == "fulltime")'
这是我试过但没有用的索引:
CREATE INDEX idxginintensitytags ON items USING GIN (intensity jsonb_path_ops);
解释分析:
# Node Rows Loops
Actual
1. Bitmap Heap Scan on items as items (rows=154922 loops=1)
Recheck Cond: (intensity @? '$[*]?(@."intensity"[*]."shift" == "fulltime")'::jsonpath)
Heap Blocks: exact=33478
154922 1
2. Bitmap Index Scan using idxginintensitytags (rows=154922 loops=1)
Index Cond: (intensity @? '$[*]?(@."intensity"[*]."shift" == "fulltime")'::jsonpath)
154922 1
我想table
按tags
、shifts
、periods
和过滤我的durations
。我有200,000 rows
。table
我怎么能index
这样field
?
我正在使用最新版本 - PostgreSQL 13
.