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 1gel7C-00032n-FB for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jan 2019 18:19:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gel7A-0004Ql-FU for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jan 2019 18:19:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gel7A-0004P9-57; Wed, 02 Jan 2019 18:19:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gel73-0001SD-BQ; Wed, 02 Jan 2019 18:19:34 +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 x02IJP4a007364; Wed, 2 Jan 2019 13:19:25 -0500 From: Tom Lane To: Mark cc: Jeff Janes , pgsql-general@lists.postgresql.org, pgsql-hackers@lists.postgresql.org Subject: Re: Query planner / Analyse statistics bad estimate rows=1 with maximum statistics 10000 on PostgreSQL 10.2 In-reply-to: References: <2025.1546445499@sss.pgh.pa.us> Comments: In-reply-to Mark message dated "Wed, 02 Jan 2019 18:04:19 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7362.1546453165.1@sss.pgh.pa.us> Date: Wed, 02 Jan 2019 13:19:25 -0500 Message-ID: <7363.1546453165@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mark writes: > Am I correct in my understanding that any row that has been modified (i.e. > UPDATE) is in state HEAPTUPLE_INSERT_IN_PROGRESS so it will not be included > in the sample? An update will mark the existing tuple as delete-in-progress and then insert a new tuple (row version) that's insert-in-progress. A concurrent ANALYZE scan will definitely see the old tuple (modulo sampling considerations) but it's timing-dependent which state it sees it in --- it could still be "live" when we see it, or already delete-in-progress. ANALYZE might or might not see the new tuple at all, depending on timing and where the new tuple gets placed. So "count/sample delete-in-progress but not insert-in-progress" seems like a good rule to minimize the timing sensitivity of the results. It's not completely bulletproof, but I think it's better than what we're doing now. > I'm going to rework the application so there is less time between the > DELETE and the COMMIT so I will only see the problem if ANALYZE runs during > this smaller time window. Yeah, that's about the best you can do from the application side. regards, tom lane