我有一个 PostgreSQL 14 数据库,在 jsonb 列上使用 GIN 索引来允许 jsonpath 查询。 然而,搜索 JSON 键似乎是这样的:
select *
from t
where
"myColumn" @?? ('$.** ? ( exists(@."abc") )')
比搜索这样的 JSON 值慢得多:
select *
from t
where
"myColumn" @?? ('$.** ? ( @.* == "abc" )')
如何提高搜索 JSON 键时的性能?
我认为你的第一个公式对应于下面的“第二种”,来自“src/backend/utils/adt/jsonb_gin.c”:
* [...] jsonb_ops might also support statements of the 2nd kind,
* but given we have no statistics keys extracted from accessors chain
* are likely non-selective. Therefore, we choose to not confuse optimizer
* and skip statements of the 2nd kind altogether. In future versions that
* might be changed.
所以听起来他们没有实施是因为他们认为不值得实施。