Re: Performance problems with prepared statements - Mailing list pgsql-performance

From Jonah H. Harris
Subject Re: Performance problems with prepared statements
Date
Msg-id 36e682920710101255n5760a009v8fdbf42e4599f16f@mail.gmail.com
Whole thread Raw
In response to Performance problems with prepared statements  (Theo Kramer <theo@flame.co.za>)
Responses Re: Performance problems with prepared statements
List pgsql-performance
On 10/10/07, Theo Kramer <theo@flame.co.za> wrote:
> When running the query directly from psql it returns the required rows
> in less than 100 milli-seconds.
>
> However, when using a prepared statement from my C application on the
> above query and executing it the query duration is as follows
> ...
> Row[s] = 25, Duration = 435409.474 ms
>

How are you timing it?  Does it really take 435 seconds to complete?
Try the following in psql:

postgres# PREPARE yourplan (VARCHAR, INT, INT) AS
SELECT oid, * FROM calllog
WHERE calllog_mainteng = $1
AND calllog_phase = $2
AND calllog_self < $3
OR calllog_mainteng = $1
AND calllog_phase < 8
ORDER BY calllog_mainteng DESC,
 calllog_phase DESC,
 calllog_self DESC limit 25;

postgres# EXECUTE yourplan('124         ', 8, 366942);

--
Jonah H. Harris, Sr. Software Architect | phone: 732.331.1324
EnterpriseDB Corporation                | fax: 732.331.1301
499 Thornall Street, 2nd Floor          | jonah.harris@enterprisedb.com
Edison, NJ 08837                        | http://www.enterprisedb.com/

pgsql-performance by date:

Previous
From: Simon Riggs
Date:
Subject: Re: hashjoin chosen over 1000x faster plan
Next
From: Theo Kramer
Date:
Subject: Re: Performance problems with prepared statements