fix compound select

This commit is contained in:
Nikita Sivukhin
2025-09-29 16:21:35 +04:00
parent 49a5617a95
commit 12863b35c4
2 changed files with 12 additions and 2 deletions

View File

@@ -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(())
}

View File

@@ -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<Box<Expr>>,