Commit Graph

1894 Commits

Author SHA1 Message Date
Levy A.
08c8c655e9 feat: initial implementation of Statement::bind 2025-01-15 16:51:04 -03:00
Pekka Enberg
b589203fea Merge 'Fix MustBeInt opcode semantics' from Vrishabh
In sqlite3 , we can create primary key with only integer column and
during insert we can pass any value which can be parsed into integer as
shown below. When I tried the same with limbo, it failed. The cause of
this was due to MustBeInt opcode behaviour not aligned with sqlite. This
PR aims to fix it.
Sqlite output
```
SQLite version 3.45.3
sqlite> create table temp (t1 integer, primary key (t1));
sqlite> insert into temp values (1),(2.0),('3'),('4.0');
sqlite> select * from temp;
1
2
3
4
```
Limbo output main branch
```
limbo>     create table temp (t1 integer, primary key (t1));
limbo>     insert into temp values (1),(2.0),('3'),('4.0');
Parse error: MustBeInt: the value in the register is not an integer
limbo>     select * from temp;
1
```
Limbo output with this PR
```
limbo> create table temp (t1 integer, primary key (t1));
limbo> insert into temp values (1),(2.0),('3'),('4.0');
limbo> select * from temp;
1
2
3
4
```

Closes #706
2025-01-15 21:14:54 +02:00
psvri
845de125db Align MustBeInt logic with sqlite 2025-01-16 00:09:45 +05:30
Pekka Enberg
f7af8150d2 Merge 'Simulator: show inner error if any' from Jussi Saurio
Seed 16184573510628167771 in git hash 7c549bc produces a missing row
error, but the underlying error is `Parse error: table
breathtaking_dimitrakis not found`, which was not obvious without
exposing the error in the message the simulator prints on assertion
failure.
This PR just exposes the inner error, if any.

Closes #704
2025-01-15 19:45:49 +02:00
Jussi Saurio
0f4cc8f0cc Simulator: expose inner error in assertion failure, if any 2025-01-15 19:22:05 +02:00
Pekka Enberg
bdc06f2d66 Merge 'Implement ShiftRight' from Vrishabh
This PR adds support for ShiftRight operator and Opcode.

Closes #703
2025-01-15 18:53:23 +02:00
Pekka Enberg
c01c80baee Merge 'Run all statements from sql argument in cli' from Vrishabh
When we had multiple sql statements in cli/interactive shell, we were
only running one from them as  shown below. This PR fixes them.
One added benefit of this is we can add complex sql in the tcl test
files like the changes in insert.test .
sqlite3 output
```
❯ sqlite3  :memory: "select 1;select 2"
1
2
```
Limbo main branch output
```
❯ ./target/debug/limbo.exe :memory: "select 1;select 2;"
1
```
Limbos output with this PR
```
❯ ./target/debug/limbo.exe :memory: "select 1;select 2;"
1
2
```

Reviewed-by: Preston Thorpe <cory.pride83@gmail.com>

Closes #673
2025-01-15 18:44:17 +02:00
Pekka Enberg
7c549bc978 Merge 'Expr: fix recursive binary operation logic' from Jussi Saurio
I believe this closes #682
```
limbo> CREATE TABLE proficient_barrett (imaginative_etrebilal BLOB,lovely_wilson BLOB);
INSERT INTO proficient_barrett VALUES (X'656E67726F7373696E675F636861636F', X'776F6E64726F75735F626F75726E65');
limbo> SELECT * FROM proficient_barrett
WHERE (
    (
        (
            (
                imaginative_etrebilal != X'6661766F7261626C655F636F726573'
                OR
                (imaginative_etrebilal > X'656E67726F7373696E675F6368616439')
            )
            AND
            (
                imaginative_etrebilal = X'656E676167696E675F6E6163696F6E616C'
                OR
                TRUE
            )
        )
        OR
        FALSE
    )
    AND
    (
        imaginative_etrebilal > X'656E67726F7373696E675F63686164F6'
        OR
        TRUE
    )
);
engrossing_chaco|wondrous_bourne
```
@PThorpe92 I don't think we need the `parent_op` machinery at all, we
just need to not jump to the `jump_target_when_true` label given by the
parent if we are evaluating the first condition of an AND.
related: https://github.com/tursodatabase/limbo/pull/633

Reviewed-by: Preston Thorpe <cory.pride83@gmail.com>

Closes #698
2025-01-15 18:32:59 +02:00
Pekka Enberg
4fafaba607 simulator: Reduce generated sequence size defaults
...otherwise the simulator runs forever...
2025-01-15 18:32:03 +02:00
psvri
d3f28c51f4 Implement ShiftRight 2025-01-15 21:21:51 +05:30
Pekka Enberg
519ba75642 Merge 'Implement ShiftLeft' from Vrishabh
This PR adds support for ShiftLeft operator and Opcode.

Closes #701
2025-01-15 17:14:19 +02:00
psvri
5b4d82abbf Implement ShiftLeft 2025-01-15 18:54:07 +05:30
psvri
9cc9577c91 Run all statements from sql argument in cli 2025-01-15 18:19:39 +05:30
Jussi Saurio
84ef8a8951 translate_condition_expr(): unify how the AND and OR cases look 2025-01-15 14:24:40 +02:00
Jussi Saurio
f8b3b06163 Expr: fix recursive binary operation logic 2025-01-15 14:12:08 +02:00
Pekka Enberg
ffe65140c1 Merge 'simulator: add counterexample minimization' from Alperen Keleş
This PR introduces counterexample minimization(shrinking) in the
simulator. It will require changes to the current structure in various
places, so I've opened it as a draft PR for now, in order to not
overwhelm the reviewers all at once.
- [x] Turn interactions plans into sequences of properties instead of
sequences of interactions, adding a semantic layer.
- [x] Add assumptions to the properties, rendering a property invalid if
its assumptions are not valid.
- [x] Record the failure point in a failing assertion, as shrinking by
definition works when the same assertion fails for a smaller input.
- [ ] Add shrinking at three levels,
  - [x] top level(removing whole properties),
  - [x] property level(removing interactions within properties),
  - [ ] interaction level(shrinking values in interactions to smaller
ones).
- [ ] Add [marauders](https://github.com/alpaylan/marauders) as a dev
dependency, inject custom mutations to a testing branch for evaluating
the simulator performance.
- [ ] Integrate the simulator evaluation with the CI.

Closes #623
2025-01-15 13:12:17 +02:00
alpaylan
ea6ad8d414 remove debug print 2025-01-15 12:44:43 +03:00
alpaylan
c446e29a50 add missed updates from the merge 2025-01-15 11:42:48 +03:00
alpaylan
ecb0f782ac Merge branch 'main' of https://github.com/tursodatabase/limbo 2025-01-15 10:59:46 +03:00
Pekka Enberg
d0b5f50f2f Merge 'Replace scalar function declaration in extension API with proc macro' from Preston Thorpe
Per @penberg's suggestion on Discord, the `declare_scalar_functions!`
declarative macro has been replaced with a procedural one, allowing for
a much nicer API.
```rust
#[export_scalar]
#[args(0)]
fn uuid4_blob(_args: &[Value]) -> Value {
    let uuid = uuid::Uuid::new_v4();
    let bytes = uuid.as_bytes();
    Value::from_blob(bytes.to_vec())
}
```

Closes #687
2025-01-15 09:15:13 +02:00
Pekka Enberg
ca2333d0c4 Merge 'Add load_extension function, resolve shared lib extensions' from Preston Thorpe
This PR adds the `load_extension` function, and allows for platform
agnostic arguments: e.g. `select
load_extension('target/debug/liblimbo_uuid');` omitting the file
extension.

Closes #680
2025-01-15 09:14:34 +02:00
Pekka Enberg
d1b05ac6e9 Merge 'java/bindings: Add support for creating statement ' from Kim Seon Woo
## Purpose of this PR
- Add support for `createStatement` in `JDBC4Connection`
- Following works can use this statement to execute queries
## Changes
- Implement `createStatement` for `JDBC4Connection`
- Add `JDBC4Statement`
## References
- https://github.com/tursodatabase/limbo/issues/615

Closes #693
2025-01-15 09:09:42 +02:00
김선우
d151824f66 Update JDBC4Statement to include resultSetType, resultSetConcurrency, resultSetHoldability 2025-01-15 09:46:42 +09:00
김선우
7104a290e4 Basic support for close method 2025-01-15 09:20:44 +09:00
김선우
e5bf3c2644 Add Codes.java 2025-01-15 09:11:51 +09:00
김선우
eed610d457 Add JDBC4Statement.java 2025-01-15 09:08:45 +09:00
Pekka Enberg
256c0d4604 Merge 'Add support for rowid keyword' from Kould
https://github.com/tursodatabase/limbo/issues/241
support keyword `rowid`
check if rowid exists when creating table
```shell
explain SELECT rowid FROM users WHERE rowid = 1;

addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     12    0                    0   Start at 12
1     OpenReadAsync      0     2     0                    0   table=users, root=2
2     OpenReadAwait      0     0     0                    0
3     RewindAsync        0     0     0                    0
4     RewindAwait        0     11    0                    0   Rewind table users
5       RowId            0     2     0                    0   r[2]=users.rowid
6       Ne               2     3     9                    0   if r[2]!=r[3] goto 9
7       RowId            0     1     0                    0   r[1]=users.rowid
8       ResultRow        1     1     0                    0   output=r[1]
9     NextAsync          0     0     0                    0
10    NextAwait          0     5     0                    0
11    Halt               0     0     0                    0
12    Transaction        0     0     0                    0
13    Integer            1     3     0                    0   r[3]=1
14    Goto               0     1     0                    0
```

Closes #596
2025-01-14 21:10:20 +02:00
Pekka Enberg
3c118db20d simulator: Welcome banner 2025-01-14 19:15:14 +02:00
PThorpe92
23d9d09b70 Add load_extension function, resolve shared lib extensions 2025-01-14 12:01:07 -05:00
PThorpe92
343ccb3f72 Replace declare_scalar_functions in extension API with proc macro 2025-01-14 11:49:57 -05:00
Pekka Enberg
a9ffa72151 simulator: Replace println() calls with log::info() 2025-01-14 18:40:03 +02:00
Pekka Enberg
9db5061d64 Merge 'Simulator improvements' from Pekka Enberg
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #683
2025-01-14 18:37:31 +02:00
Pekka Enberg
053bc0b8cf Add Jussi to .github.json 2025-01-14 18:37:26 +02:00
Pekka Enberg
0c7ebd4df5 simulator: Enable info-level logging by default 2025-01-14 17:54:39 +02:00
Pekka Enberg
30a380cab1 simulator: Move more logging under trace level 2025-01-14 17:54:29 +02:00
Pekka Enberg
d355ce785c core/storage: Remove debug printout 2025-01-14 17:54:17 +02:00
Pekka Enberg
3c6c6041ff simulator: Log query errors with debug level
...it is totally fine for a SQL query to fail as part of the simulation.
For example, if we attempt to create a table that already exists, the
expectation is that the query fails. No need to spam the logs.
2025-01-14 17:41:07 +02:00
Pekka Enberg
e1f5fa875e simulator: Make simulator runs longer by default 2025-01-14 17:37:53 +02:00
Pekka Enberg
14ec057a34 simulator: Make stats printout prettier
```
op           calls   faults
--------- -------- --------
pread            3        0
pwrite           1        0
sync             0        0
--------- -------- --------
total            4        0
```
2025-01-14 17:32:31 +02:00
Pekka Enberg
5b4c7ec7f5 simulator: Rename stats in SimulatorFile 2025-01-14 17:24:14 +02:00
Pekka Enberg
1df1f7afc5 Add scripts/run-sim helper
...to run the simulator in a loop with different seeds.
2025-01-14 17:19:58 +02:00
Pekka Enberg
9c9a6e5821 Merge 'Fix unsafe calls to mark_last_insn_constant()' from Jussi Saurio
Bug found by @alpaylan and described here: https://github.com/tursodatab
ase/limbo/issues/662#issuecomment-2589756954
The reason is that we were, as a bytecode optimization, marking
instructions as constant in places where it was not safe to do so. It is
ONLY safe to mark an instruction as constant if the register allocated
for the result of that instruction is allocated during the translation
of that expression.
In the case of e.g. `Unary(Minus, Number)` we were doing the following:
```
limbo> CREATE TABLE likable_fire (captivating_insolacion INTEGER,mirthful_shihab REAL);
limbo> INSERT INTO likable_fire VALUES (8358895602713329453, -7435384732.72567), (4233751081339504981, -6653311696.714637);
limbo> select * from likable_fire;
8358895602713329453|-6653311696.714637
4233751081339504981|-6653311696.714637
limbo> explain INSERT INTO likable_fire VALUES (8358895602713329453, -7435384732.72567), (4233751081339504981, -6653311696.714637);
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     16    0                    0   Start at 16
1     InitCoroutine      5     7     2                    0
2     Integer            1783463725  2     0                    0   r[2]=8358895602713329453
3     Yield              5     15    0                    0
4     Integer            1454033237  2     0                    0   r[2]=4233751081339504981
5     Yield              5     15    0                    0
6     EndCoroutine       5     0     0                    0
7     OpenWriteAsync     0     2     0                    0
8     OpenWriteAwait     0     0     0                    0
9     Yield              5     15    0                    0
10    NewRowId           0     1     0                    0
11    MakeRecord         2     2     4                    0   r[4]=mkrec(r[2..3])
12    InsertAsync        0     4     1                    0
13    InsertAwait        0     0     0                    0
14    Goto               0     9     0                    0
15    Halt               0     0     0                    0
16    Transaction        0     1     0                    0

<!-- Reg 3 evaluated in a loop, but marked as "constant" twice, resulting in the first value being overwritten! -->
<!-- The reason mark_last_insn_constant() breaks this is because different values are being evaluated into the -->
<!-- Same register in a loop -->
17    Real               0     3     0     -7435384732.72567  0   r[3]=-7435384732.72567
18    Real               0     3     0     -6653311696.714637  0   r[3]=-6653311696.714637

19    Goto               0     1     0                    0
```
This PR removes `.mark_last_insn_constant()` from the affected places.
We should think about a small abstraction to prevent this going forward

Closes #679
2025-01-14 17:15:38 +02:00
Kould
1bf651bd37 chore: rollback using rowid(sqlite3 unsupported) 2025-01-14 22:56:49 +08:00
Kould
5305a9d0fd feat: support keyword rowid 2025-01-14 22:41:40 +08:00
Jussi Saurio
3cbb2d2d7c Add regression test for multi insert with unary operator 2025-01-14 16:22:16 +02:00
Jussi Saurio
fcfee24c50 Remove mark_last_insn_constant() from places where it is not safe to do so 2025-01-14 16:06:49 +02:00
Pekka Enberg
55e79a72c1 Merge 'Initial pass on loadable rust extensions' from Preston Thorpe
This PR adds the start of an implementation of an extension library for
`limbo` so users can write extensions in rust, that can be loaded at
runtime with the `.load` cli command.
The existing "ExtensionFunc"  `uuid`, has been replaced with the first
complete limbo extension in `extensions/uuid`
![image](https://github.com/user-
attachments/assets/63aa06cc-9390-4277-ba09-3a9be5524535)
![image](https://github.com/user-
attachments/assets/75899748-5e26-406a-84ee-26063383afeb)
There is still considerable work to do on this, as this only implements
scalar functions, but this PR is already plenty big enough.
Design + implementation comments or suggestions would be appreciated
👍
I tried out using `abi_stable`, so that trait objects and other goodies
could be used across FFI bounds, but to be honest I didn't find it too
much better than this. I personally haven't done a whole lot with FFI,
or anything at all linking dynamically in Rust, so if there is something
I seem to be missing here, please let me know.
I added some tests, similar to how shell-tests are setup.
If anyone can test this on other platforms, that would be helpful as
well as I am limited to x86_64 linux here

Closes #658
2025-01-14 15:36:56 +02:00
PThorpe92
9c208dc866 Add tests for first extension 2025-01-14 07:27:35 -05:00
PThorpe92
e4ce6402eb Remove previous uuid implementation 2025-01-14 07:20:50 -05:00
PThorpe92
3099e5c9ba Improve api, standardize conversions between types, finish extension 2025-01-14 07:20:50 -05:00