Commit Graph

60 Commits

Author SHA1 Message Date
Jussi Saurio
8e5499e5ed Fix not evaling constant conditions when no tables in query
We were not evaluating constant conditions (e.g '1 IS NULL')
when there were no tables referenced in the query, because
our WHERE term evaluation was based on "during which loop"
to evaluate them. However, when there are no tables, there are
no loops, so they were never evaluated.
2025-02-17 13:10:27 +02:00
Jussi Saurio
447f91e5ee optimizer.rs: remove constant folding optimization for NULL since it's incorrect 2025-02-17 07:43:09 +02:00
Pekka Enberg
ac54c35f92 Switch to workspace dependencies
...makes it easier to specify a version, which is needed for `cargo publish`.
2025-02-12 17:28:04 +02:00
PThorpe92
d4c06545e1 Refactor vtable impl and remove Rc Refcell from module 2025-02-06 09:15:39 -05:00
Jussi Saurio
f5f77c0bd1 Initial virtual table implementation 2025-02-06 07:51:50 -05:00
Jussi Saurio
795576b2ec dont eagerly allocate result column name strings 2025-02-05 17:53:23 +02:00
Jussi Saurio
750a9c6463 assertions and small cleanups 2025-02-03 13:08:13 +02:00
Jussi Saurio
40f536fabb Dont store available_indexes on plan; only used in optimize_plan() 2025-02-03 12:52:14 +02:00
Jussi Saurio
d4cb0a1223 Merge 'Fix logical codegen' from Nikita Sivukhin
Fix few logical codegen issues and add fuzz tests for logical
expressions
-  Right now Limbo fails to recognize `false` constant in case when any
unary operator is used on the AST path. This PR add unary operator
option in the rewrite code and handle such cases properly.
```sql
limbo> SELECT NOT FALSE;

  × Parse error: no such column: FALSE - should this be a string literal in single-quotes?

```
- `ifnull` implementation produced incorrect codegen due to "careless"
management of registers
```
limbo> SELECT ifnull(0, NOT 0)
[NULL here]
```
- `like` implementation produced incorrect codegen due to "careless"
management of registers
```
limbo> SELECT like('a%', 'a') = 1;
thread 'main' panicked at core/vdbe/mod.rs:1902:41:
internal error: entered unreachable code: Like on non-text registers
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
Depends on https://github.com/tursodatabase/limbo/pull/867 (need
`GrammarGenerator` from this branch)

Closes #869
2025-02-03 12:39:41 +02:00
Nikita Sivukhin
a4a80f37bc rewrite unary expressions too - in order to support "NOT FALSE" expressions 2025-02-03 11:25:14 +04:00
Nikita Sivukhin
5a3587f7a2 use opposite operator for search if WHERE condition is swapped (e.g. 1 > x instead of x < 1) 2025-02-03 11:23:04 +04:00
Pekka Enberg
662d629666 Rename JoinAwareConditionExpr to WhereTerm
We transform all JOIN conditions into WHERE clause terms in the query
planner. The JoinAwareConditionExpr name tries to make that point, but I
think it makes things more confusing. Let's call it WhereTerm (suggested
by Jussi).
2025-02-03 07:46:51 +02:00
Jussi Saurio
98439cd936 optimizer.rs: refactor to use new data structures and remove unnecessary stuff
We don't need `push_predicates()` because that never REALLY was a predicate
pushdown optimization -- it just pushed WHERE clause condition expressions
into the correct SourceOperator nodes in the tree.

Now that we don't have a SourceOperator tree anymore and we keep the conditions
in the WHERE clause instead, we don't need to "push" anything anymore. Leaves
room for ACTUAL predicate pushdown optimizations later :)

We also don't need any weird bitmask stuff anymore, and perhaps we never did,
to determine where conditions should be evaluated.
2025-02-02 10:18:13 +02:00
Jussi Saurio
1bcdf99eab core/optimizer: do expression rewriting on all expressions 2025-01-10 10:04:07 +02:00
Jussi Saurio
925bd62cbc fix logic bug in check_index_scan() that swapped lhs/rhs but not the comparison op 2025-01-08 08:20:13 +02:00
Jussi Saurio
4a58898863 Rename eliminate_between to rewrite_exprs and add true/false->1/0 case there 2025-01-08 08:20:13 +02:00
Jussi Saurio
1b61749c0f feat/core/translate: create automatic index in CREATE TABLE when necessary 2025-01-04 13:54:44 +02:00
Jussi Saurio
80b9da95c0 replace termination_label_stack with much simpler LoopLabels 2025-01-01 07:56:39 +02:00
Jussi Saurio
2066475e03 feat: subqueries in FROM clause 2024-12-31 14:18:29 +02:00
Lauri Virtanen
854005b977 Run cargo clippy --fix && cargo fmt 2024-12-29 19:22:28 +02:00
PThorpe92
f6cd707544 Add clippy CI, fix or ignore warnings where appropriate 2024-12-29 10:25:41 -05:00
adamnemecek
97647ff056 Clean up code to use Self
Closes #556
2024-12-29 10:07:38 +02:00
김선우
5cdcb8d78c Split Plan into Select and Delete 2024-12-23 05:45:23 +09:00
김선우
82c127b7a3 Remove bool args in optimize_plan 2024-12-23 04:47:05 +09:00
김선우
1d3ce52812 Refactor planner and optimizer to be DRY 2024-12-22 15:11:26 +09:00
김선우
9a8b94ef93 First successful implementation of delete planning 2024-12-22 13:16:16 +09:00
jussisaurio
82bc9501fd Merge 'feat(optimizer): eliminate between statement' from KaguraMilet
Rewrite `Y BETWEEN X AND Z` as `X <= Y AND Y <= Z`. And due to the
support of this optimization rule, limbo should now be able to execute
the `BETWEEN AND` statement.

Closes #490
2024-12-20 17:23:42 +02:00
KaguraMilet
ef39f11a9f fix(optimizer): process Parenthesized expression 2024-12-20 23:11:17 +08:00
KaguraMilet
1df3189db6 feat(optimizer): support NOT BETWEEN AND with De Morgan's Laws. 2024-12-16 23:28:54 +08:00
KaguraMilet
da781dffa0 feat(optimizer): eliminate between statement 2024-12-16 20:34:25 +08:00
jussisaurio
a04cf611e0 fix bug with making an index search node in a self join where expr refers to other instance of same table 2024-12-14 17:11:32 +02:00
jussisaurio
961e57df94 Fix returning rowid instead of PK when PK is not a rowid alias 2024-12-14 15:51:08 +02:00
jussisaurio
5e9e2dffe9 support TRUE and FALSE in predicates 2024-12-13 22:58:29 +02:00
jussisaurio
fe88d45e5e Add more comments to push_predicate/push_predicates 2024-12-09 17:50:29 +02:00
jussisaurio
52beeabd45 tweaks 2024-11-26 17:31:51 +02:00
jussisaurio
d2f84edd2e fix accidentally removing push_scan_direction() 2024-11-26 17:31:51 +02:00
jussisaurio
7ecc252507 fix rest of the failing tests 2024-11-26 17:31:51 +02:00
jussisaurio
cc902ed25d GROUP BY and ORDER BY mostly work 2024-11-26 17:31:51 +02:00
jussisaurio
3f9e60633f select refactor: order by and basic agg kinda work 2024-11-26 17:31:51 +02:00
jussisaurio
d0466e1cae introduce Column member of ast::Expr and bind idents to columns 2024-11-26 17:31:51 +02:00
limeng.1
1cb1d16c08 resolve comments 2024-11-19 11:39:08 +08:00
limeng.1
8cca659052 impl order by desc 2024-11-19 11:39:07 +08:00
jussisaurio
daf5863932 manual fixes based on clippy suggestions 2024-10-13 12:19:04 +03:00
jussisaurio
f634e7f7a3 clippy fix 2024-10-13 12:08:54 +03:00
jussisaurio
b3c57d5691 core/translate: (refactor) use btreetablereference struct instead of tuple 2024-10-13 11:25:33 +03:00
jussisaurio
04ecbff7fc Eliminate unnecessary ORDER BY if result set is already ordered 2024-10-10 23:43:39 +03:00
jussisaurio
47534cb8df Get rid of Seekrowid operator in favor of a unified Search operator 2024-10-06 00:11:38 +03:00
jussisaurio
d22dbe9840 remove garbage comment 2024-10-05 18:25:04 +03:00
jussisaurio
3a11887122 fixerinos 2024-10-05 18:25:04 +03:00
jussisaurio
e118b70127 fmt 2024-10-05 18:25:04 +03:00