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 1tPlGf-00F5od-9A for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Dec 2024 16:26:53 +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 1tPlGc-00CGzl-Qa for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Dec 2024 16:26:50 +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 1tPlGc-00CGzd-Gc for pgsql-hackers@lists.postgresql.org; Mon, 23 Dec 2024 16:26:50 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tPlGY-001FDZ-FR for pgsql-hackers@lists.postgresql.org; Mon, 23 Dec 2024 16:26:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4BNGQfQw1355691; Mon, 23 Dec 2024 11:26:41 -0500 From: Tom Lane To: Michel Pelletier cc: Pavel Stehule , pgsql-hackers@lists.postgresql.org Subject: Re: Using Expanded Objects other than Arrays from plpgsql In-reply-to: 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> <3797606.1732045516@sss.pgh.pa.us> <223466! 1.1733272923@sss.pgh.pa.us> <2811228.1734553329@sss.pgh.pa.us> Comments: In-reply-to Michel Pelletier message dated "Sun, 22 Dec 2024 19:52:08 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1355689.1734971201.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 23 Dec 2024 11:26:41 -0500 Message-ID: <1355690.1734971201@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michel Pelletier writes: > On Wed, Dec 18, 2024 at 12:22 PM Tom Lane wrote: >> So, just to clarify where we're at: you are satisfied that the current >> patch-set does what you need? > There are a few cases where I have to force an expansion, I work around > this by calling a `wait()` function, which expands the datum, calls > GrB_wait() on it (a nop in this case) and returns a r/w pointer. You can > see this in the following Triangle Counting function which is a matrix > multiplication of a graph to itself, using itself as a mask. This matrix > reduces to the triangle count (times six): > create or replace function tcount_b(graph matrix) returns bigint language > plpgsql as > $$ > begin > graph = wait(graph); > graph = mxm(graph, graph, 'plus_pair_int32', mask=>graph, > descr=>'s'); > return reduce_scalar(graph) / 6; > end; > $$; > ... > I agree it makes sense to have more use cases before making deeper > changes. I only work with expanded forms, but need to call wait() to > pre-expand the object to avoid multiple expansions in functions that can > take the same object in multiple parameters. Hmm. I agree that the wait() call is a bit ugly, but there are at least two things that seem worth looking into before we go so far as inventing type-support infrastructure: 1. Why isn't the incoming "graph" object already expanded? It often would be read-only, but that seems like it might be enough given your description of GraphBLAS' behavior. 2. If the problem is primarily with passing the same object to multiple parameters of a function, couldn't you detect and optimize that within the function? It would be messier than just blindly applying DatumGetWhatever() to each parameter position; but with a bit of thought I bet you could create some support logic that would hide most of the mess. regards, tom lane