fix limit for compount select

This commit is contained in:
Nikita Sivukhin
2025-09-29 15:51:39 +04:00
parent 4d8ef6c63f
commit 49a5617a95

View File

@@ -248,19 +248,20 @@ pub fn emit_query<'a>(
plan: &'a mut SelectPlan,
t_ctx: &mut TranslateCtx<'a>,
) -> Result<usize> {
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