Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jira babel 3755 #238

Open
wants to merge 8 commits into
base: BABEL_3_X_DEV__PG_15_X
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/backend/utils/cache/plancache.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "utils/resowner_private.h"
#include "utils/rls.h"
#include "utils/snapmgr.h"
#include "utils/resowner.h"
#include "utils/syscache.h"


Expand Down Expand Up @@ -1326,7 +1327,7 @@ ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner)
*/
bool
CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource,
CachedPlan *plan, ResourceOwner owner)
CachedPlan *plan)
{
ListCell *lc;

Expand All @@ -1340,10 +1341,11 @@ CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource,
*/
Assert(plansource->magic == CACHEDPLANSOURCE_MAGIC);
Assert(plan->magic == CACHEDPLAN_MAGIC);
Assert(plansource->is_valid);
Assert(plan->is_valid);
Assert(plan == plansource->gplan);
Assert(plansource->search_path != NULL);
Assert(OverrideSearchPathMatchesCurrent(plansource->search_path));
// Assert(plansource->search_path != NULL);
// Assert(OverrideSearchPathMatchesCurrent(plansource->search_path));

/* We don't support oneshot plans here. */
if (plansource->is_oneshot)
Expand Down Expand Up @@ -1409,12 +1411,12 @@ CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource,
*/

/* Bump refcount if requested. */
if (owner)
{
ResourceOwnerEnlargePlanCacheRefs(owner);
plan->refcount++;
ResourceOwnerRememberPlanCacheRef(owner, plan);
}
// if (owner)
// {
// ResourceOwnerEnlargePlanCacheRefs(owner);
// plan->refcount++;
// ResourceOwnerRememberPlanCacheRef(owner, plan);
// }

return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/backend/utils/resowner/resowner.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,18 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
void
ResourceOwnerReleaseAllPlanCacheRefs(ResourceOwner owner)
{
ResourceOwner save;
Datum foundres;

save = CurrentResourceOwner;
CurrentResourceOwner = owner;
while (ResourceArrayGetAny(&(owner->planrefarr), &foundres))
{
CachedPlan *res = (CachedPlan *) DatumGetPointer(foundres);

ReleaseCachedPlan(res, owner);
}
CurrentResourceOwner = save;
}

/*
Expand Down
3 changes: 1 addition & 2 deletions src/include/utils/plancache.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ extern CachedPlan *GetCachedPlan(CachedPlanSource *plansource,
extern void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner);

extern bool CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource,
CachedPlan *plan,
ResourceOwner owner);
CachedPlan *plan);
extern bool CachedPlanIsSimplyValid(CachedPlanSource *plansource,
CachedPlan *plan,
ResourceOwner owner);
Expand Down
29 changes: 19 additions & 10 deletions src/pl/plpgsql/src/pl_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -6132,8 +6132,9 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
* refcount on the new plan, stored in simple_eval_resowner.
*/
if (CachedPlanAllowsSimpleValidityCheck(expr->expr_simple_plansource,
cplan,
estate->simple_eval_resowner))
cplan) &&
CachedPlanIsSimplyValid(expr->expr_simple_plansource, cplan,
estate->simple_eval_resowner))
{
/* Remember that we have the refcount */
expr->expr_simple_plan = cplan;
Expand Down Expand Up @@ -8081,16 +8082,24 @@ exec_simple_check_plan(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
* that this could fail, but if it does, just treat plan as not simple. On
* success, save a refcount on the plan in the simple-expression resowner.
*/
if (CachedPlanAllowsSimpleValidityCheck(plansource, cplan,
estate->simple_eval_resowner))
if (CachedPlanAllowsSimpleValidityCheck(plansource, cplan))
{
/* Remember that we have the refcount */
expr->expr_simple_plansource = plansource;
expr->expr_simple_plan = cplan;
expr->expr_simple_plan_lxid = MyProc->lxid;
/*
* OK, use CachedPlanIsSimplyValid to save a refcount on the plan in
* the simple-expression resowner. This shouldn't fail either, but if
* somehow it does, again we can cope by treating plan as not simple.
*/
if (CachedPlanIsSimplyValid(plansource, cplan,
estate->simple_eval_resowner))
{
/* Remember that we have the refcount */
expr->expr_simple_plansource = plansource;
expr->expr_simple_plan = cplan;
expr->expr_simple_plan_lxid = MyProc->lxid;

/* Share the remaining work with the replan code path */
exec_save_simple_expr(expr, cplan);
/* Share the remaining work with the replan code path */
exec_save_simple_expr(expr, cplan);
}
}

/*
Expand Down
Loading