Commit Graph

867 Commits

Author SHA1 Message Date
jussisaurio
a108dea825 GROUP BY 2024-09-14 16:14:45 +03:00
jussisaurio
ba3de2af58 Merge 'Pass FuncCtx to Insn::Function to keep track of arg count' from Jussi Saurio
https://github.com/penberg/limbo/pull/321 recently fixed an error with
register allocation order concerning binary expressions in
`translate_condition_expr`. I noticed we had the same bug in
`translate_expr` as well, and this led into noticing that our
implementation of `Insn::Function` diverges from SQLite in that it
doesn't provide a context object that keeps track of how many arguments
the function call has.
Not having the arg count available at runtime means that e.g.:
```
do_execsql_test length-date-binary-expr {
  select length(date('now')) = 10;
} {1}
```
Returned 0 instead of 1, because at runtime another register was already
allocated, and `date()` was implemented like this:
```
                    Func::Scalar(ScalarFunc::Date) => {
                        let result = exec_date(&state.registers[*start_reg..]); // all registers starting from start_reg
                        state.registers[*dest] = result;
                        state.pc += 1;
                    }
```
SQlite bytecode engine docs for Function say:
> Invoke a user function (P4 is a pointer to an sqlite3_context object
that contains a pointer to the function to be run) with arguments taken
from register P2 and successors. The number of arguments is in the
sqlite3_context object that P4 points to.
Accordingly, this PR implements a `FuncCtx` struct that contains a
`Func` and `arg_count` (usize).

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

Closes #323
2024-09-14 16:12:25 +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
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
270193b953 use rustqlite 2024-09-13 09:15:55 +02:00
Pere Diaz Bou
acd0298ce9 rename core tester in cargo.toml 2024-09-13 07:56:21 +02:00
Pere Diaz Bou
77be4a1757 rename core_tester -> test 2024-09-13 07:55:07 +02: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
9791e2074f Fix cargo fmt complaint 2024-09-10 14:32:25 -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
Pekka Enberg
c3a57d4c24 Merge 'Add missing assertion to substring() test' from Lauri Virtanen
Closes #317
2024-09-10 16:25:01 +03:00
Lauri Virtanen
8048b4e655 Add missing assertion to substring() test 2024-09-08 19:31:27 +03:00
Pekka Enberg
0d04f0717f scripts/merge-pr.py: Don't wrap code blocks 2024-09-08 08:59:24 +03:00
Pere Diaz Bou
1ea496a169 core_tester: sequential btree write test
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-09-05 20:50:30 +02:00
Pere Diaz Bou
d87f9c9774 core: multiple level btree page split
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-09-05 20:50:30 +02:00
Pekka Enberg
ec94770d08 scripts/merge-pr.py: Wrap merge commit message to 72 columns 2024-09-05 19:26:03 +03:00
Pekka Enberg
74bd1ed8f4 github: Simplify stale workflow name 2024-09-05 19:10:15 +03:00
Pekka Enberg
fa5765fba3 github: Close stale pull requests automatically 2024-09-05 18:48:45 +03:00
Pekka Enberg
1e8197600c scripts/merge-pr.py: Generate reviewed-by tags 2024-09-04 10:48:12 +03:00
Pekka Enberg
4ff705868a Merge 'core: support modifiers in date function' from Sonny
solves #211. related to #158, #305

## Before
date(...) does not support modifiers

## After
date(...) supports modifiers

```
limbo> explain SELECT date('2023-05-18', '+1 days', '-1 days', '+10 days');
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     8     0                    0   Start at 8
1     String8            0     2     0     2023-05-18     0   r[2]='2023-05-18'
2     String8            0     3     0     +1 days        0   r[3]='+1 days'
3     String8            0     4     0     -1 days        0   r[4]='-1 days'
4     String8            0     5     0     +10 days       0   r[5]='+10 days'
5     Function           1     2     1     date           0   r[1]=func(r[2..])
6     ResultRow          1     1     0                    0   output=r[1]
7     Halt               0     0     0                    0
8     Transaction        0     0     0                    0
9     Goto               0     1     0                    0
```

Closes #315
2024-09-03 13:10:04 +03:00
Pekka Enberg
199f2524b0 Merge 'Initial pass on index lookup support' from Ajaya Agrawal
Adds support for parsing the manually created index structure into
memory. This PR sets the stage for supporting index lookup in later PRs.

Fixes: https://github.com/penberg/limbo/issues/314

Closes #312
2024-09-03 13:08:58 +03:00
sonhmai
9cc965186f core: support modifiers in date function 2024-09-03 14:28:07 +07:00
Ajaya Agrawal
84a1d29586 fix 2024-09-03 12:20:38 +05:30
Ajaya Agrawal
5861684d1c fix 2024-09-03 00:46:53 +05:30
Ajaya Agrawal
dcc99148d2 fix 2024-09-03 00:46:53 +05:30
Ajaya Agrawal
cb275feaa2 Index lookup support
Adds support for parsing index structure
2024-09-03 00:46:53 +05:30
Pekka Enberg
a81c570cce Update CHANGELOG.md 2024-09-02 14:30:33 +03:00
Pekka Enberg
68c6b4bfbe Merge 'Chores for Python binding development' from Lauri Virtanen
Chores for Python bindings development. Follow-up for PR #298.

Key things:

 - Run tests for current multiple Python versions
 - Format Python code with Ruff and check format in CI workflow
 - Check requirements[-dev].txt correctness in CI workflow
 - Add basic Makefile for Python commands

Relates to #248

Closes #311
2024-09-02 14:30:01 +03:00
Lauri Virtanen
a09c6ef493 Add Makefile for Python bindings 2024-09-01 16:11:00 +03:00
Lauri Virtanen
9cb2164bfa Remove black and isort (replaced with Ruff) 2024-09-01 16:10:59 +03:00
Lauri Virtanen
826a2629d1 Check requirements.txt files in Python workflow 2024-09-01 16:10:59 +03:00
Lauri Virtanen
6bd1d28e26 Format Python bindings code using Ruff
- Use double quotes (Ruff/Black default)
- Configure some set of linters to use with Ruff
2024-09-01 16:10:59 +03:00
Lauri Virtanen
4738d16c6f Run Ruff checks in dedicated workflow job 2024-09-01 16:10:24 +03:00
Lauri Virtanen
c5218e2f79 Run Python tests for versions 3.8 to 3.12
Match Python versions in GitHub workflow and pyproject.toml.

Format workflow YAML and rename steps.

Checkout using `actions/checkout@v4`.

Disable pip version checking in Python workflow to suppress warnings on
older Python versions.
2024-09-01 13:28:38 +03:00
Pekka Enberg
f2235147c0 Add Discord link to README.md 2024-08-31 12:02:37 +03:00
Pekka Enberg
525f8600ca Merge 'Implement the UnixEpoch function' from Rajiv Harlalka
Adds the UnixEpoch function. #158  (without modifiers)

Closes #273
2024-08-30 18:26:16 +03:00
Rajiv Harlalka
b30974d2d2 update COMPAT.md
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:35:12 +05:30
Rajiv Harlalka
3447a553e1 chore: move tests
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:34:48 +05:30
Rajiv Harlalka
0b5b0a426d remove redundant comment
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:28:37 +05:30
Rajiv Harlalka
e2013b0ef6 add unixepoch tests
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:28:35 +05:30
Rajiv Harlalka
1de974253b add support for custom date time value as first parameter
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:27:59 +05:30
Rajiv Harlalka
6684fb46e4 FEAT: Implement the unixepoch function
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:27:58 +05:30