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 1oiGHg-00059U-IW for pgsql-general@arkaria.postgresql.org; Tue, 11 Oct 2022 14:31:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oiGHe-0008Sq-82 for pgsql-general@arkaria.postgresql.org; Tue, 11 Oct 2022 14:31:02 +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 1oiGHd-0008Sf-TY for pgsql-general@lists.postgresql.org; Tue, 11 Oct 2022 14:31:01 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiGHb-00028R-Fm for pgsql-general@lists.postgresql.org; Tue, 11 Oct 2022 14:31:01 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1oiGHV-000My1-Uw; Tue, 11 Oct 2022 10:30:53 -0400 Date: Tue, 11 Oct 2022 10:30:53 -0400 From: Bruce Momjian To: Tom Lane Cc: David Rowley , gzh , pgsql-general@lists.postgresql.org Subject: Re: Different execution plan between PostgreSQL 8.4 and 12.11 Message-ID: References: <23fe7e4b.5866.183bc03584f.Coremail.gzhcoder@126.com> <3810464.1665331329@sss.pgh.pa.us> <3bb0d13f.1d81.183bfbcf7e4.Coremail.gzhcoder@126.com> <3977622.1665369954@sss.pgh.pa.us> <5cac5c06.25be.183c507f02f.Coremail.gzhcoder@126.com> <299199.1665496783@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <299199.1665496783@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Oct 11, 2022 at 09:59:43AM -0400, Tom Lane wrote: > David Rowley writes: > > It feels like something is a bit lacking in our cost model here. I'm > > just not sure what that is. > > The example you show is the same old problem that we've understood for > decades: for cost-estimation purposes, we assume that matching rows > are more or less evenly distributed in the table. Their actual > location doesn't matter that much if you're scanning the whole table; > but if you're hoping that a LIMIT will be able to stop after scanning > just a few rows, it does matter. We do have a correlation statistics value for each column but I am unclear if that would help here. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Indecision is a decision. Inaction is an action. Mark Batterson