Commit Graph

51 Commits

Author SHA1 Message Date
Pekka Enberg
c7a67a1bf4 Fix ResultRow operands
Fix ResultRow operands to follow SQLite bytecode format for consistency.
2024-07-05 18:13:06 +03:00
Pekka Enberg
2f3c3b5404 Clean up insn_to_str()
The SQLite documentation explicitly says that P1, P2, and P3 are 32-bit
signed integers. P4 is a value, and P5 is a 16-bit unsigned integer.
Although we use different types for operands, the `EXPLAIN` output
should be compatible with SQLite and, therefore, use those types.
2024-07-05 11:39:21 +03:00
Pere Diaz Bou
ae524a07e2 core: Insn::Real support
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-04 17:19:05 +02:00
Pekka Enberg
e988ca0129 Consolidate AggregateFunction and AggFunc enums 2024-07-04 12:19:17 +03:00
Pekka Enberg
400c5210b2 Remove unreachable patterns 2024-07-03 11:41:31 +03:00
Pere Diaz Bou
56badf2513 core: fix initialization of sum vdbe
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-01 20:30:45 +02:00
Pere Diaz Bou
271397b214 core: sum aggregation
```
Welcome to Limbo SQL shell!
> select sum(age), avg(age) from users;
504915|50.4915
>
fedora :: ~/fun/limbo » sqlite3 database.db
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> select sum(age), avg(age) from users;
504915|50.4915
```

Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-01 20:19:50 +02:00
Pere Diaz Bou
18c2f5f8d2 core: clean up warnings
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-06-30 12:48:19 +02:00
Pere Diaz Bou
c7d40806fd core: Avg aggregation function
Simple implementation for aggregation functions. The code added is
purposely so that we can add things like `CEILING(avg(n))` in the future. Aggregation function
impose a higher level of complexity that requires us to plan ahead
several things:

* simple avg: `select avg(id) from users`
* nested avg: `select ceiling(avg(id)) from users`
* avg with other columns: `select ceiling(avg(id)), * from users` (yes,
  this is valid sqllite). For now I'm nullifying extra columns for
  simplicity.
* avg with other agg functions: `select avg(id), sum(id) from users`.
  This should be supported.
* At last -- Order By is a painful enough case to treat alone (not done
  in this pr)

Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-06-30 12:48:19 +02:00
Pekka Enberg
df230dc830 Fix DecrJumpZero usage in translate_select()
SQLite special-cases `LIMIT 0` by emitting an explicit `Goto` to avoid
executing any `ResultRow` statements. We, however, hacked around this in
DecrJumpZero but also the placement of the generated instruction.

Let's follow SQLite codegen here. We still need to fix `LIMIT 0`,
though.
2024-06-24 21:43:19 +03:00
Pere Diaz Bou
932ae7bf3f core: update pragma in transalte 2024-06-19 20:37:17 +02:00
Pere Diaz Bou
d795a7a3ba core: introduce pseudo program with pragma
Introduced pragma statement parsing and update in memory of default page cache size.

There are some more "improvements" to the print insn procedure —  I couldn't decide what was the preferred way in rust to do printing on different int types so I went with the stupidest I could think of at the moment.
2024-06-19 20:32:21 +02:00
Pere Diaz Bou
377073e158 core: I/O write path 2024-06-19 21:26:40 +03:00
Pekka Enberg
3f722d5827 core: Extract make_record() function 2024-05-09 07:48:49 -03:00
Pekka Enberg
3afc03cc65 Fix String8 opcode handling 2024-05-08 15:51:10 -03:00
Pekka Enberg
5c0f324b3c Improve EXPLAIN output 2024-05-08 14:22:38 -03:00
Pekka Enberg
08165fc34e core: SELECT <string> support 2024-05-08 07:18:22 -03:00
Pekka Enberg
40e5d58cea Fix RewindAwait branching when cursor is empty
Even if we have a page, the cursor can still be empty if there are no
records.
2024-05-07 06:46:03 -03:00
Pekka Enberg
a447ea0f49 Dynamic cursor ID allocation
With sorter, for example, we need more cursors per program.
2024-03-29 09:26:18 +02:00
Pekka Enberg
9a73ded4fa Add a Cursor trait and use it
We need an abstract cursor trait to implement a sorter, for example.
2024-03-28 15:01:52 +02:00
Pekka Enberg
ed9f3e6d1e Single-threaded architecture
Use Rc instead of Arc and replace the concurrent LRU with
single-threaded SIEVE.

Fixes #23
Fixes #29
2024-03-03 12:44:45 +02:00
Pekka Enberg
e0dc9dc86d Optimize trace_insn() 2024-01-28 13:14:39 +02:00
Pekka Enberg
225ee98769 cargo fmt 2024-01-28 09:58:04 +02:00
Pekka Enberg
505e28aaeb Reduce memory allocations
Fixes #26
2024-01-28 09:57:12 +02:00
Pekka Enberg
0b9b6cfd29 Asynchronous I/O 2024-01-24 08:14:53 +02:00
Pekka Enberg
ae2f403838 core: Fix step() return path when page is under I/O 2024-01-12 17:35:55 +02:00
Pekka Enberg
e08d23a008 Implement LIMIT clause
Note that we handle `LIMIT 0` a bit different from SQLite, which just
detects the case and generates an unconditional jump doing nothing.

Fixes #3
2023-09-10 13:42:57 +03:00
Pekka Enberg
a2202ed31e Implement reading primary key columns 2023-09-10 13:19:17 +03:00
Pekka Enberg
e38c816ee8 Move translate() into its own file 2023-09-10 12:37:17 +03:00
Pekka Enberg
f6f1f97171 Switch cursor lookup to use BTreeMap
We're storing integers into the HashMap, BTreeMap is faster because
it avoid the hash function. Furthermore, we expect only to have very few
cursors here anyway, so BTreeMap is perfect.
2023-09-02 20:59:22 +03:00
Pekka Enberg
942239fab1 Simplify ProgramState register allocation
...it's faster this way.
2023-09-02 20:55:20 +03:00
Pekka Enberg
ef0c4f69cc Allocate vector with capacity
...reduces memory allocations.
2023-09-02 13:59:41 +03:00
Pekka Enberg
2c84aae66d Fix instruction tracing performance 2023-09-02 13:55:26 +03:00
Pekka Enberg
37baae3ed7 Benchmark 2023-09-02 13:43:07 +03:00
Pekka Enberg
ae709f04fe Make some opcodes wait for completion 2023-09-02 13:26:44 +03:00
Pekka Enberg
3ec9c0be7c Implement ResultRow opcode 2023-09-02 11:40:11 +03:00
Pekka Enberg
6e748a066e Register allocation 2023-09-02 08:52:30 +03:00
Pekka Enberg
fa51955b43 VDBE improvements 2023-09-02 08:46:01 +03:00
Pekka Enberg
4c64590a5c Decouple Program and ProgramState 2023-09-02 08:18:05 +03:00
Pekka Enberg
14fb12ecdf Translate SQL SELECT column values 2023-09-01 21:26:12 +03:00
Pekka Enberg
591e8df377 Disable tracing by default 2023-09-01 19:49:54 +03:00
Pekka Enberg
4b714311b5 Improve Column instruction 2023-08-31 22:05:05 +03:00
Pekka Enberg
b25f8c4daf Implement Cursor::next() 2023-08-31 21:45:04 +03:00
Pekka Enberg
05621e3286 Cursors 2023-08-30 20:26:15 +03:00
Pekka Enberg
7c100ea217 Query sqlite_schema table 2023-08-29 19:46:07 +03:00
Pekka Enberg
b40438f778 Make EXPLAIN output more similar to SQLite 2023-08-27 21:21:42 +03:00
Pekka Enberg
9d7286bde0 Remove unused import 2023-08-27 21:19:43 +03:00
Pekka Enberg
6f1d03d64d Look up columns from table schema 2023-08-27 21:18:17 +03:00
Pekka Enberg
3b53f48400 Look up table root page from schema 2023-08-27 21:11:49 +03:00
Pekka Enberg
2615cdce2c Schema in-memory data structures 2023-08-27 20:40:35 +03:00