Re: Indexing on JSONB field not working

Поиск
Список
Период
Сортировка
От Jeff Janes
Тема Re: Indexing on JSONB field not working
Дата
Msg-id CAMkU=1zGu2wBkPQmF0cS_mowcdLNhevP0D6xot2SrfEqwnMTXw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Indexing on JSONB field not working  (Zhihong Zhang <zhihong@gmail.com>)
Список pgsql-bugs
On Fri, Dec 20, 2019 at 7:39 PM Zhihong Zhang <zhihong@gmail.com> wrote:
A few clarifications,

1. The index is very effective. If I treat it as text, the index works. With index, the result returns in 1 second. Otherwise, it’s 5 minutes.

An index is over a datatype.  You can't just "treat an index like text".  Either it is an index over text, or it is not.  It you cast an expression to text while defining the index, then that is a different index than if you defined it with a cast to double precision.
 
2. Removing limit doesn’t change the behavior.
 
I have no problem getting your index to be used with or without the LIMIT , as long as the expression "(_doc #> '{floatValue}'::text[])::double precision < 3.0" is selective enough that it appears to be worth using an index for it.  For example:

insert into assets (id,_doc) select x, jsonb_build_object('floatValue',random()*1000) from generate_series(1,1000000) f(x);

We can't comment on how two queries might differ, then we have only seen one of them.

Cheers,

Jeff

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: BUG #16161: pg_ctl stop fails sometimes (on Windows)
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #16161: pg_ctl stop fails sometimes (on Windows)