Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-performance by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group