pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gary Warner <gar@cis.uab.edu>
Cc: pgsql-performance@postgresql.org
Subject: Re: Seq Scan used instead of Index Scan
Date: Wed, 23 Nov 2011 22:06:10 -0500
Message-ID: <10512.1322103970@sss.pgh.pa.us> (raw)
In-Reply-To: <1930791595.3607.1322087076188.JavaMail.root@zimbra.cis.uab.edu>
References: <1930791595.3607.1322087076188.JavaMail.root@zimbra.cis.uab.edu>

Gary Warner <gar@cis.uab.edu> writes:
> Recently my database stopped respecting one of my indexes, which took a query that should run in "subsecond response time" and turning it into something that with small data sets runs in the 7-10 minute range and with large data sets runs in the 30 minute - eternity range.

> Explain Analyze tells me that what used to be an Index Scan has become a Seq Scan, doing a full table scan through 140 million records.

> Any thoughts on why that happens?

I'd bet it has a lot to do with the nigh-three-orders-of-magnitude
overestimates of the numbers of matching rows.  You might find that
increasing the statistics targets for the indexed columns helps ---
I'm guessing that these particular key values are out in the long
tail of a highly skewed distribution, and the planner needs a larger MCV
list to convince it that non-MCV values will not occur very many times.

If that is an accurate guess, then trying to force the matter with
something like enable_seqscan = off is not a good production solution,
because it will result in horrid plans whenever you decide to query
a not-so-infrequent value.

			regards, tom lane



view thread (4+ messages)

Message-ID: <10512.1322103970@sss.pgh.pa.us>
Permalink:  ../10512.1322103970@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/10512.1322103970@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, gar@cis.uab.edu
  Subject: Re: Seq Scan used instead of Index Scan
  In-Reply-To: <10512.1322103970@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox