Commit graph

220 commits

Author SHA1 Message Date
Pekka Enberg
227c979882 extensions/tests: Allow use of unwrap()
They're tests, it's fine.
2025-11-21 14:11:53 +02:00
Pekka Enberg
dcaf6f88d0 extensions: Replace unwrap() with expect() in fuzzy extension 2025-11-21 14:11:53 +02:00
Pekka Enberg
f044e39d43 extensions: Eliminate unwrap() in fuzzy extension 2025-11-21 14:11:53 +02:00
Pekka Enberg
cae17e7a36 extensions: Eliminate unwrap() call in csv extension 2025-11-21 14:11:53 +02:00
Pekka Enberg
deeb79c80e extensions: Eliminate unwrap() in crypto extension 2025-11-21 14:11:53 +02:00
Pekka Enberg
eb07a5164b extensions: Improve error handling in percentile extension
Eliminate unwrap() where we can, replace with expect() where we can't.
2025-11-21 14:11:53 +02:00
Pekka Enberg
96e63b4556 extensions: Replace unwrap() with expect() in get_column_names()
...error handling would be better here.
2025-11-21 14:11:53 +02:00
Pekka Enberg
582cc057ce extensions: Eliminate unwrap() in IndexInfo::to_ffi() 2025-11-21 14:11:53 +02:00
Pekka Enberg
23859ec6ef extensions: Replace unwrap() with expect() in generate_random_number()
Propagating the error would be even better, of course.
2025-11-21 14:11:53 +02:00
PThorpe92
8bef159582
adjust testing extension to add some test assertions for new features 2025-11-09 11:07:43 -05:00
PThorpe92
e09d9eb720
Add VBegin, VRename, VRollback and VCommit opcodes 2025-11-09 11:07:42 -05:00
danawan
468046c654 translit and script 2025-09-26 15:20:27 +07:00
danawan
189caa5d5d rsoundex 2025-09-25 16:10:34 +07:00
danawan
54a95a0b55 add caverphone 2025-09-25 10:25:12 +07:00
danawan
815f0ffe25 add phonetic and soundex 2025-09-24 13:58:19 +07:00
danawan
48ec200c17 clippy 2025-09-23 13:11:42 +07:00
danawan
16b706a8d4 add sqlean fuzzy string distances 2025-09-23 11:49:41 +07:00
Pekka Enberg
d7977c25a8 core/vtab: Mark VTabModuleImpl as Send and Sync 2025-09-17 11:48:42 +03:00
pedrocarlo
3c91ae206b move as many dependencies as possible to workspace to avoid multiple versions of the same dependency 2025-09-15 17:19:36 -03:00
Nikita Sivukhin
c771487933 add remove_file method to the IO 2025-08-21 14:51:02 +04: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
Preston Thorpe
64c83237b9
apply copilot review doc comment
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-14 16:09:25 -04:00
PThorpe92
95d448d9af
Actually defer callbacks till run_once in test extension 2025-08-13 21:42:19 -04:00
PThorpe92
1bf74970bc
Update test extension to new callback api 2025-08-13 21:42:19 -04:00
PThorpe92
20bf9ee2be
Update vfs extension to support IO callbacks 2025-08-13 21:38:21 -04:00
Pedro Muniz
c08d23b10d
Update extensions/core/README.md
Co-authored-by: Preston Thorpe <preston@unlockedlabs.org>
2025-08-08 01:01:06 -03:00
pedrocarlo
edae65fb5f global allocator should not be set for library, only for executables 2025-08-07 13:41:50 -03:00
PThorpe92
6cc5c66964
Remove useless close method on extension Connection 2025-08-06 16:46:44 -04:00
bit-aloo
e92fdfca9f
refactir regexp replace 2025-08-05 20:53:24 +05:30
bit-aloo
db17a195f3
refactor regexp capture 2025-08-05 20:48:47 +05:30
bit-aloo
20d4da7054
register regexp_capture with register_extension 2025-08-05 20:19:48 +05:30
bit-aloo
0fcb302d8f
add regexp_capture 2025-08-05 20:18:14 +05:30
Piotr Rzysko
59ec2d3949 Replace ConstraintInfo::plan_info with ConstraintInfo::index
The side of the binary expression no longer needs to be stored in
`ConstraintInfo`, since the optimizer now guarantees that it is always
on the right. As a result, only the index of the corresponding constraint
needs to be preserved.
2025-08-05 05:48:29 +02:00
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
61234eeb19 Add ResultCode to best_index result
The `best_index` implementation now returns a ResultCode along with the
IndexInfo. This allows it to signal specific outcomes, such as errors or
constraint violations. This change aligns better with SQLite’s xBestIndex
contract, where cases like missing constraints or invalid combinations of
constraints must not result in a valid plan.
2025-08-04 20:18:44 +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
Piotr Rzysko
c465ce6e7b Clarify semantics of argv_index
Extend the documentation of `argv_index` and add validations enforcing
the requirements it must meet.
2025-08-04 19:31:18 +02:00
Piotr Rzysko
b0460a589f Ensure argv_index is either None or >= 1
Previously, there were two ways to indicate that a constraint should not
be passed to the filter function: setting `argv_index` to `None` or to
a value less than 1. This was redundant, so now only `None` is used.
2025-08-04 19:27:53 +02:00
Piotr Rzysko
c6f398122d Add validation for constraint usage length returned by best_index
Additional changes:
- Update IndexInfo documentation to clarify that constraint_usages must
  have exact 1:1 correspondence with input ConstraintInfo array. The code
  translating constraints into VFilter arguments heavily relies on this.
- Fix best_index implementation in test extension to comply with new
  validation requirements by returning usage entry for each constraint
2025-08-04 19:25:10 +02:00
PThorpe92
d30157518f Impl truncate method for VFS io module and create plumbing in extension lib 2025-07-30 13:48:05 +03:00
Diego Reis
bab10909c3 Disable extension loading for wasm
We should enable it later when wasm become more mature
2025-07-28 14:49:07 -03:00
PThorpe92
d7c3256a5a
Update vtab derive macro to pass readonly const to module impl 2025-07-23 16:59:18 -04:00
PThorpe92
e7ce3efb3f
Remove default trait impl from csv extension 2025-07-23 16:50:57 -04:00
PThorpe92
eff455fb03
Add READONLY const property to virtual table module trait 2025-07-23 16:44:04 -04:00
Jussi Saurio
022f679fab chore: make every CREATE TABLE stmt in entire repo have 1 space after tbl name
`BTreeTable::to_sql` makes us incompatible with SQLite by losing e.g. the original whitespace provided during the CREATE TABLE command.

For now let's fix our tests by regex-replacing every CREATE TABLE in
the entire repo to have exactly 1 space after the table name in the
CREATE TABLE statement.
2025-07-22 11:35:21 +03:00
Nils Koch
f032de3d63
chore: link advapi32 on windows 2025-07-16 19:34:42 +01:00
Pekka Enberg
f72ceaf177 Merge 'extensions/vtab: fix i32 being passed as i64 across FFI boundary' from Jussi Saurio
as nilskch points out in #1807, Rust 1.88.0 is stricter about alignment
checks.
because rust integers default to `i32`, we were casting a pointer to an
`i32` as a pointer to an `i64` causing a panic when dereferenced due to
misalignment as rust expects it to be 8 byte aligned.

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #2064
2025-07-16 08:28:24 +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
631d62e9f8 Implement best_index for table-valued functions
In SQLite, the field equivalent to `constraint_usage` (`aConstraintUsage`
from `sqlite3_index_info`) is used to request arguments that are later
passed to the `xFilter` method. In Limbo, this behavior applies to
virtual tables, but not to table-valued functions. Currently, TVFs have
dedicated handling that passes all function arguments to the filter
method and doesn't use information provided in the `constraint_usage`
field.

This commit is a step toward unifying the handling of virtual tables and
TVFs.
2025-07-14 07:16:53 +02:00