Re: Why MemoryContextSwitch in ExecRelCheck ?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Why MemoryContextSwitch in ExecRelCheck ?
Дата
Msg-id 9605.1010424492@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Why MemoryContextSwitch in ExecRelCheck ?  (Holger Krug <hkrug@rationalizer.com>)
Ответы Re: Why MemoryContextSwitch in ExecRelCheck ?
Список pgsql-hackers
Holger Krug <hkrug@rationalizer.com> writes:
> Nevertheless in ExecRelCheck a context switch to per-query memory
> context is made:
> Is this a switch from per-query memory context to per-query memory
> context, hence not necessary, or do I miss something ?

[ thinks ... ]  It might be unnecessary.  I'm not convinced that the
per-query context would always be the active one when ExecRelCheck is
called, however.  There are various per-tuple contexts that might be
used as well.

MemoryContextSwitchTo() is cheap enough that I prefer to call it when
there's any doubt, rather than build a routine that will fail silently
if it's called in the wrong context.  There are two typical scenarios
for routines that are building data structures that will outlive the
routine's execution:

1. Data structure is to be returned to the caller.  In this case the
caller is responsible for identifying the context to allocate the data
structure in, either explicitly or by passing it as the current context.

2. Data structure is owned and managed by the routine, which must know
which context it's supposed to live in.  In these cases I think the
routine ought always to explicitly switch to that context, not assume
that it's being called in that context.

I've been trying to migrate away from running with CurrentMemoryContext
set to anything longer-lived than a per-tuple context, though the
project is by no means complete.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Holger Krug
Дата:
Сообщение: Why MemoryContextSwitch in ExecRelCheck ?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: ecpg compile error on AIX