← Back to Overview

src/backend/executor/execRPR.c

Coverage: 588/588 lines (100.0%)
Total Lines
588
modified
Covered
588
100.0%
Uncovered
0
0.0%
Keyboard navigation
nfa_mark_visited() lines 47-54
Modified Lines Coverage: 6/6 lines (100.0%)
LineHitsSourceCommit
47 3039636 nfa_mark_visited(WindowAggState *winstate, int16 elemIdx) 24cfb8dRow pattern recognition patch (executor and commands).
48 - { 24cfb8dRow pattern recognition patch (executor and commands).
49 3039636 int16 w = WORDNUM(elemIdx); 24cfb8dRow pattern recognition patch (executor and commands).
50 - 24cfb8dRow pattern recognition patch (executor and commands).
51 3039636 winstate->nfaVisitedElems[w] |= ((bitmapword) 1 << BITNUM(elemIdx)); 24cfb8dRow pattern recognition patch (executor and commands).
52 3039636 winstate->nfaVisitedMinWord = Min(winstate->nfaVisitedMinWord, w); 24cfb8dRow pattern recognition patch (executor and commands).
53 3039636 winstate->nfaVisitedMaxWord = Max(winstate->nfaVisitedMaxWord, w); 24cfb8dRow pattern recognition patch (executor and commands).
54 3039636 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_state_make() lines 209-235
Modified Lines Coverage: 11/11 lines (100.0%)
LineHitsSourceCommit
209 2015360 nfa_state_make(WindowAggState *winstate) 24cfb8dRow pattern recognition patch (executor and commands).
210 - { 24cfb8dRow pattern recognition patch (executor and commands).
211 2015360 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 2015360 if (winstate->nfaStateFree != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
215 - { 24cfb8dRow pattern recognition patch (executor and commands).
216 1982548 state = winstate->nfaStateFree; 24cfb8dRow pattern recognition patch (executor and commands).
217 1982548 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 32812 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 2015360 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 2015360 winstate->nfaStatesActive++; 24cfb8dRow pattern recognition patch (executor and commands).
230 2015360 winstate->nfaStatesTotalCreated++; 24cfb8dRow pattern recognition patch (executor and commands).
231 2015360 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 2015360 return state; 24cfb8dRow pattern recognition patch (executor and commands).
235 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_state_free() lines 243-253
Modified Lines Coverage: 5/5 lines (100.0%)
LineHitsSourceCommit
243 2011040 nfa_state_free(WindowAggState *winstate, RPRNFAState *state) 24cfb8dRow pattern recognition patch (executor and commands).
244 - { 24cfb8dRow pattern recognition patch (executor and commands).
245 2011040 winstate->nfaStatesActive--; 24cfb8dRow pattern recognition patch (executor and commands).
246 - #ifdef USE_VALGRIND 93fa390Free RPR NFA states with pfree() under USE_VALGRIND
247 - /* real free so Valgrind catches use-after-free instead of recycling */ 93fa390Free RPR NFA states with pfree() under USE_VALGRIND
248 - pfree(state); 93fa390Free RPR NFA states with pfree() under USE_VALGRIND
249 - #else 93fa390Free RPR NFA states with pfree() under USE_VALGRIND
250 2011040 state->next = winstate->nfaStateFree; 24cfb8dRow pattern recognition patch (executor and commands).
251 2011040 winstate->nfaStateFree = state; 24cfb8dRow pattern recognition patch (executor and commands).
252 - #endif 93fa390Free RPR NFA states with pfree() under USE_VALGRIND
253 2011040 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_state_free_list() lines 261-270
Modified Lines Coverage: 6/6 lines (100.0%)
LineHitsSourceCommit
261 390836 nfa_state_free_list(WindowAggState *winstate, RPRNFAState *list) 24cfb8dRow pattern recognition patch (executor and commands).
262 - { 24cfb8dRow pattern recognition patch (executor and commands).
263 390836 RPRNFAState *next; 24cfb8dRow pattern recognition patch (executor and commands).
264 - 24cfb8dRow pattern recognition patch (executor and commands).
265 781760 for (; list != NULL; list = next) 24cfb8dRow pattern recognition patch (executor and commands).
266 - { 24cfb8dRow pattern recognition patch (executor and commands).
267 390924 next = list->next; 24cfb8dRow pattern recognition patch (executor and commands).
268 390924 nfa_state_free(winstate, list); 24cfb8dRow pattern recognition patch (executor and commands).
269 - } 24cfb8dRow pattern recognition patch (executor and commands).
270 390836 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_state_clone() lines 282-303
Modified Lines Coverage: 10/10 lines (100.0%)
LineHitsSourceCommit
282 1016184 nfa_state_clone(WindowAggState *winstate, int16 elemIdx, 24cfb8dRow pattern recognition patch (executor and commands).
283 - int32 *counts, bool sourceAbsorbable) 24cfb8dRow pattern recognition patch (executor and commands).
284 - { 24cfb8dRow pattern recognition patch (executor and commands).
285 1016184 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
286 1016184 int maxDepth = pattern->maxDepth; 24cfb8dRow pattern recognition patch (executor and commands).
287 1016184 RPRNFAState *state = nfa_state_make(winstate); 24cfb8dRow pattern recognition patch (executor and commands).
288 1016184 RPRPatternElement *elem = &pattern->elements[elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
289 - 24cfb8dRow pattern recognition patch (executor and commands).
290 1016184 state->elemIdx = elemIdx; 24cfb8dRow pattern recognition patch (executor and commands).
291 - /* Every reachable caller passes a live state's counts; maxDepth >= 1. */ 24cfb8dRow pattern recognition patch (executor and commands).
292 1016184 Assert(counts != NULL && maxDepth > 0); 24cfb8dRow pattern recognition patch (executor and commands).
293 1016184 memcpy(state->counts, counts, sizeof(int32) * maxDepth); 24cfb8dRow pattern recognition patch (executor and commands).
294 - 24cfb8dRow pattern recognition patch (executor and commands).
295 - /* 24cfb8dRow pattern recognition patch (executor and commands).
296 - * Compute isAbsorbable immediately at transition time. isAbsorbable = 24cfb8dRow pattern recognition patch (executor and commands).
297 - * sourceAbsorbable && (elem->flags & ABSORBABLE_BRANCH) Monotonic: once 24cfb8dRow pattern recognition patch (executor and commands).
298 - * false, stays false (can't re-enter absorbable region). 24cfb8dRow pattern recognition patch (executor and commands).
299 - */ 24cfb8dRow pattern recognition patch (executor and commands).
300 1016184 state->isAbsorbable = sourceAbsorbable && RPRElemIsAbsorbableBranch(elem); 24cfb8dRow pattern recognition patch (executor and commands).
301 - 24cfb8dRow pattern recognition patch (executor and commands).
302 1016184 return state; 24cfb8dRow pattern recognition patch (executor and commands).
303 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_states_equal() lines 311-339
Modified Lines Coverage: 9/9 lines (100.0%)
LineHitsSourceCommit
311 804468 nfa_states_equal(WindowAggState *winstate, RPRNFAState *s1, RPRNFAState *s2) 24cfb8dRow pattern recognition patch (executor and commands).
312 - { 24cfb8dRow pattern recognition patch (executor and commands).
313 804468 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
314 804468 RPRPatternElement *elem; 24cfb8dRow pattern recognition patch (executor and commands).
315 804468 int compareDepth; 24cfb8dRow pattern recognition patch (executor and commands).
316 - 24cfb8dRow pattern recognition patch (executor and commands).
317 804468 if (s1->elemIdx != s2->elemIdx) 24cfb8dRow pattern recognition patch (executor and commands).
318 - return false; 24cfb8dRow pattern recognition patch (executor and commands).
319 - 24cfb8dRow pattern recognition patch (executor and commands).
320 - /* 24cfb8dRow pattern recognition patch (executor and commands).
321 - * Compare counts up to current element's depth. Two states sharing 24cfb8dRow pattern recognition patch (executor and commands).
322 - * elemIdx are equivalent iff every enclosing-or-current depth count 24cfb8dRow pattern recognition patch (executor and commands).
323 - * matches. 24cfb8dRow pattern recognition patch (executor and commands).
324 - * 24cfb8dRow pattern recognition patch (executor and commands).
325 - * The +1 is the slot arithmetic: comparing through depth N requires 24cfb8dRow pattern recognition patch (executor and commands).
326 - * counts[0..N], i.e., N+1 entries. Deeper slots (counts[d] with d > 24cfb8dRow pattern recognition patch (executor and commands).
327 - * elem->depth) are excluded because they hold scratch state from inner 24cfb8dRow pattern recognition patch (executor and commands).
328 - * groups. Per the count-clear policy such a slot is zeroed when its 24cfb8dRow pattern recognition patch (executor and commands).
329 - * owning element exits (see nfa_advance_var and the inline fast path in 24cfb8dRow pattern recognition patch (executor and commands).
330 - * nfa_match), so it must not participate in equivalence judgment. 24cfb8dRow pattern recognition patch (executor and commands).
331 - */ 24cfb8dRow pattern recognition patch (executor and commands).
332 692 elem = &pattern->elements[s1->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
333 692 compareDepth = elem->depth + 1; 24cfb8dRow pattern recognition patch (executor and commands).
334 - 24cfb8dRow pattern recognition patch (executor and commands).
335 692 if (memcmp(s1->counts, s2->counts, sizeof(int32) * compareDepth) != 0) 24cfb8dRow pattern recognition patch (executor and commands).
336 568 return false; 24cfb8dRow pattern recognition patch (executor and commands).
337 - 24cfb8dRow pattern recognition patch (executor and commands).
338 - return true; 24cfb8dRow pattern recognition patch (executor and commands).
339 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_add_state_unique() lines 350-387
Modified Lines Coverage: 15/15 lines (100.0%)
LineHitsSourceCommit
350 2617820 nfa_add_state_unique(WindowAggState *winstate, RPRNFAContext *ctx, RPRNFAState *state) 24cfb8dRow pattern recognition patch (executor and commands).
351 - { 24cfb8dRow pattern recognition patch (executor and commands).
352 2617820 RPRNFAState *s; 24cfb8dRow pattern recognition patch (executor and commands).
353 2617820 RPRNFAState *tail = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
354 - 24cfb8dRow pattern recognition patch (executor and commands).
355 - /* 24cfb8dRow pattern recognition patch (executor and commands).
356 - * Mark VAR in visited before duplicate check to prevent DFS loops. This 24cfb8dRow pattern recognition patch (executor and commands).
357 - * is the deferred half of the asymmetric visited-marking scheme; see 24cfb8dRow pattern recognition patch (executor and commands).
358 - * nfa_advance_state for the non-VAR (END/ALT/BEGIN/FIN) half and the 24cfb8dRow pattern recognition patch (executor and commands).
359 - * rationale for the asymmetry. 24cfb8dRow pattern recognition patch (executor and commands).
360 - */ 24cfb8dRow pattern recognition patch (executor and commands).
361 2617820 nfa_mark_visited(winstate, state->elemIdx); 24cfb8dRow pattern recognition patch (executor and commands).
362 - 24cfb8dRow pattern recognition patch (executor and commands).
363 - /* Check for duplicate and find tail */ 24cfb8dRow pattern recognition patch (executor and commands).
364 3422164 for (s = ctx->states; s != NULL; s = s->next) 24cfb8dRow pattern recognition patch (executor and commands).
365 - { 24cfb8dRow pattern recognition patch (executor and commands).
366 804468 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
367 - 24cfb8dRow pattern recognition patch (executor and commands).
368 804468 if (nfa_states_equal(winstate, s, state)) 24cfb8dRow pattern recognition patch (executor and commands).
369 - { 24cfb8dRow pattern recognition patch (executor and commands).
370 - /* 24cfb8dRow pattern recognition patch (executor and commands).
371 - * Duplicate found - existing has better lexical order, discard 24cfb8dRow pattern recognition patch (executor and commands).
372 - * new 24cfb8dRow pattern recognition patch (executor and commands).
373 - */ 24cfb8dRow pattern recognition patch (executor and commands).
374 124 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
375 124 winstate->nfaStatesMerged++; 24cfb8dRow pattern recognition patch (executor and commands).
376 124 return; 24cfb8dRow pattern recognition patch (executor and commands).
377 - } 24cfb8dRow pattern recognition patch (executor and commands).
378 804344 tail = s; 24cfb8dRow pattern recognition patch (executor and commands).
379 - } 24cfb8dRow pattern recognition patch (executor and commands).
380 - 24cfb8dRow pattern recognition patch (executor and commands).
381 - /* No duplicate, add at end */ 24cfb8dRow pattern recognition patch (executor and commands).
382 2617696 state->next = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
383 2617696 if (tail == NULL) 24cfb8dRow pattern recognition patch (executor and commands).
384 1959416 ctx->states = state; 24cfb8dRow pattern recognition patch (executor and commands).
385 - else 24cfb8dRow pattern recognition patch (executor and commands).
386 658280 tail->next = state; 24cfb8dRow pattern recognition patch (executor and commands).
387 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_add_matched_state() lines 398-425
Modified Lines Coverage: 15/15 lines (100.0%)
LineHitsSourceCommit
398 362716 nfa_add_matched_state(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
399 - RPRNFAState *state, int64 matchEndRow) 24cfb8dRow pattern recognition patch (executor and commands).
400 - { 24cfb8dRow pattern recognition patch (executor and commands).
401 362716 if (ctx->matchedState != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
402 324660 nfa_state_free(winstate, ctx->matchedState); 24cfb8dRow pattern recognition patch (executor and commands).
403 - 24cfb8dRow pattern recognition patch (executor and commands).
404 362716 ctx->matchedState = state; 24cfb8dRow pattern recognition patch (executor and commands).
405 362716 state->next = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
406 362716 ctx->matchEndRow = matchEndRow; 24cfb8dRow pattern recognition patch (executor and commands).
407 - 24cfb8dRow pattern recognition patch (executor and commands).
408 - /* Prune contexts that started within this match's range */ 24cfb8dRow pattern recognition patch (executor and commands).
409 362716 if (winstate->rpSkipTo == ST_PAST_LAST_ROW) 24cfb8dRow pattern recognition patch (executor and commands).
410 - { 24cfb8dRow pattern recognition patch (executor and commands).
411 - int64 skippedLen; 24cfb8dRow pattern recognition patch (executor and commands).
412 - 24cfb8dRow pattern recognition patch (executor and commands).
413 672336 while (ctx->next != NULL && 24cfb8dRow pattern recognition patch (executor and commands).
414 314352 ctx->next->matchStartRow <= matchEndRow) 24cfb8dRow pattern recognition patch (executor and commands).
415 - { 24cfb8dRow pattern recognition patch (executor and commands).
416 314352 RPRNFAContext *nextCtx = ctx->next; 24cfb8dRow pattern recognition patch (executor and commands).
417 - 24cfb8dRow pattern recognition patch (executor and commands).
418 314352 Assert(nextCtx->lastProcessedRow >= nextCtx->matchStartRow); 24cfb8dRow pattern recognition patch (executor and commands).
419 314352 skippedLen = nextCtx->lastProcessedRow - nextCtx->matchStartRow + 1; 24cfb8dRow pattern recognition patch (executor and commands).
420 314352 nfa_record_context_skipped(winstate, skippedLen); 24cfb8dRow pattern recognition patch (executor and commands).
421 - 24cfb8dRow pattern recognition patch (executor and commands).
422 314352 ExecRPRFreeContext(winstate, nextCtx); 24cfb8dRow pattern recognition patch (executor and commands).
423 - } 24cfb8dRow pattern recognition patch (executor and commands).
424 - } 24cfb8dRow pattern recognition patch (executor and commands).
425 362716 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_context_make() lines 433-467
Modified Lines Coverage: 19/19 lines (100.0%)
LineHitsSourceCommit
433 999176 nfa_context_make(WindowAggState *winstate) 24cfb8dRow pattern recognition patch (executor and commands).
434 - { 24cfb8dRow pattern recognition patch (executor and commands).
435 999176 RPRNFAContext *ctx; 24cfb8dRow pattern recognition patch (executor and commands).
436 - 24cfb8dRow pattern recognition patch (executor and commands).
437 999176 if (winstate->nfaContextFree != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
438 - { 24cfb8dRow pattern recognition patch (executor and commands).
439 966148 ctx = winstate->nfaContextFree; 24cfb8dRow pattern recognition patch (executor and commands).
440 966148 winstate->nfaContextFree = ctx->next; 24cfb8dRow pattern recognition patch (executor and commands).
441 - } 24cfb8dRow pattern recognition patch (executor and commands).
442 - else 24cfb8dRow pattern recognition patch (executor and commands).
443 - { 24cfb8dRow pattern recognition patch (executor and commands).
444 - /* Allocate in partition context for proper lifetime */ 24cfb8dRow pattern recognition patch (executor and commands).
445 33028 ctx = MemoryContextAlloc(winstate->partcontext, sizeof(RPRNFAContext)); 24cfb8dRow pattern recognition patch (executor and commands).
446 - } 24cfb8dRow pattern recognition patch (executor and commands).
447 - 24cfb8dRow pattern recognition patch (executor and commands).
448 999176 ctx->next = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
449 999176 ctx->prev = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
450 999176 ctx->states = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
451 999176 ctx->matchStartRow = -1; 24cfb8dRow pattern recognition patch (executor and commands).
452 999176 ctx->matchEndRow = -1; 24cfb8dRow pattern recognition patch (executor and commands).
453 999176 ctx->lastProcessedRow = -1; 24cfb8dRow pattern recognition patch (executor and commands).
454 999176 ctx->matchedState = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
455 - 24cfb8dRow pattern recognition patch (executor and commands).
456 - /* Initialize two-flag absorption design based on pattern */ 24cfb8dRow pattern recognition patch (executor and commands).
457 999176 ctx->hasAbsorbableState = winstate->rpPattern->isAbsorbable; 24cfb8dRow pattern recognition patch (executor and commands).
458 999176 ctx->allStatesAbsorbable = winstate->rpPattern->isAbsorbable; 24cfb8dRow pattern recognition patch (executor and commands).
459 - 24cfb8dRow pattern recognition patch (executor and commands).
460 - /* Update statistics */ 24cfb8dRow pattern recognition patch (executor and commands).
461 999176 winstate->nfaContextsActive++; 24cfb8dRow pattern recognition patch (executor and commands).
462 999176 winstate->nfaContextsTotalCreated++; 24cfb8dRow pattern recognition patch (executor and commands).
463 999176 winstate->nfaContextsMax = Max(winstate->nfaContextsMax, 24cfb8dRow pattern recognition patch (executor and commands).
464 - winstate->nfaContextsActive); 24cfb8dRow pattern recognition patch (executor and commands).
465 - 24cfb8dRow pattern recognition patch (executor and commands).
466 999176 return ctx; 24cfb8dRow pattern recognition patch (executor and commands).
467 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_unlink_context() lines 476-490
Modified Lines Coverage: 10/10 lines (100.0%)
LineHitsSourceCommit
476 995300 nfa_unlink_context(WindowAggState *winstate, RPRNFAContext *ctx) 24cfb8dRow pattern recognition patch (executor and commands).
477 - { 24cfb8dRow pattern recognition patch (executor and commands).
478 995300 if (ctx->prev != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
479 895216 ctx->prev->next = ctx->next; 24cfb8dRow pattern recognition patch (executor and commands).
480 - else 24cfb8dRow pattern recognition patch (executor and commands).
481 100084 winstate->nfaContext = ctx->next; /* was head */ 24cfb8dRow pattern recognition patch (executor and commands).
482 - 24cfb8dRow pattern recognition patch (executor and commands).
483 995300 if (ctx->next != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
484 294148 ctx->next->prev = ctx->prev; 24cfb8dRow pattern recognition patch (executor and commands).
485 - else 24cfb8dRow pattern recognition patch (executor and commands).
486 701152 winstate->nfaContextTail = ctx->prev; /* was tail */ 24cfb8dRow pattern recognition patch (executor and commands).
487 - 24cfb8dRow pattern recognition patch (executor and commands).
488 995300 ctx->next = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
489 995300 ctx->prev = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
490 995300 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_update_length_stats() lines 499-512
Modified Lines Coverage: 8/8 lines (100.0%)
LineHitsSourceCommit
499 761140 nfa_update_length_stats(int64 count, NFALengthStats *stats, int64 newLen) 24cfb8dRow pattern recognition patch (executor and commands).
500 - { 24cfb8dRow pattern recognition patch (executor and commands).
501 761140 if (count == 1) 24cfb8dRow pattern recognition patch (executor and commands).
502 - { 24cfb8dRow pattern recognition patch (executor and commands).
503 4668 stats->min = newLen; 24cfb8dRow pattern recognition patch (executor and commands).
504 4668 stats->max = newLen; 24cfb8dRow pattern recognition patch (executor and commands).
505 - } 24cfb8dRow pattern recognition patch (executor and commands).
506 - else 24cfb8dRow pattern recognition patch (executor and commands).
507 - { 24cfb8dRow pattern recognition patch (executor and commands).
508 756472 stats->min = Min(stats->min, newLen); 24cfb8dRow pattern recognition patch (executor and commands).
509 756472 stats->max = Max(stats->max, newLen); 24cfb8dRow pattern recognition patch (executor and commands).
510 - } 24cfb8dRow pattern recognition patch (executor and commands).
511 761140 stats->total += newLen; 24cfb8dRow pattern recognition patch (executor and commands).
512 761140 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_record_context_skipped() lines 520-526
Modified Lines Coverage: 4/4 lines (100.0%)
LineHitsSourceCommit
520 314352 nfa_record_context_skipped(WindowAggState *winstate, int64 skippedLen) 24cfb8dRow pattern recognition patch (executor and commands).
521 - { 24cfb8dRow pattern recognition patch (executor and commands).
522 314352 winstate->nfaContextsSkipped++; 24cfb8dRow pattern recognition patch (executor and commands).
523 314352 nfa_update_length_stats(winstate->nfaContextsSkipped, 24cfb8dRow pattern recognition patch (executor and commands).
524 - &winstate->nfaSkippedLen, 24cfb8dRow pattern recognition patch (executor and commands).
525 - skippedLen); 24cfb8dRow pattern recognition patch (executor and commands).
526 314352 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_record_context_absorbed() lines 534-540
Modified Lines Coverage: 4/4 lines (100.0%)
LineHitsSourceCommit
534 378620 nfa_record_context_absorbed(WindowAggState *winstate, int64 absorbedLen) 24cfb8dRow pattern recognition patch (executor and commands).
535 - { 24cfb8dRow pattern recognition patch (executor and commands).
536 378620 winstate->nfaContextsAbsorbed++; 24cfb8dRow pattern recognition patch (executor and commands).
537 378620 nfa_update_length_stats(winstate->nfaContextsAbsorbed, 24cfb8dRow pattern recognition patch (executor and commands).
538 - &winstate->nfaAbsorbedLen, 24cfb8dRow pattern recognition patch (executor and commands).
539 - absorbedLen); 24cfb8dRow pattern recognition patch (executor and commands).
540 378620 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_update_absorption_flags() lines 559-601
Modified Lines Coverage: 17/17 lines (100.0%)
LineHitsSourceCommit
559 1758388 nfa_update_absorption_flags(RPRNFAContext *ctx) 24cfb8dRow pattern recognition patch (executor and commands).
560 - { 24cfb8dRow pattern recognition patch (executor and commands).
561 1758388 RPRNFAState *state; 24cfb8dRow pattern recognition patch (executor and commands).
562 1758388 bool hasAbsorbable = false; 24cfb8dRow pattern recognition patch (executor and commands).
563 1758388 bool allAbsorbable = true; 24cfb8dRow pattern recognition patch (executor and commands).
564 - 24cfb8dRow pattern recognition patch (executor and commands).
565 - /* 24cfb8dRow pattern recognition patch (executor and commands).
566 - * Optimization: Once hasAbsorbableState becomes false, it stays false. No 24cfb8dRow pattern recognition patch (executor and commands).
567 - * need to recalculate - both flags remain false permanently. 24cfb8dRow pattern recognition patch (executor and commands).
568 - */ 24cfb8dRow pattern recognition patch (executor and commands).
569 1758388 if (!ctx->hasAbsorbableState) 24cfb8dRow pattern recognition patch (executor and commands).
570 - { 24cfb8dRow pattern recognition patch (executor and commands).
571 470200 ctx->allStatesAbsorbable = false; 24cfb8dRow pattern recognition patch (executor and commands).
572 470200 return; 24cfb8dRow pattern recognition patch (executor and commands).
573 - } 24cfb8dRow pattern recognition patch (executor and commands).
574 - 24cfb8dRow pattern recognition patch (executor and commands).
575 - /* No states means no absorbable states */ 24cfb8dRow pattern recognition patch (executor and commands).
576 1288188 if (ctx->states == NULL) 24cfb8dRow pattern recognition patch (executor and commands).
577 - { 24cfb8dRow pattern recognition patch (executor and commands).
578 513304 ctx->hasAbsorbableState = false; 24cfb8dRow pattern recognition patch (executor and commands).
579 513304 ctx->allStatesAbsorbable = false; 24cfb8dRow pattern recognition patch (executor and commands).
580 513304 return; 24cfb8dRow pattern recognition patch (executor and commands).
581 - } 24cfb8dRow pattern recognition patch (executor and commands).
582 - 24cfb8dRow pattern recognition patch (executor and commands).
583 - /* 24cfb8dRow pattern recognition patch (executor and commands).
584 - * Iterate through all states to check absorption status. Uses 24cfb8dRow pattern recognition patch (executor and commands).
585 - * state->isAbsorbable which tracks if state is in absorbable region. This 24cfb8dRow pattern recognition patch (executor and commands).
586 - * is different from RPRElemIsAbsorbable(elem) which checks comparison 0bc60efRename absorption "judgment point" to "comparison point" in comments
587 - * point. 24cfb8dRow pattern recognition patch (executor and commands).
588 - */ 24cfb8dRow pattern recognition patch (executor and commands).
589 1550160 for (state = ctx->states; state != NULL; state = state->next) 24cfb8dRow pattern recognition patch (executor and commands).
590 - { 24cfb8dRow pattern recognition patch (executor and commands).
591 775276 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
592 - 24cfb8dRow pattern recognition patch (executor and commands).
593 775276 if (state->isAbsorbable) 24cfb8dRow pattern recognition patch (executor and commands).
594 - hasAbsorbable = true; 24cfb8dRow pattern recognition patch (executor and commands).
595 - else 24cfb8dRow pattern recognition patch (executor and commands).
596 3232 allAbsorbable = false; 24cfb8dRow pattern recognition patch (executor and commands).
597 - } 24cfb8dRow pattern recognition patch (executor and commands).
598 - 24cfb8dRow pattern recognition patch (executor and commands).
599 774884 ctx->hasAbsorbableState = hasAbsorbable; 24cfb8dRow pattern recognition patch (executor and commands).
600 774884 ctx->allStatesAbsorbable = allAbsorbable; 24cfb8dRow pattern recognition patch (executor and commands).
601 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_states_covered() lines 617-659
Modified Lines Coverage: 16/16 lines (100.0%)
LineHitsSourceCommit
617 380276 nfa_states_covered(RPRPattern *pattern, RPRNFAContext *older, RPRNFAContext *newer) 24cfb8dRow pattern recognition patch (executor and commands).
618 - { 24cfb8dRow pattern recognition patch (executor and commands).
619 380276 RPRNFAState *newerState; 24cfb8dRow pattern recognition patch (executor and commands).
620 - 24cfb8dRow pattern recognition patch (executor and commands).
621 758900 for (newerState = newer->states; newerState != NULL; newerState = newerState->next) 24cfb8dRow pattern recognition patch (executor and commands).
622 - { 24cfb8dRow pattern recognition patch (executor and commands).
623 380280 RPRNFAState *olderState; 24cfb8dRow pattern recognition patch (executor and commands).
624 380280 RPRPatternElement *elem; 24cfb8dRow pattern recognition patch (executor and commands).
625 380280 int depth; 24cfb8dRow pattern recognition patch (executor and commands).
626 380280 bool found = false; 24cfb8dRow pattern recognition patch (executor and commands).
627 - 24cfb8dRow pattern recognition patch (executor and commands).
628 - /* All states are absorbable (caller checks allStatesAbsorbable) */ 24cfb8dRow pattern recognition patch (executor and commands).
629 380280 elem = &pattern->elements[newerState->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
630 380280 depth = elem->depth; 24cfb8dRow pattern recognition patch (executor and commands).
631 - 24cfb8dRow pattern recognition patch (executor and commands).
632 - /* 24cfb8dRow pattern recognition patch (executor and commands).
633 - * Only compare at absorption comparison points (RPR_ELEM_ABSORBABLE). 0bc60efRename absorption "judgment point" to "comparison point" in comments
634 - * Comparison points are where count-dominance guarantees the newer 0bc60efRename absorption "judgment point" to "comparison point" in comments
635 - * context's future matches are a subset of the older's. 24cfb8dRow pattern recognition patch (executor and commands).
636 - */ 24cfb8dRow pattern recognition patch (executor and commands).
637 380280 if (!RPRElemIsAbsorbable(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
638 - return false; 24cfb8dRow pattern recognition patch (executor and commands).
639 - 24cfb8dRow pattern recognition patch (executor and commands).
640 378632 for (olderState = older->states; olderState != NULL; olderState = olderState->next) 24cfb8dRow pattern recognition patch (executor and commands).
641 - { 24cfb8dRow pattern recognition patch (executor and commands).
642 378628 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
643 - 24cfb8dRow pattern recognition patch (executor and commands).
644 - /* Covering state must also be absorbable */ 24cfb8dRow pattern recognition patch (executor and commands).
645 378628 if (olderState->isAbsorbable && 24cfb8dRow pattern recognition patch (executor and commands).
646 378628 olderState->elemIdx == newerState->elemIdx && 24cfb8dRow pattern recognition patch (executor and commands).
647 378624 olderState->counts[depth] >= newerState->counts[depth]) 24cfb8dRow pattern recognition patch (executor and commands).
648 - { 24cfb8dRow pattern recognition patch (executor and commands).
649 - found = true; 24cfb8dRow pattern recognition patch (executor and commands).
650 - break; 24cfb8dRow pattern recognition patch (executor and commands).
651 - } 24cfb8dRow pattern recognition patch (executor and commands).
652 - } 24cfb8dRow pattern recognition patch (executor and commands).
653 - 24cfb8dRow pattern recognition patch (executor and commands).
654 378628 if (!found) 24cfb8dRow pattern recognition patch (executor and commands).
655 - return false; 24cfb8dRow pattern recognition patch (executor and commands).
656 - } 24cfb8dRow pattern recognition patch (executor and commands).
657 - 24cfb8dRow pattern recognition patch (executor and commands).
658 - return true; 24cfb8dRow pattern recognition patch (executor and commands).
659 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_try_absorb_context() lines 680-717
Modified Lines Coverage: 15/15 lines (100.0%)
LineHitsSourceCommit
680 1244288 nfa_try_absorb_context(WindowAggState *winstate, RPRNFAContext *ctx) 24cfb8dRow pattern recognition patch (executor and commands).
681 - { 24cfb8dRow pattern recognition patch (executor and commands).
682 1244288 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
683 1244288 RPRNFAContext *older; 24cfb8dRow pattern recognition patch (executor and commands).
684 - 24cfb8dRow pattern recognition patch (executor and commands).
685 - /* Early exit: ctx must have all states absorbable */ 24cfb8dRow pattern recognition patch (executor and commands).
686 1244288 if (!ctx->allStatesAbsorbable) 24cfb8dRow pattern recognition patch (executor and commands).
687 - return; 24cfb8dRow pattern recognition patch (executor and commands).
688 - 24cfb8dRow pattern recognition patch (executor and commands).
689 774580 for (older = ctx->prev; older != NULL; older = older->prev) 24cfb8dRow pattern recognition patch (executor and commands).
690 - { 24cfb8dRow pattern recognition patch (executor and commands).
691 381500 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
692 - 24cfb8dRow pattern recognition patch (executor and commands).
693 - /* 24cfb8dRow pattern recognition patch (executor and commands).
694 - * By invariant: ctx->prev chain is in creation order (oldest first), 24cfb8dRow pattern recognition patch (executor and commands).
695 - * and each row creates at most one context. So all contexts in this 24cfb8dRow pattern recognition patch (executor and commands).
696 - * chain have matchStartRow < ctx->matchStartRow. 24cfb8dRow pattern recognition patch (executor and commands).
697 - */ 24cfb8dRow pattern recognition patch (executor and commands).
698 - 24cfb8dRow pattern recognition patch (executor and commands).
699 - /* Older must also be in-progress */ 24cfb8dRow pattern recognition patch (executor and commands).
700 381500 if (older->states == NULL) 24cfb8dRow pattern recognition patch (executor and commands).
701 768 continue; 24cfb8dRow pattern recognition patch (executor and commands).
702 - 24cfb8dRow pattern recognition patch (executor and commands).
703 - /* Older must have at least one absorbable state */ 24cfb8dRow pattern recognition patch (executor and commands).
704 380732 if (!older->hasAbsorbableState) 24cfb8dRow pattern recognition patch (executor and commands).
705 456 continue; 24cfb8dRow pattern recognition patch (executor and commands).
706 - 24cfb8dRow pattern recognition patch (executor and commands).
707 - /* Check if all newer states are covered by older */ 24cfb8dRow pattern recognition patch (executor and commands).
708 380276 if (nfa_states_covered(pattern, older, ctx)) 24cfb8dRow pattern recognition patch (executor and commands).
709 - { 24cfb8dRow pattern recognition patch (executor and commands).
710 378620 int64 absorbedLen = ctx->lastProcessedRow - ctx->matchStartRow + 1; 24cfb8dRow pattern recognition patch (executor and commands).
711 - 24cfb8dRow pattern recognition patch (executor and commands).
712 378620 ExecRPRFreeContext(winstate, ctx); 24cfb8dRow pattern recognition patch (executor and commands).
713 378620 nfa_record_context_absorbed(winstate, absorbedLen); 24cfb8dRow pattern recognition patch (executor and commands).
714 378620 return; 24cfb8dRow pattern recognition patch (executor and commands).
715 - } 24cfb8dRow pattern recognition patch (executor and commands).
716 - } 24cfb8dRow pattern recognition patch (executor and commands).
717 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_absorb_contexts() lines 733-749
Modified Lines Coverage: 8/8 lines (100.0%)
LineHitsSourceCommit
733 897720 nfa_absorb_contexts(WindowAggState *winstate) 24cfb8dRow pattern recognition patch (executor and commands).
734 - { 24cfb8dRow pattern recognition patch (executor and commands).
735 897720 RPRNFAContext *ctx; 24cfb8dRow pattern recognition patch (executor and commands).
736 897720 RPRNFAContext *nextCtx; 24cfb8dRow pattern recognition patch (executor and commands).
737 - 24cfb8dRow pattern recognition patch (executor and commands).
738 2656108 for (ctx = winstate->nfaContextTail; ctx != NULL; ctx = nextCtx) 24cfb8dRow pattern recognition patch (executor and commands).
739 - { 24cfb8dRow pattern recognition patch (executor and commands).
740 1758388 nextCtx = ctx->prev; 24cfb8dRow pattern recognition patch (executor and commands).
741 - 24cfb8dRow pattern recognition patch (executor and commands).
742 - /* 24cfb8dRow pattern recognition patch (executor and commands).
743 - * Only absorb in-progress contexts; completed contexts are valid 24cfb8dRow pattern recognition patch (executor and commands).
744 - * results 24cfb8dRow pattern recognition patch (executor and commands).
745 - */ 24cfb8dRow pattern recognition patch (executor and commands).
746 1758388 if (ctx->states != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
747 1244288 nfa_try_absorb_context(winstate, ctx); 24cfb8dRow pattern recognition patch (executor and commands).
748 - } 24cfb8dRow pattern recognition patch (executor and commands).
749 897720 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_eval_var_match() lines 765-776
Modified Lines Coverage: 5/5 lines (100.0%)
LineHitsSourceCommit
765 2613488 nfa_eval_var_match(WindowAggState *winstate, RPRPatternElement *elem, 24cfb8dRow pattern recognition patch (executor and commands).
766 - bool *varMatched) 24cfb8dRow pattern recognition patch (executor and commands).
767 - { 24cfb8dRow pattern recognition patch (executor and commands).
768 - /* This function should only be called for VAR elements */ 24cfb8dRow pattern recognition patch (executor and commands).
769 2613488 Assert(RPRElemIsVar(elem)); 24cfb8dRow pattern recognition patch (executor and commands).
770 - 24cfb8dRow pattern recognition patch (executor and commands).
771 2613488 if (varMatched == NULL) 24cfb8dRow pattern recognition patch (executor and commands).
772 - return false; 24cfb8dRow pattern recognition patch (executor and commands).
773 2597724 if (elem->varId >= list_length(winstate->defineVariableList)) 24cfb8dRow pattern recognition patch (executor and commands).
774 - return true; 24cfb8dRow pattern recognition patch (executor and commands).
775 2570544 return varMatched[elem->varId]; 24cfb8dRow pattern recognition patch (executor and commands).
776 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_match() lines 798-942
Modified Lines Coverage: 55/55 lines (100.0%)
LineHitsSourceCommit
798 1955540 nfa_match(WindowAggState *winstate, RPRNFAContext *ctx, bool *varMatched) 24cfb8dRow pattern recognition patch (executor and commands).
799 - { 24cfb8dRow pattern recognition patch (executor and commands).
800 1955540 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
801 1955540 RPRPatternElement *elements = pattern->elements; 24cfb8dRow pattern recognition patch (executor and commands).
802 1955540 RPRNFAState **prevPtr = &ctx->states; 24cfb8dRow pattern recognition patch (executor and commands).
803 1955540 RPRNFAState *state; 24cfb8dRow pattern recognition patch (executor and commands).
804 1955540 RPRNFAState *nextState; 24cfb8dRow pattern recognition patch (executor and commands).
805 - 24cfb8dRow pattern recognition patch (executor and commands).
806 - /* 24cfb8dRow pattern recognition patch (executor and commands).
807 - * Evaluate VAR elements against current row. For VARs that reach max 24cfb8dRow pattern recognition patch (executor and commands).
808 - * count with END next, advance through the chain of END elements inline 24cfb8dRow pattern recognition patch (executor and commands).
809 - * so absorb phase can compare states at comparison points. 0bc60efRename absorption "judgment point" to "comparison point" in comments
810 - */ 24cfb8dRow pattern recognition patch (executor and commands).
811 4569028 for (state = ctx->states; state != NULL; state = nextState) 24cfb8dRow pattern recognition patch (executor and commands).
812 - { 24cfb8dRow pattern recognition patch (executor and commands).
813 2613488 RPRPatternElement *elem = &elements[state->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
814 - 24cfb8dRow pattern recognition patch (executor and commands).
815 2613488 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
816 - 24cfb8dRow pattern recognition patch (executor and commands).
817 2613488 nextState = state->next; 24cfb8dRow pattern recognition patch (executor and commands).
818 - 24cfb8dRow pattern recognition patch (executor and commands).
819 2613488 if (RPRElemIsVar(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
820 - { 24cfb8dRow pattern recognition patch (executor and commands).
821 2613488 bool matched; 24cfb8dRow pattern recognition patch (executor and commands).
822 2613488 int depth = elem->depth; 24cfb8dRow pattern recognition patch (executor and commands).
823 2613488 int32 count = state->counts[depth]; 24cfb8dRow pattern recognition patch (executor and commands).
824 - 24cfb8dRow pattern recognition patch (executor and commands).
825 2613488 matched = nfa_eval_var_match(winstate, elem, varMatched); 24cfb8dRow pattern recognition patch (executor and commands).
826 - 24cfb8dRow pattern recognition patch (executor and commands).
827 2613488 if (matched) 24cfb8dRow pattern recognition patch (executor and commands).
828 - { 24cfb8dRow pattern recognition patch (executor and commands).
829 - /* 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
830 - * Increment count, saturating at RPR_COUNT_INF to avoid int32 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
831 - * overflow; a saturated count then compares as "unbounded". 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
832 - */ 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
833 1383504 if (count < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
834 1383504 count++; 24cfb8dRow pattern recognition patch (executor and commands).
835 - 24cfb8dRow pattern recognition patch (executor and commands).
836 - /* Max constraint should not be exceeded */ 24cfb8dRow pattern recognition patch (executor and commands).
837 1383504 Assert(elem->max == RPR_QUANTITY_INF || count <= elem->max); 24cfb8dRow pattern recognition patch (executor and commands).
838 - 24cfb8dRow pattern recognition patch (executor and commands).
839 1383504 state->counts[depth] = count; 24cfb8dRow pattern recognition patch (executor and commands).
840 - 24cfb8dRow pattern recognition patch (executor and commands).
841 - /* 24cfb8dRow pattern recognition patch (executor and commands).
842 - * For VAR at max count with END next, advance through END 24cfb8dRow pattern recognition patch (executor and commands).
843 - * chain to reach the absorption comparison point. Only 0bc60efRename absorption "judgment point" to "comparison point" in comments
844 - * deterministic exits (count >= max, max finite) are handled; 24cfb8dRow pattern recognition patch (executor and commands).
845 - * unbounded VARs stay for advance phase. 24cfb8dRow pattern recognition patch (executor and commands).
846 - * 24cfb8dRow pattern recognition patch (executor and commands).
847 - * In nested patterns like ((A B){2}){3}, a VAR reaching its 24cfb8dRow pattern recognition patch (executor and commands).
848 - * max triggers an exit cascade: inner END increments inner 24cfb8dRow pattern recognition patch (executor and commands).
849 - * group count, which may itself reach max, requiring an exit 24cfb8dRow pattern recognition patch (executor and commands).
850 - * to the next outer END. The loop below walks this chain. 24cfb8dRow pattern recognition patch (executor and commands).
851 - * 24cfb8dRow pattern recognition patch (executor and commands).
852 - * ABSORBABLE_BRANCH marks elements inside the absorbable 24cfb8dRow pattern recognition patch (executor and commands).
853 - * region; ABSORBABLE marks the outermost comparison point 0bc60efRename absorption "judgment point" to "comparison point" in comments
854 - * where count-dominance is evaluated. We chain through 0bc60efRename absorption "judgment point" to "comparison point" in comments
855 - * BRANCH elements until reaching the ABSORBABLE point or an 0bc60efRename absorption "judgment point" to "comparison point" in comments
856 - * element that can still loop (count < max). 0bc60efRename absorption "judgment point" to "comparison point" in comments
857 - */ 24cfb8dRow pattern recognition patch (executor and commands).
858 1383504 if (RPRElemIsAbsorbableBranch(elem) && 24cfb8dRow pattern recognition patch (executor and commands).
859 5428 !RPRElemIsAbsorbable(elem) && 24cfb8dRow pattern recognition patch (executor and commands).
860 5428 count >= elem->max && 24cfb8dRow pattern recognition patch (executor and commands).
861 4884 RPRElemIsEnd(&elements[elem->next])) 24cfb8dRow pattern recognition patch (executor and commands).
862 - { 24cfb8dRow pattern recognition patch (executor and commands).
863 2284 RPRPatternElement *endElem = &elements[elem->next]; 24cfb8dRow pattern recognition patch (executor and commands).
864 2284 int endDepth = endElem->depth; 24cfb8dRow pattern recognition patch (executor and commands).
865 2284 int32 endCount = state->counts[endDepth]; 24cfb8dRow pattern recognition patch (executor and commands).
866 - 24cfb8dRow pattern recognition patch (executor and commands).
867 - /* Increment group count */ 24cfb8dRow pattern recognition patch (executor and commands).
868 2284 if (endCount < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
869 2284 endCount++; 24cfb8dRow pattern recognition patch (executor and commands).
870 2284 Assert(endElem->max == RPR_QUANTITY_INF || 24cfb8dRow pattern recognition patch (executor and commands).
871 - endCount <= endElem->max); 24cfb8dRow pattern recognition patch (executor and commands).
872 - 24cfb8dRow pattern recognition patch (executor and commands).
873 2284 state->elemIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
874 2284 state->counts[endDepth] = endCount; 24cfb8dRow pattern recognition patch (executor and commands).
875 - 24cfb8dRow pattern recognition patch (executor and commands).
876 - /* 24cfb8dRow pattern recognition patch (executor and commands).
877 - * Leaf VAR exited (reached max): clear its own count so 24cfb8dRow pattern recognition patch (executor and commands).
878 - * the next occupant enters with zero, as nfa_advance_var 24cfb8dRow pattern recognition patch (executor and commands).
879 - * does on exit (this inline path replaces that exit). 24cfb8dRow pattern recognition patch (executor and commands).
880 - * depth > endDepth, so this leaves the group count just 24cfb8dRow pattern recognition patch (executor and commands).
881 - * written intact. 24cfb8dRow pattern recognition patch (executor and commands).
882 - */ 24cfb8dRow pattern recognition patch (executor and commands).
883 2284 Assert(endDepth < depth); 24cfb8dRow pattern recognition patch (executor and commands).
884 2284 state->counts[depth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
885 - 24cfb8dRow pattern recognition patch (executor and commands).
886 - /* 24cfb8dRow pattern recognition patch (executor and commands).
887 - * Chain through END elements within the absorbable region 24cfb8dRow pattern recognition patch (executor and commands).
888 - * (ABSORBABLE_BRANCH) until reaching the comparison point 0bc60efRename absorption "judgment point" to "comparison point" in comments
889 - * (ABSORBABLE). Continue only on must-exit path (count 24cfb8dRow pattern recognition patch (executor and commands).
890 - * >= max) with END next. 24cfb8dRow pattern recognition patch (executor and commands).
891 - */ 24cfb8dRow pattern recognition patch (executor and commands).
892 4816 while (RPRElemIsAbsorbableBranch(endElem) && 24cfb8dRow pattern recognition patch (executor and commands).
893 1012 !RPRElemIsAbsorbable(endElem) && 24cfb8dRow pattern recognition patch (executor and commands).
894 3544 endCount >= endElem->max && 24cfb8dRow pattern recognition patch (executor and commands).
895 464 RPRElemIsEnd(&elements[endElem->next])) 24cfb8dRow pattern recognition patch (executor and commands).
896 - { 24cfb8dRow pattern recognition patch (executor and commands).
897 248 RPRPatternElement *outerEnd = &elements[endElem->next]; 24cfb8dRow pattern recognition patch (executor and commands).
898 248 int outerDepth = outerEnd->depth; 24cfb8dRow pattern recognition patch (executor and commands).
899 248 int32 outerCount = state->counts[outerDepth]; 24cfb8dRow pattern recognition patch (executor and commands).
900 - 24cfb8dRow pattern recognition patch (executor and commands).
901 - /* 24cfb8dRow pattern recognition patch (executor and commands).
902 - * Exit this intermediate group: clear its own count 24cfb8dRow pattern recognition patch (executor and commands).
903 - * (count-clear policy). It sits below the absorbable 24cfb8dRow pattern recognition patch (executor and commands).
904 - * comparison point, so it is excluded from the 0bc60efRename absorption "judgment point" to "comparison point" in comments
905 - * dominance comparison; the comparison point where 0bc60efRename absorption "judgment point" to "comparison point" in comments
906 - * the chain stops keeps its count. 0bc60efRename absorption "judgment point" to "comparison point" in comments
907 - */ 24cfb8dRow pattern recognition patch (executor and commands).
908 248 state->counts[endDepth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
909 - 24cfb8dRow pattern recognition patch (executor and commands).
910 - /* Increment outer group count */ 24cfb8dRow pattern recognition patch (executor and commands).
911 248 if (outerCount < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
912 248 outerCount++; 24cfb8dRow pattern recognition patch (executor and commands).
913 248 Assert(outerEnd->max == RPR_QUANTITY_INF || 24cfb8dRow pattern recognition patch (executor and commands).
914 - outerCount <= outerEnd->max); 24cfb8dRow pattern recognition patch (executor and commands).
915 - 24cfb8dRow pattern recognition patch (executor and commands).
916 248 state->elemIdx = endElem->next; 24cfb8dRow pattern recognition patch (executor and commands).
917 248 state->counts[outerDepth] = outerCount; 24cfb8dRow pattern recognition patch (executor and commands).
918 - 24cfb8dRow pattern recognition patch (executor and commands).
919 - /* Advance to next END in chain */ 24cfb8dRow pattern recognition patch (executor and commands).
920 248 endElem = outerEnd; 24cfb8dRow pattern recognition patch (executor and commands).
921 248 endDepth = outerDepth; 24cfb8dRow pattern recognition patch (executor and commands).
922 248 endCount = outerCount; 24cfb8dRow pattern recognition patch (executor and commands).
923 - } 24cfb8dRow pattern recognition patch (executor and commands).
924 - } 24cfb8dRow pattern recognition patch (executor and commands).
925 - /* else: stay at VAR for advance phase */ 24cfb8dRow pattern recognition patch (executor and commands).
926 - } 24cfb8dRow pattern recognition patch (executor and commands).
927 - else 24cfb8dRow pattern recognition patch (executor and commands).
928 - { 24cfb8dRow pattern recognition patch (executor and commands).
929 - /* 24cfb8dRow pattern recognition patch (executor and commands).
930 - * Not matched - remove state. Exit alternatives were already 24cfb8dRow pattern recognition patch (executor and commands).
931 - * created by advance phase when count >= min was satisfied. 24cfb8dRow pattern recognition patch (executor and commands).
932 - */ 24cfb8dRow pattern recognition patch (executor and commands).
933 1229984 *prevPtr = nextState; 24cfb8dRow pattern recognition patch (executor and commands).
934 1229984 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
935 1229984 continue; 24cfb8dRow pattern recognition patch (executor and commands).
936 - } 24cfb8dRow pattern recognition patch (executor and commands).
937 - } 24cfb8dRow pattern recognition patch (executor and commands).
938 - /* Non-VAR elements: keep as-is for advance phase */ 24cfb8dRow pattern recognition patch (executor and commands).
939 - 24cfb8dRow pattern recognition patch (executor and commands).
940 1383504 prevPtr = &state->next; 24cfb8dRow pattern recognition patch (executor and commands).
941 - } 24cfb8dRow pattern recognition patch (executor and commands).
942 1955540 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_route_to_elem() lines 951-1007
Modified Lines Coverage: 19/19 lines (100.0%)
LineHitsSourceCommit
951 940576 nfa_route_to_elem(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
952 - RPRNFAState *state, RPRPatternElement *nextElem, 24cfb8dRow pattern recognition patch (executor and commands).
953 - int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
954 - { 24cfb8dRow pattern recognition patch (executor and commands).
955 940576 if (RPRElemIsVar(nextElem)) 24cfb8dRow pattern recognition patch (executor and commands).
956 - { 24cfb8dRow pattern recognition patch (executor and commands).
957 542264 RPRNFAState *skipState = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
958 - 24cfb8dRow pattern recognition patch (executor and commands).
959 - /* 24cfb8dRow pattern recognition patch (executor and commands).
960 - * Entry-side check of the count-clear policy: a VAR is always routed 24cfb8dRow pattern recognition patch (executor and commands).
961 - * to with a clean slot. Each element zeroes its own count on exit, 24cfb8dRow pattern recognition patch (executor and commands).
962 - * so a nonzero count here would be a leak from an earlier element 24cfb8dRow pattern recognition patch (executor and commands).
963 - * (see nfa_advance_var / nfa_advance_end exit handling and the inline 24cfb8dRow pattern recognition patch (executor and commands).
964 - * fast path in nfa_match). 24cfb8dRow pattern recognition patch (executor and commands).
965 - */ 24cfb8dRow pattern recognition patch (executor and commands).
966 542264 Assert(state->counts[nextElem->depth] == 0); 24cfb8dRow pattern recognition patch (executor and commands).
967 - 24cfb8dRow pattern recognition patch (executor and commands).
968 - /* Create skip state before add_unique, which may free state */ 24cfb8dRow pattern recognition patch (executor and commands).
969 542264 if (RPRElemCanSkip(nextElem)) 24cfb8dRow pattern recognition patch (executor and commands).
970 134552 skipState = nfa_state_clone(winstate, nextElem->next, 24cfb8dRow pattern recognition patch (executor and commands).
971 134552 state->counts, state->isAbsorbable); 24cfb8dRow pattern recognition patch (executor and commands).
972 - 24cfb8dRow pattern recognition patch (executor and commands).
973 134552 if (skipState != NULL && RPRElemIsReluctant(nextElem)) 24cfb8dRow pattern recognition patch (executor and commands).
974 120 { 24cfb8dRow pattern recognition patch (executor and commands).
975 184 RPRNFAState *savedMatch = ctx->matchedState; 24cfb8dRow pattern recognition patch (executor and commands).
976 - 24cfb8dRow pattern recognition patch (executor and commands).
977 - /* 24cfb8dRow pattern recognition patch (executor and commands).
978 - * Reluctant optional VAR: prefer skipping. Explore the skip path 24cfb8dRow pattern recognition patch (executor and commands).
979 - * first so it outranks the enter (match) path; if it reaches FIN 24cfb8dRow pattern recognition patch (executor and commands).
980 - * the shortest match is found and the enter state is dropped. 24cfb8dRow pattern recognition patch (executor and commands).
981 - * This mirrors the reluctant branch of nfa_advance_begin used by 24cfb8dRow pattern recognition patch (executor and commands).
982 - * the leading-position and optional-group paths. 24cfb8dRow pattern recognition patch (executor and commands).
983 - */ 24cfb8dRow pattern recognition patch (executor and commands).
984 184 nfa_advance_state(winstate, ctx, skipState, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
985 - 24cfb8dRow pattern recognition patch (executor and commands).
986 184 if (ctx->matchedState != savedMatch) 24cfb8dRow pattern recognition patch (executor and commands).
987 - { 24cfb8dRow pattern recognition patch (executor and commands).
988 64 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
989 64 return; 24cfb8dRow pattern recognition patch (executor and commands).
990 - } 24cfb8dRow pattern recognition patch (executor and commands).
991 - 24cfb8dRow pattern recognition patch (executor and commands).
992 120 nfa_add_state_unique(winstate, ctx, state); 24cfb8dRow pattern recognition patch (executor and commands).
993 - } 24cfb8dRow pattern recognition patch (executor and commands).
994 - else 24cfb8dRow pattern recognition patch (executor and commands).
995 - { 24cfb8dRow pattern recognition patch (executor and commands).
996 - /* Greedy (or non-skippable): enter first, then skip */ 24cfb8dRow pattern recognition patch (executor and commands).
997 542080 nfa_add_state_unique(winstate, ctx, state); 24cfb8dRow pattern recognition patch (executor and commands).
998 - 24cfb8dRow pattern recognition patch (executor and commands).
999 542080 if (skipState != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1000 134368 nfa_advance_state(winstate, ctx, skipState, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1001 - } 24cfb8dRow pattern recognition patch (executor and commands).
1002 - } 24cfb8dRow pattern recognition patch (executor and commands).
1003 - else 24cfb8dRow pattern recognition patch (executor and commands).
1004 - { 24cfb8dRow pattern recognition patch (executor and commands).
1005 398312 nfa_advance_state(winstate, ctx, state, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1006 - } 24cfb8dRow pattern recognition patch (executor and commands).
1007 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_advance_alt() lines 1015-1055
Modified Lines Coverage: 16/16 lines (100.0%)
LineHitsSourceCommit
1015 26420 nfa_advance_alt(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
1016 - RPRNFAState *state, RPRPatternElement *elem, 24cfb8dRow pattern recognition patch (executor and commands).
1017 - int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
1018 - { 24cfb8dRow pattern recognition patch (executor and commands).
1019 26420 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
1020 26420 RPRPatternElement *elements = pattern->elements; 24cfb8dRow pattern recognition patch (executor and commands).
1021 26420 RPRElemIdx altIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
1022 - 24cfb8dRow pattern recognition patch (executor and commands).
1023 83588 while (altIdx >= 0) 24cfb8dRow pattern recognition patch (executor and commands).
1024 - { 24cfb8dRow pattern recognition patch (executor and commands).
1025 57528 RPRPatternElement *altElem; 24cfb8dRow pattern recognition patch (executor and commands).
1026 57528 RPRNFAState *newState; 24cfb8dRow pattern recognition patch (executor and commands).
1027 - 24cfb8dRow pattern recognition patch (executor and commands).
1028 - /* Branch jump/next links are always -1 or a valid index */ 24cfb8dRow pattern recognition patch (executor and commands).
1029 57528 Assert(altIdx < pattern->numElements); 24cfb8dRow pattern recognition patch (executor and commands).
1030 57528 altElem = &elements[altIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1031 - 24cfb8dRow pattern recognition patch (executor and commands).
1032 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1033 - * Stop if element is outside ALT scope (not a branch). The check 24cfb8dRow pattern recognition patch (executor and commands).
1034 - * fires when the last branch is a quantified group whose BEGIN.jump 24cfb8dRow pattern recognition patch (executor and commands).
1035 - * (set by fillRPRPatternGroup) is preserved -- not overridden by 24cfb8dRow pattern recognition patch (executor and commands).
1036 - * fillRPRPatternAlt, which only links non-last branch heads -- and 24cfb8dRow pattern recognition patch (executor and commands).
1037 - * leads to a post-ALT element. Other branch shapes terminate the 24cfb8dRow pattern recognition patch (executor and commands).
1038 - * walk earlier via altIdx = RPR_ELEMIDX_INVALID. Use <=, not <: the 24cfb8dRow pattern recognition patch (executor and commands).
1039 - * post-ALT element may sit at the same depth as the ALT when the ALT 24cfb8dRow pattern recognition patch (executor and commands).
1040 - * has a sibling at that level. 24cfb8dRow pattern recognition patch (executor and commands).
1041 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1042 57528 if (altElem->depth <= elem->depth) 24cfb8dRow pattern recognition patch (executor and commands).
1043 - break; 24cfb8dRow pattern recognition patch (executor and commands).
1044 - 24cfb8dRow pattern recognition patch (executor and commands).
1045 - /* Create independent state for each branch */ 24cfb8dRow pattern recognition patch (executor and commands).
1046 114336 newState = nfa_state_clone(winstate, altIdx, 24cfb8dRow pattern recognition patch (executor and commands).
1047 57168 state->counts, state->isAbsorbable); 24cfb8dRow pattern recognition patch (executor and commands).
1048 - 24cfb8dRow pattern recognition patch (executor and commands).
1049 - /* Recursively process this branch before next */ 24cfb8dRow pattern recognition patch (executor and commands).
1050 57168 nfa_advance_state(winstate, ctx, newState, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1051 57168 altIdx = altElem->jump; 24cfb8dRow pattern recognition patch (executor and commands).
1052 - } 24cfb8dRow pattern recognition patch (executor and commands).
1053 - 24cfb8dRow pattern recognition patch (executor and commands).
1054 26420 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
1055 26420 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_advance_begin() lines 1067-1129
Modified Lines Coverage: 25/25 lines (100.0%)
LineHitsSourceCommit
1067 19992 nfa_advance_begin(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
1068 - RPRNFAState *state, RPRPatternElement *elem, 24cfb8dRow pattern recognition patch (executor and commands).
1069 - int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
1070 - { 24cfb8dRow pattern recognition patch (executor and commands).
1071 19992 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
1072 19992 RPRPatternElement *elements = pattern->elements; 24cfb8dRow pattern recognition patch (executor and commands).
1073 19992 RPRNFAState *skipState = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1074 - 24cfb8dRow pattern recognition patch (executor and commands).
1075 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1076 - * Entry-side check of the count-clear policy: the group's own count slot 24cfb8dRow pattern recognition patch (executor and commands).
1077 - * is already zero here. BEGIN is only visited at initial group entry, 24cfb8dRow pattern recognition patch (executor and commands).
1078 - * and the previous occupant of this depth slot cleared it on exit. 24cfb8dRow pattern recognition patch (executor and commands).
1079 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1080 19992 Assert(state->counts[elem->depth] == 0); 24cfb8dRow pattern recognition patch (executor and commands).
1081 - 24cfb8dRow pattern recognition patch (executor and commands).
1082 - /* Optional group: create skip path (but don't route yet) */ 24cfb8dRow pattern recognition patch (executor and commands).
1083 19992 if (elem->min == 0) 24cfb8dRow pattern recognition patch (executor and commands).
1084 - { 24cfb8dRow pattern recognition patch (executor and commands).
1085 708 skipState = nfa_state_clone(winstate, elem->jump, 24cfb8dRow pattern recognition patch (executor and commands).
1086 708 state->counts, state->isAbsorbable); 24cfb8dRow pattern recognition patch (executor and commands).
1087 - } 24cfb8dRow pattern recognition patch (executor and commands).
1088 - 24cfb8dRow pattern recognition patch (executor and commands).
1089 708 if (skipState != NULL && RPRElemIsReluctant(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
1090 20 { 24cfb8dRow pattern recognition patch (executor and commands).
1091 28 RPRNFAState *savedMatch = ctx->matchedState; 24cfb8dRow pattern recognition patch (executor and commands).
1092 - 24cfb8dRow pattern recognition patch (executor and commands).
1093 - /* Reluctant: skip first (prefer fewer iterations), enter second */ 24cfb8dRow pattern recognition patch (executor and commands).
1094 28 nfa_route_to_elem(winstate, ctx, skipState, 24cfb8dRow pattern recognition patch (executor and commands).
1095 28 &elements[elem->jump], currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1096 - 24cfb8dRow pattern recognition patch (executor and commands).
1097 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1098 - * If skip path reached FIN, shortest match is found. Skip group entry 24cfb8dRow pattern recognition patch (executor and commands).
1099 - * to prevent longer matches. 24cfb8dRow pattern recognition patch (executor and commands).
1100 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1101 28 if (ctx->matchedState != savedMatch) 24cfb8dRow pattern recognition patch (executor and commands).
1102 - { 24cfb8dRow pattern recognition patch (executor and commands).
1103 8 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
1104 8 return; 24cfb8dRow pattern recognition patch (executor and commands).
1105 - } 24cfb8dRow pattern recognition patch (executor and commands).
1106 - 24cfb8dRow pattern recognition patch (executor and commands).
1107 20 state->elemIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
1108 20 nfa_route_to_elem(winstate, ctx, state, 24cfb8dRow pattern recognition patch (executor and commands).
1109 20 &elements[state->elemIdx], currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1110 - } 24cfb8dRow pattern recognition patch (executor and commands).
1111 - else 24cfb8dRow pattern recognition patch (executor and commands).
1112 - { 24cfb8dRow pattern recognition patch (executor and commands).
1113 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1114 - * Greedy-or-non-nullable: route to the first child. For optional 24cfb8dRow pattern recognition patch (executor and commands).
1115 - * groups (skipState != NULL, greedy min=0) additionally create the 24cfb8dRow pattern recognition patch (executor and commands).
1116 - * skip path; for non-nullable groups (skipState == NULL, min>0) the 24cfb8dRow pattern recognition patch (executor and commands).
1117 - * skip-path action is suppressed by the guard below. 24cfb8dRow pattern recognition patch (executor and commands).
1118 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1119 19964 state->elemIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
1120 19964 nfa_route_to_elem(winstate, ctx, state, 24cfb8dRow pattern recognition patch (executor and commands).
1121 19964 &elements[state->elemIdx], currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1122 - 24cfb8dRow pattern recognition patch (executor and commands).
1123 19964 if (skipState != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1124 - { 24cfb8dRow pattern recognition patch (executor and commands).
1125 680 nfa_route_to_elem(winstate, ctx, skipState, 24cfb8dRow pattern recognition patch (executor and commands).
1126 680 &elements[elem->jump], currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1127 - } 24cfb8dRow pattern recognition patch (executor and commands).
1128 - } 24cfb8dRow pattern recognition patch (executor and commands).
1129 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_advance_end() lines 1138-1312
Modified Lines Coverage: 62/62 lines (100.0%)
LineHitsSourceCommit
1138 12688 nfa_advance_end(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
1139 - RPRNFAState *state, RPRPatternElement *elem, 24cfb8dRow pattern recognition patch (executor and commands).
1140 - int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
1141 - { 24cfb8dRow pattern recognition patch (executor and commands).
1142 12688 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
1143 12688 RPRPatternElement *elements = pattern->elements; 24cfb8dRow pattern recognition patch (executor and commands).
1144 12688 int depth = elem->depth; 24cfb8dRow pattern recognition patch (executor and commands).
1145 12688 int32 count = state->counts[depth]; 24cfb8dRow pattern recognition patch (executor and commands).
1146 - 24cfb8dRow pattern recognition patch (executor and commands).
1147 12688 if (count < elem->min) 24cfb8dRow pattern recognition patch (executor and commands).
1148 - { 24cfb8dRow pattern recognition patch (executor and commands).
1149 4036 RPRPatternElement *jumpElem; 24cfb8dRow pattern recognition patch (executor and commands).
1150 4036 RPRNFAState *ffState = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1151 4036 RPRPatternElement *nextElem = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1152 - 24cfb8dRow pattern recognition patch (executor and commands).
1153 - /*---------- 24cfb8dRow pattern recognition patch (executor and commands).
1154 - * Two paths are explored when the group body is nullable 24cfb8dRow pattern recognition patch (executor and commands).
1155 - * (RPR_ELEM_EMPTY_LOOP): 24cfb8dRow pattern recognition patch (executor and commands).
1156 - * 24cfb8dRow pattern recognition patch (executor and commands).
1157 - * 1. Loop-back path: attempt real matches in the next iteration 24cfb8dRow pattern recognition patch (executor and commands).
1158 - * (state, modified below). 24cfb8dRow pattern recognition patch (executor and commands).
1159 - * 24cfb8dRow pattern recognition patch (executor and commands).
1160 - * 2. Fast-forward path: skip directly to after the group, treating 24cfb8dRow pattern recognition patch (executor and commands).
1161 - * all remaining required iterations as empty matches (ffState). 24cfb8dRow pattern recognition patch (executor and commands).
1162 - * Route to elem->next (not nfa_advance_end) to avoid creating 24cfb8dRow pattern recognition patch (executor and commands).
1163 - * competing greedy/reluctant loop states. 24cfb8dRow pattern recognition patch (executor and commands).
1164 - * 24cfb8dRow pattern recognition patch (executor and commands).
1165 - * Greedy prefers the loop-back first (more iterations); reluctant 24cfb8dRow pattern recognition patch (executor and commands).
1166 - * prefers the fast-forward (exit) first and, if it reaches FIN, drops 24cfb8dRow pattern recognition patch (executor and commands).
1167 - * the loop-back so a longer match cannot replace the shortest one -- 24cfb8dRow pattern recognition patch (executor and commands).
1168 - * mirroring the min<=count<max branch below. The ffState snapshot is 24cfb8dRow pattern recognition patch (executor and commands).
1169 - * taken BEFORE modifying state, since both paths diverge from here. 24cfb8dRow pattern recognition patch (executor and commands).
1170 - *---------- 24cfb8dRow pattern recognition patch (executor and commands).
1171 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1172 4036 if (RPRElemCanEmptyLoop(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
1173 - { 24cfb8dRow pattern recognition patch (executor and commands).
1174 568 ffState = nfa_state_clone(winstate, state->elemIdx, 24cfb8dRow pattern recognition patch (executor and commands).
1175 284 state->counts, state->isAbsorbable); 24cfb8dRow pattern recognition patch (executor and commands).
1176 - 24cfb8dRow pattern recognition patch (executor and commands).
1177 - /* Exit the group: clear its own count (count-clear policy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1178 284 ffState->counts[depth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
1179 284 ffState->elemIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
1180 284 nextElem = &elements[ffState->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1181 - 24cfb8dRow pattern recognition patch (executor and commands).
1182 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1183 - * Unlike the must-exit path, no isAbsorbable update is needed: 24cfb8dRow pattern recognition patch (executor and commands).
1184 - * the fast-forward path runs only for EMPTY_LOOP (nullable) 24cfb8dRow pattern recognition patch (executor and commands).
1185 - * groups, which are never inside an absorbable region, so 24cfb8dRow pattern recognition patch (executor and commands).
1186 - * isAbsorbable is already false here. 24cfb8dRow pattern recognition patch (executor and commands).
1187 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1188 - 24cfb8dRow pattern recognition patch (executor and commands).
1189 - /* END->END: increment outer END's count */ 24cfb8dRow pattern recognition patch (executor and commands).
1190 284 if (RPRElemIsEnd(nextElem) && 24cfb8dRow pattern recognition patch (executor and commands).
1191 12 ffState->counts[nextElem->depth] < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1192 12 ffState->counts[nextElem->depth]++; 24cfb8dRow pattern recognition patch (executor and commands).
1193 - } 24cfb8dRow pattern recognition patch (executor and commands).
1194 - 24cfb8dRow pattern recognition patch (executor and commands).
1195 - /* Prepare the loop-back state */ 24cfb8dRow pattern recognition patch (executor and commands).
1196 4036 state->elemIdx = elem->jump; 24cfb8dRow pattern recognition patch (executor and commands).
1197 4036 jumpElem = &elements[state->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1198 - 24cfb8dRow pattern recognition patch (executor and commands).
1199 4036 if (ffState != NULL && RPRElemIsReluctant(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
1200 28 { 24cfb8dRow pattern recognition patch (executor and commands).
1201 104 RPRNFAState *savedMatch = ctx->matchedState; 24cfb8dRow pattern recognition patch (executor and commands).
1202 - 24cfb8dRow pattern recognition patch (executor and commands).
1203 - /* Reluctant: take the fast-forward (exit) first */ 24cfb8dRow pattern recognition patch (executor and commands).
1204 104 nfa_route_to_elem(winstate, ctx, ffState, nextElem, 24cfb8dRow pattern recognition patch (executor and commands).
1205 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1206 - 24cfb8dRow pattern recognition patch (executor and commands).
1207 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1208 - * If the exit reached FIN, the shortest match is found. Skip the 24cfb8dRow pattern recognition patch (executor and commands).
1209 - * loop-back to prevent longer matches from replacing it. 24cfb8dRow pattern recognition patch (executor and commands).
1210 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1211 104 if (ctx->matchedState != savedMatch) 24cfb8dRow pattern recognition patch (executor and commands).
1212 - { 24cfb8dRow pattern recognition patch (executor and commands).
1213 76 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
1214 76 return; 24cfb8dRow pattern recognition patch (executor and commands).
1215 - } 24cfb8dRow pattern recognition patch (executor and commands).
1216 - 24cfb8dRow pattern recognition patch (executor and commands).
1217 - /* Loop-back second */ 24cfb8dRow pattern recognition patch (executor and commands).
1218 28 nfa_route_to_elem(winstate, ctx, state, jumpElem, 24cfb8dRow pattern recognition patch (executor and commands).
1219 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1220 - } 24cfb8dRow pattern recognition patch (executor and commands).
1221 - else 24cfb8dRow pattern recognition patch (executor and commands).
1222 - { 24cfb8dRow pattern recognition patch (executor and commands).
1223 - /* Greedy (or non-nullable): loop-back first, fast-forward second */ 24cfb8dRow pattern recognition patch (executor and commands).
1224 3932 nfa_route_to_elem(winstate, ctx, state, jumpElem, 24cfb8dRow pattern recognition patch (executor and commands).
1225 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1226 3932 if (ffState != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1227 180 nfa_route_to_elem(winstate, ctx, ffState, nextElem, 24cfb8dRow pattern recognition patch (executor and commands).
1228 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1229 - } 24cfb8dRow pattern recognition patch (executor and commands).
1230 - } 24cfb8dRow pattern recognition patch (executor and commands).
1231 8652 else if (elem->max != RPR_QUANTITY_INF && count >= elem->max) 24cfb8dRow pattern recognition patch (executor and commands).
1232 484 { 24cfb8dRow pattern recognition patch (executor and commands).
1233 - /* Must exit: reached max iterations. */ 24cfb8dRow pattern recognition patch (executor and commands).
1234 484 RPRPatternElement *nextElem; 24cfb8dRow pattern recognition patch (executor and commands).
1235 - 24cfb8dRow pattern recognition patch (executor and commands).
1236 - /* Exit: clear the group's own count (count-clear policy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1237 484 state->counts[depth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
1238 484 state->elemIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
1239 484 nextElem = &elements[state->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1240 - 24cfb8dRow pattern recognition patch (executor and commands).
1241 - /* Update isAbsorbable for target element (monotonic) */ 24cfb8dRow pattern recognition patch (executor and commands).
1242 484 state->isAbsorbable = state->isAbsorbable && 24cfb8dRow pattern recognition patch (executor and commands).
1243 216 RPRElemIsAbsorbableBranch(nextElem); 24cfb8dRow pattern recognition patch (executor and commands).
1244 - 24cfb8dRow pattern recognition patch (executor and commands).
1245 - /* END->END: increment outer END's count */ 24cfb8dRow pattern recognition patch (executor and commands).
1246 484 if (RPRElemIsEnd(nextElem) && state->counts[nextElem->depth] < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1247 16 state->counts[nextElem->depth]++; 24cfb8dRow pattern recognition patch (executor and commands).
1248 - 24cfb8dRow pattern recognition patch (executor and commands).
1249 484 nfa_route_to_elem(winstate, ctx, state, nextElem, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1250 - } 24cfb8dRow pattern recognition patch (executor and commands).
1251 - else 24cfb8dRow pattern recognition patch (executor and commands).
1252 - { 24cfb8dRow pattern recognition patch (executor and commands).
1253 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1254 - * Between min and max (with at least one iteration) - can exit or 24cfb8dRow pattern recognition patch (executor and commands).
1255 - * loop. Greedy: loop first (prefer more iterations). Reluctant: exit 24cfb8dRow pattern recognition patch (executor and commands).
1256 - * first (prefer fewer iterations). 24cfb8dRow pattern recognition patch (executor and commands).
1257 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1258 8168 RPRNFAState *exitState; 24cfb8dRow pattern recognition patch (executor and commands).
1259 8168 RPRPatternElement *jumpElem; 24cfb8dRow pattern recognition patch (executor and commands).
1260 8168 RPRPatternElement *nextElem; 24cfb8dRow pattern recognition patch (executor and commands).
1261 - 24cfb8dRow pattern recognition patch (executor and commands).
1262 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1263 - * Create exit state first (need original counts before modifying 24cfb8dRow pattern recognition patch (executor and commands).
1264 - * state) 24cfb8dRow pattern recognition patch (executor and commands).
1265 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1266 16336 exitState = nfa_state_clone(winstate, elem->next, 24cfb8dRow pattern recognition patch (executor and commands).
1267 8168 state->counts, state->isAbsorbable); 24cfb8dRow pattern recognition patch (executor and commands).
1268 - /* Exit branch: clear the group's own count (count-clear policy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1269 8168 exitState->counts[depth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
1270 8168 nextElem = &elements[exitState->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1271 - 24cfb8dRow pattern recognition patch (executor and commands).
1272 - /* END->END: increment outer END's count */ 24cfb8dRow pattern recognition patch (executor and commands).
1273 8168 if (RPRElemIsEnd(nextElem) && exitState->counts[nextElem->depth] < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1274 84 exitState->counts[nextElem->depth]++; 24cfb8dRow pattern recognition patch (executor and commands).
1275 - 24cfb8dRow pattern recognition patch (executor and commands).
1276 - /* Prepare loop state */ 24cfb8dRow pattern recognition patch (executor and commands).
1277 8168 state->elemIdx = elem->jump; 24cfb8dRow pattern recognition patch (executor and commands).
1278 8168 jumpElem = &elements[state->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1279 - 24cfb8dRow pattern recognition patch (executor and commands).
1280 8168 if (RPRElemIsReluctant(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
1281 - { 24cfb8dRow pattern recognition patch (executor and commands).
1282 44 RPRNFAState *savedMatch = ctx->matchedState; 24cfb8dRow pattern recognition patch (executor and commands).
1283 - 24cfb8dRow pattern recognition patch (executor and commands).
1284 - /* Exit first (preferred for reluctant) */ 24cfb8dRow pattern recognition patch (executor and commands).
1285 44 nfa_route_to_elem(winstate, ctx, exitState, nextElem, 24cfb8dRow pattern recognition patch (executor and commands).
1286 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1287 - 24cfb8dRow pattern recognition patch (executor and commands).
1288 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1289 - * If exit path reached FIN, shortest match is found. Skip loop to 24cfb8dRow pattern recognition patch (executor and commands).
1290 - * prevent longer matches from replacing it. 24cfb8dRow pattern recognition patch (executor and commands).
1291 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1292 44 if (ctx->matchedState != savedMatch) 24cfb8dRow pattern recognition patch (executor and commands).
1293 - { 24cfb8dRow pattern recognition patch (executor and commands).
1294 28 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
1295 28 return; 24cfb8dRow pattern recognition patch (executor and commands).
1296 - } 24cfb8dRow pattern recognition patch (executor and commands).
1297 - 24cfb8dRow pattern recognition patch (executor and commands).
1298 - /* Loop second */ 24cfb8dRow pattern recognition patch (executor and commands).
1299 16 nfa_route_to_elem(winstate, ctx, state, jumpElem, 24cfb8dRow pattern recognition patch (executor and commands).
1300 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1301 - } 24cfb8dRow pattern recognition patch (executor and commands).
1302 - else 24cfb8dRow pattern recognition patch (executor and commands).
1303 - { 24cfb8dRow pattern recognition patch (executor and commands).
1304 - /* Loop first (preferred for greedy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1305 8124 nfa_route_to_elem(winstate, ctx, state, jumpElem, 24cfb8dRow pattern recognition patch (executor and commands).
1306 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1307 - /* Exit second */ 24cfb8dRow pattern recognition patch (executor and commands).
1308 8124 nfa_route_to_elem(winstate, ctx, exitState, nextElem, 24cfb8dRow pattern recognition patch (executor and commands).
1309 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1310 - } 24cfb8dRow pattern recognition patch (executor and commands).
1311 - } 24cfb8dRow pattern recognition patch (executor and commands).
1312 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_advance_var() lines 1321-1455
Modified Lines Coverage: 52/52 lines (100.0%)
LineHitsSourceCommit
1321 2159452 nfa_advance_var(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
1322 - RPRNFAState *state, RPRPatternElement *elem, 24cfb8dRow pattern recognition patch (executor and commands).
1323 - int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
1324 - { 24cfb8dRow pattern recognition patch (executor and commands).
1325 2159452 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
1326 2159452 RPRPatternElement *elements = pattern->elements; 24cfb8dRow pattern recognition patch (executor and commands).
1327 2159452 int depth = elem->depth; 24cfb8dRow pattern recognition patch (executor and commands).
1328 2159452 int32 count = state->counts[depth]; 24cfb8dRow pattern recognition patch (executor and commands).
1329 2159452 bool canLoop = (elem->max == RPR_QUANTITY_INF || count < elem->max); 24cfb8dRow pattern recognition patch (executor and commands).
1330 2159452 bool canExit = (count >= elem->min); 24cfb8dRow pattern recognition patch (executor and commands).
1331 - 24cfb8dRow pattern recognition patch (executor and commands).
1332 - /* min <= max, so !canExit (count < min) implies canLoop (count < max) */ 24cfb8dRow pattern recognition patch (executor and commands).
1333 2159452 Assert(canLoop || canExit); 24cfb8dRow pattern recognition patch (executor and commands).
1334 - 24cfb8dRow pattern recognition patch (executor and commands).
1335 - /* elem->next must be a valid index for any reachable VAR */ 24cfb8dRow pattern recognition patch (executor and commands).
1336 2159452 Assert(elem->next >= 0 && elem->next < pattern->numElements); 24cfb8dRow pattern recognition patch (executor and commands).
1337 - 24cfb8dRow pattern recognition patch (executor and commands).
1338 2159452 if (canLoop && canExit) 24cfb8dRow pattern recognition patch (executor and commands).
1339 - { 24cfb8dRow pattern recognition patch (executor and commands).
1340 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1341 - * Both loop and exit possible. Greedy: loop first (prefer longer 24cfb8dRow pattern recognition patch (executor and commands).
1342 - * match). Reluctant: exit first (prefer shorter match). 24cfb8dRow pattern recognition patch (executor and commands).
1343 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1344 815304 RPRNFAState *cloneState; 24cfb8dRow pattern recognition patch (executor and commands).
1345 815304 RPRPatternElement *nextElem; 24cfb8dRow pattern recognition patch (executor and commands).
1346 815304 bool reluctant = RPRElemIsReluctant(elem); 24cfb8dRow pattern recognition patch (executor and commands).
1347 - 24cfb8dRow pattern recognition patch (executor and commands).
1348 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1349 - * Clone state for the first-priority path. For greedy, clone is the 24cfb8dRow pattern recognition patch (executor and commands).
1350 - * loop state; for reluctant, clone is the exit state. 24cfb8dRow pattern recognition patch (executor and commands).
1351 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1352 815304 if (reluctant) 24cfb8dRow pattern recognition patch (executor and commands).
1353 - { 24cfb8dRow pattern recognition patch (executor and commands).
1354 540 RPRNFAState *savedMatch = ctx->matchedState; 24cfb8dRow pattern recognition patch (executor and commands).
1355 - 24cfb8dRow pattern recognition patch (executor and commands).
1356 - /* Clone for exit, original stays for loop */ 24cfb8dRow pattern recognition patch (executor and commands).
1357 1080 cloneState = nfa_state_clone(winstate, elem->next, 24cfb8dRow pattern recognition patch (executor and commands).
1358 540 state->counts, state->isAbsorbable); 24cfb8dRow pattern recognition patch (executor and commands).
1359 - /* Exit: clear the VAR's own count (count-clear policy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1360 540 cloneState->counts[depth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
1361 540 nextElem = &elements[cloneState->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1362 - 24cfb8dRow pattern recognition patch (executor and commands).
1363 - /* When exiting directly to an outer END, increment its count */ 24cfb8dRow pattern recognition patch (executor and commands).
1364 540 if (RPRElemIsEnd(nextElem)) 24cfb8dRow pattern recognition patch (executor and commands).
1365 - { 24cfb8dRow pattern recognition patch (executor and commands).
1366 28 if (cloneState->counts[nextElem->depth] < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1367 28 cloneState->counts[nextElem->depth]++; 24cfb8dRow pattern recognition patch (executor and commands).
1368 - } 24cfb8dRow pattern recognition patch (executor and commands).
1369 - 24cfb8dRow pattern recognition patch (executor and commands).
1370 - /* Exit first (preferred for reluctant) */ 24cfb8dRow pattern recognition patch (executor and commands).
1371 540 nfa_route_to_elem(winstate, ctx, cloneState, nextElem, 24cfb8dRow pattern recognition patch (executor and commands).
1372 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1373 - 24cfb8dRow pattern recognition patch (executor and commands).
1374 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1375 - * If exit path reached FIN, the shortest match is found. Skip 24cfb8dRow pattern recognition patch (executor and commands).
1376 - * loop state to prevent longer matches from replacing it. 24cfb8dRow pattern recognition patch (executor and commands).
1377 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1378 540 if (ctx->matchedState != savedMatch) 24cfb8dRow pattern recognition patch (executor and commands).
1379 - { 24cfb8dRow pattern recognition patch (executor and commands).
1380 288 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
1381 288 return; 24cfb8dRow pattern recognition patch (executor and commands).
1382 - } 24cfb8dRow pattern recognition patch (executor and commands).
1383 - 24cfb8dRow pattern recognition patch (executor and commands).
1384 - /* Loop second */ 24cfb8dRow pattern recognition patch (executor and commands).
1385 252 nfa_add_state_unique(winstate, ctx, state); 24cfb8dRow pattern recognition patch (executor and commands).
1386 - } 24cfb8dRow pattern recognition patch (executor and commands).
1387 - else 24cfb8dRow pattern recognition patch (executor and commands).
1388 - { 24cfb8dRow pattern recognition patch (executor and commands).
1389 - /* Clone for loop, original used for exit */ 24cfb8dRow pattern recognition patch (executor and commands).
1390 1629528 cloneState = nfa_state_clone(winstate, state->elemIdx, 24cfb8dRow pattern recognition patch (executor and commands).
1391 814764 state->counts, state->isAbsorbable); 24cfb8dRow pattern recognition patch (executor and commands).
1392 - 24cfb8dRow pattern recognition patch (executor and commands).
1393 - /* Loop first (preferred for greedy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1394 814764 nfa_add_state_unique(winstate, ctx, cloneState); 24cfb8dRow pattern recognition patch (executor and commands).
1395 - 24cfb8dRow pattern recognition patch (executor and commands).
1396 - /* Exit second: clear the VAR's own count (count-clear policy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1397 814764 state->counts[depth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
1398 814764 state->elemIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
1399 814764 nextElem = &elements[state->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1400 - 24cfb8dRow pattern recognition patch (executor and commands).
1401 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1402 - * Update isAbsorbable for target element (monotonic: AND 24cfb8dRow pattern recognition patch (executor and commands).
1403 - * preserves false) 24cfb8dRow pattern recognition patch (executor and commands).
1404 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1405 814764 state->isAbsorbable = state->isAbsorbable && 24cfb8dRow pattern recognition patch (executor and commands).
1406 372472 RPRElemIsAbsorbableBranch(nextElem); 24cfb8dRow pattern recognition patch (executor and commands).
1407 - 24cfb8dRow pattern recognition patch (executor and commands).
1408 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1409 - * When exiting directly to an outer END, increment its iteration 24cfb8dRow pattern recognition patch (executor and commands).
1410 - * count. Simple VARs (min=max=1) handle this via inline advance 24cfb8dRow pattern recognition patch (executor and commands).
1411 - * in nfa_match, but quantified VARs bypass that path. 24cfb8dRow pattern recognition patch (executor and commands).
1412 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1413 814764 if (RPRElemIsEnd(nextElem)) 24cfb8dRow pattern recognition patch (executor and commands).
1414 - { 24cfb8dRow pattern recognition patch (executor and commands).
1415 324 if (state->counts[nextElem->depth] < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1416 324 state->counts[nextElem->depth]++; 24cfb8dRow pattern recognition patch (executor and commands).
1417 - } 24cfb8dRow pattern recognition patch (executor and commands).
1418 - 24cfb8dRow pattern recognition patch (executor and commands).
1419 814764 nfa_route_to_elem(winstate, ctx, state, nextElem, 24cfb8dRow pattern recognition patch (executor and commands).
1420 - currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1421 - } 24cfb8dRow pattern recognition patch (executor and commands).
1422 - } 24cfb8dRow pattern recognition patch (executor and commands).
1423 1344148 else if (canLoop) 24cfb8dRow pattern recognition patch (executor and commands).
1424 - { 24cfb8dRow pattern recognition patch (executor and commands).
1425 - /* Loop only: keep state as-is */ 24cfb8dRow pattern recognition patch (executor and commands).
1426 1260604 nfa_add_state_unique(winstate, ctx, state); 24cfb8dRow pattern recognition patch (executor and commands).
1427 - } 24cfb8dRow pattern recognition patch (executor and commands).
1428 - else 24cfb8dRow pattern recognition patch (executor and commands).
1429 - { 24cfb8dRow pattern recognition patch (executor and commands).
1430 - /* Exit only: advance to next element (canExit necessarily true) */ 24cfb8dRow pattern recognition patch (executor and commands).
1431 83544 RPRPatternElement *nextElem; 24cfb8dRow pattern recognition patch (executor and commands).
1432 - 24cfb8dRow pattern recognition patch (executor and commands).
1433 83544 Assert(canExit); 24cfb8dRow pattern recognition patch (executor and commands).
1434 - /* Exit: clear the VAR's own count (count-clear policy) */ 24cfb8dRow pattern recognition patch (executor and commands).
1435 83544 state->counts[depth] = 0; 24cfb8dRow pattern recognition patch (executor and commands).
1436 83544 state->elemIdx = elem->next; 24cfb8dRow pattern recognition patch (executor and commands).
1437 83544 nextElem = &elements[state->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1438 - 24cfb8dRow pattern recognition patch (executor and commands).
1439 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1440 - * Update isAbsorbable for target element (monotonic: AND preserves 24cfb8dRow pattern recognition patch (executor and commands).
1441 - * false) 24cfb8dRow pattern recognition patch (executor and commands).
1442 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1443 83544 state->isAbsorbable = state->isAbsorbable && 24cfb8dRow pattern recognition patch (executor and commands).
1444 2508 RPRElemIsAbsorbableBranch(nextElem); 24cfb8dRow pattern recognition patch (executor and commands).
1445 - 24cfb8dRow pattern recognition patch (executor and commands).
1446 - /* See comment above: increment outer END count for quantified VARs */ 24cfb8dRow pattern recognition patch (executor and commands).
1447 83544 if (RPRElemIsEnd(nextElem)) 24cfb8dRow pattern recognition patch (executor and commands).
1448 - { 24cfb8dRow pattern recognition patch (executor and commands).
1449 10372 if (state->counts[nextElem->depth] < RPR_COUNT_INF) 9c7e5bcImprove comments, documentation, and naming for row pattern recognition
1450 10372 state->counts[nextElem->depth]++; 24cfb8dRow pattern recognition patch (executor and commands).
1451 - } 24cfb8dRow pattern recognition patch (executor and commands).
1452 - 24cfb8dRow pattern recognition patch (executor and commands).
1453 83544 nfa_route_to_elem(winstate, ctx, state, nextElem, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1454 - } 24cfb8dRow pattern recognition patch (executor and commands).
1455 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_advance_state() lines 1464-1518
Modified Lines Coverage: 28/28 lines (100.0%)
LineHitsSourceCommit
1464 2581788 nfa_advance_state(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
1465 - RPRNFAState *state, int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
1466 - { 24cfb8dRow pattern recognition patch (executor and commands).
1467 2581788 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
1468 2581788 RPRPatternElement *elem; 24cfb8dRow pattern recognition patch (executor and commands).
1469 - 24cfb8dRow pattern recognition patch (executor and commands).
1470 2581788 Assert(state->elemIdx >= 0 && state->elemIdx < pattern->numElements); 24cfb8dRow pattern recognition patch (executor and commands).
1471 - 24cfb8dRow pattern recognition patch (executor and commands).
1472 - /* Protect against stack overflow for deeply complex patterns */ 24cfb8dRow pattern recognition patch (executor and commands).
1473 2581788 check_stack_depth(); 24cfb8dRow pattern recognition patch (executor and commands).
1474 - 24cfb8dRow pattern recognition patch (executor and commands).
1475 - /* Cycle detection: if this elemIdx was already visited in this DFS, bail */ 24cfb8dRow pattern recognition patch (executor and commands).
1476 2581788 if (winstate->nfaVisitedElems[WORDNUM(state->elemIdx)] & 24cfb8dRow pattern recognition patch (executor and commands).
1477 2581788 ((bitmapword) 1 << BITNUM(state->elemIdx))) 24cfb8dRow pattern recognition patch (executor and commands).
1478 - { 24cfb8dRow pattern recognition patch (executor and commands).
1479 520 nfa_state_free(winstate, state); 24cfb8dRow pattern recognition patch (executor and commands).
1480 520 return; 24cfb8dRow pattern recognition patch (executor and commands).
1481 - } 24cfb8dRow pattern recognition patch (executor and commands).
1482 - 24cfb8dRow pattern recognition patch (executor and commands).
1483 2581268 elem = &pattern->elements[state->elemIdx]; 24cfb8dRow pattern recognition patch (executor and commands).
1484 - 24cfb8dRow pattern recognition patch (executor and commands).
1485 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1486 - * Mark epsilon elements (END, ALT, BEGIN, FIN) in visited to prevent 24cfb8dRow pattern recognition patch (executor and commands).
1487 - * infinite epsilon cycles. VAR elements are marked later when added to 24cfb8dRow pattern recognition patch (executor and commands).
1488 - * the state list (nfa_add_state_unique), allowing legitimate loop-back to 24cfb8dRow pattern recognition patch (executor and commands).
1489 - * the same VAR in a new iteration. 24cfb8dRow pattern recognition patch (executor and commands).
1490 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1491 2581268 if (!RPRElemIsVar(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
1492 421816 nfa_mark_visited(winstate, state->elemIdx); 24cfb8dRow pattern recognition patch (executor and commands).
1493 - 24cfb8dRow pattern recognition patch (executor and commands).
1494 2581268 switch (elem->varId) 24cfb8dRow pattern recognition patch (executor and commands).
1495 - { 24cfb8dRow pattern recognition patch (executor and commands).
1496 362716 case RPR_VARID_FIN: 24cfb8dRow pattern recognition patch (executor and commands).
1497 - /* FIN: record match */ 24cfb8dRow pattern recognition patch (executor and commands).
1498 362716 nfa_add_matched_state(winstate, ctx, state, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1499 362716 break; 24cfb8dRow pattern recognition patch (executor and commands).
1500 - 24cfb8dRow pattern recognition patch (executor and commands).
1501 26420 case RPR_VARID_ALT: 24cfb8dRow pattern recognition patch (executor and commands).
1502 26420 nfa_advance_alt(winstate, ctx, state, elem, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1503 26420 break; 24cfb8dRow pattern recognition patch (executor and commands).
1504 - 24cfb8dRow pattern recognition patch (executor and commands).
1505 19992 case RPR_VARID_BEGIN: 24cfb8dRow pattern recognition patch (executor and commands).
1506 19992 nfa_advance_begin(winstate, ctx, state, elem, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1507 19992 break; 24cfb8dRow pattern recognition patch (executor and commands).
1508 - 24cfb8dRow pattern recognition patch (executor and commands).
1509 12688 case RPR_VARID_END: 24cfb8dRow pattern recognition patch (executor and commands).
1510 12688 nfa_advance_end(winstate, ctx, state, elem, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1511 12688 break; 24cfb8dRow pattern recognition patch (executor and commands).
1512 - 24cfb8dRow pattern recognition patch (executor and commands).
1513 2159452 default: 24cfb8dRow pattern recognition patch (executor and commands).
1514 - /* VAR element */ 24cfb8dRow pattern recognition patch (executor and commands).
1515 2159452 nfa_advance_var(winstate, ctx, state, elem, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1516 2159452 break; 24cfb8dRow pattern recognition patch (executor and commands).
1517 - } 24cfb8dRow pattern recognition patch (executor and commands).
1518 - } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_advance() lines 1530-1588
Modified Lines Coverage: 22/22 lines (100.0%)
LineHitsSourceCommit
1530 2005648 nfa_advance(WindowAggState *winstate, RPRNFAContext *ctx, int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
1531 - { 24cfb8dRow pattern recognition patch (executor and commands).
1532 2005648 RPRNFAState *states = ctx->states; 24cfb8dRow pattern recognition patch (executor and commands).
1533 2005648 RPRNFAState *state; 24cfb8dRow pattern recognition patch (executor and commands).
1534 2005648 RPRNFAState *savedMatchedState; 24cfb8dRow pattern recognition patch (executor and commands).
1535 - 24cfb8dRow pattern recognition patch (executor and commands).
1536 2005648 ctx->states = NULL; /* Will rebuild */ 24cfb8dRow pattern recognition patch (executor and commands).
1537 - 24cfb8dRow pattern recognition patch (executor and commands).
1538 - /* Process each state in lexical order (DFS order from previous advance) */ 24cfb8dRow pattern recognition patch (executor and commands).
1539 3634688 while (states != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1540 - { 24cfb8dRow pattern recognition patch (executor and commands).
1541 1991756 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
1542 1991756 savedMatchedState = ctx->matchedState; 24cfb8dRow pattern recognition patch (executor and commands).
1543 - 24cfb8dRow pattern recognition patch (executor and commands).
1544 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1545 - * Clear visited bitmap before each state's DFS expansion. Only the 24cfb8dRow pattern recognition patch (executor and commands).
1546 - * range touched since the previous reset (tracked via the high-water 24cfb8dRow pattern recognition patch (executor and commands).
1547 - * marks updated in nfa_mark_visited) needs to be cleared; for small 24cfb8dRow pattern recognition patch (executor and commands).
1548 - * NFAs this is the whole array, but for large NFAs whose DFS only 24cfb8dRow pattern recognition patch (executor and commands).
1549 - * reaches a few elements per advance it avoids walking the full 24cfb8dRow pattern recognition patch (executor and commands).
1550 - * bitmap. 24cfb8dRow pattern recognition patch (executor and commands).
1551 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1552 1991756 if (winstate->nfaVisitedMaxWord >= winstate->nfaVisitedMinWord) 24cfb8dRow pattern recognition patch (executor and commands).
1553 - { 24cfb8dRow pattern recognition patch (executor and commands).
1554 1989292 memset(&winstate->nfaVisitedElems[winstate->nfaVisitedMinWord], 0, 24cfb8dRow pattern recognition patch (executor and commands).
1555 - sizeof(bitmapword) * 24cfb8dRow pattern recognition patch (executor and commands).
1556 1989292 (winstate->nfaVisitedMaxWord - 24cfb8dRow pattern recognition patch (executor and commands).
1557 1989292 winstate->nfaVisitedMinWord + 1)); 24cfb8dRow pattern recognition patch (executor and commands).
1558 1989292 winstate->nfaVisitedMinWord = PG_INT16_MAX; 24cfb8dRow pattern recognition patch (executor and commands).
1559 1989292 winstate->nfaVisitedMaxWord = -1; 24cfb8dRow pattern recognition patch (executor and commands).
1560 - } 24cfb8dRow pattern recognition patch (executor and commands).
1561 - 24cfb8dRow pattern recognition patch (executor and commands).
1562 1991756 state = states; 24cfb8dRow pattern recognition patch (executor and commands).
1563 1991756 states = states->next; 24cfb8dRow pattern recognition patch (executor and commands).
1564 - 24cfb8dRow pattern recognition patch (executor and commands).
1565 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1566 - * Boundary contract: state->next is reset to NULL here, before 24cfb8dRow pattern recognition patch (executor and commands).
1567 - * crossing into nfa_advance_state's epsilon-expansion DFS. The inner 24cfb8dRow pattern recognition patch (executor and commands).
1568 - * branches (nfa_advance_var, nfa_advance_begin/end/alt) treat 24cfb8dRow pattern recognition patch (executor and commands).
1569 - * state->next as already-NULL and don't reset it themselves; the 24cfb8dRow pattern recognition patch (executor and commands).
1570 - * other linking site is nfa_add_state_unique, which sets it when 24cfb8dRow pattern recognition patch (executor and commands).
1571 - * appending to ctx->states. 24cfb8dRow pattern recognition patch (executor and commands).
1572 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1573 1991756 state->next = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1574 - 24cfb8dRow pattern recognition patch (executor and commands).
1575 1991756 nfa_advance_state(winstate, ctx, state, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1576 - 24cfb8dRow pattern recognition patch (executor and commands).
1577 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1578 - * Early termination: if a FIN was newly reached in this advance, 24cfb8dRow pattern recognition patch (executor and commands).
1579 - * remaining old states have worse lexical order and can be pruned. 24cfb8dRow pattern recognition patch (executor and commands).
1580 - * Only check for new FIN arrivals (not ones from previous rows). 24cfb8dRow pattern recognition patch (executor and commands).
1581 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1582 1991756 if (ctx->matchedState != savedMatchedState && states != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1583 - { 24cfb8dRow pattern recognition patch (executor and commands).
1584 240 nfa_state_free_list(winstate, states); 24cfb8dRow pattern recognition patch (executor and commands).
1585 240 break; 24cfb8dRow pattern recognition patch (executor and commands).
1586 - } 24cfb8dRow pattern recognition patch (executor and commands).
1587 - } 24cfb8dRow pattern recognition patch (executor and commands).
1588 2005648 } 24cfb8dRow pattern recognition patch (executor and commands).
nfa_reevaluate_dependent_vars() lines 1601-1636
Modified Lines Coverage: 19/19 lines (100.0%)
LineHitsSourceCommit
1601 5500 nfa_reevaluate_dependent_vars(WindowAggState *winstate, RPRNFAContext *ctx, 24cfb8dRow pattern recognition patch (executor and commands).
1602 - int64 currentPos) 24cfb8dRow pattern recognition patch (executor and commands).
1603 - { 24cfb8dRow pattern recognition patch (executor and commands).
1604 5500 ExprContext *econtext = winstate->rprContext; a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1605 5500 int64 saved_match_start = winstate->nav_match_start; 24cfb8dRow pattern recognition patch (executor and commands).
1606 5500 int64 saved_pos = winstate->currentpos; 24cfb8dRow pattern recognition patch (executor and commands).
1607 - 24cfb8dRow pattern recognition patch (executor and commands).
1608 - /* Release the previous evaluation's DEFINE expression memory */ a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1609 5500 ResetExprContext(econtext); a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1610 - a70f1c1Use a dedicated ExprContext for RPR DEFINE clause evaluation
1611 - /* Temporarily set nav_match_start and currentpos for FIRST/LAST */ 24cfb8dRow pattern recognition patch (executor and commands).
1612 5500 winstate->nav_match_start = ctx->matchStartRow; 24cfb8dRow pattern recognition patch (executor and commands).
1613 5500 winstate->currentpos = currentPos; 24cfb8dRow pattern recognition patch (executor and commands).
1614 - 24cfb8dRow pattern recognition patch (executor and commands).
1615 - /* Invalidate nav_slot cache since match_start changed */ 24cfb8dRow pattern recognition patch (executor and commands).
1616 5500 winstate->nav_slot_pos = -1; 24cfb8dRow pattern recognition patch (executor and commands).
1617 - 24cfb8dRow pattern recognition patch (executor and commands).
1618 16356 foreach_ptr(ExprState, exprState, winstate->defineClauseExprs) b848408Tidy up row pattern recognition plumbing
1619 - { 24cfb8dRow pattern recognition patch (executor and commands).
1620 10856 int varIdx = foreach_current_index(exprState); 24cfb8dRow pattern recognition patch (executor and commands).
1621 - 24cfb8dRow pattern recognition patch (executor and commands).
1622 10856 if (bms_is_member(varIdx, winstate->defineMatchStartDependent)) 24cfb8dRow pattern recognition patch (executor and commands).
1623 - { 24cfb8dRow pattern recognition patch (executor and commands).
1624 5500 Datum result; 24cfb8dRow pattern recognition patch (executor and commands).
1625 5500 bool isnull; 24cfb8dRow pattern recognition patch (executor and commands).
1626 - 24cfb8dRow pattern recognition patch (executor and commands).
1627 5500 result = ExecEvalExpr(exprState, econtext, &isnull); 24cfb8dRow pattern recognition patch (executor and commands).
1628 6296 winstate->nfaVarMatched[varIdx] = (!isnull && DatumGetBool(result)); 24cfb8dRow pattern recognition patch (executor and commands).
1629 - } 24cfb8dRow pattern recognition patch (executor and commands).
1630 - } 24cfb8dRow pattern recognition patch (executor and commands).
1631 - 24cfb8dRow pattern recognition patch (executor and commands).
1632 - /* Restore original match_start, currentpos, and invalidate cache */ 24cfb8dRow pattern recognition patch (executor and commands).
1633 5500 winstate->nav_match_start = saved_match_start; 24cfb8dRow pattern recognition patch (executor and commands).
1634 5500 winstate->currentpos = saved_pos; 24cfb8dRow pattern recognition patch (executor and commands).
1635 5500 winstate->nav_slot_pos = -1; 24cfb8dRow pattern recognition patch (executor and commands).
1636 5500 } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRStartContext() lines 1652-1702
Modified Lines Coverage: 22/22 lines (100.0%)
LineHitsSourceCommit
1652 999176 ExecRPRStartContext(WindowAggState *winstate, int64 startPos) 24cfb8dRow pattern recognition patch (executor and commands).
1653 - { 24cfb8dRow pattern recognition patch (executor and commands).
1654 999176 RPRNFAContext *ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1655 999176 RPRPattern *pattern = winstate->rpPattern; 24cfb8dRow pattern recognition patch (executor and commands).
1656 999176 RPRPatternElement *elem; 24cfb8dRow pattern recognition patch (executor and commands).
1657 - 24cfb8dRow pattern recognition patch (executor and commands).
1658 999176 ctx = nfa_context_make(winstate); 24cfb8dRow pattern recognition patch (executor and commands).
1659 999176 ctx->matchStartRow = startPos; 24cfb8dRow pattern recognition patch (executor and commands).
1660 999176 ctx->states = nfa_state_make(winstate); /* initial state at elem 0 */ 24cfb8dRow pattern recognition patch (executor and commands).
1661 - 24cfb8dRow pattern recognition patch (executor and commands).
1662 999176 elem = &pattern->elements[0]; 24cfb8dRow pattern recognition patch (executor and commands).
1663 - 24cfb8dRow pattern recognition patch (executor and commands).
1664 999176 if (RPRElemIsAbsorbableBranch(elem)) 24cfb8dRow pattern recognition patch (executor and commands).
1665 - { 24cfb8dRow pattern recognition patch (executor and commands).
1666 903680 ctx->states->isAbsorbable = true; 24cfb8dRow pattern recognition patch (executor and commands).
1667 - } 24cfb8dRow pattern recognition patch (executor and commands).
1668 - else 24cfb8dRow pattern recognition patch (executor and commands).
1669 - { 24cfb8dRow pattern recognition patch (executor and commands).
1670 95496 ctx->hasAbsorbableState = false; 24cfb8dRow pattern recognition patch (executor and commands).
1671 95496 ctx->allStatesAbsorbable = false; 24cfb8dRow pattern recognition patch (executor and commands).
1672 95496 ctx->states->isAbsorbable = false; 24cfb8dRow pattern recognition patch (executor and commands).
1673 - } 24cfb8dRow pattern recognition patch (executor and commands).
1674 - 24cfb8dRow pattern recognition patch (executor and commands).
1675 - /* 0ed285dDrive RPR row pattern matching once per row
1676 - * Add to tail of active context list (doubly-linked, oldest-first). 0ed285dDrive RPR row pattern matching once per row
1677 - * matchStartRow is nondecreasing along the list, so the head holds the 0ed285dDrive RPR row pattern matching once per row
1678 - * smallest -- an ordering other code relies on. 0ed285dDrive RPR row pattern matching once per row
1679 - */ 0ed285dDrive RPR row pattern matching once per row
1680 999176 Assert(winstate->nfaContextTail == NULL || 0ed285dDrive RPR row pattern matching once per row
1681 - startPos >= winstate->nfaContextTail->matchStartRow); 0ed285dDrive RPR row pattern matching once per row
1682 999176 ctx->prev = winstate->nfaContextTail; 24cfb8dRow pattern recognition patch (executor and commands).
1683 999176 ctx->next = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1684 999176 if (winstate->nfaContextTail != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1685 988852 winstate->nfaContextTail->next = ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1686 - else 24cfb8dRow pattern recognition patch (executor and commands).
1687 10324 winstate->nfaContext = ctx; /* first context becomes head */ 24cfb8dRow pattern recognition patch (executor and commands).
1688 999176 winstate->nfaContextTail = ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1689 - 24cfb8dRow pattern recognition patch (executor and commands).
1690 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1691 - * Initial advance (divergence): expand ALT branches and create exit 24cfb8dRow pattern recognition patch (executor and commands).
1692 - * states for VAR elements with min=0. This prepares the context for the 24cfb8dRow pattern recognition patch (executor and commands).
1693 - * first row's match phase. 24cfb8dRow pattern recognition patch (executor and commands).
1694 - * 24cfb8dRow pattern recognition patch (executor and commands).
1695 - * Use startPos - 1 as currentPos since no row has been consumed yet. If 24cfb8dRow pattern recognition patch (executor and commands).
1696 - * FIN is reached via epsilon transitions, matchEndRow = startPos - 1 24cfb8dRow pattern recognition patch (executor and commands).
1697 - * which is less than matchStartRow, resulting in UNMATCHED treatment. 24cfb8dRow pattern recognition patch (executor and commands).
1698 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1699 999176 nfa_advance(winstate, ctx, startPos - 1); 24cfb8dRow pattern recognition patch (executor and commands).
1700 - 24cfb8dRow pattern recognition patch (executor and commands).
1701 999176 return ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1702 - } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRGetHeadContext() lines 1711-1723
Modified Lines Coverage: 4/4 lines (100.0%)
LineHitsSourceCommit
1711 106192 ExecRPRGetHeadContext(WindowAggState *winstate, int64 pos) 24cfb8dRow pattern recognition patch (executor and commands).
1712 - { 24cfb8dRow pattern recognition patch (executor and commands).
1713 106192 RPRNFAContext *ctx = winstate->nfaContext; 24cfb8dRow pattern recognition patch (executor and commands).
1714 - 24cfb8dRow pattern recognition patch (executor and commands).
1715 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1716 - * Contexts are sorted by matchStartRow ascending. If the head context 24cfb8dRow pattern recognition patch (executor and commands).
1717 - * doesn't match pos, no context exists for this position. 24cfb8dRow pattern recognition patch (executor and commands).
1718 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1719 106192 if (ctx == NULL || ctx->matchStartRow != pos) 24cfb8dRow pattern recognition patch (executor and commands).
1720 16368 return NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1721 - 24cfb8dRow pattern recognition patch (executor and commands).
1722 - return ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1723 - } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRFreeContext() lines 1732-1749
Modified Lines Coverage: 12/12 lines (100.0%)
LineHitsSourceCommit
1732 995300 ExecRPRFreeContext(WindowAggState *winstate, RPRNFAContext *ctx) 24cfb8dRow pattern recognition patch (executor and commands).
1733 - { 24cfb8dRow pattern recognition patch (executor and commands).
1734 - /* Unlink from active list first */ 24cfb8dRow pattern recognition patch (executor and commands).
1735 995300 nfa_unlink_context(winstate, ctx); 24cfb8dRow pattern recognition patch (executor and commands).
1736 - 24cfb8dRow pattern recognition patch (executor and commands).
1737 - /* Update statistics */ 24cfb8dRow pattern recognition patch (executor and commands).
1738 995300 winstate->nfaContextsActive--; 24cfb8dRow pattern recognition patch (executor and commands).
1739 - 24cfb8dRow pattern recognition patch (executor and commands).
1740 995300 if (ctx->states != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1741 390596 nfa_state_free_list(winstate, ctx->states); 24cfb8dRow pattern recognition patch (executor and commands).
1742 995300 if (ctx->matchedState != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1743 37944 nfa_state_free(winstate, ctx->matchedState); 24cfb8dRow pattern recognition patch (executor and commands).
1744 - 24cfb8dRow pattern recognition patch (executor and commands).
1745 995300 ctx->states = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1746 995300 ctx->matchedState = NULL; 24cfb8dRow pattern recognition patch (executor and commands).
1747 995300 ctx->next = winstate->nfaContextFree; 24cfb8dRow pattern recognition patch (executor and commands).
1748 995300 winstate->nfaContextFree = ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1749 995300 } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRRecordContextSuccess() lines 1757-1763
Modified Lines Coverage: 4/4 lines (100.0%)
LineHitsSourceCommit
1757 37160 ExecRPRRecordContextSuccess(WindowAggState *winstate, int64 matchLen) 24cfb8dRow pattern recognition patch (executor and commands).
1758 - { 24cfb8dRow pattern recognition patch (executor and commands).
1759 37160 winstate->nfaMatchesSucceeded++; 24cfb8dRow pattern recognition patch (executor and commands).
1760 37160 nfa_update_length_stats(winstate->nfaMatchesSucceeded, 24cfb8dRow pattern recognition patch (executor and commands).
1761 - &winstate->nfaMatchLen, 24cfb8dRow pattern recognition patch (executor and commands).
1762 - matchLen); 24cfb8dRow pattern recognition patch (executor and commands).
1763 37160 } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRRecordContextFailure() lines 1773-1786
Modified Lines Coverage: 6/6 lines (100.0%)
LineHitsSourceCommit
1773 258820 ExecRPRRecordContextFailure(WindowAggState *winstate, int64 failedLen) 24cfb8dRow pattern recognition patch (executor and commands).
1774 - { 24cfb8dRow pattern recognition patch (executor and commands).
1775 258820 if (failedLen == 1) 24cfb8dRow pattern recognition patch (executor and commands).
1776 - { 24cfb8dRow pattern recognition patch (executor and commands).
1777 227812 winstate->nfaContextsPruned++; 24cfb8dRow pattern recognition patch (executor and commands).
1778 - } 24cfb8dRow pattern recognition patch (executor and commands).
1779 - else 24cfb8dRow pattern recognition patch (executor and commands).
1780 - { 24cfb8dRow pattern recognition patch (executor and commands).
1781 31008 winstate->nfaMatchesFailed++; 24cfb8dRow pattern recognition patch (executor and commands).
1782 31008 nfa_update_length_stats(winstate->nfaMatchesFailed, 24cfb8dRow pattern recognition patch (executor and commands).
1783 - &winstate->nfaFailLen, 24cfb8dRow pattern recognition patch (executor and commands).
1784 - failedLen); 24cfb8dRow pattern recognition patch (executor and commands).
1785 - } 24cfb8dRow pattern recognition patch (executor and commands).
1786 258820 } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRProcessRow() lines 1797-1908
Modified Lines Coverage: 36/36 lines (100.0%)
LineHitsSourceCommit
1797 988852 ExecRPRProcessRow(WindowAggState *winstate, int64 currentPos, 24cfb8dRow pattern recognition patch (executor and commands).
1798 - bool hasLimitedFrame, int64 frameOffset) 24cfb8dRow pattern recognition patch (executor and commands).
1799 - { 24cfb8dRow pattern recognition patch (executor and commands).
1800 988852 RPRNFAContext *ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1801 988852 bool *varMatched = winstate->nfaVarMatched; 24cfb8dRow pattern recognition patch (executor and commands).
1802 988852 bool hasDependent = !bms_is_empty(winstate->defineMatchStartDependent); 24cfb8dRow pattern recognition patch (executor and commands).
1803 - 24cfb8dRow pattern recognition patch (executor and commands).
1804 - /* Allow query cancellation once per row for simple/low-state patterns */ 24cfb8dRow pattern recognition patch (executor and commands).
1805 988852 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
1806 - 24cfb8dRow pattern recognition patch (executor and commands).
1807 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1808 - * Phase 1: Match all contexts (convergence). Evaluate VAR elements, 24cfb8dRow pattern recognition patch (executor and commands).
1809 - * update counts, remove dead states. 24cfb8dRow pattern recognition patch (executor and commands).
1810 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1811 2929844 for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) 24cfb8dRow pattern recognition patch (executor and commands).
1812 - { 24cfb8dRow pattern recognition patch (executor and commands).
1813 1940992 if (ctx->states == NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1814 20 continue; 24cfb8dRow pattern recognition patch (executor and commands).
1815 - 24cfb8dRow pattern recognition patch (executor and commands).
1816 - /* Check frame boundary - finalize the context when it is reached */ 24cfb8dRow pattern recognition patch (executor and commands).
1817 1940972 if (hasLimitedFrame) 24cfb8dRow pattern recognition patch (executor and commands).
1818 - { 24cfb8dRow pattern recognition patch (executor and commands).
1819 1296 int64 ctxFrameEnd; 24cfb8dRow pattern recognition patch (executor and commands).
1820 - 24cfb8dRow pattern recognition patch (executor and commands).
1821 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1822 - * Clamp to PG_INT64_MAX on overflow. frameOffset can be as large 24cfb8dRow pattern recognition patch (executor and commands).
1823 - * as PG_INT64_MAX (e.g. "ROWS <huge> FOLLOWING"), so add the 24cfb8dRow pattern recognition patch (executor and commands).
1824 - * offset and the trailing +1 in two separately checked steps to 24cfb8dRow pattern recognition patch (executor and commands).
1825 - * avoid signed-integer overflow in the "frameOffset + 1" 24cfb8dRow pattern recognition patch (executor and commands).
1826 - * subexpression. 24cfb8dRow pattern recognition patch (executor and commands).
1827 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1828 1296 if (pg_add_s64_overflow(ctx->matchStartRow, frameOffset, 24cfb8dRow pattern recognition patch (executor and commands).
1829 1256 &ctxFrameEnd) || 24cfb8dRow pattern recognition patch (executor and commands).
1830 1256 pg_add_s64_overflow(ctxFrameEnd, 1, &ctxFrameEnd)) 24cfb8dRow pattern recognition patch (executor and commands).
1831 - ctxFrameEnd = PG_INT64_MAX; 24cfb8dRow pattern recognition patch (executor and commands).
1832 - 24cfb8dRow pattern recognition patch (executor and commands).
1833 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1834 - * currentPos advances by exactly one per call, and a finalized 24cfb8dRow pattern recognition patch (executor and commands).
1835 - * context is skipped by the states == NULL guard above, so it can 24cfb8dRow pattern recognition patch (executor and commands).
1836 - * only ever reach ctxFrameEnd, never overshoot it. The Assert 24cfb8dRow pattern recognition patch (executor and commands).
1837 - * turns a future change that broke that invariant into an 24cfb8dRow pattern recognition patch (executor and commands).
1838 - * immediate failure rather than a silent slip past the boundary. 24cfb8dRow pattern recognition patch (executor and commands).
1839 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1840 1236 Assert(currentPos <= ctxFrameEnd); 24cfb8dRow pattern recognition patch (executor and commands).
1841 - 24cfb8dRow pattern recognition patch (executor and commands).
1842 1296 if (currentPos == ctxFrameEnd) 24cfb8dRow pattern recognition patch (executor and commands).
1843 - { 24cfb8dRow pattern recognition patch (executor and commands).
1844 - /* Frame boundary reached: force mismatch */ 24cfb8dRow pattern recognition patch (executor and commands).
1845 44 nfa_match(winstate, ctx, NULL); 24cfb8dRow pattern recognition patch (executor and commands).
1846 44 continue; 24cfb8dRow pattern recognition patch (executor and commands).
1847 - } 24cfb8dRow pattern recognition patch (executor and commands).
1848 - } 24cfb8dRow pattern recognition patch (executor and commands).
1849 - 24cfb8dRow pattern recognition patch (executor and commands).
1850 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1851 - * If this context has a different matchStartRow than the one used in 24cfb8dRow pattern recognition patch (executor and commands).
1852 - * the shared evaluation, re-evaluate match_start-dependent variables 24cfb8dRow pattern recognition patch (executor and commands).
1853 - * with this context's matchStartRow. 24cfb8dRow pattern recognition patch (executor and commands).
1854 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1855 1940928 if (hasDependent && ctx->matchStartRow != winstate->nav_match_start) 24cfb8dRow pattern recognition patch (executor and commands).
1856 5500 nfa_reevaluate_dependent_vars(winstate, ctx, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1857 1940928 nfa_match(winstate, ctx, varMatched); 24cfb8dRow pattern recognition patch (executor and commands).
1858 1940928 ctx->lastProcessedRow = currentPos; 24cfb8dRow pattern recognition patch (executor and commands).
1859 - } 24cfb8dRow pattern recognition patch (executor and commands).
1860 - 24cfb8dRow pattern recognition patch (executor and commands).
1861 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1862 - * Phase 2: Absorb redundant contexts. After match phase, states have 24cfb8dRow pattern recognition patch (executor and commands).
1863 - * converged - ideal for absorption. First update absorption flags that 24cfb8dRow pattern recognition patch (executor and commands).
1864 - * may have changed due to state removal. 24cfb8dRow pattern recognition patch (executor and commands).
1865 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1866 988852 if (winstate->rpPattern->isAbsorbable) 24cfb8dRow pattern recognition patch (executor and commands).
1867 - { 24cfb8dRow pattern recognition patch (executor and commands).
1868 2656108 for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) 24cfb8dRow pattern recognition patch (executor and commands).
1869 1758388 nfa_update_absorption_flags(ctx); 24cfb8dRow pattern recognition patch (executor and commands).
1870 - 24cfb8dRow pattern recognition patch (executor and commands).
1871 897720 nfa_absorb_contexts(winstate); 24cfb8dRow pattern recognition patch (executor and commands).
1872 - } 24cfb8dRow pattern recognition patch (executor and commands).
1873 - 24cfb8dRow pattern recognition patch (executor and commands).
1874 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1875 - * Phase 3: Advance all contexts (divergence). Create new states 24cfb8dRow pattern recognition patch (executor and commands).
1876 - * (loop/exit) from surviving matched states. 24cfb8dRow pattern recognition patch (executor and commands).
1877 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1878 2236872 for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) 24cfb8dRow pattern recognition patch (executor and commands).
1879 - { 24cfb8dRow pattern recognition patch (executor and commands).
1880 1248020 if (ctx->states == NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1881 256116 continue; 24cfb8dRow pattern recognition patch (executor and commands).
1882 - 24cfb8dRow pattern recognition patch (executor and commands).
1883 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1884 - * Phase 1 already handled frame boundary exceeded contexts by forcing 24cfb8dRow pattern recognition patch (executor and commands).
1885 - * mismatch (nfa_match with NULL), which removes all states (all 24cfb8dRow pattern recognition patch (executor and commands).
1886 - * states are at VAR positions after advance). So any surviving 24cfb8dRow pattern recognition patch (executor and commands).
1887 - * context here must be within its frame boundary. 24cfb8dRow pattern recognition patch (executor and commands).
1888 - * 24cfb8dRow pattern recognition patch (executor and commands).
1889 - * Compute the (clamped) frame end the same way as Phase 1, using two 24cfb8dRow pattern recognition patch (executor and commands).
1890 - * separately checked adds so that "frameOffset + 1" cannot overflow 24cfb8dRow pattern recognition patch (executor and commands).
1891 - * when frameOffset is near PG_INT64_MAX. 24cfb8dRow pattern recognition patch (executor and commands).
1892 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1893 - #ifdef USE_ASSERT_CHECKING 24cfb8dRow pattern recognition patch (executor and commands).
1894 991904 if (hasLimitedFrame) 24cfb8dRow pattern recognition patch (executor and commands).
1895 - { 24cfb8dRow pattern recognition patch (executor and commands).
1896 1100 int64 ctxFrameEnd; 24cfb8dRow pattern recognition patch (executor and commands).
1897 - 24cfb8dRow pattern recognition patch (executor and commands).
1898 1100 if (pg_add_s64_overflow(ctx->matchStartRow, frameOffset, 24cfb8dRow pattern recognition patch (executor and commands).
1899 1060 &ctxFrameEnd) || 24cfb8dRow pattern recognition patch (executor and commands).
1900 1060 pg_add_s64_overflow(ctxFrameEnd, 1, &ctxFrameEnd)) 24cfb8dRow pattern recognition patch (executor and commands).
1901 - ctxFrameEnd = PG_INT64_MAX; 24cfb8dRow pattern recognition patch (executor and commands).
1902 1100 Assert(currentPos < ctxFrameEnd); 24cfb8dRow pattern recognition patch (executor and commands).
1903 - } 24cfb8dRow pattern recognition patch (executor and commands).
1904 - #endif 24cfb8dRow pattern recognition patch (executor and commands).
1905 - 24cfb8dRow pattern recognition patch (executor and commands).
1906 991904 nfa_advance(winstate, ctx, currentPos); 24cfb8dRow pattern recognition patch (executor and commands).
1907 - } 24cfb8dRow pattern recognition patch (executor and commands).
1908 988852 } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRCleanupDeadContexts() lines 1918-1951
Modified Lines Coverage: 15/15 lines (100.0%)
LineHitsSourceCommit
1918 995200 ExecRPRCleanupDeadContexts(WindowAggState *winstate, RPRNFAContext *excludeCtx) 24cfb8dRow pattern recognition patch (executor and commands).
1919 - { 24cfb8dRow pattern recognition patch (executor and commands).
1920 995200 RPRNFAContext *ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1921 995200 RPRNFAContext *next; 24cfb8dRow pattern recognition patch (executor and commands).
1922 - 24cfb8dRow pattern recognition patch (executor and commands).
1923 3246644 for (ctx = winstate->nfaContext; ctx != NULL; ctx = next) 24cfb8dRow pattern recognition patch (executor and commands).
1924 - { 24cfb8dRow pattern recognition patch (executor and commands).
1925 2251444 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
1926 - 24cfb8dRow pattern recognition patch (executor and commands).
1927 2251444 next = ctx->next; 24cfb8dRow pattern recognition patch (executor and commands).
1928 - 24cfb8dRow pattern recognition patch (executor and commands).
1929 - /* Skip the target context and contexts still processing */ 24cfb8dRow pattern recognition patch (executor and commands).
1930 2251444 if (ctx == excludeCtx || ctx->states != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1931 2048388 continue; 24cfb8dRow pattern recognition patch (executor and commands).
1932 - 24cfb8dRow pattern recognition patch (executor and commands).
1933 - /* Skip successfully matched contexts (will be handled by SKIP logic) */ 24cfb8dRow pattern recognition patch (executor and commands).
1934 203056 if (ctx->matchEndRow >= ctx->matchStartRow) 24cfb8dRow pattern recognition patch (executor and commands).
1935 812 continue; 24cfb8dRow pattern recognition patch (executor and commands).
1936 - 24cfb8dRow pattern recognition patch (executor and commands).
1937 - /* 24cfb8dRow pattern recognition patch (executor and commands).
1938 - * Failed context: always removed below. Only record the failure 24cfb8dRow pattern recognition patch (executor and commands).
1939 - * statistic if it actually processed its start row; contexts created 24cfb8dRow pattern recognition patch (executor and commands).
1940 - * for beyond-partition rows are removed without being counted. 24cfb8dRow pattern recognition patch (executor and commands).
1941 - */ 24cfb8dRow pattern recognition patch (executor and commands).
1942 202244 if (ctx->lastProcessedRow >= ctx->matchStartRow) 24cfb8dRow pattern recognition patch (executor and commands).
1943 - { 24cfb8dRow pattern recognition patch (executor and commands).
1944 195896 int64 failedLen = ctx->lastProcessedRow - ctx->matchStartRow + 1; 24cfb8dRow pattern recognition patch (executor and commands).
1945 - 24cfb8dRow pattern recognition patch (executor and commands).
1946 195896 ExecRPRRecordContextFailure(winstate, failedLen); 24cfb8dRow pattern recognition patch (executor and commands).
1947 - } 24cfb8dRow pattern recognition patch (executor and commands).
1948 - 24cfb8dRow pattern recognition patch (executor and commands).
1949 202244 ExecRPRFreeContext(winstate, ctx); 24cfb8dRow pattern recognition patch (executor and commands).
1950 - } 24cfb8dRow pattern recognition patch (executor and commands).
1951 995200 } 24cfb8dRow pattern recognition patch (executor and commands).
ExecRPRFinalizeAllContexts() lines 1980-1994
Modified Lines Coverage: 8/8 lines (100.0%)
LineHitsSourceCommit
1980 6348 ExecRPRFinalizeAllContexts(WindowAggState *winstate, int64 lastPos) 24cfb8dRow pattern recognition patch (executor and commands).
1981 - { 24cfb8dRow pattern recognition patch (executor and commands).
1982 6348 RPRNFAContext *ctx; 24cfb8dRow pattern recognition patch (executor and commands).
1983 - 24cfb8dRow pattern recognition patch (executor and commands).
1984 20920 for (ctx = winstate->nfaContext; ctx != NULL; ctx = ctx->next) 24cfb8dRow pattern recognition patch (executor and commands).
1985 - { 24cfb8dRow pattern recognition patch (executor and commands).
1986 14572 CHECK_FOR_INTERRUPTS(); 24cfb8dRow pattern recognition patch (executor and commands).
1987 - 24cfb8dRow pattern recognition patch (executor and commands).
1988 14572 if (ctx->states != NULL) 24cfb8dRow pattern recognition patch (executor and commands).
1989 - { 24cfb8dRow pattern recognition patch (executor and commands).
1990 14568 nfa_match(winstate, ctx, NULL); 24cfb8dRow pattern recognition patch (executor and commands).
1991 14568 nfa_advance(winstate, ctx, lastPos); 24cfb8dRow pattern recognition patch (executor and commands).
1992 - } 24cfb8dRow pattern recognition patch (executor and commands).
1993 - } 24cfb8dRow pattern recognition patch (executor and commands).
1994 6348 } 24cfb8dRow pattern recognition patch (executor and commands).