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 1jmO6d-0005U1-PQ for pgsql-performance@arkaria.postgresql.org; Fri, 19 Jun 2020 20:59:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jmO6c-00075r-LC for pgsql-performance@arkaria.postgresql.org; Fri, 19 Jun 2020 20:59:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmO6c-00075j-5M for pgsql-performance@lists.postgresql.org; Fri, 19 Jun 2020 20:59:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jmO6W-0007Wq-0m for pgsql-performance@lists.postgresql.org; Fri, 19 Jun 2020 20:59:21 +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 05JKxFsr1757513; Fri, 19 Jun 2020 16:59:15 -0400 From: Tom Lane To: Kenneth Marshall cc: pgsql-performance@lists.postgresql.org Subject: Re: PostgreSQL 12.3 slow index scan chosen In-reply-to: <20200619204950.GL1497@aart.rice.edu> References: <20200619194914.GI1497@aart.rice.edu> <1755412.1592597470@sss.pgh.pa.us> <20200619204950.GL1497@aart.rice.edu> Comments: In-reply-to Kenneth Marshall message dated "Fri, 19 Jun 2020 15:49:50 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1757511.1592600355.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 19 Jun 2020 16:59:15 -0400 Message-ID: <1757512.1592600355@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kenneth Marshall writes: > On Fri, Jun 19, 2020 at 04:11:10PM -0400, Tom Lane wrote: >> The reason for such an estimation error usually is that the maximum >> join key values recorded in pg_stats are off: the join side that is >> going to be exhausted is the one with the smaller max join key. >> "articles" seems to be small enough that the stats for it will be >> exact, so your problem is a poor estimate of the max value of >> objectcustomfieldvalues.objectid. You might try raising the statistics >> target for that table. Or maybe it's just that ANALYZE hasn't been >> done lately on one table or the other? > Thank you for the information and suggestion. I tried bumping the statis= tics for the > objectcustomfieldvalues.objectid column to 2k, 5k and 10k followed by an= analyze and > the query plan stayed the same. I also analyzed the article table > repeatedly and their was no change in the plan. The table articles only = has 151 rows > while the objectcustomfieldvalues table has 19031909 rows. Any idea > about why it is so far off? What's the actual maximum value of objectcustomfieldvalues.objectid, and how does that compare to the endpoint value in the pg_stats histogram for that column? If you've got one outlier in the table, it might get missed by ANALYZE. regards, tom lane