On 11/11/26 14:37, ZizhuanLiu X-MAN wrote:

The main differences are where the responsibility for handling this logic 
resides:
- [2] keeps the handling within the current clause_selectivity_ext() function 
by constructing a BooleanTest node.

- [1] delegates the handling to booltestsel(IS_FALSE) in selfuncs.c.

- [3] keeps the handling within the current if branch and reimplements the 
relevant parts of booltestsel() locally.
    This avoids the additional call chain booltestsel() -> clause_selectivity() 
-> clause_selectivity_ext() when
     statistics are unavailable, while retaining the same logic.

Personally, I prefer approach [1]. I think centralizing the semantics in 
booltestsel() could help keep the handling consistent,
reduce maintenance overhead, and make future extensions to the function easier 
to manage.

Please let me know if I've overlooked anything or if you see any issues with 
this reasoning.

What do you think?

I don't think approaches [1] and [2] are equivalent to [3] in all cases.

The difference is in the fallback path when no statistics tuple is available for the argument of NOT. In [3], the recursive call preserves the caller's `use_extended_stats` value:

```
s1 = 1.0 - clause_selectivity_ext(..., use_extended_stats);
```

In [1], `booltestsel()` instead calls `clause_selectivity()`, which calls `clause_selectivity_ext()` with use_extended_stats = true:

```
booltestsel(IS_FALSE, arg) -> clause_selectivity(arg, ...) -> clause_selectivity_ext(arg, ..., true)
```

Therefore, if the original call had use_extended_stats = false, [1] can enable extended statistics when estimating the argument. Approach [2] has the same issue.

For that reason, I think v1 patch is needed to preserve the existing behavior.

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



Reply via email to