Commit Graph

77 Commits

Author SHA1 Message Date
Bennett Clement
a85f47310c Move where clause literal out of loop 2024-07-14 14:00:25 +08:00
Bennett Clement
e9647bf425 Fix comments display 2024-07-14 13:50:21 +08:00
Pekka Enberg
0f0b88cbe7 Merge pull request #140 from benclmnt/feat/improve-explain-comments 2024-07-14 08:10:37 +03:00
Bennett Clement
d64733c0b9 Improve explain comments
- Resolve cursor ID to table name and get column name from index
- Since we change the type of BranchOffset to i64, add assertions in
  Program.step() function
- opcode generation compatibility with sqlite: change register number to start from 1
- Improve Column,Rowid comment, Add DecrJumpZero comment, Fix Integer
  comment
- Fix typos in code comments
2024-07-14 11:35:22 +08:00
jussisaurio
b288ac2b89 Optimize where clause bytecode 2024-07-14 01:30:09 +03:00
jussisaurio
851aea212d add coalesce(), refactor/rename add_label() 2024-07-13 23:03:56 +03:00
Pekka Enberg
9458522164 Merge pull request #134 from Ramkarthik/add-group-concat 2024-07-13 20:28:11 +03:00
Pere Diaz Bou
7601045122 core: clear references on resolve 2024-07-13 19:04:00 +02:00
Pere Diaz Bou
d0f37969ce core: matrix of labelsXinsnref instead of hashmap 2024-07-13 18:54:33 +02:00
Pere Diaz Bou
be387eb31c core: labels system and limit refactor
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-13 18:54:33 +02:00
Ramkarthik Krishnamurthy
dddc0be88f Some refactoring 2024-07-13 02:46:37 +05:30
Ramkarthik Krishnamurthy
a303e6ad96 Implements string_agg and extends group_concat to work with column delimiters 2024-07-13 02:13:28 +05:30
Ramkarthik Krishnamurthy
9268560a51 Implements group concat aggregate function 2024-07-13 00:55:40 +05:30
Pekka Enberg
f1bca597cb Merge pull request #121 from jussisaurio/where-clauses
Basic where clause support
2024-07-12 08:21:38 +03:00
jussisaurio
1b0aa568a4 Basic where clause support 2024-07-12 00:26:32 +03:00
Bennett Clement
e377e09498 Fix avg(), total(), count() default value on empty set 2024-07-12 00:20:44 +08:00
Bennett Clement
8a9eb74f9b Implement total() aggregation function
- Returns 0.0 when called on non integer / non float columns
- Always returns floating point number
- fix: default for sum() should be NULL when there is no non-NULL row
  per docs
2024-07-11 23:40:55 +08:00
Ramkarthik Krishnamurthy
f038c1c7d2 Indent only the opcode value 2024-07-11 16:19:23 +05:30
Pere Diaz Bou
538d624770 core: apply Real affinity on columns stored as int
Values in sqlite3, as expected, can be stored in different formats to
optimize disk usage. In this case, a 79.0 float will be transformed to a
u8.

sqlite3 deals with this by adding a RealAffinity op after each column
that might need it. Therefore, in this pr we do exactly that :).

Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-10 21:21:49 +02:00
Ramkarthik Krishnamurthy
ae68c96635 Indent EXPLAIN output like SQLite 2024-07-10 00:01:52 +05:30
mazchew
fc0c3d539a add min aggregate function
add changes for all.test
2024-07-09 03:14:02 +08:00
mazchew
3f339d07d3 add max aggregate function 2024-07-09 02:45:34 +08:00
Kunal Singh
00c26286ce fix: lint warnings 2024-07-08 22:43:11 +05:30
Vivek Khatri
fe7c1b5b1d Merge branch 'main' into add-agg-fn-count 2024-07-08 13:58:14 +05:30
Vivek
94358dc665 Add aggregate fn: count 2024-07-08 13:55:06 +05:30
Pekka Enberg
30ec86a81e Add sorter utility functions and opcodes
This adds basic in-memory sorting utility functions, similar to SQLite's
src/vdbesort.c. We need to improve this later with external sorting so
to support large data sets.

This also adds sorting functionality to the VDBE. Note that none of this
is wired to SQL translation yet so it's unused for now.
2024-07-07 13:56:55 +03:00
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