pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Christophe Pettus <xof@thebuild.com>
Cc: postgre <pgsql-general@lists.postgresql.org>
Subject: Re: Row estimates for empty tables
Date: Fri, 24 Jul 2020 09:48:36 -0400
Message-ID: <373968.1595598516@sss.pgh.pa.us> (raw)
In-Reply-To: <CAApHDvrC8crSPSxQnEJ8W+mVDZAiaQyT0PryHbmW8RnoSbQmbg@mail.gmail.com>
References: <F02298E0-6EF4-49A1-BCB6-C484794D9ACC@thebuild.com>
	<CAApHDvrC8crSPSxQnEJ8W+mVDZAiaQyT0PryHbmW8RnoSbQmbg@mail.gmail.com>

David Rowley <dgrowleyml@gmail.com> writes:
> On Fri, 24 Jul 2020 at 16:01, Christophe Pettus <xof@thebuild.com> wrote:
>> I realize I've never quite known this; where does the planner get the row 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





view thread (11+ messages)  latest in thread

Message-ID: <373968.1595598516@sss.pgh.pa.us>
Permalink:  ../373968.1595598516@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/373968.1595598516@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dgrowleyml@gmail.com, xof@thebuild.com
  Subject: Re: Row estimates for empty tables
  In-Reply-To: <373968.1595598516@sss.pgh.pa.us>
  References: <F02298E0-6EF4-49A1-BCB6-C484794D9ACC@thebuild.com> <CAApHDvrC8crSPSxQnEJ8W+mVDZAiaQyT0PryHbmW8RnoSbQmbg@mail.gmail.com> <373968.1595598516@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox