Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ixCnT-00030M-T9 for pgsql-performance@arkaria.postgresql.org; Thu, 30 Jan 2020 16:36:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ixCnS-0001nL-G9 for pgsql-performance@arkaria.postgresql.org; Thu, 30 Jan 2020 16:36:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ixCnS-0001nE-7f for pgsql-performance@lists.postgresql.org; Thu, 30 Jan 2020 16:36:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ixCnL-0005jQ-El for pgsql-performance@lists.postgresql.org; Thu, 30 Jan 2020 16:36:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 00UGZovu022540; Thu, 30 Jan 2020 11:35:51 -0500 From: Tom Lane To: Duncan Whitham cc: Fahiz Mohamed , Jeff Janes , Michael Lewis , Pgsql Performance Subject: Re: Specific query taking time to process In-reply-to: References: <6bd9b9b7-f127-4e48-a456-b3bbcfb741ab@Spark> <10b65cf1-a079-4aa3-92f0-ca21375da683@Spark> <7cb455c5-dd6a-4f33-bdbe-92033f7986e2@Spark> <53622ec9-bf97-4066-ac52-9b8e5698c3ea@Spark> Comments: In-reply-to Duncan Whitham message dated "Thu, 30 Jan 2020 12:22:58 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <22538.1580402150.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 30 Jan 2020 11:35:50 -0500 Message-ID: <22539.1580402150@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Duncan Whitham writes: > We now only need 1 environment as we can replicate the performance prob= lem > on a copy of live =E2=80=93 snapshot/restore from AWS of live. We now ha= ve a vacuum > analyse running every night on the 3 tables in question on live =E2=80=93= to > eliminate bloat and inaccurate stats as the root of the problem. Hmm, doesn't seem like that's getting the job done. I can see at least one serious misestimate in these plans: > -> Bitmap Heap Scan on alf_node_aspects aspect_1 > (cost=3D3420.59..418372.63 rows=3D163099 width=3D8) (actual time=3D1.402= ..5.243 > rows=3D4909 loops=3D1) > Recheck Cond: (qname_id =3D 251) It doesn't seem to me that such a simple condition ought to be misestimated by a factor of 30, so either you need to crank up the stats target for this column or you need to analyze the table more often. The other rowcount estimates don't seem so awful, but this one is contributing to the planner thinking that "SubPlan 1" is going to be very expensive, which probably accounts for it trying to avoid what's actually a cheap plan. regards, tom lane