pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Behl, Rohit ((Infosys)) <Rohit.Behl@uk.bp.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Jdbc/postgres performance
Date: Sun, 22 Oct 2006 11:11:17 -0400
Message-ID: <5D3EE611-A725-44D3-9FA5-35D7FE938BF2@fastcrypt.com> (raw)
In-Reply-To: <686E9FBCE580BC46BB3FE11A277C2DAE0194084C@BP1XEUEX017-C.bp1.ad.bp.com>
References: <686E9FBCE580BC46BB3FE11A277C2DAE0194084C@BP1XEUEX017-C.bp1.ad.bp.com>


On 17-Oct-06, at 3:05 PM, Behl, Rohit ((Infosys)) wrote:

> Hi
>
> We are facing performance problems in postgres while executing a  
> query. When I execute this query on the server it takes 5-10  
> seconds. Also I get good performance while executing this query  
> from my code in java with the hard codes values. I face severe  
> performance problems when I run it using a prepared statement.
>
> The query is as follows:
>
> Select events.event_id, ctrl.real_name, events.tsds, events.value,  
> events.lds, events.correction, ctrl.type, ctrl.freq from  
> iso_midw_data_update_events events, iso_midw_control ctrl where  
> events.obj_id = ctrl.obj_id and events.event_id > 68971124 order by  
> events.event_id limit 2000
>
> The above query executes in 5-10 seconds.
>
> However the below query executes in 8 mins:
>
> Select events.event_id, ctrl.real_name, events.tsds, events.value,  
> events.lds, events.correction, ctrl.type, ctrl.freq from table  
> events, iso_midw_control ctrl where events.obj_id = ctrl.obj_id and  
> events.event_id > ?::bigint order by events.event_id limit ?
> setLong(1, 68971124);
>
> setInt(2, 2000);
>
> The table has close to 5 million rows. The table has the following  
> index:
>
> iso_midw_data_update_events_event_id_key
>
> iso_midw_data_update_events_lds_idx
>
> iso_midw_data_update_events_obj_id_idx
>
>
> The table is described as follows:
>
> Columns_name data_type type_name        column_size
>
> lds             2       numeric         13
>
> obj_id          2       numeric         6
>
> tsds            2       numeric         13
>
> value           12      varchar         22
>
> correction      2       numeric         1
>
> delta_lds_tsds  2       numeric         13
>
> event_id        -5      bigserial       8
>
> Please tell me what I am missing while setting the prepared  
> statement. I am using postgres7.4.2. and postgresql-8.1-407.jdbc3.jar.

Try the same query with protocolVersion=2. There are some issues with  
prepared statements being slower if the parameters are not the same  
type as the column being compared to.

protocol version 2 will issue the query exactly the same as psql  
does. Also note that your two queries are not identical. In the  
prepared query you cast to bigint ?

Version 8.1.x handles this better I think.
>
> Thanks
>
>
> Regards
>
> Rohit
>

view thread (12+ messages)

Message-ID: <5D3EE611-A725-44D3-9FA5-35D7FE938BF2@fastcrypt.com>
Permalink:  ../5D3EE611-A725-44D3-9FA5-35D7FE938BF2@fastcrypt.com/
Also on:    postgresql.org/message-id/5D3EE611-A725-44D3-9FA5-35D7FE938BF2@fastcrypt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: pg@fastcrypt.com, Rohit.Behl@uk.bp.com
  Subject: Re: Jdbc/postgres performance
  In-Reply-To: <5D3EE611-A725-44D3-9FA5-35D7FE938BF2@fastcrypt.com>
  References: <686E9FBCE580BC46BB3FE11A277C2DAE0194084C@BP1XEUEX017-C.bp1.ad.bp.com> <5D3EE611-A725-44D3-9FA5-35D7FE938BF2@fastcrypt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox