Re: Wrong rows count in EXPLAIN

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
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 09:08:22
Message-ID: 494205A7-BAD2-4289-ABFB-01C913E8BC88@yandex-team.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

> 26 апр. 2022 г., в 13:45, Пантюшин Александр Иванович <AI(dot)Pantyushin(at)gaz-is(dot)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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2022-04-27 09:43:16 Re: bogus: logical replication rows/cols combinations
Previous Message Bharath Rupireddy 2022-04-27 08:17:11 Re: pgsql: Add contrib/pg_walinspect.