src/backend/executor/execRPR.c - Coverage Report

← Back to Overview

# src/backend/executor/execRPR.c

Coverage: 584/588 lines (99.3%)
Total Lines
588
modified
Covered
584
99.3%
Uncovered
4
0.7%
Keyboard navigation
nfa_mark_visited() lines 47-54
Modified Lines Coverage: 6/6 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
47 | 3038984 | nfa_mark_visited(WindowAggState *winstate, int16 elemIdx) | 24cfb8dRow pattern recognition patch (executor and commands).
48 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
49 | 3038984 | int16 w = WORDNUM(elemIdx); | 24cfb8dRow pattern recognition patch (executor and commands).
50 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
51 | 3038984 | winstate->nfaVisitedElems[w] |= ((bitmapword) 1 << BITNUM(elemIdx)); | 24cfb8dRow pattern recognition patch (executor and commands).
52 | 3038984 | winstate->nfaVisitedMinWord = Min(winstate->nfaVisitedMinWord, w); | 24cfb8dRow pattern recognition patch (executor and commands).
53 | 3038984 | winstate->nfaVisitedMaxWord = Max(winstate->nfaVisitedMaxWord, w); | 24cfb8dRow pattern recognition patch (executor and commands).
54 | 3038984 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_state_make() lines 209-235
Modified Lines Coverage: 11/11 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
209 | 2014844 | nfa_state_make(WindowAggState *winstate) | 24cfb8dRow pattern recognition patch (executor and commands).
210 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
211 | 2014844 | RPRNFAState *state; | 24cfb8dRow pattern recognition patch (executor and commands).
212 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
213 | - | /* Try to reuse from free list first */ | 24cfb8dRow pattern recognition patch (executor and commands).
214 | 2014844 | if (winstate->nfaStateFree != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
215 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
216 | 1982164 | state = winstate->nfaStateFree; | 24cfb8dRow pattern recognition patch (executor and commands).
217 | 1982164 | winstate->nfaStateFree = state->next; | 24cfb8dRow pattern recognition patch (executor and commands).
218 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
219 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
220 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
221 | - | /* Allocate in partition context for proper lifetime */ | 24cfb8dRow pattern recognition patch (executor and commands).
222 | 32680 | state = MemoryContextAlloc(winstate->partcontext, winstate->nfaStateSize); | 24cfb8dRow pattern recognition patch (executor and commands).
223 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
224 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
225 | - | /* Initialize entire state to zero */ | 24cfb8dRow pattern recognition patch (executor and commands).
226 | 2014844 | memset(state, 0, winstate->nfaStateSize); | 24cfb8dRow pattern recognition patch (executor and commands).
227 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
228 | - | /* Update statistics */ | 24cfb8dRow pattern recognition patch (executor and commands).
229 | 2014844 | winstate->nfaStatesActive++; | 24cfb8dRow pattern recognition patch (executor and commands).
230 | 2014844 | winstate->nfaStatesTotalCreated++; | 24cfb8dRow pattern recognition patch (executor and commands).
231 | 2014844 | winstate->nfaStatesMax = Max(winstate->nfaStatesMax, | 24cfb8dRow pattern recognition patch (executor and commands).
232 | - | winstate->nfaStatesActive); | 24cfb8dRow pattern recognition patch (executor and commands).
233 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
234 | 2014844 | return state; | 24cfb8dRow pattern recognition patch (executor and commands).
235 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_state_free() lines 243-248
Modified Lines Coverage: 5/5 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
243 | 2010552 | nfa_state_free(WindowAggState *winstate, RPRNFAState *state) | 24cfb8dRow pattern recognition patch (executor and commands).
244 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
245 | 2010552 | winstate->nfaStatesActive--; | 24cfb8dRow pattern recognition patch (executor and commands).
246 | 2010552 | state->next = winstate->nfaStateFree; | 24cfb8dRow pattern recognition patch (executor and commands).
247 | 2010552 | winstate->nfaStateFree = state; | 24cfb8dRow pattern recognition patch (executor and commands).
248 | 2010552 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_state_free_list() lines 256-265
Modified Lines Coverage: 6/6 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
256 | 390760 | nfa_state_free_list(WindowAggState *winstate, RPRNFAState *list) | 24cfb8dRow pattern recognition patch (executor and commands).
257 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
258 | 390760 | RPRNFAState *next; | 24cfb8dRow pattern recognition patch (executor and commands).
259 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
260 | 781608 | for (; list != NULL; list = next) | 24cfb8dRow pattern recognition patch (executor and commands).
261 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
262 | 390848 | next = list->next; | 24cfb8dRow pattern recognition patch (executor and commands).
263 | 390848 | nfa_state_free(winstate, list); | 24cfb8dRow pattern recognition patch (executor and commands).
264 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
265 | 390760 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_state_clone() lines 277-298
Modified Lines Coverage: 10/10 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
277 | 1015988 | nfa_state_clone(WindowAggState *winstate, int16 elemIdx, | 24cfb8dRow pattern recognition patch (executor and commands).
278 | - | int32 *counts, bool sourceAbsorbable) | 24cfb8dRow pattern recognition patch (executor and commands).
279 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
280 | 1015988 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
281 | 1015988 | int maxDepth = pattern->maxDepth; | 24cfb8dRow pattern recognition patch (executor and commands).
282 | 1015988 | RPRNFAState *state = nfa_state_make(winstate); | 24cfb8dRow pattern recognition patch (executor and commands).
283 | 1015988 | RPRPatternElement *elem = &pattern->elements[elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
284 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
285 | 1015988 | state->elemIdx = elemIdx; | 24cfb8dRow pattern recognition patch (executor and commands).
286 | - | /* Every reachable caller passes a live state's counts; maxDepth >= 1. */ | 24cfb8dRow pattern recognition patch (executor and commands).
287 | 1015988 | Assert(counts != NULL && maxDepth > 0); | 24cfb8dRow pattern recognition patch (executor and commands).
288 | 1015988 | memcpy(state->counts, counts, sizeof(int32) * maxDepth); | 24cfb8dRow pattern recognition patch (executor and commands).
289 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
290 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
291 | - | * Compute isAbsorbable immediately at transition time. isAbsorbable = | 24cfb8dRow pattern recognition patch (executor and commands).
292 | - | * sourceAbsorbable && (elem->flags & ABSORBABLE_BRANCH) Monotonic: once | 24cfb8dRow pattern recognition patch (executor and commands).
293 | - | * false, stays false (can't re-enter absorbable region). | 24cfb8dRow pattern recognition patch (executor and commands).
294 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
295 | 1015988 | state->isAbsorbable = sourceAbsorbable && RPRElemIsAbsorbableBranch(elem); | 24cfb8dRow pattern recognition patch (executor and commands).
296 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
297 | 1015988 | return state; | 24cfb8dRow pattern recognition patch (executor and commands).
298 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_states_equal() lines 306-334
Modified Lines Coverage: 9/9 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
306 | 804396 | nfa_states_equal(WindowAggState *winstate, RPRNFAState *s1, RPRNFAState *s2) | 24cfb8dRow pattern recognition patch (executor and commands).
307 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
308 | 804396 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
309 | 804396 | RPRPatternElement *elem; | 24cfb8dRow pattern recognition patch (executor and commands).
310 | 804396 | int compareDepth; | 24cfb8dRow pattern recognition patch (executor and commands).
311 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
312 | 804396 | if (s1->elemIdx != s2->elemIdx) | 24cfb8dRow pattern recognition patch (executor and commands).
313 | - | return false; | 24cfb8dRow pattern recognition patch (executor and commands).
314 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
315 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
316 | - | * Compare counts up to current element's depth. Two states sharing | 24cfb8dRow pattern recognition patch (executor and commands).
317 | - | * elemIdx are equivalent iff every enclosing-or-current depth count | 24cfb8dRow pattern recognition patch (executor and commands).
318 | - | * matches. | 24cfb8dRow pattern recognition patch (executor and commands).
319 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
320 | - | * The +1 is the slot arithmetic: comparing through depth N requires | 24cfb8dRow pattern recognition patch (executor and commands).
321 | - | * counts[0..N], i.e., N+1 entries. Deeper slots (counts[d] with d > | 24cfb8dRow pattern recognition patch (executor and commands).
322 | - | * elem->depth) are excluded because they hold scratch state from inner | 24cfb8dRow pattern recognition patch (executor and commands).
323 | - | * groups. Per the count-clear policy such a slot is zeroed when its | 24cfb8dRow pattern recognition patch (executor and commands).
324 | - | * owning element exits (see nfa_advance_var and the inline fast path in | 24cfb8dRow pattern recognition patch (executor and commands).
325 | - | * nfa_match), so it must not participate in equivalence judgment. | 24cfb8dRow pattern recognition patch (executor and commands).
326 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
327 | 672 | elem = &pattern->elements[s1->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
328 | 672 | compareDepth = elem->depth + 1; | 24cfb8dRow pattern recognition patch (executor and commands).
329 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
330 | 672 | if (memcmp(s1->counts, s2->counts, sizeof(int32) * compareDepth) != 0) | 24cfb8dRow pattern recognition patch (executor and commands).
331 | 568 | return false; | 24cfb8dRow pattern recognition patch (executor and commands).
332 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
333 | - | return true; | 24cfb8dRow pattern recognition patch (executor and commands).
334 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_add_state_unique() lines 345-382
Modified Lines Coverage: 15/15 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
345 | 2617360 | nfa_add_state_unique(WindowAggState *winstate, RPRNFAContext *ctx, RPRNFAState *state) | 24cfb8dRow pattern recognition patch (executor and commands).
346 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
347 | 2617360 | RPRNFAState *s; | 24cfb8dRow pattern recognition patch (executor and commands).
348 | 2617360 | RPRNFAState *tail = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
349 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
350 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
351 | - | * Mark VAR in visited before duplicate check to prevent DFS loops. This | 24cfb8dRow pattern recognition patch (executor and commands).
352 | - | * is the deferred half of the asymmetric visited-marking scheme; see | 24cfb8dRow pattern recognition patch (executor and commands).
353 | - | * nfa_advance_state for the non-VAR (END/ALT/BEGIN/FIN) half and the | 24cfb8dRow pattern recognition patch (executor and commands).
354 | - | * rationale for the asymmetry. | 24cfb8dRow pattern recognition patch (executor and commands).
355 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
356 | 2617360 | nfa_mark_visited(winstate, state->elemIdx); | 24cfb8dRow pattern recognition patch (executor and commands).
357 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
358 | - | /* Check for duplicate and find tail */ | 24cfb8dRow pattern recognition patch (executor and commands).
359 | 3421652 | for (s = ctx->states; s != NULL; s = s->next) | 24cfb8dRow pattern recognition patch (executor and commands).
360 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
361 | 804396 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
362 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
363 | 804396 | if (nfa_states_equal(winstate, s, state)) | 24cfb8dRow pattern recognition patch (executor and commands).
364 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
365 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
366 | - | * Duplicate found - existing has better lexical order, discard | 24cfb8dRow pattern recognition patch (executor and commands).
367 | - | * new | 24cfb8dRow pattern recognition patch (executor and commands).
368 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
369 | 104 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
370 | 104 | winstate->nfaStatesMerged++; | 24cfb8dRow pattern recognition patch (executor and commands).
371 | 104 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
372 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
373 | 804292 | tail = s; | 24cfb8dRow pattern recognition patch (executor and commands).
374 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
375 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
376 | - | /* No duplicate, add at end */ | 24cfb8dRow pattern recognition patch (executor and commands).
377 | 2617256 | state->next = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
378 | 2617256 | if (tail == NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
379 | 1959008 | ctx->states = state; | 24cfb8dRow pattern recognition patch (executor and commands).
380 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
381 | 658248 | tail->next = state; | 24cfb8dRow pattern recognition patch (executor and commands).
382 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_add_matched_state() lines 393-420
Modified Lines Coverage: 15/15 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
393 | 362624 | nfa_add_matched_state(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
394 | - | RPRNFAState *state, int64 matchEndRow) | 24cfb8dRow pattern recognition patch (executor and commands).
395 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
396 | 362624 | if (ctx->matchedState != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
397 | 324600 | nfa_state_free(winstate, ctx->matchedState); | 24cfb8dRow pattern recognition patch (executor and commands).
398 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
399 | 362624 | ctx->matchedState = state; | 24cfb8dRow pattern recognition patch (executor and commands).
400 | 362624 | state->next = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
401 | 362624 | ctx->matchEndRow = matchEndRow; | 24cfb8dRow pattern recognition patch (executor and commands).
402 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
403 | - | /* Prune contexts that started within this match's range */ | 24cfb8dRow pattern recognition patch (executor and commands).
404 | 362624 | if (winstate->rpSkipTo == ST_PAST_LAST_ROW) | 24cfb8dRow pattern recognition patch (executor and commands).
405 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
406 | - | int64 skippedLen; | 24cfb8dRow pattern recognition patch (executor and commands).
407 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
408 | 672208 | while (ctx->next != NULL && | 24cfb8dRow pattern recognition patch (executor and commands).
409 | 314316 | ctx->next->matchStartRow <= matchEndRow) | 24cfb8dRow pattern recognition patch (executor and commands).
410 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
411 | 314316 | RPRNFAContext *nextCtx = ctx->next; | 24cfb8dRow pattern recognition patch (executor and commands).
412 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
413 | 314316 | Assert(nextCtx->lastProcessedRow >= nextCtx->matchStartRow); | 24cfb8dRow pattern recognition patch (executor and commands).
414 | 314316 | skippedLen = nextCtx->lastProcessedRow - nextCtx->matchStartRow + 1; | 24cfb8dRow pattern recognition patch (executor and commands).
415 | 314316 | nfa_record_context_skipped(winstate, skippedLen); | 24cfb8dRow pattern recognition patch (executor and commands).
416 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
417 | 314316 | ExecRPRFreeContext(winstate, nextCtx); | 24cfb8dRow pattern recognition patch (executor and commands).
418 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
419 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
420 | 362624 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_context_make() lines 428-462
Modified Lines Coverage: 19/19 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
428 | 998856 | nfa_context_make(WindowAggState *winstate) | 24cfb8dRow pattern recognition patch (executor and commands).
429 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
430 | 998856 | RPRNFAContext *ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
431 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
432 | 998856 | if (winstate->nfaContextFree != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
433 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
434 | 965920 | ctx = winstate->nfaContextFree; | 24cfb8dRow pattern recognition patch (executor and commands).
435 | 965920 | winstate->nfaContextFree = ctx->next; | 24cfb8dRow pattern recognition patch (executor and commands).
436 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
437 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
438 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
439 | - | /* Allocate in partition context for proper lifetime */ | 24cfb8dRow pattern recognition patch (executor and commands).
440 | 32936 | ctx = MemoryContextAlloc(winstate->partcontext, sizeof(RPRNFAContext)); | 24cfb8dRow pattern recognition patch (executor and commands).
441 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
442 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
443 | 998856 | ctx->next = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
444 | 998856 | ctx->prev = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
445 | 998856 | ctx->states = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
446 | 998856 | ctx->matchStartRow = -1; | 24cfb8dRow pattern recognition patch (executor and commands).
447 | 998856 | ctx->matchEndRow = -1; | 24cfb8dRow pattern recognition patch (executor and commands).
448 | 998856 | ctx->lastProcessedRow = -1; | 24cfb8dRow pattern recognition patch (executor and commands).
449 | 998856 | ctx->matchedState = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
450 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
451 | - | /* Initialize two-flag absorption design based on pattern */ | 24cfb8dRow pattern recognition patch (executor and commands).
452 | 998856 | ctx->hasAbsorbableState = winstate->rpPattern->isAbsorbable; | 24cfb8dRow pattern recognition patch (executor and commands).
453 | 998856 | ctx->allStatesAbsorbable = winstate->rpPattern->isAbsorbable; | 24cfb8dRow pattern recognition patch (executor and commands).
454 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
455 | - | /* Update statistics */ | 24cfb8dRow pattern recognition patch (executor and commands).
456 | 998856 | winstate->nfaContextsActive++; | 24cfb8dRow pattern recognition patch (executor and commands).
457 | 998856 | winstate->nfaContextsTotalCreated++; | 24cfb8dRow pattern recognition patch (executor and commands).
458 | 998856 | winstate->nfaContextsMax = Max(winstate->nfaContextsMax, | 24cfb8dRow pattern recognition patch (executor and commands).
459 | - | winstate->nfaContextsActive); | 24cfb8dRow pattern recognition patch (executor and commands).
460 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
461 | 998856 | return ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
462 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_unlink_context() lines 471-485
Modified Lines Coverage: 10/10 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
471 | 995004 | nfa_unlink_context(WindowAggState *winstate, RPRNFAContext *ctx) | 24cfb8dRow pattern recognition patch (executor and commands).
472 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
473 | 995004 | if (ctx->prev != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
474 | 895120 | ctx->prev->next = ctx->next; | 24cfb8dRow pattern recognition patch (executor and commands).
475 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
476 | 99884 | winstate->nfaContext = ctx->next; /* was head */ | 24cfb8dRow pattern recognition patch (executor and commands).
477 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
478 | 995004 | if (ctx->next != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
479 | 293976 | ctx->next->prev = ctx->prev; | 24cfb8dRow pattern recognition patch (executor and commands).
480 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
481 | 701028 | winstate->nfaContextTail = ctx->prev; /* was tail */ | 24cfb8dRow pattern recognition patch (executor and commands).
482 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
483 | 995004 | ctx->next = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
484 | 995004 | ctx->prev = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
485 | 995004 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_update_length_stats() lines 494-507
Modified Lines Coverage: 8/8 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
494 | 761032 | nfa_update_length_stats(int64 count, NFALengthStats *stats, int64 newLen) | 24cfb8dRow pattern recognition patch (executor and commands).
495 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
496 | 761032 | if (count == 1) | 24cfb8dRow pattern recognition patch (executor and commands).
497 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
498 | 4624 | stats->min = newLen; | 24cfb8dRow pattern recognition patch (executor and commands).
499 | 4624 | stats->max = newLen; | 24cfb8dRow pattern recognition patch (executor and commands).
500 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
501 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
502 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
503 | 756408 | stats->min = Min(stats->min, newLen); | 24cfb8dRow pattern recognition patch (executor and commands).
504 | 756408 | stats->max = Max(stats->max, newLen); | 24cfb8dRow pattern recognition patch (executor and commands).
505 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
506 | 761032 | stats->total += newLen; | 24cfb8dRow pattern recognition patch (executor and commands).
507 | 761032 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_record_context_skipped() lines 515-521
Modified Lines Coverage: 4/4 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
515 | 314316 | nfa_record_context_skipped(WindowAggState *winstate, int64 skippedLen) | 24cfb8dRow pattern recognition patch (executor and commands).
516 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
517 | 314316 | winstate->nfaContextsSkipped++; | 24cfb8dRow pattern recognition patch (executor and commands).
518 | 314316 | nfa_update_length_stats(winstate->nfaContextsSkipped, | 24cfb8dRow pattern recognition patch (executor and commands).
519 | - | &winstate->nfaSkippedLen, | 24cfb8dRow pattern recognition patch (executor and commands).
520 | - | skippedLen); | 24cfb8dRow pattern recognition patch (executor and commands).
521 | 314316 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_record_context_absorbed() lines 529-535
Modified Lines Coverage: 4/4 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
529 | 378580 | nfa_record_context_absorbed(WindowAggState *winstate, int64 absorbedLen) | 24cfb8dRow pattern recognition patch (executor and commands).
530 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
531 | 378580 | winstate->nfaContextsAbsorbed++; | 24cfb8dRow pattern recognition patch (executor and commands).
532 | 378580 | nfa_update_length_stats(winstate->nfaContextsAbsorbed, | 24cfb8dRow pattern recognition patch (executor and commands).
533 | - | &winstate->nfaAbsorbedLen, | 24cfb8dRow pattern recognition patch (executor and commands).
534 | - | absorbedLen); | 24cfb8dRow pattern recognition patch (executor and commands).
535 | 378580 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_update_absorption_flags() lines 554-596
Modified Lines Coverage: 17/17 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
554 | 1758300 | nfa_update_absorption_flags(RPRNFAContext *ctx) | 24cfb8dRow pattern recognition patch (executor and commands).
555 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
556 | 1758300 | RPRNFAState *state; | 24cfb8dRow pattern recognition patch (executor and commands).
557 | 1758300 | bool hasAbsorbable = false; | 24cfb8dRow pattern recognition patch (executor and commands).
558 | 1758300 | bool allAbsorbable = true; | 24cfb8dRow pattern recognition patch (executor and commands).
559 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
560 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
561 | - | * Optimization: Once hasAbsorbableState becomes false, it stays false. No | 24cfb8dRow pattern recognition patch (executor and commands).
562 | - | * need to recalculate - both flags remain false permanently. | 24cfb8dRow pattern recognition patch (executor and commands).
563 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
564 | 1758300 | if (!ctx->hasAbsorbableState) | 24cfb8dRow pattern recognition patch (executor and commands).
565 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
566 | 470200 | ctx->allStatesAbsorbable = false; | 24cfb8dRow pattern recognition patch (executor and commands).
567 | 470200 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
568 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
569 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
570 | - | /* No states means no absorbable states */ | 24cfb8dRow pattern recognition patch (executor and commands).
571 | 1288100 | if (ctx->states == NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
572 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
573 | 513304 | ctx->hasAbsorbableState = false; | 24cfb8dRow pattern recognition patch (executor and commands).
574 | 513304 | ctx->allStatesAbsorbable = false; | 24cfb8dRow pattern recognition patch (executor and commands).
575 | 513304 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
576 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
577 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
578 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
579 | - | * Iterate through all states to check absorption status. Uses | 24cfb8dRow pattern recognition patch (executor and commands).
580 | - | * state->isAbsorbable which tracks if state is in absorbable region. This | 24cfb8dRow pattern recognition patch (executor and commands).
581 | - | * is different from RPRElemIsAbsorbable(elem) which checks comparison | 0bc60efRename absorption "judgment point" to "comparison point" in comments
582 | - | * point. | 24cfb8dRow pattern recognition patch (executor and commands).
583 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
584 | 1549984 | for (state = ctx->states; state != NULL; state = state->next) | 24cfb8dRow pattern recognition patch (executor and commands).
585 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
586 | 775188 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
587 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
588 | 775188 | if (state->isAbsorbable) | 24cfb8dRow pattern recognition patch (executor and commands).
589 | - | hasAbsorbable = true; | 24cfb8dRow pattern recognition patch (executor and commands).
590 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
591 | 3232 | allAbsorbable = false; | 24cfb8dRow pattern recognition patch (executor and commands).
592 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
593 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
594 | 774796 | ctx->hasAbsorbableState = hasAbsorbable; | 24cfb8dRow pattern recognition patch (executor and commands).
595 | 774796 | ctx->allStatesAbsorbable = allAbsorbable; | 24cfb8dRow pattern recognition patch (executor and commands).
596 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_states_covered() lines 612-654
Modified Lines Coverage: 16/16 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
612 | 380236 | nfa_states_covered(RPRPattern *pattern, RPRNFAContext *older, RPRNFAContext *newer) | 24cfb8dRow pattern recognition patch (executor and commands).
613 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
614 | 380236 | RPRNFAState *newerState; | 24cfb8dRow pattern recognition patch (executor and commands).
615 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
616 | 758820 | for (newerState = newer->states; newerState != NULL; newerState = newerState->next) | 24cfb8dRow pattern recognition patch (executor and commands).
617 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
618 | 380240 | RPRNFAState *olderState; | 24cfb8dRow pattern recognition patch (executor and commands).
619 | 380240 | RPRPatternElement *elem; | 24cfb8dRow pattern recognition patch (executor and commands).
620 | 380240 | int depth; | 24cfb8dRow pattern recognition patch (executor and commands).
621 | 380240 | bool found = false; | 24cfb8dRow pattern recognition patch (executor and commands).
622 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
623 | - | /* All states are absorbable (caller checks allStatesAbsorbable) */ | 24cfb8dRow pattern recognition patch (executor and commands).
624 | 380240 | elem = &pattern->elements[newerState->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
625 | 380240 | depth = elem->depth; | 24cfb8dRow pattern recognition patch (executor and commands).
626 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
627 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
628 | - | * Only compare at absorption comparison points (RPR_ELEM_ABSORBABLE). | 0bc60efRename absorption "judgment point" to "comparison point" in comments
629 | - | * Comparison points are where count-dominance guarantees the newer | 0bc60efRename absorption "judgment point" to "comparison point" in comments
630 | - | * context's future matches are a subset of the older's. | 24cfb8dRow pattern recognition patch (executor and commands).
631 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
632 | 380240 | if (!RPRElemIsAbsorbable(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
633 | - | return false; | 24cfb8dRow pattern recognition patch (executor and commands).
634 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
635 | 378592 | for (olderState = older->states; olderState != NULL; olderState = olderState->next) | 24cfb8dRow pattern recognition patch (executor and commands).
636 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
637 | 378588 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
638 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
639 | - | /* Covering state must also be absorbable */ | 24cfb8dRow pattern recognition patch (executor and commands).
640 | 378588 | if (olderState->isAbsorbable && | 24cfb8dRow pattern recognition patch (executor and commands).
641 | 378588 | olderState->elemIdx == newerState->elemIdx && | 24cfb8dRow pattern recognition patch (executor and commands).
642 | 378584 | olderState->counts[depth] >= newerState->counts[depth]) | 24cfb8dRow pattern recognition patch (executor and commands).
643 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
644 | - | found = true; | 24cfb8dRow pattern recognition patch (executor and commands).
645 | - | break; | 24cfb8dRow pattern recognition patch (executor and commands).
646 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
647 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
648 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
649 | 378588 | if (!found) | 24cfb8dRow pattern recognition patch (executor and commands).
650 | - | return false; | 24cfb8dRow pattern recognition patch (executor and commands).
651 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
652 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
653 | - | return true; | 24cfb8dRow pattern recognition patch (executor and commands).
654 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_try_absorb_context() lines 675-712
Modified Lines Coverage: 15/15 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
675 | 1244200 | nfa_try_absorb_context(WindowAggState *winstate, RPRNFAContext *ctx) | 24cfb8dRow pattern recognition patch (executor and commands).
676 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
677 | 1244200 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
678 | 1244200 | RPRNFAContext *older; | 24cfb8dRow pattern recognition patch (executor and commands).
679 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
680 | - | /* Early exit: ctx must have all states absorbable */ | 24cfb8dRow pattern recognition patch (executor and commands).
681 | 1244200 | if (!ctx->allStatesAbsorbable) | 24cfb8dRow pattern recognition patch (executor and commands).
682 | - | return; | 24cfb8dRow pattern recognition patch (executor and commands).
683 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
684 | 774492 | for (older = ctx->prev; older != NULL; older = older->prev) | 24cfb8dRow pattern recognition patch (executor and commands).
685 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
686 | 381460 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
687 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
688 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
689 | - | * By invariant: ctx->prev chain is in creation order (oldest first), | 24cfb8dRow pattern recognition patch (executor and commands).
690 | - | * and each row creates at most one context. So all contexts in this | 24cfb8dRow pattern recognition patch (executor and commands).
691 | - | * chain have matchStartRow < ctx->matchStartRow. | 24cfb8dRow pattern recognition patch (executor and commands).
692 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
693 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
694 | - | /* Older must also be in-progress */ | 24cfb8dRow pattern recognition patch (executor and commands).
695 | 381460 | if (older->states == NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
696 | 768 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
697 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
698 | - | /* Older must have at least one absorbable state */ | 24cfb8dRow pattern recognition patch (executor and commands).
699 | 380692 | if (!older->hasAbsorbableState) | 24cfb8dRow pattern recognition patch (executor and commands).
700 | 456 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
701 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
702 | - | /* Check if all newer states are covered by older */ | 24cfb8dRow pattern recognition patch (executor and commands).
703 | 380236 | if (nfa_states_covered(pattern, older, ctx)) | 24cfb8dRow pattern recognition patch (executor and commands).
704 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
705 | 378580 | int64 absorbedLen = ctx->lastProcessedRow - ctx->matchStartRow + 1; | 24cfb8dRow pattern recognition patch (executor and commands).
706 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
707 | 378580 | ExecRPRFreeContext(winstate, ctx); | 24cfb8dRow pattern recognition patch (executor and commands).
708 | 378580 | nfa_record_context_absorbed(winstate, absorbedLen); | 24cfb8dRow pattern recognition patch (executor and commands).
709 | 378580 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
710 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
711 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
712 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_absorb_contexts() lines 728-744
Modified Lines Coverage: 8/8 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
728 | 897672 | nfa_absorb_contexts(WindowAggState *winstate) | 24cfb8dRow pattern recognition patch (executor and commands).
729 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
730 | 897672 | RPRNFAContext *ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
731 | 897672 | RPRNFAContext *nextCtx; | 24cfb8dRow pattern recognition patch (executor and commands).
732 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
733 | 2655972 | for (ctx = winstate->nfaContextTail; ctx != NULL; ctx = nextCtx) | 24cfb8dRow pattern recognition patch (executor and commands).
734 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
735 | 1758300 | nextCtx = ctx->prev; | 24cfb8dRow pattern recognition patch (executor and commands).
736 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
737 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
738 | - | * Only absorb in-progress contexts; completed contexts are valid | 24cfb8dRow pattern recognition patch (executor and commands).
739 | - | * results | 24cfb8dRow pattern recognition patch (executor and commands).
740 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
741 | 1758300 | if (ctx->states != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
742 | 1244200 | nfa_try_absorb_context(winstate, ctx); | 24cfb8dRow pattern recognition patch (executor and commands).
743 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
744 | 897672 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_eval_var_match() lines 760-771
Modified Lines Coverage: 5/5 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
760 | 2613076 | nfa_eval_var_match(WindowAggState *winstate, RPRPatternElement *elem, | 24cfb8dRow pattern recognition patch (executor and commands).
761 | - | bool *varMatched) | 24cfb8dRow pattern recognition patch (executor and commands).
762 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
763 | - | /* This function should only be called for VAR elements */ | 24cfb8dRow pattern recognition patch (executor and commands).
764 | 2613076 | Assert(RPRElemIsVar(elem)); | 24cfb8dRow pattern recognition patch (executor and commands).
765 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
766 | 2613076 | if (varMatched == NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
767 | - | return false; | 24cfb8dRow pattern recognition patch (executor and commands).
768 | 2597352 | if (elem->varId >= list_length(winstate->defineVariableList)) | 24cfb8dRow pattern recognition patch (executor and commands).
769 | - | return true; | 24cfb8dRow pattern recognition patch (executor and commands).
770 | 2570172 | return varMatched[elem->varId]; | 24cfb8dRow pattern recognition patch (executor and commands).
771 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_match() lines 793-937
Modified Lines Coverage: 55/55 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
793 | 1955156 | nfa_match(WindowAggState *winstate, RPRNFAContext *ctx, bool *varMatched) | 24cfb8dRow pattern recognition patch (executor and commands).
794 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
795 | 1955156 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
796 | 1955156 | RPRPatternElement *elements = pattern->elements; | 24cfb8dRow pattern recognition patch (executor and commands).
797 | 1955156 | RPRNFAState **prevPtr = &ctx->states; | 24cfb8dRow pattern recognition patch (executor and commands).
798 | 1955156 | RPRNFAState *state; | 24cfb8dRow pattern recognition patch (executor and commands).
799 | 1955156 | RPRNFAState *nextState; | 24cfb8dRow pattern recognition patch (executor and commands).
800 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
801 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
802 | - | * Evaluate VAR elements against current row. For VARs that reach max | 24cfb8dRow pattern recognition patch (executor and commands).
803 | - | * count with END next, advance through the chain of END elements inline | 24cfb8dRow pattern recognition patch (executor and commands).
804 | - | * so absorb phase can compare states at comparison points. | 0bc60efRename absorption "judgment point" to "comparison point" in comments
805 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
806 | 4568232 | for (state = ctx->states; state != NULL; state = nextState) | 24cfb8dRow pattern recognition patch (executor and commands).
807 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
808 | 2613076 | RPRPatternElement *elem = &elements[state->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
809 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
810 | 2613076 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
811 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
812 | 2613076 | nextState = state->next; | 24cfb8dRow pattern recognition patch (executor and commands).
813 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
814 | 2613076 | if (RPRElemIsVar(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
815 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
816 | 2613076 | bool matched; | 24cfb8dRow pattern recognition patch (executor and commands).
817 | 2613076 | int depth = elem->depth; | 24cfb8dRow pattern recognition patch (executor and commands).
818 | 2613076 | int32 count = state->counts[depth]; | 24cfb8dRow pattern recognition patch (executor and commands).
819 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
820 | 2613076 | matched = nfa_eval_var_match(winstate, elem, varMatched); | 24cfb8dRow pattern recognition patch (executor and commands).
821 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
822 | 2613076 | if (matched) | 24cfb8dRow pattern recognition patch (executor and commands).
823 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
824 | - | /* | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
825 | - | * Increment count, saturating at RPR_COUNT_INF to avoid int32 | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
826 | - | * overflow; a saturated count then compares as "unbounded". | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
827 | - | */ | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
828 | 1383324 | if (count < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
829 | 1383324 | count++; | 24cfb8dRow pattern recognition patch (executor and commands).
830 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
831 | - | /* Max constraint should not be exceeded */ | 24cfb8dRow pattern recognition patch (executor and commands).
832 | 1383324 | Assert(elem->max == RPR_QUANTITY_INF || count <= elem->max); | 24cfb8dRow pattern recognition patch (executor and commands).
833 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
834 | 1383324 | state->counts[depth] = count; | 24cfb8dRow pattern recognition patch (executor and commands).
835 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
836 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
837 | - | * For VAR at max count with END next, advance through END | 24cfb8dRow pattern recognition patch (executor and commands).
838 | - | * chain to reach the absorption comparison point. Only | 0bc60efRename absorption "judgment point" to "comparison point" in comments
839 | - | * deterministic exits (count >= max, max finite) are handled; | 24cfb8dRow pattern recognition patch (executor and commands).
840 | - | * unbounded VARs stay for advance phase. | 24cfb8dRow pattern recognition patch (executor and commands).
841 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
842 | - | * In nested patterns like ((A B){2}){3}, a VAR reaching its | 24cfb8dRow pattern recognition patch (executor and commands).
843 | - | * max triggers an exit cascade: inner END increments inner | 24cfb8dRow pattern recognition patch (executor and commands).
844 | - | * group count, which may itself reach max, requiring an exit | 24cfb8dRow pattern recognition patch (executor and commands).
845 | - | * to the next outer END. The loop below walks this chain. | 24cfb8dRow pattern recognition patch (executor and commands).
846 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
847 | - | * ABSORBABLE_BRANCH marks elements inside the absorbable | 24cfb8dRow pattern recognition patch (executor and commands).
848 | - | * region; ABSORBABLE marks the outermost comparison point | 0bc60efRename absorption "judgment point" to "comparison point" in comments
849 | - | * where count-dominance is evaluated. We chain through | 0bc60efRename absorption "judgment point" to "comparison point" in comments
850 | - | * BRANCH elements until reaching the ABSORBABLE point or an | 0bc60efRename absorption "judgment point" to "comparison point" in comments
851 | - | * element that can still loop (count < max). | 0bc60efRename absorption "judgment point" to "comparison point" in comments
852 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
853 | 1383324 | if (RPRElemIsAbsorbableBranch(elem) && | 24cfb8dRow pattern recognition patch (executor and commands).
854 | 5428 | !RPRElemIsAbsorbable(elem) && | 24cfb8dRow pattern recognition patch (executor and commands).
855 | 5428 | count >= elem->max && | 24cfb8dRow pattern recognition patch (executor and commands).
856 | 4884 | RPRElemIsEnd(&elements[elem->next])) | 24cfb8dRow pattern recognition patch (executor and commands).
857 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
858 | 2284 | RPRPatternElement *endElem = &elements[elem->next]; | 24cfb8dRow pattern recognition patch (executor and commands).
859 | 2284 | int endDepth = endElem->depth; | 24cfb8dRow pattern recognition patch (executor and commands).
860 | 2284 | int32 endCount = state->counts[endDepth]; | 24cfb8dRow pattern recognition patch (executor and commands).
861 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
862 | - | /* Increment group count */ | 24cfb8dRow pattern recognition patch (executor and commands).
863 | 2284 | if (endCount < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
864 | 2284 | endCount++; | 24cfb8dRow pattern recognition patch (executor and commands).
865 | 2284 | Assert(endElem->max == RPR_QUANTITY_INF || | 24cfb8dRow pattern recognition patch (executor and commands).
866 | - | endCount <= endElem->max); | 24cfb8dRow pattern recognition patch (executor and commands).
867 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
868 | 2284 | state->elemIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
869 | 2284 | state->counts[endDepth] = endCount; | 24cfb8dRow pattern recognition patch (executor and commands).
870 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
871 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
872 | - | * Leaf VAR exited (reached max): clear its own count so | 24cfb8dRow pattern recognition patch (executor and commands).
873 | - | * the next occupant enters with zero, as nfa_advance_var | 24cfb8dRow pattern recognition patch (executor and commands).
874 | - | * does on exit (this inline path replaces that exit). | 24cfb8dRow pattern recognition patch (executor and commands).
875 | - | * depth > endDepth, so this leaves the group count just | 24cfb8dRow pattern recognition patch (executor and commands).
876 | - | * written intact. | 24cfb8dRow pattern recognition patch (executor and commands).
877 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
878 | 2284 | Assert(endDepth < depth); | 24cfb8dRow pattern recognition patch (executor and commands).
879 | 2284 | state->counts[depth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
880 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
881 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
882 | - | * Chain through END elements within the absorbable region | 24cfb8dRow pattern recognition patch (executor and commands).
883 | - | * (ABSORBABLE_BRANCH) until reaching the comparison point | 0bc60efRename absorption "judgment point" to "comparison point" in comments
884 | - | * (ABSORBABLE). Continue only on must-exit path (count | 24cfb8dRow pattern recognition patch (executor and commands).
885 | - | * >= max) with END next. | 24cfb8dRow pattern recognition patch (executor and commands).
886 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
887 | 4816 | while (RPRElemIsAbsorbableBranch(endElem) && | 24cfb8dRow pattern recognition patch (executor and commands).
888 | 1012 | !RPRElemIsAbsorbable(endElem) && | 24cfb8dRow pattern recognition patch (executor and commands).
889 | 3544 | endCount >= endElem->max && | 24cfb8dRow pattern recognition patch (executor and commands).
890 | 464 | RPRElemIsEnd(&elements[endElem->next])) | 24cfb8dRow pattern recognition patch (executor and commands).
891 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
892 | 248 | RPRPatternElement *outerEnd = &elements[endElem->next]; | 24cfb8dRow pattern recognition patch (executor and commands).
893 | 248 | int outerDepth = outerEnd->depth; | 24cfb8dRow pattern recognition patch (executor and commands).
894 | 248 | int32 outerCount = state->counts[outerDepth]; | 24cfb8dRow pattern recognition patch (executor and commands).
895 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
896 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
897 | - | * Exit this intermediate group: clear its own count | 24cfb8dRow pattern recognition patch (executor and commands).
898 | - | * (count-clear policy). It sits below the absorbable | 24cfb8dRow pattern recognition patch (executor and commands).
899 | - | * comparison point, so it is excluded from the | 0bc60efRename absorption "judgment point" to "comparison point" in comments
900 | - | * dominance comparison; the comparison point where | 0bc60efRename absorption "judgment point" to "comparison point" in comments
901 | - | * the chain stops keeps its count. | 0bc60efRename absorption "judgment point" to "comparison point" in comments
902 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
903 | 248 | state->counts[endDepth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
904 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
905 | - | /* Increment outer group count */ | 24cfb8dRow pattern recognition patch (executor and commands).
906 | 248 | if (outerCount < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
907 | 248 | outerCount++; | 24cfb8dRow pattern recognition patch (executor and commands).
908 | 248 | Assert(outerEnd->max == RPR_QUANTITY_INF || | 24cfb8dRow pattern recognition patch (executor and commands).
909 | - | outerCount <= outerEnd->max); | 24cfb8dRow pattern recognition patch (executor and commands).
910 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
911 | 248 | state->elemIdx = endElem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
912 | 248 | state->counts[outerDepth] = outerCount; | 24cfb8dRow pattern recognition patch (executor and commands).
913 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
914 | - | /* Advance to next END in chain */ | 24cfb8dRow pattern recognition patch (executor and commands).
915 | 248 | endElem = outerEnd; | 24cfb8dRow pattern recognition patch (executor and commands).
916 | 248 | endDepth = outerDepth; | 24cfb8dRow pattern recognition patch (executor and commands).
917 | 248 | endCount = outerCount; | 24cfb8dRow pattern recognition patch (executor and commands).
918 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
919 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
920 | - | /* else: stay at VAR for advance phase */ | 24cfb8dRow pattern recognition patch (executor and commands).
921 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
922 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
923 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
924 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
925 | - | * Not matched - remove state. Exit alternatives were already | 24cfb8dRow pattern recognition patch (executor and commands).
926 | - | * created by advance phase when count >= min was satisfied. | 24cfb8dRow pattern recognition patch (executor and commands).
927 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
928 | 1229752 | *prevPtr = nextState; | 24cfb8dRow pattern recognition patch (executor and commands).
929 | 1229752 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
930 | 1229752 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
931 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
932 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
933 | - | /* Non-VAR elements: keep as-is for advance phase */ | 24cfb8dRow pattern recognition patch (executor and commands).
934 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
935 | 1383324 | prevPtr = &state->next; | 24cfb8dRow pattern recognition patch (executor and commands).
936 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
937 | 1955156 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_route_to_elem() lines 946-1002
Modified Lines Coverage: 19/19 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
946 | 940340 | nfa_route_to_elem(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
947 | - | RPRNFAState *state, RPRPatternElement *nextElem, | 24cfb8dRow pattern recognition patch (executor and commands).
948 | - | int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
949 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
950 | 940340 | if (RPRElemIsVar(nextElem)) | 24cfb8dRow pattern recognition patch (executor and commands).
951 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
952 | 542156 | RPRNFAState *skipState = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
953 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
954 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
955 | - | * Entry-side check of the count-clear policy: a VAR is always routed | 24cfb8dRow pattern recognition patch (executor and commands).
956 | - | * to with a clean slot. Each element zeroes its own count on exit, | 24cfb8dRow pattern recognition patch (executor and commands).
957 | - | * so a nonzero count here would be a leak from an earlier element | 24cfb8dRow pattern recognition patch (executor and commands).
958 | - | * (see nfa_advance_var / nfa_advance_end exit handling and the inline | 24cfb8dRow pattern recognition patch (executor and commands).
959 | - | * fast path in nfa_match). | 24cfb8dRow pattern recognition patch (executor and commands).
960 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
961 | 542156 | Assert(state->counts[nextElem->depth] == 0); | 24cfb8dRow pattern recognition patch (executor and commands).
962 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
963 | - | /* Create skip state before add_unique, which may free state */ | 24cfb8dRow pattern recognition patch (executor and commands).
964 | 542156 | if (RPRElemCanSkip(nextElem)) | 24cfb8dRow pattern recognition patch (executor and commands).
965 | 134488 | skipState = nfa_state_clone(winstate, nextElem->next, | 24cfb8dRow pattern recognition patch (executor and commands).
966 | 134488 | state->counts, state->isAbsorbable); | 24cfb8dRow pattern recognition patch (executor and commands).
967 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
968 | 134488 | if (skipState != NULL && RPRElemIsReluctant(nextElem)) | 24cfb8dRow pattern recognition patch (executor and commands).
969 | 68 | { | 24cfb8dRow pattern recognition patch (executor and commands).
970 | 120 | RPRNFAState *savedMatch = ctx->matchedState; | 24cfb8dRow pattern recognition patch (executor and commands).
971 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
972 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
973 | - | * Reluctant optional VAR: prefer skipping. Explore the skip path | 24cfb8dRow pattern recognition patch (executor and commands).
974 | - | * first so it outranks the enter (match) path; if it reaches FIN | 24cfb8dRow pattern recognition patch (executor and commands).
975 | - | * the shortest match is found and the enter state is dropped. | 24cfb8dRow pattern recognition patch (executor and commands).
976 | - | * This mirrors the reluctant branch of nfa_advance_begin used by | 24cfb8dRow pattern recognition patch (executor and commands).
977 | - | * the leading-position and optional-group paths. | 24cfb8dRow pattern recognition patch (executor and commands).
978 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
979 | 120 | nfa_advance_state(winstate, ctx, skipState, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
980 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
981 | 120 | if (ctx->matchedState != savedMatch) | 24cfb8dRow pattern recognition patch (executor and commands).
982 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
983 | 52 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
984 | 52 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
985 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
986 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
987 | 68 | nfa_add_state_unique(winstate, ctx, state); | 24cfb8dRow pattern recognition patch (executor and commands).
988 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
989 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
990 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
991 | - | /* Greedy (or non-skippable): enter first, then skip */ | 24cfb8dRow pattern recognition patch (executor and commands).
992 | 542036 | nfa_add_state_unique(winstate, ctx, state); | 24cfb8dRow pattern recognition patch (executor and commands).
993 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
994 | 542036 | if (skipState != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
995 | 134368 | nfa_advance_state(winstate, ctx, skipState, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
996 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
997 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
998 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
999 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1000 | 398184 | nfa_advance_state(winstate, ctx, state, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1001 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1002 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_advance_alt() lines 1010-1050
Modified Lines Coverage: 16/16 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1010 | 26420 | nfa_advance_alt(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
1011 | - | RPRNFAState *state, RPRPatternElement *elem, | 24cfb8dRow pattern recognition patch (executor and commands).
1012 | - | int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1013 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1014 | 26420 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
1015 | 26420 | RPRPatternElement *elements = pattern->elements; | 24cfb8dRow pattern recognition patch (executor and commands).
1016 | 26420 | RPRElemIdx altIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1017 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1018 | 83588 | while (altIdx >= 0) | 24cfb8dRow pattern recognition patch (executor and commands).
1019 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1020 | 57528 | RPRPatternElement *altElem; | 24cfb8dRow pattern recognition patch (executor and commands).
1021 | 57528 | RPRNFAState *newState; | 24cfb8dRow pattern recognition patch (executor and commands).
1022 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1023 | - | /* Branch jump/next links are always -1 or a valid index */ | 24cfb8dRow pattern recognition patch (executor and commands).
1024 | 57528 | Assert(altIdx < pattern->numElements); | 24cfb8dRow pattern recognition patch (executor and commands).
1025 | 57528 | altElem = &elements[altIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1026 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1027 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1028 | - | * Stop if element is outside ALT scope (not a branch). The check | 24cfb8dRow pattern recognition patch (executor and commands).
1029 | - | * fires when the last branch is a quantified group whose BEGIN.jump | 24cfb8dRow pattern recognition patch (executor and commands).
1030 | - | * (set by fillRPRPatternGroup) is preserved -- not overridden by | 24cfb8dRow pattern recognition patch (executor and commands).
1031 | - | * fillRPRPatternAlt, which only links non-last branch heads -- and | 24cfb8dRow pattern recognition patch (executor and commands).
1032 | - | * leads to a post-ALT element. Other branch shapes terminate the | 24cfb8dRow pattern recognition patch (executor and commands).
1033 | - | * walk earlier via altIdx = RPR_ELEMIDX_INVALID. Use <=, not <: the | 24cfb8dRow pattern recognition patch (executor and commands).
1034 | - | * post-ALT element may sit at the same depth as the ALT when the ALT | 24cfb8dRow pattern recognition patch (executor and commands).
1035 | - | * has a sibling at that level. | 24cfb8dRow pattern recognition patch (executor and commands).
1036 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1037 | 57528 | if (altElem->depth <= elem->depth) | 24cfb8dRow pattern recognition patch (executor and commands).
1038 | - | break; | 24cfb8dRow pattern recognition patch (executor and commands).
1039 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1040 | - | /* Create independent state for each branch */ | 24cfb8dRow pattern recognition patch (executor and commands).
1041 | 114336 | newState = nfa_state_clone(winstate, altIdx, | 24cfb8dRow pattern recognition patch (executor and commands).
1042 | 57168 | state->counts, state->isAbsorbable); | 24cfb8dRow pattern recognition patch (executor and commands).
1043 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1044 | - | /* Recursively process this branch before next */ | 24cfb8dRow pattern recognition patch (executor and commands).
1045 | 57168 | nfa_advance_state(winstate, ctx, newState, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1046 | 57168 | altIdx = altElem->jump; | 24cfb8dRow pattern recognition patch (executor and commands).
1047 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1048 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1049 | 26420 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1050 | 26420 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_advance_begin() lines 1062-1124
Modified Lines Coverage: 25/25 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1062 | 19948 | nfa_advance_begin(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
1063 | - | RPRNFAState *state, RPRPatternElement *elem, | 24cfb8dRow pattern recognition patch (executor and commands).
1064 | - | int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1065 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1066 | 19948 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
1067 | 19948 | RPRPatternElement *elements = pattern->elements; | 24cfb8dRow pattern recognition patch (executor and commands).
1068 | 19948 | RPRNFAState *skipState = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1069 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1070 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1071 | - | * Entry-side check of the count-clear policy: the group's own count slot | 24cfb8dRow pattern recognition patch (executor and commands).
1072 | - | * is already zero here. BEGIN is only visited at initial group entry, | 24cfb8dRow pattern recognition patch (executor and commands).
1073 | - | * and the previous occupant of this depth slot cleared it on exit. | 24cfb8dRow pattern recognition patch (executor and commands).
1074 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1075 | 19948 | Assert(state->counts[elem->depth] == 0); | 24cfb8dRow pattern recognition patch (executor and commands).
1076 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1077 | - | /* Optional group: create skip path (but don't route yet) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1078 | 19948 | if (elem->min == 0) | 24cfb8dRow pattern recognition patch (executor and commands).
1079 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1080 | 708 | skipState = nfa_state_clone(winstate, elem->jump, | 24cfb8dRow pattern recognition patch (executor and commands).
1081 | 708 | state->counts, state->isAbsorbable); | 24cfb8dRow pattern recognition patch (executor and commands).
1082 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1083 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1084 | 708 | if (skipState != NULL && RPRElemIsReluctant(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1085 | 20 | { | 24cfb8dRow pattern recognition patch (executor and commands).
1086 | 28 | RPRNFAState *savedMatch = ctx->matchedState; | 24cfb8dRow pattern recognition patch (executor and commands).
1087 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1088 | - | /* Reluctant: skip first (prefer fewer iterations), enter second */ | 24cfb8dRow pattern recognition patch (executor and commands).
1089 | 28 | nfa_route_to_elem(winstate, ctx, skipState, | 24cfb8dRow pattern recognition patch (executor and commands).
1090 | 28 | &elements[elem->jump], currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1091 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1092 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1093 | - | * If skip path reached FIN, shortest match is found. Skip group entry | 24cfb8dRow pattern recognition patch (executor and commands).
1094 | - | * to prevent longer matches. | 24cfb8dRow pattern recognition patch (executor and commands).
1095 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1096 | 28 | if (ctx->matchedState != savedMatch) | 24cfb8dRow pattern recognition patch (executor and commands).
1097 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1098 | 8 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1099 | 8 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
1100 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1101 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1102 | 20 | state->elemIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1103 | 20 | nfa_route_to_elem(winstate, ctx, state, | 24cfb8dRow pattern recognition patch (executor and commands).
1104 | 20 | &elements[state->elemIdx], currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1105 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1106 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1107 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1108 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1109 | - | * Greedy-or-non-nullable: route to the first child. For optional | 24cfb8dRow pattern recognition patch (executor and commands).
1110 | - | * groups (skipState != NULL, greedy min=0) additionally create the | 24cfb8dRow pattern recognition patch (executor and commands).
1111 | - | * skip path; for non-nullable groups (skipState == NULL, min>0) the | 24cfb8dRow pattern recognition patch (executor and commands).
1112 | - | * skip-path action is suppressed by the guard below. | 24cfb8dRow pattern recognition patch (executor and commands).
1113 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1114 | 19920 | state->elemIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1115 | 19920 | nfa_route_to_elem(winstate, ctx, state, | 24cfb8dRow pattern recognition patch (executor and commands).
1116 | 19920 | &elements[state->elemIdx], currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1117 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1118 | 19920 | if (skipState != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1119 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1120 | 680 | nfa_route_to_elem(winstate, ctx, skipState, | 24cfb8dRow pattern recognition patch (executor and commands).
1121 | 680 | &elements[elem->jump], currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1122 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1123 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1124 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_advance_end() lines 1133-1307
Modified Lines Coverage: 58/62 lines (93.5%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1133 | 12632 | nfa_advance_end(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
1134 | - | RPRNFAState *state, RPRPatternElement *elem, | 24cfb8dRow pattern recognition patch (executor and commands).
1135 | - | int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1136 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1137 | 12632 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
1138 | 12632 | RPRPatternElement *elements = pattern->elements; | 24cfb8dRow pattern recognition patch (executor and commands).
1139 | 12632 | int depth = elem->depth; | 24cfb8dRow pattern recognition patch (executor and commands).
1140 | 12632 | int32 count = state->counts[depth]; | 24cfb8dRow pattern recognition patch (executor and commands).
1141 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1142 | 12632 | if (count < elem->min) | 24cfb8dRow pattern recognition patch (executor and commands).
1143 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1144 | 3984 | RPRPatternElement *jumpElem; | 24cfb8dRow pattern recognition patch (executor and commands).
1145 | 3984 | RPRNFAState *ffState = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1146 | 3984 | RPRPatternElement *nextElem = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1147 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1148 | - | /*---------- | 24cfb8dRow pattern recognition patch (executor and commands).
1149 | - | * Two paths are explored when the group body is nullable | 24cfb8dRow pattern recognition patch (executor and commands).
1150 | - | * (RPR_ELEM_EMPTY_LOOP): | 24cfb8dRow pattern recognition patch (executor and commands).
1151 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
1152 | - | * 1. Loop-back path: attempt real matches in the next iteration | 24cfb8dRow pattern recognition patch (executor and commands).
1153 | - | * (state, modified below). | 24cfb8dRow pattern recognition patch (executor and commands).
1154 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
1155 | - | * 2. Fast-forward path: skip directly to after the group, treating | 24cfb8dRow pattern recognition patch (executor and commands).
1156 | - | * all remaining required iterations as empty matches (ffState). | 24cfb8dRow pattern recognition patch (executor and commands).
1157 | - | * Route to elem->next (not nfa_advance_end) to avoid creating | 24cfb8dRow pattern recognition patch (executor and commands).
1158 | - | * competing greedy/reluctant loop states. | 24cfb8dRow pattern recognition patch (executor and commands).
1159 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
1160 | - | * Greedy prefers the loop-back first (more iterations); reluctant | 24cfb8dRow pattern recognition patch (executor and commands).
1161 | - | * prefers the fast-forward (exit) first and, if it reaches FIN, drops | 24cfb8dRow pattern recognition patch (executor and commands).
1162 | - | * the loop-back so a longer match cannot replace the shortest one -- | 24cfb8dRow pattern recognition patch (executor and commands).
1163 | - | * mirroring the min<=count<max branch below. The ffState snapshot is | 24cfb8dRow pattern recognition patch (executor and commands).
1164 | - | * taken BEFORE modifying state, since both paths diverge from here. | 24cfb8dRow pattern recognition patch (executor and commands).
1165 | - | *---------- | 24cfb8dRow pattern recognition patch (executor and commands).
1166 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1167 | 3984 | if (RPRElemCanEmptyLoop(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1168 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1169 | 464 | ffState = nfa_state_clone(winstate, state->elemIdx, | 24cfb8dRow pattern recognition patch (executor and commands).
1170 | 232 | state->counts, state->isAbsorbable); | 24cfb8dRow pattern recognition patch (executor and commands).
1171 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1172 | - | /* Exit the group: clear its own count (count-clear policy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1173 | 232 | ffState->counts[depth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
1174 | 232 | ffState->elemIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1175 | 232 | nextElem = &elements[ffState->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1176 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1177 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1178 | - | * Unlike the must-exit path, no isAbsorbable update is needed: | 24cfb8dRow pattern recognition patch (executor and commands).
1179 | - | * the fast-forward path runs only for EMPTY_LOOP (nullable) | 24cfb8dRow pattern recognition patch (executor and commands).
1180 | - | * groups, which are never inside an absorbable region, so | 24cfb8dRow pattern recognition patch (executor and commands).
1181 | - | * isAbsorbable is already false here. | 24cfb8dRow pattern recognition patch (executor and commands).
1182 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1183 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1184 | - | /* END->END: increment outer END's count */ | 24cfb8dRow pattern recognition patch (executor and commands).
1185 | 232 | if (RPRElemIsEnd(nextElem) && | 24cfb8dRow pattern recognition patch (executor and commands).
1186 | 0 | ffState->counts[nextElem->depth] < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1187 | 0 | ffState->counts[nextElem->depth]++; | 24cfb8dRow pattern recognition patch (executor and commands).
1188 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1189 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1190 | - | /* Prepare the loop-back state */ | 24cfb8dRow pattern recognition patch (executor and commands).
1191 | 3984 | state->elemIdx = elem->jump; | 24cfb8dRow pattern recognition patch (executor and commands).
1192 | 3984 | jumpElem = &elements[state->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1193 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1194 | 3984 | if (ffState != NULL && RPRElemIsReluctant(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1195 | 0 | { | 24cfb8dRow pattern recognition patch (executor and commands).
1196 | 52 | RPRNFAState *savedMatch = ctx->matchedState; | 24cfb8dRow pattern recognition patch (executor and commands).
1197 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1198 | - | /* Reluctant: take the fast-forward (exit) first */ | 24cfb8dRow pattern recognition patch (executor and commands).
1199 | 52 | nfa_route_to_elem(winstate, ctx, ffState, nextElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1200 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1201 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1202 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1203 | - | * If the exit reached FIN, the shortest match is found. Skip the | 24cfb8dRow pattern recognition patch (executor and commands).
1204 | - | * loop-back to prevent longer matches from replacing it. | 24cfb8dRow pattern recognition patch (executor and commands).
1205 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1206 | 52 | if (ctx->matchedState != savedMatch) | 24cfb8dRow pattern recognition patch (executor and commands).
1207 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1208 | 52 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1209 | 52 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
1210 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1211 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1212 | - | /* Loop-back second */ | 24cfb8dRow pattern recognition patch (executor and commands).
1213 | 0 | nfa_route_to_elem(winstate, ctx, state, jumpElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1214 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1215 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1216 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1217 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1218 | - | /* Greedy (or non-nullable): loop-back first, fast-forward second */ | 24cfb8dRow pattern recognition patch (executor and commands).
1219 | 3932 | nfa_route_to_elem(winstate, ctx, state, jumpElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1220 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1221 | 3932 | if (ffState != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1222 | 180 | nfa_route_to_elem(winstate, ctx, ffState, nextElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1223 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1224 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1225 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1226 | 8648 | else if (elem->max != RPR_QUANTITY_INF && count >= elem->max) | 24cfb8dRow pattern recognition patch (executor and commands).
1227 | 484 | { | 24cfb8dRow pattern recognition patch (executor and commands).
1228 | - | /* Must exit: reached max iterations. */ | 24cfb8dRow pattern recognition patch (executor and commands).
1229 | 484 | RPRPatternElement *nextElem; | 24cfb8dRow pattern recognition patch (executor and commands).
1230 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1231 | - | /* Exit: clear the group's own count (count-clear policy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1232 | 484 | state->counts[depth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
1233 | 484 | state->elemIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1234 | 484 | nextElem = &elements[state->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1235 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1236 | - | /* Update isAbsorbable for target element (monotonic) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1237 | 484 | state->isAbsorbable = state->isAbsorbable && | 24cfb8dRow pattern recognition patch (executor and commands).
1238 | 216 | RPRElemIsAbsorbableBranch(nextElem); | 24cfb8dRow pattern recognition patch (executor and commands).
1239 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1240 | - | /* END->END: increment outer END's count */ | 24cfb8dRow pattern recognition patch (executor and commands).
1241 | 484 | if (RPRElemIsEnd(nextElem) && state->counts[nextElem->depth] < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1242 | 16 | state->counts[nextElem->depth]++; | 24cfb8dRow pattern recognition patch (executor and commands).
1243 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1244 | 484 | nfa_route_to_elem(winstate, ctx, state, nextElem, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1245 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1246 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1247 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1248 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1249 | - | * Between min and max (with at least one iteration) - can exit or | 24cfb8dRow pattern recognition patch (executor and commands).
1250 | - | * loop. Greedy: loop first (prefer more iterations). Reluctant: exit | 24cfb8dRow pattern recognition patch (executor and commands).
1251 | - | * first (prefer fewer iterations). | 24cfb8dRow pattern recognition patch (executor and commands).
1252 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1253 | 8164 | RPRNFAState *exitState; | 24cfb8dRow pattern recognition patch (executor and commands).
1254 | 8164 | RPRPatternElement *jumpElem; | 24cfb8dRow pattern recognition patch (executor and commands).
1255 | 8164 | RPRPatternElement *nextElem; | 24cfb8dRow pattern recognition patch (executor and commands).
1256 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1257 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1258 | - | * Create exit state first (need original counts before modifying | 24cfb8dRow pattern recognition patch (executor and commands).
1259 | - | * state) | 24cfb8dRow pattern recognition patch (executor and commands).
1260 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1261 | 16328 | exitState = nfa_state_clone(winstate, elem->next, | 24cfb8dRow pattern recognition patch (executor and commands).
1262 | 8164 | state->counts, state->isAbsorbable); | 24cfb8dRow pattern recognition patch (executor and commands).
1263 | - | /* Exit branch: clear the group's own count (count-clear policy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1264 | 8164 | exitState->counts[depth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
1265 | 8164 | nextElem = &elements[exitState->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1266 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1267 | - | /* END->END: increment outer END's count */ | 24cfb8dRow pattern recognition patch (executor and commands).
1268 | 8164 | if (RPRElemIsEnd(nextElem) && exitState->counts[nextElem->depth] < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1269 | 84 | exitState->counts[nextElem->depth]++; | 24cfb8dRow pattern recognition patch (executor and commands).
1270 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1271 | - | /* Prepare loop state */ | 24cfb8dRow pattern recognition patch (executor and commands).
1272 | 8164 | state->elemIdx = elem->jump; | 24cfb8dRow pattern recognition patch (executor and commands).
1273 | 8164 | jumpElem = &elements[state->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1274 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1275 | 8164 | if (RPRElemIsReluctant(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1276 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1277 | 40 | RPRNFAState *savedMatch = ctx->matchedState; | 24cfb8dRow pattern recognition patch (executor and commands).
1278 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1279 | - | /* Exit first (preferred for reluctant) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1280 | 40 | nfa_route_to_elem(winstate, ctx, exitState, nextElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1281 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1282 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1283 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1284 | - | * If exit path reached FIN, shortest match is found. Skip loop to | 24cfb8dRow pattern recognition patch (executor and commands).
1285 | - | * prevent longer matches from replacing it. | 24cfb8dRow pattern recognition patch (executor and commands).
1286 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1287 | 40 | if (ctx->matchedState != savedMatch) | 24cfb8dRow pattern recognition patch (executor and commands).
1288 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1289 | 28 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1290 | 28 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
1291 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1292 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1293 | - | /* Loop second */ | 24cfb8dRow pattern recognition patch (executor and commands).
1294 | 12 | nfa_route_to_elem(winstate, ctx, state, jumpElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1295 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1296 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1297 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1298 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1299 | - | /* Loop first (preferred for greedy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1300 | 8124 | nfa_route_to_elem(winstate, ctx, state, jumpElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1301 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1302 | - | /* Exit second */ | 24cfb8dRow pattern recognition patch (executor and commands).
1303 | 8124 | nfa_route_to_elem(winstate, ctx, exitState, nextElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1304 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1305 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1306 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1307 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_advance_var() lines 1316-1450
Modified Lines Coverage: 52/52 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1316 | 2159060 | nfa_advance_var(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
1317 | - | RPRNFAState *state, RPRPatternElement *elem, | 24cfb8dRow pattern recognition patch (executor and commands).
1318 | - | int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1319 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1320 | 2159060 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
1321 | 2159060 | RPRPatternElement *elements = pattern->elements; | 24cfb8dRow pattern recognition patch (executor and commands).
1322 | 2159060 | int depth = elem->depth; | 24cfb8dRow pattern recognition patch (executor and commands).
1323 | 2159060 | int32 count = state->counts[depth]; | 24cfb8dRow pattern recognition patch (executor and commands).
1324 | 2159060 | bool canLoop = (elem->max == RPR_QUANTITY_INF || count < elem->max); | 24cfb8dRow pattern recognition patch (executor and commands).
1325 | 2159060 | bool canExit = (count >= elem->min); | 24cfb8dRow pattern recognition patch (executor and commands).
1326 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1327 | - | /* min <= max, so !canExit (count < min) implies canLoop (count < max) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1328 | 2159060 | Assert(canLoop || canExit); | 24cfb8dRow pattern recognition patch (executor and commands).
1329 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1330 | - | /* elem->next must be a valid index for any reachable VAR */ | 24cfb8dRow pattern recognition patch (executor and commands).
1331 | 2159060 | Assert(elem->next >= 0 && elem->next < pattern->numElements); | 24cfb8dRow pattern recognition patch (executor and commands).
1332 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1333 | 2159060 | if (canLoop && canExit) | 24cfb8dRow pattern recognition patch (executor and commands).
1334 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1335 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1336 | - | * Both loop and exit possible. Greedy: loop first (prefer longer | 24cfb8dRow pattern recognition patch (executor and commands).
1337 | - | * match). Reluctant: exit first (prefer shorter match). | 24cfb8dRow pattern recognition patch (executor and commands).
1338 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1339 | 815228 | RPRNFAState *cloneState; | 24cfb8dRow pattern recognition patch (executor and commands).
1340 | 815228 | RPRPatternElement *nextElem; | 24cfb8dRow pattern recognition patch (executor and commands).
1341 | 815228 | bool reluctant = RPRElemIsReluctant(elem); | 24cfb8dRow pattern recognition patch (executor and commands).
1342 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1343 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1344 | - | * Clone state for the first-priority path. For greedy, clone is the | 24cfb8dRow pattern recognition patch (executor and commands).
1345 | - | * loop state; for reluctant, clone is the exit state. | 24cfb8dRow pattern recognition patch (executor and commands).
1346 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1347 | 815228 | if (reluctant) | 24cfb8dRow pattern recognition patch (executor and commands).
1348 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1349 | 540 | RPRNFAState *savedMatch = ctx->matchedState; | 24cfb8dRow pattern recognition patch (executor and commands).
1350 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1351 | - | /* Clone for exit, original stays for loop */ | 24cfb8dRow pattern recognition patch (executor and commands).
1352 | 1080 | cloneState = nfa_state_clone(winstate, elem->next, | 24cfb8dRow pattern recognition patch (executor and commands).
1353 | 540 | state->counts, state->isAbsorbable); | 24cfb8dRow pattern recognition patch (executor and commands).
1354 | - | /* Exit: clear the VAR's own count (count-clear policy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1355 | 540 | cloneState->counts[depth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
1356 | 540 | nextElem = &elements[cloneState->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1357 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1358 | - | /* When exiting directly to an outer END, increment its count */ | 24cfb8dRow pattern recognition patch (executor and commands).
1359 | 540 | if (RPRElemIsEnd(nextElem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1360 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1361 | 28 | if (cloneState->counts[nextElem->depth] < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1362 | 28 | cloneState->counts[nextElem->depth]++; | 24cfb8dRow pattern recognition patch (executor and commands).
1363 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1364 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1365 | - | /* Exit first (preferred for reluctant) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1366 | 540 | nfa_route_to_elem(winstate, ctx, cloneState, nextElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1367 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1368 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1369 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1370 | - | * If exit path reached FIN, the shortest match is found. Skip | 24cfb8dRow pattern recognition patch (executor and commands).
1371 | - | * loop state to prevent longer matches from replacing it. | 24cfb8dRow pattern recognition patch (executor and commands).
1372 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1373 | 540 | if (ctx->matchedState != savedMatch) | 24cfb8dRow pattern recognition patch (executor and commands).
1374 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1375 | 288 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1376 | 288 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
1377 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1378 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1379 | - | /* Loop second */ | 24cfb8dRow pattern recognition patch (executor and commands).
1380 | 252 | nfa_add_state_unique(winstate, ctx, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1381 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1382 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1383 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1384 | - | /* Clone for loop, original used for exit */ | 24cfb8dRow pattern recognition patch (executor and commands).
1385 | 1629376 | cloneState = nfa_state_clone(winstate, state->elemIdx, | 24cfb8dRow pattern recognition patch (executor and commands).
1386 | 814688 | state->counts, state->isAbsorbable); | 24cfb8dRow pattern recognition patch (executor and commands).
1387 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1388 | - | /* Loop first (preferred for greedy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1389 | 814688 | nfa_add_state_unique(winstate, ctx, cloneState); | 24cfb8dRow pattern recognition patch (executor and commands).
1390 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1391 | - | /* Exit second: clear the VAR's own count (count-clear policy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1392 | 814688 | state->counts[depth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
1393 | 814688 | state->elemIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1394 | 814688 | nextElem = &elements[state->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1395 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1396 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1397 | - | * Update isAbsorbable for target element (monotonic: AND | 24cfb8dRow pattern recognition patch (executor and commands).
1398 | - | * preserves false) | 24cfb8dRow pattern recognition patch (executor and commands).
1399 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1400 | 814688 | state->isAbsorbable = state->isAbsorbable && | 24cfb8dRow pattern recognition patch (executor and commands).
1401 | 372424 | RPRElemIsAbsorbableBranch(nextElem); | 24cfb8dRow pattern recognition patch (executor and commands).
1402 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1403 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1404 | - | * When exiting directly to an outer END, increment its iteration | 24cfb8dRow pattern recognition patch (executor and commands).
1405 | - | * count. Simple VARs (min=max=1) handle this via inline advance | 24cfb8dRow pattern recognition patch (executor and commands).
1406 | - | * in nfa_match, but quantified VARs bypass that path. | 24cfb8dRow pattern recognition patch (executor and commands).
1407 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1408 | 814688 | if (RPRElemIsEnd(nextElem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1409 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1410 | 324 | if (state->counts[nextElem->depth] < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1411 | 324 | state->counts[nextElem->depth]++; | 24cfb8dRow pattern recognition patch (executor and commands).
1412 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1413 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1414 | 814688 | nfa_route_to_elem(winstate, ctx, state, nextElem, | 24cfb8dRow pattern recognition patch (executor and commands).
1415 | - | currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1416 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1417 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1418 | 1343832 | else if (canLoop) | 24cfb8dRow pattern recognition patch (executor and commands).
1419 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1420 | - | /* Loop only: keep state as-is */ | 24cfb8dRow pattern recognition patch (executor and commands).
1421 | 1260316 | nfa_add_state_unique(winstate, ctx, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1422 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1423 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1424 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1425 | - | /* Exit only: advance to next element (canExit necessarily true) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1426 | 83516 | RPRPatternElement *nextElem; | 24cfb8dRow pattern recognition patch (executor and commands).
1427 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1428 | 83516 | Assert(canExit); | 24cfb8dRow pattern recognition patch (executor and commands).
1429 | - | /* Exit: clear the VAR's own count (count-clear policy) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1430 | 83516 | state->counts[depth] = 0; | 24cfb8dRow pattern recognition patch (executor and commands).
1431 | 83516 | state->elemIdx = elem->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1432 | 83516 | nextElem = &elements[state->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1433 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1434 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1435 | - | * Update isAbsorbable for target element (monotonic: AND preserves | 24cfb8dRow pattern recognition patch (executor and commands).
1436 | - | * false) | 24cfb8dRow pattern recognition patch (executor and commands).
1437 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1438 | 83516 | state->isAbsorbable = state->isAbsorbable && | 24cfb8dRow pattern recognition patch (executor and commands).
1439 | 2508 | RPRElemIsAbsorbableBranch(nextElem); | 24cfb8dRow pattern recognition patch (executor and commands).
1440 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1441 | - | /* See comment above: increment outer END count for quantified VARs */ | 24cfb8dRow pattern recognition patch (executor and commands).
1442 | 83516 | if (RPRElemIsEnd(nextElem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1443 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1444 | 10360 | if (state->counts[nextElem->depth] < RPR_COUNT_INF) | 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1445 | 10360 | state->counts[nextElem->depth]++; | 24cfb8dRow pattern recognition patch (executor and commands).
1446 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1447 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1448 | 83516 | nfa_route_to_elem(winstate, ctx, state, nextElem, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1449 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1450 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_advance_state() lines 1459-1513
Modified Lines Coverage: 28/28 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1459 | 2581172 | nfa_advance_state(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
1460 | - | RPRNFAState *state, int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1461 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1462 | 2581172 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
1463 | 2581172 | RPRPatternElement *elem; | 24cfb8dRow pattern recognition patch (executor and commands).
1464 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1465 | 2581172 | Assert(state->elemIdx >= 0 && state->elemIdx < pattern->numElements); | 24cfb8dRow pattern recognition patch (executor and commands).
1466 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1467 | - | /* Protect against stack overflow for deeply complex patterns */ | 24cfb8dRow pattern recognition patch (executor and commands).
1468 | 2581172 | check_stack_depth(); | 24cfb8dRow pattern recognition patch (executor and commands).
1469 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1470 | - | /* Cycle detection: if this elemIdx was already visited in this DFS, bail */ | 24cfb8dRow pattern recognition patch (executor and commands).
1471 | 2581172 | if (winstate->nfaVisitedElems[WORDNUM(state->elemIdx)] & | 24cfb8dRow pattern recognition patch (executor and commands).
1472 | 2581172 | ((bitmapword) 1 << BITNUM(state->elemIdx))) | 24cfb8dRow pattern recognition patch (executor and commands).
1473 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1474 | 488 | nfa_state_free(winstate, state); | 24cfb8dRow pattern recognition patch (executor and commands).
1475 | 488 | return; | 24cfb8dRow pattern recognition patch (executor and commands).
1476 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1477 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1478 | 2580684 | elem = &pattern->elements[state->elemIdx]; | 24cfb8dRow pattern recognition patch (executor and commands).
1479 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1480 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1481 | - | * Mark epsilon elements (END, ALT, BEGIN, FIN) in visited to prevent | 24cfb8dRow pattern recognition patch (executor and commands).
1482 | - | * infinite epsilon cycles. VAR elements are marked later when added to | 24cfb8dRow pattern recognition patch (executor and commands).
1483 | - | * the state list (nfa_add_state_unique), allowing legitimate loop-back to | 24cfb8dRow pattern recognition patch (executor and commands).
1484 | - | * the same VAR in a new iteration. | 24cfb8dRow pattern recognition patch (executor and commands).
1485 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1486 | 2580684 | if (!RPRElemIsVar(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1487 | 421624 | nfa_mark_visited(winstate, state->elemIdx); | 24cfb8dRow pattern recognition patch (executor and commands).
1488 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1489 | 2580684 | switch (elem->varId) | 24cfb8dRow pattern recognition patch (executor and commands).
1490 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1491 | 362624 | case RPR_VARID_FIN: | 24cfb8dRow pattern recognition patch (executor and commands).
1492 | - | /* FIN: record match */ | 24cfb8dRow pattern recognition patch (executor and commands).
1493 | 362624 | nfa_add_matched_state(winstate, ctx, state, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1494 | 362624 | break; | 24cfb8dRow pattern recognition patch (executor and commands).
1495 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1496 | 26420 | case RPR_VARID_ALT: | 24cfb8dRow pattern recognition patch (executor and commands).
1497 | 26420 | nfa_advance_alt(winstate, ctx, state, elem, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1498 | 26420 | break; | 24cfb8dRow pattern recognition patch (executor and commands).
1499 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1500 | 19948 | case RPR_VARID_BEGIN: | 24cfb8dRow pattern recognition patch (executor and commands).
1501 | 19948 | nfa_advance_begin(winstate, ctx, state, elem, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1502 | 19948 | break; | 24cfb8dRow pattern recognition patch (executor and commands).
1503 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1504 | 12632 | case RPR_VARID_END: | 24cfb8dRow pattern recognition patch (executor and commands).
1505 | 12632 | nfa_advance_end(winstate, ctx, state, elem, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1506 | 12632 | break; | 24cfb8dRow pattern recognition patch (executor and commands).
1507 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1508 | 2159060 | default: | 24cfb8dRow pattern recognition patch (executor and commands).
1509 | - | /* VAR element */ | 24cfb8dRow pattern recognition patch (executor and commands).
1510 | 2159060 | nfa_advance_var(winstate, ctx, state, elem, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1511 | 2159060 | break; | 24cfb8dRow pattern recognition patch (executor and commands).
1512 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1513 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_advance() lines 1525-1583
Modified Lines Coverage: 22/22 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1525 | 2005184 | nfa_advance(WindowAggState *winstate, RPRNFAContext *ctx, int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1526 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1527 | 2005184 | RPRNFAState *states = ctx->states; | 24cfb8dRow pattern recognition patch (executor and commands).
1528 | 2005184 | RPRNFAState *state; | 24cfb8dRow pattern recognition patch (executor and commands).
1529 | 2005184 | RPRNFAState *savedMatchedState; | 24cfb8dRow pattern recognition patch (executor and commands).
1530 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1531 | 2005184 | ctx->states = NULL; /* Will rebuild */ | 24cfb8dRow pattern recognition patch (executor and commands).
1532 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1533 | - | /* Process each state in lexical order (DFS order from previous advance) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1534 | 3633892 | while (states != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1535 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1536 | 1991332 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
1537 | 1991332 | savedMatchedState = ctx->matchedState; | 24cfb8dRow pattern recognition patch (executor and commands).
1538 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1539 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1540 | - | * Clear visited bitmap before each state's DFS expansion. Only the | 24cfb8dRow pattern recognition patch (executor and commands).
1541 | - | * range touched since the previous reset (tracked via the high-water | 24cfb8dRow pattern recognition patch (executor and commands).
1542 | - | * marks updated in nfa_mark_visited) needs to be cleared; for small | 24cfb8dRow pattern recognition patch (executor and commands).
1543 | - | * NFAs this is the whole array, but for large NFAs whose DFS only | 24cfb8dRow pattern recognition patch (executor and commands).
1544 | - | * reaches a few elements per advance it avoids walking the full | 24cfb8dRow pattern recognition patch (executor and commands).
1545 | - | * bitmap. | 24cfb8dRow pattern recognition patch (executor and commands).
1546 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1547 | 1991332 | if (winstate->nfaVisitedMaxWord >= winstate->nfaVisitedMinWord) | 24cfb8dRow pattern recognition patch (executor and commands).
1548 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1549 | 1988916 | memset(&winstate->nfaVisitedElems[winstate->nfaVisitedMinWord], 0, | 24cfb8dRow pattern recognition patch (executor and commands).
1550 | - | sizeof(bitmapword) * | 24cfb8dRow pattern recognition patch (executor and commands).
1551 | 1988916 | (winstate->nfaVisitedMaxWord - | 24cfb8dRow pattern recognition patch (executor and commands).
1552 | 1988916 | winstate->nfaVisitedMinWord + 1)); | 24cfb8dRow pattern recognition patch (executor and commands).
1553 | 1988916 | winstate->nfaVisitedMinWord = PG_INT16_MAX; | 24cfb8dRow pattern recognition patch (executor and commands).
1554 | 1988916 | winstate->nfaVisitedMaxWord = -1; | 24cfb8dRow pattern recognition patch (executor and commands).
1555 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1556 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1557 | 1991332 | state = states; | 24cfb8dRow pattern recognition patch (executor and commands).
1558 | 1991332 | states = states->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1559 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1560 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1561 | - | * Boundary contract: state->next is reset to NULL here, before | 24cfb8dRow pattern recognition patch (executor and commands).
1562 | - | * crossing into nfa_advance_state's epsilon-expansion DFS. The inner | 24cfb8dRow pattern recognition patch (executor and commands).
1563 | - | * branches (nfa_advance_var, nfa_advance_begin/end/alt) treat | 24cfb8dRow pattern recognition patch (executor and commands).
1564 | - | * state->next as already-NULL and don't reset it themselves; the | 24cfb8dRow pattern recognition patch (executor and commands).
1565 | - | * other linking site is nfa_add_state_unique, which sets it when | 24cfb8dRow pattern recognition patch (executor and commands).
1566 | - | * appending to ctx->states. | 24cfb8dRow pattern recognition patch (executor and commands).
1567 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1568 | 1991332 | state->next = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1569 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1570 | 1991332 | nfa_advance_state(winstate, ctx, state, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1571 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1572 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1573 | - | * Early termination: if a FIN was newly reached in this advance, | 24cfb8dRow pattern recognition patch (executor and commands).
1574 | - | * remaining old states have worse lexical order and can be pruned. | 24cfb8dRow pattern recognition patch (executor and commands).
1575 | - | * Only check for new FIN arrivals (not ones from previous rows). | 24cfb8dRow pattern recognition patch (executor and commands).
1576 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1577 | 1991332 | if (ctx->matchedState != savedMatchedState && states != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1578 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1579 | 240 | nfa_state_free_list(winstate, states); | 24cfb8dRow pattern recognition patch (executor and commands).
1580 | 240 | break; | 24cfb8dRow pattern recognition patch (executor and commands).
1581 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1582 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1583 | 2005184 | } | 24cfb8dRow pattern recognition patch (executor and commands).

nfa_reevaluate_dependent_vars() lines 1596-1631
Modified Lines Coverage: 19/19 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1596 | 5480 | nfa_reevaluate_dependent_vars(WindowAggState *winstate, RPRNFAContext *ctx, | 24cfb8dRow pattern recognition patch (executor and commands).
1597 | - | int64 currentPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1598 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1599 | 5480 | ExprContext *econtext = winstate->rprContext; | a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1600 | 5480 | int64 saved_match_start = winstate->nav_match_start; | 24cfb8dRow pattern recognition patch (executor and commands).
1601 | 5480 | int64 saved_pos = winstate->currentpos; | 24cfb8dRow pattern recognition patch (executor and commands).
1602 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1603 | - | /* Release the previous evaluation's DEFINE expression memory */ | a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1604 | 5480 | ResetExprContext(econtext); | a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1605 | - |  | a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1606 | - | /* Temporarily set nav_match_start and currentpos for FIRST/LAST */ | 24cfb8dRow pattern recognition patch (executor and commands).
1607 | 5480 | winstate->nav_match_start = ctx->matchStartRow; | 24cfb8dRow pattern recognition patch (executor and commands).
1608 | 5480 | winstate->currentpos = currentPos; | 24cfb8dRow pattern recognition patch (executor and commands).
1609 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1610 | - | /* Invalidate nav_slot cache since match_start changed */ | 24cfb8dRow pattern recognition patch (executor and commands).
1611 | 5480 | winstate->nav_slot_pos = -1; | 24cfb8dRow pattern recognition patch (executor and commands).
1612 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1613 | 16296 | foreach_ptr(ExprState, exprState, winstate->defineClauseExprs) | b848408Tidy up row pattern recognition plumbing
1614 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1615 | 10816 | int varIdx = foreach_current_index(exprState); | 24cfb8dRow pattern recognition patch (executor and commands).
1616 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1617 | 10816 | if (bms_is_member(varIdx, winstate->defineMatchStartDependent)) | 24cfb8dRow pattern recognition patch (executor and commands).
1618 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1619 | 5480 | Datum result; | 24cfb8dRow pattern recognition patch (executor and commands).
1620 | 5480 | bool isnull; | 24cfb8dRow pattern recognition patch (executor and commands).
1621 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1622 | 5480 | result = ExecEvalExpr(exprState, econtext, &isnull); | 24cfb8dRow pattern recognition patch (executor and commands).
1623 | 6276 | winstate->nfaVarMatched[varIdx] = (!isnull && DatumGetBool(result)); | 24cfb8dRow pattern recognition patch (executor and commands).
1624 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1625 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1626 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1627 | - | /* Restore original match_start, currentpos, and invalidate cache */ | 24cfb8dRow pattern recognition patch (executor and commands).
1628 | 5480 | winstate->nav_match_start = saved_match_start; | 24cfb8dRow pattern recognition patch (executor and commands).
1629 | 5480 | winstate->currentpos = saved_pos; | 24cfb8dRow pattern recognition patch (executor and commands).
1630 | 5480 | winstate->nav_slot_pos = -1; | 24cfb8dRow pattern recognition patch (executor and commands).
1631 | 5480 | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRStartContext() lines 1647-1697
Modified Lines Coverage: 22/22 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1647 | 998856 | ExecRPRStartContext(WindowAggState *winstate, int64 startPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1648 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1649 | 998856 | RPRNFAContext *ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1650 | 998856 | RPRPattern *pattern = winstate->rpPattern; | 24cfb8dRow pattern recognition patch (executor and commands).
1651 | 998856 | RPRPatternElement *elem; | 24cfb8dRow pattern recognition patch (executor and commands).
1652 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1653 | 998856 | ctx = nfa_context_make(winstate); | 24cfb8dRow pattern recognition patch (executor and commands).
1654 | 998856 | ctx->matchStartRow = startPos; | 24cfb8dRow pattern recognition patch (executor and commands).
1655 | 998856 | ctx->states = nfa_state_make(winstate); /* initial state at elem 0 */ | 24cfb8dRow pattern recognition patch (executor and commands).
1656 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1657 | 998856 | elem = &pattern->elements[0]; | 24cfb8dRow pattern recognition patch (executor and commands).
1658 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1659 | 998856 | if (RPRElemIsAbsorbableBranch(elem)) | 24cfb8dRow pattern recognition patch (executor and commands).
1660 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1661 | 903624 | ctx->states->isAbsorbable = true; | 24cfb8dRow pattern recognition patch (executor and commands).
1662 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1663 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1664 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1665 | 95232 | ctx->hasAbsorbableState = false; | 24cfb8dRow pattern recognition patch (executor and commands).
1666 | 95232 | ctx->allStatesAbsorbable = false; | 24cfb8dRow pattern recognition patch (executor and commands).
1667 | 95232 | ctx->states->isAbsorbable = false; | 24cfb8dRow pattern recognition patch (executor and commands).
1668 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1669 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1670 | - | /* | 0ed285dDrive RPR row pattern matching once per row
1671 | - | * Add to tail of active context list (doubly-linked, oldest-first). | 0ed285dDrive RPR row pattern matching once per row
1672 | - | * matchStartRow is nondecreasing along the list, so the head holds the | 0ed285dDrive RPR row pattern matching once per row
1673 | - | * smallest -- an ordering other code relies on. | 0ed285dDrive RPR row pattern matching once per row
1674 | - | */ | 0ed285dDrive RPR row pattern matching once per row
1675 | 998856 | Assert(winstate->nfaContextTail == NULL || | 0ed285dDrive RPR row pattern matching once per row
1676 | - | startPos >= winstate->nfaContextTail->matchStartRow); | 0ed285dDrive RPR row pattern matching once per row
1677 | 998856 | ctx->prev = winstate->nfaContextTail; | 24cfb8dRow pattern recognition patch (executor and commands).
1678 | 998856 | ctx->next = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1679 | 998856 | if (winstate->nfaContextTail != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1680 | 988588 | winstate->nfaContextTail->next = ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1681 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1682 | 10268 | winstate->nfaContext = ctx; /* first context becomes head */ | 24cfb8dRow pattern recognition patch (executor and commands).
1683 | 998856 | winstate->nfaContextTail = ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1684 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1685 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1686 | - | * Initial advance (divergence): expand ALT branches and create exit | 24cfb8dRow pattern recognition patch (executor and commands).
1687 | - | * states for VAR elements with min=0. This prepares the context for the | 24cfb8dRow pattern recognition patch (executor and commands).
1688 | - | * first row's match phase. | 24cfb8dRow pattern recognition patch (executor and commands).
1689 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
1690 | - | * Use startPos - 1 as currentPos since no row has been consumed yet. If | 24cfb8dRow pattern recognition patch (executor and commands).
1691 | - | * FIN is reached via epsilon transitions, matchEndRow = startPos - 1 | 24cfb8dRow pattern recognition patch (executor and commands).
1692 | - | * which is less than matchStartRow, resulting in UNMATCHED treatment. | 24cfb8dRow pattern recognition patch (executor and commands).
1693 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1694 | 998856 | nfa_advance(winstate, ctx, startPos - 1); | 24cfb8dRow pattern recognition patch (executor and commands).
1695 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1696 | 998856 | return ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1697 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRGetHeadContext() lines 1706-1718
Modified Lines Coverage: 4/4 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1706 | 105988 | ExecRPRGetHeadContext(WindowAggState *winstate, int64 pos) | 24cfb8dRow pattern recognition patch (executor and commands).
1707 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1708 | 105988 | RPRNFAContext *ctx = winstate->nfaContext; | 24cfb8dRow pattern recognition patch (executor and commands).
1709 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1710 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1711 | - | * Contexts are sorted by matchStartRow ascending. If the head context | 24cfb8dRow pattern recognition patch (executor and commands).
1712 | - | * doesn't match pos, no context exists for this position. | 24cfb8dRow pattern recognition patch (executor and commands).
1713 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1714 | 105988 | if (ctx == NULL || ctx->matchStartRow != pos) | 24cfb8dRow pattern recognition patch (executor and commands).
1715 | 16312 | return NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1716 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1717 | - | return ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1718 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRFreeContext() lines 1727-1744
Modified Lines Coverage: 12/12 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1727 | 995004 | ExecRPRFreeContext(WindowAggState *winstate, RPRNFAContext *ctx) | 24cfb8dRow pattern recognition patch (executor and commands).
1728 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1729 | - | /* Unlink from active list first */ | 24cfb8dRow pattern recognition patch (executor and commands).
1730 | 995004 | nfa_unlink_context(winstate, ctx); | 24cfb8dRow pattern recognition patch (executor and commands).
1731 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1732 | - | /* Update statistics */ | 24cfb8dRow pattern recognition patch (executor and commands).
1733 | 995004 | winstate->nfaContextsActive--; | 24cfb8dRow pattern recognition patch (executor and commands).
1734 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1735 | 995004 | if (ctx->states != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1736 | 390520 | nfa_state_free_list(winstate, ctx->states); | 24cfb8dRow pattern recognition patch (executor and commands).
1737 | 995004 | if (ctx->matchedState != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1738 | 37912 | nfa_state_free(winstate, ctx->matchedState); | 24cfb8dRow pattern recognition patch (executor and commands).
1739 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1740 | 995004 | ctx->states = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1741 | 995004 | ctx->matchedState = NULL; | 24cfb8dRow pattern recognition patch (executor and commands).
1742 | 995004 | ctx->next = winstate->nfaContextFree; | 24cfb8dRow pattern recognition patch (executor and commands).
1743 | 995004 | winstate->nfaContextFree = ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1744 | 995004 | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRRecordContextSuccess() lines 1752-1758
Modified Lines Coverage: 4/4 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1752 | 37128 | ExecRPRRecordContextSuccess(WindowAggState *winstate, int64 matchLen) | 24cfb8dRow pattern recognition patch (executor and commands).
1753 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1754 | 37128 | winstate->nfaMatchesSucceeded++; | 24cfb8dRow pattern recognition patch (executor and commands).
1755 | 37128 | nfa_update_length_stats(winstate->nfaMatchesSucceeded, | 24cfb8dRow pattern recognition patch (executor and commands).
1756 | - | &winstate->nfaMatchLen, | 24cfb8dRow pattern recognition patch (executor and commands).
1757 | - | matchLen); | 24cfb8dRow pattern recognition patch (executor and commands).
1758 | 37128 | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRRecordContextFailure() lines 1768-1781
Modified Lines Coverage: 6/6 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1768 | 258652 | ExecRPRRecordContextFailure(WindowAggState *winstate, int64 failedLen) | 24cfb8dRow pattern recognition patch (executor and commands).
1769 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1770 | 258652 | if (failedLen == 1) | 24cfb8dRow pattern recognition patch (executor and commands).
1771 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1772 | 227644 | winstate->nfaContextsPruned++; | 24cfb8dRow pattern recognition patch (executor and commands).
1773 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1774 | - | else | 24cfb8dRow pattern recognition patch (executor and commands).
1775 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1776 | 31008 | winstate->nfaMatchesFailed++; | 24cfb8dRow pattern recognition patch (executor and commands).
1777 | 31008 | nfa_update_length_stats(winstate->nfaMatchesFailed, | 24cfb8dRow pattern recognition patch (executor and commands).
1778 | - | &winstate->nfaFailLen, | 24cfb8dRow pattern recognition patch (executor and commands).
1779 | - | failedLen); | 24cfb8dRow pattern recognition patch (executor and commands).
1780 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1781 | 258652 | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRProcessRow() lines 1792-1903
Modified Lines Coverage: 36/36 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1792 | 988588 | ExecRPRProcessRow(WindowAggState *winstate, int64 currentPos, | 24cfb8dRow pattern recognition patch (executor and commands).
1793 | - | bool hasLimitedFrame, int64 frameOffset) | 24cfb8dRow pattern recognition patch (executor and commands).
1794 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1795 | 988588 | RPRNFAContext *ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1796 | 988588 | bool *varMatched = winstate->nfaVarMatched; | 24cfb8dRow pattern recognition patch (executor and commands).
1797 | 988588 | bool hasDependent = !bms_is_empty(winstate->defineMatchStartDependent); | 24cfb8dRow pattern recognition patch (executor and commands).
1798 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1799 | - | /* Allow query cancellation once per row for simple/low-state patterns */ | 24cfb8dRow pattern recognition patch (executor and commands).
1800 | 988588 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
1801 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1802 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1803 | - | * Phase 1: Match all contexts (convergence). Evaluate VAR elements, | 24cfb8dRow pattern recognition patch (executor and commands).
1804 | - | * update counts, remove dead states. | 24cfb8dRow pattern recognition patch (executor and commands).
1805 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1806 | 2929236 | for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) | 24cfb8dRow pattern recognition patch (executor and commands).
1807 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1808 | 1940648 | if (ctx->states == NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1809 | 20 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
1810 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1811 | - | /* Check frame boundary - finalize the context when it is reached */ | 24cfb8dRow pattern recognition patch (executor and commands).
1812 | 1940628 | if (hasLimitedFrame) | 24cfb8dRow pattern recognition patch (executor and commands).
1813 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1814 | 1296 | int64 ctxFrameEnd; | 24cfb8dRow pattern recognition patch (executor and commands).
1815 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1816 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1817 | - | * Clamp to PG_INT64_MAX on overflow. frameOffset can be as large | 24cfb8dRow pattern recognition patch (executor and commands).
1818 | - | * as PG_INT64_MAX (e.g. "ROWS <huge> FOLLOWING"), so add the | 24cfb8dRow pattern recognition patch (executor and commands).
1819 | - | * offset and the trailing +1 in two separately checked steps to | 24cfb8dRow pattern recognition patch (executor and commands).
1820 | - | * avoid signed-integer overflow in the "frameOffset + 1" | 24cfb8dRow pattern recognition patch (executor and commands).
1821 | - | * subexpression. | 24cfb8dRow pattern recognition patch (executor and commands).
1822 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1823 | 1296 | if (pg_add_s64_overflow(ctx->matchStartRow, frameOffset, | 24cfb8dRow pattern recognition patch (executor and commands).
1824 | 1256 | &ctxFrameEnd) || | 24cfb8dRow pattern recognition patch (executor and commands).
1825 | 1256 | pg_add_s64_overflow(ctxFrameEnd, 1, &ctxFrameEnd)) | 24cfb8dRow pattern recognition patch (executor and commands).
1826 | - | ctxFrameEnd = PG_INT64_MAX; | 24cfb8dRow pattern recognition patch (executor and commands).
1827 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1828 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1829 | - | * currentPos advances by exactly one per call, and a finalized | 24cfb8dRow pattern recognition patch (executor and commands).
1830 | - | * context is skipped by the states == NULL guard above, so it can | 24cfb8dRow pattern recognition patch (executor and commands).
1831 | - | * only ever reach ctxFrameEnd, never overshoot it. The Assert | 24cfb8dRow pattern recognition patch (executor and commands).
1832 | - | * turns a future change that broke that invariant into an | 24cfb8dRow pattern recognition patch (executor and commands).
1833 | - | * immediate failure rather than a silent slip past the boundary. | 24cfb8dRow pattern recognition patch (executor and commands).
1834 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1835 | 1236 | Assert(currentPos <= ctxFrameEnd); | 24cfb8dRow pattern recognition patch (executor and commands).
1836 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1837 | 1296 | if (currentPos == ctxFrameEnd) | 24cfb8dRow pattern recognition patch (executor and commands).
1838 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1839 | - | /* Frame boundary reached: force mismatch */ | 24cfb8dRow pattern recognition patch (executor and commands).
1840 | 44 | nfa_match(winstate, ctx, NULL); | 24cfb8dRow pattern recognition patch (executor and commands).
1841 | 44 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
1842 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1843 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1844 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1845 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1846 | - | * If this context has a different matchStartRow than the one used in | 24cfb8dRow pattern recognition patch (executor and commands).
1847 | - | * the shared evaluation, re-evaluate match_start-dependent variables | 24cfb8dRow pattern recognition patch (executor and commands).
1848 | - | * with this context's matchStartRow. | 24cfb8dRow pattern recognition patch (executor and commands).
1849 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1850 | 1940584 | if (hasDependent && ctx->matchStartRow != winstate->nav_match_start) | 24cfb8dRow pattern recognition patch (executor and commands).
1851 | 5480 | nfa_reevaluate_dependent_vars(winstate, ctx, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1852 | 1940584 | nfa_match(winstate, ctx, varMatched); | 24cfb8dRow pattern recognition patch (executor and commands).
1853 | 1940584 | ctx->lastProcessedRow = currentPos; | 24cfb8dRow pattern recognition patch (executor and commands).
1854 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1855 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1856 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1857 | - | * Phase 2: Absorb redundant contexts. After match phase, states have | 24cfb8dRow pattern recognition patch (executor and commands).
1858 | - | * converged - ideal for absorption. First update absorption flags that | 24cfb8dRow pattern recognition patch (executor and commands).
1859 | - | * may have changed due to state removal. | 24cfb8dRow pattern recognition patch (executor and commands).
1860 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1861 | 988588 | if (winstate->rpPattern->isAbsorbable) | 24cfb8dRow pattern recognition patch (executor and commands).
1862 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1863 | 2655972 | for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) | 24cfb8dRow pattern recognition patch (executor and commands).
1864 | 1758300 | nfa_update_absorption_flags(ctx); | 24cfb8dRow pattern recognition patch (executor and commands).
1865 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1866 | 897672 | nfa_absorb_contexts(winstate); | 24cfb8dRow pattern recognition patch (executor and commands).
1867 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1868 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1869 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1870 | - | * Phase 3: Advance all contexts (divergence). Create new states | 24cfb8dRow pattern recognition patch (executor and commands).
1871 | - | * (loop/exit) from surviving matched states. | 24cfb8dRow pattern recognition patch (executor and commands).
1872 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1873 | 2236340 | for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) | 24cfb8dRow pattern recognition patch (executor and commands).
1874 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1875 | 1247752 | if (ctx->states == NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1876 | 255952 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
1877 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1878 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1879 | - | * Phase 1 already handled frame boundary exceeded contexts by forcing | 24cfb8dRow pattern recognition patch (executor and commands).
1880 | - | * mismatch (nfa_match with NULL), which removes all states (all | 24cfb8dRow pattern recognition patch (executor and commands).
1881 | - | * states are at VAR positions after advance). So any surviving | 24cfb8dRow pattern recognition patch (executor and commands).
1882 | - | * context here must be within its frame boundary. | 24cfb8dRow pattern recognition patch (executor and commands).
1883 | - | * | 24cfb8dRow pattern recognition patch (executor and commands).
1884 | - | * Compute the (clamped) frame end the same way as Phase 1, using two | 24cfb8dRow pattern recognition patch (executor and commands).
1885 | - | * separately checked adds so that "frameOffset + 1" cannot overflow | 24cfb8dRow pattern recognition patch (executor and commands).
1886 | - | * when frameOffset is near PG_INT64_MAX. | 24cfb8dRow pattern recognition patch (executor and commands).
1887 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1888 | - | #ifdef USE_ASSERT_CHECKING | 24cfb8dRow pattern recognition patch (executor and commands).
1889 | 991800 | if (hasLimitedFrame) | 24cfb8dRow pattern recognition patch (executor and commands).
1890 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1891 | 1100 | int64 ctxFrameEnd; | 24cfb8dRow pattern recognition patch (executor and commands).
1892 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1893 | 1100 | if (pg_add_s64_overflow(ctx->matchStartRow, frameOffset, | 24cfb8dRow pattern recognition patch (executor and commands).
1894 | 1060 | &ctxFrameEnd) || | 24cfb8dRow pattern recognition patch (executor and commands).
1895 | 1060 | pg_add_s64_overflow(ctxFrameEnd, 1, &ctxFrameEnd)) | 24cfb8dRow pattern recognition patch (executor and commands).
1896 | - | ctxFrameEnd = PG_INT64_MAX; | 24cfb8dRow pattern recognition patch (executor and commands).
1897 | 1100 | Assert(currentPos < ctxFrameEnd); | 24cfb8dRow pattern recognition patch (executor and commands).
1898 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1899 | - | #endif | 24cfb8dRow pattern recognition patch (executor and commands).
1900 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1901 | 991800 | nfa_advance(winstate, ctx, currentPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1902 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1903 | 988588 | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRCleanupDeadContexts() lines 1913-1946
Modified Lines Coverage: 15/15 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1913 | 994916 | ExecRPRCleanupDeadContexts(WindowAggState *winstate, RPRNFAContext *excludeCtx) | 24cfb8dRow pattern recognition patch (executor and commands).
1914 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1915 | 994916 | RPRNFAContext *ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1916 | 994916 | RPRNFAContext *next; | 24cfb8dRow pattern recognition patch (executor and commands).
1917 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1918 | 3245788 | for (ctx = winstate->nfaContext; ctx != NULL; ctx = next) | 24cfb8dRow pattern recognition patch (executor and commands).
1919 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1920 | 2250872 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
1921 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1922 | 2250872 | next = ctx->next; | 24cfb8dRow pattern recognition patch (executor and commands).
1923 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1924 | - | /* Skip the target context and contexts still processing */ | 24cfb8dRow pattern recognition patch (executor and commands).
1925 | 2250872 | if (ctx == excludeCtx || ctx->states != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1926 | 2047836 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
1927 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1928 | - | /* Skip successfully matched contexts (will be handled by SKIP logic) */ | 24cfb8dRow pattern recognition patch (executor and commands).
1929 | 203036 | if (ctx->matchEndRow >= ctx->matchStartRow) | 24cfb8dRow pattern recognition patch (executor and commands).
1930 | 812 | continue; | 24cfb8dRow pattern recognition patch (executor and commands).
1931 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1932 | - | /* | 24cfb8dRow pattern recognition patch (executor and commands).
1933 | - | * Failed context: always removed below. Only record the failure | 24cfb8dRow pattern recognition patch (executor and commands).
1934 | - | * statistic if it actually processed its start row; contexts created | 24cfb8dRow pattern recognition patch (executor and commands).
1935 | - | * for beyond-partition rows are removed without being counted. | 24cfb8dRow pattern recognition patch (executor and commands).
1936 | - | */ | 24cfb8dRow pattern recognition patch (executor and commands).
1937 | 202224 | if (ctx->lastProcessedRow >= ctx->matchStartRow) | 24cfb8dRow pattern recognition patch (executor and commands).
1938 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1939 | 195896 | int64 failedLen = ctx->lastProcessedRow - ctx->matchStartRow + 1; | 24cfb8dRow pattern recognition patch (executor and commands).
1940 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1941 | 195896 | ExecRPRRecordContextFailure(winstate, failedLen); | 24cfb8dRow pattern recognition patch (executor and commands).
1942 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1943 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1944 | 202224 | ExecRPRFreeContext(winstate, ctx); | 24cfb8dRow pattern recognition patch (executor and commands).
1945 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1946 | 994916 | } | 24cfb8dRow pattern recognition patch (executor and commands).

ExecRPRFinalizeAllContexts() lines 1975-1989
Modified Lines Coverage: 8/8 lines (100.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
1975 | 6328 | ExecRPRFinalizeAllContexts(WindowAggState *winstate, int64 lastPos) | 24cfb8dRow pattern recognition patch (executor and commands).
1976 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1977 | 6328 | RPRNFAContext *ctx; | 24cfb8dRow pattern recognition patch (executor and commands).
1978 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1979 | 20860 | for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) | 24cfb8dRow pattern recognition patch (executor and commands).
1980 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1981 | 14532 | CHECK_FOR_INTERRUPTS(); | 24cfb8dRow pattern recognition patch (executor and commands).
1982 | - |  | 24cfb8dRow pattern recognition patch (executor and commands).
1983 | 14532 | if (ctx->states != NULL) | 24cfb8dRow pattern recognition patch (executor and commands).
1984 | - | { | 24cfb8dRow pattern recognition patch (executor and commands).
1985 | 14528 | nfa_match(winstate, ctx, NULL); | 24cfb8dRow pattern recognition patch (executor and commands).
1986 | 14528 | nfa_advance(winstate, ctx, lastPos); | 24cfb8dRow pattern recognition patch (executor and commands).
1987 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1988 | - | } | 24cfb8dRow pattern recognition patch (executor and commands).
1989 | 6328 | } | 24cfb8dRow pattern recognition patch (executor and commands).