Commit Graph

4811 Commits

Author SHA1 Message Date
Jussi Saurio
8abe5efe99 Merge 'Add Schema reference to Resolver - needed for adhoc subquery planning' from Jussi Saurio
enabler for WHERE clause subquery ad-hoc planning&translation

Closes #1589
2025-05-27 20:19:45 +03:00
Jussi Saurio
ad0f2bb399 Merge 'Small VDBE insn tweaks' from Jussi Saurio
1. allow calling op_null with Insn::BeginSubrtn
    - BeginSubrtn is identical to Null, but named differently so that
its use in context is clearer
2. Insn::Return: add possibility to fallthrough on non-integer values as
per sqlite spec

Closes #1588
2025-05-27 20:19:31 +03:00
Jussi Saurio
d67e22c557 Merge 'Use the SetCookie opcode to implement user_version pragma' from meteorgan
1. implement the `SetCookie` opcode for `user_version`
2. reimplement `PRAGMA user_version=N` functionality using the
`SetCookie` opcode
**sqlite**
```
sqlite> explain pragma user_version=10;
addr  opcode         p1    p2    p3    p4             p5  comment
----  -------------  ----  ----  ----  -------------  --  -------------
0     Init           0     5     0                    0   Start at 5
1     Expire         1     1     0                    0
2     Transaction    0     1     0                    0
3     SetCookie      0     6     10                   1
4     Halt           0     0     0                    0
5     Goto           0     1     0                    0
```
**limbo**
```
limbo>  explain pragma user_version=10;
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     3     0                    0   Start at 3
1     SetCookie          0     6     10                   1
2     Halt               0     0     0                    0
3     Transaction        0     1     0                    0   write=true
4     Goto               0     1     0                    0
```
To fully align the opcodes with SQLite, we still need to implement the
`Expire` opcode, which I plan to address in the next PR.

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

Closes #1590
2025-05-27 20:19:13 +03:00
meteorgan
86249d9c28 add more tests for pragma user_version 2025-05-28 00:47:09 +08:00
meteorgan
2f82762ca2 add function parse_signed_number 2025-05-28 00:33:41 +08:00
meteorgan
d9d3a5ecbb Use the SetCookie opcode to implement user_version pragma 2025-05-28 00:31:11 +08:00
Jussi Saurio
d2a287f67f Add Schema reference to Resolver - needed for adhoc subquery planning 2025-05-27 19:12:47 +03:00
Jussi Saurio
6914d61180 allow calling op_null with Insn::BeginSubrtn 2025-05-27 19:09:15 +03:00
Jussi Saurio
70965f4b28 Insn::Return: add possibility to fallthrough on non-integer values as per sqlite spec 2025-05-27 19:09:10 +03:00
Pekka Enberg
ac97ac36a6 Fix broken build in sqlite3 tests
Thanks for the heads up Pedro!
2025-05-27 18:44:41 +03:00
Pekka Enberg
8d7f20b7d2 Merge 'Add libsql_wal_get_frame() API' from Pekka Enberg
This pull request implements the `libsql_wal_get_frame()` API. To do
that, we also introduce a `wait_for_completion()` API in I/O dispatcher.

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

Closes #1533
2025-05-27 18:17:32 +03:00
Pekka Enberg
99926c5f99 sqlite3/tests: Clippy is not happy 2025-05-27 18:16:54 +03:00
Pekka Enberg
edfa7402f0 sqlite3/test: Use tempfile in read frame test case
...make test runs idempotent, as suggested by Jussi.
2025-05-27 16:45:02 +03:00
Pekka Enberg
59d28eac93 core: Switch Completion "is_completed" to use Cell
Suggested by Jussi
2025-05-27 14:05:07 +03:00
Pekka Enberg
3250560eb8 sqlite3: Add libsql_wal_get_frame() API 2025-05-27 13:47:40 +03:00
Pekka Enberg
05df548b10 core/io: Add wait_for_completion() to I/O dispatcher 2025-05-27 13:47:40 +03:00
Jussi Saurio
a88e1c38f3 Merge 'Fix bug: op_vopen should replace cursor slot, not add new one' from Jussi Saurio
Found this when reviewing #1528 locally and this was crashing
```sql
INSERT INTO t SELECT * FROM generate_series(1,10,1);
```
Reason was that `op_vopen` was not replacing the already allocated
cursor slot, but using `.insert()`

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1583
2025-05-27 12:50:11 +03:00
Pere Diaz Bou
312bb5205a Merge 'Reset idx delete state after successful finish' from Pere Diaz Bou
If we don't reset the state of `IdxDelete`, next `IdxDelete` will start
in `Deleting` state which is completely wrong since it should seek from
the start.

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

Closes #1584
2025-05-27 11:31:25 +02:00
Pere Diaz Bou
a5a8a52a07 reset-idx-delete-state 2025-05-27 10:47:21 +02:00
Pekka Enberg
eca9a5b703 core/io: Switch to Arc<Completion> 2025-05-27 11:28:49 +03:00
Jussi Saurio
f035e076ca Merge 'bind/js: Add support for bind() method and reduce boilerplate' from Diego Reis
EDIT: This PR also adds support for the `pluck()` logic in all methods

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

Closes #1582
2025-05-27 11:01:27 +03:00
Jussi Saurio
b843ad0a58 Add INSERT INTO ... SELECT * FROM generate_series() regression test 2025-05-27 10:54:55 +03:00
Jussi Saurio
360b1fcdae Fix bug: op_vopen should replace cursor slot, not add new one 2025-05-27 10:52:36 +03:00
Jussi Saurio
b72b99c973 Merge 'feature: INSERT INTO <table> SELECT' from Pedro Muniz
Closes #1528 .
- Modified `translate_select` so that the caller can define if the
statement is top-level statement or a subquery.
- Refactored `translate_insert` to offload the translation of multi-row
VALUES and SELECT statements to `translate_select`
- I did not try to change much of `populate_column_registers` as I did
not want to break `translate_virtual_table_insert`. Ideally, I would
want to unite this remaining logic folding `populate_column_registers`
into `populate_columns_multiple_rows` and the
`translate_virtual_table_insert` into `translate_insert`. But, I think
this may be best suited for a separate PR.
## TODO
- ~Tests~ - *Done*
- ~Need to emit a temp table when we are selecting and inserting into
the Same Table -
https://github.com/sqlite/sqlite/blob/master/src/insert.c#L1369~ -
*Done*
- Optimization when table have the exact same schema - open an Issue
about it
- Virtual Tables do not benefit yet from this feature - open an Issue
about it

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

Closes #1566
2025-05-27 10:50:26 +03:00
Jussi Saurio
1c4b5c0333 Merge 'Clear test db's WAL too in clone_test_db.sh' from Jussi Saurio
Before #1570 , we never read anything from the on-disk WAL at startup,
so the `test_wal_frame_count()` test assertion `frame_count == 0`would
always pass, regardless of whether there was anything in the WAL or not
Now that the actual bug is fixed, the current test isn't idempotent
because the `clone_test_db.sh` command does not clear the wal, just the
db file

Closes #1581
2025-05-27 10:04:02 +03:00
Pekka Enberg
21535018aa core: Don't pass page to begin_read_wal_frame()
Make `begin_read_wal_frame()` a bit more generic by not requiring a page
to be passed.
2025-05-27 10:02:36 +03:00
Diego Reis
b012d07aa3 bind/js: Apply pluck's logic to all methods 2025-05-26 17:14:33 -03:00
Diego Reis
b60fd81995 bind/js: Reduce boilerplate of binding variables and checking
Statement's state
2025-05-26 17:00:55 -03:00
Diego Reis
799f4149c5 bind/js: Add bind method 2025-05-26 16:52:48 -03:00
Jussi Saurio
7e16c235af Clear test db's WAL too in clone_test_db.sh 2025-05-26 22:00:39 +03:00
Jussi Saurio
4395b7cf4a Merge 'Small cleanups to pager/wal/vdbe - mostly naming' from Jussi Saurio
- Instead of using a confusing `CheckpointStatus` for many different
things, introduce the following statuses:
    * `PagerCacheflushStatus` - cacheflush can result in either:
       - the WAL being written to disk and fsynced
       - but also a checkpoint to the main DB file, and fsyncing the
main DB file
      Reflect this in the type.
    * `WalFsyncStatus`
      - previously `CheckpointStatus` was also used for this, even
though fsyncing the WAL doesn't checkpoint.
    * `CheckpointStatus`/`CheckpointResult` is now used only for actual
checkpointing.
- Rename `HaltState` to `CommitState` (program.halt_state ->
program.commit_state)
   * `HaltState`'s only variant was `HaltState::Checkpointing` but it
wasn't necessarily reflective of checkpoint being in progress.
   * Now the variants are `CommitState::Ready` and
`CommitState::Committing` and `commit_state` is
      non-optional in `ProgramState`
- Make `wal` a non-optional property in `Pager`
  * This gets rid of a lot of `if let Some(...)` boilerplate
  * For ephemeral indexes, provide a `DummyWAL` implementation that does
nothing.
- Rename `program.halt()` to `program.commit_txn()`
- Add some documentation comments to structs and functions

Reviewed-by: Preston Thorpe (@PThorpe92)

Closes #1578
2025-05-26 21:38:02 +03:00
Pekka Enberg
bc25ef0fba Merge 'bindings/javascript: API enhancements' from Diego Reis
This PR:
- Fix compatibility for variadic functions;
- Adds pragma, transaction, close, and pluck methods;
- Add variables to get, iterate, and all methods

Closes #1576
2025-05-26 20:46:10 +03:00
Pekka Enberg
11f7526a73 Merge 'github: Migrate workflows to Blacksmith runners' from blacksmith-sh[bot]
To whomever may be reviewing this PR,
**[Blacksmith](https://www.blacksmith.sh/) is the fastest way to run
your GitHub Actions.**
## What does this PR change?
This PR has been automatically generated by a team member in your GitHub
organization using Blacksmith's [Migration
Wizard](https://docs.blacksmith.sh/introduction/quickstart), or MigWiz
for short. This PR changes the following:
1. Updates your selected workflows to use Blacksmith's `runs-on:
blacksmith-4vcpu-ubuntu-2204`. Learn more about the [different instances
available to choose from](https://docs.blacksmith.sh/blacksmith-
runners/config).
2. Updates your `actions/cache`, `actions/setup-*` to use Blacksmith's
`useblacksmith/cache`, `useblacksmith/setup-*`. Learn more about
[Blacksmith's cache action](https://docs.blacksmith.sh/blacksmith-
caching/dependencies-actions).
## FAQ
- Is this free? The first 3,000 minutes per month are free.
- Who uses Blacksmith? Clerk, Ashby, VEED, and 300+ others.
- What's the catch? There is none. Merge this thing already.

Closes #1579
2025-05-26 20:44:40 +03:00
Pekka Enberg
400fe6a4fe github: Switch release workflow to use Github Actions
...the file is auto-generated by `cargo-dist` and won't run if edited manually.
2025-05-26 20:28:48 +03:00
blacksmith-sh[bot]
c08b6a8957 Migrate workflows to Blacksmith 2025-05-26 16:28:46 +00:00
Diego Reis
bce4ac45db bind/js: Remove broken try/catch 2025-05-26 12:49:47 -03:00
Diego Reis
c2efab35e0 bind/js: Refactor tests 2025-05-26 12:48:51 -03:00
Diego Reis
7dc69c9c39 bindings/js: Add extension loading 2025-05-26 12:25:43 -03:00
Jussi Saurio
3ba9f2ab97 Small cleanups to pager/wal/vdbe - mostly naming
- Instead of using a confusing CheckpointStatus for many different things,
  introduce the following statuses:
    * PagerCacheflushStatus - cacheflush can result in either:
      - the WAL being written to disk and fsynced
      - but also a checkpoint to the main BD file, and fsyncing the main DB file

      Reflect this in the type.
    * WalFsyncStatus - previously CheckpointStatus was also used for this, even
      though fsyncing the WAL doesn't checkpoint.
    * CheckpointStatus/CheckpointResult is now used only for actual checkpointing.

- Rename HaltState to CommitState (program.halt_state -> program.commit_state)
- Make WAL a non-optional property in Pager
  * This gets rid of a lot of if let Some(...) boilerplate
  * For ephemeral indexes, provide a DummyWAL implementation that does nothing.
- Rename program.halt() to program.commit_txn()
- Add some documentation comments to structs and functions
2025-05-26 10:37:34 +03:00
pedrocarlo
1410e57112 correct union result_row or yield emission + test 2025-05-26 01:06:26 -03:00
pedrocarlo
ee93316c46 fix num_values detection + emitting correct column for temp_table + tests 2025-05-25 19:15:28 -03:00
pedrocarlo
e3fd1e589e support using a INSERT SELECT that references the same table in both statements 2025-05-25 19:15:28 -03:00
pedrocarlo
90e3c8483d tests with compound select 2025-05-25 19:15:28 -03:00
pedrocarlo
c86e7542ec simple smoke tests 2025-05-25 19:13:40 -03:00
pedrocarlo
72c1f2f582 fix rebase issues and make code compile by cloning query type. Adjust the compound select behavior with insert 2025-05-25 19:13:40 -03:00
pedrocarlo
c8144340a0 adjust proper ordering for value insert 2025-05-25 19:12:30 -03:00
pedrocarlo
810211b3d1 passing incorrect number of values to virtual table insert 2025-05-25 19:12:30 -03:00
pedrocarlo
4bcfc8ca60 create separate function to populate multiple columns in a multi-row VALUES clause or in an INSERT INTO <table> SELECT. Virtual Table insert is broken, need to fix it still 2025-05-25 19:12:30 -03:00
pedrocarlo
bb7da39c72 remove assumption that translate_select is always called from a top-level context + adjust insert to use translate_select when needed 2025-05-25 19:12:30 -03:00
pedrocarlo
fd9e0db5cc pass the owned ast to translate_insert + remove assumption of a list of values in populate_columns_insert 2025-05-25 19:02:17 -03:00