Commit Graph

4056 Commits

Author SHA1 Message Date
PThorpe92
39d230a899 Add bitmap for tracking pages in arena 2025-08-08 10:55:27 -04:00
PThorpe92
0ffba81216 Make register buffer io trait return the buf index 2025-08-08 10:55:27 -04:00
PThorpe92
3cff47e490 Fix btree test to properly initialize pool 2025-08-08 10:55:27 -04:00
PThorpe92
fd09fe1237 Adjust io_uring to register two arenas, one for frames and the other for db pages 2025-08-08 10:55:27 -04:00
PThorpe92
cc75bc448e Move TLC buffer cache to io/mod 2025-08-08 10:55:27 -04:00
PThorpe92
9d1ca1c8ca Add ReadFixed/WriteFixed opcodes for buffers from registered arena 2025-08-08 10:55:27 -04:00
PThorpe92
dffa47b048 Use temp buffer for wal header 2025-08-08 10:55:27 -04:00
PThorpe92
7ea52a3f89 Fix changing page size and initialization for buffer pool 2025-08-08 10:55:26 -04:00
PThorpe92
0884fec799 Use parent buffer pool for ephemeral pager and wal 2025-08-08 10:55:26 -04:00
PThorpe92
5750b1229c Setup and initialize pool properly 2025-08-08 10:55:26 -04:00
PThorpe92
4ffb273b53 Adjust IO to use new buffer pool and buffer API 2025-08-08 10:55:26 -04:00
PThorpe92
27113885a9 Update sorter to use new buffer api 2025-08-08 10:55:26 -04:00
PThorpe92
a02f527c06 Add fast path for pwritev on other IO backends 2025-08-08 10:55:25 -04:00
PThorpe92
39bccc2357 Update Buffer type in io module to adjust to new pool 2025-08-08 10:55:25 -04:00
PThorpe92
d38cd6360a Create new arena backed buffer pool 2025-08-08 10:55:25 -04:00
Preston Thorpe
d3e6172516 Merge 'global allocator should not be set for library, only for executables' from Pedro Muniz
We should be allocator-agnostic. It is pretty limiting for us to force a
user to use a particular allocator. This is specially restricting for
`no_std` in the future.

Reviewed-by: bit-aloo (@Shourya742)
Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2481
2025-08-08 09:45:35 -04:00
Jussi Saurio
2fbe33d200 Merge 'translate: return parse errors for unsupported features instead of silently ignoring' from Jussi Saurio
Closes #1510

Closes #2505
2025-08-08 15:56:13 +03:00
Jussi Saurio
cca2f6c947 Merge 'Evaluate WHERE conditions after LEFT JOIN' from Piotr Rżysko
This fix ensures that `WHERE` conditions are emitted after the `LEFT
JOIN` match flag is set, so rows from the right table are properly
filtered, even when they are `NULL` due to the outer join.
Previously, the query below would return rows where `products.price` was
`NULL`:
```sql
SELECT users.id, price
FROM users
LEFT JOIN products ON users.id = products.id
WHERE products.price IS NOT NULL;
```

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

Closes #2501
2025-08-08 15:54:17 +03:00
Jussi Saurio
21dc2d0161 translate: return parse errors for unsupported features instead of silently ignoring 2025-08-08 11:39:30 +03:00
Jussi Saurio
7fd63d8a5d btree: cache usable_space in the btreecursor constructor 2025-08-08 10:32:18 +03:00
Jussi Saurio
15c429b673 btree: remove completely unused ParseRecordState 2025-08-08 10:08:59 +03:00
Pekka Enberg
0f9d0cf519 Merge branch 'main' into 2025-08-07-add-query-only-pragma 2025-08-08 07:41:38 +03:00
Piotr Rzysko
375b9047e2 Evaluate WHERE conditions after LEFT JOIN
Previously, the query from the added test would not filter out rows
where `products.price` was NULL.
2025-08-08 06:26:30 +02:00
Piotr Rzysko
92ba25e44d Extract loop emitting conditions into a method
No functional changes — this is just preparation for reusing this code
and avoiding polluting future commits with trivial refactoring.
2025-08-08 06:21:08 +02:00
bit-aloo
c7f7ae32e3 review fixes 2025-08-08 08:43:15 +05:30
Preston Thorpe
850ee8fe62 Merge 'bench/insert: fix expected return value from pragma' from Jussi Saurio
CI did not fail when this panicked :]

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2489
2025-08-07 21:34:13 -04:00
Preston Thorpe
7a793b818d Merge 'perf: a few small insert optimizations' from Jussi Saurio
1. We spend a lot of time in `cell_get_raw_region` in the balancing
routine, and especially calling `contents.page_type()` there a lot, so
extract a version that can take some precomputed arguments so those
don't have to be redundantly computed multiple times for successive
calls where those values are going to be the same
2. Avoid calling `self.usable_space()` in a loop in
`insert_into_page()`.
3. Avoid accessing `pages_in_frames` lock if we're not going to modify
it
main improvement is to the "insert 100 rows" bench which ends up doing
balancing a lot:
```
Insert rows in batches/limbo_insert_1_rows
                        time:   [22.856 µs 24.342 µs 27.496 µs]
                        change: [-3.3579% +15.495% +67.671%] (p = 0.62 > 0.05)
                        No change in performance detected.

Benchmarking Insert rows in batches/limbo_insert_10_rows: Collecting 100 samples in estim
Insert rows in batches/limbo_insert_10_rows
                        time:   [32.196 µs 32.604 µs 32.981 µs]
                        change: [+1.3253% +2.9177% +4.5863%] (p = 0.00 < 0.05)
                        Performance has regressed.

Insert rows in batches/limbo_insert_100_rows
                        time:   [89.425 µs 92.105 µs 96.304 µs]
                        change: [-18.317% -13.605% -9.1022%] (p = 0.00 < 0.05)
                        Performance has improved.
```

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2483
2025-08-07 21:33:30 -04:00
Preston Thorpe
6b266e7e84 Merge 'Direct schema mutation – add instruction' from Levy A.
<img width="960" height="205" alt="image" src="https://github.com/user-
attachments/assets/f60a2133-dfe4-4411-9a7c-7283eb073875" />
<img width="944" height="504" alt="image" src="https://github.com/user-
attachments/assets/9383c8e2-4d8d-40b9-8ace-825ca3cf8682" />
```
`ALTER TABLE _ ADD COLUMN _`/limbo_add_column/
                        time:   [2.1199 ms 2.1921 ms 2.2756 ms]
                        change: [-85.983% -85.416% -84.716%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 13 outliers among 100 measurements (13.00%)
  6 (6.00%) high mild
  7 (7.00%) high severe
`ALTER TABLE _ ADD COLUMN _`/sqlite_add_column/
                        time:   [10.358 ms 10.404 ms 10.469 ms]
                        change: [-6.2566% -2.3515% +0.2046%] (p = 0.21 > 0.05)
                        No change in performance detected.
Found 14 outliers among 100 measurements (14.00%)
  2 (2.00%) high mild
  12 (12.00%) high severe
  ```

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2482
2025-08-07 21:31:49 -04:00
PThorpe92
bcadcb2014 Remove RefCell from copy_to method in io trait 2025-08-07 17:07:53 -04:00
PThorpe92
98f4e5cd2d Add comment/TODO about method we use to copy the db file 2025-08-07 16:27:08 -04:00
PThorpe92
e32d04ea97 Use ephemeral PlatformIO for clone method to support memory io 2025-08-07 16:27:08 -04:00
PThorpe92
039fe22405 Add copy_to to io::File trait to support copying DB files 2025-08-07 16:27:02 -04:00
Preston Thorpe
e23637b6ad Merge 'only allow multiples of 64 for performance in arena bitmap' from Preston Thorpe
Trying to support this is unnecessary and just adds branches and bit ops
when we could just round the allocation up or down

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

Closes #2497
2025-08-07 14:25:11 -04:00
bit-aloo
aaeec4d4f3 Implement PRAGMA query_only logic 2025-08-07 23:49:07 +05:30
bit-aloo
2cf7f66a02 Enforce query_only in write operations 2025-08-07 23:46:00 +05:30
bit-aloo
ef084af42f Add getter and setter methods 2025-08-07 23:44:54 +05:30
bit-aloo
697eb35ca9 Add query_only field to Connection 2025-08-07 23:44:29 +05:30
PThorpe92
c03ca5701a Dont accept values that are not multiples of 64 for performance in page bitmap 2025-08-07 13:45:07 -04:00
Piotr Rzysko
8986266394 Emit conditions in open_loop in one place
The loop emitting conditions is independent of the operation type.
2025-08-07 19:26:32 +02:00
pedrocarlo
edae65fb5f global allocator should not be set for library, only for executables 2025-08-07 13:41:50 -03:00
Jussi Saurio
aea6d942d6 bench/insert: fix expected return value from pragma 2025-08-07 17:44:46 +03:00
Levy A.
658405d6b3 feat: add AddColumn instruction 2025-08-07 11:43:16 -03:00
Jussi Saurio
1fe32dadf3 PageContent: make read_x/write_x methods private and add dedicated methods
Problem:

A very easy source of bugs is to mistakenly use e.g. PageContent::read_u16()
instead of PageContent::read_u16_no_offset(). The difference between the two
is that `read_u16()` adds 100 bytes to the requested byte offset if and only if
the page in question is page 1, which contains a 100-byte database header.

Case in point: see #2491.

Observation:

In all of the cases where we want to read from or write to a page  "header-sensitively",
those reads/writes are to so-called "well known offsets", e.g. specific bytes in a btree
page header.

In all other cases, the "no-offset" versions, i.e. the ones taking the absolute byte offset
as parameter, should be used.

Solution:

1. Make all the offset-sensitive versions (read_u16() and friends) private methods of
`PageContent`.
2. Expose dedicated methods for things like updating rightmost pointer, updating fragmented
bytes count and so on, and use them instead of the plain read/write methods universally.
2025-08-07 17:00:06 +03:00
Pekka Enberg
3f181c9145 Merge 'btree: Use correct byte offsets for page 1 in defragmentation ' from Jussi Saurio
## Beef
`defragment_page_fast()` incorrectly didn't use the version of
read/write methods on `PageContent` that does NOT add the 100 byte
database header into the requested byte offset.
this resulted in defragment of page 1 in reading 2nd/3rd freeblocks
from the wrong offset and reading/writing freeblock sizes and cell
offsets to the wrong location.
## Testing
Adds fuzz test for CREATE TABLE / DROP TABLE / ALTER TABLE, which I was
able to reproduce this with.

Closes #2491
2025-08-07 16:52:11 +03:00
Jussi Saurio
6cd7334afc btree/fix: use correct byte offsets for page1 in defragmentation
`defragment_page_fast()` incorrectly didn't use the version of
read/write methods on `PageContent` that does NOT add the 100 byte
database header into the requested byte offset.

this resulted in defragment of page 1 in reading 2nd/3rd freeblocks
from the wrong offset and writing cell offsets to the wrong location.
2025-08-07 15:42:06 +03:00
Jussi Saurio
95c6c7581b bench/insert: use PRAGMA synchronous=full
synchronous=FULL means WAL is fsynced on every commit,
which is what we also do.

however we do not do the padding to sector alignment that
sqlite does (see #2450), which makes sqlite do more work
than we do.
2025-08-07 13:40:14 +03:00
Jussi Saurio
c5bdbe306d perf/wal: avoid accessing pages_in_frames unless necessary 2025-08-07 10:27:11 +03:00
Jussi Saurio
2ed41bbb35 btree/insert: avoid calling self.usable_space() in a loop 2025-08-07 10:09:35 +03:00
Jussi Saurio
4b27cc0d46 btree: add fast path version of cell_get_raw_region 2025-08-07 09:57:56 +03:00
Jussi Saurio
c98136c8c4 btree: use new cell start helper method in cell_get_raw_region 2025-08-07 09:37:33 +03:00