Hi!

> 26 апр. 2022 г., в 13:45, Пантюшин Александр Иванович 
> <ai.pantyus...@gaz-is.ru> написал(а):
> 
> 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. Seem like it was calculated from some default 
> values.
> Is this normal behavior or a bug? Can it lead to a poor choice of the plan of 
> a query in general?

Which Postgres version do you use?

I observe:
postgres=# CREATE TABLE test1(f INTEGER PRIMARY KEY NOT NULL);
CREATE TABLE
postgres=# ANALYZE test1;
ANALYZE
postgres=# EXPLAIN SELECT * FROM test1;
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Index Only Scan using test1_pkey on test1  (cost=0.12..8.14 rows=1 width=4)
(1 row)

postgres=# select version();
                                                       version                  
                                      
----------------------------------------------------------------------------------------------------------------------
 PostgreSQL 15devel on x86_64-apple-darwin19.6.0, compiled by Apple clang 
version 11.0.3 (clang-1103.0.32.62), 64-bit
(1 row)

Without "ANALYZE test1;" table_block_relation_estimate_size() assumes relation 
size is 10 blocks.

Best regards, Andrey Borodin.

Reply via email to