1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

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.
This commit is contained in:
Tom Lane
2011-09-16 00:42:53 -04:00
parent 09e98a3e17
commit e6faf910d7
27 changed files with 1994 additions and 1424 deletions

View File

@ -190,12 +190,11 @@ check_primary_key(PG_FUNCTION_ARGS)
/*
* Remember that SPI_prepare places plan in current memory context -
* so, we have to save plan in Top memory context for latter use.
* so, we have to save plan in Top memory context for later use.
*/
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
if (SPI_keepplan(pplan))
/* internal error */
elog(ERROR, "check_primary_key: SPI_saveplan returned %d", SPI_result);
elog(ERROR, "check_primary_key: SPI_keepplan failed");
plan->splan = (SPIPlanPtr *) malloc(sizeof(SPIPlanPtr));
*(plan->splan) = pplan;
plan->nplans = 1;
@ -537,13 +536,12 @@ check_foreign_key(PG_FUNCTION_ARGS)
/*
* Remember that SPI_prepare places plan in current memory context
* - so, we have to save plan in Top memory context for latter
* - so, we have to save plan in Top memory context for later
* use.
*/
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
if (SPI_keepplan(pplan))
/* internal error */
elog(ERROR, "check_foreign_key: SPI_saveplan returned %d", SPI_result);
elog(ERROR, "check_foreign_key: SPI_keepplan failed");
plan->splan[r] = pplan;

View File

@ -345,11 +345,10 @@ timetravel(PG_FUNCTION_ARGS)
/*
* Remember that SPI_prepare places plan in current memory context -
* so, we have to save plan in Top memory context for latter use.
* so, we have to save plan in Top memory context for later use.
*/
pplan = SPI_saveplan(pplan);
if (pplan == NULL)
elog(ERROR, "timetravel (%s): SPI_saveplan returned %d", relname, SPI_result);
if (SPI_keepplan(pplan))
elog(ERROR, "timetravel (%s): SPI_keepplan failed", relname);
plan->splan = pplan;
}