Re: tableam: abstracting relation sizing code

Robert Haas <robertmhaas@gmail.com>

From: Robert Haas <robertmhaas@gmail.com>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Daniel Gustafsson <daniel@yesql.se>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Andres Freund <andres@anarazel.de>
Date: 2019-06-11T13:17:25Z
Lists: pgsql-hackers
On Mon, Jun 10, 2019 at 3:46 PM Alvaro Herrera <alvherre@2ndquadrant.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



Commits

  1. tableam: Provide helper functions for relation sizing.