Commit Graph

6043 Commits

Author SHA1 Message Date
Nikita Sivukhin
f61d733dd3 make new functions dependend on "json" Cargo feature 2025-07-14 11:26:51 +04:00
Nikita Sivukhin
c9e7271eaf properly pass subtype 2025-07-14 11:20:49 +04:00
Nikita Sivukhin
bf25a0e3f1 fix clippy 2025-07-14 11:20:16 +04:00
Nikita Sivukhin
81cd04dd65 add bin_record_json_object and table_columns_json_array functions 2025-07-14 11:19:45 +04:00
Nikita Sivukhin
eed89993f9 fix clippy 2025-07-14 11:17:32 +04:00
Nikita Sivukhin
5409812610 properly implement generation of before/after records for new modes 2025-07-14 11:17:32 +04:00
Nikita Sivukhin
9e04102a94 add basic cdc tests for new modes 2025-07-14 11:17:31 +04:00
Nikita Sivukhin
fabb00f385 fix test 2025-07-14 11:16:06 +04:00
Nikita Sivukhin
b258c10c9a generate before/after row values in modification statements 2025-07-14 11:16:06 +04:00
Nikita Sivukhin
9129991b62 add id,before,after,full modes 2025-07-14 11:16:06 +04:00
Pekka Enberg
8f8d582b4a Merge 'Ignore double quotes around table names' from Zaid Humayun
This PR normalizes the table name identifier by removing quotes to
improve SQLite compatibility. Fixes
https://github.com/tursodatabase/turso/issues/1964
<img width="545" height="175" alt="Screenshot 2025-07-13 at 5 12 23 PM"
src="https://github.com/user-
attachments/assets/10952fc7-9ade-4c97-a427-385ff2dc3b44" />
<img width="384" height="110" alt="Screenshot 2025-07-13 at 5 12 32 PM"
src="https://github.com/user-
attachments/assets/5d87e0fe-72a4-4472-abc3-24c0d4cc8add" />

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

Closes #2069
2025-07-14 10:04:59 +03:00
Pekka Enberg
26ba8c1176 Merge 'Efficient Record Comparison and Incremental Record Parsing ' from Krishna Vishal
Currently we deserialize the entire record to compare them or to get a
particular column. This PR introduces efficient record operations such
as incremental column deserialization and efficient record comparison.
### Incremental Column Deserialization
- Introduced `RecordCursor` to keep track of how much of the header and
the record we have already parsed. Each `BTreeCursor` will have its own
`RecordCursor` similar to an `ImmutableRecord`.
- The `RecordCursor` gets the number of columns from schema when the
BTreeCursor is initialized in VDBE. This helps in cutting down heap
allocs by reserving the correct amount of space for underlying `Vec`s.
- `Immutable` record only carries the serialized `payload` now.
- We parse the header up till we reach the required serial type (denoted
by the column index) and then calculate the offsets and deserialize only
that particular slice of the payload.
- Manually inlined most of the deserialization code into `fn op_column`
code because the compiler is refusing to inline even with
`#[inline(always)]` hint. This is probably due to complicated control
flow.
- Tried to follow SQLite semantics, where it returns `Null` when the
requested column falls outside the number of columns available in the
record or when the payload is empty etc.
### Efficient Record Comparison ops
- Three record comparison function are introduced for Integer, String
and for general case which replaces the `compare_immutable`. These
functions compare a serialized record with deserialized one.
- `compare_records_int`: is used when the first field is integer, header
≤63 bytes, ≤13 total fields. No varint parsing, direct integer
extraction.
- `compare_records_string`: is used when the first field is text with
binary collation, header ≤63 bytes.
-  `compare_records_generic`: is used in complex cases, custom
collations, large headers. Here we parse the record incrementally field
by field and comparing each field with the one from the deserialized
record. We early exit on the first mismatch saving on the
deserialization cost.
- `find_compare`: selects the optimal comparison strategy for a given
case and dispatches the function required.
### Benchmarks `main` vs `incremental_column`
I've used the `testing/testing.db` for this benchmark.
| Query                                                       | Main
| Incremental | % Change (Faster is +ve) |
|-------------------------------------------------------------|---------
-|-------------|------------------------|
| SELECT first_name FROM users                                | 1.3579ms
| 1.1452ms      | 15.66          |
| SELECT age FROM users                                       | 912.33µs
| 897.97µs      | 1.57            |
| SELECT email FROM users                                     | 1.3632ms
| 1.215ms       | 10.87            |
| SELECT id FROM users                                        | 1.4985ms
| 1.1762ms      | 21.50            |
| SELECT first_name, last_name FROM users                     | 1.5736ms
| 1.4616ms      | 7.11            |
| SELECT first_name, last_name, email FROM users              | 1.7965ms
| 1.754ms       | 2.36            |
| SELECT id, first_name, last_name, email, age FROM users     | 2.3545ms
| 2.4059ms      | -2.18           |
| SELECT * FROM users                                         | 3.5731ms
| 3.7587ms      | -5.19           |
| SELECT * FROM users WHERE age = 30                          | 87.947µs
| 85.545µs     | 2.73            |
| SELECT id, first_name FROM users WHERE first_name LIKE 'John%' |
1.8594ms   | 1.6781ms      | 9.75            |
| SELECT age FROM users LIMIT 1000                            | 100.27µs
| 95.418µs      | 4.83            |
| SELECT first_name, age, email FROM users LIMIT 1000         | 176.04µs
| 167.56µs      | 4.81            |
Closes: https://github.com/tursodatabase/turso/issues/1703

Closes #1923
2025-07-14 10:04:19 +03:00
Krishna Vishal
370d437491 Add docs for get_tie_breaker_from_idx_comp_op 2025-07-14 03:28:55 +05:30
Krishna Vishal
4c5383b0b3 chore: clippy 2025-07-14 03:28:55 +05:30
Krishna Vishal
e27b9c7e0f Address review comments 2025-07-14 03:28:55 +05:30
Krishna Vishal
a79fe458db Fix merge conflicts and adapt schema.rs to use RecordCursor 2025-07-14 03:28:55 +05:30
Krishna Vishal
ea4a4708ea - Address some review comments
- Add docs for `RecordCursor`
2025-07-14 03:28:55 +05:30
Krishna Vishal
b1f27cad94 chore: fix clippy 2025-07-14 03:28:55 +05:30
Krishna Vishal
d3368a28bc fix merge conflicts 2025-07-14 03:28:55 +05:30
Krishna Vishal
894bdca05f refactor: change ImmutableRecord payload to Value for compatibility 2025-07-14 03:28:54 +05:30
Krishna Vishal
d78185bd62 Remove mistakenly pushed file 2025-07-14 03:28:54 +05:30
Krishna Vishal
9de3cf0c60 Remove redundant checks 2025-07-14 03:28:54 +05:30
Krishna Vishal
235e798561 Return corrupt errors. 2025-07-14 03:28:54 +05:30
Krishna Vishal
9393aba0bd Add docs for RecordCompare 2025-07-14 03:28:54 +05:30
Krishna Vishal
e7e5f28c0a chore: Clippy chill 2025-07-14 03:28:54 +05:30
Krishna Vishal
f3b169bf30 Fix empty blob test failure. 2025-07-14 03:28:54 +05:30
Krishna Vishal
9b315d1d7e Manually inline the record deserialization code for performance.
This is done because the compiler is refusing to inline even after
adding inline hint.
- Get refvalues from directly from registers without using
`make_record`
2025-07-14 03:28:54 +05:30
Krishna Vishal
35ed279644 Clean up indexbtree_move_to 2025-07-14 03:28:54 +05:30
Krishna Vishal
dca4e669f7 Reduce allocations in compare_records_generic 2025-07-14 03:28:54 +05:30
Krishna Vishal
f0e8e5871b Replace compare_immutable with compare_records_generic 2025-07-14 03:28:54 +05:30
Krishna Vishal
860de412d9 Add num_columns to BTreeCursor so we can initialize
`Vecs` inside `RecordCursor` to their appropriate to reduce
allocations.
2025-07-14 03:28:54 +05:30
Krishna Vishal
ef147181c2 Working version of the incremental column and "optimal" record
compare functions. Now we optimize them
2025-07-14 03:28:54 +05:30
Krishna Vishal
692f0413eb Stash 2025-07-14 03:28:54 +05:30
Krishna Vishal
0b1ed44c1f Add optimized index record compare methods
compare_records_int
compare_records_string
compare_records_generic

comapre_records_generic will still be more efficient than compare-
_immutable because it deserializes the record column by column
2025-07-14 03:28:54 +05:30
Krishna Vishal
c7aa3c3d93 Fix btree to invalidate RecordCursor
Use `read_value` instead of `deserialize_column_data`
Add `sqlite_int_float_compare` which takes care of out of range
floats
2025-07-14 03:28:54 +05:30
Krishna Vishal
515712b7f2 Fix sorter 2025-07-14 03:28:54 +05:30
Krishna Vishal
601540af6e Make OP_column do on demand serialization baby! 2025-07-14 03:28:54 +05:30
Krishna Vishal
2323763a4f Integrate incremental column parsing into btree.rs 2025-07-14 03:28:54 +05:30
Krishna Vishal
6c5b95a8d7 Add get_values methods to ImmutableRecord 2025-07-14 03:28:54 +05:30
Krishna Vishal
35fa9b368c Decouple Value parsing and Record loading.
Introduced `RecordCursor`, using which we can parse the record
header incrementally.
2025-07-14 03:28:54 +05:30
Krishna Vishal
180bcc7b60 Add incremental and on-demand parsing of ImmutableRecord.
First step at resolving the currently wasteful eager parsing.
2025-07-14 03:28:54 +05:30
Zaid Humayun
9dd746d1ce fixes issues where double quotes are not removed from around table nam 2025-07-13 17:26:58 +05:30
Pekka Enberg
c454feeba4 Turso 0.1.2-pre.3 2025-07-13 12:55:02 +03:00
Jussi Saurio
5f6a7965cb Merge 'Fix clippy errors for Rust 1.88.0' from Nils Koch
I am currently working on upgrading Rust to the latest version
(https://github.com/tursodatabase/limbo/pull/1807). Initially, I wanted
to address all Clippy errors in that PR, but I decided to move them into
a separate one to make it easier to review.
**Note:** In the latest version of Clippy, it is considered an error to
place variables after a comma in string formatting macros (e.g.,
`format!`), rather than inside the `{}` placeholders. That's where most
of the errors are coming from.

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

Closes #1827
2025-07-12 19:36:05 +03:00
Jussi Saurio
a48b6d049a Another post-rebase clippy round with 1.88.0 2025-07-12 19:10:56 +03:00
Nils Koch
1a91966c7e fix clippy errors for rust 1.88.0 (manual fix) 2025-07-12 18:58:55 +03:00
Nils Koch
828d4f5016 fix clippy errors for rust 1.88.0 (auto fix) 2025-07-12 18:58:41 +03:00
Jussi Saurio
b68aaebe50 Merge 'sim: return LimboError::Busy when busy, instead of looping forever' from Jussi Saurio
Although concurrency doesn't work yet (#2059), we do want to support
concurrency, and one good first step is not to make the simulator hang
forever once any connection gets a `Busy` result from the VDBE
Closes #2060

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

Closes #2061
2025-07-12 10:34:21 +03:00
Jussi Saurio
cb16301157 sim: return LimboError::Busy when busy, instead of looping forever 2025-07-12 10:24:49 +03:00
Pekka Enberg
416ab28c2c Merge 'parse_schema_rows optimizations' from Levy A.
- Also added a benchmark for opening databases, the main thing that is
slowing `Database::open_file` is `parse_schema_rows`.
- `to_uppercase` was being called multiple times, leaving a relevant
mark on stack traces due to multiple allocations. `make_ascii_upper`
reuses the memory and is faster due to not handling unicode characters
(still compatible with sqlite).
- Do direct btree calls instead of creating a program for updating
`Schema` with `Schema::make_from_btree`.
- Faster type substr comparison using fixed size `u8` slices.
<img width="952" height="507" alt="image" src="https://github.com/user-
attachments/assets/0d0c52ff-05a1-431e-a93d-e333b53c0bb8" />

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

Closes #2042
2025-07-12 09:11:20 +03:00