Commit Graph

8324 Commits

Author SHA1 Message Date
Piotr Rzysko
569e41cb1e Skip traversing children of aggregate functions
Aggregate functions cannot be nested, and this is validated during the
translation of aggregate function arguments. Therefore, traversing their
child expressions is unnecessary.
2025-09-02 08:22:37 +02:00
Piotr Rzysko
9b742a64c2 Handle functions with star argument wrapped in expressions
Handled in the same way as in `prepare_one_select_plan` for bare
function calls.
2025-09-02 08:22:36 +02:00
Piotr Rzysko
f3cbc382ce Support external aggregate functions wrapped in expressions
Handled in the same way as in `prepare_one_select_plan` for bare
function calls. In `prepare_one_select_plan`, however, resolving
external scalar functions is performed unnecessarily twice.
2025-09-02 08:22:36 +02:00
Piotr Rzysko
d361734819 Remove unnecessary recursion in resolve_aggregates
The walk_expr method already traverses arguments, so there is no need
to do this explicitly.
2025-09-02 08:22:36 +02:00
Piotr Rzysko
ab0f673f44 Add benchmark for result column expression handling
The new query combines multiple aggregate functions, plain columns,
arithmetic expressions, and aggregates wrapped in additional expressions.

Local run results:
```
Prepare `SELECT first_name, last_name, state, city, age + 10, LENGTH(email), UPPER(first_name), LOWE...
                        time:   [64.535 µs 64.623 µs 64.713 µs]
Found 9 outliers among 100 measurements (9.00%)
  4 (4.00%) high mild
  5 (5.00%) high severe
```
2025-09-02 08:22:36 +02:00
Pekka Enberg
7189e98455 Merge 'Unify handling of grouped and ungrouped aggregations' from Piotr Rżysko
The initial commits fix issues and plug gaps between ungrouped and
grouped aggregations.
The final commit consolidates the code that emits `AggStep` to prevent
future disparities between the two.

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2867
2025-09-02 09:11:40 +03:00
Pekka Enberg
0868af29df Merge 'core/printf: support for more basic substitution types' from Luiz Gustavo
Some progress working on `printf` support.
(relevant issue https://github.com/tursodatabase/turso/issues/885)
Implementation of the basic substitution types cited in the `TODO`
comment on the beginning of the file (%i, %x, %X, %o, %e, %E, %c). There
are some others in the sqlite spec which I will implement in a future
PR.
I tried to pay attention to the specific behaviors from sqlite as much
as possible while testing this, but if there's something I missed please
tell me.
Also, I see this code needs to be reorganized already, I'm still
thinking on the best approach to do that without affecting the
ergonomics of new implementations, I'm still learning Rust so this is
not obvious for me right now. I'm open to suggestions about it.

Closes #2868
2025-09-02 09:10:03 +03:00
Pekka Enberg
1f6ba4f822 Merge 'Fix sim-schema command ' from Pedro Muniz
Create the directory to store the schema if it does not exists

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2882
2025-09-02 09:08:57 +03:00
Pekka Enberg
87d3f74e6e Merge 'Evict page from cache if page is unlocked and unloaded' from Pedro Muniz
Because we can abort a read_page completion, this means a page can be in
the cache but be unloaded and unlocked. However, if we do not evict that
page from the page cache, we will return an unloaded page later which
will trigger assertions later on. This is worsened by the fact that page
cache is not per `Statement`, so you can abort a completion in one
Statement, and trigger some error in the next one if we don't evict the
page in these circumstances.
Also, to propagate IO errors we need to return the Error from
IOCompletions on step.

Closes #2785
2025-09-02 09:08:12 +03:00
Pekka Enberg
d959319b42 Merge 'Use u64 for file offsets in I/O and calculate such offsets in u64' from Preston Thorpe
Using `usize` to compute file offsets caps us at ~16GB on 32-bit
systems. For example, with 4 KiB pages we can only address up to 1048576
pages; attempting the next page overflows a 32-bit usize and can wrap
the write offset, corrupting data. Switching our I/O APIs and offset
math to u64 avoids this overflow on 32-bit targets

Closes #2791
2025-09-02 09:06:49 +03:00
Pekka Enberg
cfaba4ab10 Merge 'Implement libSQL's ALTER COLUMN extension' from Levy A.
Implement `ALTER COLUMN` as described here:
https://github.com/tursodatabase/libsql/blob/main/libsql-
sqlite3/doc/libsql_extensions.md#altering-columns
- [x] Add `ALTER COLUMN` to parser
- [x] Implement `Insn::AlterColumn`
- [x] Add tests

Closes #2814
2025-09-02 09:06:03 +03:00
Pekka Enberg
da81e43f9a Merge 'Document how to use CDC' from Pavan Nambi
Fixes #2221

Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #2871
2025-09-02 09:04:44 +03:00
Pekka Enberg
149942abe4 Merge 'Return sqlite_version() without being initialized' from Preston Thorpe
needed to support opening in Gorm

Closes #2878
2025-09-02 09:04:25 +03:00
Pekka Enberg
a21d580f80 Merge 'Upgrade Rust version in simulator build Dockerfile' from Preston Thorpe
otherwise simulator profiles will not build as it uses the new if let
syntax

Closes #2880
2025-09-02 09:04:03 +03:00
pedrocarlo
72d697e0eb fix sim-schema command by creating directory if it not exists 2025-09-01 21:05:25 -03:00
PThorpe92
be2807b61f Upgrade rust version in simulator build dockerfile 2025-09-01 14:56:05 -04:00
PThorpe92
e9b50b63fb Return sqlite_version() without being initialized 2025-09-01 13:36:41 -04:00
Preston Thorpe
f3d252d665 Merge 'Parse booleans to integer literals in expressions' from Preston Thorpe
Adds tests for edgecases for the insane cases where someone might want
to name a table `true` :)

Closes #2874
2025-09-01 13:36:29 -04:00
PThorpe92
b76f9b7733 Use eq_ignore_ascii_case in place of allocating new string in parser 2025-09-01 12:32:33 -04:00
PThorpe92
f02e02af75 Fix TCL test 2025-09-01 11:39:43 -04:00
PThorpe92
bd9d6aa168 Add edge-case tests for boolean literals 2025-09-01 11:27:43 -04:00
PThorpe92
46f5565faf Add more tests for boolean literals 2025-09-01 11:25:16 -04:00
PThorpe92
46182aa7ed add test for inserting boolean literals 2025-09-01 11:25:10 -04:00
PThorpe92
4bb2497d36 Parser: translate true and false to 0 and 1 literals 2025-09-01 11:24:12 -04:00
pedrocarlo
bc707fd9be cleanup + comments 2025-09-01 11:10:40 -03:00
pedrocarlo
53cfae1db4 return Error from step if IO failed 2025-09-01 11:10:39 -03:00
pedrocarlo
6f1eed7aca clippy 2025-09-01 11:10:39 -03:00
pedrocarlo
4618df9d1a because we can abort a read_page completion, this means that the page can be in the cache but be unloaded and unlocked. However, if we do not evict that page from the page cache, we will return an unloaded page later 2025-09-01 11:10:39 -03:00
pedrocarlo
be3f944c4f impl Error for CacheError and propagate it into LimboError 2025-09-01 11:10:39 -03:00
Pavan-Nambi
b343b79613 add details about table columns and how cdc behaves with transactions and stuff 2025-09-01 18:56:59 +05:30
Pavan Nambi
668213888d Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 18:16:53 +05:30
Pavan Nambi
5a6db2c2d5 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 18:16:40 +05:30
Pavan Nambi
6d6e8d2944 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 18:16:29 +05:30
Pavan Nambi
fa51256d4f Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 18:16:18 +05:30
Pekka Enberg
89fe0da26f Remove duplicate COPY directives from Antithesis Dockerfile 2025-09-01 14:22:39 +03:00
Pekka Enberg
d64263c09f Fix Antithesis Dockerfile 2025-09-01 14:21:55 +03:00
Pavan Nambi
826c6c7ee6 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:18:23 +05:30
Pavan Nambi
2fb2366105 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:18:16 +05:30
Pavan Nambi
4538455fe4 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:05:53 +05:30
Pavan Nambi
d969902809 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:05:46 +05:30
Pavan Nambi
98f6ed6b61 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:05:39 +05:30
Pavan Nambi
3aa85a46e0 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:05:32 +05:30
Pavan Nambi
7a26351efc Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:05:23 +05:30
Pavan Nambi
635720ed74 Update docs/manual.md
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2025-09-01 16:05:15 +05:30
Pekka Enberg
e209a17780 Merge 'Support encryption for raw WAL frames' from Gaurav Sarma
Fixes https://github.com/tursodatabase/turso/issues/2704
The PR decrypts the page referred to by the WAL frame while reading raw
frames.
<img width="923" height="189" alt="Screenshot 2025-08-31 at 12 42 53 AM"
src="https://github.com/user-
attachments/assets/5e353cf3-aae7-4260-9378-ee2a2cde3f69" />

Reviewed-by: Avinash Sajjanshetty (@avinassh)

Closes #2762
2025-09-01 13:14:08 +03:00
Pavan-Nambi
b122e0cc0e add docs to cdc 2025-09-01 13:31:21 +05:30
Gaurav Sarma
453cbd3201 Decrypt WAL page while reading raw frames 2025-09-01 15:29:01 +08:00
Pekka Enberg
d6543ac25c Merge 'Simulator Profiles' from Pedro Muniz
## Changes
- Refactor sql generation to always accept a `Context` trait object so
we can query the current Generation `Opts`. This change allows us to be
more granular in generating our sql statements. It also opens
opportunities for us to add even more knobs to tweak generation as
needed. I tried to make this as generic as possible as I believe this
library can be useful for fuzz testing outside the simulator.
- Introduce `Profile` struct that aggregates the different
configurations needed to execute the simulator. With this Profile struct
we can bias sql generation towards different statements and create
predefined profiles.
`WriteHeavy` Profile:
```rust
Profile {
            query: QueryProfile {
                gen_opts: Opts {
                    // TODO: in the future tweak blob size for bigger inserts
                    // TODO: increase number of rows as well
                    table: TableOpts {
                        large_table: LargeTableOpts {
                            large_table_prob: 0.4,
                            ..Default::default()
                        },
                        ..Default::default()
                    },
                    query: QueryOpts {
                        insert: InsertOpts {
                            min_rows: NonZeroU32::new(5).unwrap(),
                            max_rows: NonZeroU32::new(11).unwrap(),
                        },
                        ..Default::default()
                    },
                    ..Default::default()
                },
                select_weight: 30,
                insert_weight: 70,
                delete_weight: 0,
                update_weight: 0,
                ..Default::default()
            },
            ..Default::default()
        };
```
As you can see we disable the `delete` and `update` weights, decrease
`select` and increase `insert` weights. This means that we disable
updates and deletes in favor of inserting more data and checking the
validity of the database with fewer select statements.
- `Profile` and `Opts` are validated with `garde` and can generate json
schemas with `schemars` so that we can have editor integration when
creating new profiles to play with.
- Added some docs in the README explaining how you can add LSP
integration for the Json config by generating a `JsonSchema` file

Closes #2852
2025-09-01 10:26:33 +03:00
Pekka Enberg
0a01d4841d Merge 'bindings/java: Implement date, time related methods under JDBC4PreparedStatement' from Kim Seon Woo
- Implement data and time related methods under JDBC4PreparedStatement

Closes #2864
2025-09-01 10:06:16 +03:00
Pekka Enberg
9d06e0bf8e Merge 'Support encryption for non-4k page size' from
Closes #2734.

Reviewed-by: Avinash Sajjanshetty (@avinassh)

Closes #2860
2025-09-01 10:05:52 +03:00