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 1hbodp-0000oT-0p for pgsql-docs@arkaria.postgresql.org; Fri, 14 Jun 2019 16:01:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hbodk-0005wy-4u for pgsql-docs@arkaria.postgresql.org; Fri, 14 Jun 2019 16:01:20 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbodj-0005wr-Tj for pgsql-docs@lists.postgresql.org; Fri, 14 Jun 2019 16:01:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hbodd-0003Ou-4H for pgsql-docs@lists.postgresql.org; Fri, 14 Jun 2019 16:01:19 +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 x5EG16mr029902; Fri, 14 Jun 2019 12:01:07 -0400 From: Tom Lane To: theolassonder@hotmail.com cc: pgsql-docs@lists.postgresql.org Subject: Re: Mistake in documentation for CREATE STATISTICS In-reply-to: <156041783045.1348.6661129085836800862@wrigleys.postgresql.org> References: <156041783045.1348.6661129085836800862@wrigleys.postgresql.org> Comments: In-reply-to PG Doc comments form message dated "Thu, 13 Jun 2019 09:23:50 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29900.1560528066.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 14 Jun 2019 12:01:06 -0400 Message-ID: <29901.1560528066@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Doc comments form writes: > The example on https://www.postgresql.org/docs/11/sql-createstatistics.h= tml > seems wrong: instead of "EXPLAIN ANALYZE SELECT ..." it should say "EXPL= AIN > SELECT ...". If changed that way, the query optimizer estimates the numb= er > of rows at 1 and then 100 after statistics are created which is indeed h= ow > many the query returns. In the current wording, with ANALYZE, the query > optimizer estimates the number of rows at 100 for both the first and sec= ond > select. I think you're mistaking actual rows for estimated rows in the output of EXPLAIN ANALYZE. The point of using EXPLAIN ANALYZE here is just to make it easier to see that the estimate is indeed wrong, by providing the actual count alongside the estimate. I don't think that taking out ANALYZE would be an improvement. For instance, in the first EXPLAIN I get Gather (cost=3D1000.00..11675.10 rows=3D1 width=3D8) (actual time=3D1.21= 5..45.218 rows =3D100 loops=3D1) which without ANALYZE would just be Gather (cost=3D1000.00..11675.10 rows=3D1 width=3D8) The rows=3D1 estimate is equally wrong either way, but you don't get to see the correct value without ANALYZE. regards, tom lane