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.98.2) (envelope-from ) id 1xMgsh-000000029Tv-46Sl for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:32 +0000 Received: from localhost ([127.0.0.1]:51196 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMgsf-00000008qJy-2M2n for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Oct 2026 07:18:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:58268) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMYZS-00000006Ws9-26st for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 22:26:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMYZQ-00000001b4a-3Yb9 for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 22:26:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=jmGdkD21WSFP3J2iQ7woEyPjQHbct/7RFcJD89xXQMw=; b=k290dQOG/MEpmWIfGkDraSzNNW EHe4CiqqROVBSgUB9eFsLaJUG1lVsCRQfQu9aRqI7T1pagz64MCdH8ZqnnRUeLHfvIO0IMds88mPt pdGUY9nOkiPg4aW7eq03R0bfM/S1o2Ku/lUp/EZLnl+1ECYxFBXLp1qLolyblxpfkJR56Nb7yKsAd MZOlNqr7NW9KcLvWjVlY+88i0cPv6FGtZwN2mzVv+cHfbKwmK3CbZj6izjsdi/i2NNVZ0ik68hwh0 eSyg4EF3DHiMJJObS8YttSWWWD4tBjZpXRoosOi19HE0xOwIKFtnTLjJnZYs/BhnpiH4h6tOfW/VG FzvLMKBA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xMYZQ-00000004bba-1XOk for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 22:26:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xMYZO-00000006axK-1fKo for pgsql-bugs@lists.postgresql.org; Thu, 29 Oct 2026 22:26:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19816: PL/Python SD dictionary is split by input collation in 19rc1 To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: marcos.castedo@anachronics.com Reply-To: marcos.castedo@anachronics.com, pgsql-bugs@lists.postgresql.org Date: Thu, 29 Oct 2026 22:25:07 +0000 Message-ID: <19816-921b5cbc3ee63146@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19816 Logged by: Marcos Castedo Email address: marcos.castedo@anachronics.com PostgreSQL version: 19rc1 Operating system: Debian GNU/Linux (x86_64) Description: =20 Version: 19rc1, built from the postgresql-19rc1.tar.bz2 release tarball, unmodified. In 19rc1 PL/Python uses the generic function cache (funccache.c), so a function gets one compiled entry per CachedFunctionHashKey, and that key includes the call's input collation. Each entry builds its own PLyProcedure and therefore its own SD dictionary. As a result, SD is no longer shared between calls to the same function when the calls resolve to different input collations. The documentation describes SD as private data "between repeated calls to the same function", and that is how it behaves in 17, where PL/Python's own cache is keyed by function OID (plus the trigger relation). I have not checked 18. Code that stores state in SD with one call and reads it back with another now loses it whenever the two call sites differ in input collation. The most common way to hit this is an optional text argument: a call that passes it has the default collation, and a call that omits it Steps to reproduce: CREATE FUNCTION tt(set_ boolean, a text DEFAULT NULL) RETURNS int AS $$ if set_: SD['x'] =3D 1 return SD.get('x') $$ LANGUAGE plpython3u; SELECT tt(true, 'z'); -- 1 SELECT tt(false); -- 19rc1: NULL 17: 1 SELECT tt(false, 'z' COLLATE "C"); -- 19rc1: NULL SELECT tt(false, 'w'); -- 1 (same collation as the first call) SELECT tt(false, NULL); -- 1 (unknown literal resolves to text, -- default collation) Calls that agree in input collation see the same SD. With an optional argument of a non-collatable type (int), all calls share SD. GD is not affected. Expected: SD is shared by all calls to the function in the session, as in 17. Actual: SD is partitioned by input collation. The collation is part of the key for good reason in PL/pgSQL, where it affects the compiled code. PL/Python does not use the input collation when compiling, so splitting the entry there only splits SD. A possible fix is to keep the SD dictionary per function OID, outside the funccache entry, and have every PLyProcedure for that function share it. Another is to leave the collation out of the hash key for PL/Python. Plans that callers cache in SD with plpy.prepare() also get duplicated per collation, but that only costs memory; losing stored state is the visible regression.