Re: Query plan not using index for some reason.

Поиск
Список
Период
Сортировка
От Jean-Christian Imbeault
Тема Re: Query plan not using index for some reason.
Дата
Msg-id 3D99DDFD.1030703@mega-bucks.co.jp
обсуждение исходный текст
Ответ на Query plan not using index for some reason.  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
Список pgsql-general
Tom Lane wrote:
>
>>$ psql TMP -c "explain select products.id as pid from
>>products,rel_genres_movies where maker_id='53' OR
>>(rel_genres_movies.minor_id='11' AND rel_genres_movies.prod_id=products.id)"
>
>
> Is that *really* the query you want to run?
>
> Rows having maker_id=53 will be joined to *every* row of the other
> table.  I'm suspecting you really wanted
>     where (maker_id='53' OR rel_genres_movies.minor_id='11') AND
>           rel_genres_movies.prod_id=products.id
> so that the join behaves sensibly.

As you can see my SQL ability is poor ... you are of course absolutely
right ...

Which query would be most efficient, the one you gave or

select id from products where maker_id='53' UNION select prod_id from
rel_genres_movies where minor_id='11'

I think they are both equivalent but I am wondering which is most
efficient ...

Jc


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Query plan not using index for some reason.
Следующее
От: "Johnson, Shaunn"
Дата:
Сообщение: execute transaction / insert rows