Re: Optimize cardinality estimation when unique keys are fully covered

2025-11-21 Thread feichanghong
> On Nov 22, 2025, at 02:52, Tom Lane wrote: > > "=?utf-8?B?ZmVpY2hhbmdob25n?=" writes: >> We may consider checking in cardinality estimation whether the restrictlist >> fully covers a unique index. If so, we can directly set the estimated rows >> to 1. The attached patch provides a very early

Re: Optimize cardinality estimation when unique keys are fully covered

2025-11-21 Thread Nico Williams
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 f

Re: Optimize cardinality estimation when unique keys are fully covered

2025-11-21 Thread Tom Lane
"=?utf-8?B?ZmVpY2hhbmdob25n?=" writes: > We may consider checking in cardinality estimation whether the restrictlist > fully covers a unique index. If so, we can directly set the estimated rows > to 1. The attached patch provides a very early demo of this approach. I think this is far harder than

Re: Optimize cardinality estimation when unique keys are fully covered

2025-11-21 Thread feichanghong
> On Nov 22, 2025, at 00:54, feichanghong wrote: > > Hi, > > Recently, I ran into a cardinality estimation problem where the query > predicates fully cover a primary key or unique index. The issue can be > reproduced with the following case: > > ```sql > create table t1(a int, b int, primary

Optimize cardinality estimation when unique keys are fully covered

2025-11-21 Thread feichanghong
Hi, Recently, I ran into a cardinality estimation problem where the query predicates fully cover a primary key or unique index. The issue can be reproduced with the following case: ```sql create table t1(a int, b int, primary key(a, b)); DO $$ DECLARE     i integer; BEGIN     FOR i IN 1..1000