Re: [GENERAL] Index using in jsonb query - Mailing list pgsql-general

From Francisco Olarte
Subject Re: [GENERAL] Index using in jsonb query
Date
Msg-id CA+bJJbxTueGFg-e7aK_2w3T3VMu28fd_PudKLu9mYvWKYZFEDA@mail.gmail.com
Whole thread Raw
In response to Re: [GENERAL] Index using in jsonb query  (SuperCiccio <sc_030268@yahoo.it>)
List pgsql-general
On Sun, Mar 12, 2017 at 9:50 AM, SuperCiccio <sc_030268@yahoo.it> wrote:
> But even if I create a specific index
> CREATE INDEX on datatable (((jsonfield#>>'{path1,path2}')::numeric));
> it isn't used in such a query; it is used in this query:
> select field1,field2 from datatable where
> (jsonfield#>>'{path1,path2}')::numeric = 1000;
> Definitely, I didn't find a way to optimize a query that checks a range in a
> json subfield.

Have you checked why it does not use the index? ( how many rows are
returned, stimates etc.. ). Maybe it is not using it because it is
faster ( than using it, index fetches are slower than sequential
fetches ( for the same number of rows ), so for some queries it is
better to not use the index  ) ( specially if you are using them for
small test tables, i.e., for a single page table nothing beats a
sequential scan ).


Francisco Olarte.


pgsql-general by date:

Previous
From: SuperCiccio
Date:
Subject: Re: [GENERAL] Index using in jsonb query
Next
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] How to define the limit length for numeric type?