Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mhyLU-0001Ep-1l for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Nov 2021 18:17:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mhyLS-00050a-1d for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Nov 2021 18:17:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mhyLR-00050R-PE for pgsql-hackers@lists.postgresql.org; Tue, 02 Nov 2021 18:17:13 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mhyLN-0000bx-Re for pgsql-hackers@postgresql.org; Tue, 02 Nov 2021 18:17:12 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 1BDE75C007F; Tue, 2 Nov 2021 14:17:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 02 Nov 2021 14:17:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=/iet7oojRQ2nEx5JHqeOZoZm7LTIe4Hzkzp8Cce5dsI=; b=L0rsOHRH xdlDm/5W9jnhf7oCLcPcwtGgiI5LdSeV8ZarVyEMvsGVC52jEsuXDpR1Mzj2ZwKe AApaHI0eSHbMTuZDihEOETKkZo97HCLCfVt2p0UgLTSGTSLdkmhdES1mJy3mHKEi irtE/QDrBfnTpNBuooU8csRtZlqtZXH5GkQipgGrdxBsyz39bV+3Mom0fLtesLJA yyOugkW8tAnOvDg7pAmTqb+vwbexgQn4SkMyIuCSdLJWMObERW1Hb1yx85zVuppH CzOG/k05N1fj9bVH8F8uZ+YW6nxOwU29hmmlVmW4bOqJEbseJsJfVfo5wSXpgdXk n9DRcPI9mqNSwg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrtddtgdekhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepudejveejffejveduudetvdekieeuiedtvdeileefkeevjedu feeguedvjefhueelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgv rhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Nov 2021 14:17:08 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id D443E2A080D; Tue, 2 Nov 2021 15:17:05 -0300 (-03) Date: Tue, 2 Nov 2021 15:17:05 -0300 From: Alvaro Herrera To: Melanie Plageman Cc: Pg Hackers , Andres Freund Subject: Re: make tuplestore helper function Message-ID: <202111021817.ngdvsnnsmkq5@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Nov-02, Melanie Plageman wrote: > Attached is a patch to create a helper function which creates a > tuplestore to be used by FUNCAPI-callable functions. Looks good, and given the amount of code being removed, it seems a no-brainer that some helper(s) is/are needed. I think the name is a bit too generic. How about MakeFuncResultTuplestore()? I think the function should not modify rsinfo -- having that as (undocumented) side effect is weird. I would suggest to just return the tuplestore, and have the caller stash it in rsinfo->setResult and modify the other struct members alongside that. It's a couple more lines per caller, but the code is clearer that way. > There are a few places with very similar code to the new helper > (MakeTuplestore()) but which, for example, don't expect the return type > to be a row (pg_ls_dir(), pg_tablespace_databases(), text_to_table()). I > wasn't sure if it was worth modifying it for their benefit. Is this just because of the tupdesc? If that's the case, then maybe the tupdesc can be optionally passed in by caller, and when it's not, the helper does get_call_result_type() and the tupdesc is used as output argument. > I wasn't sure if the elog() check for call result type should be changed > to an ereport(). I don't see a reason for that: it's still an internal (not user-facing) error. > All callers of MakeTuplestore() pass work_mem as the third parameter, so > I could just omit it and hard-code it in, but I wasn't sure that felt > right in a utility/helper function. No opinion. I would have used the global in the function instead of passing it in. > I inlined deflist_to_tuplestore() in foreign.c since it was billed as a > helper function but wasn't used elsewhere and it made it harder to use > MakeTuplestore() in this location. This is a bit strange. Does it work to pass rsinfo->expectedDesc? -- Álvaro Herrera Valdivia, Chile — https://www.EnterpriseDB.com/ "No renuncies a nada. No te aferres a nada."