diff --git a/core/translate/compound_select.rs b/core/translate/compound_select.rs index eaa312b6a..82a9fca8f 100644 --- a/core/translate/compound_select.rs +++ b/core/translate/compound_select.rs @@ -1,5 +1,5 @@ use crate::schema::{Index, IndexColumn, Schema}; -use crate::translate::emitter::{emit_query, LimitCtx, Resolver, TranslateCtx}; +use crate::translate::emitter::{emit_query, init_limit, LimitCtx, Resolver, TranslateCtx}; use crate::translate::expr::translate_expr; use crate::translate::plan::{Plan, QueryDestination, SelectPlan}; use crate::translate::result_row::try_fold_expr_to_i64; @@ -133,6 +133,14 @@ fn emit_compound_select( unreachable!() }; + let compound_select_end = program.allocate_label(); + if let Some(limit_ctx) = &limit_ctx { + program.emit_insn(Insn::IfNot { + reg: limit_ctx.reg_limit, + target_pc: compound_select_end, + jump_if_null: false, + }); + } let mut right_most_ctx = TranslateCtx::new( program, schema, @@ -359,6 +367,8 @@ fn emit_compound_select( } } + program.preassign_label_to_next_insn(compound_select_end); + Ok(()) } diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index 4b6163784..6222c9222 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -1726,7 +1726,7 @@ pub fn emit_cdc_insns( /// Initialize the limit/offset counters and registers. /// In case of compound SELECTs, the limit counter is initialized only once, /// hence [LimitCtx::initialize_counter] being false in those cases. -fn init_limit( +pub fn init_limit( program: &mut ProgramBuilder, t_ctx: &mut TranslateCtx, limit: &Option>,