Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BCBFD632DA9 for ; Sun, 3 May 2009 11:42:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 48076-04 for ; Sun, 3 May 2009 11:41:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 36976632D8B for ; Sun, 3 May 2009 11:41:57 -0300 (ADT) 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 n43EfaNE011396; Sun, 3 May 2009 10:41:36 -0400 (EDT) To: John Lister cc: pgsql-jdbc@postgresql.org Subject: Re: Very strange performance decrease when reusing a PreparedStatement In-reply-to: <49FD7383.1010005@kickstone.com> 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> Comments: In-reply-to John Lister message dated "Sun, 03 May 2009 11:35:47 +0100" Date: Sun, 03 May 2009 10:41:36 -0400 Message-ID: <11395.1241361696@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/15 X-Sequence-Number: 19565 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. There are certainly cases where lack of parameter type information could lead to a poor plan, but they are corner cases. regards, tom lane