Skip to main content

min_start_distances

Function min_start_distances 

Source
fn min_start_distances(pattern: &MatchRecognizePattern) -> HashMap<String, u64>
Expand description

Per pattern variable: the minimum number of rows a match has necessarily consumed before a row can be labeled with that variable — its minimum distance from the match start.

This is what makes a physical PREV(col, k) in the variable’s DEFINE safe without any retention of pre-match rows: if the variable can only ever sit at distance >= k from the match start, every PREV read lands inside the match span, and rows of a live match are never evicted (the eviction walker keeps everything from the first live start onward). A read that could reach before the match start would observe a retained row before eviction and NULL after it — the same row flipping its verdict on timing — so those shapes are rejected at bind time (see the check in Binder::bind_match_recognize).

The walk is exact for the supported constructs and conservative by construction elsewhere:

  • concatenation shifts a variable’s distance by the minimum length of everything before it (a zero-minimum quantifier prefix contributes 0 — (a* b) leaves b at distance 0);
  • alternation takes the minimum across branches;
  • a quantified sub-pattern keeps its inner distances unshifted (the first iteration starts at the node’s start; later iterations only sit further from the match start);
  • PERMUTE puts every element at distance 0 (any ordering may put it first).

A variable occurring several times keeps the smallest distance of any occurrence.