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 1t7008-00Guaw-Vv for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 22:20:16 +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 1t7006-000qUV-6c for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Nov 2024 22:20:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t7005-000qUN-Sw for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 22:20:14 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t7003-0041pn-EZ for pgsql-hackers@lists.postgresql.org; Fri, 01 Nov 2024 22:20:12 +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 4A1MK9eD1947218; Fri, 1 Nov 2024 18:20:09 -0400 From: Tom Lane To: Michel Pelletier cc: 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> <2259890.1729696885@sss.pgh.pa.us> <2351536.1729735831@sss.pgh.pa.us> Comments: In-reply-to Michel Pelletier message dated "Thu, 31 Oct 2024 16:41:48 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1947216.1730499609.1@sss.pgh.pa.us> Date: Fri, 01 Nov 2024 18:20:09 -0400 Message-ID: <1947217.1730499609@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michel Pelletier writes: > Here's two backtraces from gdb from this function: > CREATE OR REPLACE FUNCTION test2(graph matrix) > RETURNS bigint LANGUAGE plpgsql AS > $$ > BEGIN > perform set_element(graph, 1, 1, 1); > RETURN nvals(graph); > end; > $$; Well, you shouldn't be using PERFORM. Not only does it not do the right thing, but it's not optimized for expanded objects at all: they'll get flattened both on the way into the statement and on the way out. Try it with graph := set_element(graph, 1, 1, 1); RETURN nvals(graph); regards, tom lane