Hi, >Which Postgres version do you use? I checked this on PG 11 postgres=# select version(); version ------------------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 11.5 on x86_64-w64-mingw32, compiled by x86_64-w64-mingw32-gcc.exe (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0, 64-bit (1 row)
and on PG 13 postgres=# select version(); version ----------------------------------------------------------------------------------------------------- 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 <x4...@yandex-team.ru> Отправлено: 27 апреля 2022 г. 13:08:22 Кому: Пантюшин Александр Иванович Копия: pgsql-hack...@postgresql.org; Тарасов Георгий Витальевич Тема: Re: Wrong rows count in EXPLAIN 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.