pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guyren Howe <guyren@gmail.com>
To: Marcos Pegoraro <marcos@f10.com.br>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: massive update on gin index
Date: Wed, 14 Sep 2022 12:38:17 -0700
Message-ID: <3D4F5EA2-3144-4F3B-8FBC-A4FD524B663F@gmail.com> (raw)
In-Reply-To: <CAB-JLwa1KMTj17y5cCdNQC_KFd16VXViZ_Hf1Jt+AUgiUo75Qg@mail.gmail.com>
References: <CAB-JLwa1KMTj17y5cCdNQC_KFd16VXViZ_Hf1Jt+AUgiUo75Qg@mail.gmail.com>

You might consider defining a phone type that includes your “type” information, and just having an array of those, if you really want to do something like this.

But a related table instead would be the obvious answer.

> On Sep 14, 2022, at 12:33 , Marcos Pegoraro <marcos@f10.com.br <mailto:marcos@f10.com.br>> wrote:
> 
> In a table with people's info I have 3 phone numbers, mobile, work and home. But then some have 2 mobiles, some have 2 work numbers, so decided to test it as an array of json. I know I could have another table for that, but I was just testing.
> 
> So my original table had
> Mobile, Work, Home and all of them are btree indexed.
> 
> Then added a jsonb field and updated it with those 3 phone numbers on it
> [{"phone": 2236279878, "type": 1}, {"phone": 22998432631, "type": 2}]
> [{"phone": 22996783278, "type": 2}]
> create index idxPhones on People using gin(Phones)
> 
> If I select using old or new fields, both uses index and Execution Time is similar
> explain analyze select * from People where Phones @> '[{"phone": 2236279878}]';
> explain analyze select * from People where Mobile = 2236279878 or Work = 2236279878 or Home = 2236279878;
>  
> But then I repeated 2 or 3 times that update which stores those 3 phones on json and then my gin index became slow, very very slow, why ?
> 
> select using btree on 3 phone numbers - Execution Time: 0.164 ms
> select using gin on json on first update - Execution Time: 0.220 ms
> select using gin on json next to 2 or 3 updates - Execution Time: 11.220 ms
> 
> And that execution time will come back to 0.220 ms only if I recreate the index.
> 
> Then I found gin_pending_list_limit and fast_update which I think are used to update GIN indexes, but didn´t find any examples of both.
> 
> What am I missing ? That gin index needs to have some more options or attributes on it ?
> I know in a day by day use I'll never do that massive update twice but just to understand when will this index be updated ?
> 
> Thanks
> Marcos

view thread (6+ messages)  latest in thread

Message-ID: <3D4F5EA2-3144-4F3B-8FBC-A4FD524B663F@gmail.com>
Permalink:  ../3D4F5EA2-3144-4F3B-8FBC-A4FD524B663F@gmail.com/
Also on:    postgresql.org/message-id/3D4F5EA2-3144-4F3B-8FBC-A4FD524B663F@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: guyren@gmail.com, marcos@f10.com.br
  Subject: Re: massive update on gin index
  In-Reply-To: <3D4F5EA2-3144-4F3B-8FBC-A4FD524B663F@gmail.com>
  References: <CAB-JLwa1KMTj17y5cCdNQC_KFd16VXViZ_Hf1Jt+AUgiUo75Qg@mail.gmail.com> <3D4F5EA2-3144-4F3B-8FBC-A4FD524B663F@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox