Re: Extended statistics improvement: multi-column MCV missing values - Mailing list pgsql-hackers

From Ilia Evdokimov
Subject Re: Extended statistics improvement: multi-column MCV missing values
Date
Msg-id 4f101ba3-1fcf-49e5-b4d8-28993bedba1f@tantorlabs.com
Whole thread
In response to Re: Extended statistics improvement: multi-column MCV missing values  (Enrique Sánchez <enriqueesanchz@gmail.com>)
Responses Re: Extended statistics improvement: multi-column MCV missing values
List pgsql-hackers

On 6/7/26 18:22, Enrique Sánchez wrote:

## v3-0001
- logic remains the same
- added a `IsA(clause, RestrictInfo)` check before casting to RestrictInfo in `mcv_can_cap()`
- added some tests

1. mcv_can_cap() reimplements logic already present in dependency_is_compatible_clause(). Shall we combine the two in order to avoid code duplication?

2. mcv_can_cap() runs unconditionally before the if (is_or) branch, but can_cap is only consumed in the else/AND branch. This means mcv_can_cap() - including get_oprrest, syscache lookups per clause - runs for every OR query as wasted work. Both can_cap and covered_attnums should be moved inside the else branch.



## v3-0002
- used ndistinct to calculate `non_mcv_sel = (1.0 - mcv_totalsel) / (ndistinct - mcv_nitems)` and applied it as an upper bound for non-MCV combinations, similarly to what `var_eq_const()` does in `selfuncs.c`

get_ndistinct_for_keys() reimplements the ndistinct item lookup already present in estimate_multivariate_ndistinct(). Both functions iterate over MVNDistinct->items match by attributes count.

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/


pgsql-hackers by date:

Previous
From: Nitin Jadhav
Date:
Subject: Re: [PATCH] Fix minRecoveryPoint not advanced past checkpoint in CreateRestartPoint
Next
From: Peter Eisentraut
Date:
Subject: Re: [PATCH v4] pg_stat_statements: Add last_execution_start column