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 1vdST9-000nEZ-0q for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Jan 2026 12:16:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdST7-00DxiI-14 for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Jan 2026 12:16:54 +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 1vdST7-00DxiA-0B for pgsql-bugs@lists.postgresql.org; Wed, 07 Jan 2026 12:16:53 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdST6-004i2q-08 for pgsql-bugs@lists.postgresql.org; Wed, 07 Jan 2026 12:16:52 +0000 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-bc0d7255434so1041232a12.0 for ; Wed, 07 Jan 2026 04:16:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767788211; x=1768393011; 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=AvkHhW7Dm8wJb5zYSBNBm/F0bxtGuz1QgAeiCEN35y0=; b=JUdcKoO0GHgDn8MykQTboUvPJAnqkF4qCcyfsFkouk+J4EPr+I1pd5/5ONGFHA7LMo FtfkPNV6pTPd7Up6Rsx2UZnZi1GipoQyY35LdaiX0x2hhcEx9s2hJgdNJp1Sa6fjtPey IhPCWeW+V/S6qIPWVHwHXsoBDD5dnMiyEwpNAvb+J5ML8TUtUcGIi/iCeMDWiKRuJ7yU f41543ZcvQuChbiNozeKI34vy5NxJVd1/nygyMOpF6l2icqThHCy7q0vszon4bZGDw7M Rm0dEOCuwH+XDL5HEkTNVMaP+yIbRi+6CXDtN27TFohCV+LH5leD0p8qoyj6VYLLb0Fd RdXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767788211; x=1768393011; 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=AvkHhW7Dm8wJb5zYSBNBm/F0bxtGuz1QgAeiCEN35y0=; b=j8UTvL7mGs+k4QvOMReKeCMyKtmfWHDGgIc06KFs/jPQEJMJKtZunKC0kUlqJlFX74 hIkSO+lz5MiOpibQVchWTWQIg++dkxEOkui9097qyuMDo+dnmzJ2rYT8DiQrHT+tJ7o5 PsYuhxUEvYcfbVFiNKqqwmKXnHHSJHjX31hzPxoBNvmcQWbU1qNBNvN150hGnxOFi45+ R4PDLAz0E4m0UB098EOetQHFnwtIOc7PtTAtQIkIahScrCiTUfktwRrFmbU+jTRtMKmu vZfmY6U/X5EjcUlFpcUgMqipDvEr8h1ZMzi8Gs5b46k7oxpHV7OJef02/8GlNha7gGbl St6Q== X-Forwarded-Encrypted: i=1; AJvYcCVMgxzC9nHM47QGr2+Iku4V4U+RXce38sWRHfoz5XFFiwYRSTF4NPu3FePE7zm/pnqSfCAysuspCesN@lists.postgresql.org X-Gm-Message-State: AOJu0YysXwIbKqmB7TZuwfAAIs9JPpH7Rf008kfDIOJz/iefchywzHdu YH9mzwC9Q3UvYNBmesRsm/u+BTE6kA7pt+U/cdvRkuXV5axECtLPHbDnVeqc7oVAXGpLVsB3kF1 ddyfK0BeCn+lrLF6BKGGAfa1UBn9PsFM= X-Gm-Gg: AY/fxX71qhLuiSA5DkRCRFuVcHDmmQnYoSPpdHfM2R9SkF/j/D7uv40ZPNGKdJj287q 3sHphMsR14fU77HQRR0S4dXrAcu+FROdCObZ9Cv1UMGop2wtP7uUAi0wY+RhhdTBgoZloQTEiRW dY5aILEsN9Q8Q9jXPfL7O0DLfEsn67sJ7DP1xdrqJzZZfN/3c6oyVG8xn6rHMCf/gkMVfqO8cQx +6Y+iq9ho2PUtyiz6FVwVf0AODs6GbYFttmcN4qdNOYHQrrM/2frVVwY8YKnh+0KDiurlrV X-Google-Smtp-Source: AGHT+IFOMBnEdNM/56zxp/+vOvF7/6eQX+nEYv1EvoPHF3L38kgeKfIYI/gW17jdmS4jS6dn9SWbNA/pGQWd3bngt/c= X-Received: by 2002:a17:90b:57f0:b0:349:2136:83eb with SMTP id 98e67ed59e1d1-34f68c282a5mr1983534a91.29.1767788210740; Wed, 07 Jan 2026 04:16:50 -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 21:16:34 +0900 X-Gm-Features: AQt7F2rSSjo1mRbnQU-GyIQeFLdMt10p1jR_2H4vhsXHmg4OFQ6wBPAaUeNVzh8 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 On Wed, Jan 7, 2026 at 6:45=E2=80=AFPM Amit Langote wrote: > On Fri, Jan 2, 2026 at 6:58=E2=80=AFAM Bernice Southey > wrote: > > 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 remembered more on why I insisted on putting only relations with OID (RTE_RELATION and RTE_SUBQUERY with relid set (views)) into PlannerGlobal.allRelids and thus PlannedStmt.unprunableRelids. The reason is that I did not want loops iterating over unprunableRelids to have to skip relations that do not have an OID. For example, AcquireExecutorLocks() currently iterates over the rtable and skips non-RELATION RTEs; in a now-reverted commit (525392d57) I had changed it to iterate over unprunableRelids instead, which avoided the need for that skip logic entirely, because unprunableRelids by design only contains OID-bearing relations: - foreach(lc2, plannedstmt->rtable) + while ((rtindex =3D bms_next_member(plannedstmt->unprunableRelids, + rtindex)) >=3D 0) { - RangeTblEntry *rte =3D (RangeTblEntry *) lfirst(lc2); + RangeTblEntry *rte =3D list_nth_node(RangeTblEntry, + plannedstmt->rtable, + rtindex - 1); - if (!(rte->rtekind =3D=3D RTE_RELATION || - (rte->rtekind =3D=3D RTE_SUBQUERY && OidIsValid(rte->reli= d)))) - continue; + Assert(rte->rtekind =3D=3D RTE_RELATION || + (rte->rtekind =3D=3D RTE_SUBQUERY && OidIsValid(rte->rel= id))); This is why adding all RTEs to allRelids, as Tender suggested, would be problematic -- it would defeat the design intent that allows loops over unprunableRelids to skip the filtering logic. While there are no such loops today (I reverted the patch that added one), keeping this design makes sense. Dean's fix addresses the buggy bms_is_member() check directly, without changing allRelids - albeit the name's a bit misleading as has been mentioned. -- Thanks, Amit Langote