Re: Join query on 1M row table slow

From: "Matthew Lunnon" <mlunnon(at)rwa-net(dot)co(dot)uk>
To: "CSN" <cool_screen_name90001(at)yahoo(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Join query on 1M row table slow
Date: 2004-02-11 09:43:41
Message-ID: 005101c3f083$b1a74fa0$8e8bbd3e@rwanet.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have found in previous versions of postgres that rewriting the join can help. Have you tried something like:

select p.*
from product_categories pc, products p
where pc.product_id = p.id AND pc.category_id = $category_id
order by p.title
limit 25
offset $offset

cheers
Matthew
--

Matthew Lunnon
Senior Software Engineer
RWA Ltd
www.rwa-net.co.uk

----- Original Message -----
From: CSN
To: pgsql-general(at)postgresql(dot)org
Sent: Tuesday, February 10, 2004 7:51 PM
Subject: [GENERAL] Join query on 1M row table slow

I have a pretty simple select query that joins a table
(p) with 125K rows with another table (pc) with almost
one million rows:

select p.*
from product_categories pc
inner join products p
on pc.product_id = p.id
where pc.category_id = $category_id
order by p.title
limit 25
offset $offset

The query usually takes about five seconds to execute
(all other PG queries perform fast enough). I have
indexes on everything needed, and EXPLAIN shows
they're being used. Is there anything else I can do to
improve performance - such as tweaking some settings
in the config?

Redhat 9, PG 7.4.1.

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

_____________________________________________________________________
This e-mail has been scanned for viruses by MCI's Internet Managed Scanning Services - powered by MessageLabs. For further information visit http://www.mci.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message William ZHANG 2004-02-11 10:08:10 Re: pg_class and relfilenode
Previous Message NTPT 2004-02-11 09:42:29 Re: DB cache size strategies