Re: Query plan not using index for some reason.

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query plan not using index for some reason.
Date: 2002-10-01 16:25:39
Message-ID: 20021001091756.B94756-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2 Oct 2002, Jean-Christian Imbeault wrote:

> One of my SQL is is slow so I tried using EXPLAIN to find out why but
> the query plan is gives seems bad ... it's not using indexes ...
>
> The query is on two tables, both of which have indexes. When I check
> EXPLAIN for the query without the OR clause the planner uses the index.
> When I add the OR clause it uses a seq scan ...
>
> Is the planner right in choosing a seq scan?

Given it wants to use one index in a scan, probably, since I don't think
either of those indexes will help that full condition if I'm guessing the
schema correctly. I can't see an index on id helping when you also
need to get all the maker_id=53 rows and the one on maker_id doesn't
seem like it'd help the joining of the tables on id.

Hmm, maybe
select products.id as pid from products where maker_id='53'
union
select products.id as pid from products, rel_genres_movies where
(rel_genres_movies.minor_id='11' AND rel_genres_movies.prod_id=products.id)"
would run better (or union all if it's safe to have duplicates).

An index on id doesn't help since you also need to get
all the rows where maker_id is 53 and one on maker_id doesn't help join
ids.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2002-10-01 16:53:03 Re: string parsing
Previous Message Jean-Christian Imbeault 2002-10-01 15:56:10 Query plan not using index for some reason.