Commit Graph

214 Commits

Author SHA1 Message Date
Pekka Enberg
bad5f2cad3 Merge 'Fix a handful of typos' from Aarni Koskela
I noticed the README had a prominent typo ("workin on"), so I decided to
run [crate-ci/typos](https://github.com/crate-ci/typos) on the repo and
fix what it flagged.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #952
2025-02-10 07:41:01 +02:00
Pekka Enberg
2eda8a54d9 Merge 'Fix various bugs in B-Tree handling' from Nikita Sivukhin
This PR introduce simple fuzz test for BTree insertion algorithm and
fixes few bugs found by fuzzer
- BTree algorithm returned early although there were overflow pages on
stack and more rebalances were needed
- BTree balancing algorithm worked under assumption that single page
will be enough for rebalance - although this is not always true (if page
were tightly packed with relatively big cells, insertion of new very big
cell can require 3 split pages to distribute the content between them)
- `overflow_cells` wasn't cleared properly during rebalancing
- insertions of dividers to the parent node were implemented incorrectly
- `defragment_page` didn't reset
`PAGE_HEADER_OFFSET_FRAGMENTED_BYTES_COUNT` field which can lead to
suboptimal usage of pages

Closes #951
2025-02-10 07:40:27 +02:00
Aarni Koskela
eaea02c567 Fix a handful of typos 2025-02-09 18:08:29 +02:00
Nikita Sivukhin
1b9772e9ad fix clippy 2025-02-09 19:36:14 +04:00
Nikita Sivukhin
32b5b0d019 introduce additional condition for cells distribution in order to avoid almost empty pages 2025-02-09 19:26:03 +04:00
Nikita Sivukhin
bc289d314a adjust test a bit 2025-02-09 19:20:48 +04:00
Nikita Sivukhin
e23ea35993 add simple B-tree validation func 2025-02-09 19:20:37 +04:00
Nikita Sivukhin
a59589844d fix insertion to the parent 2025-02-09 19:19:36 +04:00
Nikita Sivukhin
6c40f52fc8 separate fuzz tests in categories 2025-02-09 18:37:04 +04:00
Nikita Sivukhin
9049c91863 find cell in parent node 2025-02-09 18:36:37 +04:00
Nikita Sivukhin
9e4afd1d13 relax assertion 2025-02-09 18:36:26 +04:00
Nikita Sivukhin
8e6569434a add fuzz 2025-02-09 18:10:59 +04:00
Nikita Sivukhin
a62265eef4 hanle balancing cases when more than 1 level is affected 2025-02-09 18:10:19 +04:00
Nikita Sivukhin
d2251b1dd1 fix 2025-02-09 18:09:53 +04:00
Nikita Sivukhin
e8a585f87a adjust logging 2025-02-09 18:09:43 +04:00
Nikita Sivukhin
8659dbba8e fix pointer structure in case of root split 2025-02-09 17:31:39 +04:00
Nikita Sivukhin
d4bbad161b handle case when we can't balance all cells between current page and one new allocated page
- if we have page which is tightly packed with relatively big cells, we
  will be unable to balance its content if we will insert very big
  (~page size) cell in the middle (because nothing can't be merged with
  new cell - so we will need to split 1 page into 3)
2025-02-09 17:31:39 +04:00
Nikita Sivukhin
ea61f31843 clear overflow_cells 2025-02-09 17:31:39 +04:00
Nikita Sivukhin
6aa10701a4 fix comment 2025-02-09 17:31:39 +04:00
Nikita Sivukhin
eec0493c60 remove misleading comment 2025-02-09 17:31:39 +04:00
Nikita Sivukhin
fc502b86c7 fix defragmentation code a bit 2025-02-09 17:31:39 +04:00
Nikita Sivukhin
5ce3d12f75 fix typo 2025-02-09 17:31:39 +04:00
Nikita Sivukhin
62b4787d3d simplify write_varint_to_vec function 2025-02-09 17:31:39 +04:00
Nikita Sivukhin
3557c8aada adjust fuzz test 2025-02-09 17:31:39 +04:00
Jorge López
83b158fb3a core: silence some unused warnings when building without default features 2025-02-09 01:13:12 +01:00
Nikita Sivukhin
75e2f01ec4 print btree for debugging 2025-02-08 13:03:38 +04:00
Nikita Sivukhin
55dd108878 setup simple insertion fuzz test 2025-02-08 12:38:32 +04:00
Krishna Vishal
7cb7eb4e65 Merge branch 'main' into delete-btree-row 2025-02-07 01:15:21 +05:30
krishvishal
349fd51559 Get db_header from Pager instead of BTreeCursor.
Fix page_cache in btree tests to use `parking_lot::RwLock`
2025-02-07 00:11:06 +05:30
krishvishal
ea174e32f1 chore: cargo fmt 2025-02-06 23:39:12 +05:30
krishvishal
c80007d8a0 Add local constants for free_page offsets for clarity. 2025-02-06 23:39:12 +05:30
krishvishal
f836ad7561 Remove write to PAGE_HEADER_OFFSET_CELL_CONTENT_AREA in insert_into_cell. This causes corruption when you reuse cell spaces from free_list. 2025-02-06 23:39:12 +05:30
krishvishal
7d67895306 1. Added frangmentation handling to find_free_cell
2. Added asserts and corruption error to `allocate_cell_space`
2025-02-06 23:39:09 +05:30
krishvishal
8263bd0482 Update page offsets in drop_cell and update cell pointer array after dropping a cell. 2025-02-06 23:36:27 +05:30
krishvishal
73dae3003d Implement block coalescing in free_cell_range to reduce fragmentation and also added fragmentation tracking. 2025-02-06 23:36:26 +05:30
krishvishal
95da2244bb Implemented delete(). Now we are able to delete a row. It handles both interior page and leaf page cell differently. 2025-02-06 23:34:27 +05:30
krishvishal
f62ec61694 Added a unit-test to test the case where clear_overflow_pages function is called on cell with no overflow pages 2025-02-06 23:34:26 +05:30
krishvishal
8c763780a8 Added free list and free_page functionality in Pager module. Now we can add dropped pages to free list, so pages can be reused in allocate_page. 2025-02-06 23:34:12 +05:30
krishvishal
83b214a4e3 Added clear_over_pages it deletes all the overflow pages related to a cell. 2025-02-06 23:27:07 +05:30
Pekka Enberg
f3902ef9b6 core: Rename OwnedRecord to Record
We only have one record type so let's call it `Record`.
2025-02-06 13:40:34 +02:00
Pekka Enberg
f9828e0e6f core: Parse UTF-8 strings lazily 2025-02-06 13:27:52 +02:00
Pekka Enberg
e4d7474372 core: Switch to parking_lot for RwLock
We really need to make the WAL lock less expensive, but switching to
`parking_lot` is anyway something we should do.

Before:

```
Execute `SELECT 1`/Limbo
                        time:   [56.230 ns 56.463 ns 56.688 ns]
```

After:

```
Execute `SELECT 1`/Limbo
                        time:   [52.003 ns 52.132 ns 52.287 ns]
```
2025-02-04 18:38:33 +02:00
Pekka Enberg
f69804969c Merge 'Adding checkpoint result' from Sonny
### What?
adding checkpoint result returning number of pages in wal and num pages
checkpointed.
Part of #696
### Context
SQLite returns in checkpoint result of calling `pragma wal_checkpoint;`
`0|3|3` while limbo returns `0|0|0`.
https://sqlite.org/pragma.html#pragma_wal_checkpoint
- 1st col: 1 (checkpoint SQLITE_BUSY) or 0 (not busy).
- 2nd col: # modified pages written to wal file
- 3rd col: # pages moved to db after checkpoint
This PR aims to add 2nd and 3rd column to the checkpoint result.
SQLite
```
sqlite3 test.db
sqlite> pragma journal_mode=wal;
wal
sqlite> pragma journal_mode;
wal
sqlite> create table t1 (id text);
sqlite> insert into t1(id) values (1),(2);
sqlite> select * from t1;
1
2
sqlite> pragma wal_checkpoint;
0|3|3
```
Limbo
```
./target/debug/limbo test.db
Limbo v0.0.13
Enter ".help" for usage hints.
limbo> pragma journal_mode;
wal
limbo> create table t1(id text);
limbo> insert into t1(id) values (1),(2);
limbo> select * from t1;
1
2
# current the 2nd and 3rd columns are hard coded in limbo to 0
limbo> pragma wal_checkpoint;
0|0|0
```

Closes #827
2025-02-04 18:26:24 +02:00
Jussi Saurio
1f888fea4f Dont fsync the WAL on read queries 2025-02-03 20:42:50 +02:00
sonhmai
022a8d7a83 core: return checkpoint result 2025-02-03 19:02:16 +07:00
sonhmai
1c803aa079 feat: add wal checkpoint result 2025-02-03 18:57:22 +07:00
Alex Miller
9ac52b66d9 Refactor cursor to support multiple state machines 2025-01-30 14:08:44 -08:00
Pekka Enberg
983875c443 core: Remove database header from BTreeCursor
It's already in the pager so use it from there to reduce the size of the
`BTreeCursor` struct.
2025-01-26 16:48:12 +02:00
sonhmai
fcd893284b chore: fix typos 2025-01-23 11:25:01 +07:00
sonhmai
cb631dafdc feat: wire checkpoint to bytecode execution 2025-01-20 08:34:13 +07:00