default cardinality with non-existent value

From: Igor Kustov <iakustov(at)yandex(dot)ru>
To: "pgsql-sql(at)lists(dot)postgresql(dot)org" <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: default cardinality with non-existent value
Date: 2025-04-25 09:35:39
Message-ID: 58011745572979@mail.yandex.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

<div>hello all,</div><div> </div><div>I noticed that the optimizer expects one row when there is a condition on the field for which optimizer does not know the value based on statistics, e.g.</div><div> </div><div><div>postgres=# create table t1 (a int, b int);</div><div>CREATE TABLE</div><div>postgres=# insert into t1 values (generate_series(1,1000),1);</div><div>INSERT 0 1000</div><div>and so on...</div><div>postgres=# insert into t1 values (generate_series(4001,5000),5);</div><div>INSERT 0 1000</div><div>postgres=# analyze t1;</div><div>ANALYZE</div><div>postgres=# explain select * from t1 where b=5;</div><div>                      QUERY PLAN</div><div>------------------------------------------------------</div><div> Seq Scan on t1  (cost=0.00..85.50 rows=1000 width=8)</div><div>   Filter: (b = 5)</div><div>(2 rows)</div><div> </div><div>postgres=# explain select * from t1 where b=6;</div><div>                    QUERY PLAN</div><div>---------------------------------------------------</div><div> Seq Scan on t1  (cost=0.00..85.50 rows=1 width=8)</div><div>   Filter: (b = 6)</div><div>(2 rows)</div><div> </div><div>do you know if there is a formula for such a cardinality based on the size of the table or is it always one row?</div><div>can you point to the source code location?</div><div> </div><div>Thanks,</div><div>Igor</div></div>

Attachment Content-Type Size
unknown_filename text/html 1.4 KB

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2025-04-25 14:03:24 Re: default cardinality with non-existent value
Previous Message Shay Patel 2025-04-14 19:25:38 Detached partitioning tables with RF keys in latest minor version is changed