Commit Graph

3301 Commits

Author SHA1 Message Date
Pekka Enberg
bc30ca57e8 Merge 'sqlite3: Add Rust tests for SQLite3 API implementation' from Karan Janthe
This PR introduces test for SQLite3 API implementation, adding both unit
tests in Rust and maintaining existing C compatibility tests.
## Changes
- Added unit tests for core SQLite3 operations in `lib.rs`:
  - Database initialization and shutdown
  - Memory database operations
  - Error code handling and messages
  - Statement preparation and execution
  - Version information verification

Closes #1108
2025-03-08 09:03:18 +02:00
karan
58a12d0a51 Merge branch 'main' into sqlite3-tests 2025-03-08 09:58:27 +05:30
karan
34876c4711 fixing erro code for sqlite open
Signed-off-by: karan <karanjanthe@gmail.com>
2025-03-08 09:52:43 +05:30
karan
eba5e74a2c Cargo fmt
Signed-off-by: karan <karanjanthe@gmail.com>
2025-03-07 19:12:44 +05:30
karan
d7939f05c2 Added tests in sqlite3
Signed-off-by: karan <karanjanthe@gmail.com>
2025-03-07 19:09:58 +05:30
Pekka Enberg
051d879db2 core: Fix btree test compilation 2025-03-06 19:14:48 +02:00
Pekka Enberg
b0636e4494 Merge 'Adds Drop Table' from Zaid Humayun
This PR adds support for `DROP TABLE` and addresses issue
https://github.com/tursodatabase/limbo/issues/894
It depends on https://github.com/tursodatabase/limbo/pull/785 being
merged in because it requires the implementation of `free_page`.
EDIT: The PR above has been merged.
It adds the following:
* an implementation for the `DropTable` AST instruction via a method
called `translate_drop_table`
* a couple of new instructions - `Destroy` and `DropTable`. The former
is to modify physical b-tree pages and the latter is to modify in-memory
structures like the schema hash table.
* `btree_destroy` on `BTreeCursor` to walk the tree of pages for this
table and place it in free list.
* state machine traversal for both `btree_destroy` and
`clear_overflow_pages` to ensure performant, correct code.
* unit & tcl tests
* modifies the `Null` instruction to follow SQLite semantics and accept
a second register. It will set all registers in this range to null. This
is required for `DROP TABLE`.
The screenshots below have a comparison of the bytecodes generated via
SQLite & Limbo.
Limbo has the same instruction set except for the subroutines which
involve opening an ephemeral table, copying over the triggers from the
`sqlite_schema` table and then re-inserting them back into the
`sqlite_schema` table.
This is because `OpenEphemeral` is still a WIP and is being tracked at
https://github.com/tursodatabase/limbo/pull/768
![Screenshot 2025-02-09 at 7 05 03 PM](https://github.com/user-
attachments/assets/1d597001-a60c-4a76-89fd-8b90881c77c9)
![Screenshot 2025-02-09 at 7 05 35 PM](https://github.com/user-
attachments/assets/ecfd2a7a-2edc-49cd-a8d1-7b4db8657444)

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

Closes #897
2025-03-06 18:27:41 +02:00
Pekka Enberg
869bd5b363 Fix installer script URL
Fixes #1103
2025-03-06 14:34:51 +02:00
Pekka Enberg
ab8161c357 Merge 'Integrate MVCC' from Pekka Enberg
This pull request integrates MVCC with the VDBE.

The long term plan is to implement SQLite `BEGIN CONCURRENT` by
introducing a "MV store" abstraction (that implements the Hekaton in-
memory MVCC index) above the pager. Traditional SQLite transactions use
the pager and the WAL, but MV store has its own transaction path that
updates the in-memory multi-versioned index. If a key does not exist in
the MVCC index, we read records from the pager. When a MVCC transaction
commits, we emit WAL entries.

In this pull request, we wire up the MVCC transaction machinery to VDBE
and multi-version cursor to the b-tree cursor. Currently, the database
either runs in normal b-tree mode or in in-memory MVCC, but we need to
explore if we can make it a hybrid solution where you can read from both
MVCC index and B-Tree. Note that this pull request also does not add
logical logging to a file, which is something we'll defer for later.

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

Closes #917
2025-03-06 13:00:40 +02:00
Pekka Enberg
ef180fa1cb core/mvcc: Improve tracing format
Suggested by Pere
2025-03-06 12:58:41 +02:00
Pekka Enberg
2c9d30cef4 core/vdbe: Don't commit MVCC on Halt if no autocommit
Spotted by Pere.
2025-03-06 12:52:03 +02:00
Pekka Enberg
d6c514c8d1 core: Integrate MVCC to B-Tree cursor 2025-03-06 10:16:42 +02:00
Pekka Enberg
bf3163c7fe core: Fix parse_schema() to use existing MVCC TX 2025-03-06 10:16:42 +02:00
Pekka Enberg
ef32a82941 core/vdbe: Integrate MVCC transactions 2025-03-06 10:16:42 +02:00
Pekka Enberg
461be0dc87 core: Add multi-version store to Database 2025-03-06 10:16:42 +02:00
Pekka Enberg
96175cccf7 cli: Add --experimental-mvcc option to enable MVCC 2025-03-06 10:16:42 +02:00
Pekka Enberg
5d0982f5db core/mvcc: Add RowID::new() and Row::new() helpers 2025-03-06 09:59:40 +02:00
Pekka Enberg
4247974f95 core/mvcc: Add insert() helper to Cursor 2025-03-06 09:32:48 +02:00
Pekka Enberg
b7382ffab1 core/mvcc: Switch Cursor to use Rc instead of lifetimes 2025-03-06 09:31:34 +02:00
Pekka Enberg
ff6d9465eb core/mvcc: Improve trace logging 2025-03-06 09:31:04 +02:00
Pekka Enberg
92863c0d6b Merge 'Transaction finish lock fixes' from Pere Diaz Bou
While adding logs to our locks in `Wal` I noticed we weren't cleaning up
connection's transaction state. This PR set to `TransactionState::None`
once commited and calls `end_read_txn` and `end_tx` in case of write.
Fixes #1004

Reviewed-by: Pekka Enberg <penberg@iki.fi>

Closes #1099
2025-03-06 07:51:27 +02:00
Pere Diaz Bou
aa7391da50 fix halt return 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
e4d22a22df ignore test again :) 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
b555561aeb make Program::halt reentrant 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
3492ed4641 remove unused import Add 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
7aae885af4 add logs to wal locks 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
7b1e2093e8 add multi threaded test for simple writer/reader test 2025-03-05 22:32:59 +01:00
Pere Diaz Bou
feeb398e73 finish transaction and reset transaction state 2025-03-05 22:32:59 +01:00
Pekka Enberg
3932309678 Merge 'core/mvcc: Eliminate row generic types' from Pekka Enberg
The logging code that writes out transactions to disk needs to write out
the byte array that we actually use. The code is less hairly without the
generics so drop them.

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

Closes #1100
2025-03-05 19:24:54 +02:00
Pekka Enberg
81b79bc833 core/mvcc: Eliminate row generic types
The logging code that writes out transactions to disk needs to write out
the byte array that we actually use. The code is less hairly without the
generics so drop them.
2025-03-05 19:17:16 +02:00
Pere Diaz Bou
c63286215e Merge 'Add tracing_subscriber and test_log::test' from Pere Diaz Bou
I don't know when and why we dropped log::* in favor of tracing but when
it was done, it made relevant logs not appear any more while debugging
so... I added test_log::test which helps by automatically adding info
logs from trace package (useful for printing seeds too).

Closes #1097
2025-03-05 16:03:51 +01:00
Pekka Enberg
acf0fb4425 scripts: Add missing parser crate to publish-crates.sh 2025-03-05 16:56:50 +02:00
Pere Diaz Bou
a79b3f5746 remove unused imports test_wal.rs 2025-03-05 15:52:10 +01:00
Pere Diaz Bou
5c0d44d0d8 test_wal conditional setup tracing 2025-03-05 15:42:04 +01:00
Pere Diaz Bou
262c4de548 add line number and thread id to tracing logs 2025-03-05 15:36:47 +01:00
Pere Diaz Bou
9a01e32c01 add tracing_subscriber and test_log::test
I don't know when and why we dropped log::* in favor of tracing but when it was done, it made relevant logs not appear any more while debugging so... I added test_log::test which helps by automatically adding info logs from trace package.
2025-03-05 15:36:06 +01:00
Pere Diaz Bou
a7f3579a0a Merge 'Bunch Database changes to prepare for multi threading.' from Pere Diaz Bou
This is an umbrella PR for multi threading where I modify the following:
* Loaded extensions (`syms`) are now moved to `Connection` as loading
extensions in SQLite is per connection and not per database.
* `Schema` is not a `RWLock` so that it behaves equally to SQLite where
schema changes block preparing new statements.
* Sprinkled a bunch of `unsafe impl Send` and `unsafe impl Sync` on top
of all `IO` implementations and inner structures for now in order to
allow multi threading. Ideally this will be enforced with transaction
locks and internal locks instead of throwing a bunch of mutexes like
rust would like us to do -- this means the work is not finished and
rather started for future improvements.

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1091
2025-03-05 15:30:07 +01:00
Pere Diaz Bou
5f5ca50c41 Move schema lock read to translate only 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
b63f541150 impl Send Sync for GenericFile 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
d1e7f0826b impl Send Sync for WindowsFile 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
3d3cdbeb0c fix generic and windows sync compilation 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
ab2fc3fb13 fix clippy arc warnings for now 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
d1c7d758c4 fix uring Sync,Sync unsafe impl 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
47cd54a7fe remove schema comment 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
17bf67e8a9 Add first multi threaded test which fails. 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
e20dd59353 Make schema a RWLock
This makes it work like in SQLite where only one schema writer is permitted and readers will return error while preparing statement if the schema is changing.
2025-03-05 14:07:48 +01:00
Pere Diaz Bou
e4a8ee5402 move load extensions to Connection
Extensions are loaded per connection and not per database as per SQLite
behaviour. This also helps with removing locks.
2025-03-05 14:07:48 +01:00
Pere Diaz Bou
0149e86356 add todo comments to remove mutex from database structures 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
8daf7666d1 Make database Sync + Send 2025-03-05 14:07:48 +01:00
Pere Diaz Bou
205cd148ca Merge 'Enable local file connection in Rust binding' from 南宫茜
It's so weird that other bindings can open local file but Rust binding
itself cannot.

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

Closes #1095
2025-03-05 14:05:35 +01:00