Re:

Michael Lewis <mlewis@entrata.com>

From: Michael Lewis <mlewis@entrata.com>
To: Steve Midgley <science@misuse.org>
Cc: Дмитрий Воронин <carriingfate92@yandex.ru>, pgsql-sql@lists.postgresql.org
Date: 2022-02-01T20:10:53Z
Lists: pgsql-sql
On Tue, Feb 1, 2022, 9:16 AM Steve Midgley <science@misuse.org> wrote:

>
>
> On Tue, Feb 1, 2022 at 12:42 AM Дмитрий Воронин <carriingfate92@yandex.ru>
> wrote:
>
>>
>> SELECT attrs FROM document_resinfo WHERE attrs @? '$.dates[*].datetime()
>> ? (@ >= "2020-10-02".datetime())';
>>
>> How can I create index on attrs field to query docids with other date?
>> Thanks.
>>
>>
>
> Have you tried just putting a default index on that column? I think it
> should work fine.
>
> CREATE INDEX attrs_idx ON test (attrs)
>


You'd want to use gin index type. Btree won't be very helpful.

I would consider a btree on the jsonb key itself.

One major hesitation I have with using jsonb much is that you don't get
statistics on the distribution of data (ndistinct, mcv, histogram, etc).

>