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 1tAbww-00GjTP-Is for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 21:27:54 +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 1tAbwu-000fHp-2J for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 21:27:52 +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 1tAbwt-000fHg-Le for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 21:27:52 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAbwq-001QM6-Kx for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 21:27:51 +0000 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2ff3232ee75so15422251fa.0 for ; Mon, 11 Nov 2024 13:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731360469; x=1731965269; 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=G1utTa1KFQWuZ7EZ2a/zxTbhYhqeBANvAl2K0ydiW6Y=; b=QweqUpCEXbQsuoWy5ZF5o7o1R4MuVow8AGyCch08twpRiQF6mpAL3fNkd4ABBedKnh E8izCo7Xo43R6jZXcb+GOlvt5vWAAWdOKIn0aF/2DiuLsw9Di7VelBZkAXBCsz0gIfUz V/pecP3gx5YKn41r1z2OmZao0je6uDsCesnXgevpqzvA/qosAKe3hF6iGyTYtQHI/hgp 7/RGnMdCCGmG4VgxFt3lICaf1Iz8KHCqGAh6a3E3JR7prDi9nvKINljOUqOvSZ33iTQB 4ZGmvto0A0Oaslwpqlz9UsGrGDf9jdcRIwn8D66kK67+KbNyLys7VfpYljGINusepJxO rmFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731360469; x=1731965269; 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=G1utTa1KFQWuZ7EZ2a/zxTbhYhqeBANvAl2K0ydiW6Y=; b=FZm3IfzMR/IRHyvlD2eCvNHp3itFw1Feiw/DmTBXUNxSSh9jBxp7hP9ybVMjn8TzG8 NRiPLwIch6Nl2IbNifIxPtS0AR+gDzFVvKSfpRRHkbaCVitvaVggwRdXn3MLuvyTfLqS DwHcUUjqxDEcBdhx05a7tEXjKwZYiCWv+rzFstjyy7Zu18RhEMKd7B5S40LA7EIxt81i eSUPX6dZo9aK1joCktmzNwVxup3/bnRSPeigyu0/bebHqpt7y4XqadgVArdveDIljQ1Y I5SgztPzTVwI5VWWSbRvP9kFa0qqN8WqR5BPZTnm+Eva4Oh7B/Bx8+hCd43gd4VmjFy3 H4QQ== X-Gm-Message-State: AOJu0YzYeAEKHMFOpvU+Fd4BlNWxPtBOiAOd/duwuNSvyV3azFXP4rXs Ojw+YjAzrU85teDBP683iaaTH6Nn4Rx5zbaJA8Cx4TXT7zxxEFTcb1bO32Ri/wKekOGXF+tbySM xhWKzZRQHlCyf/g3SZ9S6wdhy5wG2cYSY X-Google-Smtp-Source: AGHT+IGTydBFQRiv3nWk2L9xTHKdGmpe9niuMtEXUMcWVS2xs8IR50rOrNljmFZS9dnJpD8DCixHfJw2b/G6XvZ1/eU= X-Received: by 2002:a05:651c:549:b0:2fa:dadf:aad5 with SMTP id 38308e7fff4ca-2ff202683eamr69727241fa.28.1731360468597; Mon, 11 Nov 2024 13:27:48 -0800 (PST) MIME-Version: 1.0 References: <1342498.1729444411@sss.pgh.pa.us> <1445998.1729482404@sss.pgh.pa.us> <2062830.1729625620@sss.pgh.pa.us> <2265411.1729699470@sss.pgh.pa.us> <2354718.1729737539@sss.pgh.pa.us> <2581216.1729794746@sss.pgh.pa.us> <1948345.1730500073@sss.pgh.pa.us> In-Reply-To: From: Michel Pelletier Date: Mon, 11 Nov 2024 13:27:12 -0800 Message-ID: Subject: Re: Using Expanded Objects other than Arrays from plpgsql To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000b584120626a9c58d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b584120626a9c58d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Nov 1, 2024 at 5:53=E2=80=AFPM Michel Pelletier wrote: > On Fri, Nov 1, 2024 at 3:27=E2=80=AFPM Tom Lane wrote= : > >> Michel Pelletier writes: >> >> Here is a v1 patch series that does the first part of what we've been >> talking about, which is to implement the new optimization rule for >> the case of a single RHS reference to the target variable. I'm >> curious to know if it helps you at all by itself. You'll definitely >> also need commit 534d0ea6c, so probably applying these on our git >> master branch would be the place to start. >> > > I'll apply these tonight and get back to you asap. There are many > functions in my API that take only one expanded RHS argument, so I'll loo= k > for some cases where your changes reduce expansions when I run my tests. > I tested these patches with my test setup and can confirm there is now one less expansion in this function: create or replace function test_expand(graph matrix) returns matrix language plpgsql as $$ declare nvals bigint =3D nvals(graph); begin return graph; end; $$; postgres=3D# select test_expand(a) from test_fixture ; DEBUG: matrix_nvals DEBUG: DatumGetMatrix DEBUG: expand_matrix DEBUG: new_matrix DEBUG: context_callback_matrix_free DEBUG: matrix_out DEBUG: DatumGetMatrix DEBUG: expand_matrix DEBUG: new_matrix DEBUG: context_callback_matrix_free The second expansion in matrix_out happens outside the function, so inside there is only the one expansion for both matrix_nvals and the assignment. Thank you! All my tests continue to pass and the change seems to work well= . Looking forward to helping test the support function idea, let me know if there's anything else I can do to validate the idea. -Michel > --000000000000b584120626a9c58d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Nov 1, 2024 at 5:53=E2=80=AFPM Mi= chel Pelletier <pelletier.= michel@gmail.com> wrote:
On= Fri, Nov 1, 2024 at 3:27=E2=80=AFPM Tom Lane <tgl@sss.pgh.pa.us> wrote:
M= ichel Pelletier <pelletier.michel@gmail.com> writes:

Here is a v1 patch series that does the first part of what we've been talking about, which is to implement the new optimization rule for
the case of a single RHS reference to the target variable.=C2=A0 I'm curious to know if it helps you at all by itself.=C2=A0 You'll definite= ly
also need commit 534d0ea6c, so probably applying these on our git
master branch would be the place to start.

<= div>I'll apply these tonight and get back to you asap.=C2=A0 There are = many functions in my API that take only one expanded RHS argument, so I'= ;ll look for some cases where your changes reduce expansions when I run my = tests.

I tested these patches = with my test setup and can confirm there is now one less expansion in this = function:

create or replace function test_expand(graph m= atrix) returns matrix language plpgsql as
=C2=A0 =C2=A0 $$
=C2=A0 =C2= =A0 declare
=C2=A0 =C2=A0 =C2=A0 =C2=A0 nvals bigint =3D nvals(graph);=C2=A0 =C2=A0 begin
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return graph;
=C2= =A0 =C2=A0 end;
=C2=A0 =C2=A0 $$;

postgres=3D# select = test_expand(a) from test_fixture ;
DEBUG: =C2=A0matrix_nvals
DEBUG: = =C2=A0DatumGetMatrix
DEBUG: =C2=A0expand_matrix
DEBUG: =C2=A0new_matr= ix
DEBUG: =C2=A0context_callback_matrix_free
DEBUG: =C2=A0matrix_out<= br>DEBUG: =C2=A0DatumGetMatrix
DEBUG: =C2=A0expand_matrix
DEBUG: =C2= =A0new_matrix
DEBUG: =C2=A0context_callback_matrix_free
The second expansion in matrix_out happens outside the functio= n, so inside there is only the one expansion for both matrix_nvals and the = assignment.=C2=A0 Thank you!=C2=A0 All my tests continue to pass and the ch= ange seems to work well.

Looking forward to helpin= g test the support function idea, let me know if there's anything else = I can do to validate the idea.

-Michel
--000000000000b584120626a9c58d--