diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index 1fe085c94..a47b1e46b 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -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);