Received: from ganesh.paneris.org (IDENT:root@paneris.org [194.128.98.74]) by hub.org (8.9.3/8.9.3) with ESMTP id RAA84040 for ; Fri, 19 Nov 1999 17:51:44 -0500 (EST) (envelope-from tim@hoop.co.uk) Received: from noonoo (flav1.dircon.co.uk [194.112.47.31]) by ganesh.paneris.org (8.8.7/8.8.7) with SMTP id WAA00748; Fri, 19 Nov 1999 22:49:59 GMT Message-ID: <003f01bf32e1$42cee930$0501a8c0@noonoo> From: "Tim Joyce" To: "Tom Lane" , References: <3610.943049932@sss.pgh.pa.us> Subject: Re: [SQL] selecting from indexes Date: Fri, 19 Nov 1999 22:55:48 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 > "Tim Joyce" writes: > >>>> select id from books, book_words where book_words.word='happy' and > >>>> book_words.id = books.id and books.category_key=1471; > >> > >> If this is what you're really doing, I think what you actually want is > >> indexes on book_words.word and books.id. > > > I have indexes on both of these. > > Hmm. So the question is why the system is (apparently) doing an > indexscan on category_key rather than on id. You didn't show us > the EXPLAIN output... bloomsbury=> explain select id from books, books_title_words_idx t where t.word= 'happy' and t.rec_id = books.id and books.category_key=1471; NOTICE: QUERY PLAN: Hash Join (cost=43709.86 rows=2817 width=8) -> Index Scan using books_categories_idx on books (cost=32855.63 rows=293573 width=4) -> Hash (cost=733.03 rows=12221 width=4) -> Index Scan using books_title_words_idx_word on books_title_words_idx t (cost=733.03 rows=12221 width=4) EXPLAIN thanks again timj > > regards, tom lane