diff --git a/core/storage/btree.rs b/core/storage/btree.rs index 763b9340b..febb08ade 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -576,6 +576,7 @@ impl BTreeCursor { } else { cell_idx }; + let cell = contents.cell_get( cell_idx, payload_overflow_threshold_max(contents.page_type(), self.usable_space() as u16), @@ -589,6 +590,7 @@ impl BTreeCursor { _rowid, }) => { let mem_page = self.read_page(_left_child_page as usize)?; + self.stack.retreat(); self.stack.push_backwards(mem_page); continue; } diff --git a/testing/orderby.test b/testing/orderby.test index b5b56cdd4..d930bb388 100755 --- a/testing/orderby.test +++ b/testing/orderby.test @@ -199,4 +199,15 @@ do_execsql_test orderby_desc_with_filter_id_le { 6665 6664 6663 -6662} \ No newline at end of file +6662} + +# regression test where backwards iteration used to hang indefinitely +do_execsql_test orderby_desc_regression { + select count(1) from (select * from users where id < 100 order by id desc) +} {99} + +do_execsql_test orderby_desc_regression_verify_order { + select id from users where id < 100 order by id desc limit 3; +} {99 +98 +97} \ No newline at end of file diff --git a/tests/integration/fuzz/mod.rs b/tests/integration/fuzz/mod.rs index a981ce4a1..f7c3860d7 100644 --- a/tests/integration/fuzz/mod.rs +++ b/tests/integration/fuzz/mod.rs @@ -51,7 +51,7 @@ mod tests { let insert = format!( "INSERT INTO t VALUES {}", - (1..10000) + (1..2000) .map(|x| format!("({})", x)) .collect::>() .join(", ") @@ -71,9 +71,9 @@ mod tests { for comp in COMPARISONS.iter() { for order_by in ORDER_BY.iter() { - for max in 0..=10000 { + for max in 0..=2000 { let query = format!( - "SELECT * FROM t WHERE x {} {} {} LIMIT 3", + "SELECT * FROM t WHERE x {} {} {}", comp, max, order_by.unwrap_or("")