Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在postgresql中使用gin索引在jsonb列上运行GROUPBY查询?_Postgresql_Indexing_Group By_Jsonb - Fatal编程技术网

如何在postgresql中使用gin索引在jsonb列上运行GROUPBY查询?

如何在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

我有一个表,其中一列名为data,格式为jsonb。 我在此列上创建了一个索引

我想让postgres在执行GROUPBY子句时使用gin索引。 此查询的正确语法是什么? 下面是数据列中的一个示例条目

{"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}'))