pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philippe Doussot <philippe.doussot@up.coop>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: update non-indexed value is slow if some non-related index/fk are enabled
Date: Mon, 6 Sep 2021 11:32:55 +0200
Message-ID: <fd92be8d-39dd-1afa-8d12-7095e0ded80a@up.coop> (raw)
In-Reply-To: <2875218.1630855266@sss.pgh.pa.us>
References: <f5710d56-504f-46d9-986a-8ca03980363c@up.coop>
	<CAKFQuwZbx8v9Ect=FDk34FhJdCDw3ekQ=vDcKW==XaNTCiF5Cg@mail.gmail.com>
	<2875218.1630855266@sss.pgh.pa.us>

On 05/09/2021 17:21, Tom Lane wrote:
> "David G. Johnston"<david.g.johnston@gmail.com>  writes:
>> On Friday, September 3, 2021, Philippe Doussot<philippe.doussot@up.coop>
>> wrote:
>>> I don't understand why disabling all index from the table speed up the
>>> update because the boolean column is not indexed
>> Index entries point to physical records.  You just deleted one physical
>> record and added another.  The indexes need to be updated with that
>> information.
> Yeah.  The OP's mental model is apparently update-in-place, but that's
> not how Postgres does things.
>
> The index-update overhead is avoided if the update is "HOT", which
> requires that (a) no indexed column changes and (b) there is room
> on the same page for the new copy of the row.  Ensuring (b) requires
> running with a fairly low fill-factor, which bloats your table and
> thereby creates its own costs.  Still, that might be worth doing
> depending on your particular circumstances.
>
> 			regards, tom lane
Hi,

Thank you both David and Tom for this precious information.

Yes, I was thinking that the update was made in-place because a boolean true or false take the same size :).
I did't expect the ctid was changed.

The main reason is effectivly
 > (b) there is (no) room on the same page for the new copy of the row.

I now see that the default TABLE fillfactor is 100. No room for update in same page by default (our case).

The CTID is changing for each update (even if I UPDATE many time the same boolean column with same value false, false, false .. maybe a room for optimisation here )

And with some room (lower fillfactor) I see the HOT working well with the help from https://habr.com/en/company/postgrespro/blog/483768/ , Thanks Егор Рогов @erogov


Disabing index during update obviously put index out of sync with the new row location which require an reindex.

I can now better explain to my team why this update is slow ( without lower fillfactor).
Why it is quick with index disabled.
Why disabling index without reindexing it after enabling it is a very bad idea .. the ctid as changed (without HOT update) and index is out-of-date.

Many thanks

Philippe

view thread (9+ messages)  latest in thread

Message-ID: <fd92be8d-39dd-1afa-8d12-7095e0ded80a@up.coop>
Permalink:  ../fd92be8d-39dd-1afa-8d12-7095e0ded80a@up.coop/
Also on:    postgresql.org/message-id/fd92be8d-39dd-1afa-8d12-7095e0ded80a@up.coop

 · 

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: philippe.doussot@up.coop, tgl@sss.pgh.pa.us, david.g.johnston@gmail.com
  Subject: Re: update non-indexed value is slow if some non-related index/fk are enabled
  In-Reply-To: <fd92be8d-39dd-1afa-8d12-7095e0ded80a@up.coop>
  References: <f5710d56-504f-46d9-986a-8ca03980363c@up.coop> <CAKFQuwZbx8v9Ect=FDk34FhJdCDw3ekQ=vDcKW==XaNTCiF5Cg@mail.gmail.com> <2875218.1630855266@sss.pgh.pa.us> <fd92be8d-39dd-1afa-8d12-7095e0ded80a@up.coop>

* 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