Commit Graph

5102 Commits

Author SHA1 Message Date
Pere Diaz Bou
a24e1b775c check order of rowids 2025-06-11 17:56:19 +02:00
Pere Diaz Bou
d3c646378a Cell coverage checker
We check cells and freeblocks do not overlap and the fragmentation is
correct.
2025-06-11 16:50:30 +02:00
Pere Diaz Bou
9383ba207d introduce integrity_check pragma 2025-06-11 11:14:29 +02:00
Pere Diaz Bou
a4237dbe6e Merge 'Fix incorrect usage of indexes with non-contiguous columns' from Jussi Saurio
Due to the left-prefix rule of indexes, for an index key to be usable,
it needs to:
- Use the columns in contiguous order (0, 1, 2...)
  * eg if WHERE refers to cols 0 and 2, only 0 can be used
- Stop at the first range operator
  * eg if WHERE: col1 = 5 AND col2 > 5 AND col3 = 5, only col1 and col2
can be used.
This wasn't properly tested, and resulted in simulator failures (e.g.
seed `10818913476224476676` which no longer fails with this fix). Added
some regression tests for this behavior, as well.

Reviewed-by: Preston Thorpe (@PThorpe92)
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1698
2025-06-10 15:10:25 +02:00
Jussi Saurio
547ca6cf2a Fix incorrect usage of indexes with non-contiguous columns
Due to the left-prefix rule of indexes, for an index key to be usable,
it needs to:

- Use the columns in contiguous order (0, 1, 2...)
  * eg if WHERE refers to cols 0 and 2, only 0 can be used
- Stop at the first range operator
  * eg if WHERE: col1 = 5 AND col2 > 5 AND col3 = 5, only col1 and col2
    can be used.

This wasn't properly tested, and resulted in simulator failures. Added
some regression tests for this behavior.
2025-06-10 15:21:26 +03:00
Pere Diaz Bou
9770ffb902 Merge 'BTree traversal refactor and bugfixes' from Pere Diaz Bou
The major change in this PR is the following:
- It refactors deserializing the record from the cell so that it does
not happen in `next()` or `prev()`, but lazily when it is needed. This
will allow a further enhancement where we only read a _partial_ section
of the record payload, e.g. when `Insn::Column` is requested by the
VDBE, we can only deserialize the relevant column.
It also fixes multiple bugs in `BTreeCursor`
Follow-ups:
ASAP: fix performance regression (probably due to too much record
invalidation)
ASAP: do post-balance seek key calculation only when balance will be
needed
ASAP: fix balancing scenario where interior index cell is deleted - even
if leaf doesnt require balance, parent might. both need to be checked
LATER: implement safe way to use indexes for UPDATE -- ephemeral indexes
needed, see FIXME in `optimizer/mod.rs`
LATER: implement on-demand serialization of parts of the record, instead
of entire record

Closes #1664
2025-06-10 13:38:20 +02:00
Jussi Saurio
f8df870fb7 Fix implementation of InteriorNodeReplacement(interior index cell being deleted) 2025-06-10 14:16:26 +03:00
Jussi Saurio
6d2ca58235 get_prev_record() small fixes 2025-06-10 14:16:26 +03:00
Jussi Saurio
07c947b47d use GE for idx delete seek, although it doesnt really matter 2025-06-10 14:16:26 +03:00
Jussi Saurio
9caa8334be add FIXME about balance after interior node replacement 2025-06-10 14:16:26 +03:00
Jussi Saurio
10caca25c9 advance in balance_non_root() if -1 idx 2025-06-10 14:16:26 +03:00
Jussi Saurio
d827eeade0 For now always calculate post-balance seek key 2025-06-10 14:16:26 +03:00
Jussi Saurio
976c2f72ef OpIdxDeleteState needs another state to be re-entrant 2025-06-10 14:16:26 +03:00
Jussi Saurio
58172641fd Use SeekOP:LT after post-deletebalancing to end up pointing to the left of the deleted row 2025-06-10 14:16:26 +03:00
Jussi Saurio
e1bc268a65 fix CREATE TABLE hang 2025-06-10 14:16:26 +03:00
Jussi Saurio
a5aeff9a3d Fix index insert accidentally double-inserting after balance 2025-06-10 14:16:26 +03:00
Jussi Saurio
04e89c0c4a actually fix drop table 2025-06-10 14:16:26 +03:00
Jussi Saurio
3265e0a789 adjust timeouts in ci 2025-06-10 14:16:26 +03:00
Jussi Saurio
843eb18daf simplify cursor.exists() by using seek() 2025-06-10 14:16:26 +03:00
Jussi Saurio
844461d20b update and delete fixes 2025-06-10 14:16:26 +03:00
Jussi Saurio
d81f5f67bd insert spaghetti fixes 2025-06-10 14:16:26 +03:00
Jussi Saurio
499296d396 fix drop table again: only stack.advance() in a single place 2025-06-10 14:16:26 +03:00
Jussi Saurio
1b4bef9c7c Fix op_idx_delete infinite seeking loop 2025-06-10 14:16:26 +03:00
Jussi Saurio
5c08d259bf Fix drop table: initialize loaded pages to cell idx 0 2025-06-10 14:16:26 +03:00
Jussi Saurio
e897052650 flatten process_overflow_read() to get rid of borrowmuterror possibility 2025-06-10 14:16:26 +03:00
Jussi Saurio
da2437408e get_new_rowid(): fix off by one - rowids start at 1 2025-06-10 14:16:26 +03:00
Jussi Saurio
5f60cce3c7 fix seek_to_last() 2025-06-10 14:16:26 +03:00
Jussi Saurio
0ce18a9146 Fix comment 2025-06-10 14:16:26 +03:00
Jussi Saurio
0b7f5a2a13 Merge MoveTo&Seek states, remove unnecessary seekstate methods, add eq_seen flag to prevent unnecessary next()/prev() 2025-06-10 14:16:26 +03:00
Jussi Saurio
2bac140d73 Remove SeekOp::EQ and encode eq_only in LE&GE - needed for iteration direction aware equality seeks 2025-06-10 14:16:26 +03:00
Jussi Saurio
ae6a943e43 Leave parent pointing at rightmost pointer at the end of balance_root() 2025-06-10 14:16:26 +03:00
Jussi Saurio
cba84b7ce9 Remove premature cast to usize (cell_idx can be negative) 2025-06-10 14:16:26 +03:00
Jussi Saurio
8ad6aadbbd remove unnecessary SeekingIndexMoveUp state 2025-06-10 14:16:26 +03:00
Jussi Saurio
a3ffc6f4e2 Align prev() implementation with next() 2025-06-10 14:16:26 +03:00
Jussi Saurio
58e1a2f5bc Remove unnecessary self.prev() from last() 2025-06-10 14:16:26 +03:00
Jussi Saurio
8941c4a537 fmt 2025-06-10 14:16:26 +03:00
Jussi Saurio
6e5f05a257 Remove unnecessary cell_idx move from tablebtree_move_to() 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
0f79b0dd50 fix prev? 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
f83d837131 fix next to not advance if not necessary 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
f261d5b6af compare on next/prev after seek 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
681df9b1eb fix get record 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
b46852a366 move setting target key in delete if balance is needed 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
c52d9a52d9 fix count 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
96324834a5 invalidate records on movement 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
77b6896eae implement lazy record and rowid in cursor
This also comments save_context for now
2025-06-10 14:16:26 +03:00
Pere Diaz Bou
b0c64cb4d2 parse record lazily 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
105de7e1d8 seek, next and prev return bool 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
0698249c5e test_delete_with_index 2025-06-10 14:16:26 +03:00
Pere Diaz Bou
4a25578723 Merge 'Namespace functions that operate on Value' from Pedro Muniz
This PR is extracted from #1674. This PR creates the optional feature
flag `simulator` that exposes the numeric module and enables an optional
Serde derive on limbo's `Value` type. Additionally, it also namespaces
all of the exec_* functions that operate on a `Value` or indirectly
operate on a `Value` (e.g `exec_like` operates on a pattern string that
is derived from the `Value`). This is necessary so that instead of
reimplementing all of the expected behaviours of different operations
inside the simulator, we can just tap into the existing code we already
have. The next step for this will be wrap be to use `Value` inside the
simulator, which is something that I did in #1674.

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

Closes #1692
2025-06-10 10:54:38 +02:00
PThorpe92
09b345dda1 Merge 'Add sleep between write tests to avoid database locking issues' from Pedro Muniz
My guess as to why the sleep solves the problem is that when you ask
Limbo to quit it needs to checkpoint and with large blobs this probably
takes a while. What I think happens is:
- Now after the python code asks for the program to quit, it already
tries to sleep to allow the checkpointing to succeed
- It terminates the pipe
- Then kills it so that the locking of file is dropped sooner
Then later, we open another shell with SQLite in `test.test_compat()`
and try to run some queries in the database, but the file locking is
still in place. This is my guess on what is going on. I remember
@PThorpe92 had a similar problem a while back on something similar to
this.
```python
    def quit(self) -> None:
        self._write_to_pipe(".quit")
        sleep(0.3)
        self.pipe.terminate()
        self.pipe.kill()
```
This PR also adds a `PRAGMA integrity_check` for the write tests

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1694
2025-06-09 18:10:23 -04:00