Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVcNx-0001Pm-WB for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 10:29:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVcNx-00072n-EE for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 10:29:49 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVcNw-00070u-Mq for pgsql-hackers@postgreSQL.org; Fri, 05 Aug 2016 10:29:48 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bVcNt-0008K3-QH for pgsql-hackers@postgreSQL.org; Fri, 05 Aug 2016 10:29:47 +0000 Received: from localhost ([127.0.0.1]:39522 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.84 (FreeBSD)) (envelope-from ) id 1bVcNq-0006uM-Jt; Fri, 05 Aug 2016 10:29:42 +0000 From: Andrew Gierth To: Tom Lane Cc: pgsql-hackers@postgreSQL.org, Andreas Joseph Krogh Subject: Re: Bogus ANALYZE results for an otherwise-unique column with many nulls In-Reply-To: <871t23fwgb.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Fri, 05 Aug 2016 09:42:03 +0100") Message-ID: <87wpjvecwz.fsf@news-spur.riddles.org.uk> References: <16143.1470350371@sss.pgh.pa.us> <871t23fwgb.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) Date: Fri, 05 Aug 2016 11:29:42 +0100 MIME-Version: 1.0 Content-Type: text/plain 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" == Andrew Gierth writes: >>>>> "Tom" == Tom Lane writes: Tom> What I did in the patch is to scale the formerly fixed "-1.0" Tom> stadistinct estimate to discount the fraction of nulls we found. Andrew> This seems quite dubious to me. stadistinct representing only Andrew> the non-null values seems to me to be substantially more useful Andrew> and less confusing; it should be up to consumers to take Andrew> stanullfrac into account (in general they already do) since in Andrew> many cases we explicitly do _not_ want to count nulls. 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. For example, if a million-row table has stanullfrac=0.9 and stadistinct=-1, then get_variable_numdistinct is returning 1 million, and (for example) var_eq_non_const divides 0.1 by that to give a selectivity of 1 in 10 million, which is obviously wrong. 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. Would it not make more sense to do the adjustment in get_variable_numdistinct, instead? -- Andrew (irc:RhodiumToad) -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers