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 1m81bs-0004Fd-U2 for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Jul 2021 14:29:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m81br-0004lu-Rr for pgsql-bugs@arkaria.postgresql.org; Mon, 26 Jul 2021 14:29:35 +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 1m81br-0004lk-LZ for pgsql-bugs@lists.postgresql.org; Mon, 26 Jul 2021 14:29:35 +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 1m81bp-0001IX-Mz for pgsql-bugs@lists.postgresql.org; Mon, 26 Jul 2021 14:29:34 +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 16QETOZQ086587; Mon, 26 Jul 2021 10:29:24 -0400 From: Tom Lane To: christoph.berg@credativ.de cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17123: ALTER TABLE ... NO INHERIT leaves orphaned statistics behind In-reply-to: <17123-734abc3934f500b6@postgresql.org> References: <17123-734abc3934f500b6@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 26 Jul 2021 12:54:22 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <86585.1627309764.1@sss.pgh.pa.us> Date: Mon, 26 Jul 2021 10:29:24 -0400 Message-ID: <86586.1627309764@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Removing the last/only inheritance child from a table using ALTER TABLE NO > INHERIT leaves orphaned statistics behind that ANALYZE doesn't remove. > Original customer complaint on 10.16, but 15devel has the same issue. Good catch. I imagine DETACH PARTITION has related issues? It seems like there are basically two ways to fix this: 1. Make ALTER TABLE NO INHERIT/DETACH PARTITION get rid of no-longer-wanted stats. 2. Make ANALYZE check for and remove any inappropriate stats. I'm kind of inclined to prefer #1, on the grounds that #2 would add almost-always-useless cycles to every ANALYZE run forevermore. On the other hand, #2 seems a bit more robust, in that we'd not have to remember to consider this issue every time somebody invents a new flavor of DDL that affects these things. Thoughts? regards, tom lane