Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D307A632F81 for ; Sun, 3 May 2009 14:50:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 11621-04 for ; Sun, 3 May 2009 14:50:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mk-filter-4-a-1.mail.uk.tiscali.com (mk-filter-4-a-1.mail.uk.tiscali.com [212.74.100.55]) by mail.postgresql.org (Postfix) with ESMTP id BBAB1632F15 for ; Sun, 3 May 2009 14:50:49 -0300 (ADT) X-Trace: 188827212/mk-filter-4.mail.uk.tiscali.com/B2C/$b2c-THROTTLED-DYNAMIC/b2c-CUSTOMER-DYNAMIC-IP/62.64.158.120/None/john.lister-ps@kickstone.com X-SBRS: None X-RemoteIP: 62.64.158.120 X-IP-MAIL-FROM: john.lister-ps@kickstone.com X-SMTP-AUTH: X-MUA: Thunderbird 2.0.0.21 (Windows/20090302) X-IP-BHB: Once X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Au8CAJ92/Uk+QJ54/2dsb2JhbAAIzBeDfQU X-IronPort-AV: E=Sophos;i="4.40,287,1238972400"; d="scan'208";a="188827212" Received: from 62-64-158-120.dynamic.dial.as9105.com (HELO [192.168.6.11]) ([62.64.158.120]) by smtp.tiscali.co.uk with ESMTP; 03 May 2009 18:50:46 +0100 Message-ID: <49FDD975.1020002@kickstone.com> Date: Sun, 03 May 2009 18:50:45 +0100 From: John Lister User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Tom Lane CC: John Lister , pgsql-jdbc@postgresql.org Subject: Re: Very strange performance decrease when reusing a PreparedStatement References: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr> <49F71EDD.2070200@opencloud.com> <02437794-A78D-449C-843F-B823195F9623@noopsis.fr> <491f66a50905030310j5b4cdcd8jbf4f6e757c2ba580@mail.gmail.com> <49FD7383.1010005@kickstone.com> <11395.1241361696@sss.pgh.pa.us> In-Reply-To: <11395.1241361696@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.198 tagged_above=0 required=5 tests=AWL=0.198 X-Spam-Level: X-Archive-Number: 200905/18 X-Sequence-Number: 19568 Tom Lane wrote: > John Lister writes: > >> However it seems that other optimisations can't be made for example it >> doesn't seem possible to tell the server that parameter 1 is always >> going to be an int and therefore it should be using index A. The current >> implementation may not use index A as it is unaware as to the type of >> the supplied parameter. >> > > I don't think this is true either. The wire protocol certainly provides > the ability for the client to tell the server what data type a parameter > has. I don't know whether the JDBC driver makes use of that, but if it > does not, then something like > variable = ? > is going to be treated exactly like > variable = 'unmarked literal' > and in both cases the parser's default assumption is that the > unknown-type value has the same data type as the thing it's being > compared to. So if the variable is indexed this would always be > seen as a indexable comparison. > The JDBC driver tries to mitigate this by delaying the parse until execution time when all the query parameters are known. > There are certainly cases where lack of parameter type information could > lead to a poor plan, but they are corner cases. > > I was guessing on the server implementation (wrongly probably) based on a some other posts and comments in the code. My knowledge of the query planner is limited but i would hope there are only a few cases where knowing the types isn't sufficient to generate good plans without knowing the values JOHN