pgsql: Change function call information to be variable length.

Поиск
Список
Период
Сортировка
От Andres Freund
Тема pgsql: Change function call information to be variable length.
Дата
Msg-id E1gnWWY-0003Jj-5E@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Change function call information to be variable length.

Before this change FunctionCallInfoData, the struct arguments etc for
V1 function calls are stored in, always had space for
FUNC_MAX_ARGS/100 arguments, storing datums and their nullness in two
arrays.  For nearly every function call 100 arguments is far more than
needed, therefore wasting memory. Arg and argnull being two separate
arrays also guarantees that to access a single argument, two
cachelines have to be touched.

Change the layout so there's a single variable-length array with pairs
of value / isnull. That drastically reduces memory consumption for
most function calls (on x86-64 a two argument function now uses
64bytes, previously 936 bytes), and makes it very likely that argument
value and its nullness are on the same cacheline.

Arguments are stored in a new NullableDatum struct, which, due to
padding, needs more memory per argument than before. But as usually
far fewer arguments are stored, and individual arguments are cheaper
to access, that's still a clear win.  It's likely that there's other
places where conversion to NullableDatum arrays would make sense,
e.g. TupleTableSlots, but that's for another commit.

Because the function call information is now variable-length
allocations have to take the number of arguments into account. For
heap allocations that can be done with SizeForFunctionCallInfoData(),
for on-stack allocations there's a new LOCAL_FCINFO(name, nargs) macro
that helps to allocate an appropriately sized and aligned variable.

Some places with stack allocation function call information don't know
the number of arguments at compile time, and currently variably sized
stack allocations aren't allowed in postgres. Therefore allow for
FUNC_MAX_ARGS space in these cases. They're not that common, so for
now that seems acceptable.

Because of the need to allocate FunctionCallInfo of the appropriate
size, older extensions may need to update their code. To avoid subtle
breakages, the FunctionCallInfoData struct has been renamed to
FunctionCallInfoBaseData. Most code only references FunctionCallInfo,
so that shouldn't cause much collateral damage.

This change is also a prerequisite for more efficient expression JIT
compilation (by allocating the function call information on the stack,
allowing LLVM to optimize it away); previously the size of the call
information caused problems inside LLVM's optimizer.

Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20180605172952.x34m5uz6ju6enaem@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a9c35cf85ca1ff72f16f0f10d7ddee6e582b62b8

Modified Files
--------------
contrib/hstore/hstore_op.c            |   2 +-
doc/src/sgml/plhandler.sgml           |   8 +-
src/backend/commands/event_trigger.c  |   8 +-
src/backend/commands/functioncmds.c   |  15 +-
src/backend/commands/tablecmds.c      |   8 +-
src/backend/commands/trigger.c        |  12 +-
src/backend/executor/README           |   6 +-
src/backend/executor/execExpr.c       |  83 ++--
src/backend/executor/execExprInterp.c | 139 +++---
src/backend/executor/execSRF.c        |  45 +-
src/backend/executor/functions.c      |   4 +-
src/backend/executor/nodeAgg.c        |  83 ++--
src/backend/executor/nodeWindowAgg.c  |  64 +--
src/backend/jit/llvm/llvmjit.c        |   2 +
src/backend/jit/llvm/llvmjit_expr.c   | 146 ++----
src/backend/jit/llvm/llvmjit_types.c  |   3 +-
src/backend/postmaster/pgstat.c       |   2 +-
src/backend/tcop/fastpath.c           |  42 +-
src/backend/utils/adt/arrayfuncs.c    | 122 +++--
src/backend/utils/adt/int.c           |  20 +-
src/backend/utils/adt/oid.c           |  20 +-
src/backend/utils/adt/rowtypes.c      |  32 +-
src/backend/utils/fmgr/README         |  23 +-
src/backend/utils/fmgr/fmgr.c         | 866 ++++++++++++++--------------------
src/backend/utils/sort/sortsupport.c  |  15 +-
src/include/executor/execExpr.h       |  21 +-
src/include/executor/nodeAgg.h        |   6 +-
src/include/fmgr.h                    |  60 ++-
src/include/jit/llvmjit.h             |   1 +
src/include/jit/llvmjit_emit.h        |  55 +++
src/include/nodes/execnodes.h         |   2 +-
src/include/pgstat.h                  |   2 +-
src/include/postgres.h                |  15 +
src/pl/plperl/plperl.c                |  20 +-
src/pl/plpgsql/src/pl_exec.c          |   8 +-
src/pl/plpgsql/src/pl_handler.c       |  20 +-
src/pl/plpython/plpy_exec.c           |   4 +-
src/pl/plpython/plpy_main.c           |   8 +-
src/pl/tcl/pltcl.c                    |  16 +-
src/tools/pgindent/typedefs.list      |   3 +-
40 files changed, 957 insertions(+), 1054 deletions(-)


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix psql's "\g target" meta-command to work with COPY TOSTDOUT.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Allow for yet another crash symptom in 013_crash_restart.pl.