Chengpeng Yan <[email protected]> writes:
>> On Nov 21, 2026, at 04:06, Tom Lane <[email protected]> wrote:
>> It is nearly the same logic, but I'm not sure you can easily use that
>> in combination with the fixed-prefix logic in patternsel_common,
>> which we should certainly not give up. I'd be inclined to approach
>> this by just replacing "rest_selec" with a constant and removing all
>> the subsidiary code that calculates that.
> What I would change is the single line that produces the heuristic value:
> heursel = prefixsel * rest_selec;
> rest_selec comes from the per-byte model, so both the complexity and the
> encoding dependence come from that line alone.
Right.
> Following your suggestion it becomes a constant:
> heursel = prefixsel * C;
> but multiplying by it has two problems. The constant stands for "no
> information", so the product pretends to know how likely the remainder is
> once the prefix has matched; and because the prefix estimate is below 1, a
> selective prefix makes the product shrink toward the clamp floor, where it
> stops distinguishing anything. A different constant for the two cases
> would avoid the shrink, but then the same unknown remainder would be
> charged different amounts with no basis in the pattern.
> So I would rather use the prefix as the answer where it is all we need,
> and otherwise only bound the constant by it:
> heursel = rest_free ? prefixsel : min(C, prefixsel);
> rest_free is true when the pattern constrains nothing beyond the prefix:
> a LIKE remainder made only of % and _, or a regex the engine reduces to a
> length test (MATCHALL).
I don't quite agree with that definition: a length restriction is
not "no constraint". But that's a side point.
Yes, we could distinguish cases where the pattern is like "abc%"
or "^abc", and maybe that's common enough to be worth the trouble,
but I'm not really convinced. I think when we put in the
check-all-the-histogram-entries logic we eliminated pretty much
all reason to work hard on pattern analysis. The fixed-prefix
logic is worth keeping because it allows a preliminary index-based
filter, but I think we should stop with that rather than trying
to do fragmentary pattern analysis.
regards, tom lane