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 1wZ8ia-000nv0-01 for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jun 2026 14:55:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZ8iX-00COjO-2A for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jun 2026 14:55:13 +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.96) (envelope-from ) id 1wZ8iX-00COj0-0a for pgsql-hackers@lists.postgresql.org; Mon, 15 Jun 2026 14:55:13 +0000 Received: from mail-dy1-x132f.google.com ([2607:f8b0:4864:20::132f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZ8iV-00000000UV0-21oq for pgsql-hackers@lists.postgresql.org; Mon, 15 Jun 2026 14:55:12 +0000 Received: by mail-dy1-x132f.google.com with SMTP id 5a478bee46e88-304f590dd91so3883358eec.0 for ; Mon, 15 Jun 2026 07:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781535308; cv=none; d=google.com; s=arc-20240605; b=bUgbRQx+jg4uwttMaWmlkEF5Dvr/a1sf7f5MxtTrZ6wGRUt1KdPNRT6mm4rg/kCGLr wk7u68LubHFe93nKTzU0R34FndmRCPrMl5mRISniqWBANOgfC0EBCGUbZJeYsmRzDY7I y3tpVeLclbOMaI2xVMdjQV1LYYaN4GGoWQGomUPEhWtNG/z1yhnBfRcn9s83kdQYptOR Tvc55zyNhkwaO5hlkjZnVHs3fay4CwISfuwIg8iOBXA9cB0lvGDIGb4oSKFRfBuKErUg dMiDQyZ0sOBbCRvinZ/a4whMAqSLh7wupxvddkgoPIRQt2M8SUBt3KGWUExNNVOZh/2+ s6Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=C8xQIzyRXJTWNvNMYKUNTyvZ3Z32Y87UYiY3labqgzw=; fh=jF5BzrGD4zaykoRSaoYNaW7iUKA27xxxVn/MKG9TiiE=; b=lTV212flqiiQMflUtomKfmPVuhFAZi2FUATcEZePzgo32Ryoh/vzq3liLIm08U0Loc 6xLz0bTxxegoAGuriNZcQO7+xjVp4c7l8MQUz0DPrxmxkjRjLsQTgdrXDuMWyMkOd/hZ AP2aZ2NIEr2wecjFavbKuo5kHRlGhRjTKeT7LfiUhXrIfqVJQTxhd3pdRbe9yvM6pcDu kZryA2xhA8Y3K0rFyryT+qk5RGja5JgXZhBY4yiWuljdJxlGsELqoEDrXn2UrRadG2dS LIrgo4pj3NLyyzhAY0JOi0NjelkrJjHpFOzMMbUJropfjk9jL50Dbnckli7AUECiR7F0 nKCQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781535308; x=1782140108; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=C8xQIzyRXJTWNvNMYKUNTyvZ3Z32Y87UYiY3labqgzw=; b=MdpvG5LAMtf1eUDpewenZrQyPDsllrf8+a+b/B/0cEnXzGlbqLhA0CrBQWCqS+x5ZH KY9dcYLbYCN/ipvS4GllrORRh0k1edMJcA67Wm/oonWe+kUsM98mNNA63G1zWJUi9NJA hKBAyWHlDh9XhlL44dsYvjvxGkaxYMYsmvbGJkCfTtWMQ6JnUOrCzoB7XPtmvu8fEUSN idO2o2Q5GQkpTFtpgKGQp/gz/s0ZQm2iiiW1hc0DadutkETwU4j4jnDd5CJUbNIBvTED MddyQ0d5Q7yP9MptvIBse5KLa/yZGtokkDzApK/AoYIIqLyZKJR92EROi+ncJOYtONS9 qH0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781535308; x=1782140108; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=C8xQIzyRXJTWNvNMYKUNTyvZ3Z32Y87UYiY3labqgzw=; b=rWlz2HXxlO+MJa0u2JMZ/C3fhBQiXxlIi5ctxpsd/HIIf1WnpH96omnvux1vN+w5v+ MTq6TYuUwCJevZGMsr7hs7HqxJ1wujrfC8yGvBq7wTEWZrHAMsPyJ222V4zjhAOAXyN5 u07CuJ51MhotAhhaIWGkhmrCju6vgibe87h5duM+Xi6fdW3musbmbAaY9AFH+8TvxzZY 8CdDytdGgDhzgvMLcso9kZB5GWBBz5dAADq5rWVhOW2u0AfBaIi7QWx8UlRdREFBoiaN RMFhnUFdtXoNzQbc2dG3O9yIbKXn26OztddSN44yKOO+8VTRN9p/bGCQlvt3sKvQOg7F bo3w== X-Forwarded-Encrypted: i=1; AFNElJ++zuY8yJN9S3Af3OQoDNodO6MhEyChI+koYwOqzfHGPCsNtY69uuoYzbc3zG3REHQDm7g+dQ4SMpAEW+g+@lists.postgresql.org X-Gm-Message-State: AOJu0Yw5QUHLGnEHppiQdhHKuvPStoaL3StK0PcPBG93y1Ef0q6YLSK8 2tzgQnXU9uphKKTOga08zRsQwPpeDlsH1wa8uDQDGKFsHSo9MT1RYqIa4MrbqrJNJ2y4JF+2+9G QyS/E/JmBhJ70bqad74O04P3QrErrHwM= X-Gm-Gg: Acq92OE6IJbQjmyCj35qj6ASKKKLwln+yF7EaQS3sD0W1ZH3r7c68dQvEZ2AOgNnGpJ jZZsq0IgXohiJONGa5liDTHlbYyDsVDrDoYExp/KhhgWfXLh1lh/BUnAy4HjjmQzk7QHoJhFU2n cxqho57ffa/N8tEmqZ2XU7rLESJlgsmGcQMfvQf/RGlLcxzdMEOnjiCzHq/viKzmVnlH/CAfJzA l8W8JhstSrflzXH8Y7NJPWydh4Tr2qYRS/Vz/5FqdqRfMIdlrI3qw5ybW3O+TIg1jKMVDo8wx9o jghpR52GvWUQ+zoCiOCSOP2tNrNAm8QXqFpPhhq0HUm8VyQnKJiMIFAxQbbUFK8lkPoz6T6dDZT hE4rdwnXNKkef03K+x9eXnEI1sqkG/BvYIzOQEGLdcLq6qG7xHXM= X-Received: by 2002:a05:693c:830f:b0:2dd:8ac2:9f7a with SMTP id 5a478bee46e88-30b83e6c959mr1507814eec.11.1781535308400; Mon, 15 Jun 2026 07:55:08 -0700 (PDT) MIME-Version: 1.0 References: <20250718175314.4513c00a@karst> <20250729174852.14f23557@karst> In-Reply-To: From: Etsuro Fujita Date: Mon, 15 Jun 2026 23:54:55 +0900 X-Gm-Features: AVVi8CcGfO3ULJ38bpvI33bs6KTrfDbeQp7Z8r6o7GNEq8P2N2GYcUG84Z386uw Message-ID: Subject: Re: [(known) BUG] DELETE/UPDATE more than one row in partitioned foreign table To: Nikita Malakhov Cc: Michael Paquier , Jehan-Guillaume de Rorthais , pgsql-hackers@lists.postgresql.org 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 On Sun, Jun 14, 2026 at 4:43=E2=80=AFAM Nikita Malakhov = wrote: > While testing the proposed solution we've stumbled upon another vanilla b= ug related to FDW - > a query with DELETE ... USING selects invalid records from partitioned FD= W tables: > CREATE TABLE acc_entry > ( > id bigint, > doc_date date, > impact int, > amount numeric > ) PARTITION BY RANGE (doc_date); > > CREATE TABLE acc_entry_p1 > PARTITION OF acc_entry > FOR VALUES FROM ('2025-01-01') TO ('2025-07-01'); > > CREATE TABLE acc_entry_p2 > PARTITION OF acc_entry > FOR VALUES FROM ('2025-07-01') TO ('2026-01-01'); > > CREATE FOREIGN TABLE measurement_fdw > ( > id bigint, > doc_date date, > impact int, > amount numeric > ) > SERVER loopback > OPTIONS (table_name 'acc_entry'); > > INSERT INTO acc_entry > SELECT > CASE > WHEN g IN (4,15,26,35,46,55,66,75,86,95) > THEN 2501020100000124 > ELSE g > END AS id, > CASE WHEN g % 2 =3D 0 THEN timestamp '2025-02-02' ELSE timestamp '202= 5-08-08' END, > 1, > g > FROM generate_series(1,100) g; > > DELETE FROM measurement_fdw > USING ( > SELECT id > FROM measurement_fdw > WHERE id =3D 2501020100000124 > LIMIT 1 > ) s > WHERE measurement_fdw.id =3D s.id; > > The latter query selects and deletes records with invalid ID which should= not be selected at all. I think that that would be another example that the bug discussed here causes unexpected results, as I have this after inserting the data into the partitioned table: select tableoid::regclass, ctid, * from acc_entry where ctid in (select ctid from acc_entry where id =3D 2501020100000124); tableoid | ctid | id | doc_date | impact | amount --------------+--------+------------------+------------+--------+-------- acc_entry_p1 | (0,2) | 2501020100000124 | 2025-02-02 | 1 | 4 acc_entry_p1 | (0,8) | 16 | 2025-02-02 | 1 | 16 acc_entry_p1 | (0,13) | 2501020100000124 | 2025-02-02 | 1 | 26 acc_entry_p1 | (0,18) | 36 | 2025-02-02 | 1 | 36 acc_entry_p1 | (0,23) | 2501020100000124 | 2025-02-02 | 1 | 46 acc_entry_p1 | (0,28) | 56 | 2025-02-02 | 1 | 56 acc_entry_p1 | (0,33) | 2501020100000124 | 2025-02-02 | 1 | 66 acc_entry_p1 | (0,38) | 76 | 2025-02-02 | 1 | 76 acc_entry_p1 | (0,43) | 2501020100000124 | 2025-02-02 | 1 | 86 acc_entry_p1 | (0,48) | 96 | 2025-02-02 | 1 | 96 acc_entry_p2 | (0,2) | 3 | 2025-08-08 | 1 | 3 acc_entry_p2 | (0,8) | 2501020100000124 | 2025-08-08 | 1 | 15 acc_entry_p2 | (0,13) | 25 | 2025-08-08 | 1 | 25 acc_entry_p2 | (0,18) | 2501020100000124 | 2025-08-08 | 1 | 35 acc_entry_p2 | (0,23) | 45 | 2025-08-08 | 1 | 45 acc_entry_p2 | (0,28) | 2501020100000124 | 2025-08-08 | 1 | 55 acc_entry_p2 | (0,33) | 65 | 2025-08-08 | 1 | 65 acc_entry_p2 | (0,38) | 2501020100000124 | 2025-08-08 | 1 | 75 acc_entry_p2 | (0,43) | 85 | 2025-08-08 | 1 | 85 acc_entry_p2 | (0,48) | 2501020100000124 | 2025-08-08 | 1 | 95 (20 rows) Note that the rows with normal ids have the same ctid as the rows with id=3D2501020100000124 (for example, ctid of the row with id=3D3 is (0,2), which is the same as that of the first row, which has id=3D2501020100000124), so the bug would delete such normal-id rows as well when performing the delete query. Best regards, Etsuro Fujita