Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 9EEFFB5DC09 for ; Tue, 20 Sep 2011 23:36:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 35086-01 for ; Wed, 21 Sep 2011 02:36:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from tamriel.snowman.net (tamriel.snowman.net [72.66.115.51]) by mail.postgresql.org (Postfix) with ESMTP id DB0CFB5DBC4 for ; Tue, 20 Sep 2011 23:36:15 -0300 (ADT) Received: by tamriel.snowman.net (Postfix, from userid 1000) id 28F742299A; Tue, 20 Sep 2011 22:36:15 -0400 (EDT) Date: Tue, 20 Sep 2011 22:36:15 -0400 From: Stephen Frost To: Royce Ausburn Cc: Craig Ringer , pgsql-performance Subject: Re: Prepared statements and suboptimal plans Message-ID: <20110921023615.GV12765@tamriel.snowman.net> References: <4E792417.5080205@ringerc.id.au> <4AC1C03D-9531-497D-B8EF-1B55D890A3FB@inomial.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="zGqVP2YgkFRp/g3j" Content-Disposition: inline In-Reply-To: <4AC1C03D-9531-497D-B8EF-1B55D890A3FB@inomial.com> X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/2.6.32-5-amd64 (x86_64) X-Uptime: 22:34:53 up 230 days, 11:04, 13 users, load average: 0.02, 0.03, 0.00 User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/300 X-Sequence-Number: 45076 --zGqVP2YgkFRp/g3j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Royce Ausburn (royce.ml@inomial.com) wrote: > > Tom just mentioned that 9.1 will be able to re-plan parameterized prepa= red statements, so this issue will go away. In the mean time you can only r= eally use the standard workaround of setting the prepare theshold to 0 to d= isable server-side prepare, so you can continue to use JDBC prepared statem= ents and have the driver do the parameter substitution for you. >=20 > Thanks Craig -- that trick helps a lot. =20 You might also be able to bump up work_mem by a fair bit to get PG to use a hashagg instead of groupagg/sort, even though its estimate is way off. That's what I've done in the past for similar situations and it's worked well. I'd recommend increasing it for just this query and then resetting it (assuming you don't just drop the connection, in which case you don't need to reset it since a new connection will get the default). Thanks, Stephen --zGqVP2YgkFRp/g3j Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAk55TZ8ACgkQrzgMPqB3kihsZQCggL3IOpY9szTjTxm7pepOZe2Q cHgAnj9F0fd4vfl2p+Go6zkeCtbWj6gx =ZSJM -----END PGP SIGNATURE----- --zGqVP2YgkFRp/g3j--