PostgreSQL 13.5 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0, 64-bit
(1 row)
Both versions shows same strange rows counting in EXPLAINE
От: Andrey Borodin <x4mmm@yandex-team.ru> Отправлено: 27 апреля 2022 г. 13:08:22 Кому: Пантюшин Александр Иванович Копия: pgsql-hackers@postgresql.org; Тарасов Георгий Витальевич Тема: Re: Wrong rows count in EXPLAIN
Hi!
> 26 апр. 2022 г., в 13:45, Пантюшин Александр Иванович <AI.Pantyushin@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.