Commit Graph

91 Commits

Author SHA1 Message Date
Pekka Enberg
ad70a240d4 Merge pull request #147 from benclmnt/feat/where-and 2024-07-16 21:35:01 +03:00
Bennett Clement
3c4f2b07e6 Respect jump_if_true in like implementation 2024-07-16 18:17:37 +08:00
Bennett Clement
6f983702c3 Refactor if/ifnot implementation 2024-07-16 16:36:30 +08:00
Bennett Clement
05558527af Implement like in where clause 2024-07-16 15:55:33 +08:00
Bennett Clement
2f738e0c8b Implement like function 2024-07-16 15:23:52 +08:00
Bennett Clement
1df2ee6683 Fix real explain format 2024-07-16 13:29:47 +08:00
Bennett Clement
4d077cf3e5 Implement std::cmp::PartialOrd for OwnedValue 2024-07-16 08:32:14 +08:00
Bennett Clement
fdf77cee2b Merge branch 'main' of github.com:benclmnt/limbo into feat/where-and 2024-07-16 08:10:24 +08:00
Pere Diaz Bou
0a7d0588d7 core: implement AND and OR + complex conditions.
this also fixes NULL print to empty string

Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-15 19:42:12 +02:00
Bennett Clement
f955187b70 Implement where and 2024-07-15 23:36:35 +08:00
jussisaurio
ea793e4126 Inner join, table aliases, qualified column names 2024-07-14 20:09:40 +03:00
Pekka Enberg
99a6ca4f2f Merge pull request #142 from imor/clippy_fixes 2024-07-14 20:00:10 +03:00
Bennett Clement
72f1cdd5c4 Fix pr comments 2024-07-14 23:03:01 +08:00
Raminder Singh
e4a9c5ce6e fix clippy warnings 2024-07-14 16:50:54 +05:30
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