From: | Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> |
---|---|
To: | Ali Akbar <the(dot)apaan(at)gmail(dot)com> |
Cc: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Marti Raudsepp <marti(at)juffo(dot)org>, Платон Малюгин <malugin(dot)p(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Add generate_series(numeric, numeric) |
Date: | 2014-12-15 05:38:29 |
Message-ID: | 87d27lpkmh.fsf@news-spur.riddles.org.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
>>>>> "Ali" == Ali Akbar <the(dot)apaan(at)gmail(dot)com> writes:
Ali> I think yes, it will be good. The alternative is restructuring
Ali> this paragraph in the SRF docs:
>> The memory context that is current when the SRF is called is a
>> transient context that will be cleared between calls. This means
>> that you do not need to call pfree on everything you allocated
>> using palloc; it will go away anyway. However, if you want to
>> allocate any data structures to live across calls, you need to put
>> them somewhere else. The memory context referenced by
>> multi_call_memory_ctx is a suitable location for any data that
>> needs to survive until the SRF is finished running. In most cases,
>> this means that you should switch into multi_call_memory_ctx while
>> doing the first-call setup.
Ali> The important part "However, if you want to allocate any data
Ali> structures to live across calls, you need to put them somewhere
Ali> else." is buried in the docs.
Ali> But i think explicit warning is more noticeable for new
Ali> developer like me.
I was thinking something like this, added just after that para:
<warning>
<para>
While the actual arguments to the function remain unchanged between
calls, if you detoast the argument values (which is normally done
transparently by the
<function>PG_GETARG_<replaceable>xxx</replaceable></function> macro)
in the transient context then the detoasted copies will be freed on
each cycle. Accordingly, if you keep references to such values in
your <structfield>user_fctx</>, you must either copy them into the
<structfield>multi_call_memory_ctx</> after detoasting, or ensure
that you detoast the values only in that context.
</para>
</warning>
--
Andrew (irc:RhodiumToad)
From | Date | Subject | |
---|---|---|---|
Next Message | Petr Jelinek | 2014-12-15 05:57:48 | Logical Replication Helpers WIP for discussion |
Previous Message | Michael Paquier | 2014-12-15 05:37:57 | Commit fest 2014-12, let's begin! |