Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 90C962EC09B for ; Mon, 4 Jun 2012 22:26:33 -0300 (ADT) Received: from na3sys009aog132.obsmtp.com ([74.125.149.250]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SbiXU-0002m9-Q3 for pgsql-performance@postgresql.org; Tue, 05 Jun 2012 01:26:32 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) (using TLSv1) by na3sys009aob132.postini.com ([74.125.148.12]) with SMTP ID DSNKT81gNQVJYOSMMzzRaUMEUvK1f8cjs+eo@postini.com; Mon, 04 Jun 2012 18:26:28 PDT Received: by pbbrp8 with SMTP id rp8so6765562pbb.19 for ; Mon, 04 Jun 2012 18:26:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:x-gm-message-state; bh=QXxWH3bi0uL1iD8R5cWKWZwC4+dtFNbWuahLWptiOJ8=; b=bm0LY4NrA1CJnldH+Eb7bMCSz2Ynm08mpPDVP+j5gXqKaCLSS0PgVuH+jr9cGGzyRM uqdE5vnK8iQQLcuxcWJRli2cTuxJtLPqMBNSUrmZBVlJ1B3zjzneNQUdnHp4BktGiH6M Jf5Yzgiu72s5BsiglprZbr3czgfa+mjk1DovQ1S6mgm7fLgAmwt14eBWb6ekAPAHnok3 1W2jGH/WOQw7/tUZqTt9LEpvg14lPXYiclu0Kfc6Yx+TDRXRozXF1o645IXlOEMJPniE J6YejUFxvJBSCVlCTkN/ocz7q8Wxt+htRymbwYlv/had6i9aFuz1EfhII4KpYnAcDltC G8qQ== Received: by 10.68.211.170 with SMTP id nd10mr9746135pbc.68.1338859561164; Mon, 04 Jun 2012 18:26:01 -0700 (PDT) Received: from [172.20.9.121] (eth59-167-133-99.static.internode.on.net. [59.167.133.99]) by mx.google.com with ESMTPS id pb10sm476570pbc.68.2012.06.04.18.25.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 04 Jun 2012 18:26:00 -0700 (PDT) Message-ID: <4FCD6024.10507@atlassian.com> Date: Tue, 05 Jun 2012 11:25:56 +1000 From: Trevor Campbell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: Maciek Sakrejda CC: Vitalii Tymchyshyn , Craig James , pgsql-performance@postgresql.org Subject: Re: Trouble with plan statistics for behaviour for query. References: <4FC7F0DB.40600@atlassian.com> <4FC7F844.8070205@atlassian.com> <4FC80000.2000900@atlassian.com> <4FC8862B.70103@gmail.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------070405020307020701090808" X-Gm-Message-State: ALoCoQn7fVBlDiHhFr24qEjzeTycMyo8GvjwQV73HR0mdfaT2uX5bLUBCVLXehYLQXAd6swbohlB X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201206/17 X-Sequence-Number: 47043 This is a multi-part message in MIME format. --------------070405020307020701090808 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Thanks for all your help so far. I have been away for a couple of days so my apologies for not replying earlier. We are using a third party library to run our SQL via JDBC (not one of the common ones like Hibernate etc), but I have been able to dig out the exact statements run in the scenario we are experiencing. We always run a prepare and then execute a query as follows, we never reuse the prepared statement: _ps = _connection.prepareStatement(sql, resultSetType, resultSetConcurrency); // The values here are: // sql = SELECT CG.ID, CG.issueid, CG.AUTHOR, CG.CREATED, CI.ID, CI.groupid, CI.FIELDTYPE, CI.FIELD, CI.OLDVALUE, CI.OLDSTRING, CI.NEWVALUE, CI.NEWSTRING // FROM public.changegroup CG INNER JOIN public.changeitem CI ON CG.ID = CI.groupid // WHERE CG.issueid=? ORDER BY CG.CREATED ASC, CI.ID ASC // resultSetType = ResultSet.TYPE_FORWARD_ONLY // resultSetConcurrency = ResultSet.CONCUR_READ_ONLY _ps.setLong(1, field); _rs = _ps.executeQuery(); On 02/06/12 01:38, Maciek Sakrejda wrote: >> If I am correct, JDBC uses named portal only on the 5th time you use >> PreparedStatement (configurable). Before it uses unnamed thing that should >> work as if you did embed the value. > If this is due to the difference in parameter type information, this > doesn't have anything to do with named portals. > > My guess is that the driver has one idea about parameter types (based > on either the specific setTypeFoo call or the Java type of the > parameter passed to setObject), and the server another (based on the > type information of the CHANGEGROUP.ISSUEID column). Actually, I'm > rather surprised to see 'real' there: if you're using setObject with a > Long, I would imagine that turns into a bigint (which I believe the > server knows how to coerce to numeric). Can you show us your JDBC > code? --------------070405020307020701090808 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks for all your help so far.  I have been away for a couple of days so my apologies for not replying earlier.

We are using a third party library to run our SQL via JDBC (not one of the common ones like Hibernate etc), but I have been able to dig out the exact statements run in the scenario we are experiencing.

We always run a prepare and then execute a query as follows, we never reuse the prepared statement:

_ps = _connection.prepareStatement(sql, resultSetType, resultSetConcurrency); 

// The values here are:
// sql = SELECT CG.ID, CG.issueid, CG.AUTHOR, CG.CREATED, CI.ID, CI.groupid, CI.FIELDTYPE, CI.FIELD, CI.OLDVALUE, CI.OLDSTRING, CI.NEWVALUE, CI.NEWSTRING 
//                           FROM public.changegroup CG INNER JOIN public.changeitem CI ON CG.ID = CI.groupid
//                           WHERE CG.issueid=? ORDER BY CG.CREATED ASC, CI.ID ASC
// resultSetType = ResultSet.TYPE_FORWARD_ONLY
// resultSetConcurrency =  ResultSet.CONCUR_READ_ONLY

_ps.setLong(1, field);     

_rs = _ps.executeQuery();

On 02/06/12 01:38, Maciek Sakrejda wrote:
If I am correct, JDBC uses named portal only on the 5th time you use
PreparedStatement (configurable). Before it uses unnamed thing that should
work as if you did embed the value.
If this is due to the difference in parameter type information, this
doesn't have anything to do with named portals.

My guess is that the driver has one idea about parameter types (based
on either the specific setTypeFoo call or the Java type of the
parameter passed to setObject), and the server another (based on the
type information of the CHANGEGROUP.ISSUEID column). Actually, I'm
rather surprised to see 'real' there: if you're using setObject with a
Long, I would imagine that turns into a bigint (which I believe the
server knows how to coerce to numeric). Can you show us your JDBC
code?
--------------070405020307020701090808--