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 1vdQ6V-000IyR-1r for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Jan 2026 09:45:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdQ6T-00DJOj-34 for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Jan 2026 09:45:22 +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 1vdQ6T-00DJOW-27 for pgsql-bugs@lists.postgresql.org; Wed, 07 Jan 2026 09:45:22 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdQ6R-0053cD-31 for pgsql-bugs@lists.postgresql.org; Wed, 07 Jan 2026 09:45:21 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-34c24f4dfb7so1205603a91.0 for ; Wed, 07 Jan 2026 01:45:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767779117; x=1768383917; 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=t31hieA1qWpQtcAC99pGHZIPKafIBobm/gsKbojzoKQ=; b=MWlvlg0tEtW1Lkmw0aLIXNilyWkq3BVxeQlKWecQx45SQz1t4S1OMU6eVi/G0n2GRV /0+kt9y6+iQZ5xQJ65GwfV2HZT79MDp0fgPVTQiMy13GhnNYmVh/f7lVJy/UX1TeAOhM w9NnTBASYiLFQAUBD4YKfOzWJWAZLTNfILlvtDbe5AffID1AppnynLSazvNDP5qZbXmB OVD+xezxALer/jmugbdAsLjQWST5n1E/Q9YTaX7VgfWOQK/SzBX6tCSuR0Jivx9Fyype yneIc0v8VI1n9K84XXVbQF/z+mMCq95Ib8vjUFGqYRfezVyWEqiQttUFPVXwT6CGc4lj kp1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767779117; x=1768383917; 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=t31hieA1qWpQtcAC99pGHZIPKafIBobm/gsKbojzoKQ=; b=Eug/D1ikuotZ0gKBI9n5XV4BpTiLL7g8dtiGG20vkjtOdE0+7dU26Y5Jji2GsPZtvF vtnggpq7K1jAebn08S2uxDEbfeGHwHh0dOYmkzr9T6D/KMX07i9gcSQIvWuPvgXBV727 4I65U6AbDxE6KFSontHr/EswUJXbeczWKu1t/CYb4QEoG3naCYKXn54/KkZx66fH5OX7 etu6+mg21BhbytQiq/eHQBdEtHWO6RBTD4W/D+eX+2GVWVdzsVjlO+p0gJ2tbx0Olhxc b1ZB6PIORSshtcx3Lt31ALj8ld/eZbnji7E3/BLDZPFKgWkwDU/9LwGiKmaEDeq/F2ir cdVg== X-Forwarded-Encrypted: i=1; AJvYcCXIBBrk4YldCXPI2KeMLzAmAJlCv1fccf0iU8XKMWrT7q7lFWg7gvgFWv6EgcYJ9RZ63aiDpRXS41JB@lists.postgresql.org X-Gm-Message-State: AOJu0Yw4xy6mpHLnzcuaqSQXAv2Peqfpmpt+91iaHgly3KZ93gpOK8Oo dtRBGxchlQuXXA1Jn/afQI8QgoW7UAnZTW+/0FDMYNpaCzy1vy308zW08OtriFKsWEUAN5ylV9F 39VN+uPLxXOb6QCPfLODbjvVwgApG5lw= X-Gm-Gg: AY/fxX7/OveNm/pczoSxVNECFWo+q65CK1R9KcGytbnmI6sNm5vDikD8FK09JjP0gG1 owmgvLxG7smQDILBgsqNr0/I/ZAgXXIwlHMVjX2/81fkf7WPo/JZvYI49xwUSBuxEOvTJj7p3yV H2fALGDFBGfu/8X6pV8vS6a7gABqv8HP7PEWHU/MX0RRuhFDMd51AZjqImj/+T2NwCGtoo0QBxd dfMeYCuCh2TxIlw9SCbLPhD1PabdiV2qP+z6csqcflYD2i9RliCyVugcXxnOi0PvWH64zhZ X-Google-Smtp-Source: AGHT+IEG4nc/MZNnFqwehR8p90iVBHlV9lMch90fTxhRmaTucP9ugaxwFeDGXi78hhxqoNBulGdAHGocTyPZhj3JiYk= X-Received: by 2002:a17:90a:c88b:b0:34c:6124:3616 with SMTP id 98e67ed59e1d1-34f68cdd6bemr1966258a91.27.1767779117381; Wed, 07 Jan 2026 01:45:17 -0800 (PST) MIME-Version: 1.0 References: <19355-57d7d52ea4980dc6@postgresql.org> <868ff2a518820c8864b6d28510294b2457a126af.camel@cybertec.at> In-Reply-To: From: Amit Langote Date: Wed, 7 Jan 2026 18:45:01 +0900 X-Gm-Features: AQt7F2p65Pb1_cyNKcFGt3yW2SBZXkmkeNmyY9ej0FOWIFpWC8pKRUdNcwBdmuM Message-ID: Subject: Re: BUG #19355: Attempt to insert data unexpectedly during concurrent update To: Bernice Southey Cc: Tender Wang , Dean Rasheed , Bh W , Laurenz Albe , pgsql-bugs@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 Hi Bernice, On Fri, Jan 2, 2026 at 6:58=E2=80=AFAM Bernice Southey wrote: > > > Dean Rasheed wrote: > > >> I'm somewhat conflicted as to which approach is better. I think mayb= e > > >> there is less chance of other unintended side-effects if the set of > > >> RTEs included in PlannerGlobal.allRelids, unprunableRelids, and > > >> es_unpruned_relids is not changed. However, as it stands, > > >> PlannerGlobal.allRelids is misnamed (it should probably have been > > >> called "relationRelids", in line with the "relationOids" field). > > >> Making it actually include all RTEs would solve that. > > I did some more digging (postgres source code is addictive). > > Up until v56-0004-Defer-locking-of-runtime-prunable-relations-to-e.patch > [1], the existing unfiltered rtable is used to create > unprunableRelids. > > +++ b/src/backend/optimizer/plan/planner.c > @@ -555,6 +555,8 @@ standard_planner(Query *parse, const char > *query_string, int cursorOptions, > result->planTree =3D top_plan; > result->partPruneInfos =3D glob->partPruneInfos; > result->rtable =3D glob->finalrtable; > + result->unprunableRelids =3D bms_difference(bms_add_range(NULL, 1, > list_length(result->rtable)), > + glob->prunableRelids); > > In v56 [2], the filtered allRelids was added. I think this is when the > bug was introduced, because the three places from Dean's patch are in > both versions. > > I've looked much harder at the code (I'm still at > stumbling-around-in-the-dark-with-a-match level) and AFAICT, the two > approaches are very similar. I think equal effort is required to check > that PlannerGlobal.allRelids, unprunableRelids, and es_unpruned_relids > are correct, whichever approach is used. I can't find any missed cases > in either approach - with my matchlight. Good catch on the history -- that's exactly when the bug was introduced. I'd say Dean's approach is easier to verify since it's a simple check at the point of use, rather than ensuring allRelids is built correctly across all planner code paths. > Sorry for my ignorance: does a relId refer to a range table index and > a relation to a...for lack of a better word...table+? Depends on the context, but "relid" in the planner internal data structures refer to RT index. In the planner output data structures (plan nodes, etc.), we typically use "rti" or "rtindex". --=20 Thanks, Amit Langote