pgsql: Redesign the plancache mechanism for more flexibility and effici - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Redesign the plancache mechanism for more flexibility and effici
Date
Msg-id E1R4QI5-0000Bh-RS@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Redesign the plancache mechanism for more flexibility and efficiency.

Rewrite plancache.c so that a "cached plan" (which is rather a misnomer
at this point) can support generation of custom, parameter-value-dependent
plans, and can make an intelligent choice between using custom plans and
the traditional generic-plan approach.  The specific choice algorithm
implemented here can probably be improved in future, but this commit is
all about getting the mechanism in place, not the policy.

In addition, restructure the API to greatly reduce the amount of extraneous
data copying needed.  The main compromise needed to make that possible was
to split the initial creation of a CachedPlanSource into two steps.  It's
worth noting in particular that SPI_saveplan is now deprecated in favor of
SPI_keepplan, which accomplishes the same end result with zero data
copying, and no need to then spend even more cycles throwing away the
original SPIPlan.  The risk of long-term memory leaks while manipulating
SPIPlans has also been greatly reduced.  Most of this improvement is based
on use of the recently-added MemoryContextSetParent primitive.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/e6faf910d75027bdce7cd0f2033db4e912592bcc

Modified Files
--------------
contrib/spi/refint.c                |   14 +-
contrib/spi/timetravel.c            |    7 +-
doc/src/sgml/plpgsql.sgml           |  119 ++--
doc/src/sgml/protocol.sgml          |   50 +-
doc/src/sgml/ref/prepare.sgml       |   44 +-
doc/src/sgml/spi.sgml               |  237 ++++--
src/backend/catalog/namespace.c     |   18 +
src/backend/commands/prepare.c      |  144 ++--
src/backend/executor/spi.c          |  363 ++++-----
src/backend/tcop/postgres.c         |  226 ++----
src/backend/utils/adt/ri_triggers.c |    4 +-
src/backend/utils/adt/ruleutils.c   |    6 +-
src/backend/utils/cache/plancache.c | 1521 +++++++++++++++++++++++------------
src/backend/utils/mmgr/mcxt.c       |   12 +
src/backend/utils/mmgr/portalmem.c  |    6 +-
src/include/catalog/namespace.h     |    1 +
src/include/commands/prepare.h      |    8 +-
src/include/executor/spi.h          |    1 +
src/include/executor/spi_priv.h     |   41 +-
src/include/nodes/parsenodes.h      |    3 +
src/include/utils/memutils.h        |    1 +
src/include/utils/plancache.h       |  156 +++--
src/pl/plperl/plperl.c              |   18 +-
src/pl/plpgsql/src/pl_exec.c        |  215 ++++--
src/pl/plpython/plpython.c          |   11 +-
src/pl/tcl/pltcl.c                  |   17 +-
src/test/regress/regress.c          |    5 +-
27 files changed, 1909 insertions(+), 1339 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: gistendscan() forgot to free so->giststate.
Next
From: itagaki@pgfoundry.org (User Itagaki)
Date:
Subject: textsearch-ja - textsearch-ja: Support EXTENSION for PostgreSQL 9.1.