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 1tAc3d-00GkFw-GK for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 21:34:48 +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 1tAc3a-000iao-G9 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 21:34:47 +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 1tAc3a-000iag-5S for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 21:34:46 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAc3X-001QPD-9m for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 21:34:46 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2fb561f273eso38837041fa.2 for ; Mon, 11 Nov 2024 13:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731360883; x=1731965683; 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=HMrr4NVHDcg2NHIrK8rRSgDEmm2en9gqFHAEg4pixgE=; b=lsd7E294MfikTJmzWGSY+u9OotssfgtYjsgKXlZgN1Btn9WS9MT8GPr8dXANMuAINw mLqlAvRpaz4MaaDtC+J9dqsV2o8u3/2mJ5KSO+uD6ZOGDAmlL5g+qDdDikZhqSp6xXEO qlirPeFub3hNix0vRiWuNVy2E8j7v7pAvAX43GXcciRvB81tpfgB+R97ktFPXVcnHYsa 5qiY2z6MNtvqXfyWywULfKe7MpvhlhO9VmmGRpniBDnA5y+xlUNVB7IUTyQtaOo9Wyke 9swQybOd0uUA762S0mGz0LdQIljN9k658N14uC1M0O+atN81+/L/w79aoPAbcrkHJ4st mtUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731360883; x=1731965683; 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=HMrr4NVHDcg2NHIrK8rRSgDEmm2en9gqFHAEg4pixgE=; b=Xd1pFYfdJeKY9WKY0ku9DF9syoTr3FS+VO4DY9u0RVCcvvaQJ0MIQ3Ek4HQlKoVWRI U+X2xm9ujKnyZ81LAZGKxUwBL091iVI1UkFc9wLBjvZhM0nEaOGt7XbFKq3T5NRH8v1L ljuEffqUJH8xiQA/wfKEG7BwKO/B/9P7+KiMcnw+e1VRZe0cqhuwGCpH9Ra3+ASU9D9k km+qivgwwGfWXR3MT3y12Sf+LcDDmewPSuSxWhZLxeKVyeUzXK3I1+QXnncBMEm+ASdn jFo0FLHofwrNkR8kqqgM5tDX0oCeVa+bMVuvc1xzTOHu0OsVvgHvh+BCo80AA+BG5O+u OiqA== X-Gm-Message-State: AOJu0YwFbxMkfJraHBrYJZSupbjbteFLNvfS9ZzjoVzfh0EUIcAHYJwZ zMiDkWddHr6MnN1f2AT5bll9saxJu3gB1vykat9M2NBGVpxFTo/tBvWp5yKYIkJNcRXovz3pirj 9qFGUbvh/uQSSyWr4b2w73K8c+jN12a6S X-Google-Smtp-Source: AGHT+IE1AbB5gM7jAUr+306hS8CErFBnz3x5RXXCp7pxcp74ZUq4AjqIeOpAgUjYAVztw8TlY0dR4RAiHwLcmCu0UK8= X-Received: by 2002:a2e:beac:0:b0:2fb:4a63:92c0 with SMTP id 38308e7fff4ca-2ff426a4742mr1836611fa.14.1731360883045; Mon, 11 Nov 2024 13:34:43 -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:34:06 -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="000000000000697b280626a9de43" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000697b280626a9de43 Content-Type: text/plain; charset="UTF-8" > > 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. Hmm, well I spoke to soon looking at the wrong function without an assignment, I've been down in gdb a bit too much and I got mixed up, here's another function that wraps it and does an assignment, and it looks like there is another expansion happening after the nvals but before the assignment: create or replace function test_expand_expand(graph matrix) returns matrix language plpgsql as $$ declare nvals bigint = nvals(graph); begin graph = test_expand(graph); return test_expand(graph); end; $$; postgres=# select test_expand_expand(a) from test_fixture ; DEBUG: matrix_nvals DEBUG: DatumGetMatrix DEBUG: expand_matrix DEBUG: new_matrix DEBUG: context_callback_matrix_free DEBUG: matrix_nvals DEBUG: DatumGetMatrix DEBUG: expand_matrix DEBUG: new_matrix DEBUG: context_callback_matrix_free 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 So going back on the assumption I'm somehow not returning the right pointer, but digging into the array code I'm pretty sure I'm following the same pattern and tracing my code path is calling EOHPGetRWDatum when I return the object, I can't get it to stop on DeleteExpandedObject, so I don't think plpgsql is deleting it, I'm going to keep investigating, sorry for the noise. -Michel > --000000000000697b280626a9de43 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
The second expansion in matrix_out happens outside the function,= so inside there is only the one expansion for both matrix_nvals and the as= signment.=C2=A0 Thank you!=C2=A0 All my tests continue to pass and the chan= ge seems to work well.

Hm= m, well I spoke to soon looking at the wrong function without an assignment= , I've been down in gdb a bit too much and I got mixed up, here's a= nother function that wraps it and does an assignment, and it looks like the= re is another expansion happening after the nvals but before the assignment= :

create or replace function test_expand_expand(graph ma= trix) 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 graph =3D test_expand(= graph);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return test_expand(graph);
=C2=A0= =C2=A0 end;
=C2=A0 =C2=A0 $$;

postgres=3D#= select test_expand_expand(a) from test_fixture ;
DEBUG: =C2=A0matrix_nv= als
DEBUG: =C2=A0DatumGetMatrix
DEBUG: =C2=A0expand_matrix
DEBUG: = =C2=A0new_matrix
DEBUG: =C2=A0context_callback_matrix_free
DEBUG: =C2= =A0matrix_nvals
DEBUG: =C2=A0DatumGetMatrix
DEBUG: =C2=A0expand_matri= x
DEBUG: =C2=A0new_matrix
DEBUG: =C2=A0context_callback_matrix_freeDEBUG: =C2=A0matrix_nvals
DEBUG: =C2=A0DatumGetMatrix
DEBUG: =C2=A0= expand_matrix
DEBUG: =C2=A0new_matrix
DEBUG: =C2=A0context_callback_m= atrix_free
DEBUG: =C2=A0matrix_out
DEBUG: =C2=A0DatumGetMatrix
DEB= UG: =C2=A0expand_matrix
DEBUG: =C2=A0new_matrix
DEBUG: =C2=A0context_= callback_matrix_free

So going back on the assu= mption I'm somehow not returning the right pointer, but digging into th= e array code I'm pretty sure I'm following the same pattern and tra= cing my code path is calling EOHPGetRWDatum when I return the object, I can= 't get it to stop on DeleteExpandedObject, so I don't think plpgsql= is deleting it, I'm going to keep investigating, sorry for the noise.<= /div>

-Michel
--000000000000697b280626a9de43--