Re: tableam: abstracting relation sizing code

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: tableam: abstracting relation sizing code
Date: 2019-06-10 19:35:18
Message-ID: CA+TgmoapT1EU7=54Nh8cWhGtyTnm_Ksapvtp5sUVXje32mvrcA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 7, 2019 at 6:42 PM Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
> > Good catch, and now I notice that the callback is not called
> > estimate_rel_size but relation_estimate_size. Updated patch attached;
> > thanks for the review.
>
> The commit message still refers to it as estimate_rel_size though. The comment on
> table_block_relation_estimate_size does too but that one might be intentional.

Oops. New version attached, hopefully fixing those and the compiler
warning Alvaro noted.

> During re-review, the below part stood out as a bit odd however:
>
> + if (curpages < 10 &&
> + relpages == 0 &&
> + !rel->rd_rel->relhassubclass)
> + curpages = 10;
> +
> + /* report estimated # pages */
> + *pages = curpages;
> + /* quick exit if rel is clearly empty */
> + if (curpages == 0)
> + {
> + *tuples = 0;
> + *allvisfrac = 0;
> + return;
> + }
>
> While I know this codepath isn’t introduced by this patch (it was introduced in
> 696d78469f3), I hadn’t seen it before so sorry for thread-jacking slightly.
>
> Maybe I’m a bit thick but if the rel is totally empty and without children,
> then curpages as well as relpages would be both zero. But if so, how can we
> enter the second "quick exit” block since curpages by then will be increased to
> 10 in the block just before for the empty case? It seems to me that the blocks
> should be the other way around to really have a fast path, but I might be
> missing something.

Well, as you say, I'm just moving the code. However, note that
curpages is the size of the relation RIGHT NOW whereas relpages is the
size the last time the relation was analyzed. So I guess the case
you're wondering about would happen if the relation were analyzed and
then truncated. It seems there are lots of things that could be done
here in the hopes of improving things, like keeping track in pg_class
of whether analyze has ever happened rather than using relpages == 0
as a bad approximation, but I'd rather not drift further OT, so if
you're in the mood to talk about that stuff, I would appreciate it if
you could start a new thread.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment Content-Type Size
v3-0001-tableam-Provide-helper-functions-for-relation-siz.patch application/octet-stream 14.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2019-06-10 19:46:48 Re: tableam: abstracting relation sizing code
Previous Message Alexander Korotkov 2019-06-10 18:28:12 Hash join explain is broken