From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Holger Krug <hkrug(at)rationalizer(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Why MemoryContextSwitch in ExecRelCheck ? |
Date: | 2002-01-07 17:28:12 |
Message-ID: | 9605.1010424492@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Holger Krug <hkrug(at)rationalizer(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-01-07 17:40:07 | Re: ecpg compile error on AIX |
Previous Message | Tom Lane | 2002-01-07 16:39:35 | Re: LWLock contention: I think I understand the problem |