Re: Execution from java - slow

Lists: pgsql-performance
From: Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Execution from java - slow
Date: 2012-08-27 12:37:32
Message-ID: OF29CD043F.CF9B30CB-ON65257A67.0044CA19-65257A67.00455DBC@ibsplc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

Hello all,

I have a plpgsql function that takes a few seconds (less than 5) when
executed from psql. The same function, when invoked from java via a
prepared statement takes a few minutes. There are a few queries in the
function. Out of these, the first query takes input parameters for
filtering the data. It is this query which takes a long time when the
procedure is invoked from java. To ensure that the query does use actual
values (and not bind variables) for optimization, we used

execute
'
select x.col_type_desc,x.acc_id,acc_svr from (.....
'
using d_from_date,d_to_date

It did not help. Any suggestions? It is from_date and to_date on which
data gets filtered. We are using the same values for filtering, when we
execute it from java/psql

Regards,
Jayadevan

DISCLAIMER:

"The information in this e-mail and any attachment is intended only for
the person to whom it is addressed and may contain confidential and/or
privileged material. If you have received this e-mail in error, kindly
contact the sender and destroy all copies of the original communication.
IBS makes no warranty, express or implied, nor guarantees the accuracy,
adequacy or completeness of the information contained in this email or any
attachment and is not liable for any errors, defects, omissions, viruses
or for resultant loss or damage, if any, direct or indirect."


From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Jayadevan M *EXTERN*" <Jayadevan(dot)Maymala(at)ibsplc(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Execution from java - slow
Date: 2012-08-27 12:47:12
Message-ID: D960CB61B694CF459DCFB4B0128514C2084EFBF1@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

Jayadevan M wrote:
> I have a plpgsql function that takes a few seconds (less than 5) when
executed from psql. The same
> function, when invoked from java via a prepared statement takes a few
minutes. There are a few queries
> in the function. Out of these, the first query takes input parameters
for filtering the data. It is
> this query which takes a long time when the procedure is invoked from
java. To ensure that the query
> does use actual values (and not bind variables) for optimization, we
used
>
> execute
> '
> select x.col_type_desc,x.acc_id,acc_svr from (.....
> '
> using d_from_date,d_to_date
>
> It did not help. Any suggestions? It is from_date and to_date on which
data gets filtered. We are
> using the same values for filtering, when we execute it from java/psql

Use the auto_explain contrib with
auto_explain.log_nested_statements=on
to see the statements that are really executed
and compare!

Yours,
Laurenz Albe


From: Pavan Deolasee <pavan(dot)deolasee(at)gmail(dot)com>
To: Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Execution from java - slow
Date: 2012-08-28 07:11:16
Message-ID: CABOikdP1uTvULh59dhr-et6-5h-rA6sXYjc7s5P3sznBz_jR8w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

On Mon, Aug 27, 2012 at 6:07 PM, Jayadevan M
<Jayadevan(dot)Maymala(at)ibsplc(dot)com>wrote:

> Hello all,
>
> I have a plpgsql function that takes a few seconds (less than 5) when
> executed from psql. The same function, when invoked from java via a
> prepared statement takes a few minutes. There are a few queries in the
> function. Out of these, the first query takes input parameters for
> filtering the data. It is this query which takes a long time when the
> procedure is invoked from java. To ensure that the query does use actual
> values (and not bind variables) for optimization, we used
>
> execute
> '
> select x.col_type_desc,x.acc_id,acc_svr from (.....
> '
> using d_from_date,d_to_date
>
> It did not help. Any suggestions? It is from_date and to_date on which
> data gets filtered. We are using the same values for filtering, when we
> execute it from java/psql
>
>
It looks highly unlikely that a function execution will take more time
through different client interfaces. May be you want to log the function
input parameters and see if they are coming different through these
interfaces (I think you can use RAISE NOTICE for that). I'm not sure but
client side encoding might also cause changes in the real values of the
date parameters you are passing (e.g mm/dd/yy vs dd/mm/yy). So that will be
worth checking as well.

Thanks,
Pavan


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Pavan Deolasee <pavan(dot)deolasee(at)gmail(dot)com>
Cc: Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Execution from java - slow
Date: 2012-08-28 13:32:15
Message-ID: CAHyXU0xM0LMaRR8L8riPzSQS+tBEtY9puS152sCGxAy9-Fme+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

On Tue, Aug 28, 2012 at 2:11 AM, Pavan Deolasee
<pavan(dot)deolasee(at)gmail(dot)com> wrote:
>
>
> On Mon, Aug 27, 2012 at 6:07 PM, Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>
> wrote:
>>
>> Hello all,
>>
>> I have a plpgsql function that takes a few seconds (less than 5) when
>> executed from psql. The same function, when invoked from java via a
>> prepared statement takes a few minutes. There are a few queries in the
>> function. Out of these, the first query takes input parameters for filtering
>> the data. It is this query which takes a long time when the procedure is
>> invoked from java. To ensure that the query does use actual values (and not
>> bind variables) for optimization, we used
>>
>> execute
>> '
>> select x.col_type_desc,x.acc_id,acc_svr from (.....
>> '
>> using d_from_date,d_to_date
>>
>> It did not help. Any suggestions? It is from_date and to_date on which
>> data gets filtered. We are using the same values for filtering, when we
>> execute it from java/psql
>>
>
> It looks highly unlikely that a function execution will take more time
> through different client interfaces. May be you want to log the function
> input parameters and see if they are coming different through these
> interfaces (I think you can use RAISE NOTICE for that). I'm not sure but
> client side encoding might also cause changes in the real values of the date
> parameters you are passing (e.g mm/dd/yy vs dd/mm/yy). So that will be worth
> checking as well.

Yeah. well, hm. Is the function returning a whole bunch of data?
Also, try confirming the slow runtime from the server's point of view;
log_min_duration_statement is a good setting for that.

merlin


From: Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Pavan Deolasee <pavan(dot)deolasee(at)gmail(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Execution from java - slow
Date: 2012-09-03 08:35:27
Message-ID: OF0F598946.D0106DD5-ON65257A6E.002EF270-65257A6E.002F2BDD@ibsplc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

Hi,

>
>
> Yeah. well, hm. Is the function returning a whole bunch of data?
> Also, try confirming the slow runtime from the server's point of view;
> log_min_duration_statement is a good setting for that.
>
I did try those options. In the end, removing an order by (it was not
necessary) from the SELECT solved the problem. But why the behavior was
different when executed from psql and java is still a mystery.

Thanks a lot for the suggestions.
Regards,
Jayadevan

DISCLAIMER:

"The information in this e-mail and any attachment is intended only for
the person to whom it is addressed and may contain confidential and/or
privileged material. If you have received this e-mail in error, kindly
contact the sender and destroy all copies of the original communication.
IBS makes no warranty, express or implied, nor guarantees the accuracy,
adequacy or completeness of the information contained in this email or any
attachment and is not liable for any errors, defects, omissions, viruses
or for resultant loss or damage, if any, direct or indirect."