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 1w0jlF-002ALD-15 for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Mar 2026 17:23:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0jlD-00G4p0-2T for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Mar 2026 17:23:48 +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 1w0jlD-00G4os-18 for pgsql-bugs@lists.postgresql.org; Thu, 12 Mar 2026 17:23:48 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0jlB-00000002KbQ-0PnV for pgsql-bugs@lists.postgresql.org; Thu, 12 Mar 2026 17:23:47 +0000 Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-8cd71fb9f06so87094285a.2 for ; Thu, 12 Mar 2026 10:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1773336223; x=1773941023; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=k8/VaNCLfONpuzhosCxEODV5AEdRZ6yrP5g3xf8S7OA=; b=YCC821tpM7ng9mUUsVd5TqLlWVoRBQIjfUSKyzNFbBUWLnF+1DAH2FASY1jUbMkcH6 ZWmIRZ7FVgSBmHi/WXsqm1GZtiaTYWKVEtnTEMzSSpC+Gm7HcoS2zyuBe8wMtuh/pnMx rDEUJqoWpzQ3OvxRrI2Q/9x7KMALpBa++MM3qMwH1RdDhfsPSHWtewhvM6Jwo7BopWrh tIM1sEednxUxL7K/SuEwpgZJQqtYg6w2UJDOEFzt9x1Q3KbD7l1qBd+ulaYFzyZx8nWO 5g6LCNjYBRnim6C0rtf5FrBhTPP69OCZNsYDCDjOZAhj7sIMlFSiX5yE614XO+skgcXf KVjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773336223; x=1773941023; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=k8/VaNCLfONpuzhosCxEODV5AEdRZ6yrP5g3xf8S7OA=; b=JEP7FBS0I7R6QBztFlFaSBuBzWFiwVThqbCbdj2McGb/cmv9ivd+iIXtqZYNr4bYDo eWh3fW63yQnW6bX6dlQhiMORMoMk/pxYaDe2kfLP66zC9/plZQdBj7vYxU6naxMEg/XO IqMtz0nGyrC60FbEeUiicJQzLz87QXzo1+C8Q3OJ0pgx/AdEsR3K5GoBH+lviy59/ErK qQGl/haMaQ3BtDLK7dfC50EHLjokNFdu69jN24F0PJRMQqBItZv3J9aN/UscaCMJx/z3 Zog1AnyqiNRw2TrNc+NoyaA/Q5PBbuXJ+rYQjU9bQA8e6Te7cspGFqQfll91tRIxehDG 8LSA== X-Forwarded-Encrypted: i=1; AJvYcCWdXdUYkAESWR4HVZ8t4xut9C+Pl81gDC1oj7MbDWowAs8I4brlMvyqxqTMSWGgyD8LKUS/SK2GZAVZ@lists.postgresql.org X-Gm-Message-State: AOJu0Yz9o3ZF+JLOqRT+1mI9ZKWIfDb1711YbIDCLJn/7Pq4Scmpl+go mW/6yrfkQvJ5OTp7dsrrDflkYf/W1hX61ewFe7SO61tYjXK+KUKUnMDFFY4gBka6n1N19G7FY1y MZoC0 X-Gm-Gg: ATEYQzzEwzoBIwsQLAXZmLMx/IrlWT3Ndjjzyy553ICv7Yp6xCjO+8Wm8ZKNI5ON8FA bZ2mL0l0EJ9Qmnl4KcHwXpelS5sWGX3l3PO8LN4F4HG+aGYEQfJxIEx1LZqScl004ZLIOXm1aun tYcx58klwb+uMRm2gEQ/vrcVVR4l6zi1BFy5hFpRaPOCS+c13IeWSKpr5GGKRtIfycmABWLy2aB 98YQc+IZG0G7e77w8xFZzLlTgNfS4l5QGeFtuIAaevaMgcKCwrbf7+QkZNzCgcKHvBsocClWGwe nCsylFNjAFhjdzWoJ76HbCX0CCyBq3J3SQBWOog8SFKMT4T+9YdPrbVVI6ubNxQXnDCiFCWXSxx zgByCb2pmkEo88x52AFp4bew0BX0Sf/dLP1N7UyhFC35WgSwm7dm7J4i+skyAkF9dri7lhqKHmN PN6BbH8ko2/AIuYMmBlQ93MyNV+mspmnjSmeUHIfiV X-Received: by 2002:a05:620a:4416:b0:8cd:8938:f007 with SMTP id af79cd13be357-8cdb59ec189mr76143085a.11.1773336222438; Thu, 12 Mar 2026 10:23:42 -0700 (PDT) Received: from ?IPV6:2605:a601:a6b0:500::1cb? ([2605:a601:a6b0:500::1cb]) by smtp.googlemail.com with ESMTPSA id af79cd13be357-8cda2151db2sm366464385a.44.2026.03.12.10.23.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Mar 2026 10:23:41 -0700 (PDT) Message-ID: Date: Thu, 12 Mar 2026 13:23:40 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19431: limitation of the data type jsonb equals 8Kb To: Tom Lane Cc: perovaa@sbermarketing.ru, pgsql-bugs@lists.postgresql.org References: <19431-0a33306c00df939f@postgresql.org> <5e048736-26bd-4254-84fa-c74ad0bf0c88@dunslane.net> <4517.1773330924@sss.pgh.pa.us> From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBN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9dkEiGjgna2Rk6e15kln4ZvFBWUg23p93w/pqXcxY6+k/8TEk+C4R+M6w7o2PLGOjdZ +kPiUcw5H85zf/yZJwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaYL++LAEOqrlvm2Tvq QqZRtnEAEQEAAcLAfAQYAQgAJgIbDBYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNI2BQkd EODdAAoJEJn6f8tZ/DuBfw0IAKTsfD40teP/pp+bsLLMSxPXUYrrprTj7WFB5v61p6dkpSr/ qXmMlyahdxQFaPmfVgVirB1Vk/kHiWNnnGjfUV9nB2Zg9LI0Xb9/ts3LsUiRWXzG3tkMY6XL vsVOxW4XFRND9l2q+WW93aZ1DZl+fqWfYgMvsusFRhmGFOKTRfKPta2Pkv+AhA24N4+PrR5p bU4k2MO8PAGiK8eaYKGFG1bHKuAvoDoF7WXJ3FHxuWqLnKEt4dfOLm5pAe3zq1Lt6q8azT9i QWGpSAK5vQUWQHBHpiDjdPeqKZ6HiAXIIKfSmb+jrvXBqoP+D6/K7rUjG2aXiRtTIAXms9sm VRu7cmw= In-Reply-To: <4517.1773330924@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-03-12 Th 11:55 AM, Tom Lane wrote: > Andrew Dunstan writes: >> On 2026-03-12 Th 8:11 AM, PG Bug reporting form wrote: >>> The following bug has been logged on the website: >>> >>> Bug reference: 19431 >>> Logged by: Alex Perov >>> Email address: perovaa@sbermarketing.ru >>> PostgreSQL version: 18.3 >>> Operating system: Windows 10 >>> Description: >>> >>> Hello. >>> I have a type: >>> CREATE TYPE public.t_dict AS >>> ( >>> id bigint, >>> name text, >>> gid uuid, >>> alias text, >>> bgcolor text, >>> disabled boolean, >>> checked boolean, >>> options jsonb, >>> "order" integer >>> ); >>> and function >>> CREATE OR REPLACE FUNCTION public.f_func(data jsonb, uid bigint, context >>> text = null, ext text = null, pid bigint = null, pgid uuid = null) >>> returns setof rd.t_dict >>> language plpgsql >>> AS $$ >>> begin >>> context := coalesce(context, data->>'context', ''); >>> ext = coalesce(ext, ''); >>> >>> create temp table tmp_f_table of public.t_dict; >>> if dict = 'dict1' then >>> insert into tmp_f_table (id, name) >>> select >>> 1, name >>> from public.tbl1 a; >>> elsif dict = 'dict2' then >>> insert into tmp_f_table (id, name, alias) >>> select >>> t.objecttypeid, t.objecttype, t.alias >>> from public.tbl2 t >>> where (t.objecttypeid <> 0) >>> and t.active; >>> elsif dict = 'dict3' then >>> insert into tmp_f_table (id, name, options) >>> select >>> t.linktypeid, t.linktype, >>> json_object( >>> 'rev': t.reftypeid = (data->'objecttype')::bigint, >>> 'items': t.options >>> ) >>> from public.tbl3 t; >>> end if; >>> return query select * from tmp_f_cpdictionary; >>> drop table tmp_f_cpdictionary; >>> end >>> $$; >>> when calling a function for dict3, I have an error "could not open relation >>> with OID 196327". >>> As far as I know, this is due to a limitation of the data type jsonb equals >>> 8Kb. >>> Is it possible to fix this error without changing the logic of the code? >>> >> This has nothing to do with any limit on the size of jsonb, and in fact >> jsonb can have values vastly larger than 8Kb. >> The real problem is the well-known plan caching + temp table OID >> mismatch issue. Here's what's actually happening: >>   1. The function does CREATE TEMP TABLE tmp_f_table OF public.t_dict >> at the start and DROP TABLE tmp_f_table at the end. >>   2. On the first call, PL/pgSQL parses/plans the INSERT INTO >> tmp_f_table and SELECT * FROM tmp_f_table statements, caching plans that >> reference tmp_f_table by its OID (e.g., OID 196327). >>   3. On a subsequent call, the old temp table has been dropped and a >> new one is created with a different OID. The cached plan still >> references the old OID leading to "could not open relation with OID 196327". > I believe we have replanning logic that will handle that. I think the > actual issue is that the function tries to do this: > >> return query select * from tmp_f_cpdictionary; >> drop table tmp_f_cpdictionary; > The RETURN QUERY stuffed the data into a tuplestore ... but what it > stuffed there was TOAST pointers referencing the temp table. So the fetch > failure occurs when we try to read out the tuplestore contents after the > function returns. While the OP didn't say this in so many words, I gather > that he found it to work fine for small jsonb values but not for large > ones, which would be explained if it only fails for toasted values. > > In principle we could fix this by forcing the values to be detoasted > before we put them into the tuplestore. I'm not sure that we want to > accept that overhead though. > > Oh. Hah! makes sense. I learn something every day. Sorry for the noise. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com