From 47c8fd1964d59d1bb79b5241a3735ded831d78e0 Mon Sep 17 00:00:00 2001 From: Arpit Saxena Date: Wed, 2 Oct 2024 11:58:42 +0530 Subject: [PATCH] Fix NextAwait's next instruction; rename rewind_labels Closes #351 NextAwait's next instruction was pointing to RewindAwait earlier which is not current. The instruction now points to the instruction after RewindAwait, which will be the loop body. Hence, rename rewind_labels to scan_loop_body_labels to make it clearer --- core/translate/emitter.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index 770cbe484..e0d22a986 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -124,7 +124,7 @@ pub struct Metadata { // in a join with a scan and a seek, the seek will jump to the scan's Next instruction when the join condition is false. next_row_labels: HashMap, // labels for the Rewind instructions. - rewind_labels: Vec, + scan_loop_body_labels: Vec, // mapping between Aggregation operator id and the register that holds the start of the aggregation result aggregation_start_registers: HashMap, // mapping between Aggregation operator id and associated metadata (if the aggregation has a group by clause) @@ -196,10 +196,8 @@ impl Emitter for Operator { SCAN_REWIND_AND_CONDITIONS => { let cursor_id = program.resolve_cursor_id(table_identifier, None); program.emit_insn(Insn::RewindAsync { cursor_id }); - let rewind_label = program.allocate_label(); + let scan_loop_body_label = program.allocate_label(); let halt_label = m.termination_label_stack.last().unwrap(); - m.rewind_labels.push(rewind_label); - program.defer_label_resolution(rewind_label, program.offset() as usize); program.emit_insn_with_label_dependency( Insn::RewindAwait { cursor_id, @@ -207,6 +205,11 @@ impl Emitter for Operator { }, *halt_label, ); + m.scan_loop_body_labels.push(scan_loop_body_label); + program.defer_label_resolution( + scan_loop_body_label, + program.offset() as usize, + ); let jump_label = m.next_row_labels.get(id).unwrap_or(halt_label); if let Some(preds) = predicates { @@ -235,7 +238,7 @@ impl Emitter for Operator { program .resolve_label(*m.next_row_labels.get(id).unwrap(), program.offset()); program.emit_insn(Insn::NextAsync { cursor_id }); - let jump_label = m.rewind_labels.pop().unwrap(); + let jump_label = m.scan_loop_body_labels.pop().unwrap(); program.emit_insn_with_label_dependency( Insn::NextAwait { cursor_id, @@ -1439,7 +1442,7 @@ fn prologue( group_bys: HashMap::new(), left_joins: HashMap::new(), next_row_labels: HashMap::new(), - rewind_labels: vec![], + scan_loop_body_labels: vec![], sorts: HashMap::new(), };