Commit Graph

1631 Commits

Author SHA1 Message Date
Jussi Saurio
9bf5b9609f expr.rs: Binary: use translate_expr()'s impl for currently unsupported ops in translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
28ad12699f expr.rs: Unary: use shared impl in translate_expr() and translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
dc852fee8c expr.rs: Like: use shared impl in translate_expr() and translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
c6b8100d64 expr.rs: Case: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
4f384e3a02 expr.rs: Rowid: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:09 +02:00
Jussi Saurio
d91ba9573b expr.rs: Column: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:08 +02:00
Jussi Saurio
7023ffc215 expr.rs: FunctionCall: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:08 +02:00
Jussi Saurio
b93e01d59f expr.rs: Cast: call translate_expr() from translate_condition_expr() 2025-02-17 07:43:05 +02:00
Nikita Sivukhin
37e27131e3 fix inequality 2025-02-16 12:49:55 +04:00
Nikita Sivukhin
d2a507e458 add unit tests for reading integer serial types 2025-02-16 12:46:45 +04:00
Nikita Sivukhin
279652b271 extend sign for 24/48 bit width serial types 2025-02-16 12:46:18 +04:00
Nikita Sivukhin
db7544fe7a Merge branch 'tursodatabase:main' into fix-and-predicate 2025-02-15 22:57:56 +04:00
Jussi Saurio
aea8b416bc Merge 'mvcc: comments and small cleanup' from Jussi Saurio
Closes #930
2025-02-15 18:18:01 +02:00
Jussi Saurio
01f51a4c20 Merge 'Fix math binary' from Nikita Sivukhin
Fix codegen for binary functions and add fuzz test for math functions
(we need to compile `rusqlite` with `-DSQLITE_ENABLE_MATH_FUNCTIONS` in
order to bundle sqlite with math functions compiled)

Reviewed-by: Jussi Saurio (@jussisaurio)

Closes #1015
2025-02-15 18:17:08 +02:00
Jussi Saurio
cbfd77849d Merge 'Fix substr' from Nikita Sivukhin
Align `substr` implementation with SQLite spec
(https://www.sqlite.org/lang_corefunc.html#substr):
> The substr(X,Y,Z) function returns a substring of input string X that
begins with the Y-th character and which is Z characters long. If Z is
omitted then substr(X,Y) returns all characters through the end of the
string X beginning with the Y-th. The left-most character of X is number
1. If Y is negative then the first character of the substring is found
by counting from the right rather than the left. If Z is negative then
the abs(Z) characters preceding the Y-th character are returned. If X is
a string then characters indices refer to actual UTF-8 characters. If X
is a BLOB then the indices refer to bytes.

Reviewed-by: Jussi Saurio (@jussisaurio)

Closes #1013
2025-02-15 18:16:57 +02:00
Nikita Sivukhin
ee8b03528d fix codegen for and predicate - as jump_if_condition_is_true can be overwritten higher in the stack 2025-02-15 16:27:27 +04:00
Jussi Saurio
e4541edb48 Fix IdxGt,IdxGe,IdxLt,IdxLe instructions
According to SQLite documentation, the way to use these instructions
is to compare the seek key to the index key as you would with the
Compare opcode. The compare opcode states:

"Compare two vectors of registers in reg(P1)..reg(P1+P3-1)
(call this vector "A") and in reg(P2)..reg(P2+P3-1) ("B")."

In other words, we should compare the same number of columns from each,
not compare the entire keys.

This fixes a few Clickbench queries returning incorrect results, and
so closes #1009

---

Future work: support index seek keys that use multiple columns. Our
index seek is many times slower than SQLite because we're not utilizing
all the possible columns -- instead we just use the first index column
to seek.
2025-02-15 12:44:56 +02:00
Nikita Sivukhin
e25660833b fix codegen for binary functions 2025-02-15 14:33:57 +04:00
Nikita Sivukhin
91d723016d fix test 2025-02-15 13:29:14 +04:00
Nikita Sivukhin
b35dab5b6d fix substr implementation 2025-02-15 13:21:43 +04:00
Pekka Enberg
30f700174c Merge 'Added IdxLE and IdxLT opcodes' from Omolola Olamide
I added the two opcodes as an initial step. They are pretty easy to
implement since we already have the counterparts i.e., IdxGE and IdxGT
Is there a design reason behind their omission @penberg @PThorpe92?
I noticed the same for SeekLE and SeekLT.

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

Closes #1010
2025-02-15 11:10:17 +02:00
Pekka Enberg
20e37e485a Merge 'Implement the legacy_file_format pragma' from Glauber Costa
easy implementation, sqlite claims it is a noop now
"This pragma no longer functions. It has become a no-op. The
capabilities formerly provided by PRAGMA legacy_file_format are now
available using the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option to the
sqlite3_db_config() C-language interface."

Closes #1007
2025-02-15 11:03:05 +02:00
Pekka Enberg
c53897cb6c Merge 'Support numeric column references in GROUP BY' from Jussi Saurio
We already supported this for ORDER BY but not GROUP BY - again noticed
this when running against some clickbench queries

Closes #1008
2025-02-15 11:02:28 +02:00
[B
e52f218136 fix format 2025-02-14 21:10:51 +01:00
[B
5214cf9859 Added IdxLE and IdxLT opcodes 2025-02-14 20:22:30 +01:00
Jussi Saurio
eca196a54b Support numeric column references in GROUP BY 2025-02-14 16:57:45 +02:00
Glauber Costa
fbe439f6c2 Implement the legacy_file_format pragma
easy implementation, sqlite claims it is a noop now

"This pragma no longer functions. It has become a no-op. The capabilities
formerly provided by PRAGMA legacy_file_format are now available using
the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option to the sqlite3_db_config()
C-language interface."
2025-02-14 09:50:29 -05:00
Jussi Saurio
a7300a4e0c select: fix bug with referring to a mixed-case alias 2025-02-14 16:40:58 +02:00
Pekka Enberg
a302828376 core/transalte: Fix invalid sqlite3_parser import 2025-02-14 12:27:57 +02:00
Pekka Enberg
43574528c9 Merge 'Switch to workspace dependencies' from Pekka Enberg
...makes it easier to specify a version, which is needed for `cargo
publish`.

Closes #991
2025-02-14 12:21:24 +02:00
Pekka Enberg
64cdfd829e Merge 'core/translate: BEGIN EXCLUSIVE support' from Pekka Enberg
After reading the fine print, SQLite documentation explains that `BEGIN
IMMEDIATE` and `BEGIN EXCLUSIVE` are the same thing in WAL mode:
https://www.sqlite.org/lang_transaction.html
As that's the only mode we support, let's just add code generation for
`BEGIN EXCLUSIVE`.
Fixes #1002

Closes #1003
2025-02-14 12:20:22 +02:00
Pekka Enberg
e3925c4531 core/vdbe: Fix Program::halt() to respect autocommit state 2025-02-14 12:11:37 +02:00
Pekka Enberg
76bdbb54ef core/translate: BEGIN EXCLUSIVE support
After reading the fine print, SQLite documentation explains that `BEGIN
IMMEDIATE` and `BEGIN EXCLUSIVE` are the same thing in WAL mode:

https://www.sqlite.org/lang_transaction.html

As that's the only mode we support, let's just add code generation for
`BEGIN EXCLUSIVE`.

Fixes #1002
2025-02-14 11:52:18 +02:00
Pekka Enberg
ae3c6b7ec5 core/vdbe: Fix AutoCommit instruction to halt the VM
Pointed out by Jussi
2025-02-14 11:43:16 +02:00
Pekka Enberg
948585bb42 core/vdbe: Extract Program::halt() helper
We need this for AutoCommit opcode too.
2025-02-14 11:42:24 +02:00
Pekka Enberg
5626ca450f core/translate: COMMIT support
```
limbo> EXPLAIN COMMIT;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     3     0                    0   Start at 3
1     AutoCommit         1     0     0                    0   auto_commit=true, rollback=false
2     Halt               0     0     0                    0
3     Goto               0     1     0                    0
```
2025-02-14 10:26:55 +02:00
Pekka Enberg
9fff9f6081 core/translate: BEGIN IMMEDIATE support
Emit the following code sequence for `BEGIN IMMEDIATE`:

```
limbo> EXPLAIN BEGIN IMMEDIATE;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     4     0                    0   Start at 4
1     Transaction        0     1     0                    0
2     AutoCommit         0     0     0                    0   auto_commit=false, rollback=false
3     Halt               0     0     0                    0
4     Goto               0     1     0                    0
```

Please note that SQLite emits *two* transaction instructions -- one for
main database and one for temporary tables. However, since we don't
support the latter, we only emit one transaction instruction.
2025-02-14 10:26:31 +02:00
Pekka Enberg
34b0c7c09a core/vdbe: AutoCommit instruction 2025-02-14 10:26:31 +02:00
Pekka Enberg
ac54c35f92 Switch to workspace dependencies
...makes it easier to specify a version, which is needed for `cargo publish`.
2025-02-12 17:28:04 +02:00
Pekka Enberg
01671d1d1e Merge 'Performance improvements for Unix I/O backend' from Preston Thorpe
This PR reworks the unix I/O backend, removing runtime reference
counting/borrow checking and optimizing away the hashmap in favor of a
static array, with an unlikely fallback vec.
The only reason the fallback vec is there is because unlike the
`io_uring` module, we cannot simply index into the array with the fd  as
the OS could theoretically give us a fd up to I believe 1024 so keeping
an array of that size for a few elements is unnecessary.

Closes #940
2025-02-12 09:29:41 +02:00
Pekka Enberg
e4d4e5cd5d Merge 'Streamline dependencies to build for all wasm targets' from Doug A
In order [experimentally
compile](https://github.com/DougAnderson444/wit-limbo) `limbo_core` to a
[wasm component](https://component-model.bytecodealliance.org/), limbo
needed to have no reliance on `js`, `js-sys`, `wasm-bindgen`, et al.
(for those who aren't familiar, there are many `wasm` runtimes and not
all of them play nice with `wasm-bindgen`)
This PR simply cleans up the dependencies, and puts them behind optional
flags and whatnot in order to enable this. Both `log` and `tracing` were
being used, so I reduced this only to `tracing`.
End result is limbo can be used like this:
https://github.com/DougAnderson444/wit-limbo
We can open a discussion on the possibilities that running limbo as a
wasm component can offer, including potentially using composable
components to implement the sqlite runtime extensions, as well as giving
us a clean interface for PlatformIO operations -- define them once,
implement many ways on various platforms. I'm new to limbo, but it looks
like current extension are Rust based deps and features flags, whereas
sqlite is runtime, right? What if limbo was runtime extensible too?
The WIT interface is largely sync (though I believe wasmtime has an
async feature), but in my limited exposure to limbo so far a lot of the
wasm seems sync already anyway. Again, topic for further discussion.
Suffice to say, aligning these deps in this way paves the road for
further experiments and possibilities.
Related: https://github.com/neilg63/julian_day_converter/pull/2
Related: https://github.com/tursodatabase/limbo/issues/950
Closes: https://github.com/tursodatabase/limbo/issues/950

Closes #983
2025-02-12 09:24:04 +02:00
PThorpe92
e3ab80ae28 Replace Option with MaybeUninit in unix IO 2025-02-11 09:09:49 -05:00
PThorpe92
9098237a12 Add as_read method to completion enum 2025-02-11 09:09:47 -05:00
PThorpe92
975cf95c37 Reformat unix io with wrappers for unsafecell 2025-02-11 09:06:49 -05:00
PThorpe92
159e2fbd71 Remove rc refcell in unix io module 2025-02-11 09:01:57 -05:00
Doug Anderson444
2566577b70 libc dep only when io_uring feature 2025-02-11 09:06:26 -04:00
Doug Anderson444
39c3b135e3 make all serde optional
to reduce dep size
2025-02-11 09:05:34 -04:00
Doug Anderson444
0aa5de6d9f rm log, switch all to tracing 2025-02-11 09:03:36 -04:00
wyhaya
351a032cc1 core: Add default column name 2025-02-11 07:03:51 +00:00
Doug Anderson444
3734870c6b rm old julian dep 2025-02-10 22:00:18 -04:00