Commit Graph

556 Commits

Author SHA1 Message Date
jussisaurio
c738674c5d Merge 'fix: cmp integer/float' from Jean Arhancet
Closes https://github.com/penberg/limbo/issues/339

Reviewed-by: Lauri Virtanen <pere-altea@hotmail.com>

Closes #340
2024-09-21 18:06:04 +03:00
JeanArhancet
41c1708ee7 fix: cmp integer/float 2024-09-21 16:10:42 +02:00
Lauri Virtanen
67573e12e5 Add typeof(X) scalar function 2024-09-21 15:56:29 +03:00
김선우
bbd1eea9ae Add support for parenthesized conditions 2024-09-21 16:03:49 +09:00
Pekka Enberg
b67640c437 Merge 'core: constraint check uniqueness' from Pere Diaz Bou
```bash
limbo> insert into products values (1, 'asdf', 432);
Runtime error: UNIQUE constraint failed: products.id (19)
```

Closes #336
2024-09-20 13:27:10 +03:00
Pere Diaz Bou
c8e5673f7a core: constraint check uniqueness 2024-09-20 11:45:55 +02:00
김선우
f7304a15a6 Fix clippy 2024-09-18 17:59:11 +09:00
김선우
e9ba458514 Add support for sqlite_version 2024-09-18 17:57:51 +09:00
Pekka Enberg
a8b8c1d2c9 Merge 'Fix clippy ' from Kim Seon Woo
### Changes
- Remove clippy warning messages
- Add `#[allow(clippy...)]` in places where it might be better not to
fix
### TODO
recommended changes by `cargo fmt` on my local and github differs on
`sqlite3/src/lib.rs`. Should check for the reason
=> just upgrade the rust toolchain

Closes #329
2024-09-18 09:46:07 +03:00
Pekka Enberg
e364d10d9a Merge 'Implementation of scalar function glob() and GLOB operator' from RJ Barman
Related to #144
- Separates `glob` and `like` regex caches, since the same pattern would
result in a different regex depending on which rules you apply
- Also fixes the value of `constant_mask` when translating LIKE
expressions now that non-constant pattern values are supported.
Note that LIKE and GLOB are almost entirely the same, the only
difference being the matching rules (so in our case, the regex
construction).

Closes #334
2024-09-18 09:44:51 +03:00
rjhallsted
f6b7a3fba4 Remove duplication of glob and like translation 2024-09-16 16:31:37 -07:00
rjhallsted
338effa0ca Separate glob and like regex caches 2024-09-16 16:22:31 -07:00
rjhallsted
af09f0b7f4 Add testing 2024-09-16 16:18:26 -07:00
rjhallsted
f39dc534a6 add glob execution 2024-09-16 16:12:53 -07:00
rjhallsted
b87b874ed0 WIP commit on glob support 2024-09-16 15:51:32 -07:00
rjhallsted
4aaa0b0989 Make LIKE expressions case-insensitive 2024-09-16 14:43:39 -07:00
김선우
b68efa32d9 Merge branch 'main' into feature/fix-clippy 2024-09-16 21:58:07 +09:00
Pekka Enberg
9bbfdab5fa Revert "Merge 'Add support for sqlite_version() scalar function' from Kim Seon Woo"
This reverts commit e365c12ce0, reversing
changes made to 21bd1a961e. The pull request broke some tests:

```
thread 'main' panicked at core/vdbe/mod.rs:1713:72:
index out of bounds: the len is 3 but the index is 3
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    while executing
"exec {*}$command"
    (procedure "evaluate_sql" line 3)
    invoked from within
"evaluate_sql $sqlite_exec $sql"
    (procedure "run_test" line 2)
    invoked from within
"run_test $::sqlite_exec $combined_sql $combined_expected_output"
    (procedure "do_execsql_test" line 5)
    invoked from within
"do_execsql_test sqlite_version {
  SELECT sqlite_version();
} {3.46.1}"
    (file "./testing/scalar-functions.test" line 434)
    invoked from within
"source $testdir/scalar-functions.test"
    (file "./testing/all.test" line 16)
make: *** [Makefile:59: test-compat] Error 1
```
2024-09-16 14:28:18 +03:00
Pekka Enberg
e365c12ce0 Merge 'Add support for sqlite_version() scalar function' from Kim Seon Woo
### sqlite
<img width="792" alt="image" src="https://github.com/user-
attachments/assets/1a9238db-d948-4583-a808-f9adfec7c534">
### limbo
<img width="809" alt="image" src="https://github.com/user-
attachments/assets/ea3e5f7e-bb3e-450d-be34-59ca00128beb">
### Changes
- Add support for `sqlite_version()` function
- Update function's explain message depending on the number of arguments

Closes #331
2024-09-16 14:18:19 +03:00
Pekka Enberg
21bd1a961e Merge 'Fix three issues with LIKE operator (#319)' from Jussi Saurio
Closes #319
1. Allow using a column as the pattern
2. Construct LIKE regexes with `^` and `$` so that eg the string
`'foobar'` does not match the pattern `'fooba'` unless the pattern
specifically has a wildcard
3. Support function expressions as the LIKE pattern

Closes #327
2024-09-16 14:17:48 +03:00
Pekka Enberg
95987f9824 Merge 'Support grouping by a function expression' from Jussi Saurio
Closes #326
2024-09-16 14:17:03 +03:00
김선우
469f345c16 Fix explain message for function depending on the number of args 2024-09-16 18:47:53 +09:00
김선우
6b40acabbc Add support for sqlite_version() scalar function 2024-09-16 18:38:42 +09:00
김선우
f592ed15c1 Add test to verify root and leaf splitting 2024-09-16 16:50:30 +09:00
JeanArhancet
d03a734f21 feat: add sign function 2024-09-15 14:57:01 +02:00
김선우
07c4ca9edd Nit 2024-09-15 17:16:33 +09:00
김선우
28884181be Fix clippy 2024-09-15 16:23:27 +09:00
jussisaurio
3f0162c76c Support grouping by a function expression 2024-09-15 09:58:46 +03:00
jussisaurio
6b8cd02f71 Fix function expressions in like pattern not working 2024-09-15 09:57:54 +03:00
jussisaurio
234c56ca81 Fix two issues with LIKE operator (#319) 2024-09-15 09:57:54 +03:00
jussisaurio
b6e88ca883 cargo clippy --fix --allow-dirty && cargo fmt 2024-09-15 09:35:39 +03:00
김선우
8b3e4da8da Apply comments
- Specify the number of arguments using arg_count
- Add test for concat_ws
2024-09-15 10:04:30 +09:00
김선우
fc07ca9d73 Add support for concat_ws 2024-09-14 23:47:45 +09:00
Pekka Enberg
2395ed2b71 Merge 'core,btree: support overflow pages' from Pere Diaz Bou
This PR adds support for traversing overflow payloads and inserting them
too. The test added is a simple one and must be tested with higher
degree of stress in the future.

Closes #322
2024-09-14 16:35:02 +03:00
jussisaurio
a108dea825 GROUP BY 2024-09-14 16:14:45 +03:00
jussisaurio
0839211a49 Pass FuncCtx to Insn::Function to keep track of arg count 2024-09-14 12:38:14 +03:00
Pekka Enberg
f67b915855 Merge 'Allocate the right-hand-side register for a binary expression after translating the left-hand-side' from RJ Barman
I found a bug in queries using a like function in the where clause, ex:
`SELECT first_name, last_name FROM users WHERE like('Jas%', first_name)
= 1`.  That panicked with the message:
```
thread 'main' panicked at core/vdbe/mod.rs:1226:33:
internal error: entered unreachable code: Like on non-text registers
```
This was caused by an off-by-one error in the vdbe code for executing a
`ScalarFunc::Like`. However, this only happened in where-like-fn
queries. Queries using the like operator (ex: `SELECT first_name,
last_name FROM users WHERE first_name LIKE 'Jas%'`) did not have this
problem.
I did some digging around, looked at the explains for these queries from
both limbo and sqlite, and it turns out, for binary expressions, limbo
positions the arguments in the register differently, which is the
ultimate root cause of this problem.
For the where-like-fn query, before execution limbo's registers look
like this:
```
[Null, Null, Integer(1), Text("Jas%"), Text("Jason"), Null, Null]
                  ^the rhs 1  ^pattern         ^haystack str
```
Sqlite's look look something like this:
```
[Null, Null, Text("Jas%"), Text("Jason"), Integer(1), Null, Null]
                   ^pattern        ^haystack str  ^the rhs 1
```
Ultimately limbo's execution of scalar like function was looking in
positions 2 and 3 always, but because we stored the right-hand-side
before the like-fn arguments, there was an off-by-one error, and the
non-text register it was finding was the `Integer(1)`.
This PR changes the binary expression translation to allocate the right-
hand-side register *after* translating the left-hand-side, fixing the
off-by-one and matching sqlite's register layout.

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

Closes #321
2024-09-14 08:29:43 +03:00
Pere Diaz Bou
6f30b67ec4 fix overflow range read 2024-09-13 21:34:45 +02:00
Pere Diaz Bou
e9bc4b04a7 overflow pages support 2024-09-13 20:32:33 +02:00
Pere Diaz Bou
4316a5f4c3 simplify filling a cell 2024-09-13 11:39:03 +02:00
Pekka Enberg
59baa209f9 Merge 'core: core btree splitting' from Pere Diaz Bou
This pr adds a new crate to increase expressivity of tests with complex
things like btree node splitting.
To run tests:
```bash
cd core_tester
cargo test test_sequential_write -- --nocapture
```
This prs improves btree balancing with simple page splitting and some
minor refactors.

Closes #316
2024-09-13 10:29:43 +03:00
Pere Diaz Bou
9d1bb4d4ea get_mem_page 2024-09-13 07:24:34 +02:00
rjhallsted
dc3d3a492a Fix register positions of binary expression arguments to fix where-like-fn case 2024-09-12 12:03:27 -07:00
Pekka Enberg
b7926dfe7c Merge 'Cache LIKE regexes' from RJ Barman
This PR adds a regex cache to `ProgramState` so that we ca re-use
already constructed regexes while processing LIKE expressions. I didn't
find anywhere else that seemed like a good fit to put an execution-time
only cache like this, so let me know if there's a better spot.
To best match sqlite, I added the constant mask into the `Function`
instruction (this indicates whether the first argument to the function
was determined to be constant at compile time), and decide whether to
use the cache based on its value. I've left the value for
`constant_mask` as 0 on every other kind of `Function` instruction. That
seemed to be the safest choice, as that appears to be what has been
implicitly done up to this point. Happy to change that if you'd advise
otherwise.

Fixes #168
Closes #320
2024-09-12 16:57:57 +03:00
rjhallsted
e67f1e910e Functionally meaningless change to get cargo fmt to play nice in ci 2024-09-10 14:40:57 -07:00
rjhallsted
960560dffc Use the same comment for Expr::Like case 2024-09-10 14:26:21 -07:00
rjhallsted
a038d1f700 Add comment on why constant_mask is 1 in ScalarFunc::Like case 2024-09-10 14:24:32 -07:00
rjhallsted
e1b134dd88 Fix the spot that constant_mask was being set to 1 2024-09-10 14:08:15 -07:00
rjhallsted
6ac78dfb03 Cache constructed LIKE regexes if FUNCTION P1 is set 2024-09-10 13:54:52 -07:00
rjhallsted
9f18fdbfd2 Remove unecessary clone when executing LIKE function 2024-09-10 11:25:52 -07:00