Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1euL6t-0003Xp-HV for pgsql-general@arkaria.postgresql.org; Fri, 09 Mar 2018 16:43:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1euL6s-00083c-0N for pgsql-general@arkaria.postgresql.org; Fri, 09 Mar 2018 16:43:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1euL6r-00083T-Ou for pgsql-general@lists.postgresql.org; Fri, 09 Mar 2018 16:43:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1euL6o-0000bO-Jx for pgsql-general@lists.postgresql.org; Fri, 09 Mar 2018 16:43:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w29Gh09C026362; Fri, 9 Mar 2018 11:43:00 -0500 From: Tom Lane To: wolfgang@alle-noten.de cc: pgsql-general@lists.postgresql.org Subject: Re: pg/tcl performance related In-reply-to: References: Comments: In-reply-to wolfgang@alle-noten.de message dated "09 Mar 2018 08:52:26 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26360.1520613780.1@sss.pgh.pa.us> Date: Fri, 09 Mar 2018 11:43:00 -0500 Message-ID: <26361.1520613780@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk wolfgang@alle-noten.de writes: > Now, for pl/tcl, I could use either > create function check(text) returns text as $$ > set data { > # the data value > } > foreach d $data { > # the work > } > $$ language pltcl; > or > create function check(text) returns text as $$ > if ![info exists GD(data)] { > set GD(data) { > # the data value > } > } > foreach d $GD(data) { > # the work > } > $$ language pltcl; > Does this make any difference - i.e. how often will parsing the data happen? Obviously, in the first case the "set data" will happen every time you call the function. The cost of that should be about the same as it would be in standalone Tcl. PL/Tcl builds a Tcl code object for the function body on first call in a session, and thereafter reuses that code object, so that you shouldn't have extra parsing overhead per se ... but execution of the command costs something too. regards, tom lane