From a1ac0ca17539995946f5bd3b6dfb454cd3143def Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Wed, 26 Mar 2025 15:33:05 -0400 Subject: [PATCH] Handle limit zero case in query plan emitter --- core/translate/emitter.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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);