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/