Re: update non-indexed value is slow if some non-related index/fk are enabled - Mailing list pgsql-general

From Tom Lane
Subject Re: update non-indexed value is slow if some non-related index/fk are enabled
Date
Msg-id 2875218.1630855266@sss.pgh.pa.us
Whole thread Raw
In response to Re: update non-indexed value is slow if some non-related index/fk are enabled  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: update non-indexed value is slow if some non-related index/fk are enabled  (rob stone <floriparob@gmail.com>)
Re: update non-indexed value is slow if some non-related index/fk are enabled  (Philippe Doussot <philippe.doussot@up.coop>)
List pgsql-general
"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



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: update non-indexed value is slow if some non-related index/fk are enabled
Next
From: Shubham Mittal
Date:
Subject: Re: Query takes around 15 to 20 min over 20Lakh rows