From: Philippe Doussot <philippe.doussot@up.coop>
To: rob stone <floriparob@gmail.com>
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:29:09 +0200
Message-ID: <a0615923-0430-a31c-bef2-65580c30085e@up.coop> (raw)
In-Reply-To: <b67dcf853ff3ea29a60097737811e0186288362b.camel@gmail.com>
References: <f5710d56-504f-46d9-986a-8ca03980363c@up.coop>
<CAKFQuwZbx8v9Ect=FDk34FhJdCDw3ekQ=vDcKW==XaNTCiF5Cg@mail.gmail.com>
<2875218.1630855266@sss.pgh.pa.us>
<b67dcf853ff3ea29a60097737811e0186288362b.camel@gmail.com>
On 06/09/2021 10:21, rob stone wrote:
>
> On Sun, 2021-09-05 at 11:21 -0400, 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
>>
>>
> If the DDL for that table had the column defined like this:-
>
> my_boolean BOOLEAN,
>
> instead of:-
>
> my_boolean BOOLEAN NOT NULL DEFAULT FALSE/TRUE, (whichever is
> convenient)
>
> then that column would contain either 'f' or 't' on insert instead of
> null.
>
> Then even if a fillfactor was not specified for that table, an update
> of that single column (which does not appear in an index) would merely
> swap the values.
> Surely that would write it back in place?
>
> Also, having boolean columns containing a null makes it difficult for
> the getter's of that table deciding if 'null' is true or false.
>
> Just an observation.
>
> Rob
>
Yes my columns are NOT NULL DEFAULT FALSE
but the update always change the ctid ( new row in page )
I whas hopping the same optimisation as you: Write in place.
For boolean it is maybe doable because the value is fixed in size but for variable length ..
I was also expecting no row rewrite if value don't change .. easy for boolean but not for bigger fields
Philippe
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, floriparob@gmail.com, 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: <a0615923-0430-a31c-bef2-65580c30085e@up.coop>
References: <f5710d56-504f-46d9-986a-8ca03980363c@up.coop> <CAKFQuwZbx8v9Ect=FDk34FhJdCDw3ekQ=vDcKW==XaNTCiF5Cg@mail.gmail.com> <2875218.1630855266@sss.pgh.pa.us> <b67dcf853ff3ea29a60097737811e0186288362b.camel@gmail.com> <a0615923-0430-a31c-bef2-65580c30085e@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