Commit Graph

111 Commits

Author SHA1 Message Date
Piotr Rzysko
d1a91a63e6 Extract TVF-related tests to TCL
These tests verify interactions between the database engine and TVFs.
They happen to use generate_series, but they are not intended to test
the behavior of any specific extension. Tests that verify generate_series
specific behavior remain in extensions.py.
2025-08-15 21:06:30 +02:00
Piotr Rzysko
20ea079679 Add framework for testing extensions in TCL
There is a distinction between tests that verify extension-specific
behavior and tests that verify interactions between the database engine
and extensions. Previously, both types of tests were kept in extensions.py.
With this new framework, we can extract the latter type of tests from
extensions.py into TCL. This cleans up extensions.py and provides
compatibility testing with SQLite at no extra cost.

To demonstrate the framework’s usage, tests verifying the handling of
virtual tables were extracted to TCL.

In the future, we may consider moving extension-specific tests to TCL as
well, especially those that have counterparts in SQLite or sqlean.
2025-08-15 21:06:27 +02:00
PThorpe92
6d7b660dd4 Adjust test for .clone method 2025-08-14 21:31:14 -04:00
PThorpe92
ae22af29cd Fix pragma module list tests 2025-08-11 12:13:47 -04:00
Lucas Forato
673cfdbc0f test: include tests in extensions.py 2025-08-11 08:42:08 -03:00
PThorpe92
b131331673 Add shell .py tests for .clone cli command 2025-08-07 16:27:08 -04:00
Preston Thorpe
f55d34a3db Merge 'Fix panic on loading extension on brand new connection' from Preston Thorpe
Closes #2476

Closes #2477
2025-08-06 23:44:38 -04:00
PThorpe92
ae99edf4a6 Adjust test to test for behavior of loading extension on brand new connection 2025-08-06 16:55:54 -04:00
bit-aloo
84316d9206 fix python lint 2025-08-06 12:02:20 +05:30
bit-aloo
b26a58f652 update extension.py with regexp_replace test 2025-08-05 20:36:09 +05:30
Piotr Rzysko
99f87c07c1 Support column references in table-valued function arguments
This change extends table-valued function support by allowing arguments
to be column references, not only literals.

Virtual tables can now reject a plan by returning an error from
best_index (e.g., when a TVF argument references a table that appears
later in the join order). The planner using this information excludes
invalid plans during join order search.
2025-08-05 05:48:28 +02:00
Piotr Rzysko
82491ceb6a Integrate virtual tables with optimizer
This change connects virtual tables with the query optimizer.
The optimizer now considers virtual tables during join order search
and invokes their best_index callbacks to determine feasible access
paths.

Currently, this is not a visible change, since none of the existing
extensions return information indicating that a plan is invalid.
2025-08-05 05:48:28 +02:00
Piotr Rzysko
6a4cf02a90 Fix computation of argv_index in best_index
The `filter` methods for extensions affected by this fix expect arguments
to be passed in a specific order. For example, `generate_series` assumes
that if the `start` argument exists, it is always passed to `filter`
first. If `start` does not exist, then `stop` is passed first — but
`stop` must never come before `start`.

Previously, this was not guaranteed: `best_index` relied on constraints
being passed in the order matching `filter`'s expectations.
2025-08-04 19:38:45 +02:00
PThorpe92
28283e4d1c Fix bench_vfs python script to use fresh db for each run 2025-07-30 19:42:52 -04:00
PThorpe92
efcffd380d Clean up io_uring writev implementation, add iovec and cqe cache 2025-07-30 19:42:52 -04:00
PThorpe92
d189f66328 Add pwritev to wasm/js api 2025-07-30 19:42:48 -04:00
Iaroslav Zeigerman
6f63327320 fix overlooked tests 2025-07-26 04:51:44 -07:00
PThorpe92
3358e85889 Update py tests for new error msg 2025-07-23 17:05:46 -04:00
Pekka Enberg
8e98c33fce Ruff you are an idiot 2025-07-17 21:51:34 +03:00
Pekka Enberg
d11a8063f0 testing: Format mvcc.py to make ruff happy... 2025-07-17 21:39:08 +03:00
Pekka Enberg
458dd815ac testing: Add MVCC test suite 2025-07-17 16:23:31 +03:00
Jussi Saurio
cc47bfba02 CSV import fixes
- Fix not being able to create table while importing
    * The behavior now aligns with SQLite so that if the table already
      exists, all the rows are treated as data. If the table doesn't exist,
      the first row is treated as the header from which column names for the
      new table are populated.
- Insert in batches instead of one at a time
2025-07-15 16:44:11 +03:00
Piotr Rzysko
30ae6538ee Treat table-valued functions as tables
With this change, the following two queries are considered equivalent:
```sql
SELECT value FROM generate_series(5, 50);
SELECT value FROM generate_series WHERE start = 5 AND stop = 50;
```
Arguments passed in parentheses to the virtual table name are now
matched to hidden columns.

Column references are still not supported as table-valued function
arguments. The only difference is that previously, a query like:
```sql
SELECT one.value, series.value
FROM (SELECT 1 AS value) one, generate_series(one.value, 3) series;
```
would cause a panic. Now, it returns a proper error message instead.

Adding support for column references is more nuanced for two main
reasons:
- We need to ensure that in joins where a TVF depends on other tables,
those other tables are processed first. For example, in:
```sql
SELECT one.value, series.value
FROM generate_series(one.value, 3) series, (SELECT 1 AS value) one;
```
the one table must be processed by the top-level loop, and series must
be nested.
- For outer joins involving TVFs, the arguments must be treated as ON
predicates, not WHERE predicates.
2025-07-14 07:16:53 +02:00
Piotr Rzysko
44b1b1852a Fix referencing virtual table predicates
We need to enumerate first and filter afterward — not the other way
around — because we later use the indexes produced by `enumerate` to
access the original `predicates` slice.
2025-07-14 07:16:53 +02:00
Piotr Rzysko
319cdbe3af Don't use search for virtual tables
Previously, the test queries added in this commit would fail with:
thread 'main' panicked at core/schema.rs:129:34:
not implemented
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: limbo_core::schema::Table::get_root_page
             at ./core/schema.rs:129:34
   4: limbo_core::translate::main_loop::init_loop
             at ./core/translate/main_loop.rs:260:44
   5: limbo_core::translate::emitter::emit_query
             at ./core/translate/emitter.rs:568:5
   6: limbo_core::translate::emitter::emit_program_for_select
             at ./core/translate/emitter.rs:496:5
   7: limbo_core::translate::emitter::emit_program
             at ./core/translate/emitter.rs:187:31
   8: limbo_core::translate::select::translate_select
             at ./core/translate/select.rs:82:5
   9: limbo_core::translate::translate_inner
             at ./core/translate/mod.rs:241:13
  10: limbo_core::translate::translate
             at ./core/translate/mod.rs:95:17
  11: limbo_core::Connection::run_cmd
             at ./core/lib.rs:416:31
  12: <limbo_core::QueryRunner as core::iter::traits::iterator::Iterator>::next
             at ./core/lib.rs:916:22
  13: limbo::app::Limbo::run_query
             at ./cli/app.rs:442:27
  14: limbo::app::Limbo::handle_input_line
             at ./cli/app.rs:544:13
  15: limbo::main
             at ./cli/main.rs:51:31
  16: core::ops::function::FnOnce::call_once
2025-07-14 07:16:53 +02:00
Piotr Rzysko
000d70f1f3 Propagate info about hidden columns 2025-07-14 07:16:53 +02:00
Jussi Saurio
f312227825 uv run ruff format && uv run ruff check --fix 2025-07-09 10:06:29 +03:00
Pekka Enberg
b895381ae6 Revert "Merge 'Reachable assertions in Antithesis Python Test for better logging' from Pedro Muniz"
This reverts commit dbbc3f5190, reversing
changes made to 1cd5a49705. We're missing
some mandatory parameters, causing these to fail under Antithesis.
2025-07-08 17:51:12 +03:00
pedrocarlo
e9361c0eba add more logging to antithesis tests
format python tests
2025-07-07 19:11:55 -03:00
pedrocarlo
81f80edd4a remove experimental_flag from script + remove -q flag default flag from TestTursoShell 2025-07-07 15:34:03 -03:00
Pekka Enberg
7f91768ff6 core/translate: Unify no such table error messages
We're now mixing different error messages, which makes compatibility
testing pretty hard. Unify on a single, SQLite compatible error message
"no such table".
2025-07-07 11:10:46 +03:00
pedrocarlo
c5bed21dff fix python test import naming 2025-07-03 02:15:08 -03:00
PThorpe92
0d80e3a21b Fix naming and ruff format check 2025-07-02 11:02:32 -04:00
PThorpe92
297cbbf726 Rename Limbo -> Turso in python tests 2025-07-02 10:57:46 -04:00
PThorpe92
2bbfe15ec1 Add readonly python test 2025-06-30 22:04:56 -04:00
Pekka Enberg
eb0de4066b Rename limbo_ext crate to turso_ext 2025-06-29 12:14:08 +03:00
PThorpe92
b655ac8267 Remove tests that dynamically load generate_series extension 2025-06-27 09:50:15 -04:00
Piotr Rzysko
dda1ee86e2 Fix ruff errors 2025-06-21 19:32:16 +02:00
Jussi Saurio
d0f9df1f97 Merge 'Improve extension compatibility testing' from Piotr Rżysko
Extracted from https://github.com/tursodatabase/limbo/pull/1727.

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1741
2025-06-21 19:09:33 +03:00
pedrocarlo
80ccca8827 ruff lint fix 2025-06-20 15:59:03 -03:00
Pere Diaz Bou
871eee109f test_limbo_cli use SQLITE_EXEC if possible 2025-06-17 21:26:32 +02:00
Piotr Rzysko
9d54d9baf5 Add compatibility test for generate_series 2025-06-14 05:26:11 +02:00
Piotr Rzysko
c4fa715036 Add test SQLite KV extension
This extension mimics Limbo's kv_store and is used in tests to verify
that Limbo and SQLite handle extensions in a compatible way.
2025-06-14 05:26:10 +02:00
pedrocarlo
3e05496078 add integrity check to write tests 2025-06-09 17:44:00 -03:00
pedrocarlo
c7799c8ec5 add sleep to allow file lock to be removed 2025-06-09 16:29:58 -03:00
Pekka Enberg
c6ef19396d Merge 'Add support for pragma table-valued functions' from Piotr Rżysko
This PR adds support for table-valued functions for PRAGMAs (see the
[PRAGMA functions section](https://www.sqlite.org/pragma.html)).
Additionally, it introduces built-in table-valued functions. I
considered using extensions for this, but there are several reasons in
favor of a dedicated mechanism:
* It simplifies the use of internal functions, structs, etc. For
example, when implementing `json_each` and `json_tree`, direct access to
internals was necessary:
https://github.com/tursodatabase/limbo/pull/1088
* It avoids FFI overhead. [Benchmarks](https://github.com/piotrrzysko/li
mbo/blob/pragma_vtabs_bench/core/benches/pragma_benchmarks.rs) on my
hardware show that `pragma_table_info()` implemented as an extension is
2.5× slower than the built-in version.

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

Closes #1642
2025-06-04 09:08:10 +03:00
Piotr Rzysko
d1d8ead475 Add support for pragma table-valued functions 2025-06-01 10:25:42 +02:00
pedrocarlo
2ddbb7eeed adjust move_to and seek functions to make them truly reentrant + adding return_if_locked_maybe_load in some places so that we read loaded pages 2025-06-01 01:01:35 -03:00
pedrocarlo
d688cfd547 make find_cell and process_overflow_page reentrant 2025-05-31 23:31:59 -03:00
pedrocarlo
e97227ccb9 added delete operations to blobs in memory and write tests 2025-05-31 14:47:49 -03:00