Commit Graph

131 Commits

Author SHA1 Message Date
Pekka Enberg
e3f71259d8 Rename OwnedValue -> Value
We have not had enough merge conflicts for a while so let's do a
tree-wide rename.
2025-05-15 09:59:46 +03:00
Jussi Saurio
6096cfb3d8 Merge 'Add PRAGMA schema_version' from Anton Harniakou
This PR adds `PRAGMA schema_version` to get the value of the schema-
version integer at offset 40 in the database header.

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

Closes #1427
2025-05-01 10:50:02 +03:00
Anton Harniakou
525b7fdbaa Add PRAGMA schema_version 2025-04-30 09:41:04 +03:00
meteorgan
d2dce740f7 fix some issues about page_size 2025-04-28 16:13:07 +08:00
Jussi Saurio
75c6678a06 sqlite3_ondisk: use debug asserts for cell_table_interior_read... funcs 2025-04-26 14:50:42 +03:00
Jussi Saurio
23ae5a27c4 btree/tablebtree_move_to: micro-optimizations 2025-04-26 11:32:24 +03:00
Jussi Saurio
3553d05c32 Merge 'Give name to hard-coded page_size values' from Anton Harniakou
Related to #1379
I guess there are more hard-coded values.

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

Closes #1404
2025-04-25 22:03:43 +03:00
Anton Harniakou
dd7c0ad1c8 Give name to hard-coded page_size values 2025-04-25 14:15:15 +03:00
Jussi Saurio
7921d7c2e0 types: refactor serialtype again to make it faster 2025-04-24 17:28:31 +03:00
Jussi Saurio
04adf8242a faster validate 2025-04-24 16:05:12 +03:00
Jussi Saurio
af6a783f4d core/types: remove duplicate serialtype implementation 2025-04-24 15:38:47 +03:00
Jussi Saurio
017cdb9568 btree: avoid reading entire cell when only rowid needed 2025-04-18 16:52:05 +03:00
Jussi Saurio
f79da7194f implement Iterator for SmallVec and add const generic for array size 2025-04-14 11:23:37 +03:00
Pekka Enberg
53633e8b6f core/btree: Add PageContent::new() helper 2025-04-10 13:14:38 +03:00
Pere Diaz Bou
d9453f6e06 fix cell_get_raw_region length calculation 2025-04-09 15:04:45 +02:00
TcMits
56fa9049c3 fix: overflow pos in write_page 2025-04-03 15:02:53 +07:00
Pere Diaz Bou
2a49fe9bd2 Remove RWLock from Shared wal state
WalShared state can be shared without having to wrap everything with a
lock, and instead use atomics on some places and rwlock on others -- for
now.

## Results:
From:
----
Execute `SELECT 1`/limbo_execute_select_1
                        time:   [34.125 ns 34.218 ns 34.324 ns]
Execute `SELECT 1`/sqlite_execute_select_1
                        time:   [28.124 ns 28.254 ns 28.385 ns]

To:
----
Gnuplot not found, using plotters backend
Execute `SELECT 1`/limbo_execute_select_1
                        time:   [31.919 ns 32.113 ns 32.327 ns]
Execute `SELECT 1`/sqlite_execute_select_1
                        time:   [29.662 ns 29.900 ns 30.139 ns]
2025-04-02 16:18:36 +02:00
Pere Diaz Bou
8d74f4b8ab remove unnecessary partial ord 2025-03-30 11:07:23 +02:00
Pere Diaz Bou
6ccb2e16d1 safer api for ImmutableRecord recreation 2025-03-30 11:00:13 +02:00
Pere Diaz Bou
d9f5cd870d clippy 2025-03-29 22:04:08 +01:00
Pere Diaz Bou
e504262bd5 fix rebase 2025-03-29 22:04:08 +01:00
Pere Diaz Bou
105b421274 make read_record, read_varint and read_value faster
We make read_record faster by not allocating Vec if not needed. This is
why I introduced a simple `SmallVec<T>` that will have a stack allocated
list for the simplest workloads, and a heap allocated if we were to
require more stuff.

Both read_varint and read_value, at least in my mac m4, were not
inlined. Since these functions are called so many times it made sense to
inline them to avoid call overhead. With this I saw something like 20%
improvement over previous commit in my m4.
2025-03-29 22:04:08 +01:00
Pere Diaz Bou
3317195a53 Reusable ImmutableRecord -> allocation reduction
Improve allocation usage from ImmutableRecords by reusing them.
ImmutableRecord is basically a contigous piece of memory that holds the
current record. If we move to some other record we usually deallocate
the previous one and allocate a new one -- obviously this is wasteful.
With this commit we will reuse the ImmutableRecord to allow payload to
be extended if needed or reused if we can, making it faster to iterate
records basically.
2025-03-29 22:04:08 +01:00
Pere Diaz Bou
c5b718ac32 fix review comments 2025-03-28 11:30:19 +01:00
Pere Diaz Bou
f51c20adf0 read overflow pages on demand 2025-03-28 11:12:43 +01:00
Pere Diaz Bou
dc8acf1a4a cell_get no allocations 2025-03-28 11:12:27 +01:00
Pekka Enberg
c1a0236dcc Merge 'Introduce immutable record' from Pere Diaz Bou
Currently we have a Record, which is a dumb vector of cloned values.
This is incredibly bad for performance as we do not want to clone
objects unless needed. Therefore, let's start by introducing this type
so that any record that has already been serialized will be returned
from btree in the format of a simple payload with reference to payload.

Closes #1176
2025-03-26 20:31:04 +02:00
Pere Diaz Bou
f07f10ac53 fix read empty blob/text 2025-03-26 18:11:44 +01:00
Daniel Boll
6d42d6d485 Remove commented-out code and update min_frame assignment 2025-03-25 21:44:18 -03:00
Daniel Boll
5fc9ccdc8c Update checkpoint result initialization and WAL frame handling
- Use `CheckpointResult::default()` instead of `CheckpointResult::new()`
- Correct WAL frame header salt and checksum handling
- Ensure frame ID is 1-based and adjust frame offset calculation
- Add `Default` implementation for `CheckpointResult`
- Use random values for WAL header salts
2025-03-25 21:38:12 -03:00
Pere Diaz Bou
8642d416c7 Introduce immutable record.
Currently we have a Record, which is a dumb vector of cloned values.
This is incredibly bad for performance as we do not want to clone
objects unless needed. Therefore, let's start by introducing this type
so that any record that has already been serialized will be returned
from btree in the format of a simple payload with reference to payload.
2025-03-25 17:35:41 +01:00
Pekka Enberg
df6af6ed79 core: Rename FileStorage to DatabaseFile 2025-03-25 11:15:16 +02:00
Pekka Enberg
52ccc36061 Merge 'Impl Copy on some types in the pager to prevent explicit clones' from Preston Thorpe
Tried to keep this as small and focused as possible, just a few that I
ran into while debugging the page cache

Closes #1107
2025-03-21 18:40:14 +02:00
Pere Diaz Bou
00ab3d1c0c Fix ordering and implement Deref 2025-03-17 10:22:42 +01:00
Pere Diaz Bou
20f5ade95e Experiment with a custom Lock for database header 2025-03-17 10:21:34 +01:00
PThorpe92
e22c86c230 Impl Copy on some types in the pager to prevent explicit clones 2025-03-12 21:57:35 -04:00
Pekka Enberg
b73df180cc Merge 'Fix various issues in insert_into_cell()' from Krishna Vishal
There are two bugs in #1085.
1. `find_free_cell` accesses non-existent free blocks and returns their
size to `allocate_space`. This is out of range access error. The fix is
to add a loop termination condition that stops it when we hit the end of
the blocks
2. This bug is caused by `find_free_cell` some how swallowing the blocks
with size `4 bytes`. So `compute_free_space` consistently undercounts by
`4 bytes`. I've refactored that part of the code to make sure 4 sized
block are not deleted.
I've also added a unit test which proves these fixes work and also added
a function called `debug_print_freelist` which prints all free blocks of
a page.
For now I've silenced the `overflow_page` tests.
Fixes #1085

Closes #1111
2025-03-12 18:51:19 +02:00
Pere Diaz Bou
aa4703c442 Fix read frame setting wrong offset
When I added frame reading support I thought, okay, who cares about the page id of this page it we read it from a frame because we don't need it to compute the offset to read from the file in this case. Fuck me, because it was needed in case we read `page 1` from WAL because it has a differnt `offset`.
2025-03-12 17:24:59 +01:00
Pere Diaz Bou
be3badc1f3 modify a few btree log level and add end_write_txn after checkpoint 2025-03-12 15:48:22 +01:00
krishvishal
91fa6a5fa3 Remove debug prints and make clippy happy 2025-03-11 20:30:09 +05:30
krishvishal
a1a63f621e Add a method that can help while debugging freelist blocks 2025-03-11 20:30:09 +05:30
Pere Diaz Bou
ab2fc3fb13 fix clippy arc warnings for now 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
8daf7666d1 Make database Sync + Send 2025-03-05 14:07:48 +01:00
Pekka Enberg
b4e8afa3c7 Merge 'Implement SQLite balancing algorithm' from Pere Diaz Bou
Beep boop.
What happened you ask? I removed the dumb balancing algorithm I
implemented in favor of SQLite's implementation based on B*Tree[1] where
a page is 2/3 full instead of 1/2. It also tries to balance a page by
taking a maximum 3 pages and distributing cells evenly between them.
I've made some changes that are somewhat related:
* Moved most operations on pages out of BTreeCursor because those
operations are based on a page, not on a cursor, and it makes it easier
to test.
* Fixed `write_u16` and `read_u16` cases that didn't need a implicit
offset calculation. Added: `write_u16_no_offset` and
`read_u16_no_offset` to counter this.
* Added some tests with fuzz testing too.
* Fixed some important actions like: `compute_free_space`,
`defragment_page` and `drop_cell`.
[1] https://dl.acm.org/doi/10.1145/356770.356776

Closes #968
2025-02-28 19:10:52 +02:00
Pekka Enberg
6d44ad22fd core: Optimize read_record() function
The SerialType::try_from() was pretty high up in CPU profiles so I asked
my dear friend Claude to optimize it away by using the serial type
integer value directly instead of constructing a fancy enumeration.
2025-02-26 13:31:38 +02:00
Pere Diaz Bou
b64cc769b6 fix rebase 2025-02-16 18:31:03 +01:00
Nikita Sivukhin
37e27131e3 fix inequality 2025-02-16 12:49:55 +04:00
Nikita Sivukhin
d2a507e458 add unit tests for reading integer serial types 2025-02-16 12:46:45 +04:00
Nikita Sivukhin
279652b271 extend sign for 24/48 bit width serial types 2025-02-16 12:46:18 +04:00
Pere Diaz Bou
7e55f46b26 fix defragment 2025-02-15 16:46:22 +01:00