Re: Anything I can do to speed up this query?

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Wei Weng <wweng(at)kencast(dot)com>
Cc: PostgreSQL-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Anything I can do to speed up this query?
Date: 2006-12-05 21:07:19
Message-ID: 1165352839.14565.456.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2006-12-05 at 14:56, Wei Weng wrote:
> I have a table that has roughly 200,000 entries and many columns.
>
> The query is very simple:
>
> SELECT Field1, Field2, Field3... FieldN FROM TargetTable;
>
> TargetTable has an index that is Field1.
>
> The thing is on this machine with 1Gig Ram, the above query still takes
> about 20 seconds to finish. And I need it to run faster, ideally around
> 5 seconds.

You're basically asking for everything in the table, right?

If you're not using a cursor, then it's gonna take the time to grab the
data then transfer it across the wire.

If you wrap that query in a cursor:

begin;
declare bubba cursor for select * from targettable;
fetch 100 from bubba; -- repeat as necessary
commit; -- or rollback, doesn't really matter.

That way you can start getting data before the whole result set is
returned. You won't get the data any faster, but you can start spewing
it at the user almost immediately. Which makes is feel faster.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2006-12-05 21:09:20 Re: HELP: Urgent, Vacuum problem
Previous Message Bill Moran 2006-12-05 21:06:27 Online index builds (was: [ANNOUNCE] PostgreSQL 8.2 Now Available)