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.
Showing
- contrib/spi/refint.c 6 additions, 8 deletionscontrib/spi/refint.c
- contrib/spi/timetravel.c 3 additions, 4 deletionscontrib/spi/timetravel.c
- doc/src/sgml/plpgsql.sgml 51 additions, 68 deletionsdoc/src/sgml/plpgsql.sgml
- doc/src/sgml/protocol.sgml 15 additions, 35 deletionsdoc/src/sgml/protocol.sgml
- doc/src/sgml/ref/prepare.sgml 23 additions, 21 deletionsdoc/src/sgml/ref/prepare.sgml
- doc/src/sgml/spi.sgml 167 additions, 70 deletionsdoc/src/sgml/spi.sgml
- src/backend/catalog/namespace.c 18 additions, 0 deletionssrc/backend/catalog/namespace.c
- src/backend/commands/prepare.c 57 additions, 87 deletionssrc/backend/commands/prepare.c
- src/backend/executor/spi.c 170 additions, 193 deletionssrc/backend/executor/spi.c
- src/backend/tcop/postgres.c 74 additions, 152 deletionssrc/backend/tcop/postgres.c
- src/backend/utils/adt/ri_triggers.c 2 additions, 2 deletionssrc/backend/utils/adt/ri_triggers.c
- src/backend/utils/adt/ruleutils.c 4 additions, 2 deletionssrc/backend/utils/adt/ruleutils.c
- src/backend/utils/cache/plancache.c 998 additions, 523 deletionssrc/backend/utils/cache/plancache.c
- src/backend/utils/mmgr/mcxt.c 12 additions, 0 deletionssrc/backend/utils/mmgr/mcxt.c
- src/backend/utils/mmgr/portalmem.c 3 additions, 3 deletionssrc/backend/utils/mmgr/portalmem.c
- src/include/catalog/namespace.h 1 addition, 0 deletionssrc/include/catalog/namespace.h
- src/include/commands/prepare.h 1 addition, 7 deletionssrc/include/commands/prepare.h
- src/include/executor/spi.h 1 addition, 0 deletionssrc/include/executor/spi.h
- src/include/executor/spi_priv.h 23 additions, 18 deletionssrc/include/executor/spi_priv.h
- src/include/nodes/parsenodes.h 3 additions, 0 deletionssrc/include/nodes/parsenodes.h
Loading
Please register or sign in to comment