Re: Indexing on JSONB field not working - Mailing list pgsql-bugs

From Zhihong Zhang
Subject Re: Indexing on JSONB field not working
Date
Msg-id 9499358C-9E3A-4050-901F-BA988FC286FC@gmail.com
Whole thread Raw
In response to Re: Indexing on JSONB field not working  (Jeff Janes <jeff.janes@gmail.com>)
Responses Re: Indexing on JSONB field not working  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-bugs
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.
2. Removing limit doesn’t change the behavior.
3. I ran Analyze multiple times after indexing.

Zhihong


On Dec 20, 2019, at 5:57 PM, Jeff Janes <jeff.janes@gmail.com> wrote:

On Fri, Dec 20, 2019 at 5:12 PM Zhihong Zhang <zhihong@gmail.com> wrote:

I have an index on JSONB fields like this,

 

CREATE INDEX float_number_index_path2

    ON public.assets USING btree

    (((_doc #> '{floatValue}'::text[])::double precision) ASC NULLS LAST)

    TABLESPACE pg_default;

 

However query doesn’t use it,


Did you analyze the table after building the index?  Expression indexes have their own statistics, but they don't get populated until the table is analyzed.

Cheers,

Jeff

pgsql-bugs by date:

Previous
From: Jeremy Schneider
Date:
Subject: Re: logical decoding bug: segfault in ReorderBufferToastReplace()
Next
From: Zhihong Zhang
Date:
Subject: Re: Indexing on JSONB field not working