From: Atesz <atesz@ritek.hu>
To: 'Vitaly Belman' <vitalib@012.net.il>
To: pgsql-performance@postgresql.org
Subject: Re: Simply join in PostrgeSQL takes too long
Date: Tue, 27 Apr 2004 23:56:07 +0200
Message-ID: <002a01c42ca2$7492ac30$0b02010a@atesz> (raw)
In-Reply-To: <282909734.20040428002740@012.net.il>
Hi,
You can try some variation:
SELECT
book_id
FROM
bookgenres, genre_children
WHERE
bookgenres.genre_id = genre_children.genre_child_id AND
genre_children.genre_id = 1
GROUP BY book_id
LIMIT 10
The next works if the 'genre_child_id' is UNIQUE on the 'genre_children'
table.
SELECT
book_id
FROM
bookgenres
WHERE
bookgenres.genre_id = (SELECT genre_child_id FROM genre_children
WHERE genre_id = 1)
GROUP BY book_id
LIMIT 10
You may need some index. Try these with EXPLAIN!
CREATE INDEX bookgenres_genre_id_book_id ON bookgenres(genre_id,
book_id); or
CREATE INDEX bookgenres_book_id_genre_id ON bookgenres(book_id,
genre_id);
CREATE INDEX genre_children_genre_id ON genre_children(genre_id);
Regards, Antal Attila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: atesz@ritek.hu, vitalib@012.net.il
Subject: Re: Simply join in PostrgeSQL takes too long
In-Reply-To: <002a01c42ca2$7492ac30$0b02010a@atesz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox