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 1mNBdF-0000tS-2F for pgsql-general@arkaria.postgresql.org; Mon, 06 Sep 2021 10:13:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mNBdE-0000Os-3R for pgsql-general@arkaria.postgresql.org; Mon, 06 Sep 2021 10:13:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNAwJ-0006Nu-16 for pgsql-general@lists.postgresql.org; Mon, 06 Sep 2021 09:29:19 +0000 Received: from mail-eopbgr70070.outbound.protection.outlook.com ([40.107.7.70] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNAwG-0008Sk-Iw for pgsql-general@lists.postgresql.org; Mon, 06 Sep 2021 09:29:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fVb8bbDL7dbK1g8LAohEzBOLGV3JRmlLqFpvU4NIrACJziW85R25gmci+G91mkV8F9tMXFlVuFEmNBF3QcrlA0VFKqYS5i1xCZnbRxV2+kwfQIDgYKscnJpGomWiD3K8DQTHrR9PoqNrcn5iMG6xIrzz7LEgN8fBjgGw1MV7/tkXEri75wHo+aqejVi33cWk54lJwzN/GuKmsDcPONsnQAaEVMo7JO2w4LSIXjf19BZZQu//t60+7cMsTAlcBj6NXdGanRAW5QwefzJ/u1q+lTkrzrRs6cUemojY3pZcPsybG2ow81mx+M/N91ilR0PVQx2Nm0D8FKUmK3fDffl7gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=IhYmbo+6OdE1qX+nbX2mNKODKrh10vrItJ16msLSMYc=; b=DCBjyGKKm08vZ9e21JuQkOZFO5PzCNCMYdaC8gj8Y/Gx6WnWYWPT0pLblXPuq50poFsBdDqCSKgW3wLwnWNM8YWKhBXa6GgnjbFxx9y4Fr6EgBbbYuMjv1BuhXNMxsjriUQZwuKtn6MwJsXHgrn1vI0Hai0SbRHe510XrNivIMzGmZ5iQ2IFkfFEEID/Zewugw7gauXCyMwnfDyf8sHGgXCCnG0ry1scU96mSltp8uTOO+ov1gdTWRYOoWeqMMdMu9SJlKM6QpaeuSRIiIMh08Iq/YCdxDyiPHtn81bTYn1QnfqvErs8QqrrzrowzBIm4wAmPwmNIBK6HCchNmUI9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=up.coop; dmarc=pass action=none header.from=up.coop; dkim=pass header.d=up.coop; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=groupechequedejeuner.onmicrosoft.com; s=selector2-groupechequedejeuner-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IhYmbo+6OdE1qX+nbX2mNKODKrh10vrItJ16msLSMYc=; b=5ekUo/laT/ejCjNyJb7PjcSTlf1h4n9wp+KcHWwiSuO9kEruuw5/GqpRp5urZhgWWnHDrW9XceEY/VzAX5Lx/KuRpxhgOxCrR1oZj/45ZMRXJzZ3FOpgI8GcjQ2xsM7wrJ71GNz0nNEBDdHJzMBAhGdHxv8R4FGjQTLFKTP6xTM= Authentication-Results: lists.postgresql.org; dkim=none (message not signed) header.d=none;lists.postgresql.org; dmarc=none action=none header.from=up.coop; Received: from PR3PR07MB8243.eurprd07.prod.outlook.com (2603:10a6:102:17a::6) by PR3PR07MB8276.eurprd07.prod.outlook.com (2603:10a6:102:17b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.4; Mon, 6 Sep 2021 09:29:12 +0000 Received: from PR3PR07MB8243.eurprd07.prod.outlook.com ([fe80::a08b:a60b:f76:e422]) by PR3PR07MB8243.eurprd07.prod.outlook.com ([fe80::a08b:a60b:f76:e422%7]) with mapi id 15.20.4436.017; Mon, 6 Sep 2021 09:29:12 +0000 Subject: Re: update non-indexed value is slow if some non-related index/fk are enabled To: rob stone , Tom Lane , "David G. Johnston" Cc: "pgsql-general@lists.postgresql.org" References: <2875218.1630855266@sss.pgh.pa.us> From: Philippe Doussot Message-ID: Date: Mon, 6 Sep 2021 11:29:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------AAA079802369E8EB4692870A" Content-Language: fr X-ClientProxiedBy: PR3P191CA0016.EURP191.PROD.OUTLOOK.COM (2603:10a6:102:54::21) To PR3PR07MB8243.eurprd07.prod.outlook.com (2603:10a6:102:17a::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.2.27] (91.167.4.78) by PR3P191CA0016.EURP191.PROD.OUTLOOK.COM (2603:10a6:102:54::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Mon, 6 Sep 2021 09:29:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fa9a5811-4258-4d75-27ba-08d97118c933 X-MS-TrafficTypeDiagnostic: PR3PR07MB8276: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U7a/Cxu9M8f54n1q6/8X2CMmoX9pZpmLu6YhHtbYgQgRd5ooUVaFCgffJGOIKaGuqrtUzeWrl5qyENE7Dgu8z3sxg8Jtp7wxPHsCBMZy4dVkDcXrE6HtO4gamLHC8MIs7DSPTERkb0+conD3fdIr/QNWO0uWPpC2KnFZMrkLzoGFu7CQPUe6WRR6M4X8e18ZrBbz28vqBonroNH8KilDChZ5qRHJHcjU2FBzpGbboMZxOF4GnswkDIdlo5/IhM4lNloyB+AVoJRj5a4RJuxaPtXROFlP6jyOQZxvGK+L+NJ3rUbYa3Y0sbhm4wekMCvnMxKiuDCWHer0PjSXrkG4PSU+kldLctpjeYNutblMpQeo273IhpxPtK4JttTMu1IV0MN1K6HGnoNlxMI6XQeY+QYoF4kQ4c3g9clNcdHLaS12M4azSSUW3AVeS61qPfSBDa4uC6dMrkugK7lvT1iT2rmPrIur5cOjo8i1MPXApkXPRfKhpJMDZEsPqnj/JkOvoXSjfC8pntJSL2Lj225B3Y/sMPChXdQH8qD1XkVXaAfbVT66MX2K1IS1tuq/Ml41aLfTR11H2KTD6DIF5Y86O1y9RWjL/KMGAxuQtcfYewVFSypq9yRhQCUazjJDEPaSlJ0PnboGCSptahAYODD67Ci5AB3qgAMcIGTTRFIAAtpK2WA86uvL/hgSTpI845FlpFsiyYpPZpyrx5i887K90sNWxiVjokvTsXfGBTY8Sy7TUZ7WLBYmkHvYRtriNIaDe2zmY/thCW3n8y2VKkGVqA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PR3PR07MB8243.eurprd07.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(136003)(346002)(39860400002)(396003)(38100700002)(83380400001)(86362001)(5660300002)(66556008)(956004)(66946007)(66476007)(38350700002)(478600001)(33964004)(4326008)(44832011)(31686004)(52116002)(316002)(16576012)(2616005)(36756003)(110136005)(15650500001)(6486002)(26005)(2906002)(8936002)(186003)(8676002)(53546011)(31696002)(45980500001)(43740500002);DIR:OUT;SFP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OFB1M095eml0QWxIYTdXcWVaU1FYbzVySmtjVjh4?= =?utf-8?Q?QXcS4Z0kceyDpB2mAwh9evG+vEYazNnS7qbzeiw?= X-OriginatorOrg: up.coop X-MS-Exchange-CrossTenant-Network-Message-Id: fa9a5811-4258-4d75-27ba-08d97118c933 X-MS-Exchange-CrossTenant-AuthSource: PR3PR07MB8243.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2021 09:29:11.9696 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 475fd1d1-212f-472f-9c02-635526f47568 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: q0jOPL/9QT1M+c5uZRypZH85AiiyzHNNchwnL04Y57w+l2sBt0g+xUYc+kTXlhd7Q+ILcAwcXHHvWMdc1eom6KEuc1FflFzEqIhxmaqczrA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB8276 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------------AAA079802369E8EB4692870A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 06/09/2021 10:21, rob stone wrote: > > On Sun, 2021-09-05 at 11:21 -0400, Tom Lane wrote: >> "David G. Johnston" 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.=C2=A0 You just deleted one >>> physical >>> record and added another.=C2=A0 The indexes need to be updated with t= hat >>> information. >> Yeah.=C2=A0 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.=C2=A0 Ensuring (b) requi= res >> running with a fairly low fill-factor, which bloats your table and >> thereby creates its own costs.=C2=A0 Still, that might be worth doing >> depending on your particular circumstances. >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= 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 boo= lean but not for bigger fields Philippe --------------AAA079802369E8EB4692870A Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
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, 20=
21, Philippe Doussot <
philippe.doussot@up.coop>
wrote:
I don't understand why d=
isabling all index from the table speed
up the
update because the boolean column is not indexed

        
Index entries point to phy=
sical 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", whic=
h
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.

            &nb=
sp;           regard=
s, 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


--------------AAA079802369E8EB4692870A--