Re: Query plan not using index for some reason. - Mailing list pgsql-general

From Jean-Christian Imbeault
Subject Re: Query plan not using index for some reason.
Date
Msg-id 3D99DDFD.1030703@mega-bucks.co.jp
Whole thread Raw
In response to Query plan not using index for some reason.  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: Query plan not using index for some reason.
Next
From: "Johnson, Shaunn"
Date:
Subject: execute transaction / insert rows