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 1jyy41-0006ed-VT for pgsql-general@arkaria.postgresql.org; Fri, 24 Jul 2020 13:48:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jyy40-0007qw-RQ for pgsql-general@arkaria.postgresql.org; Fri, 24 Jul 2020 13:48:40 +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 1jyy40-0007qi-JU for pgsql-general@lists.postgresql.org; Fri, 24 Jul 2020 13:48:40 +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 1jyy3y-0000Vd-Gc for pgsql-general@lists.postgresql.org; Fri, 24 Jul 2020 13:48:39 +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 06ODmaOK373969; Fri, 24 Jul 2020 09:48:36 -0400 From: Tom Lane To: David Rowley cc: Christophe Pettus , postgre Subject: Re: Row estimates for empty tables In-reply-to: References: Comments: In-reply-to David Rowley message dated "Fri, 24 Jul 2020 16:56:49 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <373967.1595598516.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 24 Jul 2020 09:48:36 -0400 Message-ID: <373968.1595598516@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Rowley writes: > On Fri, 24 Jul 2020 at 16:01, Christophe Pettus wrote= : >> I realize I've never quite known this; where does the planner get the r= ow estimates for an empty table? Example: > We just assume there are 10 pages if the relation has not yet been > vacuumed or analyzed. The row estimates you see are the number of > times 1 tuple is likely to fit onto a single page multiplied by the > assumed 10 pages. If you had made your table wider then the planner > would have assumed fewer rows Yeah. Also note that since we have no ANALYZE stats in this scenario, the row width estimate is going to be backed into via some guesses based on column data types. (It's fine for fixed-width types, much less fine for var-width.) There's certainly not a lot besides tradition to justify the exact numbers used in this case. However, we do have a good deal of practical experience to justify the principle of "never assume a table is empty, or even contains just one row, unless you're really sure of that". Otherwise you tend to end up with nestloop joins that will perform horrifically if you were wrong. The other join types are notably less brittle. regards, tom lane