Commit Graph

1583 Commits

Author SHA1 Message Date
Pekka Enberg
e4d4e5cd5d Merge 'Streamline dependencies to build for all wasm targets' from Doug A
In order [experimentally
compile](https://github.com/DougAnderson444/wit-limbo) `limbo_core` to a
[wasm component](https://component-model.bytecodealliance.org/), limbo
needed to have no reliance on `js`, `js-sys`, `wasm-bindgen`, et al.
(for those who aren't familiar, there are many `wasm` runtimes and not
all of them play nice with `wasm-bindgen`)
This PR simply cleans up the dependencies, and puts them behind optional
flags and whatnot in order to enable this. Both `log` and `tracing` were
being used, so I reduced this only to `tracing`.
End result is limbo can be used like this:
https://github.com/DougAnderson444/wit-limbo
We can open a discussion on the possibilities that running limbo as a
wasm component can offer, including potentially using composable
components to implement the sqlite runtime extensions, as well as giving
us a clean interface for PlatformIO operations -- define them once,
implement many ways on various platforms. I'm new to limbo, but it looks
like current extension are Rust based deps and features flags, whereas
sqlite is runtime, right? What if limbo was runtime extensible too?
The WIT interface is largely sync (though I believe wasmtime has an
async feature), but in my limited exposure to limbo so far a lot of the
wasm seems sync already anyway. Again, topic for further discussion.
Suffice to say, aligning these deps in this way paves the road for
further experiments and possibilities.
Related: https://github.com/neilg63/julian_day_converter/pull/2
Related: https://github.com/tursodatabase/limbo/issues/950
Closes: https://github.com/tursodatabase/limbo/issues/950

Closes #983
2025-02-12 09:24:04 +02:00
Doug Anderson444
2566577b70 libc dep only when io_uring feature 2025-02-11 09:06:26 -04:00
Doug Anderson444
39c3b135e3 make all serde optional
to reduce dep size
2025-02-11 09:05:34 -04:00
Doug Anderson444
0aa5de6d9f rm log, switch all to tracing 2025-02-11 09:03:36 -04:00
wyhaya
351a032cc1 core: Add default column name 2025-02-11 07:03:51 +00:00
Doug Anderson444
3734870c6b rm old julian dep 2025-02-10 22:00:18 -04:00
Doug Anderson444
0423945803 restrict chrono to no-dfault-features, update julian_day_converter
chrono has default features that are incompatible with some targets, such as non-js WebAssembly.

Removing the unused defaults allows limbo to compile to these targets
2025-02-10 21:58:34 -04:00
Pekka Enberg
1da43266e9 Merge 'Json path refine' from Ihor Andrianov
Hey! I've rebuilt the JSON path parser to make it easier to maintain and
catch more edge cases.
Main stuff:
- Removed pest dependency in favor of hand-written parser
- Better memory usage (pre-allocates space, use Cow)
- Handles quoted keys properly now
- Added tests for weird edge cases
- Added PPState (Shoutout ThePrimeagen)

Closes #970
2025-02-10 19:39:20 +02:00
Ihor Andrianov
b8b0f860d7 clippy 2025-02-10 15:34:47 +02:00
Ihor Andrianov
aad0522f56 refactor to make parser more readable 2025-02-10 15:13:36 +02:00
Ihor Andrianov
a10955cbcf refine quoted key handling, add RawString option for SQLite compat 2025-02-10 15:12:07 +02:00
Ihor Andrianov
ee16c49c6c add support for quoted path 2025-02-10 15:09:27 +02:00
Ihor Andrianov
f84a6b878a fixed edge cases and add some tests, remove pest grammar 2025-02-10 15:09:26 +02:00
Ihor Andrianov
166532cc81 simplify json path parsing 2025-02-10 15:09:23 +02:00
l.gualtieri
3487969c40 fix floating point numbers get truncated in json #877 2025-02-10 12:23:43 +01:00
Pekka Enberg
8f49024dd1 Fix build_text() call site to use new API 2025-02-10 13:07:19 +02:00
Pekka Enberg
5205c23eed Merge 'Initial support for WITH clauses (common table expressions)' from Jussi Saurio
Adds initial limited support for CTEs.
- No MATERIALIZED
- No RECURSIVE
- No named CTE columns
- Only SELECT statements supported inside CTE
Basically this kind of WITH clause can just be rewritten as a subquery,
so this PR adds some plumbing to rewrite them using the existing
subquery machinery.
It also introduces the concept of a `Scope` where a child query can
refer to its parent, useful for CTEs like:
```
do_execsql_test nested-subquery-cte {
    with nested_sub as (
        select concat(name, '!!!') as loud_hat
        from products where name = 'hat'
    ),
    sub as (
        select upper(nested_sub.loud_hat) as loudest_hat from nested_sub
    )
    select sub.loudest_hat from sub;
} {HAT!!!}
```
I think we need to expand the use of `Scope` to all of our identifier
resolutions (currently we don't explicitly have logic for determining
what a given query can see), but I didn't want to bloat the PR too much.
Hence, this implementation is probably full of all sorts of bugs, but
I've added equivalent tests for ALL the existing subquery tests,
rewritten in CTE form.

Closes #920
2025-02-10 12:15:07 +02:00
Pekka Enberg
d221f158cc Merge 'Add read implementation of user_version pragma with ReadCookie opcode' from Jonathan Webb
Just a bare bones implementation of ReadCookie and support for the
user_version pragma

Closes #909
2025-02-10 12:12:15 +02:00
Pekka Enberg
0638550be7 Merge 'Remove unnecessary reference counting from completion I/O callbacks' from Preston Thorpe
I am on a bit of a mission to revisit a lot of the ref counting, this
was an easy first win.
It seems to be a linear path of function calls or hashmaps which can own
the completions directly, no cloning needed.

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

Closes #912
2025-02-10 12:11:30 +02:00
Pekka Enberg
604ca4085d Merge 'Make record values private' from Tiago
This is an attempt to move towards #881. I am not sure this is the
direction you want to take. In any case, I thought I would take a crack
at converting `values` from `Record` to private and see how bad it would
be.
In the end, as you can see, it is not so bad. I think performance-wise
it shouldn't be a bad hit with Rust's zero-cost abstraction. Also,
during the process I noticed a couple improvements that could be made
here and there but I honestly wanted to start with something small
enough that wouldn't be too hard to review.
Anyway, let me know if this is really how you would like to proceed.

Closes #962
2025-02-10 11:23:21 +02:00
Pekka Enberg
fcad8d125e Merge 'refactor: remove RC<String> requirement for build_text and new text' from Pedro Muniz
This PR aims to simplify text creation and to reduce allocation overhead
of creating a new OwnedValue::Text. Instead of creating Rc<String> every
time you need to create a text, you just pass the string slice and the
Rc<String> is created at the end. This change, at least on my machine,
has removed a lot of variability in the benchmarking performance, while
maintaining roughly the same performance.

Closes #961
2025-02-10 11:21:50 +02:00
Pekka Enberg
00a546e775 Merge 'Fix string funcs' from Nikita Sivukhin
Add fuzz test for string functions and fix 2 bugs in implementation of
`LTRIM/RTRIM/TRIM` and `QUOTE`:
- `QUOTE` needs to escape internal quote(`'`) symbols
- `LTRIM`/`RTRIM`/`TRIM` needs to check if they have additional argument

Closes #958
2025-02-10 11:17:51 +02:00
Pekka Enberg
55058cade3 Merge 'Fix cast' from Nikita Sivukhin
Fix codegen for `CAST` expression and also adjust implementation of
`CAST: Real -> Int` because `SQLite` use "closest integer between the
REAL value and zero" as a CAST result.

Closes #956
2025-02-10 10:53:56 +02:00
Pekka Enberg
09b402e261 Merge 'Fix coalesce' from Nikita Sivukhin
Add `COALESCE` function in fuzz test and fix bug (found by fuzzer with
`COALESCE`) related to the resolution of labels which needs to be
resolved to next emitted instruction.
Before, code assumed that no two labels will need to be resolved to next
emitted instruction. But this assumption is wrong (at least in current
codegen logic) for example for following expression `COALESCE(0,
COALESCE(0, 0))`. Here, both `COALESCE` functions will create label and
resolve it to next emitted instruction in the end of generation. So, in
this case one of the labels will be actually "orphaned" and never be
assigned any position in the emitted code.

Closes #955
2025-02-10 10:53:44 +02:00
Pekka Enberg
31886e8f4c Merge 'Fix case and emit' from Nikita Sivukhin
(after fixing complicated b-tree bugs - I want to end my day with the
joy of fixing simple bugs)
This PR fix bug in emit (which was introduced after switch from
`HashMap` to `Vec`) and also align `CASE` codegen in case of `NULL`
result from `WHEN` clause with SQLite behaviour.

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

Closes #953
2025-02-10 10:53:31 +02:00
Tiago Ribeiro
295691d81b Update core/vdbe to use the new retrieval methods to access Record values. 2025-02-10 00:27:51 -07:00
Tiago Ribeiro
af12036e88 Update core/storage/btree.rs to use the new retrieval methods to access Record values. 2025-02-10 00:27:51 -07:00
Tiago Ribeiro
510a7b033a Make the Record.values attribute private and add method to retrieve it. 2025-02-10 00:27:50 -07:00
Pekka Enberg
bad5f2cad3 Merge 'Fix a handful of typos' from Aarni Koskela
I noticed the README had a prominent typo ("workin on"), so I decided to
run [crate-ci/typos](https://github.com/crate-ci/typos) on the repo and
fix what it flagged.

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

Closes #952
2025-02-10 07:41:01 +02:00
Pekka Enberg
2eda8a54d9 Merge 'Fix various bugs in B-Tree handling' from Nikita Sivukhin
This PR introduce simple fuzz test for BTree insertion algorithm and
fixes few bugs found by fuzzer
- BTree algorithm returned early although there were overflow pages on
stack and more rebalances were needed
- BTree balancing algorithm worked under assumption that single page
will be enough for rebalance - although this is not always true (if page
were tightly packed with relatively big cells, insertion of new very big
cell can require 3 split pages to distribute the content between them)
- `overflow_cells` wasn't cleared properly during rebalancing
- insertions of dividers to the parent node were implemented incorrectly
- `defragment_page` didn't reset
`PAGE_HEADER_OFFSET_FRAGMENTED_BYTES_COUNT` field which can lead to
suboptimal usage of pages

Closes #951
2025-02-10 07:40:27 +02:00
Pekka Enberg
e559b0c4b3 Merge 'Expose types in Wal' from Jorge López Tello
We expose Wal trait as public, but there are three types in its
signature that are private.
Notice I chose to expose limbo_core::result instead of
limbo_core::result::LimboResult, since LimboResult is the only type in
that module.

Closes #939
2025-02-10 07:38:59 +02:00
pedrocarlo
41360075ba cargo clippy 2025-02-10 00:59:20 -03:00
Nikita Sivukhin
7cdad64a5f fix assertion in test_quote 2025-02-09 23:50:11 +04:00
Nikita Sivukhin
cd4bfac059 fix quote functions 2025-02-09 23:43:34 +04:00
Nikita Sivukhin
cc7267b0bd fix trim function pattern handling 2025-02-09 23:43:34 +04:00
Nikita Sivukhin
5773f767af fix bug after refactoring in LIKE and GLOB 2025-02-09 23:42:53 +04:00
Nikita Sivukhin
a744dd8419 translate_and_mark helper with its previous signature is error prone - so replace it with more explicit option which accept target register 2025-02-09 23:18:46 +04:00
Nikita Sivukhin
a37b74666f remove unnecessary floor() 2025-02-09 22:41:08 +04:00
Nikita Sivukhin
3c4d9a93af fix rounding of REAL to INTEGER
- SQLite rounds (x: f64) to the nearest number between x and 0 - so
  basically truncates the x
2025-02-09 22:32:54 +04:00
Nikita Sivukhin
dff1fdc853 fix codegen of CAST 2025-02-09 22:20:28 +04:00
Nikita Sivukhin
cf59771599 allow multiple labels to be resolved as next emitted instruction
- right-nested expression can generate multiple labels which needs to be
  resolved to next generated instruction
- for example, COALESCE(0, COALESCE(0, 1))
2025-02-09 21:54:48 +04:00
Nikita Sivukhin
a61736bec1 adjust evaluation of NULL results in WHEN clauses with SQLite spec 2025-02-09 21:33:54 +04:00
Nikita Sivukhin
6d67016492 fix bug after switch from HashMap to Vec 2025-02-09 21:33:37 +04:00
pedrocarlo
fe453ecfc5 remove RC<String> requirement for build_text and new text 2025-02-09 13:44:39 -03:00
Aarni Koskela
eaea02c567 Fix a handful of typos 2025-02-09 18:08:29 +02:00
Pekka Enberg
728e8ca4f1 Merge 'chore: remove unused dependencies' from meteorgan
remove unused dependencies

Closes #948
2025-02-09 17:36:18 +02:00
Nikita Sivukhin
1b9772e9ad fix clippy 2025-02-09 19:36:14 +04:00
Pekka Enberg
9e65d7ddea Merge 'perf/prepare: box even more stuff to shrink the YYMINORTYPE enum further' from Jussi Saurio
the boxings will continue until morale improves
<img width="621" alt="Screenshot 2025-02-09 at 14 16 21"
src="https://github.com/user-
attachments/assets/887d218d-3db7-4a64-ad81-b7431adb23bb" />

Closes #947
2025-02-09 17:36:03 +02:00
Nikita Sivukhin
32b5b0d019 introduce additional condition for cells distribution in order to avoid almost empty pages 2025-02-09 19:26:03 +04:00
Nikita Sivukhin
bc289d314a adjust test a bit 2025-02-09 19:20:48 +04:00