Commit Graph

154 Commits

Author SHA1 Message Date
Pere Diaz Bou
6802bb7e6a distinguish balance and balance_non_root
`balance_non_root` should be as close as possible to `balance_non_root`
in SQLite. This commits extract `balance_non_root` from `balance` and
renames `balance_leaf` to `balance` as it enables future work on a
complete `balance_non_root` procedure.
2025-01-08 19:05:49 +01:00
Ziyak Jehangir
4f119f4b95 refactor: simplify database header write logic 2025-01-04 14:31:23 +05:30
Kould
a33984087f chore: add comment on BTreeCursor::seek 2025-01-02 18:18:17 +08:00
Kould
e5d0ad044e fix: index seek wrong 2025-01-02 11:11:44 +08:00
Lauri Virtanen
854005b977 Run cargo clippy --fix && cargo fmt 2024-12-29 19:22:28 +02:00
PThorpe92
f6cd707544 Add clippy CI, fix or ignore warnings where appropriate 2024-12-29 10:25:41 -05:00
adamnemecek
97647ff056 Clean up code to use Self
Closes #556
2024-12-29 10:07:38 +02:00
김선우
ad2d515ffd Merge branch 'main' into feature/delete-planning 2024-12-27 23:21:35 +09:00
Pekka Enberg
244326ee57 core: Remove unused imports 2024-12-27 10:55:31 +02:00
Pekka Enberg
5065074617 Merge 'core: disk serialization changes to align with sqlite' from Jussi Saurio
This PR's genesis is from investigating #532, but I still can't reliably
reproduce it on either `main` or this branch so I don't know if this PR
_fixes_ anything, but I guess it aligns us more with sqlite anyway
---
Anyway: I looked at DBs created with limbo and with sqlite using
[ImHex](https://github.com/WerWolv/ImHex) and the differences seem to
be:
1. SQLite uses varint according to [the
spec](https://www.sqlite.org/fileformat.html#record_format), whereas
limbo always encodes integers as i64
2. Limbo adds 4 bytes of zeros for overflow page pointer (even in cases
where the cell doesnt overflow)
3. Limbo adds a space after `CREATE TABLE name` before the `(` even when
user doesn't specify it?
I implemented the following:
- Fix 1: Varint serialization of i8, i16, i24, i32, i48 and i64
according to payload, instead of always using i64
- Fix 2: Removed the 4 bytes reserved for overflow page pointer in non-
overflow cases

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #550
2024-12-27 10:06:52 +02:00
Pekka Enberg
937779b8c0 Merge 'core/btree: small refactoring + documentation tweaks' from Jussi Saurio
small follow up to https://github.com/tursodatabase/limbo/pull/539
contains:
- Variable renaming and comments to `btreecursor.insert_into_cell()`
- New utility methods `pagecontent.header_size()`,
`pagecontent.cell_pointer_array_size()`,
`pagecontent.unallocated_region_start()` and
`pagecontent.unallocated_region_size()`
- Refactor of `btreecursor.compute_free_space()` (plus comments and
variable renaming)
- Rename `pagecontent.cell_get_raw_pointer_region()` to
`pagecontent.cell_pointer_array_offset_and_size()` and remove its usage
in `btreecursor.defragment_page()`

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #543
2024-12-27 10:06:30 +02:00
jussisaurio
80933a32e9 remove space allocated for overflow pointer in non-overflow cases 2024-12-25 23:09:23 +02:00
Pere Diaz Bou
a2921bd32c core: add checkpoint mode passive 2024-12-24 18:30:58 +01:00
jussisaurio
42ea9041e1 rename cell_get_raw_pointer_region() and refactor a bit 2024-12-24 19:27:01 +02:00
Pere Diaz Bou
3bce282352 respect max_frame on checkpoint 2024-12-24 18:18:17 +01:00
Pere Diaz Bou
aed14117c9 core: transaction support 2024-12-24 18:04:30 +01:00
jussisaurio
25338b5cb4 refactor compute_free_space() 2024-12-24 19:00:22 +02:00
jussisaurio
c6b7ddf77a Improve comments in BTreeCursor::compute_free_space() 2024-12-24 10:30:27 +02:00
jussisaurio
91cca0d5b7 use more descriptive names in BTreeCursor::insert_into_cell() 2024-12-24 10:28:53 +02:00
jussisaurio
c727ed7e8a rename cell_start to cell_pointer_array_start, part 2: electric boogaloo 2024-12-23 22:31:35 +02:00
jussisaurio
17440393f5 rename cell_start to cell_pointer_array_start 2024-12-23 22:30:05 +02:00
jussisaurio
81526089a4 add comment about cell_get_raw_pointer_region() 2024-12-23 22:26:49 +02:00
jussisaurio
668a0ecae8 comment about page header size difference between page types 2024-12-23 22:18:22 +02:00
jussisaurio
9ea4c95ee1 even more comments 2024-12-23 22:07:20 +02:00
jussisaurio
6a287ae1a9 add comment about cell_content_area 0 value meaning u16::MAX 2024-12-23 21:33:57 +02:00
jussisaurio
40a0bef0dc better fixme comments 2024-12-23 21:19:18 +02:00
jussisaurio
c417fe7880 add link to sqlite source about payload_overflows() 2024-12-23 21:14:20 +02:00
jussisaurio
b57a95752c core/btree: improve documentation 2024-12-22 23:05:25 +02:00
김선우
9bacf80f2e Change to println! 2024-12-22 14:41:12 +09:00
김선우
a42b185ece Nit 2024-12-22 14:22:10 +09:00
김선우
9a8b94ef93 First successful implementation of delete planning 2024-12-22 13:16:16 +09:00
jussisaurio
5b4ef4412b Merge 'Implement json_array' from Kacper Madej
Implements [json_array](https://sqlite.org/json1.html#jarray).
As a side quest, this PR also fixes an issue with the `CHAR` function
which didn't work properly if the parameters were  non-leaf AST nodes.
The PR is quite big, because as I mentioned in https://github.com/tursod
atabase/limbo/issues/127#issuecomment-2541307979 we had to modify
`OwnedValue::Text` to support a `subtype` parameter, which is what
SQLite does.

Closes #504
2024-12-20 16:35:40 +02:00
Kacper Madej
19ae42dfa3 Implement json_array 2024-12-20 11:15:48 +01:00
Ziyak Jehangir
99d1b0e5a3 cleanup: replace &(*x) with x.as_ref() for smart pointer derefs 2024-12-19 19:36:04 +05:30
Pere Diaz Bou
a03749be21 Merge 'Page cache by page_number and frame_number' from Pere Diaz Bou
Since page cache is now shared by default, we need to cache pages by
page number and something else. I chose to go with max_frame of
connection, because this connection will have a max_frame set until from
the start of a transaction until the end of it.
With key pairs of (pgno, max_frame) we make sure each connection is
caching based on the snapshot it is at as two different connections
might have the same pageno being using but a different frame. If both
have same max_frame then they will share same page.

Closes #468
2024-12-16 10:08:34 +01:00
Pere Diaz Bou
a4d7fee090 typos 2024-12-15 22:54:32 +01:00
Pere Diaz Bou
78d8bb1fa6 comments for everyone 2024-12-15 22:52:49 +01:00
Pere Diaz Bou
37005a23d2 fix checkpoint 2024-12-15 18:55:23 +00:00
Pere Diaz Bou
de3449be5a add todo for cache invalidation 2024-12-15 10:03:10 +01:00
Pere Diaz Bou
c6481c4250 add missing propagation error 2024-12-15 10:02:08 +01:00
Pere Diaz Bou
e75b90e35b add contents to checkpoint page 2024-12-15 10:01:22 +01:00
Ikko Eltociear Ashimine
043fba2632 core: update btree.rs
postion -> position
2024-12-15 03:31:46 +09:00
Pere Diaz Bou
39a75147d4 Page cache by page_number and frame_number
Since page cache is now shared by default, we need to cache pages by
page number and something else. I chose to go with max_frame of
connection, because this connection will have a max_frame set until from
the start of a transaction until the end of it.

With key pairs of (pgno, max_frame) we make sure each connection is
caching based on the snapshot it is at as two different connections
might have the same pageno being using but a different frame. If both
have same max_frame then they will share same page.
2024-12-13 21:57:27 +01:00
Pere Diaz Bou
1e5239a164 use correct min/max frames 2024-12-13 14:06:29 +01:00
Pere Diaz Bou
b43e8e46f6 impl sync/send for cache 2024-12-13 13:09:13 +01:00
Pere Diaz Bou
97dd95abea core: change Rc<RefCell<Page>> to Arc<Page>
This includes an inner struct in Page wrapped with Unsafe cell to access
it. This is done intentionally because concurrency control of pages is
handled by pages and not by the page itself.
2024-12-13 13:09:13 +01:00
Pere Diaz Bou
c816186326 fmt 2024-12-13 13:09:13 +01:00
Pere Diaz Bou
3fda2d09b9 Extract multi threaded part from WalFile to WalFileShared
Since we expect to ensure thread safety between multiple threads in the
future, we extract what is important to be shared between multiple
connections with regards to WAL.

This is WIP so I just put whatever feels like important behind a RwLock
but expect this to change to Atomics in the future as needed. Maybe even
these locks might disappear because they will be better served with
transaction locks.
2024-12-13 13:09:13 +01:00
Pere Diaz Bou
a4297702bd extract page cache to be multi threaded 2024-12-13 13:09:13 +01:00
krishvishal
7e2928a5f1 Feature: last_insert_rowid()
- Changed `Cursor` trait to be able to get access to `root_page`
- SQLite only updates last_insert_rowid for non-schema inserts. So we check if the `InsertAwait` is not for `root_page` before
  updating rowid
2024-12-09 22:48:42 +05:30