Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYYDN-000819-Hu for pgsql-general@arkaria.postgresql.org; Wed, 14 Sep 2022 19:38:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oYYDM-0007zr-DO for pgsql-general@arkaria.postgresql.org; Wed, 14 Sep 2022 19:38:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYYDM-0007zf-0g for pgsql-general@lists.postgresql.org; Wed, 14 Sep 2022 19:38:28 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oYYDJ-00027b-9f for pgsql-general@postgresql.org; Wed, 14 Sep 2022 19:38:27 +0000 Received: by mail-pg1-x534.google.com with SMTP id q9so6121945pgq.8 for ; Wed, 14 Sep 2022 12:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:cc:date:in-reply-to:from:subject :mime-version:from:to:cc:subject:date; bh=cFUSKHT4eG/IVDQPVbWWAYDoXw3Bx7mv4FJ1D8L8UaM=; b=Me52sS7DleO35DKU8YY5aXVbK/i8GQHMrcJU/aNYMTL3EgRbEDdJZleVmgHXOwzInu VeFi0lQFCAQHWsWYz3m1S42rzv8yggJ4bvhEX5YTpfHITGbNpqSVZ03sTnvnRGrpnmYM ut2d1DHCKsVhFFCzqHxMx1Zo3jIniT5j4qN4WVY9AqLzzi0EvacARJheiJVcKtYVLLs1 x530kcx+9xm3KHSb9QAkI1fYKFpfrVyR6mOzKfj/0E6n3Nc8dUwCmG7/SAIORUOBXOnJ pL7Esi1AEbCFt/joqI6FmTkUw0s0rTwtLbEJCZCeGobTEX3uhDP3NqGHu8TTjOLCu9Sh mFTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:cc:date:in-reply-to:from:subject :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=cFUSKHT4eG/IVDQPVbWWAYDoXw3Bx7mv4FJ1D8L8UaM=; b=lDDXpUBFM4wik3RuCJyk54Qlma7lBxNQNXKclCEQg/zUmctbTHx4kMXxJqppxyps9x EhlvprTCiChO/C/tSq1BSIzraX+hjqPkOUlsG6NELceNLIv2ReGR30Mmqzovip5x2d3B ohb54lrBZjgwHufRnoRn+RU41jt3BrxzzuPTr87dLpWatobbLiGOHBIR/V7MrXx3mYT/ CBDW28CZVXeXzv6Hx55c6QhnyNUEbrRTb1Hz5YdJBdDDlfx7P/q+vgTnPZBHo6U8WzgO XKwC5COgMzuj2rk/JjNNi2oOBqZhno2Bu1N/cpgtX7AlXyLBor4b4rZevOjOmTm5cKmC yLbQ== X-Gm-Message-State: ACgBeo05vIa0klD1CbQ9BlvRshB4Nz2AD+UKBfYvQE+eGTxW/NdsYsD6 7lzBnx4o0j4tXAdCDqYpRBnLBfjuGysRcg== X-Google-Smtp-Source: AA6agR48ET/whuS0ibDcKL34EAR4D/Iclq8Vc2sm/lOon5tCFGNrBEK/4nsOVC5hDVTjIBJwyoVNzg== X-Received: by 2002:a63:e14c:0:b0:439:2e24:e014 with SMTP id h12-20020a63e14c000000b004392e24e014mr10686976pgk.173.1663184302639; Wed, 14 Sep 2022 12:38:22 -0700 (PDT) Received: from smtpclient.apple ([2600:8801:8800:29::1b]) by smtp.gmail.com with ESMTPSA id m2-20020a170902f64200b00176e7761f16sm11103321plg.231.2022.09.14.12.38.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Sep 2022 12:38:21 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_63D313AE-9B33-4880-B2D1-3ADDAFD9C498" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: massive update on gin index From: Guyren Howe In-Reply-To: Date: Wed, 14 Sep 2022 12:38:17 -0700 Cc: Postgres General X-Mailbutler-Message-Id: 3E90CCC0-CD79-4591-BD76-C3862BEDBACC Message-Id: <3D4F5EA2-3144-4F3B-8FBC-A4FD524B663F@gmail.com> References: To: Marcos Pegoraro X-Mailer: Apple Mail (2.3696.120.41.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_63D313AE-9B33-4880-B2D1-3ADDAFD9C498 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 You might consider defining a phone type that includes your =E2=80=9Ctype=E2= =80=9D 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 > wrote: >=20 > 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. >=20 > So my original table had > Mobile, Work, Home and all of them are btree indexed. >=20 > 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) >=20 > 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 =3D 2236279878 or = Work =3D 2236279878 or Home =3D 2236279878; > =20 > 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 ? >=20 > 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 >=20 > And that execution time will come back to 0.220 ms only if I recreate = the index. >=20 > Then I found gin_pending_list_limit and fast_update which I think are = used to update GIN indexes, but didn=C2=B4t find any examples of both. >=20 > 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 ? >=20 > Thanks > Marcos --Apple-Mail=_63D313AE-9B33-4880-B2D1-3ADDAFD9C498 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 You = might consider defining a phone type that includes your =E2=80=9Ctype=E2=80= =9D 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> 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 =3D 2236279878 or Work = =3D 2236279878 or Home =3D 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=C2=B4t 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

3D""= --Apple-Mail=_63D313AE-9B33-4880-B2D1-3ADDAFD9C498--