Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vbHYn-003jda-1h for pgsql-general@arkaria.postgresql.org; Thu, 01 Jan 2026 12:13:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vbHYm-008J0t-1k for pgsql-general@arkaria.postgresql.org; Thu, 01 Jan 2026 12:13:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vbEEq-007wDH-2W for pgsql-general@lists.postgresql.org; Thu, 01 Jan 2026 08:40:57 +0000 Received: from iad-out-009.esa.us-east-1.outbound.mail-perimeter.amazon.com ([34.198.94.229]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vbEEo-003tvL-0J for pgsql-general@lists.postgresql.org; Thu, 01 Jan 2026 08:40:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1767256854; x=1798792854; h=from:to:cc:date:message-id:references:in-reply-to: mime-version:subject; bh=zj8p61kF3i4GaqpdgWVHZCWXeAREXLglwyhZeP/rIlQ=; b=A8OxTTbIs9+iJqOQ6OGoGLYqWVKENHak/1NJkp6kYZNXJHeMRtIq0oVM REHgmiJ6QdWj4abXyZ+HDdAB4x2RBPXEkjzbUVX24wTL2pgmVKqOZxVO5 kmTYaMG+WzTrJjiHf5FhUHtQxsPvGtjj2yYWaa7IBMjU/0yDzPP+0NFgI 60E+2cpgwyw/U/rG7zibcF0Ws1CXR+Ev0Pfh4cY+z0N6sEguY/cjD57Ne 7/oOnBtvohF5Wu0LpGQYwpL4ur7IImNsyb4QBIyWKtH3Advt4oZkNP+jQ O+/gVYlRevhrVdfc95Ekb4/ef2+37obHF5XZXwthcU9nQtlJ44CZmO9cz g==; X-CSE-ConnectionGUID: h6sUSvtDS3GVEbDkIonkTA== X-CSE-MsgGUID: +aJr+Q/rSlmiu+i8VdYJLQ== X-IronPort-AV: E=Sophos;i="6.21,193,1763424000"; d="scan'208,217";a="9175085" Subject: Re: SELECT FOR UDPATE behavior inside joins Thread-Topic: SELECT FOR UDPATE behavior inside joins Received: from ip-10-4-10-75.ec2.internal (HELO smtpout.naws.us-east-1.prod.farcaster.email.amazon.dev) ([10.4.10.75]) by internal-iad-out-009.esa.us-east-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jan 2026 08:40:49 +0000 Received: from EX19MTAUEA001.ant.amazon.com [72.21.196.67:21144] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.46.15:2525] with esmtp (Farcaster) id 3f8e8a7d-c808-4347-a4f2-e648586da652; Thu, 1 Jan 2026 08:40:49 +0000 (UTC) X-Farcaster-Flow-ID: 3f8e8a7d-c808-4347-a4f2-e648586da652 Received: from EX19EXOUEB001.ant.amazon.com (10.252.135.46) by EX19MTAUEA001.ant.amazon.com (10.252.134.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.35; Thu, 1 Jan 2026 08:40:49 +0000 Received: from DM2PR04CU003.outbound.protection.outlook.com (10.252.134.239) by EX19EXOUEB001.ant.amazon.com (10.252.135.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.35 via Frontend Transport; Thu, 1 Jan 2026 08:40:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=moSekGegPxnjNUKLCZ0wPmAfj5F2TCsiRNofdg161DPqsmKiDSSx3FBs/Ixx+bGyWETfcnP0FJXt6YNjaDpsue84o0xdb/inmEE8H2HsFAXfDB0GeGd6LJpDDSxJK0DEmDb0e1w/tuVGkPK/gMQXdAvbhwRcVoEttRkmEUeype+JuASSHrnHs0M9WrruN8vZlrjQ0nciUZjvQMacy+tPeCM3KyITSlD/SxPiCz9ExGW3b7u4zbPRPfAUW7HWmlpH/EoBtAFUL1b4Ag+cDPuVJTAdav+oSQMbd8kubMtY/wnCk9KwwRQVLsv9Zlu3RHOGkk0Bp878ocgb/E7EHSQwOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zj8p61kF3i4GaqpdgWVHZCWXeAREXLglwyhZeP/rIlQ=; b=xuk7fkSiYoq24Mk5opTgRvuip6PhGL8ieVraWitzHzoGg7pzAD56ss8wqGuuvl2ev54Xo+oGj+yLjkHiDKjF0dDEvG/wDajI7OJ0zNPPwrgHpbTUfKoAw4tdiZsLH0WMVrcL8fsJBTFChR1L/Ze9U+ZjT2uKfpc3rXSPfMR+vWVu5mMsAztVHqMN7922/m3qgyjX7/MaEhW+FOC4SYqfKDW+n5+n7+Z9GeSBvhjnFAm7g1XScCUrw01N2oYYd/wcvrlUE5z12Nq4B8ZlNEti4a5Jx3HElUsEBgltBv5lG9laWM7vhyiCHj/Ljdp01m47FNIvR3wuP+THKwDXzssDKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amazon.com; dmarc=pass action=none header.from=amazon.com; dkim=pass header.d=amazon.com; arc=none Received: from CH5PR18MB927659.namprd18.prod.outlook.com (2603:10b6:610:2ef::20) by LV8PR18MB5882.namprd18.prod.outlook.com (2603:10b6:408:22d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9456.11; Thu, 1 Jan 2026 08:40:41 +0000 Received: from CH5PR18MB927659.namprd18.prod.outlook.com ([fe80::2963:ef10:e182:bcae]) by CH5PR18MB927659.namprd18.prod.outlook.com ([fe80::2963:ef10:e182:bcae%5]) with mapi id 15.20.9478.004; Thu, 1 Jan 2026 08:40:40 +0000 From: "Khan, Tanzeel" To: Tom Lane CC: "pgsql-general@lists.postgresql.org" Thread-Index: AQHceKFQG1f4JGngWEKdz2KQb5dGT7U75EkAgAEA/d8= Date: Thu, 1 Jan 2026 08:40:40 +0000 Message-ID: References: <3914049.1767195192@sss.pgh.pa.us> In-Reply-To: <3914049.1767195192@sss.pgh.pa.us> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-reactions: allow authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amazon.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH5PR18MB927659:EE_|LV8PR18MB5882:EE_ x-ms-office365-filtering-correlation-id: 4f4de3fb-64c8-40a0-251c-08de49117208 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|366016|376014|1800799024|10070799003|8096899003|38070700021; x-microsoft-antispam-message-info: =?us-ascii?Q?541bhpLkwTCqlyPj4pTcz6BHTdH229pd6WhkWJ69SZcXp24YVhUwZ6y42i4x?= =?us-ascii?Q?O41E3RDR6r4Mx8QjG4N5N2KMvUOYf5cr10YD9dtftUKHf+0qh5TJJ71ApDN/?= =?us-ascii?Q?LrtbDafd3nA3s97fvWRZto0yoA6zvSFolgLgOav/7tqROwLHdMjNh3CKa4Mc?= =?us-ascii?Q?x177dHHv5+m6DlIqKNbT0Wxknu0LivFgavZY30/9q5upB3tcfEfNvdAn5f4s?= =?us-ascii?Q?XT14pk2tnUzl3ShuyXQAs0/0+xBeuoos3PQDRM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ii?Q?iUAWcdAsPtVOw/XCE7rR7T+rfVGqBss6DDEan6Gva9Z9pqB1obT4QC8UO/Do?= =?us-ascii?Q?VdSk9Fq4tR5F5lsp8shI20RYuqCwIFwpXBrRxDPhhsZBwYz9ZeR2HqB4SpMA?= =?us-ascii?Q?5nnyDlgYNcBNDPOwyoKJAemhzlGsN3hbqh+ZaSSj4qmUYZLZ9N1jjl1Oq9+Q?= =?us-ascii?Q?UyVHU59NTaPAaSvbeBrx7VRPgVHNfeG/lJQ/sPnt79M+gO6ucB0mtxWbdzOV?= =?us-ascii?Q?909PQ1vhTc4djeMPY6JjNerLFDf5qlxKti6vM1fJBAlG6Uj7xsvMfLRiV6oL?= =?us-ascii?Q?tQAyyLkFTUTsaEHjrglHDCBH2dmPTwgvFLbmYcV9KsPJwXT0N9fyOUBCBQMI?= =?us-ascii?Q?bWYQYQq5fkoo4GbQWf2NhmzvF5pDt7DivVlT?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH5PR18MB927659.namprd18.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024)(10070799003)(8096899003)(38070700021);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 2 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?hTbjHLlVsT8VjmY94d9s2gK1kCPVXZhLRB7kuDVadKGxCH6xQ5/0tZ2RGrAn?= =?us-ascii?Q?lWM8C+t57EWljNCsba78VuXfeJ2QAyCYkJs4GWHbI1GWHXW6Vi/JlMZ5tol8?= =?us-ascii?Q?FJZ39PWD0QV6uKtJBc52yVioX1M7QxiwKwZB9j95FdqeXdQG3XvGazsTRIcv?= =?us-ascii?Q?HRb6foDugZ3gwpm+/w6msnCqcoUyahLcl+ORsg2Q2dcqLBQCT0LtJoiWLaLk?= =?us-ascii?Q?SpYZolweonjdZJZfvRcMN+qxLHdSDlUEGR/5T5hVxIy6+urHd/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EpwfNaHpc8D50Ux9n+LIHQPK2bCQDFH00?= =?us-ascii?Q?ahgFzMsortuohR6lbsgrfDJvD11Rp2VETy4e5i37ZjqegAG2MOjkb0peO0mP?= =?us-ascii?Q?tKlknqL9ZN/+m8pOVp1GUlOMA/ajlR5O6FMuz9ip50I9KXZvF1Wk+PQBsdER?= =?us-ascii?Q?qtC2853VNtRCAxN7u1uqBkCXIivt/SX2vkFrhYH5l/raP6QKSM2YGF5hR5Ob?= =?us-ascii?Q?gX6O/tC4kzYZoCRGTjV6CUDVxPSWrfpD/czS1u9RWP71Z+QP9173HpeOrVxT?= =?us-ascii?Q?mlm4IwgM/6YZ19ttTegFhTUlw869KLftSgUiJhFQc61zIVkyUT3UZJk0iobY?= =?us-ascii?Q?lHnhzq9JrGD2UPymZG3pmlAp0trPIgsDorb5+/AtZGxlXjc5b52ajtb/74ic?= =?us-ascii?Q?p4idaq4PuBFh2XZ6FpvfJtz7OCBeLr6mGQK9XpWo77xQGRC0puzhVWJowuPA?= =?us-ascii?Q?xltJeQWAqAdMYBpmeRPTFH6m7SZybnQzpKiUYrG+f/LnFUalagUUJkFPh0bt?= =?us-ascii?Q?QZXbeZYRsdEcVF2BLb/+gzwT6dQFvy/PW9cbmhNlgzSqST2tCSVoUM1wk1m7?= =?us-ascii?Q?E61rJ1iRXErJdmp7+dmAgd/PBoG+nk+Zgcy/+rM34M5aYxGgSrwHui75IhQ7?= x-ms-exchange-antispam-messagedata-1: JHnrjiDuinK3N2EDKif/La/DY0XBaCLkIJg= Content-Type: multipart/alternative; boundary="_000_CH5PR18MB927659CE30CC405704D6D81E6DCDBAACH5PR18MB927659_" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH5PR18MB927659.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f4de3fb-64c8-40a0-251c-08de49117208 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Jan 2026 08:40:40.9097 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5280104a-472d-4538-9ccf-1e1d0efe8b1b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: J3nvcEZRCOAntMPzCbmkKTHEMoiq75mUlDsO3DCsw9dgL8CoPX8d7UmUgVkooYq2dzjsKiT06Og3EdumpgDldA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR18MB5882 X-OriginatorOrg: amazon.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_CH5PR18MB927659CE30CC405704D6D81E6DCDBAACH5PR18MB927659_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > Since the CTE has FOR UPDATE, it blocks and returns the updated-by-S1 > version of the row. But the outer query initially reads the old > version of the row, so the join condition fails, and we never get > to the lock-row-and-recheck behavior of UPDATE. I see, thanks. > I am not sure what you are hoping to accomplish with that self-join. > I suppose this is an oversimplified example, but it's too > oversimplified for anyone to see why you'd want to do it like that. I was original trying to build a generic way for fetching old rows in UPDATE RETURNING clause for pre-18 versions but the self join does not work well with concurrent updates either resulting in lost updates or not returning the concurrently updated value in RETURNING. ----------- Thanks, Tanzeel --_000_CH5PR18MB927659CE30CC405704D6D81E6DCDBAACH5PR18MB927659_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
> Since the CTE has FOR UPDATE, it blocks and returns the updated-by-S1<= br> > version of the row.  But the outer query initially reads the old<= br> > version of the row, so the join condition fails, and we never get
> to the lock-row-and-recheck behavior of UPDATE.

I see, thanks.

> I am not sure what you are hoping to accomplish with that self-join. > I suppose this is an oversimplified example, but it's too
> oversimplified for anyone to see why you'd want to do it like that.
I was original trying to build a generic way for fetching old rows in
UPDATE RETURNING clause for pre-18 versions but the self join does
not work well with concurrent updates either resulting in lost updates
or not returning the concurrently updated value in RETURNING.

-----------
Thanks,
Tanzeel
--_000_CH5PR18MB927659CE30CC405704D6D81E6DCDBAACH5PR18MB927659_--