Re: optimizer choosing the wrong index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martin Below <machtin(dot)below(at)googlemail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: optimizer choosing the wrong index
Date: 2010-07-07 14:20:05
Message-ID: 5911.1278512405@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martin Below <machtin(dot)below(at)googlemail(dot)com> writes:
> Why is "idx_wrong" used (which only includes one of the fields
> queried) instead of idx_correct (which contains both fields)?

It's not immediately clear that that choice is "wrong". A two-column
index is bigger and hence more expensive to search than a one-column
index --- perhaps quite substantially so, given this particular
combination of datatypes. The planner is probably estimating that
the expires_on condition is selective enough that nothing much will be
gained by using the two-column index. If that's wrong (which is not
proven by your example) you might be able to fix it by increasing
the stats target for the table. Also, if you haven't customized
effective_cache_size, increasing that makes large indexes look
cheaper to use.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2010-07-07 14:27:32 Re: make view with union return one record
Previous Message Vick Khera 2010-07-07 14:14:14 Re: Want to schedule tasks for the future