使用Postgres 9.4,我想在json列上创建一个索引,在搜索列中的特定键时将使用该索引.
例如,我有一个带有json列"animals"的"farm"表.
"动物"列包含通用格式的json对象:
'{"cow": 2, "chicken": 11, "horse": 3}'
我try 了许多索引(分别):
create INDEX animal_index ON farm ((animal ->> 'cow'));
create INDEX animal_index ON farm using gin ((animal ->> 'cow'));
create INDEX animal_index ON farm using gist ((animal ->> 'cow'));
我想运行如下查询:
SELECT * FROM farm WHERE (animal ->> 'cow') > 3;
并让该查询使用索引.
当我运行此查询时:
SELECT * FROM farm WHERE (animal ->> 'cow') is null;
然后(1)指数起作用,但我不能让任何指数对不等式起作用.
Is such an index possible?
farm表只包含约5000个农场,但其中一些包含100个动物,对于我的用例来说,查询时间太长.像这样的索引是我能想到的加快查询速度的唯一方法,但也许还有另一种 Select .