Skip site navigation (1) Skip section navigation (2)

Re: Index called with Union but not with OR clause

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: V Chitra <vchitra(at)techbooks(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org, pgsql-performance(at)postgresql(dot)org
Subject: Re: Index called with Union but not with OR clause
Date: 2004-02-20 20:11:39
Message-ID: 20040220201139.GA25578@wolff.to (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-performance
This discussion really belongs on the performance list and I am copying
that list with mail-followup-to set.

On Fri, Feb 20, 2004 at 12:26:22 +0530,
  V Chitra <vchitra(at)techbooks(dot)com> wrote:
> Hi All,
> 
> I have a select statement 
> 
> select * from v_func_actual_costs
> where parent_project='10478' or proj_pk = '10478'
> 
> both the fields parent_project and proj_pk have indexes based on them, but when I ran explain plan on this statement I found that none of the indexes are being called. But, if I make two separate statement and combine them with Union ALL, the indexes are being called. The select statement in this case is
> 
> select * from ct_admin.v_func_actual_costs
> where parent_project='10478'
> union all
> select * from ct_admin.v_func_actual_costs
> where proj_pk = '10478' 
> 
> Can anybody help me to find a reason for the same. This is just a part of the query so I cannot use the Union ALL clause.

Have you analyzed the databases recently?

Can you supply explain analyze output for the queries?

It isn't necessarily faster to use two index scans instead of one sequential
scan depending on the fraction of the table being returned and some other
factors. If the planner is making the wrong choice in your case, you need
to supply the list with more information to get help figuring out why
the wrong choice is being made.

In response to

pgsql-performance by date

Next:From: scott.marloweDate: 2004-02-20 21:10:07
Subject: Re: General performance questions about postgres on Apple
Previous:From: Sean ShannyDate: 2004-02-20 19:17:10
Subject: General performance questions about postgres on Apple hardware...

pgsql-admin by date

Next:From: Mitch PirtleDate: 2004-02-20 20:24:28
Subject: Re: PosgreSQL hogging resources?
Previous:From: Jeremy SmithDate: 2004-02-20 20:05:07
Subject: Re: "DELETE FROM" protection

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group