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.94.2) (envelope-from ) id 1ugmZV-007Iw7-UD for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Jul 2025 15:48:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ugmZV-002klU-29 for pgsql-hackers@arkaria.postgresql.org; Tue, 29 Jul 2025 15:48:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ugmZU-002klL-Nn for pgsql-hackers@lists.postgresql.org; Tue, 29 Jul 2025 15:48:57 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ugmZT-001PB1-0W for pgsql-hackers@lists.postgresql.org; Tue, 29 Jul 2025 15:48:56 +0000 Received: from karst (82-65-23-130.subs.proxad.net [82.65.23.130]) by mail.dalibo.com (Postfix) with ESMTPSA id E79EA27925; Tue, 29 Jul 2025 17:48:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1753804133; bh=CfM5sHwaTpcopKbTo4Zi17J4wzXVKAkDPBMsbpP93gQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=b5JmoIUL29pvH0yDNYGsMJPYUPmCQEHesC6pVBdJPXn1630QRfD9okkrFSt/F2oDd 7r37Z7dCGvhG3CFch23C8Hro0Ek9/Vm/+O17j89FaLZVjPk0Jn7RRgz5Dzbn4ePZnS qUgF9LYlbeF9x9kPHoosHkm9e5N/gN2d35RcviDc= Date: Tue, 29 Jul 2025 17:48:52 +0200 From: Jehan-Guillaume de Rorthais To: Etsuro Fujita Cc: pgsql-hackers@lists.postgresql.org Subject: Re: [(known) BUG] DELETE/UPDATE more than one row in partitioned foreign table Message-ID: <20250729174852.14f23557@karst> In-Reply-To: References: <20250718175314.4513c00a@karst> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, 23 Jul 2025 19:38:19 +0900 Etsuro Fujita wrote: > Hi, >=20 > On Sat, Jul 19, 2025 at 12:53=E2=80=AFAM Jehan-Guillaume de Rorthais > wrote: > > [=E2=80=A6] > > Please, find in attachment the old patch forbidding more than one row t= o be > > deleted/updated from postgresExecForeignDelete and > > postgresExecForeignUpdate. I just rebased them without modification. I > > suppose this is much safer than leaving the FDW destroy arbitrary rows = on > > the remote side based on their sole ctid. >=20 > Thanks for rebasing the patch set, but I don't think the idea > implemented in the second patch is safe; even with the patch we have: >=20 > [=E2=80=A6] >=20 > The row in the partition plt_p2 is updated, which is wrong as the row > doesn't satisfy the query's WHERE condition. That's a clever test to expose the weakness of this patch=E2=80=A6 > > Or maybe we should just not support foreign table to reference a > > remote partitioned table? >=20 > I don't think so because we can execute SELECT, INSERT, and direct > UPDATE/DELETE safely on such a foreign table. Sure, but it's still possible to create one local foreign partition pointin= g to remote foreign equivalent. And it seems safer considering how hard it seems= to keep corruptions away from the current situation.=20 > I think a simple fix for this is to teach the system that the foreign > table is a partitioned table; in more detail, I would like to propose > to 1) add to postgres_fdw a table option, inherited, to indicate > whether the foreign table is a partitioned/inherited table or not, and > 2) modify postgresPlanForeignModify() to throw an error if the given > operation is an update/delete on such a foreign table. Attached is a > WIP patch for that. I think it is the user's responsibility to set > the option properly, but we could modify postgresImportForeignSchema() > to support that. Also, I think this would be back-patchable. So it's just a flag the user must set to allow/disallow UPDATE/DELETE on a foreign table. I'm not convinced by this solution as users can still easily corrupt their data just because they overlooked the documentation. What about the first solution Ashutosh Bapat was suggesting: =C2=ABUse WHER= E CURRENT OF with cursors to update rows.=C2=BB ? https://www.postgresql.org/message-id/CAFjFpRfcgwsHRmpvoOK-GUQi-n8MgAS%2BOx= cQo%3DaBDn1COywmcg%40mail.gmail.com It seems to me it never has been explored, is it? Regards,