Commit Graph

8400 Commits

Author SHA1 Message Date
Pekka Enberg
9fc5947fa6 core/vdbe: Micro-optimize "zero_or_null" opcode
It's a hot instruction for TPC-H, for example, so worth optimizing.
Reduces op_zero_or_null() from 5.6% to 2.4% in CPU flamegraph for TCP-H
Q1.
2025-08-29 14:38:50 +03:00
Pere Diaz Bou
db5e2883ee core/wal: cache wal is initialized 2025-08-29 13:15:09 +02:00
Pekka Enberg
13e62ce435 Merge 'core: Initial pass on synchronous pragma' from Pekka Enberg
This adds support for "OFF" and "FULL" (default) synchronous modes. As
future work, we need to add NORMAL and EXTRA as well because
applications expect them.

Closes #2833
2025-08-29 07:27:12 +03:00
Pekka Enberg
70ae983685 Merge 'perf: avoid constructing PageType in helper methods' from Jussi Saurio
I think the `try_into()` is probably expensive. we can use the fact that
both interior page types are `<=5` to our advantage for a little perf
boost in these hot path function calls
Based on #2836 (just to see aggregate perf difference in benchmarks)

Closes #2837
2025-08-29 07:27:02 +03:00
Pekka Enberg
96778cfb0a Merge 'refactor/perf: remove BTreePageInner' from Jussi Saurio
it wasn't used for anything. no more `page.get().get().id`.
i did this simply to clean up the code (we haven't needed BTreePageInner
in probably at least 8 months or more?), but it also:
- makes practically every tpc-h query faster due to removing indirection
and refcell runtime borrowing every time the btree stack is accessed etc
- makes every SELECT * FROM users bench query faster
- drops the count() benchmark runtime by like half

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

Closes #2836
2025-08-29 07:26:56 +03:00
Jussi Saurio
ae0ac189fa perf: avoid constructing PageType for helper methods 2025-08-28 22:56:44 +03:00
Jussi Saurio
ce860b7ec9 clippy 2025-08-28 21:48:29 +03:00
Jussi Saurio
9aae3fa859 refactor: remove BTreePageInner
it wasn't used for anything. no more `page.get().get().id`.
2025-08-28 21:44:54 +03:00
Pekka Enberg
3952dbb445 Merge 'Fix sorter column deduplication' from Piotr Rżysko
Previously, the added test case failed because the last result column
was missing - a nonexistent column in the sorter was referenced.

Closes #2824
2025-08-28 18:29:44 +03:00
PThorpe92
fb7e6fb280 Guard against all overflow when calculating IO offsets 2025-08-28 09:50:26 -04:00
PThorpe92
a0e5536360 Fix clippy warnings and remove self casts 2025-08-28 09:45:19 -04:00
PThorpe92
0a56d23402 Use u64 for file offsets in IO and calculate such offsets in u64 2025-08-28 09:44:00 -04:00
Pekka Enberg
2ea4354afe Merge 'Improve integrity check' from Nikita Sivukhin
- check free list trunk and pages
- use shared hash map to check for duplicate references for pages
- properly check overflow pages

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

Closes #2816
2025-08-28 16:06:15 +03:00
Pekka Enberg
44ed4d562f core: Initial pass on synchronous pragma
This adds support for "OFF" and "FULL" (default) synchronous modes. As
future work, we need to add NORMAL and EXTRA as well because
applications expect them.
2025-08-28 16:02:41 +03:00
Pekka Enberg
878147b931 Merge 'translate/insert: Improve string format performance' from Pere Diaz Bou
Rust's `fmt!` is slow af for the simplest of cases, let's just create
strings with a known size and skip all the fmt stuff.

Closes #2832
2025-08-28 14:36:09 +03:00
Pekka Enberg
a5322d2ab7 Merge 'core/schema: get_dependent_materialized_views_unnormalized' from Pere Diaz Bou
If we get a table name for in memory structure, it's safe to assume it's
already normalized.

Closes #2830
2025-08-28 14:34:06 +03:00
Pekka Enberg
eba90e1c5e Merge 'core/util: emit literal, cow instead of replace' from Pere Diaz Bou
Closes #2828
2025-08-28 14:33:04 +03:00
Pekka Enberg
44e619be1a Merge 'core/translate: sanize_string fast path improvement' from Pere Diaz Bou
Closes #2827
2025-08-28 14:32:43 +03:00
Pere Diaz Bou
964422375e translate/insert: string fmt perf improvmenets 2025-08-28 13:22:54 +02:00
Pere Diaz Bou
c7230f4ab0 translate: with_capacity insns 2025-08-28 13:13:19 +02:00
Pere Diaz Bou
48e5ad7a55 core/schema: get_dependent_materialized_views_unnormalized
If we get a table name for in memory structure, it's safe to assume it's
already normalized.
2025-08-28 13:11:40 +02:00
Pere Diaz Bou
84c5c4e581 core/util: emit literal, cow instead of replace 2025-08-28 12:59:55 +02:00
Pere Diaz Bou
082f18c073 core/translate: sanize_string fast path improvement 2025-08-28 12:57:28 +02:00
Piotr Rzysko
c383d9f16e Remove outdated comment in order_by.rs
The removed comment no longer matches the current code. The
OrderByRemapping struct and the surrounding comments are sufficient to
explain deduplication and remapping.
2025-08-28 09:49:55 +02:00
Piotr Rzysko
e33c2e0f0b Fix sorter column deduplication
Previously, the added test case failed because the last result column
was missing - a nonexistent column in the sorter was referenced.
2025-08-28 09:49:55 +02:00
김선우
b50011d96b Implement setTimestamp 2025-08-28 14:49:16 +09:00
김선우
6c93d78394 Add TODOs 2025-08-28 14:38:13 +09:00
김선우
a9ae588159 Implement setTime 2025-08-28 14:35:01 +09:00
김선우
a61ad217f1 Implement setDate 2025-08-28 14:20:40 +09:00
Pekka Enberg
b4eba8b456 Merge 'Fix planner alias and table name handling' from
closes: #2817
```
turso> select * from simple_view as "v" where "v"."x" = 1;
┌───┐
│ x │
├───┤
│ 1 │
└───┘
turso> select "s"."x" from simple as "s" where "s"."x" = 1;
┌───┐
│ x │
├───┤
│ 1 │
└───
```

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

Closes #2818
2025-08-28 07:39:47 +03:00
Pekka Enberg
591914a63b Merge 'Introduce and propagate IOContext as required' from Avinash Sajjanshetty
I added `IOContext` to `DatbaseStorage` IO trait and this struct will
carry the necessary ctx required for encryption (or checksums.). This
lets us set the encryption at outside and let the IO layer handle it
properly

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

Closes #2812
2025-08-28 07:38:52 +03:00
Pekka Enberg
20260c9dc0 Merge 'core/io: Switch Unix I/O to use libc::pwrite()' from Pekka Enberg
We use libc elsewhere for fault injection reasons, so let's do this
call-site too.

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

Closes #2811
2025-08-28 07:38:42 +03:00
Pekka Enberg
376dbc9261 Merge 'Update README.md for Go documentation' from Preston Thorpe
Closes #2819
2025-08-28 07:38:20 +03:00
PThorpe92
1526448089 Update README.md for Go documentation 2025-08-27 22:23:19 -04:00
themixednuts
79a9f4743e fix: planner alias and table name 2025-08-27 18:13:03 -05:00
Nikita Sivukhin
1c0efcfbff fix clippy 2025-08-27 23:22:21 +04:00
Glauber Costa
143c84c4e0 add tests for rollback of views. 2025-08-27 14:21:32 -05:00
Glauber Costa
565c2a698a adjust views to use circuits 2025-08-27 14:21:32 -05:00
Glauber Costa
29b93e3e58 add DBSP circuit compiler
The next step is to adapt the view code to use circuits instead of
listing the operators manually.
2025-08-27 14:21:32 -05:00
Glauber Costa
898c0260f3 move operator to eval / commit pattern
We need a read only phase and a commit phase. Otherwise we will never
be able to rollback changes properly. We currently do that, but we
do that in the view. Before we move to circuits, this needs to be
internalized by the operator.
2025-08-27 14:21:32 -05:00
Nikita Sivukhin
09d4590ece fix compilation 2025-08-27 23:19:26 +04:00
Nikita Sivukhin
ae705445bf improve integrity check
- check free list trunk and pages
- use shared hash map to check for duplicate references for pages
- properly check overflow pages
2025-08-27 23:14:21 +04:00
Avinash Sajjanshetty
2c0842ff52 Set and propagate IOContext as required 2025-08-27 22:05:01 +05:30
Glauber Costa
7e4bacca55 remove join operator
I am 100% sure they are total bullshit by now, since we don't implement
the join operator yet. The code evolved a lot, and in every turn there
are issues with aggregators, projectors, filters... some subtle, some
not so subtle.

We keep having to patch join slightly as we make changes to the API, but
we don't truly exercise whether or not they keep working because there
is no support for them in the views. Therefore: let's remove it. We'll
bring it back later.
2025-08-27 11:18:54 -05:00
Glauber Costa
05b275f865 remove min/max and add more tests for other aggregations
min/max require O(N) storage because of deletions. It is easy to see
why: if you *add* a new row, you can quickly and incrementally check
if it is smaller / larger than the previous accumulator.

But when you *delete* a row you can't do that and have to check the
previous values.

Feldera uses something called "traces" which to me look a lot like
indexes. When we implement materialization, this is easy to do. But to
avoid having something broken, we'll just disable min / max until then.
2025-08-27 11:18:54 -05:00
Glauber Costa
6e2bd364ee fix issue with rowids and deletions
The operator itself should handle deletions and updates that change
the rowid by consolidating its state.

Our current materialized views track state themselves, so we don't
see this problem now. But it becomes apparent once we switch the
views to use circuits.
2025-08-27 11:18:54 -05:00
Glauber Costa
dbe29e4bab fix aggregator operator
It needs to keep track of the old values to emit retractions (when the
aggregation changes, remove old value, insert new)
2025-08-27 11:18:54 -05:00
Glauber Costa
c776e4eefb First implementation of Logical plan
This is a first pass on logical plans. The idea is that the DBSP
compiler will have an easier time operating on a logical plan, that
exposes linear algebra operators, than on SQL expr.

To keep this simple, we only support filters, aggregates and projections
for now, and will add more later as we agree on the core of the
implementation.

To make sure that the implementations is reasonable, I tried my best to
generate a couple of logical plans using Datafusion and seeing if we
were generating something similar.

Our plans are not the same as Datafusion's, though. There are two
important differences:

* SQLite is weird, and it allows columns that are not part of the group
  by statement to appear in aggregated statements. For example:
  select a, count(b) from table group by c; <== that "a" is usually not
  permitted and datafusion will reject it. SQLite will be happy to
  accept it

* Datafusion will not generate a projection on queries like this:
  select sum(hex(a)) from table, and just keep the complex expression
  hex(a) inside the aggregation. For DBSP to work well, we'll need an
  explicit aggregation there.

Because there are no users yet, I am marking this as [cfg(test)], but
I wanted to put this out there ASAP.
2025-08-27 11:18:54 -05:00
Avinash Sajjanshetty
9e663c7f46 Add IOContext to carry encryption/checksum ctx 2025-08-27 21:33:05 +05:30
Pekka Enberg
e6ae7f990d Merge 'improve sync engine' from Nikita Sivukhin
This PR makes plenty of changes to the sync engine among which the main
ones are:
1. Now, we have only single database file which we use to directly
execute `pull` and `push` requests (so we don't have `draft` / `synced`
databases)
2. Last-write-win strategy were fixed a little bit - because before this
PR insert-insert conflict wasn't resolved automatically
3. Now sync engine can apply arbitrary `transform` function to the
logical changes
4. Sync-engine-aware checkpoint was implemented. Now, database created
by sync-engine has explicit `checkpoint()` method which under the hood
will use additional file to save frames needed for revert operation
during pull
5. Pull operation were separated into 2 phases internally: wait for
changes & apply changes
    * The problem is that pull operation itself (e.g. apply) right now
require exclusive lock to the sync engine and if user wants to pull &
push independently this will be problematic (as pull will lock the db
and push will never succeed)
6. Added support for V1 pull protocol
7. Exposed simple `stats()` method which return amount of pending cdc
operations and current wal size

Closes #2810
2025-08-27 18:08:21 +03:00