Re: Optimize cardinality estimation when unique keys are fully covered

Nico Williams <nico@cryptonector.com>

From: Nico Williams <nico@cryptonector.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: feichanghong <feichanghong@qq.com>, pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-11-21T19:52:01Z
Lists: pgsql-hackers
On Fri, Nov 21, 2025 at 01:52:07PM -0500, Tom Lane wrote:
> But the conclusion that "where t1.a = t2.a and t1.b = 0" means that
> t1's rowcount is 1 only applies if the join is implemented as an inner
> indexscan.  If we choose some other method, say a hash join based on
> a seqscan of t1, having forced that rowcount to 1 would produce
> completely false estimates.

But wouldn't knowing that for an inner indexscan the cardinality is one
then drive the optimizer to choose inner indexscan over other methods?

Nico
--