Re: Performance on JSONB select

2019-10-08 Thread PegoraroF10
Sorry, I told you that the status was always populated but not, I need that filter for the index because not all records are using that json structure. When json is not null then yes, Status is always there. I have maybe 20 or 25% of records having json populated, so, I really need that filter. Y

Re: Performance on JSONB select

2019-10-07 Thread Michael Lewis
> > My Json has always a status > Why declare the "where" clause when creating the index? It would not seem needed if status is always set and so your index will reference all rows in the table. Thanks for sharing the trick of having the second column in the index determine the key based on the f

Re: Performance on JSONB select

2019-10-05 Thread PegoraroF10
No, no, no, partial index is the where clause of it and I´m not talking about that. I´m talking about datevalue, which will be used one or another, depending on status value This record iindex will be status and datevalue from "visitadescartada" object {   "status": "visitadescartada",   "atribui

Re: Performance on JSONB select

2019-10-05 Thread Fabrízio de Royes Mello
Em sáb, 5 de out de 2019 às 11:49, PegoraroF10 escreveu: > I told it was almost dynamic because it uses DateValue from an object or > another, depending on value of staus key. > Actually it’s named partial index. Regards, > -- Fabrízio de Royes Mello Timbira - http://www.timbira.co

Re: Performance on JSONB select

2019-10-05 Thread PegoraroF10
I told it was almost dynamic because it uses DateValue from an object or another, depending on value of staus key. -- Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html

Re: Performance on JSONB select

2019-10-05 Thread Pavel Stehule
Hi so 5. 10. 2019 v 13:34 odesílatel PegoraroF10 napsal: > I think I solved my problem. I didn´t know it was possible but I´ve created > an almost dynamic index, because it´ll index for status and corresponding > datevalue of an object with that status value. > you created multicolumn functiona

Re: Performance on JSONB select

2019-10-05 Thread PegoraroF10
I think I solved my problem. I didn´t know it was possible but I´ve created an almost dynamic index, because it´ll index for status and corresponding datevalue of an object with that status value. Postgres, I love you. Just one B-Tree index with 2 fields, Status and DateTime of that respective S

Re: Performance on JSONB select

2019-10-05 Thread PegoraroF10
I think I solved my problem. I didn´t know it was possible but I´ve created an almost dynamic index, because it´ll index for status and corresponding datevalue of an object with that status value. Postgres, I love you. Just one B-Tree index with 2 fields, Status and DateTime of that respective

Re: Performance on JSONB select

2019-10-02 Thread Stephen Frost
Greetings, * Michael Lewis (mle...@entrata.com) wrote: > Much of indexing strategy depends on knowing the data like how many > distinct values and what the distribution is like. Is JsonBField->>'status' > always set? Are those three values mentioned in this query common or rare? > Can you re-write

Re: Performance on JSONB select

2019-10-02 Thread PegoraroF10
ok, my select performed better but I had to create 8 indices to speed up my query. I would love to create just one index using GIN(JsonBField jsonb_ops) but using version 11 I cannot use operators like > and <. I see on docs that version 12 has jsonpath Filter Expression Elements and they inclu

Re: Performance on JSONB select

2019-10-02 Thread Michael Lewis
Much of indexing strategy depends on knowing the data like how many distinct values and what the distribution is like. Is JsonBField->>'status' always set? Are those three values mentioned in this query common or rare? Can you re-write this query to avoid using an OR in the where clause? Are you ju

Performance on JSONB select

2019-10-02 Thread PegoraroF10
select * from MyTable where ((JsonBField->>'status'='descartada' and To_Date(JsonBField->'descartada'->>'data','-mm-dd') > Current_Date) or (JsonBField->>'status'='contrato' and To_Date(JsonBField->'contrato'->>'data','-mm-dd') > Current_Date-7) or (JsonBField->>'status'='naoatribui