Extract loop emitting conditions into a method

No functional changes — this is just preparation for reusing this code
and avoiding polluting future commits with trivial refactoring.
This commit is contained in:
Piotr Rzysko
2025-08-08 06:21:08 +02:00
parent 8986266394
commit 92ba25e44d

View File

@@ -628,25 +628,15 @@ pub fn open_loop(
}
}
for cond in predicates
.iter()
.filter(|cond| cond.should_eval_at_loop(join_index, join_order))
{
let jump_target_when_true = program.allocate_label();
let condition_metadata = ConditionMetadata {
jump_if_condition_is_true: false,
jump_target_when_true,
jump_target_when_false: next,
};
translate_condition_expr(
program,
table_references,
&cond.expr,
condition_metadata,
&t_ctx.resolver,
)?;
program.preassign_label_to_next_insn(jump_target_when_true);
}
emit_conditions(
program,
&t_ctx,
table_references,
join_order,
predicates,
join_index,
next,
)?;
// Set the match flag to true if this is a LEFT JOIN.
// At this point of execution we are going to emit columns for the left table,
@@ -667,6 +657,38 @@ pub fn open_loop(
Ok(())
}
fn emit_conditions(
program: &mut ProgramBuilder,
t_ctx: &&mut TranslateCtx,
table_references: &TableReferences,
join_order: &[JoinOrderMember],
predicates: &[WhereTerm],
join_index: usize,
next: BranchOffset,
) -> Result<()> {
for cond in predicates
.iter()
.filter(|cond| cond.should_eval_at_loop(join_index, join_order))
{
let jump_target_when_true = program.allocate_label();
let condition_metadata = ConditionMetadata {
jump_if_condition_is_true: false,
jump_target_when_true,
jump_target_when_false: next,
};
translate_condition_expr(
program,
table_references,
&cond.expr,
condition_metadata,
&t_ctx.resolver,
)?;
program.preassign_label_to_next_insn(jump_target_when_true);
}
Ok(())
}
/// SQLite (and so Limbo) processes joins as a nested loop.
/// The loop may emit rows to various destinations depending on the query:
/// - a GROUP BY sorter (grouping is done by sorting based on the GROUP BY keys and aggregating while the GROUP BY keys match)