Re: [SQL] selecting from indexes - Mailing list pgsql-sql

From Tim Joyce
Subject Re: [SQL] selecting from indexes
Date
Msg-id 003f01bf32e1$42cee930$0501a8c0@noonoo
Whole thread Raw
In response to Re: [SQL] selecting from indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql

> "Tim Joyce" <tim@hoop.co.uk> 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=293573width=4) ->  Hash  (cost=733.03 rows=12221 width=4)       ->  Index Scan using books_title_words_idx_word
on
books_title_words_idxt  (cost=733.03 rows=12221 width=4)

EXPLAIN

thanks again

timj
>
> regards, tom lane



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] selecting from indexes
Next
From: Matthew Hagerty
Date:
Subject: Deleting indexes before vacuum?