Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVg6G-0003LB-64 for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 14:27:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVg6F-0003RH-PD for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 14:27:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVg6E-0003Pv-8R for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 14:27:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVg6B-0004Oq-Oy for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 14:27:45 +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 u75ERfOG004175; Fri, 5 Aug 2016 10:27:41 -0400 From: Tom Lane To: Andrew Gierth cc: pgsql-hackers@postgresql.org, Andreas Joseph Krogh Subject: Re: Bogus ANALYZE results for an otherwise-unique column with many nulls In-reply-to: <87wpjvecwz.fsf@news-spur.riddles.org.uk> References: <16143.1470350371@sss.pgh.pa.us> <871t23fwgb.fsf@news-spur.riddles.org.uk> <87wpjvecwz.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Fri, 05 Aug 2016 11:29:42 +0100" Date: Fri, 05 Aug 2016 10:27:41 -0400 Message-ID: <4174.1470407261@sss.pgh.pa.us> X-Pg-Spam-Score: -3.1 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Andrew Gierth writes: > Hm. I am wrong about this, since it's the fact that consumers are taking > stanullfrac into account that makes the value wrong in the first place. Also, the way that the value is calculated in the samples-not-all-distinct case corresponds to the way I have it in the patch. What you want to do would correspond to leaving these edge cases alone and changing all the other ANALYZE cases instead (*plus* changing the consumers). I find that a tad scary. > But I think the fix is still wrong, because it changes the meaning of > ALTER TABLE ... ALTER col SET (n_distinct=...) in a non-useful way; it > is no longer possible to nail down a useful negative n_distinct value if > the null fraction of the column is variable. I think that argument is bogus. If we change the way that get_variable_numdistinct (and other consumers) use the value, that will break all existing custom settings of n_distinct, because they will no longer mean what they did before. There have been exactly zero field complaints that people could not get the results they wanted, so I do not think that's justified. In short, what you want to do constitutes a redefinition of stadistinct, while my patch doesn't. That is far more invasive and I fear it will break things that are not broken today. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers