From 49a5617a951694e060a09630edca1d3f66a9ca7e Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Mon, 29 Sep 2025 15:51:39 +0400 Subject: [PATCH] fix limit for compount select --- core/translate/emitter.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index 4758b9a1c..4b6163784 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -248,19 +248,20 @@ pub fn emit_query<'a>( plan: &'a mut SelectPlan, t_ctx: &mut TranslateCtx<'a>, ) -> Result { + let after_main_loop_label = program.allocate_label(); + t_ctx.label_main_loop_end = Some(after_main_loop_label); + + init_limit(program, t_ctx, &plan.limit, &plan.offset); + if !plan.values.is_empty() { let reg_result_cols_start = emit_values(program, plan, t_ctx)?; + program.preassign_label_to_next_insn(after_main_loop_label); return Ok(reg_result_cols_start); } // Emit subqueries first so the results can be read in the main query loop. emit_subqueries(program, t_ctx, &mut plan.table_references)?; - let after_main_loop_label = program.allocate_label(); - t_ctx.label_main_loop_end = Some(after_main_loop_label); - - init_limit(program, t_ctx, &plan.limit, &plan.offset); - // No rows will be read from source table loops if there is a constant false condition eg. WHERE 0 // however an aggregation might still happen, // e.g. SELECT COUNT(*) WHERE 0 returns a row with 0, not an empty result set