Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgtMR-0006cZ-Lq for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 17:08:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgtMP-0006TU-Nd for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 17:08:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgtMP-0006TJ-Fy for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 17:08:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgtMI-0007Vf-QQ for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 17:08:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 054H8jGg1251998; Thu, 4 Jun 2020 13:08:45 -0400 From: Tom Lane To: Adrian Klaver cc: Koen De Groote , pgsql-general@lists.postgresql.org Subject: Re: Index no longer being used, destroying and recreating it restores use. In-reply-to: References: <1251078.1591289012@sss.pgh.pa.us> Comments: In-reply-to Adrian Klaver message dated "Thu, 04 Jun 2020 09:48:28 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1251996.1591290525.1@sss.pgh.pa.us> Date: Thu, 04 Jun 2020 13:08:45 -0400 Message-ID: <1251997.1591290525@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > On 6/4/20 9:43 AM, Tom Lane wrote: >> It's possible that the index had bloated to the point where the planner >> thought it was cheaper to use a seqscan. Did you make a note of the >> cost estimates for the different plans? > I missed the part where the OP pointed to a SO question. In that > question where links to explain.depesz.com output. Ah, I didn't bother to chase that link either. So the cost estimates are only a fraction of a percent apart, making it unsurprising for not-so-large changes in the index size to cause a flip in the apparently-cheapest plan. The real question then is why the cost estimates aren't actually modeling the real execution times very well; and I'd venture that that question boils down to why is this rowcount estimate so far off: > -> Parallel Seq Scan on oscar mike_three > (cost=0.000..1934568.500 rows=2385585 width=3141) (actual > time=159.800..158018.961 rows=23586 loops=3) > Filter: (four AND (NOT bravo) AND (zulu <= > 'echo'::timestamp without time zone)) > Rows Removed by Filter: 8610174 We're not going to be able to answer that if the OP doesn't wish to decloak his data a bit more ... but a reasonable guess is that those filter conditions are correlated. With late-model Postgres you might be able to improve matters by creating extended statistics for this table. regards, tom lane