Commit graph

628 commits

Author SHA1 Message Date
Anton Harniakou
9d31f5d848 Test DROP INDEX 2025-05-04 12:18:36 +03:00
Jussi Saurio
40c04c7074 Merge 'Adjust vtab schema creation to display the underlying columns' from Preston Thorpe
### The problem:
Sqlite displays the column names of the underlying vtab module when
displaying the `.schema`
![image](https://github.com/user-
attachments/assets/ca6aa1c9-0af7-4f34-a5c4-c8336fa23858)
Previously limbo omitted this, which makes it difficult for the user to
see what/how many columns the module's table has.
This matches sqlite's behavior by fetching the module's schema when the
schema entry is being inserted in translation.
![image](https://github.com/user-
attachments/assets/a56b8239-0f65-420b-a0b6-536ede117fba)

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

Closes #1168
2025-05-03 19:17:25 +03:00
Jussi Saurio
c2f30d796e Merge 'Test that DROP TABLE also deletes the related indices' from Anton Harniakou
These test were commented out, maybe they were written before CREATE
INDEX was added.

Closes #1437
2025-05-03 18:35:20 +03:00
Jussi Saurio
306e097950 Merge 'Fix bug: we cant remove order by terms from the head of the list' from Jussi Saurio
we had an incorrect optimization in `eliminate_orderby_like_groupby()`
where it could remove e.g. the first term of the ORDER BY if it matched
the first GROUP BY term and the result set was naturally ordered by that
term. this is invalid. see e.g.:
```sql
main branch - BAD: removes the `ORDER BY id` term because the results are naturally ordered by id.
However, this results in sorting the entire thing by last name only!

limbo> select id, last_name, count(1) from users GROUP BY 1,2 order by id, last_name desc limit 3;
┌──────┬───────────┬───────────┐
│ id   │ last_name │ count (1) │
├──────┼───────────┼───────────┤
│ 6235 │ Zuniga    │         1 │
├──────┼───────────┼───────────┤
│ 8043 │ Zuniga    │         1 │
├──────┼───────────┼───────────┤
│  944 │ Zimmerman │         1 │
└──────┴───────────┴───────────┘

after fix - GOOD:

limbo> select id, last_name, count(1) from users GROUP BY 1,2 order by id, last_name desc limit 3;
┌────┬───────────┬───────────┐
│ id │ last_name │ count (1) │
├────┼───────────┼───────────┤
│  1 │ Foster    │         1 │
├────┼───────────┼───────────┤
│  2 │ Salazar   │         1 │
├────┼───────────┼───────────┤
│  3 │ Perry     │         1 │
└────┴───────────┴───────────┘

I also refactored sorters to always use the ast `SortOrder` instead of boolean vectors, and use the `compare_immutable()` utility we use inside btrees too.

Closes #1365
2025-05-03 12:48:08 +03:00
Anton Harniakou
b6a5cbe626 Test that DROP TABLE also deletes the related indices 2025-05-03 12:41:19 +03:00
Preston Thorpe
d837f89d74
Merge branch 'main' into vtab_schema 2025-04-28 22:09:10 -04:00
meteorgan
eabe5e1631 temporarily comment the pragma-page-count-empty test case 2025-04-26 21:45:18 +08:00
meteorgan
f3f09a5b7b Fix pragma page_count 2025-04-26 21:45:18 +08:00
pedrocarlo
2e147b20a8 Adjustments and explicitely just emitting NoConflict on unique indexes 2025-04-24 13:13:39 -03:00
Jussi Saurio
f53448ae75 Fix bug: we cant remove order by terms from the head of the list 2025-04-24 10:34:06 +03:00
pedrocarlo
9dd1ced5ad added tests 2025-04-23 20:38:08 -03:00
Preston Thorpe
e1d9bfc792
Merge branch 'main' into bench_vfs 2025-04-22 21:36:07 -04:00
Pekka Enberg
7308f6d6e8 Merge 'Bump julian_day_converter to 0.4.5' from meteorgan
The previous version of `julian_day-converter` had precision issues,
potentially causing loss of precision when converting between
`julianday` and `datetime`
![image](https://github.com/user-
attachments/assets/84042ca3-28cc-4020-a248-714df6298791)

Reviewed-by: Diego Reis (@diegoreis42)

Closes #1344
2025-04-22 10:48:36 +03:00
PThorpe92
9bbd6a3a7f
Add vfs bench to testing pyproject.toml 2025-04-21 12:23:06 -04:00
PThorpe92
7f170756ae
Add python script to benchmark vfs against eachother 2025-04-21 12:22:20 -04:00
Jussi Saurio
83c509a613 Fix bug: left join null flag not being cleared
In left joins, even if the join condition is not matched, the system
must emit a row for every row of the outer table:

-- this must return t1.count() rows, with NULLs for all columns of t2
SELECT * FROM t1 LEFT JOIN t2 ON FALSE;

Our logic for clearing the null flag was to do it in Next/Prev. However,
this is problematic for a few reasons:

- If the inner table of the left join is using SeekRowid, then Next/Prev
  is never called on its cursor, so the null flag doesn't get cleared.
- If the inner table of the left join is using a non-covering index seek,
  i.e. it iterates its rows using an index, but seeks to the main table
  to fetch data, then Next/Prev is never called on the main table, and the
  main table's null flag doesn't get cleared.

What this results in is NULL values incorrectly being emitted for the
inner table after the first correct NULL row, since the null flag is
correctly set to true, but never cleared.

This PR fixes the issue by clearing the null flag whenever seek() is
invoked on the cursor. Hence, the null flag is now cleared on:

- next()
- prev()
- seek()
2025-04-19 13:56:52 +03:00
PThorpe92
d02900294e
Remove 2nd shell in vtab tests, fix expr translation in main loop 2025-04-17 14:01:45 -04:00
Jussi Saurio
bde808f731 Merge 'Test: write tests for file backed db' from Pedro Muniz
First attempt at closing #1212. Also with this PR, I added the option of
using `with` syntax for `TestLimboShell`. It automatically closes the
shell on error, and facilitates error handling overall. If this is
merged, I can update the other python tests to use `with` as well.

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1230
2025-04-16 11:16:18 +03:00
Jussi Saurio
913367409e Merge 'Parse hex integers 2' from Anton Harniakou
Continuation of #1329

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

Closes #1347
2025-04-16 11:13:01 +03:00
pedrocarlo
bd5531987e adjusting memory test to use UV 2025-04-15 12:51:43 -03:00
pedrocarlo
3cd2017df4 introduce test theme 2025-04-15 12:51:43 -03:00
pedrocarlo
321def3c30 adjust stack_offset for test_limbo_cli 2025-04-15 12:51:43 -03:00
pedrocarlo
4c0bd50ac9 force terminal colors 2025-04-15 12:50:35 -03:00
pedrocarlo
d71029cda7 Overhaul in printing using rich 2025-04-15 12:50:35 -03:00
pedrocarlo
b34e7e011e Prettier console 2025-04-15 12:45:46 -03:00
pedrocarlo
bdef83dc1c update test 2025-04-15 12:45:46 -03:00
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
46eaa52400 write tests for file backed db 2025-04-15 12:45:45 -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
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
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
Anton Harniakou
3c06ddadde Parse hex integers in unary operators
Unary operators ~ and - should work with hex integers
2025-04-14 21:13:39 +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
meteorgan
04cb09be2a Bump julian_day_converter to 0.4.5 2025-04-14 20:57:54 +08: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
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
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
pedrocarlo
1297cb107c bit-not and boolean-not
Co-authored-by: Diego Reis <79876389+diegoreis42@users.noreply.github.com>
2025-04-13 02:45:12 -03:00
meteorgan
8200b328d8 support modifiers for julianday() 2025-04-12 19:29:20 +08:00
Jussi Saurio
973696228a Add TCL regression test 2025-04-12 11:13:32 +03:00
Jussi Saurio
6bea4de30f Check that index seek key members are not null 2025-04-11 17:22:46 +03:00