Re: [PERFORM] Query much slower when run from postgres function

From: Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>
To: pgsql-performance(at)postgresql(dot)org
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [PERFORM] Query much slower when run from postgres function
Date: 2009-03-09 19:26:05
Message-ID: 49B56D4D.9090605@megafon.hr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc pgsql-performance

Guillaume Cottenceau wrote:
>>> Now I'm confused, why is 'sql' function much slower than 'direct' SELECT?
>> Usually the reason for this is that the planner chooses a different plan
>> when it has knowledge of the particular value you are searching for than
>> when it does not.
>
> Yes, and since Mario is coming from JDBC, I'll share my part on
> this: I also noticed some very wrong plans in JDBC because of the
> "optimization" in prepared statements consisting of planning once
> for all runs, e.g. without any parameter values to help planning.
>

For what is worth:

When I call postgres function via JDBC, I have almost the same execution
time as when calling function from psql.

When I call SELECT COUNT(*)... WHERE... query from JDBC, I again have
almost the same execution time as when executing query from psql.

Postgres function takes around 200ms, and SELECT query takes around 2-4ms.

Mike

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tom Lane 2009-03-09 19:51:58 Re: Query much slower when run from postgres function
Previous Message Saleem EDAH-TALLY 2009-03-09 19:20:58 getGeneratedKeys

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2009-03-09 19:51:58 Re: Query much slower when run from postgres function
Previous Message Mario Splivalo 2009-03-09 19:13:01 Re: Query much slower when run from postgres function