Re: tableam: abstracting relation sizing code

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Daniel Gustafsson <daniel(at)yesql(dot)se>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: tableam: abstracting relation sizing code
Date: 2019-06-11 13:17:25
Message-ID: CA+Tgmob36b4rznk3NEeh_GV=bGyW6Y6DhGD=D_Bwwa=7pQCkMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jun 10, 2019 at 3:46 PM Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> I agree that you're just moving the code, but this seems to have been
> recently broken in 696d78469f37 -- it was correct before that (the
> heuristic for never vacuumed rels was in optimizer/plancat.c). So in
> reality the problem that Daniel pointed out is an open item for pg12.

I took a look at this but I don't see that Andres did anything in that
commit other than move code. In the new code,
heapam_estimate_rel_size() does this:

+ 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;
+ }

And here's what the code in estimate_rel_size looked like before the
commit you mention:

if (curpages < 10 &&
rel->rd_rel->relpages == 0 &&
!rel->rd_rel->relhassubclass &&
rel->rd_rel->relkind != RELKIND_INDEX)
curpages = 10;

/* report estimated # pages */
*pages = curpages;
/* quick exit if rel is clearly empty */
if (curpages == 0)
{
*tuples = 0;
*allvisfrac = 0;
break;
}

It's all the same, except that now that the test is in heap-specific
code it no longer needs to test for RELKIND_INDEX.

I may be missing something here, but I don't know what it is.

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2019-06-11 13:20:42 Re: Ought to use heap_multi_insert() for pg_attribute/depend insertions?
Previous Message Robert Haas 2019-06-11 12:27:59 Re: Custom table AMs need to include heapam.h because of BulkInsertState