Re: Row estimates for empty tables

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Christophe Pettus <xof(at)thebuild(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>
Subject: Re: Row estimates for empty tables
Date: 2020-08-23 21:08:16
Message-ID: 2476864.1598216896@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> I am sending a patch that is years used in GoodData.

I'm quite unexcited about that. I'd be the first to agree that the
ten-pages estimate is a hack, but it's not an improvement to ask users
to think of a better value ... especially not as a one-size-fits-
all-relations GUC setting.

I did have an idea that I think is better than my previous one:
rather than lying about the value of relpages, let's represent the
case where we don't know the tuple density by setting reltuples = -1
initially. This leads to a patch that's a good bit more invasive than
the quick-hack solution, but I think it's a lot cleaner on the whole.

A possible objection is that this changes the FDW API slightly, as
GetForeignRelSize callbacks now need to deal with rel->tuples possibly
being -1. We could avoid an API break if we made plancat.c clamp
that value to zero; but then FDWs still couldn't tell the difference
between the "empty" and "never analyzed" cases, and I think this is
just as much of an issue for them as for the core code.

I'll add this to the upcoming CF.

regards, tom lane

Attachment Content-Type Size
use-minus-one-for-unknown-reltuples-1.patch text/x-diff 19.5 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message harish supare 2020-08-24 10:06:06 Substitute Variable in select query
Previous Message Paul Förster 2020-08-23 15:03:35 Re: has_database_privilege is true?

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2020-08-24 02:18:33 Re: proposal - function string_to_table
Previous Message Andrey M. Borodin 2020-08-23 09:39:38 Re: Yet another fast GiST build (typo)