BUG #15184: Planner overestimates number of rows in empty table - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #15184: Planner overestimates number of rows in empty table
Date
Msg-id 152533737110.23585.5446055718425840639@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #15184: Planner overestimates number of rows in empty table
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      15184
Logged by:          Alexey Ermakov
Email address:      alexey.ermakov@dataegret.com
PostgreSQL version: 10.3
Operating system:   Linux
Description:

Hello,

in optimizer/util/plancat.c we have following lines
(https://github.com/postgres/postgres/blob/master/src/backend/optimizer/util/plancat.c#L957):

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

if table is really empty then in first condition we set curpages = 10 and
second condition doesn't apply.
so we estimate that empty table has 10 pages and 2550 rows (for table with
one int column)
which doesn't look good. is it intended behavior? perhaps we should add
(curpages > 0) condition ?

that overestimate could mess plans for example when we use temporary tables
which might be empty.

Thanks,
Alexey Ermakov


pgsql-bugs by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: postgresql license question
Next
From: "postgresql_2016@163.com"
Date:
Subject: Asia/Jakarta Timezone problem