带有jsonb列的多列索引

时间:2016-03-11 10:54:04

标签: postgresql indexing jsonb

说我有一张桌子:

CREATE TABLE items
(
  index         serial primary key,
  segment       int not null,
  definition    jsonb not null
)

definition列如下:

{
  "array": [
    { "name: "Bob", "age": 21 },
    { "name: "Alice", "age": 31 }
  ]
}

我希望能够索引诸如

之类的查询
select * from items
where segment = 4 and definition->'array' @> '[ { "name": "Bob" } ]'::jsonb

是否可以索引此查询,索引应该是什么样的?我不需要segment + age查询,只需segment + name

0 个答案:

没有答案