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-0000tT-6W 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-0000Ot-3U 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 1mNAzw-0006Xr-NQ for pgsql-general@lists.postgresql.org; Mon, 06 Sep 2021 09:33:04 +0000 Received: from mail-eopbgr150072.outbound.protection.outlook.com ([40.107.15.72] helo=EUR01-DB5-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 1mNAzt-0008Uh-V1 for pgsql-general@lists.postgresql.org; Mon, 06 Sep 2021 09:33:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mC+3yHFs43gk2B4LyWDgjzxYYy/gf5Tjtyw04B3drZpi+sBkXh7XXLCHcH25jRpB58Hd0zz2TGZCSUzvzqZSNwJ0m2wkVDhRa/dfrqA/BJzOU/miHyg149DFFnC7tTUgBlbR/0xPFWHFdnvuzOiAEWGXi7zXT6HY7RxiHqZ9N1LVEoeIkLsIONEQp5JuPHmYCff3Mo6rHimOtZtP04mk5uucbGrtPn1fN9WR5nrq8RoTr+xQ5wscEqSrdIbOh9KPMF3PjmcbYBhIoOlfCgPX39nSzJD7j2hnIPi6RDzywJqEA9LJlUE/1MPOemPL5RbaTzGlZ1a9mYUoPHhEJlI2zQ== 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=8L45x+YjGndOx11QuQeEeJMm2cp8f+TkDC3YM9Jg7bY=; b=XFfy9vhOlTluXY8Nj53x/GJ2rqHG6zU9zslYZfdvhN4n+5ue5GsU5Ge8T8a46XK5GlSbJeKteJ9PxFl5+ynEImXlsNnp4ulR3fHrCtxSOJGb8Q9ET9kBuzLyoV5NVC/A8AByJlz5vXMdNHheC35VncmeTjMVzu66dSxUeo7FpYwnic2mvu6nHfb59+joAbUEGrdYdDOOW12YuVQUBS/iYWD8O4EP7DRicbKKNoUkHq5GtJRrFD/D15hUPckIJ1C5v2+WIQZisb9k7Y3Ebb/CKkqNgVWO12KgwljSI4ogu7KUTcWxxh+8CwBJDdaFo35DV82Hi/zTg8rN8Hx7G5ZURg== 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=8L45x+YjGndOx11QuQeEeJMm2cp8f+TkDC3YM9Jg7bY=; b=1+kOB+QeLvI+0bcO1AYJ2a7lUuJ/UspVFgQEfFE88rLT4nM6RGwdHK4xUk2yrizM6Qqy1cKVhNiNwHDPJazoanGqPOVJ0tQ3kPEc3ZezcW3OhceCjShTPjAdKnCKw/TYXjcz2LYRT14MlfxZHKDfrqNyNdQm/BtyVxKtxx6zERY= 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 PR3PR07MB8273.eurprd07.prod.outlook.com (2603:10a6:102:178::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.8; Mon, 6 Sep 2021 09:32:58 +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:32:58 +0000 From: Philippe Doussot Subject: Re: update non-indexed value is slow if some non-related index/fk are enabled To: Tom Lane , "David G. Johnston" Cc: "pgsql-general@lists.postgresql.org" References: <2875218.1630855266@sss.pgh.pa.us> Message-ID: Date: Mon, 6 Sep 2021 11:32:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 In-Reply-To: <2875218.1630855266@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------C07EC4F8617019FFFC3814A3" Content-Language: fr X-ClientProxiedBy: AM0PR01CA0116.eurprd01.prod.exchangelabs.com (2603:10a6:208:168::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 AM0PR01CA0116.eurprd01.prod.exchangelabs.com (2603:10a6:208:168::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:32:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f8788e51-df68-4305-f64d-08d971194ff5 X-MS-TrafficTypeDiagnostic: PR3PR07MB8273: 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: MZuoALEJviC9UIgcyxag9DgEo+wU7rsLs7ns/HB97+0mWk2Haw0AHDznjfxlr0p13LjKxsCpNGZ5MSHGNA7vQXtBS3LBN/qW4hpoiSbt+mFx78SjQKAkqJ1nCvxB+5YY56Y7rdWp0bwbj2b4SOhiJuTL3go89vc74QGpWiONSYk57b/OSAJmG3QafFiCyJ41hfVcToCKsJ4IIDxxc3ghTlOj7QOsQ9CRUVHAbVINDA0ee7FIJmrseC3rPQebmpz9Pgl90ZSbxRxtnG2wZTrf4tBXzeAmdrBSidnYfw+82xKbi7Q2Qr3kXi/xpbQjYhR7WU2CcHxDSkgcKQdq03+r114Ufsi2WFg1fpUGMZBR6D45rIiLEYpeUOa8wVTvRYhqoDfkIfS06oeEW5KrYU2GxgH4n5K4FNn+VjlQ5ZHL+nXgiD7mds/petQsWcqqJAFjndHanC+6ArGL2cOdOj0zr8ikKIRdvkHiVj3M0LXP+/jrME6uC4IblUqE8vuHWcrrB7Kl6HGwYxfFoFZxzyPSHuBUQGo3srnFnNIPTyqKkJBDqDKTufiauFd1HyK8LG/3rEodplX5RFY7mo6B42Zo/9L5Wrv8UodcOp/wcjZJIPxWxdNHO0Fw59Kt2ANZNPK86LM9a3ldZ8ztIR5ABOiipL6xQpjE7VaPl/U23B4itOv2CUsFFRfVwxvX2ZAti+AfQ9a7HC2CXVKGXutQhAkX3xnMwA8GE0iVXgMVkUlZOM+FWaWxb0wljsV6mzhoMGWZcBnJ7nA65E+nIF9ttI7VPMtmqvzwba668XvSkK9jSimwZL9E3N5Wlkosv7BQZs/t 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)(366004)(44832011)(508600001)(110136005)(15650500001)(38350700002)(166002)(38100700002)(66556008)(31686004)(66946007)(66476007)(2906002)(966005)(316002)(16576012)(31696002)(8936002)(26005)(83380400001)(86362001)(5660300002)(186003)(33964004)(36756003)(956004)(2616005)(8676002)(52116002)(53546011)(6486002)(4326008)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VElrRXRGZnRtS1lGeGNJc1NxUTFpQ2Q5bHVBS1h3NWpGd1M4b2lNWHFiRVU0?= =?utf-8?B?SjE5UGlFS0I1RllQS1Y0d3ZKNmNWNmN4eXJPL1Q0dXNOcTRWM1dwWEoyUHFH?= =?utf-8?B?dG9ubEtQdkFZMmd2Q1lDRDNMNnNVb3ZDRCtYaVlzeDNLOGhHeWFTK0kxZ3Zu?= =?utf-8?B?cVd3NWE2cUhhUEJvdGNlU1NQaHVRbFdUM1hsZ0NwNHhYMyswQTB0TVlCSExq?= =?utf-8?B?MkxVVUE5WnVLQnZ2ZkU0RVZaTno2RlcrSUNIclkwVldadmNoditCUVBWM3FZ?= =?utf-8?B?SEh1SDRPWk5rajRGT2tHV0NwdE9QVC9HazFKbE94dVBDUXRzUjdncmk0R0RM?= =?utf-8?B?Y1hkcDFBNSt1YjVaazVmM1hYajRScWNHOVJVRGt2am5pVjhQVktPNG9OMFVt?= =?utf-8?B?Z3VzS3VBaVNDbVFlNmRSRjlRWUFyRnhYVXM1ODRVR1BaMjg1eVo0REd2R1Fh?= =?utf-8?B?R3pXRVBoMm1VeWp6ZGtUOXRpZFF2ZEVINW1kanJNc0R1L2JsaW0ybWtSQ1I5?= =?utf-8?B?bVhqZ3R4YkV2bjRkcGc5czVoTE1JUEpYT0hNRW53cHJaMElpM1Foei9Famky?= =?utf-8?B?SWdGVkFHOHg0L0RPUmsyNjl3YWpLV2pKWFMxdTNxNVJGM0x2VE1KK0lzRUlh?= =?utf-8?B?SGxSSVpEK29rRVlRcjBvNWFWSSt0SyttWERBSXd1TmRRYVM5S3E1eW9QcGYz?= =?utf-8?B?VFpiNWRwR2c0SFh6N0Fxa3d6dXpuaGVkMUw1QzdmT083czJsMDNt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FQkRobEhGQVBlNlpQNktL?= =?utf-8?B?QUQ2b3NMSjJYNDhVbEFWSjRXRTZaWXA1ODRmV21MNzFpSDVPOFRuMWN3dGdJ?= =?utf-8?Q?/gpCBlodwN7i0aO561aFFJgs+nqGFT/w6UFwi8X?= X-OriginatorOrg: up.coop X-MS-Exchange-CrossTenant-Network-Message-Id: f8788e51-df68-4305-f64d-08d971194ff5 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:32:58.0809 (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: 85iSkY6zF2+oHo+w5KllYS56bVhzKPH3fqdYk6vrQC2osVI+kubW+Em5aWOfej8QLbCm2SFe4u9NC+stkQBGUuQRDUmFiB5wZzXQUuYQgAI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR07MB8273 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------------C07EC4F8617019FFFC3814A3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 05/09/2021 17:21, Tom Lane wrote: > "David G. Johnston" writes: >> On Friday, September 3, 2021, Philippe Doussot >> wrote: >>> I don't understand why disabling all index from the table speed up th= e >>> update because the boolean column is not indexed >> Index entries point to physical records. You just deleted one physica= l >> 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 t= rue 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 o= ptimisation 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 = =D0=95=D0=B3=D0=BE=D1=80 =D0=A0=D0=BE=D0=B3=D0=BE=D0=B2 @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 low= er 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-dat= e. Many thanks Philippe --------------C07EC4F8617019FFFC3814A3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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&g=
t;
wrote:
I don't understand why dis=
abling all index from the table speed up the
update because the boolean column is not indexed
Index entries point to physi=
cal 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 i=
s 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.

			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 htt= ps://habr.com/en/company/postgrespro/blog/483768/ , Thanks =D0=95=D0=B3=D0=BE=D1=80 =D0=A0=D0=BE=D0=B3=D0=BE=D0=B2 @ero= gov


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


--------------C07EC4F8617019FFFC3814A3--