Thread: Re: [BUGS] Postgres bug (working with iserverd)

Re: [BUGS] Postgres bug (working with iserverd)

From
Tom Lane
Date:
I wrote:
> The direct cause of the problem is that EvalPlanQual isn't completely
> initializing the estate that it sets up for re-evaluating the plan.
> In particular it's not filling in es_result_relations and
> es_num_result_relations, which need to be set up if the top plan node
> is an Append.  (That's probably my fault.)  But there are a bunch of
> other fields that it's failing to copy, too.

I believe I have fixed this problem in CVS sources for current and
REL7_1, at least to the extent that EvalPlanQual processing produces
the right answers for updates/deletes in inheritance trees.

However, EvalPlanQual still leaks more memory than suits me ---
auxiliary memory allocated by the plan nodes is not recovered.
I think the correct way to implement it would be to create a new
memory context for each level of EvalPlanQual execution and use
that context as the "per-query context" for the sub-query.  The
whole context (including the copied plan) would be freed at the
end of the sub-query.  The notion of a stack of currently-unused
epqstate nodes would go away.

This would mean a few more cycles per tuple to copy the plan tree over
again each time, but I think that's pretty trivial compared to the plan
startup/shutdown costs that we incur anyway.  Besides, I have hopes of
making plan trees read-only whenever we do the fabled querytree
redesign, so the cost will someday go away.

Comments, objections?
        regards, tom lane


Re: [BUGS] Postgres bug (working with iserverd)

From
"Vadim Mikheev"
Date:
> However, EvalPlanQual still leaks more memory than suits me ---
> auxiliary memory allocated by the plan nodes is not recovered.
> I think the correct way to implement it would be to create a new
> memory context for each level of EvalPlanQual execution and use
> that context as the "per-query context" for the sub-query.  The
> whole context (including the copied plan) would be freed at the
> end of the sub-query.  The notion of a stack of currently-unused
> epqstate nodes would go away.
> 
> This would mean a few more cycles per tuple to copy the plan tree over
> again each time, but I think that's pretty trivial compared to the plan
> startup/shutdown costs that we incur anyway.  Besides, I have hopes of
> making plan trees read-only whenever we do the fabled querytree
> redesign, so the cost will someday go away.

Isn't plan shutdown supposed to free memory? How subselects run queries
again and again? I wasn't in planner/executor areas for long time and
have no time to look there now -:(, so - just asking -:)

Vadim




Re: [BUGS] Postgres bug (working with iserverd)

From
Tom Lane
Date:
"Vadim Mikheev" <vmikheev@sectorbase.com> writes:
>> However, EvalPlanQual still leaks more memory than suits me ---
>> auxiliary memory allocated by the plan nodes is not recovered.

> Isn't plan shutdown supposed to free memory?

Yeah, but it leaks all over the place; none of the plan node types
bother to free their state nodes, for example.  There are lots of other
cases.  You really have to reset the per-query context to get rid of all
the cruft allocated during ExecInitNode.

> How subselects run queries again and again?

They don't end and restart them; they just rescan them.  If we had
this substitute-a-new-tuple hack integrated into the Param mechanism,
then EvalPlanQual could use ExecReScan too, but at the moment no...
        regards, tom lane


Re: [BUGS] Postgres bug (working with iserverd)

From
"Vadim Mikheev"
Date:
> > How subselects run queries again and again?
> 
> They don't end and restart them; they just rescan them.  If we had

Thanks for recollection.

> this substitute-a-new-tuple hack integrated into the Param mechanism,
> then EvalPlanQual could use ExecReScan too, but at the moment no...

I see.

Vadim