From: Tom Lane <tgl@sss.pgh.pa.us>
To: g.vanluffelen@qipc.com
Cc: pgsql-hackers@postgreSQL.org
Subject: Re: [BUGS] BUG #8573: int4range memory consumption
Date: Fri, 01 Nov 2013 15:08:28 -0400
Message-ID: <18832.1383332908@sss.pgh.pa.us> (raw)
In-Reply-To: <E1VcC7Y-0006Tl-He@wrigleys.postgresql.org>
References: <E1VcC7Y-0006Tl-He@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
g.vanluffelen@qipc.com writes:
> int4range ( and any other range function) consumes much memory when used in
> a select statement on a big table.
The problem is that range_out leaks memory, as a consequence of creating a
number of intermediate strings that it doesn't bother to free. I don't
believe it's the only output function that leaks memory, but it does
so with particular vim: now that we've increased the initial size of
StringInfo buffers, it's probably wasting upwards of 2K per call.
While we could doubtless hack range_out to release those strings again,
it seems to me that that's just sticking a finger in the dike. I'm
inclined to think that we really ought to solve this class of problems
once and for all by fixing printtup.c to run the output functions in a
temporary memory context, which we could reset once per row to recover all
memory used. That would also let us get rid of the inadequate kluges that
printtup currently uses to try to minimize leakage, namely forced
detoasting of varlena fields and forced pfree'ing of the strings returned
by output functions. (There is no other context in which we imagine that
it's safe to pfree a function's result, and there are a number of
datatypes for which it'd make sense to return constant strings, were it
not for this kluge.)
It's possible that this would result in some net slowdown in tuple output;
but it's also possible that eliminating the retail pfree's in favor of a
single context reset per tuple would make for a net savings. In any case,
we're already using a reset-per-row approach to memory management of
output function calls in COPY OUT, and I know for a fact that we've
squeezed that code path as hard as we could.
Thoughts?
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, g.vanluffelen@qipc.com, pgsql-hackers@postgreSQL.org
Subject: Re: [BUGS] BUG #8573: int4range memory consumption
In-Reply-To: <18832.1383332908@sss.pgh.pa.us>
References: <E1VcC7Y-0006Tl-He@wrigleys.postgresql.org> <18832.1383332908@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox