Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 688001C20C56 for ; Wed, 16 Nov 2011 20:36:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 65084-10 for ; Thu, 17 Nov 2011 00:36:06 +0000 (UTC) Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 784591C20C55 for ; Wed, 16 Nov 2011 20:36:06 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RQpxW-00054c-9y for pgsql-jdbc@postgresql.org; Thu, 17 Nov 2011 00:36:06 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id pAH0ZqSp025037; Wed, 16 Nov 2011 19:35:53 -0500 (EST) To: Kris Jurka cc: Maciek Sakrejda , Anish Kejariwal , "pgsql-jdbc@postgresql.org" Subject: Re: avoid prepared statements on complex queries? In-reply-to: References: <1321406281.74175.YahooMailNeo@web33903.mail.mud.yahoo.com> <1321475873.74818.YahooMailNeo@web33905.mail.mud.yahoo.com> Comments: In-reply-to Kris Jurka message dated "Wed, 16 Nov 2011 16:16:59 -0500" Date: Wed, 16 Nov 2011 19:35:52 -0500 Message-ID: <25036.1321490152@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201111/36 X-Sequence-Number: 22371 Kris Jurka writes: > On Wed, 16 Nov 2011, Maciek Sakrejda wrote: >> Maybe, although I've never seen that happen and as I understand, the >> driver always sends parameters along with the statement when using >> unnamed statements, so I'm not sure what would trigger this. > The standard example is "WHERE col LIKE ?". If the parameter is something > like 'abcdef%' then the query can potentially be converted to a range > scan, but only if knows the parameter value. When preparing this with an > unnamed statement the server has the parameter value, but cannot assume > that the same unnamed statement won't be used with a different parameter > value later and must come up with a plan that is correct for all possible > parameters even if it's not ideal for the current one. BTW, this should be all better in 9.2 ... so if anyone is thinking of expending lots of effort to fix it on the JDBC side, don't bother. regards, tom lane