【发布时间】:2017-07-11 07:57:09
【问题描述】:
我有以下疑问:
SELECT "survey_results".* FROM "survey_results" WHERE (raw @> '{"client":{"token":"test_token"}}');
EXPLAIN ANALYZE 返回以下结果:
Seq Scan on survey_results (cost=0.00..352.68 rows=2 width=2039) (actual time=132.942..132.943 rows=1 loops=1)
Filter: (raw @> '{"client": {"token": "test_token"}}'::jsonb)
Rows Removed by Filter: 2133
Planning time: 0.157 ms
Execution time: 132.991 ms
(5 rows)
我想在raw 字段内的client 键上添加索引,这样搜索会更快。我不知道该怎么做。当我像这样为整个raw 列添加索引时:
CREATE INDEX test_index on survey_results USING GIN (raw);
然后一切都按预期进行。我不想为整个raw 添加索引,因为我在数据库中有很多记录,我不想增加它的大小。
【问题讨论】:
标签: sql postgresql jsonb