From: Tom Lane <tgl@sss.pgh.pa.us>
To: Oliver Jowett <oliver@opencloud.com>
Cc: Barry Lind <blind@xythos.com>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [JDBC] Strange server error with current 8.0beta driver
Date: Sun, 28 Nov 2004 17:23:04 -0500
Message-ID: <21575.1101680584@sss.pgh.pa.us> (raw)
In-Reply-To: <41A4565F.2080804@opencloud.com>
References: <03E7D3E231BB7B4A915A6581D4296CC6CC9794@NSNOVPS00411.nacio.xythos.com>
<41A452A8.9010505@opencloud.com>
<41A4565F.2080804@opencloud.com>
Oliver Jowett <oliver@opencloud.com> writes:
>> Perhaps PerformCursorOpen should copy the query tree before planning, or
>> plan in a different memory context?
> Patch attached. It moves query planning inside the new portal's memory
> context. With this applied I can run Barry's testcase without errors,
> and valgrind seems OK with it too.
I think the better solution is the first way (copy the querytree first).
The problem with the way you did it is that all the temporary structures
built by the planner will be left behind in the cursor's memory context,
and can't be reclaimed until the cursor is destroyed. In the case of a
complex query that could represent a pretty serious memory leak. It
seems better to eat the cost of copying the querytree an extra time,
especially since this way forms a patch that's easy to reverse whenever
we fix the planner to be less cavalier about scribbling on its input.
I've applied the attached patch instead (and analogously in 7.4 branch).
Would you confirm it fixes the problem you see?
regards, tom lane
inline patch 1: src/backend/commands/portalcmds.c (+10/-1 lines) download inline-1.patch*** src/backend/commands/portalcmds.c.orig Thu Sep 16 12:58:28 2004
--- src/backend/commands/portalcmds.c Sun Nov 28 17:02:22 2004
***************
*** 62,73 ****
RequireTransactionChain((void *) stmt, "DECLARE CURSOR");
/*
* The query has been through parse analysis, but not rewriting or
* planning as yet. Note that the grammar ensured we have a SELECT
* query, so we are not expecting rule rewriting to do anything
* strange.
*/
! rewritten = QueryRewrite((Query *) stmt->query);
if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query))
elog(ERROR, "unexpected rewrite result");
query = (Query *) linitial(rewritten);
--- 62,82 ----
RequireTransactionChain((void *) stmt, "DECLARE CURSOR");
/*
+ * Because the planner is not cool about not scribbling on its input,+ * we make a preliminary copy of the source querytree. This prevents+ * problems in the case that the DECLARE CURSOR is in a portal and is+ * executed repeatedly. XXX the planner really shouldn't modify its+ * input ... FIXME someday.+ */+ query = copyObject(stmt->query);+ + /*
* The query has been through parse analysis, but not rewriting or
* planning as yet. Note that the grammar ensured we have a SELECT
* query, so we are not expecting rule rewriting to do anything
* strange.
*/
! rewritten = QueryRewrite(query);
if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query))
elog(ERROR, "unexpected rewrite result");
query = (Query *) linitial(rewritten);
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-jdbc@postgresql.org
Cc: tgl@sss.pgh.pa.us, oliver@opencloud.com, blind@xythos.com, pgsql-hackers@postgresql.org
Subject: Re: [JDBC] Strange server error with current 8.0beta driver
In-Reply-To: <21575.1101680584@sss.pgh.pa.us>
References: <03E7D3E231BB7B4A915A6581D4296CC6CC9794@NSNOVPS00411.nacio.xythos.com> <41A452A8.9010505@opencloud.com> <41A4565F.2080804@opencloud.com> <21575.1101680584@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