在 PostgreSQL 中使用 gin 索引时,为什么 jsonpath 查询键比查询值慢得多?

问题描述 投票:0回答:1

我有一个 PostgreSQL 14 数据库,在 jsonb 列上使用 GIN 索引来允许 jsonpath 查询。 然而,搜索 JSON 键似乎是这样的:

select *
from t
where 
"myColumn" @?? ('$.** ? ( exists(@."abc") )')

比搜索这样的 JSON 值慢得多:

select *
from t
where 
"myColumn" @?? ('$.** ? ( @.* == "abc" )')

如何提高搜索 JSON 键时的性能?

postgresql indexing jsonpath
1个回答
0
投票

我认为你的第一个公式对应于下面的“第二种”,来自“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.

所以听起来他们没有实施是因为他们认为不值得实施。

© www.soinside.com 2019 - 2024. All rights reserved.