Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id EE0EB1AE2382 for ; Wed, 23 Nov 2011 23:06:23 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RTPdn-0007D6-RF for pgsql-performance@postgresql.org; Thu, 24 Nov 2011 03:06:24 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id pAO36AWn010513; Wed, 23 Nov 2011 22:06:10 -0500 (EST) To: Gary Warner cc: pgsql-performance@postgresql.org Subject: Re: Seq Scan used instead of Index Scan In-reply-to: <1930791595.3607.1322087076188.JavaMail.root@zimbra.cis.uab.edu> References: <1930791595.3607.1322087076188.JavaMail.root@zimbra.cis.uab.edu> Comments: In-reply-to Gary Warner message dated "Wed, 23 Nov 2011 16:24:36 -0600" Date: Wed, 23 Nov 2011 22:06:10 -0500 Message-ID: <10512.1322103970@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 201111/262 X-Sequence-Number: 45773 Gary Warner 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