pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg/tcl performance related
2+ messages / 2 participants
[nested] [flat]

* pg/tcl performance related
@ 2018-03-09 08:52 wolfgang@alle-noten.de
  2018-03-09 16:43 ` Re: pg/tcl performance related Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: wolfgang@alle-noten.de @ 2018-03-09 08:52 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org



Hi,

suppose I want to create a tcl function that basically walks through a long list and compares its
argument against all entries
In plain tcl I would probably write

set data {
  # .... lots of stuff here
}
proc check val {
  global data
  foreach d $data {
    # .... this does the work
  }
}

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?

Best regards
Wolfgang Hamann





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: pg/tcl performance related
  2018-03-09 08:52 pg/tcl performance related wolfgang@alle-noten.de
@ 2018-03-09 16:43 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2018-03-09 16:43 UTC (permalink / raw)
  To: wolfgang@alle-noten.de; +Cc: pgsql-general@lists.postgresql.org

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-03-09 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-09 08:52 pg/tcl performance related wolfgang@alle-noten.de
2018-03-09 16:43 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox