Commit Graph

720 Commits

Author SHA1 Message Date
PThorpe92
47aa03997b fix pc issue in sequence test op 2025-09-24 08:26:34 -04:00
Pekka Enberg
0b6f535f4a core: Wrap Connection fields with AtomicI64 2025-09-24 09:12:46 +03:00
Pekka Enberg
248b38b6a9 Merge 'core: Wrap Connection::transaction_state with RwLock' from Pekka Enberg
Closes #3269
2025-09-24 08:44:40 +03:00
Jussi Saurio
d5de088abe Merge 'translate: implement Sequence opcode and fix sort order' from Preston Thorpe
This PR implements the `Sequence` and `SequenceTest` opcodes, although
does not yet add plumbing to emit the latter.
SQLite has two distinct mechanisms that determine the final row order
with aggregates:
Traversal order of GROUP BY, and ORDER BY tiebreaking. When ORDER BY
contains only aggregate expressions and/or constants, SQLite has no
extra tiebreak key, but when ORDER BY mixes aggregate and non-aggregate
terms, SQLite adds an implicit, stable row `sequence` so “ties” respect
the input order.
This PR also fixes an issue with a query like the following:
```sql
SELECT u.first_name, COUNT(*) AS c
FROM users u
JOIN orders o ON o.user_id = u.id
GROUP BY u.first_name
ORDER BY c DESC;
```
Because ORDER BY has only an aggregate (COUNT(*) DESC) and no non-
aggregate terms, SQLite traverses the group key (u.first_name) in DESC
order in this case, so ties on c naturally appear with group keys in
descending order.
Previously tursodb would return the group key sorted in ASC order,
because it was used in all cases as the default

Closes #3287
2025-09-24 08:38:08 +03:00
PThorpe92
3c8216caab Add Sequence and SequenceTest opcodes to vdbe and sorter 2025-09-23 22:34:13 -04:00
Pekka Enberg
f5d3962459 core: Wrap Connection::transaction_state with RwLock 2025-09-23 14:01:31 +03:00
Pekka Enberg
fa8065ca52 core: Wrap Connection::autocommit in AtomicBool 2025-09-23 13:18:49 +03:00
Pekka Enberg
233beeb8e7 Merge 'core: Wrap Connection::schema in RwLock' from Pekka Enberg
Closes #3261
2025-09-23 11:50:24 +03:00
Pekka Enberg
b94aa22499 core: Wrap Connection::schema in RwLock 2025-09-23 10:31:20 +03:00
Pekka Enberg
9d395a5a52 Merge 'Stop incrementing n_changes for idx delete' from Preston Thorpe
closes #3259
Previously we were emitting the following:
<img width="483" height="135" alt="image" src="https://github.com/user-
attachments/assets/e12100ed-5815-4619-829a-3230eb8c8f7f" />
After:
<img width="484" height="310" alt="image" src="https://github.com/user-
attachments/assets/28591f52-18b1-4060-8c92-7a3f7194fca0" />

Closes #3258
2025-09-23 07:30:41 +03:00
Pekka Enberg
b857f94fe4 Merge 'core: Wrap Connection::pager in RwLock' from Pekka Enberg
Closes #3247
2025-09-23 07:29:09 +03:00
PThorpe92
9238584a75 Stop incrementing n_changes for idx delete 2025-09-22 19:10:35 -04:00
Pavan Nambi
f1ac855441 Merge branch 'main' into cdc_fail_autoincrement 2025-09-22 21:11:26 +05:30
PThorpe92
8420b9be04 Disable runtime extension loading unless enabled 2025-09-22 11:28:19 -04:00
Pekka Enberg
aa454a6637 core: Wrap Connection::pager in RwLock 2025-09-22 17:02:08 +03:00
PThorpe92
a1ca56620a Add SQLITE_CONSTRAINT_UNIQUE constraint to op_halt handling 2025-09-21 13:29:01 -04:00
Pavan Nambi
47194d7658 Merge branch 'tursodatabase:main' into cdc_fail_autoincrement 2025-09-21 16:03:38 +05:30
Pavan-Nambi
c9ab268bf5 remove extra checks for int column autoincr 2025-09-20 12:59:14 +05:30
Pavan-Nambi
294db6de2d Prevent sqlite_sequence updates from overwriting last_insert_rowid 2025-09-20 12:36:30 +05:30
Pavan-Nambi
16072de4f6 use Arc not rc and add auto_increment to window 2025-09-20 10:53:48 +05:30
Jussi Saurio
ba7ae50eff mvcc: remove unused code related to is_logical_log()
is always logical log
2025-09-19 12:55:27 +03:00
Jussi Saurio
5aa788691b Merge 'Fix math functions compatibility issues' from Levy A.
Adds `round`, `hex`, `unhex`, `abs`, `lower`, `upper`, `sign` and `log`
(with base) to the expression fuzzer.
Rounding with the precision argument still has some incompatibilities.

Closes #3160
2025-09-19 09:15:11 +03:00
Pere Diaz Bou
d53c64e84b core/schema: parse schema rows for MVCC transactions 2025-09-18 18:22:06 +02:00
Levy A.
85e0f1444d fix: add log with base to fuzzer 2025-09-18 13:09:39 -03:00
Levy A.
5016123214 fix: compatible rounding precision 2025-09-18 11:10:15 -03:00
Levy A.
2b632d4fe0 fix upper, lower and sign tests 2025-09-18 11:08:15 -03:00
Pavan-Nambi
020921f803 Merge remote-tracking branch 'upstream/main' into cdc_fail_autoincrement 2025-09-18 19:27:19 +05:30
Pekka Enberg
ecbe2c231f core: Rename Connection::_db to db 2025-09-18 16:00:41 +03:00
Pekka Enberg
2a5284afb9 core/storage: Use AtomicU32 for Pager::page_size 2025-09-18 11:33:32 +03:00
Nikita Sivukhin
ed819c9865 Merge branch 'main' into more-async 2025-09-18 10:48:54 +04:00
Pekka Enberg
d2376a239a Merge 'core/mvcc: introduce with_header for MVCC header update tracking' from Pere Diaz Bou
Currently header changes are tracked through pager by reading page 1.
MVCC has it's own layer to track changes during txn so this commit makes
it so that headers are tracked by each txn separately.
On commit we update the _global_ header which is used to update
`database_size` because pager commits require it to be up to date. This
also makes it _simpler_ to keep track of header updates and update
pager's header accordingly.
This PR is needed in order to make logical log work because we don't
want to rely on pager as much as possible!

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

Closes #3156
2025-09-18 08:13:14 +03:00
Nikita Sivukhin
bf5397dade fix op_sorter 2025-09-17 21:30:40 +04:00
Nikita Sivukhin
dea041b7c0 fix after rebase 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
a8bc06ea9c fix clippy 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
c4c9d409c9 remove io.block from op_checkpoint 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
27627bdb8d remove IOExt import from execute 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
85b671997e remove io.block from op_open_ephemeral 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
18feacf824 remove io.block from op_sorter_open 2025-09-17 19:06:07 +04:00
Nikita Sivukhin
e250285513 make op_transaction non-blocking 2025-09-17 19:06:07 +04:00
Pere Diaz Bou
88307197cc with_header mvcc update rc to arc 2025-09-17 11:50:24 +02:00
Pekka Enberg
182565fe0c core: Wrap MvCursor in Arc<RwLock<>>
Make it Send and Sync.
2025-09-17 12:46:55 +03:00
Pere Diaz Bou
64616dc2ca core/mvcc: introduce with_header for MVCC header update tracking
Currently header changes are tracked through pager by reading page 1.
MVCC has it's own layer to track changes during txn so this commit makes
it so that headers are tracked by each txn separately.

On commit we update the _global_ header which is used to update
`database_size` because pager commits require it to be up to date. This
also makes it _simpler_ to keep track of header updates and update
pager's header accordingly.
2025-09-17 11:42:44 +02:00
Jussi Saurio
9a2797963a Merge 'Remove LimboResult enum and InsnFunctionStepResult::Busy variant' from Jussi Saurio
We can just use `LimboError::Busy` for both of these.

Reviewed-by: Pekka Enberg <penberg@iki.fi>

Closes #3170
2025-09-17 12:06:54 +03:00
Jussi Saurio
e066e4f747 clippy 2025-09-17 11:25:50 +03:00
Jussi Saurio
b9ceacc356 Remove InsnFunctionStepResult::Busy
we don't need all these busy variants, let's just handle
LimboError::Busy
2025-09-17 11:22:49 +03:00
Jussi Saurio
dc103da2ed Remove LimboResult
this is only used for returning LimboResult::Busy, and we already
have LimboError::Busy, so it only adds confusion.

Moreover, the current busy handler was not handling LimboError::Busy,
because it's returned as an error, not as Ok. So this may fix the
"busy handler not working" issue in the perf thrpt benchmark.
2025-09-17 11:04:44 +03:00
Pekka Enberg
50653258cf core: Wrap symbol table with RwLock
Make it Send.
2025-09-17 10:58:32 +03:00
Pekka Enberg
17e9f05ea4 core: Convert Rc<Pager> to Arc<Pager> 2025-09-17 09:32:49 +03:00
Jussi Saurio
fad8d0c8b8 fix build 2025-09-17 08:45:13 +03:00
Jussi Saurio
cae234818b Merge 'Inital support for window functions' from Piotr Rżysko
This adds basic support for window functions. For now:
* Only existing aggregate functions can be used as window functions.
* Specialized window-specific functions (`rank`, `row_number`, etc.) are
not yet supported.
* Only the default frame definition is implemented:
`RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE NO OTHERS`.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>
Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3079
2025-09-17 08:29:16 +03:00