Handle limit zero case in query plan emitter

This commit is contained in:
PThorpe92
2025-03-26 15:33:05 -04:00
parent e0c414f9dd
commit a1ac0ca175

View File

@@ -180,12 +180,13 @@ fn emit_program_for_select(
if let Some(limit) = plan.limit {
if limit == 0 {
epilogue(program, init_label, start_offset)?;
program.result_columns = plan.result_columns;
program.table_references = plan.table_references;
return Ok(());
}
}
// Emit main parts of query
emit_query(program, &mut plan, &mut t_ctx)?;
// Finalize program
epilogue(program, init_label, start_offset)?;
program.result_columns = plan.result_columns;
@@ -302,6 +303,14 @@ fn emit_program_for_delete(
plan.result_columns.len(),
)?;
// exit early if LIMIT 0
if let Some(0) = plan.limit {
epilogue(program, init_label, start_offset)?;
program.result_columns = plan.result_columns;
program.table_references = plan.table_references;
return Ok(());
}
// No rows will be read from source table loops if there is a constant false condition eg. WHERE 0
let after_main_loop_label = program.allocate_label();
t_ctx.label_main_loop_end = Some(after_main_loop_label);