pgsql: Further reduce overhead for passing plpgsql variables to the exe

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Further reduce overhead for passing plpgsql variables to the exe
Дата
Msg-id E1ZBnEM-0000MM-45@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Further reduce overhead for passing plpgsql variables to the executor.

This builds on commit 21dcda2713656a7483e3280ac9d2ada20a87a9a9 by keeping
a plpgsql function's shared ParamListInfo's entries for simple variables
(PLPGSQL_DTYPE_VARs) valid at all times.  That adds a few cycles to each
assignment to such variables, but saves significantly more cycles each time
they are used; so except in the pathological case of many dead stores, this
should always be a win.  Initial testing says it's good for about a 10%
speedup of simple calculations; more in large functions with many datums.

We can't use this method for row/record references unfortunately, so what
we do for those is reset those ParamListInfo slots after use; which we
can skip doing unless some of them were actually evaluated during the
previous evaluation call.  So this should frequently be a win as well,
while worst case is that it's similar cost to the previous approach.

Also, closer study suggests that the previous method of instantiating a
new ParamListInfo array per evaluation is actually probably optimal for
cursor-opening executor calls.  The reason is that whatever is visible in
the array is going to get copied into the cursor portal via copyParamList.
So if we used the function's main ParamListInfo for those calls, we'd end
up with all of its DTYPE_VAR vars getting copied, which might well include
large pass-by-reference values that the cursor actually has no need for.
To avoid a possible net degradation in cursor cases, go back to creating
and filling a private ParamListInfo in those cases (which therefore will be
exactly the same speed as before 21dcda271365).  We still get some benefit
out of this though, because this approach means that we only have to defend
against copyParamList's try-to-fetch-every-slot behavior in the case of an
unshared ParamListInfo; so plpgsql_param_fetch() can skip testing
expr->paramnos in the common case.

To ensure that the main ParamListInfo's image of a DTYPE_VAR datum is
always valid, all assignments to such variables are now funneled through
assign_simple_var().  But this makes for cleaner and shorter code anyway.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/6c82d8d1fdb1f1265f93d89640edcbd0ae22c627

Modified Files
--------------
src/pl/plpgsql/src/pl_comp.c |   81 +++++--
src/pl/plpgsql/src/pl_exec.c |  480 ++++++++++++++++++++++++++----------------
src/pl/plpgsql/src/plpgsql.h |    5 +
3 files changed, 359 insertions(+), 207 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix bad grammar in brin.sgml.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix some typos in regression test comments.