Commit Graph

585 Commits

Author SHA1 Message Date
Pere Diaz Bou
4d80b8237d write page1 on database initialization
Page 1 must be initialized and written as soon as possible without
marking page as dirty.
2025-06-26 14:44:23 +02:00
Pekka Enberg
2fc5c0ce5c Switch to runtime flag for enabling indexes
Makes it easier to test the feature:

```
$ cargo run --  --experimental-indexes
Limbo v0.0.22
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database
limbo> CREATE TABLE t(x);
limbo> CREATE INDEX t_idx ON t(x);
limbo> DROP INDEX t_idx;
```
2025-06-26 10:07:28 +03:00
Pekka Enberg
a48198ec60 Merge 'Rollback simple support' from Pere Diaz Bou
Support for simple interactive rollback like:
```sql
    create table t (x);
    insert into t values (1);
    begin;
    insert into t values (2);
    rollback;
    select * from t;
```
This PR also fixes some other issues I found while debugging:
* Checkpoint would never `clear_dirty` on pages in page cache.
* Auto commit for interactive transactions was not respected so any
`insert` after `begin` would flush frames regardless of `auto_commit`
state.
* `max_frame` on wal shared state was being updated after every
`append_frame` which was incorrect, as another transaction would be able
to use that new `max_frame` even tho the transaction could've rolled
back. Instead we update the private copy of `max_frame` and only update
it at the end.
Follow up for later are savepoints which require implementing a
subjournal to track savepoints and their modified pages.

Closes #1825
2025-06-25 20:02:09 +03:00
Pere Diaz Bou
0119b0f99d clippy 2025-06-25 14:01:53 +02:00
Pere Diaz Bou
22f9cd695d commit_txn track rollback case 2025-06-25 14:00:57 +02:00
Jussi Saurio
27b3ecf599 core/db&pager: fix locking for initializing empty database
When `struct Database` is constructed, store `is_empty` as an
`Arc<AtomicBool>` - the value is true if:

1. DB size is zero
2. WAL has no frames

When `struct Pager` is constructed, this `Arc` is simply cloned.
When any connection runs a transaction it will first check `is_empty`,
and if the DB is empty, it will lock `init_lock` and then check `is_empty`
again, and if it's still true, it allocates page1 and stores `false` in
the `is_empty` `AtomicBool` and drops the lock.

---

Note that Limbo can currently have a zero DB and a WAL with frames,
as we have no special logic for folding page1 to the main DB file
during initialization.

Page 1 allocation currently happens on the first transaction (read or
write, due to having to support `select * from sqlite_schema` on an
empty DB; we should really check how SQLite actually does this.).
2025-06-25 14:45:21 +03:00
Jussi Saurio
133d498724 Implement a header_accessor module so that DatabaseHeader structs arent initialized on every access 2025-06-24 14:41:50 -03:00
Jussi Saurio
acafe71d9e Dont allocate fresh page1 if it's in the WAL 2025-06-24 14:41:50 -03:00
Jussi Saurio
cc2e14b11c Read page 1 from pager always, no separate db_header 2025-06-24 14:41:49 -03:00
Jussi Saurio
bdfbb8fe54 Fix erroneous early return 2025-06-24 11:26:00 +03:00
Jussi Saurio
5878724d0e fix/btree: balance and seek after overwritten cell overflows 2025-06-24 11:08:22 +03:00
Nils Koch
2827b86917 chore: fix clippy warnings 2025-06-23 19:52:13 +01:00
pedrocarlo
74beac5ea8 ephemeral table for update when rowid is being update 2025-06-20 16:28:10 -03:00
Pere Diaz Bou
34592b172c run index tests with flags instead of ignore 2025-06-17 19:33:23 +02:00
Pekka Enberg
4496a0d08a core: Clean up integrity_check()
Suggested by Jussi.
2025-06-16 14:46:36 +03:00
Pekka Enberg
882c5ca168 Merge 'Simple integrity check on btree' from Pere Diaz Bou
This PR adds support for the instruction `IntegrityCk` which performs an
integrity check on the contents of a single table. Next PR I will try to
implement the rest of the integrity check where we would check indexes
containt correct amount of data and some more.
<img width="1151" alt="image" src="https://github.com/user-
attachments/assets/29d54148-55ba-480f-b972-e38587f0a483" />

Closes #1719
2025-06-16 13:46:26 +03:00
Pekka Enberg
90c1e3fc06 Switch Connection to use Arc instead of Rc
Connection needs to be Arc so that bindings can wrap it with `Mutex` for
multi-threading.
2025-06-16 10:43:19 +03:00
pedrocarlo
8dbf09bb42 betters instrumentation for btree operations 2025-06-11 23:34:32 -03:00
Pere Diaz Bou
9edbfa436a fmt again 2025-06-11 19:12:19 +02:00
Pere Diaz Bou
3f3e91927f fmt 2025-06-11 19:02:23 +02:00
Pere Diaz Bou
a24e1b775c check order of rowids 2025-06-11 17:56:19 +02:00
Pere Diaz Bou
d3c646378a Cell coverage checker
We check cells and freeblocks do not overlap and the fragmentation is
correct.
2025-06-11 16:50:30 +02:00
Pere Diaz Bou
9383ba207d introduce integrity_check pragma 2025-06-11 11:14:29 +02:00
Jussi Saurio
f8df870fb7 Fix implementation of InteriorNodeReplacement(interior index cell being deleted) 2025-06-10 14:16:26 +03:00
Jussi Saurio
6d2ca58235 get_prev_record() small fixes 2025-06-10 14:16:26 +03:00
Jussi Saurio
9caa8334be add FIXME about balance after interior node replacement 2025-06-10 14:16:26 +03:00
Jussi Saurio
10caca25c9 advance in balance_non_root() if -1 idx 2025-06-10 14:16:26 +03:00
Jussi Saurio
d827eeade0 For now always calculate post-balance seek key 2025-06-10 14:16:26 +03:00
Jussi Saurio
58172641fd Use SeekOP:LT after post-deletebalancing to end up pointing to the left of the deleted row 2025-06-10 14:16:26 +03:00
Jussi Saurio
e1bc268a65 fix CREATE TABLE hang 2025-06-10 14:16:26 +03:00
Jussi Saurio
a5aeff9a3d Fix index insert accidentally double-inserting after balance 2025-06-10 14:16:26 +03:00
Jussi Saurio
04e89c0c4a actually fix drop table 2025-06-10 14:16:26 +03:00
Jussi Saurio
843eb18daf simplify cursor.exists() by using seek() 2025-06-10 14:16:26 +03:00
Jussi Saurio
844461d20b update and delete fixes 2025-06-10 14:16:26 +03:00
Jussi Saurio
d81f5f67bd insert spaghetti fixes 2025-06-10 14:16:26 +03:00
Jussi Saurio
499296d396 fix drop table again: only stack.advance() in a single place 2025-06-10 14:16:26 +03:00
Jussi Saurio
5c08d259bf Fix drop table: initialize loaded pages to cell idx 0 2025-06-10 14:16:26 +03:00
Jussi Saurio
e897052650 flatten process_overflow_read() to get rid of borrowmuterror possibility 2025-06-10 14:16:26 +03:00
Jussi Saurio
5f60cce3c7 fix seek_to_last() 2025-06-10 14:16:26 +03:00
Jussi Saurio
0ce18a9146 Fix comment 2025-06-10 14:16:26 +03:00
Jussi Saurio
0b7f5a2a13 Merge MoveTo&Seek states, remove unnecessary seekstate methods, add eq_seen flag to prevent unnecessary next()/prev() 2025-06-10 14:16:26 +03:00
Jussi Saurio
2bac140d73 Remove SeekOp::EQ and encode eq_only in LE&GE - needed for iteration direction aware equality seeks 2025-06-10 14:16:26 +03:00
Jussi Saurio
ae6a943e43 Leave parent pointing at rightmost pointer at the end of balance_root() 2025-06-10 14:16:26 +03:00
Jussi Saurio
cba84b7ce9 Remove premature cast to usize (cell_idx can be negative) 2025-06-10 14:16:26 +03:00
Jussi Saurio
8ad6aadbbd remove unnecessary SeekingIndexMoveUp state 2025-06-10 14:16:26 +03:00
Jussi Saurio
a3ffc6f4e2 Align prev() implementation with next() 2025-06-10 14:16:26 +03:00
Jussi Saurio
58e1a2f5bc Remove unnecessary self.prev() from last() 2025-06-10 14:16:26 +03:00
Jussi Saurio
8941c4a537 fmt 2025-06-10 14:16:26 +03:00
Jussi Saurio
6e5f05a257 Remove unnecessary cell_idx move from tablebtree_move_to() 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
0f79b0dd50 fix prev? 2025-06-10 14:16:26 +03:00