From bf1afb56cf2ab0d4a503dbeeca06c12b50511cc0 Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Wed, 19 Nov 2025 16:56:32 +0100 Subject: [PATCH] core/mvcc: test with delete after checkpoint --- core/mvcc/database/tests.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/mvcc/database/tests.rs b/core/mvcc/database/tests.rs index 6f24c5bf6..5cdce0acc 100644 --- a/core/mvcc/database/tests.rs +++ b/core/mvcc/database/tests.rs @@ -1658,3 +1658,34 @@ fn test_cursor_with_btree_and_mvcc_with_backward_cursor() { assert_eq!(rows[1], vec![Value::Integer(2)]); assert_eq!(rows[2], vec![Value::Integer(1)]); } + +#[test] +#[ignore = "we need to implement seek with btree cursor"] +fn test_cursor_with_btree_and_mvcc_with_backward_cursor_with_delete() { + let mut db = MvccTestDbNoConn::new_with_random_db(); + // First write some rows and checkpoint so data is flushed to BTree file (.db) + { + let conn = db.connect(); + conn.execute("CREATE TABLE t(x integer primary key)") + .unwrap(); + conn.execute("INSERT INTO t VALUES (1)").unwrap(); + conn.execute("INSERT INTO t VALUES (2)").unwrap(); + conn.execute("INSERT INTO t VALUES (4)").unwrap(); + conn.execute("INSERT INTO t VALUES (5)").unwrap(); + conn.execute("PRAGMA wal_checkpoint(TRUNCATE)").unwrap(); + } + // Now restart so new connection will have to read data from BTree instead of MVCC. + db.restart(); + let conn = db.connect(); + // Insert a new row so that we have a gap in the BTree. + conn.execute("INSERT INTO t VALUES (3)").unwrap(); + conn.execute("DELETE FROM t WHERE x = 2").unwrap(); + println!("getting rows"); + let rows = get_rows(&conn, "SELECT * FROM t order by x desc"); + dbg!(&rows); + assert_eq!(rows.len(), 4); + assert_eq!(rows[0], vec![Value::Integer(5)]); + assert_eq!(rows[1], vec![Value::Integer(4)]); + assert_eq!(rows[2], vec![Value::Integer(3)]); + assert_eq!(rows[2], vec![Value::Integer(1)]); +}