Commit Graph

614 Commits

Author SHA1 Message Date
Pere Diaz Bou
f137ddfdf8 add loop left pointer validation 2025-04-07 18:01:08 +02:00
Pere Diaz Bou
6ac2368ae2 update divider cell that is being balanced 2025-04-07 18:00:49 +02:00
Pere Diaz Bou
0541da46df add strict btree validation after non root balancing in debug mode 2025-04-07 18:00:49 +02:00
Pere Diaz Bou
ff8ec5455c fix divider cell selection 2025-04-07 18:00:30 +02:00
Pere Diaz Bou
9eb9e7021e Fix index table new divider cell pointer 2025-04-07 18:00:30 +02:00
Pere Diaz Bou
f4920cb96b assert new divider cell points to the correct place 2025-04-07 18:00:30 +02:00
Pere Diaz Bou
15ed7642c9 check all keys are present on every insert with fuzz test
Let's make sure every insert does still contain all keys. Previously we
did this at the end but it made it hard to debug issues that
`validate_btree` might not encounter.
2025-04-07 18:00:30 +02:00
PThorpe92
bd04b10f17 Fix btree tests to adapt to new type for BTreeKey 2025-04-05 11:19:10 -04:00
PThorpe92
abc97c8774 Add doc comments to new btree key enum and remove unused lifetimes 2025-04-05 11:19:10 -04:00
PThorpe92
6b42808f1a Dont re-seek if we are inserting a new unique index 2025-04-05 11:19:10 -04:00
PThorpe92
068ab4ab27 Refactor btree to reuse existing insert and seek with idx keys 2025-04-05 11:19:09 -04:00
PThorpe92
007fbe8cc7 Fix unique index issue and prealloc in sql string for schema 2025-04-05 11:19:09 -04:00
PThorpe92
2c3fd509fe Remove unused imports and consolidate ordering comparison 2025-04-05 11:19:09 -04:00
PThorpe92
b0016a0ee2 Support create index with SeekEnd and IdxCreate opcode functionality 2025-04-05 11:15:36 -04:00
Pere Diaz Bou
5dedc68fda remove arc import 2025-04-02 16:56:34 +02:00
Pere Diaz Bou
e85fb86ff4 Request load page on insert_into_page
We assumed page was loaded because before inserting we would move there. `NewRowId` unfortunately moves cursor to the rightmost page causing eviction of root page -- this arose the issue with `insert_into_page` not loading the page we were supposed to have loaded so I added `return_if_locked_maybe_load` which is a utility macro to check if the page is locked and if not, load it if needed.
2025-04-02 16:24:53 +02:00
Pekka Enberg
7394ad6854 Disable more b-tree fuzzers... 2025-04-02 13:38:09 +03:00
Pekka Enberg
cc8340d30e Disable btree_insert_fuzz_run_random test 2025-04-02 09:15:01 +03:00
Pekka Enberg
6199c3994a Merge 'Create plan for Update queries' from Preston Thorpe
closes #1186, or at least works towards it by implementing an actual
Plan for update queries instead of translating everything inline. This
allows for actually using index's, rewriting const expressions, pushing
predicates instead of hardcoding a full scan in the translation.
### TODOs:
1.  `RETURNING` clause/result columns
2.  `OFFSET` clauses
3. on conflict
### LIMIT:
By supporting `LIMIT` directly in update queries, we'll have to put the
tests outside of the compatibility tests, maybe in the CLI tests.

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

Closes #1189
2025-04-01 17:33:32 +03:00
Pere Diaz Bou
6b05dbddb0 remove unnecessary code while building count old and size old balancing 2025-04-01 13:11:55 +02:00
Pere Diaz Bou
141303e330 Validate cells inside a page after each operation
We need to ensure an operation doesn't transform the cells inside a page
to an invalid state. In debug mode we can enable a
`debug_validate_cells` with `#[cfg(debug_assertions)]` so that it is
skipped on release mode.

Modify pager logs
2025-04-01 11:19:23 +02:00
Pere Diaz Bou
bab748e538 fix key generation 2025-04-01 01:05:07 +02:00
Pere Diaz Bou
d2642dfe0c skip repeated keys 2025-04-01 00:58:10 +02:00
Pere Diaz Bou
4308f8c73a Fix propagation of divider cell balancing interior page
Newly added divider cells to parent of an interior page must point to
the page in question. Moreover rightmost pointer of the page will point
to previous divider cell pointer.
2025-04-01 00:58:10 +02:00
Pere Diaz Bou
24e4af7ee8 Allow balance_root to balance with interior pages 2025-03-31 12:42:01 +02:00
Pere Diaz Bou
78f6480e8f remove ignored from fuzz tests 2025-03-31 10:59:28 +02:00
Pere Diaz Bou
bc660446a8 fuzz test ensure we "seek" until done 2025-03-31 10:57:55 +02:00
Pere Diaz Bou
0653ccf711 ensure btree fuzz doesn't repeat keys for now 2025-03-31 10:57:30 +02:00
PThorpe92
516e443a2b Fix use index cursor id in emitter and prevent reinsert pk on update 2025-03-30 12:15:25 -04:00
Pere Diaz Bou
541b67bd2b rename get_lazy_immutable_record -> get_immutable_record_or_create 2025-03-30 11:00:59 +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
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
5b7fcd27bd make column reuse blob/text fields 2025-03-29 22:02:49 +01:00
Pere Diaz Bou
bf37fd3314 wip 2025-03-29 22:02:49 +01:00
Pere Diaz Bou
c5b718ac32 fix review comments 2025-03-28 11:30:19 +01:00
Pere Diaz Bou
83d0c9a1b6 fix read overflow page procedure 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
9a646acead Merge 'Add BTree balancing after delete' from Krishna Vishal
This PR adds balancing after delete.
- [x] Remove linear search for cell in the page
- [x] Change the implementation to state machine approach
- [x] Handle cases when balancing is needed and not needed
- [x] Add unit test to verify that balancing after delete maintains
BTree integrity.
Fixes: https://github.com/tursodatabase/limbo/issues/1019
Closes: https://github.com/tursodatabase/limbo/issues/455

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

Closes #1147
2025-03-28 07:32:15 +02:00
krishvishal
1b77b76d58 Add comments detailing Delete state machine flow and few delete steps. 2025-03-27 01:02:59 +05:30
krishvishal
fe7ff6f53d Add balancing states. Balancing test works. 2025-03-27 00:27:03 +05:30
krishvishal
3e3a0f56a1 Make delete re-entrant.
Setup DeleteState enum
2025-03-26 22:44:49 +05:30
Pere Diaz Bou
63cf86ba36 fix comparison of records 2025-03-26 10:10:19 +01:00
krishvishal
16d77acac6 Add comments describing the test_delete_balancing 2025-03-26 12:29:19 +05:30
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
krishvishal
6fe7e419e2 cleanup 2025-03-25 08:58:18 +05:30
krishvishal
ac29563efb Add test to verify balancing after maintains the following:
1. Delete is working properly.
2. Balancing after delete still maintains the validity of btree.
2025-03-25 08:55:13 +05:30