Re: Simply join in PostrgeSQL takes too long

From: "Atesz" <atesz(at)ritek(dot)hu>
To: "'Vitaly Belman'" <vitalib(at)012(dot)net(dot)il>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Simply join in PostrgeSQL takes too long
Date: 2004-04-27 21:56:07
Message-ID: 002a01c42ca2$7492ac30$0b02010a@atesz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Nick Barr 2004-04-27 22:00:28 Re: Simply join in PostrgeSQL takes too long
Previous Message Edoardo Ceccarelli 2004-04-27 21:42:58 Re: [JDBC] [PERFORM] is a good practice to create an index on the