Commit Graph

4010 Commits

Author SHA1 Message Date
pedrocarlo
0c137d6dff Cleaner and less error prone Write Tests 2025-04-15 12:45:46 -03:00
pedrocarlo
58e091cb23 setup uv for limbo 2025-04-15 12:45:46 -03:00
pedrocarlo
862783aec7 forgot to add to test command in makefile 2025-04-15 12:45:46 -03:00
pedrocarlo
46eaa52400 write tests for file backed db 2025-04-15 12:45:45 -03:00
Jussi Saurio
2b4ff48a8b Merge 'More index utils' from Jussi Saurio
Some more helper utilities extracted out from #1351 to make the surface
area of that PR smaller

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

Closes #1353
2025-04-15 18:20:41 +03:00
Jussi Saurio
1fe1f0ebba ProgramBuilder: add resolve_cursor_id_safe() which doesn't unwrap 2025-04-15 15:13:39 +03:00
Jussi Saurio
5a1cfb7d15 Add ColumnUsedMask struct to TableReference to track columns referenced in query 2025-04-15 15:13:31 +03:00
Jussi Saurio
72dac59813 Operation: add method index() to retrieve used index, if any 2025-04-15 15:13:24 +03:00
Jussi Saurio
e299a0e77e vdbe: add Insn::IdxRowId 2025-04-15 15:13:18 +03:00
Jussi Saurio
d2a1433345 Merge 'Fix truncation of error output in tests' from Pedro Muniz
When the python tests fail, they will sometimes truncate the output if
it is smaller than the `PIPE_BUFF` size. With this fix we can now
properly print the backtrace, when the program panics.
# Before
This is the problematic CI output from #1331  that led me to fix this.
In this case, it was already truncating the output of the `assert`
prints.
```
./testing/cli_tests/extensions.py
Extension ./target/debug/liblimbo_regexp loaded successfully.
Testing: uuid functions are registered properly with ext loaded
Testing: scalar alias's are registered properly
Testing: median agg function returns null when ext not loaded
Testing: median agg function works
Testing: median agg function works with odd number of elements
Testing: test aggregate percentile function with 2 arguments works
Testing: test aggregate percentile function with 1 argument works
Testing: crypto_blake3 returns null when ext not loaded
Testing: blake3 should encrypt correctly
Testing: md5 should encrypt correctly
Testing: sha1 should encrypt correctly
Testing: sha256 should encrypt correctly
Testing: sha384 should encrypt correctly
Testing: sha512 should encrypt correctly
Testing: base32 should encode correctly
Testing: base32 should decode correctly
Testing: base64 should encode correctly
Testing: base64 should decode correctly
Testing: base85 should encode correctly
Testing: base85 should decode correctly
Testing: hex should encode correctly
Testing: hex should decode correctly
Testing: url should encode correctly
Testing: url should decode correctly
Testing: ipfamily function returns null when ext not loaded
Testing: ipfamily function returns 4 for IPv4
Testing: ipfamily function returns 6 for IPv6
Testing: ipcontains function returns 1 for IPv4
Testing: ipcontains function returns 0 for IPv4
Testing: iphost function returns the host for IPv4
Testing: iphost function returns the host for IPv6
Testing: ipmasklen function returns the mask length for IPv4
Testing: ipmasklen function returns the mask length for IPv6
Testing: ipnetwork function returns the flattened CIDR for IPv4
Testing: ipnetwork function returns the network for IPv6
Testing: testvfs not loaded
Testing: testvfs extension loaded
thread 'main' panicked at core/storage/pager.rs:61:38:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Test FAILED: Error encountered in Limbo shell.
make: *** [Makefile:70: test-extensions] Error 1
```
# After
```
with-env {RUST_BACKTRACE:1} {make test-extensions}
cargo build
   Compiling limbo_regexp v0.0.19-pre.4 (/Users/pedro/Projects/limbo/extensions/regexp)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.51s
cargo build --package limbo_regexp
   Compiling limbo_regexp v0.0.19-pre.4 (/Users/pedro/Projects/limbo/extensions/regexp)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
./testing/cli_tests/extensions.py
Extension ./target/debug/liblimbo_regexp loaded successfully.
Testing: uuid functions are registered properly with ext loaded
Testing: scalar alias's are registered properly
Testing: median agg function returns null when ext not loaded
Testing: median agg function works
Testing: median agg function works with odd number of elements
Testing: test aggregate percentile function with 2 arguments works
Testing: test aggregate percentile function with 1 argument works
Testing: crypto_blake3 returns null when ext not loaded
Testing: blake3 should encrypt correctly
Testing: md5 should encrypt correctly
Testing: sha1 should encrypt correctly
Testing: sha256 should encrypt correctly
Testing: sha384 should encrypt correctly
Testing: sha512 should encrypt correctly
Testing: base32 should encode correctly
Testing: base32 should decode correctly
Testing: base64 should encode correctly
Testing: base64 should decode correctly
Testing: base85 should encode correctly
Testing: base85 should decode correctly
Testing: hex should encode correctly
Testing: hex should decode correctly
Testing: url should encode correctly
Testing: url should decode correctly
Testing: ipfamily function returns null when ext not loaded
Testing: ipfamily function returns 4 for IPv4
Testing: ipfamily function returns 6 for IPv6
Testing: ipcontains function returns 1 for IPv4
Testing: ipcontains function returns 0 for IPv4
Testing: iphost function returns the host for IPv4
Testing: iphost function returns the host for IPv6
Testing: ipmasklen function returns the mask length for IPv4
Testing: ipmasklen function returns the mask length for IPv6
Testing: ipnetwork function returns the flattened CIDR for IPv4
Testing: ipnetwork function returns the network for IPv6
Testing: testvfs not loaded
Testing: testvfs extension loaded
thread 'main' panicked at core/storage/pager.rs:61:38:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: core::panicking::panic
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:148:5
   3: core::option::unwrap_failed
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/option.rs:2012:5
   4: core::option::Option<T>::unwrap
             at /Users/pedro/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:972:21
   5: limbo_core::storage:📟:Page::get_contents
             at ./core/storage/pager.rs:61:9
   6: limbo_core::storage::btree::BTreeCursor::balance_non_root
             at ./core/storage/btree.rs:1723:40
   7: limbo_core::storage::btree::BTreeCursor::balance
             at ./core/storage/btree.rs:1570:35
   8: limbo_core::storage::btree::BTreeCursor::insert_into_page
             at ./core/storage/btree.rs:1512:35
   9: limbo_core::storage::btree::BTreeCursor::insert
             at ./core/storage/btree.rs:3024:31
  10: limbo_core::vdbe::execute::op_insert
             at ./core/vdbe/execute.rs:3654:23
  11: limbo_core::vdbe::Program::step
             at ./core/vdbe/mod.rs:379:23
  12: limbo_core::Statement::step
             at ./core/lib.rs:582:9
  13: limbo::app::Limbo::print_query_result
             at ./cli/app.rs:657:27
  14: limbo::app::Limbo::run_query
             at ./cli/app.rs:420:20
  15: limbo::app::Limbo::handle_input_line
             at ./cli/app.rs:527:13
  16: limbo::main
             at ./cli/main.rs:29:31
  17: core::ops::function::FnOnce::call_once
             at /Users/pedro/.rustup/toolchains/1.83.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Testing: Tested large write to testfs
Test FAILED: Test failed
SQL: SELECT count(*) FROM test;
Actual:
None
make: *** [test-extensions] Error 1
```

Closes #1346
2025-04-15 15:02:58 +03:00
Jussi Saurio
67f4cd7a9b Merge 'Index utils' from Jussi Saurio
Extracted a few commits out from #1351 which are also going to be useful
elsewhere

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

Closes #1352
2025-04-15 14:55:30 +03:00
Jussi Saurio
a467060e1c Index: add method column_table_pos_to_index_pos() 2025-04-15 14:47:56 +03:00
Jussi Saurio
198aedb042 Refactor: add 'pos_in_table' to IndexColumn for easier lookup 2025-04-15 14:47:49 +03:00
Jussi Saurio
cc8f89e8e0 Merge 'Fix Unary Negate Operation on Blobs' from Pedro Muniz
Fixing stuff that appears in Fuzz testing.
# Before
<img width="668" alt="image" src="https://github.com/user-
attachments/assets/f1f59b63-5173-4932-98b2-774803cb8a8e" />
```
limbo> EXPLAIN SELECT -x'';
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     5     0                    0   Start at 5
1     Blob               0     2     0                    0   r[2]= (len=0)
2     Multiply           3     2     1                    0   r[1]=r[3]*r[2]
3     ResultRow          1     1     0                    0   output=r[1]
4     Halt               0     0     0                    0
5     Integer            -1    3     0                    0   r[3]=-1
6     Goto               0     1     0                    0
```
# After
<img width="175" alt="image" src="https://github.com/user-
attachments/assets/9f361dc3-b243-4d69-bdd2-d6a2bbc0bf20" />
```
limbo> EXPLAIN SELECT -x'';
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     5     0                    0   Start at 5
1     Blob               0     2     0                    0   r[2]= (len=0)
2     Subtract           3     2     1                    0   r[1]=r[3]-r[2]
3     ResultRow          1     1     0                    0   output=r[1]
4     Halt               0     0     0                    0
5     Integer            0     3     0                    0   r[3]=0
6     Goto               0     1     0                    0
```
# Sqlite
```
sqlite> SELECT -x'';
0
sqlite> EXPLAIN SELECT -x'';
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     4     0                    0   Start at 4
1     Subtract       3     2     1                    0   r[1]=r[2]-r[3]
2     ResultRow      1     1     0                    0   output=r[1]
3     Halt           0     0     0                    0
4     Integer        0     2     0                    0   r[2]=0
5     Blob           0     3     0                    0   r[3]= (len=0)
6     Goto           0     1     0                    0
```

Closes #1333
2025-04-15 14:42:54 +03:00
Jussi Saurio
6463448fdc Merge 'Fix incompatibility AND Operation' from Pedro Muniz
Sqlite reference implementation: https://github.com/sqlite/sqlite/blob/8
37dc09bce7de8971c7488b70cf5da93c60fbed0/src/vdbe.c#L2558
We did not support blobs before and our ordering of the match statements
were incorrect when one of the arguments was NULL

Closes #1337
2025-04-15 14:37:29 +03:00
Jussi Saurio
57816a12f6 Merge 'Fix: comment out incorrect assert in fuzz' from Pedro Muniz
Currently, to run the fuzz test you need to remove an assert statement.
EDIT: @diegoreis42 pointed it out to me that the method had just changed
actually. Made the change to use `row.len()` instead
# Problem
```
cargo +nightly fuzz run --target=aarch64-apple-darwin expression
   Compiling limbo_core v0.0.19-pre.4 (/Users/pedro/Projects/limbo/core)
   Compiling limbo-fuzz v0.0.0 (/Users/pedro/Projects/limbo/fuzz)
error[E0599]: `&limbo_core::vdbe::Row` is not an iterator
   --> fuzz_targets/expression.rs:198:36
    |
198 |                     assert_eq!(row.count(), 1, "expr: {:?}", expr);
    |                                    ^^^^^
    |                                    |
    |                                    `&limbo_core::vdbe::Row` is not an iterator
    |                                    private field, not a method
    |
   ::: /Users/pedro/Projects/limbo/core/vdbe/mod.rs:221:1
    |
221 | pub struct Row {
    | -------------- doesn't satisfy `limbo_core::vdbe::Row: std::iter::Iterator`
    |
    = note: the following trait bounds were not satisfied:
            `&limbo_core::vdbe::Row: std::iter::Iterator`
            which is required by `&mut &limbo_core::vdbe::Row: std::iter::Iterator`
            `limbo_core::vdbe::Row: std::iter::Iterator`
            which is required by `&mut limbo_core::vdbe::Row: std::iter::Iterator`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `limbo-fuzz` (bin "expression") due to 1 previous error
Error: failed to build fuzz script: ASAN_OPTIONS="detect_odr_violation=0" RUSTFLAGS="-Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=4 -Cllvm-args=-sanitizer-coverage-inline-8bit-counters -Cllvm-args=-sanitizer-coverage-pc-table -Cllvm-args=-sanitizer-coverage-trace-compares --cfg fuzzing -Clink-dead-code -Zsanitizer=address -Cdebug-assertions -C codegen-units=1" "cargo" "build" "--manifest-path" "/Users/pedro/Projects/limbo/fuzz/Cargo.toml" "--target" "aarch64-apple-darwin" "--release" "--config" "profile.release.debug=true" "--bin" "expression"
```

Closes #1334
2025-04-15 14:36:12 +03:00
Jussi Saurio
5a38b38e71 Merge 'Feature: VDestroy for Dropping Virtual Tables' from Pedro Muniz
Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1274
2025-04-15 14:34:30 +03:00
Jussi Saurio
e0e031d8af Merge 'Fix two issues with indexes' from Jussi Saurio
Fixes #1298
- Fixes Limbo trying to use an index using a WHERE clause constraint
that refers to the same table on both sides, e.g. `WHERE t.x = t.x`
- Fixes not using indexes when the relevant expression is paren wrapped,
e.g.
    - `SELECT * FROM t WHERE (indexcol) > 5`
    - `SELECT * FROM t WHERE (indexcol > 5)`
- Changes existing table logical expr fuzz test to have primary keys
(which helped me find both issues above)

Closes #1300
2025-04-15 14:00:58 +03:00
Pere Diaz Bou
0518107443 Merge 'Feat balance shallower' from Lâm Hoàng Phúc
Fixed is_empty assertion in #1203 , but simulator still has error.
```sh
[ERROR] error Internal error: select '(engrossing_berger < X'6566651A3C70278D4E200657551D8071A1' AND competitive_petit > 1236742147.9451914)' should return no values for table 'super_becky'
```

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

Closes #1308
2025-04-15 11:02:31 +02:00
pedrocarlo
fab2ddc8cf Fix: incorrect assert in fuzz 2025-04-14 16:52:13 -03:00
pedrocarlo
53eb2204ce Fix truncation of error output in tests 2025-04-14 13:35:49 -03:00
pedrocarlo
e1ddf5ffcc Fix Unary Negate Operation on Blobs 2025-04-14 12:05:00 -03:00
TcMits
96112f8e54 missing check for balance-shallower 2025-04-14 18:30:32 +07:00
TcMits
18d779924b post validation should be after balance-shallower 2025-04-14 18:13:47 +07:00
Jussi Saurio
e07a6fc5c0 Merge 'Add Ansi Colors to tcl test runner' from Pedro Muniz
Closes #1336. I really do not like only black and white text. Have a
look in CI to see the colors

Closes #1338
2025-04-14 11:59:40 +03:00
Jussi Saurio
d20782350d Merge 'support modifiers for julianday()' from meteorgan
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1321
2025-04-14 11:52:43 +03:00
Jussi Saurio
79b08a80ab Merge 'Parse hexidecimal integers' from Anton Harniakou
Fixes #1304
Maybe I should add tests?

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

Closes #1329
2025-04-14 11:49:10 +03:00
Jussi Saurio
4b7a5f39b3 Merge 'Implement Once and OpenAutoindex opcodes' from Jussi Saurio
Some enabler work for enabling autoindexing, which means creating a
transient in memory index when a persistent index is not found. This is
used to avoid nested full table scans.
@pereman2 I added some functionality to your `SmallVec` so would
appreciate a review of those parts

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

Closes #1340
2025-04-14 11:45:41 +03:00
Jussi Saurio
23f8fffe12 Add Insn::OpenAutoindex, which is just an alias for OpenEphemeral 2025-04-14 11:23:37 +03:00
Jussi Saurio
9dadc58194 Add support for Insn::Once 2025-04-14 11:23:37 +03:00
Jussi Saurio
f79da7194f implement Iterator for SmallVec and add const generic for array size 2025-04-14 11:23:37 +03:00
Jussi Saurio
f5523e7a23 Merge pull request #1339 from tursodatabase/yeet-async-await-opcodes
refactor: fold Async/Await insns into a single instruction
2025-04-14 10:37:53 +03:00
TcMits
ee660187dc fix negative free space after balance-shallower 2025-04-14 14:25:18 +07:00
Jussi Saurio
d286a56e15 refactor: fold Async/Await insns into a single instruction 2025-04-14 09:40:20 +03:00
TcMits
b3c2593980 btree balance-shallower 2025-04-14 12:49:30 +07:00
pedrocarlo
f3a07c86a0 Add Ansi Colors to tcl test runner 2025-04-13 23:36:09 -03:00
pedrocarlo
af456513d1 Fix incompatibility AND Expression 2025-04-13 22:38:43 -03:00
pedrocarlo
6249cd67e9 added print statement to test that VDestroy is being called 2025-04-13 17:10:43 -03:00
pedrocarlo
2181de79de add destroy function to vtab 2025-04-13 17:06:12 -03:00
pedrocarlo
c0747e8064 update COMPAT.md 2025-04-13 17:06:12 -03:00
pedrocarlo
000d8756ec Implment VDestroy opcode 2025-04-13 17:06:12 -03:00
Anton Harniakou
499d9b8d45 Add integration tests for hex numbers 2025-04-13 21:50:48 +03:00
Jussi Saurio
472afdd841 Merge 'Add support for OpenEphemeral bytecode' from Diego Reis
First ~actual~ step to close #741, this time I'm following an approach
way closer to what SQLite does by just creating a normal `BTreeCursor`
and using an in-memory pager (thanks @krishvishal for the insight
🤝).

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

Closes #1139
2025-04-13 17:25:37 +03:00
Diego Reis
fd79ad2644 core/vdbe: Change is_btree to is_table in OpenEphemeral 2025-04-13 11:15:01 -03:00
Diego Reis
4c315e1bb6 core/vdbe: Update OpenEphemeral to use CreateBtreeFlags 2025-04-13 11:13:25 -03:00
Diego Reis
135330b736 core/pager: Fix page handling issue due change in wal type 2025-04-13 11:10:06 -03:00
Diego Reis
035e6dcef4 core/vdbe: Fix logic error during btree creation
I do thing we should change this 1,2 flag to 0,1 or just an enum, to be more rustacean. The current state can be very misleading
2025-04-13 11:10:06 -03:00
Diego Reis
61c324cca5 core/vdbe: Add missing work to get cursor and transient table usable 2025-04-13 11:10:06 -03:00
Diego Reis
bcac1fe778 core/vdbe: Rename page_io to db_file in OpenEphemeral 2025-04-13 11:10:06 -03:00
Diego Reis
09d83aadf3 Fix dumb conflict errors 2025-04-13 11:10:06 -03:00