Re: [SQL] selecting from indexes

From: "Tim Joyce" <tim(at)hoop(dot)co(dot)uk>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: [SQL] selecting from indexes
Date: 1999-11-19 22:55:48
Message-ID: 003f01bf32e1$42cee930$0501a8c0@noonoo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> "Tim Joyce" <tim(at)hoop(dot)co(dot)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=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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Matthew Hagerty 1999-11-20 01:03:57 Deleting indexes before vacuum?
Previous Message Tom Lane 1999-11-19 22:18:52 Re: [SQL] selecting from indexes