pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Christophe Pettus <xof@thebuild.com>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: postgre <pgsql-general@lists.postgresql.org>
Subject: Re: Row estimates for empty tables
Date: Fri, 24 Jul 2020 17:09:33 -0400
Message-ID: <578094.1595624973@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFj8pRBfm4-J-fULxn3H8=4n39P9D8csgRh3PDptUYa9YKZZDA@mail.gmail.com>
References: <F02298E0-6EF4-49A1-BCB6-C484794D9ACC@thebuild.com>
	<CAApHDvrC8crSPSxQnEJ8W+mVDZAiaQyT0PryHbmW8RnoSbQmbg@mail.gmail.com>
	<373968.1595598516@sss.pgh.pa.us>
	<A2D82246-2556-4BBB-8C44-7F729CC02317@thebuild.com>
	<CAFj8pRBfm4-J-fULxn3H8=4n39P9D8csgRh3PDptUYa9YKZZDA@mail.gmail.com>

Pavel Stehule <pavel.stehule@gmail.com> writes:
> pá 24. 7. 2020 v 16:38 odesílatel Christophe Pettus <xof@thebuild.com>
> napsal:
>> Since we already special-case parent tables for partition sets, would a
>> storage parameter that lets you either tell the planner "no, really, zero
>> is reasonable here" or sets a minimum number of rows to plan for be
>> reasonable?

> It is an issue for special, not typical applications (this situation is
> typical for some OLAP patterns)  - it is not too often - but some clean
> solution (instead hacking postgres) can be nice.

The core issue here is "how do we know whether the table is likely to stay
empty?".  I can think of a couple of more or less klugy solutions:

1. Arrange to send out a relcache inval when adding the first page to
a table, and then remove the planner hack for disbelieving relpages = 0.
I fear this'd be a mess from a system structural standpoint, but it might
work fairly transparently.

2. Establish the convention that vacuuming or analyzing an empty table
is what you do to tell the system that this state is going to persist.
That's more or less what the existing comments in plancat.c envision,
but we never made a definition for how the occurrence of that event
would be recorded in the catalogs, other than setting relpages > 0.
Rather than adding another pg_class column, I'm tempted to say that
vacuum/analyze should set relpages to a minimum of 1, even if the
relation has zero pages.  That does get the job done:

regression=# create table foo(f1 text);
CREATE TABLE
regression=# explain select * from foo;
                       QUERY PLAN                       
--------------------------------------------------------
 Seq Scan on foo  (cost=0.00..23.60 rows=1360 width=32)
(1 row)

regression=# vacuum foo;  -- doesn't help
VACUUM
regression=# explain select * from foo;
                       QUERY PLAN                       
--------------------------------------------------------
 Seq Scan on foo  (cost=0.00..23.60 rows=1360 width=32)
(1 row)
regression=# update pg_class set relpages = 1 where relname = 'foo';
UPDATE 1
regression=# explain select * from foo;
                     QUERY PLAN                     
----------------------------------------------------
 Seq Scan on foo  (cost=0.00..0.00 rows=1 width=32)
(1 row)

(We're still estimating one row, but that's as a result of different
decisions that I'm not nearly as willing to compromise on...)

			regards, tom lane





view thread (11+ messages)  latest in thread

Message-ID: <578094.1595624973@sss.pgh.pa.us>
Permalink:  ../578094.1595624973@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/578094.1595624973@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, pavel.stehule@gmail.com, xof@thebuild.com, dgrowleyml@gmail.com
  Subject: Re: Row estimates for empty tables
  In-Reply-To: <578094.1595624973@sss.pgh.pa.us>
  References: <F02298E0-6EF4-49A1-BCB6-C484794D9ACC@thebuild.com> <CAApHDvrC8crSPSxQnEJ8W+mVDZAiaQyT0PryHbmW8RnoSbQmbg@mail.gmail.com> <373968.1595598516@sss.pgh.pa.us> <A2D82246-2556-4BBB-8C44-7F729CC02317@thebuild.com> <CAFj8pRBfm4-J-fULxn3H8=4n39P9D8csgRh3PDptUYa9YKZZDA@mail.gmail.com> <578094.1595624973@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