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 1vdPyu-000HY1-33 for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Jan 2026 09:37:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdPyt-00DI8V-24 for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Jan 2026 09:37:32 +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 1vdPyt-00DI8L-18 for pgsql-bugs@lists.postgresql.org; Wed, 07 Jan 2026 09:37:32 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdPys-004gzK-2d for pgsql-bugs@lists.postgresql.org; Wed, 07 Jan 2026 09:37:31 +0000 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-c026e074373so1149172a12.1 for ; Wed, 07 Jan 2026 01:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767778649; x=1768383449; 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=HzF2fslhEEeJTmhuKu2PbDCtac+UTCjrl9KAGVV1s10=; b=KPikm6A1HIGFZx6M3PEQbALXysuznfyafxzo/IjsZs+zEu6huoiENYd1SImgCFj8Xj SSCc5nVnEZt1j2AuAoo8QbGgjxysOSCwtGm85Z9zKXKXcd89Cy52juw0rQ6z9sU8FVyn Ljl2rAXDbd2gpzVkiJZvpZeSqVYH3jNgZebW59gDuzxEydwZdS8oPx4Gev8ZRLrrxTde QqTDVV0YqkUF87aYWLMsuJjP86eCnII5fQ1wnm/jgh3NnNy8XUUqTA/v5IVplP0rGLg6 aGXoPCphlNkZbpZNJXJMTAfy5OtAZOh+jhJ6R11VIJXJlLa2keytVkHW9Q9fqTeW5bLJ lm9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767778649; x=1768383449; 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=HzF2fslhEEeJTmhuKu2PbDCtac+UTCjrl9KAGVV1s10=; b=T+nm0sDXgLCidZMW+n/b5Y4NoC8EE5XzGoOdt/a0iK63hILVkhxGxHx/3LgVj8uFP3 vHH4noz7xMq7uSrwomDdT4ljuJRk94U7pRT5DbdYY4Jkt/4RnFL0/2YqvfAwfz64bR9j 9Qo4CjYuAYZ5BBvTvzk1mFukzhGuWHcCUySCrVBYPwop28MbyxZGIkC2Hbb0ybGMK411 0Fbo+fqThtdbnyZxHUj8CQv8Dt0havaXNwaXa2dtnfL5zq+NDEsk3Bndge/aq/qxV4uO ONU+cJJFEHLuzXcL93+YYl+qSvd0Mwvi+/5Z/tDiGm3PtMnpt5rZ9aO9vSKzNxnPnf6r uhmw== X-Forwarded-Encrypted: i=1; AJvYcCWYvpTq3k37GiIR8diirDADjgKKcUlQ3+pQnjUaDuiG78zV9XZEADA6CSWoS9peH2XyOIUR/8/aB8W/@lists.postgresql.org X-Gm-Message-State: AOJu0Yzi3Bou+sfxZJMx+VmsejWETB3jvzuEV5TRa3dBevyJ8M/q/kCq 4eaPv63RgrEieaIkFYj2Osu8d0yVybSQju7PVOEAJ2YsbLGl29gAjtSl2a/zddd+/Zd38RRYyCN NZAAutHFZI4jREpSPqPFvzcx57QrF54E= X-Gm-Gg: AY/fxX5L8vFAh/4oN0di6WZW28XlxK9B3JxpTUoXWItnG2UzoKqLZnn6w0zaGBd9CIm 6BEvFU+Ym4fw3oNN1U5uF6QNVqrynzaS9vyhZ+/alkVnHn8DyBDyWv/iHmkxVbXMHrtUUjZqVGX o3RlBWtE9EuQr2/szBqvFRT5aXsZuTeWQVkp7YA9VwgH+wZldNBledBH9gLKYoJuiJB18a5igXt pQZiSb/fcOHui0MXVdp9Yje2NMMr7EHSfm7oQlzhGtD17QacSZ4QL02V96wUbdM1oII4j+p X-Google-Smtp-Source: AGHT+IFyihU1BJIJ52qHfmvXWM6RrCW0kgCBbYvY8rDBqtjzUEzE/8s6KGt5z8qfad9Fy27KFHpWeBw2n7+/Zjk2hL8= X-Received: by 2002:a17:90b:3c81:b0:340:ecad:414 with SMTP id 98e67ed59e1d1-34f68c26c6dmr2178907a91.27.1767778649347; Wed, 07 Jan 2026 01:37:29 -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:37:12 +0900 X-Gm-Features: AQt7F2rDqMb1xMnF9FY4rOjNUVKH_RI74HK5rHa1wy1l03HkBEJLmW7n1GoYFUg Message-ID: Subject: Re: BUG #19355: Attempt to insert data unexpectedly during concurrent update To: Dean Rasheed Cc: Tender Wang , 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 Dean, Apologies for the delay in getting back to this thread (vacation got unexpectedly long for family reasons). On Thu, Dec 25, 2025 at 8:12=E2=80=AFAM Dean Rasheed wrote: > > On Wed, 24 Dec 2025 at 12:07, Tender Wang wrote: > > > > I did some debugging, and I found that: > > In add_rte_to_flat_rtable(), the RTE of value was not added into glob= ->AllRelids, because below codes: > > ..... > > the estate->es_unpruned_relids equals with result->unprunableRelids con= tains. So the rowMark was skipped incorrectly. > > > > I did a quick fix as the attached patch. > > Any thoughts? > > Yes. However, it's not sufficient to only add RTE_VALUES RTEs to what > gets included in PlannerGlobal.allRelids. Rowmarks can be attached to > other kinds of RTEs. An obvious example is an RTE_SUBQUERY RTE that is > an actual subquery that did not come from a view. So, for this > approach to work robustly, it really should include *all* RTEs in > PlannerGlobal.allRelids. > > I took a slightly different approach, which was to change the test in > InitPlan() (and also in ExecInitLockRows() and ExecInitModifyTable()) > to only ignore rowmarks for pruned relations that are plain > RTE_RELATION relations, since those are the only relations that are > ever actually pruned. So rowmarks attached to any other kind of RTE > are not ignored. I also added an isolation test case. > > I'm somewhat conflicted as to which approach is better. I think maybe > 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. Yes, I think the approach in your patch seems better for the reason you mentioned, at least for back-patching sanity. I intended all of these relid sets to account for prunable RELATION RTEs on= ly. Thanks Tender and Bernice for the additional analysis. I prefer Dean's fix-the-executor approach for back-patching. Bernice, are there other related issues you're aware of beyond this rowmark bug? Want to make sure Dean's patch covers them too. > 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. Yeah, I agree it should have been named relationRelids. Perhaps worth renaming in a separate cleanup, though not urgent. Thanks for the patch! Do you intend to commit and back-patch this yourself, or would you like me to handle it? --=20 Thanks, Amit Langote