Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id F3AF19F9A9B for ; Mon, 1 Oct 2007 05:18:16 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 34202-06 for ; Mon, 1 Oct 2007 05:18:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mirth.inuus.com (mirth.inuus.com [67.100.95.85]) by postgresql.org (Postfix) with ESMTP id 423379F9A97 for ; Mon, 1 Oct 2007 05:18:11 -0300 (ADT) Received: from mirth.inuus.com (localhost.localdomain [127.0.0.1]) by mirth.inuus.com (8.14.1/8.14.1) with ESMTP id l918HTi9000379 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 1 Oct 2007 01:17:29 -0700 Received: (from lindner@localhost) by mirth.inuus.com (8.14.1/8.14.1/Submit) id l918HK8w000378; Mon, 1 Oct 2007 01:17:20 -0700 X-Authentication-Warning: mirth.inuus.com: lindner set sender to lindner@inuus.com using -f Date: Mon, 1 Oct 2007 01:17:20 -0700 From: Paul Lindner To: Oliver Jowett Cc: Paul Lindner , Gregory Stark , pgsql-jdbc@postgresql.org Subject: Re: Prepared Statements vs. pgbouncer Message-ID: <20071001081720.GM3140@inuus.com> References: <20070929002513.GG3140@inuus.com> <87sl4xvmn2.fsf@oxford.xeocode.com> <20070929144635.GK3140@inuus.com> <46FED6A2.8000209@opencloud.com> <20070930070725.GL3140@inuus.com> <46FF4C08.2090608@opencloud.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="SEFvVLxbW/dEDtN8" Content-Disposition: inline In-Reply-To: <46FF4C08.2090608@opencloud.com> User-Agent: Mutt/1.5.14 (2007-02-12) X-Virus-Scanned: ClamAV 0.91.2/4443/Sun Sep 30 15:16:01 2007 on mirth.inuus.com X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/3 X-Sequence-Number: 17575 --SEFvVLxbW/dEDtN8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 30, 2007 at 08:11:04PM +1300, Oliver Jowett wrote: > Paul Lindner wrote: >=20 > >2) If we try to prepare a statement with an hashed name and it already > > exists then we ignore the error and continue. >=20 > Errors will cause the current transaction to fail.. Looking through the backend code and the protocol flow documenation it appears we could just close the statement name and it won't cause an error: switch (close_type) { case 'S': if (close_target[0] !=3D '\0') DropPreparedStatement(close_target, false); else where void DropPreparedStatement(const char *stmt_name, bool showError) So amend number 2 to say: 2) Before preparing a statement with a hashed name, send a close statement to insure that we don't get an error inside of a transaction. This is just as performant as the current driver which will happily re-prepare the same SQL many times. Sadly it appears that the protocol does not allow for arbitrary optional data to be sent along with the query.=20 For example, it would be fairly easy to modify gram.y to support IF EXISTS or OR REPLACE -- getting that into the protocol looks to be a bit more difficult. (FYI if anyone is interested in the following syntax let me know, If there's interest I could spend some of my free time hacking the backend) DEALLOCATE [IF EXISTS] ; PREPARE [OR REPLACE] [(args, ...)] AS > >3) If we receive an error while executing a prepared statement with an > > hashed name the driver will try to re-prepare the statement and > > re-execute the query. If an error occurs after this retry step then > > error are surfaced to the caller. >=20 > ... so you can't just back off and try again. Actually #3 isn't needed anymore if the deallocate/re-prepare steps are carried out as mentioned above. For me it still appears worth the effort to modify the driver to support what I've outlined. I do hope that you'll find any work done useful for general consumption. --=20 Paul Lindner ||||| | | | | | | | | | lindner@inuus.com --SEFvVLxbW/dEDtN8 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHAK0P+FkoUnP1gFQRAuhdAKCMrFdgRk2nm+uC0PSLoPMV6MkLOACfdJyw QPyU5DeahA2yH5lgk6WgGG0= =DY39 -----END PGP SIGNATURE----- --SEFvVLxbW/dEDtN8--