Speed up plpgsql function startup by doing fewer pallocs.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Feb 2018 00:10:43 +0000 (19:10 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Feb 2018 00:10:43 +0000 (19:10 -0500)
commit40301c1c8bcbe92a9ba9bf017da03e83476ae0e5
tree648c6e27936e5ea5bd356de5099c06926fd53288
parent4b93f57999a2ca9b9c9e573ea32ab1aeaa8bf496
Speed up plpgsql function startup by doing fewer pallocs.

Previously, copy_plpgsql_datum did a separate palloc for each variable
needing instance-local storage.  In simple benchmarks this made for a
noticeable fraction of the total runtime.  Improve it by precalculating
the space needed for all of a function's variables and doing just one
palloc for all of them.

In passing, remove PLPGSQL_DTYPE_EXPR from the list of plpgsql "datum"
types, since in fact it has nothing in common with the others, and there
is noplace that needs to discriminate on the basis of dtype between an
expression and any type of datum.  And add comments clarifying which
datum struct fields are generic and which aren't.

Tom Lane, reviewed by Pavel Stehule

Discussion: https://postgr.es/m/11986.1514407114@sss.pgh.pa.us
src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_gram.y
src/pl/plpgsql/src/plpgsql.h