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 1vbQgv-005KIi-2g for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Jan 2026 21:58:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vbQgs-008x6o-1s for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Jan 2026 21:58:43 +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 1vbQgs-008x6e-10 for pgsql-bugs@lists.postgresql.org; Thu, 01 Jan 2026 21:58:43 +0000 Received: from mail-yx1-xb12f.google.com ([2607:f8b0:4864:20::b12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vbQgr-003iMl-16 for pgsql-bugs@lists.postgresql.org; Thu, 01 Jan 2026 21:58:41 +0000 Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-6446c2bbfe3so9195425d50.1 for ; Thu, 01 Jan 2026 13:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767304720; x=1767909520; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=9DBLeP4R88ozhLbJkIO1qAwSK7u4wTkbbg9uNj/+TzA=; b=MvTcvUUDEpkzzezH3LMpAcnZGWTMGYYdKhUbclmRXd+hZBQEhl+OQvxFuSrwF6yNd5 /0jK62gqDLTdcw42G8diwlslzYTsHFw6AvdgGLWY8Hk2mMo3gHhocUcGZKR2Zf/7yHXr 4HBzFWNMHjkGBJ+KrLyxNN/pQa/ZPYbMOp4poK5PSZSxm5Wtu7acGM/xsADJhLYyokPQ M40A12ztICa4pcTzyEITSzH1VWZQppfAGgyqo0ia+5Kx3HNu3g9nzpD4gmVXiJE+A3f7 gEmjBWL9zXiVFpbpjbh9Ic9anFoIQbyqlzaHvH6R7OFuxtMlwoCiWn52Qmnl59MN6e8/ 3dyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767304720; x=1767909520; h=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=9DBLeP4R88ozhLbJkIO1qAwSK7u4wTkbbg9uNj/+TzA=; b=Cbt70UrOKcN/MVyH4a6W/caT1H4Uq0uIWMJ51+OP6qfClMRGx7tkjWIssour2PgYG7 +guSZeRj9DIg3jTl0AQ44GX00ljvjdcuqKEyqibHcn6b6InwA9tiGESzgB17MRdP8gOb AYczvEGWwmirFOdWvSfs4bsC0zHN5p4MGMqZftUdWlj1mp8u7mu16E9aKa4u412Zowzk B6pP7CWh1cmi2xMZmdEmKg8FmwpcJnp6h3c3i/Ikif6RFEVU/u3T16GCzM+BARE1g+Eh nao/VAtB8R45yC7dduFkCR05UFQok5aGRvGW1oY2F9RInIEgc/kCp30APmKxiI4cOlvy /rJQ== X-Forwarded-Encrypted: i=1; AJvYcCXAEM5oppuIofYB5L0hGLIjm0E3eWv+Thvl0mxo2TMSxpemiyPFOVa753U1aQQjvKkrtW74V4Bq+ya/@lists.postgresql.org X-Gm-Message-State: AOJu0YwX/B4iiBjqepn86xt4PN1L6emRifWv3hJvt5MZgvZwionpH2Do jk1lIPvdCJE1ro8CAhBcqC6BlhWI8tNpw47aqHDm+T7y8CjXfjIAzf5GvAuNBXD4T1s/JVo0vNd cpKrZOmkbiK1TmvSK1jorRrY4Fylgv+Q= X-Gm-Gg: AY/fxX7iuAR2RaR0HtWtI3zXEs1nWYiZzODUxvWH8T/dFavfdCNuwwIAYkuFFjIv1pk rBNqSuJr+OGOJLJUzY+k6A2ntgYh8x3S7lSD12FGHOtF3y4f7KGulstbfiIYTU5q22ScwgScujd dSa4aAErfxd70SSuV3r+RYhB/VKPcR6j186weM15FW+tURm9Pmi6H9vDq+gp/7/adV34xPvRs5o EVj6IOKq5NC1Oel4s0HWjftbWUXIl+QJ+N9zPcxcReVouIpOby6BYTMZafkYWK95c4OknhSPpgR ajwgMHlxxPjP4rxi0xY= X-Google-Smtp-Source: AGHT+IFKV/pqoljLVtP0fHElhgGMI1qPUvBa4q4fKlXSG45HvMbKw2vC+VpZBfflqSDFrYfYFrOxT67i0fH6gRr0sL4= X-Received: by 2002:a05:690e:2513:10b0:644:7933:ae89 with SMTP id 956f58d0204a3-6466a8d621fmr25331195d50.89.1767304720307; Thu, 01 Jan 2026 13:58:40 -0800 (PST) MIME-Version: 1.0 References: <19355-57d7d52ea4980dc6@postgresql.org> <868ff2a518820c8864b6d28510294b2457a126af.camel@cybertec.at> In-Reply-To: From: Bernice Southey Date: Thu, 1 Jan 2026 21:58:04 +0000 X-Gm-Features: AQt7F2qg4x7swHsyBHnjzTQkZss7JzTzE25SBDftumUsFN7QyKxLNSVoWJWLLSQ Message-ID: Subject: Re: BUG #19355: Attempt to insert data unexpectedly during concurrent update To: Tender Wang Cc: Dean Rasheed , Amit Langote , Bh W , Laurenz Albe , pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > > Dean Rasheed wrote: > >> 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. 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 = top_plan; result->partPruneInfos = glob->partPruneInfos; result->rtable = glob->finalrtable; + result->unprunableRelids = 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. 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+? I can really see these much appreciated extra features and enhancements don't come cheap. Thanks, Bernice [1] https://www.postgresql.org/message-id/CA%2BHiwqE7%2BiwMH4NYtFi28Pt9fT_gRW%2BGt-%3DCvOX%3DPkquo%3DAN8w%40mail.gmail.com [2] https://www.postgresql.org/message-id/CA%2BHiwqHRRFQN6yZ54fBydOTM6ncqZBCmewZ6n519RjRdDsO44g%40mail.gmail.com