Re: Very slow queries on 8.1 - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Very slow queries on 8.1
Date
Msg-id 20051117170651.GA17315@winnie.fuhr.org
Whole thread Raw
In response to Very slow queries on 8.1  (David Rysdam <drysdam@ll.mit.edu>)
Responses Re: Very slow queries on 8.1
List pgsql-general
On Thu, Nov 17, 2005 at 10:38:50AM -0500, David Rysdam wrote:
> I'm porting an application from Sybase and I've noticed that similar
> application functions take 2 to 3 times longer on postgres than they
> used to on the same machine running under Sybase.  I've tried changing
> various "performance tuning" parameters, such as shared_buffers,
> effective_cache_size, etc but there's little or no effect.

What's your OS and hardware environment and what are your non-default
PostgreSQL settings?

> Right now, I'm working on a test case that involves a table with ~360k
> rows called "nb.sigs".  My sample query is:
>
> select * from nb.sigs where signum > 250000
>
> With no index, explain says this query costs 11341.  After CREATE INDEX
> on the signum field, along with an ANALYZE for nb.sigs, the query costs
> 3456 and takes around 4 seconds to return the first row.

Please post the EXPLAIN ANALYZE output for the query -- that'll
show us the query plan, the accuracy of the planner's row count
estimate, and how long the query takes to execute on the server.
It might also be useful to see the table definition and the output
of the following query:

SELECT null_frac, n_distinct, correlation
FROM pg_stats
WHERE schemaname = 'nb' AND tablename = 'sigs' AND attname = 'signum';

What client interface are you using?  If the query returns a lot
of rows then you might benefit from using a cursor to fetch the
result set in chunks; otherwise the client library is probably
waiting for the entire result set to arrive before returning any
rows to you.  If the result set is large then you can experience
performance problems due to a shortage of real memory.

How volatile is the data and how common are queries based on signum?
You might benefit from clustering on the signum index.

> (If necessary, I can write an entire script that creates and populates a
> table and then give my performance on that sample for someone else to
> check against.)

If it's a short script that populates the table with canned data
then go ahead and post it.

--
Michael Fuhr

pgsql-general by date:

Previous
From: David Rysdam
Date:
Subject: Re: Very slow queries on 8.1
Next
From: Robby Russell
Date:
Subject: Re: Moving from MySQL to PostgreSQL with Ruby on Rails.