Re: Wrong rows count in EXPLAIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Пантюшин Александр Иванович <AI(dot)Pantyushin(at)gaz-is(dot)ru>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Тарасов Георгий Витальевич <Tarasov-G(at)gaz-is(dot)ru>
Subject: Re: Wrong rows count in EXPLAIN
Date: 2022-04-27 13:44:21
Message-ID: 369407.1651067061@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

=?koi8-r?B?8MHO1MDbyc4g4czFy9PBzsTSIOnXwc7P18ne?= <AI(dot)Pantyushin(at)gaz-is(dot)ru> writes:
> When I create a new table, and then I evaluate the execution of the SELECT query, I see a strange rows count in EXPLAIN
> CREATE TABLE test1(f INTEGER PRIMARY KEY NOT NULL);
> ANALYZE test1;
> EXPLAIN SELECT * FROM test1;
> QUERY PLAN
> ---------------------------------------------------------
> Seq Scan on test1 (cost=0.00..35.50 rows=2550 width=4)
> (1 row)

> Table is empty but rows=2550.

This is intentional, arising from the planner's unwillingness to
assume that a table is empty. It assumes that such a table actually
contains (from memory) 10 pages, and then backs into a rowcount
estimate from that depending on the data-type-dependent width of
the table rows.

Without this provision, we'd produce very bad plans for cases
where a newly-populated table hasn't been analyzed yet.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2022-04-27 13:51:15 Re: Wrong rows count in EXPLAIN
Previous Message vignesh C 2022-04-27 12:50:11 Re: Skipping schema changes in publication