X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D2EFD3A1D8E for ; Wed, 24 Nov 2004 09:33:09 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 88173-07 for ; Wed, 24 Nov 2004 09:33:01 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 357CC3A1D89 for ; Wed, 24 Nov 2004 09:33:02 +0000 (GMT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CWtWB-0001Yh-00; Wed, 24 Nov 2004 22:32:55 +1300 Message-ID: <41A4565F.2080804@opencloud.com> Date: Wed, 24 Nov 2004 22:37:35 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.9 (X11/20041115) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Barry Lind Cc: Tom Lane , pgsql-hackers@postgresql.org Subject: Re: [JDBC] Strange server error with current 8.0beta driver References: <03E7D3E231BB7B4A915A6581D4296CC6CC9794@NSNOVPS00411.nacio.xythos.com> <41A452A8.9010505@opencloud.com> In-Reply-To: <41A452A8.9010505@opencloud.com> X-Enigmail-Version: 0.86.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/mixed; boundary="------------040201000407010303030108" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/895 X-Sequence-Number: 61467 This is a multi-part message in MIME format. --------------040201000407010303030108 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Oliver Jowett wrote: > 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. -O --------------040201000407010303030108 Content-Type: text/plain; name="pgsql-declare-memory-clobber.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pgsql-declare-memory-clobber.txt" Index: src/backend/commands/portalcmds.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/commands/portalcmds.c,v retrieving revision 1.36 diff -c -r1.36 portalcmds.c *** src/backend/commands/portalcmds.c 16 Sep 2004 16:58:28 -0000 1.36 --- src/backend/commands/portalcmds.c 24 Nov 2004 09:28:34 -0000 *************** *** 67,73 **** * 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); --- 67,86 ---- * query, so we are not expecting rule rewriting to do anything * strange. */ ! ! /* Create a new portal, and do all query planning on a copy of ! * the query allocated in the new portal's memory context. The ! * planner may modify the query, and it is not safe to have ! * those modifications persist as we are ourselves running in a ! * transient portal context. ! */ ! portal = CreatePortal(stmt->portalname, false, false); ! ! oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal)); ! ! query = copyObject(stmt->query); ! ! rewritten = QueryRewrite(query); if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query)) elog(ERROR, "unexpected rewrite result"); query = (Query *) linitial(rewritten); *************** *** 86,102 **** plan = planner(query, true, stmt->options, NULL); - /* - * Create a portal and copy the query and plan into its memory - * context. - */ - portal = CreatePortal(stmt->portalname, false, false); - - oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal)); - - query = copyObject(query); - plan = copyObject(plan); - PortalDefineQuery(portal, NULL, /* unfortunately don't have sourceText */ "SELECT", /* cursor's query is always a SELECT */ --- 99,104 ---- --------------040201000407010303030108--