如何在postgresql中使用gin索引在jsonb列上运行GROUPBY查询?
我有一个表,其中一列名为data,格式为jsonb。 我在此列上创建了一个索引 我想让postgres在执行GROUPBY子句时使用gin索引。 此查询的正确语法是什么? 下面是数据列中的一个示例条目如何在postgresql中使用gin索引在jsonb列上运行GROUPBY查询?,postgresql,indexing,group-by,jsonb,Postgresql,Indexing,Group By,Jsonb,我有一个表,其中一列名为data,格式为jsonb。 我在此列上创建了一个索引 我想让postgres在执行GROUPBY子句时使用gin索引。 此查询的正确语法是什么? 下面是数据列中的一个示例条目 {"firstname": "Bob", "lastname": "Smith", "home_zip": "11234"} 我已经试过了,但是当我运行这个查询时,postgr
{"firstname": "Bob", "lastname": "Smith", "home_zip": "11234"}
我已经试过了,但是当我运行这个查询时,postgres没有使用gin索引
explain analyze select data#>'{home_zip}',count(*) from contacts group by data#>'{home_zip}'
Gin索引不支持
can_order
,因此不能用于加速group by(除了通过加速WHERE子句来为group by提供数据)
您可以通过以下方式使用表达式索引加速此过程:
create index on contacts btree ((data #> '{home_zip}'))