1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/) Copyright 2025-Present Datadog, Inc.
//! Per-batch monomorphized direct scan loop and winner publication.
use super::ambiguous_lane::InlineLaneOutcome;
use super::{
BatchOutcome, BoolColKind, ClosedDirectDriver, ClosedSegmentOutcome, DirectPublish,
DirectSpan, DirectSymbolSource,
};
use crate::execution::matching::ResolvedAfterMatchSkip;
use crate::execution::matching::collection::selected_output::checked_match_number_successor;
use crate::execution::matching::collection::{
PatternMatcher, SkipDirect, absolute_row_from_usize, lane_scan,
};
use crate::execution::matching::row_loop::lane_scan::{
ClassifierDemand, CompactSelection, DirectLinearStep, LaneScanState, StaticProbe,
direct_payload::{DirectRow, evaluate_direct_payload},
};
use crate::execution::matching::row_loop::state::WorkGovernor;
use crate::execution::matching::row_loop::symbol_evaluator::LaneRow;
use crate::execution::storage::accumulator::{DirectPublicationBatch, MatchAccumulator};
use datafusion::arrow::array::{Array, AsArray, BooleanArray};
use datafusion::arrow::datatypes::UInt64Type;
use datafusion::common::Result;
use datafusion::execution::memory_pool::MemoryReservation;
use smallvec::SmallVec;
use std::sync::Arc;
#[inline]
pub(super) fn row_masks(
local: usize,
packed: Option<&[u64]>,
bool_cols: &[(&BooleanArray, u64, BoolColKind)],
eager_bitmap: u64,
) -> LaneRow {
if let Some(values) = packed {
LaneRow {
eligible: values[local],
or_passes: 0,
}
} else if bool_cols.is_empty() {
LaneRow {
eligible: eager_bitmap,
or_passes: 0,
}
} else {
let mut eligible = eager_bitmap;
let mut or_passes = 0u64;
for &(arr, bit, kind) in bool_cols {
match kind {
BoolColKind::StaticSymbol => {
if arr.is_valid(local) && arr.value(local) {
eligible |= bit;
}
}
BoolColKind::AndGuard => {
if arr.is_valid(local) && !arr.value(local) {
eligible &= !bit;
}
}
BoolColKind::OrGuard => {
if arr.is_valid(local) && arr.value(local) {
or_passes |= bit;
}
}
}
}
LaneRow {
eligible,
or_passes,
}
}
}
#[inline]
fn row_can_start(
local: usize,
packed: Option<&[u64]>,
bool_cols: &[(&BooleanArray, u64, BoolColKind)],
eager_bitmap: u64,
start_mask: u64,
) -> bool {
row_masks(local, packed, bool_cols, eager_bitmap).eligible & start_mask != 0
}
#[expect(clippy::too_many_arguments)]
fn publish_direct_winner(
matcher: &PatternMatcher,
accumulator: &mut MatchAccumulator,
publication: DirectPublicationBatch<'_>,
selected: &CompactSelection<'_>,
regs: &[u64],
match_number: u64,
governor: &mut WorkGovernor,
work: &mut usize,
) -> Result<DirectPublish> {
let successor = checked_match_number_successor(match_number)?;
if !accumulator.can_append_direct_winner() {
return Ok(DirectPublish::Handoff);
}
let after_match_skip = matcher.program.after_match_skip();
if !selected.can_skip_atomically(after_match_skip)? {
return Ok(DirectPublish::Handoff);
}
let (target, skip_work) = selected.skip_target_row(after_match_skip)?;
*work += skip_work;
let next_row = after_match_skip
.plan_selected_cursor(selected.start, selected.end, false, target)?
.row_idx;
let mut winning_registers = 0;
if !accumulator.try_publish_bound_winner(
match_number,
selected,
|_| Ok(publication),
|units| {
let total = std::mem::take(work) + units;
governor.record_completed(total, || matcher.is_aborted())
},
|id, ty| {
let value = matcher.bound_state_cells().get(id)?.winning_value(regs, ty);
winning_registers += usize::from(value.is_some());
value
},
)? {
return Ok(DirectPublish::Handoff);
}
Ok(DirectPublish::Published {
next_match_number: successor,
next_row,
winning_registers,
})
}
impl ClosedDirectDriver<'_> {
#[expect(clippy::too_many_arguments)]
pub(super) fn drive_span_batch_typed<
const NO_NULLS: bool,
const TRACK_HISTORY: bool,
>(
&mut self,
batch: usize,
batch_origin: usize,
batch_span_end: usize,
is_eof: bool,
span: DirectSpan,
row_idx: &mut usize,
match_number: &mut u64,
accumulator: &mut MatchAccumulator,
lane_scan: &mut Option<LaneScanState>,
lane_state_memory: &MemoryReservation,
governor: &mut WorkGovernor,
work: &mut usize,
) -> Result<BatchOutcome> {
let arrow = self.collection.batch(batch);
let bound = self.collection.bound_batch(batch);
let mut bool_cols = SmallVec::<[(&BooleanArray, u64, BoolColKind); 8]>::new();
let packed = match &self.symbol_source {
DirectSymbolSource::Packed(i) => Some(
arrow
.column(*i)
.as_primitive::<UInt64Type>()
.values()
.as_ref(),
),
DirectSymbolSource::Constant => None,
DirectSymbolSource::PhysicalBools(entries) => {
for &(col_idx, bit, kind) in entries {
bool_cols.push((arrow.column(col_idx).as_boolean(), bit, kind));
}
None
}
};
let bool_slice = bool_cols.as_slice();
let cached_symbols = self.cached_symbols;
let publication = accumulator.direct_publication_batch(
span.partition_start..span.read_end_row,
self.global_offset,
self.collection,
)?;
let matcher = self.matcher;
let variant = self.variant;
let program = self.program;
let start_state = self.start_state;
let start_mask = self.start_symbols_mask;
let min_tail_rows = self.min_tail_rows();
let eager_bitmap = self.eager_bitmap;
let quantum = self.quantum;
let yield_policy = self.yield_policy;
let start_anchored = program.requires_partition_start();
let can_skip_start = self.min_match_rows > 0
&& (packed.is_some()
|| (!bool_slice.is_empty()
&& (eager_bitmap & start_mask & !self.and_guarded_mask) == 0));
let suffix_reuse = program.suffix_reuse.filter(|_| {
matches!(self.classifier_demand, ClassifierDemand::Symbols(_))
&& !matches!(
matcher.program.after_match_skip(),
ResolvedAfterMatchSkip::PastLastRow
)
});
let can_retire = variant.can_retire_ordered_siblings || suffix_reuse.is_some();
let symbol_programs = variant.symbol_programs();
let mut start_limit = span.end_row.min(batch_span_end);
if let Some(words) = packed
&& self.cursor.suffix_run.is_none()
&& is_eof
&& self.min_match_rows > 0
&& self.required_packed_mask != 0
&& matcher.program.can_skip_candidate_evaluation()
{
let local_start = *row_idx - batch_origin;
let local_end = batch_span_end - batch_origin;
if local_end > local_start && local_end - local_start <= quantum {
let mut missing = self.required_packed_mask;
for i in (local_start..local_end).rev() {
missing &= !words[i];
*work += 1;
if missing == 0 {
start_limit = start_limit.min(batch_origin + i + 1);
break;
}
}
if missing != 0 {
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::Complete(
*row_idx,
)));
}
}
}
let mid_yield = |row: usize| {
if suffix_reuse.is_some()
|| (span.yield_mid_as_handoff && row == span.start_row)
{
BatchOutcome::Done(ClosedSegmentOutcome::handoff_at(row))
} else {
BatchOutcome::Done(ClosedSegmentOutcome::Yield(row))
}
};
while *row_idx < start_limit
&& (!start_anchored || *row_idx == span.partition_start)
{
if let Some(outcome) =
span.short_tail(*row_idx, self.min_match_rows, min_tail_rows)
{
return Ok(BatchOutcome::Done(outcome));
}
if can_skip_start && self.cursor.suffix_run.is_none() {
if start_anchored {
if !row_can_start(
*row_idx - batch_origin,
packed,
bool_slice,
eager_bitmap,
start_mask,
) {
*row_idx += 1;
*work += 1;
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::Complete(
*row_idx,
)));
}
} else {
while *row_idx < start_limit {
if let Some(outcome) =
span.short_tail(*row_idx, self.min_match_rows, min_tail_rows)
{
return Ok(BatchOutcome::Done(outcome));
}
if let Some(words) = packed {
let local = *row_idx - batch_origin;
let tail_limit = if !span.final_flush {
span.read_end_row
.saturating_sub(self.min_match_rows.saturating_sub(1))
} else {
span.read_end_row
.saturating_sub(min_tail_rows.saturating_sub(1))
};
let limit = start_limit
.min(tail_limit)
.min(*row_idx + quantum.saturating_sub(*work).max(1))
- batch_origin;
let skipped = words[local..limit]
.iter()
.take_while(|&&word| word & start_mask == 0)
.count();
*row_idx += skipped;
*work += skipped;
if *work >= quantum {
governor
.record_completed(std::mem::take(work), || {
matcher.is_aborted()
})?;
// A backwards proof can exhaust the budget without
// advancing the start. Evaluate that candidate before yielding.
if skipped > 0
&& (!is_eof || *row_idx < start_limit)
&& *row_idx < span.end_row
&& (!span.final_flush
|| span.read_end_row - *row_idx >= min_tail_rows)
&& governor.take_yield_if_due_hot(yield_policy)
{
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::Yield(*row_idx),
));
}
}
if *row_idx - batch_origin == limit {
continue;
}
break;
}
if row_can_start(
*row_idx - batch_origin,
packed,
bool_slice,
eager_bitmap,
start_mask,
) {
break;
}
*row_idx += 1;
*work += 1;
if *work >= quantum {
governor.record_completed(std::mem::take(work), || {
matcher.is_aborted()
})?;
if *row_idx < span.end_row
&& (!span.final_flush
|| span.read_end_row - *row_idx >= min_tail_rows)
&& governor.take_yield_if_due_hot(yield_policy)
{
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::Yield(*row_idx),
));
}
}
}
if *row_idx >= start_limit {
break;
}
}
}
// Admission puts every consuming choice before root acceptance.
// If no static transition can start here, the empty winner is exact.
if self.min_match_rows == 0
&& program.payload_symbols == 0
&& !row_can_start(
*row_idx - batch_origin,
packed,
bool_slice,
eager_bitmap,
start_mask,
)
{
let position = absolute_row_from_usize(*row_idx, "direct empty winner")?;
let successor = checked_match_number_successor(*match_number)?;
let next = matcher
.program
.after_match_skip()
.plan_selected_cursor(position, position, true, None)?
.row_idx;
if !accumulator.try_publish_empty_in_batch(
*match_number,
*row_idx,
span.partition_start..span.read_end_row,
&mut |units| {
governor.record_completed(units, || matcher.is_aborted())
},
)? {
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::handoff_at(
*row_idx,
)));
}
*match_number = successor;
*row_idx = next;
self.routes.record_continuous(true, false, bound.is_some());
*work += 1;
if *work >= quantum {
governor.record_completed(std::mem::take(work), || {
matcher.is_aborted()
})?;
if *row_idx < span.end_row
&& governor.take_yield_if_due_hot(yield_policy)
{
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::Yield(
*row_idx,
)));
}
}
continue;
}
if let Some(reuse) = suffix_reuse
&& self.cursor.suffix_run.is_some_and(|(peel, end, _)| {
peel >= batch_origin && *row_idx < end && end <= batch_span_end
})
{
if let Some(outcome) =
self.drive_suffix_reuse_run(*row_idx, governor, work, |row| {
program.suffix_symbol(
reuse,
row_masks(
row - batch_origin,
packed,
bool_slice,
eager_bitmap,
)
.eligible,
)
})?
{
return Ok(BatchOutcome::Done(outcome));
}
} else {
self.cursor
.reset::<TRACK_HISTORY>(program, start_state, *row_idx);
}
let cand_start = *row_idx;
let candidate = cand_start - batch_origin;
let candidate_row = bound.and_then(|b| b.row(candidate));
loop {
let row = self.cursor.next_row();
let mut eval_handoff = false;
let step = if self.cursor.suffix_run.is_some() {
DirectLinearStep::Finished
} else if row >= batch_span_end {
if !is_eof {
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::handoff_at(
cand_start,
)));
}
DirectLinearStep::Finished
} else {
if *work != 0
&& work.saturating_add(self.cursor.step_work_bound(program))
> quantum
{
governor.record_completed(std::mem::take(work), || {
matcher.is_aborted()
})?;
if governor.take_yield_if_due_hot(yield_policy) {
return Ok(mid_yield(cand_start));
}
}
let local = row - batch_origin;
let static_step = if let Some(words) = packed
&& self.cursor.can_step_static_packed(program, cached_symbols)
{
let limit = (batch_span_end - row)
.min(quantum.saturating_sub(*work).max(1));
self.cursor.step_static_packed::<TRACK_HISTORY>(
program,
&words[local..local + limit],
cached_symbols,
can_retire,
quantum.saturating_sub(*work).max(1),
work,
|sym, row, nav| {
let user = symbol_programs[usize::from(sym)]
.user()
.expect("admitted static symbol");
evaluate_direct_payload::<NO_NULLS>(
program,
user,
DirectRow {
current: bound
.and_then(|b| b.row(row - batch_origin)),
candidate_start: candidate_row,
sequence: (row - cand_start + 1) as i64,
match_number: *match_number,
},
false,
&mut [],
nav,
)
.map(|result| result.map(|_| ()))
},
)?
} else {
None
};
if let Some(step) = static_step {
step
} else {
let masks = row_masks(local, packed, bool_slice, eager_bitmap);
let operands = DirectRow {
current: bound.and_then(|b| b.row(local)),
candidate_start: candidate_row,
sequence: (row - cand_start + 1) as i64,
match_number: *match_number,
};
self.cursor.step::<TRACK_HISTORY>(
program,
masks.eligible,
can_retire,
&mut self.scratch,
work,
|edge, regs, nav| {
if let Some(accepted) =
matcher.program.classification.as_ref().and_then(
|c| c.cached_demand(arrow, local, edge.symbol_id),
)
{
return Ok(Some(accepted));
}
let user = symbol_programs[edge.symbol_id.index()]
.user()
.expect("admitted consuming edge has a user program");
let or_pass = masks.or_passes
& (1u64 << edge.symbol_id.index())
!= 0;
let res = evaluate_direct_payload::<NO_NULLS>(
program, user, operands, or_pass, regs, nav,
);
if !matches!(res, Ok(Some(_))) {
eval_handoff = true;
}
res
},
)?
}
};
match step {
DirectLinearStep::Handoff if eval_handoff => {
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::handoff_at(
cand_start,
)));
}
DirectLinearStep::Ambiguous | DirectLinearStep::Handoff => {
if step == DirectLinearStep::Ambiguous
&& program.payload_symbols == 0
&& variant.automaton().nfa().state_count() <= 64
&& self.min_match_rows > 0
&& self.cursor.has_no_winner()
{
let probe = self.cursor.probe_static_bitset_reject(
program,
batch_span_end,
|r| {
row_masks(
r - batch_origin,
packed,
bool_slice,
eager_bitmap,
)
.eligible
},
work,
|work, cost| {
if *work != 0 && work.saturating_add(cost) > quantum {
governor.record_completed(
std::mem::take(work),
|| matcher.is_aborted(),
)?;
return Ok(
governor.take_yield_if_due_hot(yield_policy)
);
}
Ok(false)
},
)?;
match probe {
StaticProbe::Yield => return Ok(mid_yield(cand_start)),
StaticProbe::Boundary(_) if !is_eof => {
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::handoff_at(cand_start),
));
}
StaticProbe::NoMatch(r) | StaticProbe::Boundary(r) => {
if matcher.program.can_skip_candidate_evaluation()
&& lane_scan::start_search::graph_work_threshold(
program,
)
.is_some_and(|threshold| {
r - cand_start >= threshold
})
{
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::Handoff {
row_idx: cand_start,
skip_direct: SkipDirect::StaticFailure(
cand_start,
),
},
));
}
*row_idx = cand_start + 1;
self.routes
.record_inline_lane(false, bound.is_some());
break;
}
StaticProbe::FoundWinner | StaticProbe::NeedLane => {}
}
}
if lane_scan
.as_ref()
.is_some_and(|state| !state.is_for(program))
{
*lane_scan = None;
}
if lane_scan.is_none() {
*lane_scan = Some(LaneScanState::try_new(
Arc::clone(program),
lane_state_memory,
)?);
}
let lane = lane_scan.as_mut().expect("initialized lane state");
let inline_res = self
.run_ambiguous_lane::<NO_NULLS, TRACK_HISTORY>(
lane,
arrow,
cand_start,
batch_span_end,
is_eof,
batch_origin,
bound,
candidate_row,
packed,
bool_slice,
*match_number,
governor,
work,
);
let resolved = match inline_res {
Ok(InlineLaneOutcome::Resolved) => {
let publish_res =
if let Some(incumbent) = lane.incumbent() {
(|| -> Result<DirectPublish> {
let selected = if TRACK_HISTORY {
lane.selected_runs()?
} else {
CompactSelection::from_extent(
incumbent.best_match.match_start_row,
incumbent.end_row,
incumbent.best_match.row,
)?
};
let regs = lane
.incumbent_view()
.expect("incumbent view exists")
.registers;
publish_direct_winner(
matcher,
accumulator,
publication,
&selected,
regs,
*match_number,
governor,
work,
)
})()
.map(Some)
} else if self.min_match_rows == 0 {
Ok(Some(DirectPublish::Handoff))
} else {
*row_idx = cand_start + 1;
Ok(None)
};
lane.discard_candidate();
match publish_res? {
Some(DirectPublish::Published {
next_match_number,
next_row,
winning_registers,
}) => {
*match_number = next_match_number;
*row_idx = next_row;
self.routes
.record_winning_registers(winning_registers);
true
}
None => false,
Some(DirectPublish::Handoff) => {
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::handoff_at(cand_start),
));
}
}
}
Ok(InlineLaneOutcome::Yield) => {
lane.discard_candidate();
return Ok(mid_yield(cand_start));
}
Ok(InlineLaneOutcome::Handoff) => {
lane.discard_candidate();
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::handoff_at(cand_start),
));
}
Err(err) => {
lane.discard_candidate();
return Err(err);
}
};
self.routes.record_inline_lane(resolved, bound.is_some());
break;
}
DirectLinearStep::Advanced => {
if *work >= quantum {
governor.record_completed(std::mem::take(work), || {
matcher.is_aborted()
})?;
if governor.take_yield_if_due_hot(yield_policy) {
return Ok(mid_yield(cand_start));
}
}
}
DirectLinearStep::Finished => {
if self.min_match_rows == 0 && self.cursor.has_no_winner() {
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::handoff_at(cand_start),
));
}
// Share expensive static failures in the retained candidate
// driver, whose search survives work-budget suspension.
if program.payload_symbols == 0
&& matcher.program.can_skip_candidate_evaluation()
&& self.cursor.has_no_winner()
&& lane_scan::start_search::graph_work_threshold(program)
.is_some_and(|threshold| {
self.cursor.next_row() - cand_start >= threshold
})
{
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::Handoff {
row_idx: cand_start,
skip_direct: SkipDirect::StaticFailure(cand_start),
},
));
}
if suffix_reuse.is_some() {
self.cursor.retain_suffix();
}
// Direct publication leaves the last output slot to the
// flush transaction. Preserve the closed suffix across it.
if self.cursor.suffix_run.is_some()
&& !accumulator.can_append_direct_winner()
&& !accumulator.is_empty()
{
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::Flush(
cand_start,
)));
}
let advanced = self.cursor.next_row() > cand_start;
let winner = self.cursor.winner::<TRACK_HISTORY>(program)?;
let matched = winner.is_some();
if let Some((selected, regs)) = winner {
match publish_direct_winner(
matcher,
accumulator,
publication,
&selected,
regs,
*match_number,
governor,
work,
)? {
DirectPublish::Published {
next_match_number,
next_row,
winning_registers,
} => {
*match_number = next_match_number;
*row_idx = next_row;
if self
.cursor
.suffix_run
.is_some_and(|(_, end, _)| *row_idx >= end)
{
self.cursor.suffix_run = None;
}
self.routes
.record_winning_registers(winning_registers);
}
DirectPublish::Handoff => {
return Ok(BatchOutcome::Done(
ClosedSegmentOutcome::handoff_at(cand_start),
));
}
}
} else {
*row_idx = cand_start + 1;
}
self.routes
.record_continuous(matched, advanced, bound.is_some());
break;
}
}
}
if *work >= quantum {
governor
.record_completed(std::mem::take(work), || matcher.is_aborted())?;
}
if *work == 0
&& *row_idx < span.end_row
&& (!is_eof || *row_idx < start_limit)
&& (!start_anchored || *row_idx == span.partition_start)
&& (!span.final_flush || span.read_end_row - *row_idx >= min_tail_rows)
&& governor.take_yield_if_due_hot(yield_policy)
{
return Ok(BatchOutcome::Done(ClosedSegmentOutcome::Yield(*row_idx)));
}
}
Ok(if is_eof {
BatchOutcome::Done(ClosedSegmentOutcome::Complete(*row_idx))
} else {
BatchOutcome::NextBatch
})
}
}