Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQaMO-0001tB-F8 for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jun 2018 15:28:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQaMM-0002V5-3j for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jun 2018 15:28:26 +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.89) (envelope-from ) id 1fQaML-0002Uv-Q9 for pgsql-bugs@lists.postgresql.org; Wed, 06 Jun 2018 15:28:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQaMJ-0007JC-47 for pgsql-bugs@postgresql.org; Wed, 06 Jun 2018 15:28:24 +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 w56FSDua009102; Wed, 6 Jun 2018 11:28:13 -0400 From: Tom Lane To: Andreas Seltenreich cc: pgsql-bugs@postgresql.org Subject: Re: Unnecessarily imprecise stats for very small tables leading to bad plans In-reply-to: <87o9gos42e.fsf@credativ.de> References: <87o9gos42e.fsf@credativ.de> Comments: In-reply-to Andreas Seltenreich message dated "Wed, 06 Jun 2018 10:38:01 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9100.1528298893.1@sss.pgh.pa.us> Date: Wed, 06 Jun 2018 11:28:13 -0400 Message-ID: <9101.1528298893@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andreas Seltenreich writes: > Intuitively, I'd say pg_statistic can represent such a small dataset > perfectly. But instead, most_common_values only contains one of the two > distinct values. This seems like a bug to me. I looked at the code for > why this is the case, but couldn't find an answer right-away. Any > input? ANALYZE has a hard-and-fast rule that a value must appear more than once in the sample in order to possibly be considered an MCV. Perhaps we could tinker with that if the sample is known to comprise the entire table, but it feels a bit ad-hoc. regards, tom lane