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 1whqTt-000S6C-2q for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 15:16:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whqTs-00DUcq-0c for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 15:16:04 +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 1whqTr-00DUch-2x for pgsql-hackers@lists.postgresql.org; Thu, 09 Jul 2026 15:16:04 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1whqTp-00000000Uik-2r7N for pgsql-hackers@postgresql.org; Thu, 09 Jul 2026 15:16:04 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-698b6c87884so3394684a12.2 for ; Thu, 09 Jul 2026 08:16:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783610160; cv=none; d=google.com; s=arc-20260327; b=etQz0rcQZfUfHgfvQyVChu8uSkMrMGrxq658NYcoy3aQOeH4EcuLGOUaXBXmPNDGn7 kqsztm7C38Whq8jNt4txbA3YZ87t4EZ4pnibFmEOyyi5ciGpvgF6TbZNg8qKi2jwmZKJ NGXJxbaTLslcP3I0WvcpcZni4LKCu4QnlsnYlQuUpBUJL7GihsYfPRobmjR85Dl3p5oW Nn6SNhqYB6VK54/yn1mA1o1B3mteyw89PDpdIdgaoX/WRor2OIvpSLNbjV34ks9Iv0yA tGV82upoCPV+qizbZISZMqfSorQ23LEycK8p3I87fhSPVy/CyJk62zfmHCmlT3Or0KkI A2uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jikP/NPRErJrW1DzE9kMCCB/Ts1IxjWVU71spTDEObA=; fh=SGCcWlSuIDVccXQZ+Oi6OvsLiJQMF7bsQbsvhEREeuE=; b=Yl0ey4CSCaJPOoGMJn2yixUcIUP/YOQMPiVrTpwZ7iW3vrbRf5rH634w2fsNQYTZfJ p/nzBS5gRjbUQ6scOedpFSgOS6x5rxVwsBI/ouvaVkaACzEwwu1q77EZV3WZWIciiSzt O0gjGUcCO08chfNoMjV1L6x3CoLdvQhiJClQIMRD2d3njnvYPpE63WIOg/ai1D5kl4Vw 9Sb0WZX8MeDocsaCFZCAhOpW0MKm/wUNamHToKL+M1NBGHe6SVFV5rJ6kH8N/fCGVCCp d2/bRxzwAPuq4+YzRDBMVFU2txtbT7BAl1EoYbBn1bYurlCpsz9AsyYXU0f3gehzUuF/ KREw==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783610160; x=1784214960; darn=postgresql.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=jikP/NPRErJrW1DzE9kMCCB/Ts1IxjWVU71spTDEObA=; b=nZDRGAXax5+hzQ/XW+CcuqpnW+x0t7awYxoOPt6iS9m53iURaYJv2y7UbbS+GeL3gr RX+pE+50M0a4W4L3z7mfx/FEruzy0WyWWVbw5q9TMo+ZVBhc/VpscDjalzlp7OR0BIDJ uCuk2VWjNt2RP7LccovdTYzNzcxQ/5063CriTS5hS3g7Ikc6qqN7WgSlQge+ghnjgwH2 4HU8tzTXooGrK27TF6mfIAk/+sfZQfxrs5Xu1f2zHVbvJkTzP47fZAeBXsLumqSDFeQ1 cs+THsI+lJUfbAsn6or3NGvUrDcss5m4kfLg1zgRduKhMtrtHUkMo+joJWvmnpIBLs3O ESCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783610160; x=1784214960; h=content-transfer-encoding:content-type: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 :content-type; bh=jikP/NPRErJrW1DzE9kMCCB/Ts1IxjWVU71spTDEObA=; b=tR3HPcJmIS5X73TBh1ufsS5L+1ujJdtIbj0r7J4eSD71USh0DtIrTVN3cESCZeX5xJ cTCK0FQ2JtOgmv6N93rU/Bkul3uTLH7DdPacWrZJirH7BVCPE7Urc1Al6WfiOmTi13fn 2uUFyQayVwEo0O8Q42PY47sae0uej3Gx/hZ3DmZns1LmirqiExJmkJbVaieArI59ZtcV mUOhSKko/HhF+DIjcUbmY829HsTMJTgmn3pz14tOjAydBa5daCHjij7IlJ04hrZZggr5 ieEf7FxAM4ewUhnHrJ7esOkRaob6gbWPfQsLmk23DtwQERMbyEb17Lt0K3dE4II6ac6m +myA== X-Gm-Message-State: AOJu0YynQzBOfosXM5e1n/tVLFNhRnK3utBGS736wngxF1GkG0VAADoe MoRl9RLpBCXRtuulOtHCgILtR1F5nq0P0kFP5wC4RTbcUpcqDt958a/2t9NjUp6xgfP8iemJPbx mAh5ljigFUSG/pZns6zv/QaQQfvz6+dc= X-Gm-Gg: AfdE7cn2oqcX0p+Qf6GYQ+VMf+ZHxhQ1IoCeSpj9W4KroJAKaE2CD1nmFyMXMI/M5VH TLqIQHfCjOqp2HffmtOhEShZidRnKXNbizNVnGy5Sc7C5H2nhgDwC/eeg5oWitfjKaMvMJt6DhN 6jMbwXxb7RLwiNxZWO8sfSWBBqQlde1YjfA0nCQ9ewf+/gmG1cBM6SudexaLtHI6abOYlmyCnoU VAqLohYVYNuQC/NT94aPOC5Lt5W/T8KaRJjv9+Unoap8kfUqCgz9NkwDt883WfpujlcCMBkl5/b GnNY6V9XtA00RY0S0nxAUBtJylUR3A== X-Received: by 2002:a17:906:33c1:b0:c12:7476:8913 with SMTP id a640c23a62f3a-c15cded11d8mr355270966b.11.1783610159611; Thu, 09 Jul 2026 08:15:59 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Thu, 9 Jul 2026 11:15:46 -0400 X-Gm-Features: AVVi8CfLBkNJvS09NYvejBepDFGp3jVYkZrNTlj62a2kZ0zfyFgmNBPMQ0Y2gsA Message-ID: Subject: Re: json/jsonb cleanup + FmgrInfo caching To: Andrew Dunstan Cc: "pgsql-hackers@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, Jul 8, 2026 at 11:16=E2=80=AFAM Andrew Dunstan wrote: > Looks pretty good. Thanks for looking. > The old `add_json()`/`add_jsonb()` helpers (removed in 0004/0005) checked= `val_type =3D=3D InvalidOid` and raised a clean `ERRCODE_INVALID_PARAMETER= _VALUE` / "could not determine input data type" error. Now I think we'd get= something like "cache lookup failed for type 0", which is rather more opaq= ue. Not sure if that matters. I definitely don't want to show "cache lookup failed" errors, but I don't think that's reachable. If I'm wrong and it is, we should add a guard. Do you have a test case, by any chance? > For VARIADIC arrays, > > for (int i =3D 0; i < nargs; ++i) > fmgr_info_copy(&(*outflinfos)[i], &jcache->flinfos[0], CurrentMemo= ryContext); > > is going to copy the same flinfo for every array element for every row, T= he comment says that it's done that way to avoid complicating the code, and= that seems reasonable. I don't know how often these functions are used wit= h explicit VARIADIC array arguments, so it might be a niche case. Right. I think it is a niche case, but I also don't think this is really costing us anything. As far as I can tell from my benchmarking to date, fmgr_info() is kind of expensive, but fmgr_info_copy() is pretty cheap. So, we could arrange to share a single flinfo for every argument of the VARIADIC list, but the savings are pretty limited because we wouldn't save fmgr_info() calls, only fmgr_info_copy() calls. And on the downside json{,b}_build_{array,object}_worker would all need to support two modes, one where there is an fcinfo per Datum and a second where there is one fcinfo for all Datums. There's a code-complexity argument against that, but it would also have some cost in CPU cycles, because every call would have to branch into one path or the other. We'd be slowing down both variadic and non-variadic calls slightly by adding those branches, in the hopes that saving fmgr_info_copy() calls in the non-variadic case would be valuable enough to make it worthwhile. Somebody can certainly try that, but my guess is that there won't be any performance benefit worth caring about and the code will be uglier. --=20 Robert Haas EDB: http://www.enterprisedb.com