Commit Graph

24 Commits

Author SHA1 Message Date
Pekka Enberg
5fbcdbb424 Fix SELECT .. LIMIT not respecting the limit
Fix the codegen to emit DecrJumpZero in the right place.
2024-06-30 19:11:45 +03:00
Pere Diaz Bou
123f6353f7 core: rename ColumnAggregationInfo -> ColumnInfo
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-06-30 12:48:19 +02:00
Pere Diaz Bou
1cd6101b44 core: add some comments explaining analyze_column
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-06-30 12:48:19 +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
4d8e0f1214 core: Clean up translate.rs by moving update_pragma()
Makes the code flow read better from top to bottom.
2024-06-28 08:44:27 +03: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
Pekka Enberg
6290c8167d Unify SELECT .. LIMIT handling in translate_select()
Working towards a saner translate_select(), let's unify `SELECT ..
LIMIT` handling across different types of select statements.
2024-06-24 21:36:34 +03:00
Pekka Enberg
bdbbbda84f Extract translate_column() function 2024-06-22 09:44:35 +03:00
Pekka Enberg
828fb813a8 core: Fix codegen for rowid alias
We should emit `Column` bytecode for a primary key, unless it is an alias for a rowid.
2024-06-21 13:10:21 +03:00
Pere Diaz Bou
932ae7bf3f core: update pragma in transalte 2024-06-19 20:37:17 +02:00
Pere Diaz Bou
53c348402a core: parse unary and write to disk 2024-06-19 20:37:15 +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
Pekka Enberg
3afc03cc65 Fix String8 opcode handling 2024-05-08 15:51:10 -03:00
Pekka Enberg
08165fc34e core: SELECT <string> support 2024-05-08 07:18:22 -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
454b1047ce Simplify translate_select() 2024-03-29 09:22:02 +02:00
Pekka Enberg
a9eb6918d3 SELECT expression support 2024-03-28 19:41:21 +02:00
Pekka Enberg
3f17ac0e17 Simplify code 2024-03-28 19:32:38 +02:00
Pekka Enberg
2c55cc797d cargo clippy --fix 2024-01-28 10:21:38 +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
f6cbd9cd6c Eliminate unused variables 2023-09-10 12:39:30 +03:00
Pekka Enberg
e38c816ee8 Move translate() into its own file 2023-09-10 12:37:17 +03:00