diff --git a/core/translate/emitter.rs b/core/translate/emitter.rs index 939a287f0..1f13c6e15 100644 --- a/core/translate/emitter.rs +++ b/core/translate/emitter.rs @@ -68,6 +68,10 @@ pub struct TranslateCtx<'a> { pub reg_result_cols_start: Option, // The register holding the limit value, if any. pub reg_limit: Option, + // The register holding the offset value, if any. + pub reg_offset: Option, + // The register holding the limit+offset value, if any. + pub reg_limit_offset_sum: Option, // metadata for the group by operator pub meta_group_by: Option, // metadata for the order by operator @@ -111,6 +115,8 @@ fn prologue<'a>( label_main_loop_end: None, reg_agg_start: None, reg_limit: None, + reg_offset: None, + reg_limit_offset_sum: None, reg_result_cols_start: None, meta_group_by: None, meta_left_joins: HashMap::new(), @@ -200,6 +206,14 @@ pub fn emit_query<'a>( t_ctx.reg_limit = plan.limit.map(|_| program.alloc_register()); } + if t_ctx.reg_offset.is_none() { + t_ctx.reg_offset = plan.offset.map(|_| program.alloc_register()); + } + + if t_ctx.reg_limit_offset_sum.is_none() { + t_ctx.reg_limit_offset_sum = plan.offset.map(|_| program.alloc_register()); + } + // 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 diff --git a/core/translate/subquery.rs b/core/translate/subquery.rs index fd0e6667b..c805f3ca5 100644 --- a/core/translate/subquery.rs +++ b/core/translate/subquery.rs @@ -97,6 +97,8 @@ pub fn emit_subquery<'a>( result_column_indexes_in_orderby_sorter: HashMap::new(), result_columns_to_skip_in_orderby_sorter: None, reg_limit: plan.limit.map(|_| program.alloc_register()), + reg_offset: plan.offset.map(|_| program.alloc_register()), + reg_limit_offset_sum: plan.offset.map(|_| program.alloc_register()), resolver: Resolver::new(t_ctx.resolver.symbol_table), }; let subquery_body_end_label = program.allocate_label();