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 1jnSIG-00037g-EK for pgsql-performance@arkaria.postgresql.org; Mon, 22 Jun 2020 19:39:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnSIF-0006Ip-5T for pgsql-performance@arkaria.postgresql.org; Mon, 22 Jun 2020 19:39:47 +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 1jnSIE-0006Ih-UQ for pgsql-performance@lists.postgresql.org; Mon, 22 Jun 2020 19:39:46 +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 1jnSIC-0007Uy-Qe for pgsql-performance@lists.postgresql.org; Mon, 22 Jun 2020 19:39:46 +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 05MJdg2H2087062; Mon, 22 Jun 2020 15:39:42 -0400 From: Tom Lane To: Alvaro Herrera cc: Kenneth Marshall , pgsql-performance@lists.postgresql.org Subject: Re: PostgreSQL 12.3 slow index scan chosen In-reply-to: <20200622192732.GA29072@alvherre.pgsql> References: <20200622192732.GA29072@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Mon, 22 Jun 2020 15:27:32 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2087060.1592854782.1@sss.pgh.pa.us> Date: Mon, 22 Jun 2020 15:39:42 -0400 Message-ID: <2087061.1592854782@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2020-Jun-20, Tom Lane wrote: >> You said you'd increased the stats target for >> objectcustomfieldvalues.objectid, but maybe the real problem is needing >> to increase the targets for content and largecontent, in hopes of driving >> down the estimate for how many rows will pass this filter condition. > ... but those on content and largecontent are unanchored conditions -- > are we still able to do any cardinality analysis using those? Yes, if the stats histogram is large enough we'll apply it by just evaluating the query operator verbatim on each entry (thereby assuming that the histogram is usable as a random sample). And we apply the query condition on each MCV entry too (no assumptions needed there). The unanchored LIKE conditions could not be used as btree indexquals, but that has little to do with selectivity estimation. Since we bound those things at 10K entries, the histogram alone can't give better than 0.01% estimation precision, which in itself wouldn't have done the job for the OP -- he needed a couple more places of accuracy than that. I surmise that he had a nontrivial MCV population as well, since he found that raising the stats target did eventually drive down the estimate far enough to fix the problem. regards, tom lane