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

e0uiprwp  于 5个月前  发布在  PostgreSQL
关注(0)|答案(1)|浏览(50)

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

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

字符串
比像这样搜索JSON值要慢得多:

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


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

zqdjd7g9

zqdjd7g91#

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

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

相关问题