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.94.2) (envelope-from ) id 1t2j7G-006bdy-Is for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2024 03:29:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t2j7D-003r7A-G9 for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2024 03:29:55 +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.94.2) (envelope-from ) id 1t2j7D-003r71-3F for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2024 03:29:55 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t2j7A-0029af-Mf for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2024 03:29:54 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-539f4d8ef66so5262053e87.1 for ; Sun, 20 Oct 2024 20:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729481391; x=1730086191; 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=Z0ImSDOE/AyolLb1BczL2vhEqZDiKyE6eZrneAD4BSQ=; b=JFdj61ANZi4kTMwt6aGnTIZ+fdtlJXjqnhisZRDeYX5qImKn7t2WnpzVYuGqHSA5XI umHi+u9pARokKdjq4sBKpHcWPf0BPe10Ns+MVU6IqiozQcHa5/pGu5GcxJCvljNiqAKS 7sx6oEI5Uz583UDihablzAGcWv2VT+2UvuPLhwIrJRIjHhHTP+7fuD+LQ5ei0UDVPfLC WjL7uxFnBbX4/dBjFNizh6cy6NqXrpkvM0pu4plrd488nTfVSpfVmmKESU+Oa6zTXULs rD7G6i0EmTV4vLpfimqc1ewbffcYAfwBTowJOH2QayH3OfLnKFkTrx3msTCs3jDZ2R/a 8kXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729481391; x=1730086191; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z0ImSDOE/AyolLb1BczL2vhEqZDiKyE6eZrneAD4BSQ=; b=DOZvc7mFevzGbIJ1sEIfMBmf9pTApLl89l9anofHcTtlNBDcJrELJ38V4uOjMmsiOi RiyXnPlLiyDjhuslUvy8SfH+gPT73fwOeoUVaWVA0OsPll68ig7wgq9zAdfDstasPNm6 NkPwiLLmD8RviFvcYiRD8ukbqH26EVhG2RviaP4kA4qBbVHsrMJIhJzVEJmwHf7GmtAQ Y71LXr8FAhEYaEm0+tSj6zRaKYhWCkZHJIzWdeB7J0F6uhT8xLk7laX61PGZyP2Gx4IC 6dS4hSEEOn9thv9j64ugDhwf52U9c9XhtMmFk9cqEcaWSj9193KqC3QlRIlfA3cMsKqw D+TA== X-Gm-Message-State: AOJu0YwjQbTioJO9DsisFVRgHuf6zPQdKxpG/Pe5D6RM1GJgaDroGvG2 IughcjDTmjZpJVvgNe6VLTj5Vh5jBbwMuwkxg/BntIrl28Bf6Cw5HPp8utRO08lZoxOONqxl9nZ iyCwIevaurApGDa+6xPrvI9kc0rPvBgCL X-Google-Smtp-Source: AGHT+IFb7lrW4o/zNtaKDfSTrru+K37/VMJnvf4gGsnNj4c3RbwQc+P6pwoWoP91u8RsDzslsgPk49FL00Xtog3L0w8= X-Received: by 2002:a05:6512:3083:b0:539:f949:c027 with SMTP id 2adb3069b0e04-53a15219738mr4129472e87.18.1729481390313; Sun, 20 Oct 2024 20:29:50 -0700 (PDT) MIME-Version: 1.0 References: <1342498.1729444411@sss.pgh.pa.us> In-Reply-To: <1342498.1729444411@sss.pgh.pa.us> From: Michel Pelletier Date: Sun, 20 Oct 2024 20:29:13 -0700 Message-ID: Subject: Re: Using Expanded Objects other than Arrays from plpgsql To: Tom Lane Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000ea61e70624f44321" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ea61e70624f44321 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Oct 20, 2024 at 10:13=E2=80=AFAM Tom Lane wrote= : > > I'm not sure. It seems certain that if the object is already expanded > (either R/W or R/O), the paths for that in plpgsql_exec_function could > be taken regardless of its specific type. > > But it seems like we could get an easy win by adjusting > plpgsql_exec_function along the lines of > > l. 549: > - if (!var->isnull && var->datatype->typisarray) > + if (!var->isnull) > > l. 564: > - else > + else if (var->datatype->typisarray) > > How far does that improve matters for you? > I tried this change and couldn't get it to work, on the next line: if (!var->isnull) { if (VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(var->value))) var->value might not be a pointer, as it seems at least from my gdb scratching, but say an integer. This segfaults on non-array but non-expandable datum. I guess this gets back into knowing if a flat thing is expandable or not. I'm going to spend some more time looking at it, I haven't been in this corner of Postgres before. Another comment that caught my eye was this one: https://github.com/postgres/postgres/blob/master/src/pl/plpgsql/src/pl_exec= .c#L8304 Not sure what the implication is there. -Michel --000000000000ea61e70624f44321 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Sun, Oct 20, 2024 at 10:13=E2=80= =AFAM Tom Lane <tgl@sss.pgh.pa.us> wrote:
I'm not sure.=C2=A0 It seems certain that if the object is already expa= nded
(either R/W or R/O), the paths for that in plpgsql_exec_function could
be taken regardless of its specific type.=C2=A0=C2=A0
But it seems like we could get an easy win by adjusting
plpgsql_exec_function along the lines of

l. 549:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (= !var->isnull && var->datatype->typisarray)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (= !var->isnull)

l. 564:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 else
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 else if (var->datatype->typisarray)

How far does that improve matters for you?

<= div>I tried this change and couldn't get it to work, on the next line:<= /div>

if (!var->isnull)
{
=C2=A0 =C2=A0 if (VAR= ATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(var->value)))
=
var->value might not be a pointer, as it seems at least f= rom my gdb scratching, but say an integer.=C2=A0 This segfaults on non-arra= y but non-expandable datum.

I guess this gets back= into knowing if a flat thing is expandable or not.=C2=A0 I'm going to = spend some more time looking at it, I haven't been in this corner of Po= stgres before.

Another comment that caught my eye = was this one:

=C2=A0
Not sure what the implication is there.
<= div>
-Michel
--000000000000ea61e70624f44321--