Re: row estimate for partial index

2023-01-19 Thread Harmen
On Mon, Jan 16, 2023 at 09:59:38AM -0500, Tom Lane wrote: > Harmen writes: > > On Sat, Jan 14, 2023 at 11:23:07AM -0500, Tom Lane wrote: > >> If you are running a reasonably recent PG version you should be able to > >> fix that by setting up "extended statistics" on that pair of columns: > > >

Re: row estimate for partial index

2023-01-16 Thread Tom Lane
Harmen writes: > On Sat, Jan 14, 2023 at 11:23:07AM -0500, Tom Lane wrote: >> If you are running a reasonably recent PG version you should be able to >> fix that by setting up "extended statistics" on that pair of columns: > CREATE STATISTICS dist4 (ndistinct) ON deleted, org_id FROM contactsbo

Re: row estimate for partial index

2023-01-16 Thread Harmen
On Sat, Jan 14, 2023 at 11:23:07AM -0500, Tom Lane wrote: > Harmen writes: > > Works well enough. However, we now have an org_id which has > 10% of the > > rows, > > but only a handful rows where "deleted is null" matches (so the org has a > > lot > > of "deleted" contacts). The planner doesn't

Re: row estimate for partial index

2023-01-14 Thread Tom Lane
Harmen writes: > Works well enough. However, we now have an org_id which has > 10% of the rows, > but only a handful rows where "deleted is null" matches (so the org has a lot > of "deleted" contacts). The planner doesn't like this and it falls back to a > full table scan for the above query. > I