Re: Wrong rows count in EXPLAIN - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Wrong rows count in EXPLAIN
Date
Msg-id 369407.1651067061@sss.pgh.pa.us
Whole thread Raw
In response to Wrong rows count in EXPLAIN  (Пантюшин Александр Иванович <AI.Pantyushin@gaz-is.ru>)
Responses Re: Wrong rows count in EXPLAIN  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
=?koi8-r?B?8MHO1MDbyc4g4czFy9PBzsTSIOnXwc7P18ne?= <AI.Pantyushin@gaz-is.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



pgsql-hackers by date:

Previous
From: vignesh C
Date:
Subject: Re: Skipping schema changes in publication
Next
From: Bruce Momjian
Date:
Subject: Re: Wrong rows count in EXPLAIN