Commit Graph

67 Commits

Author SHA1 Message Date
김선우
6b40acabbc Add support for sqlite_version() scalar function 2024-09-16 18:38:42 +09:00
JeanArhancet
d03a734f21 feat: add sign function 2024-09-15 14:57:01 +02:00
jussisaurio
b6e88ca883 cargo clippy --fix --allow-dirty && cargo fmt 2024-09-15 09:35:39 +03:00
김선우
fc07ca9d73 Add support for concat_ws 2024-09-14 23:47:45 +09:00
jussisaurio
a108dea825 GROUP BY 2024-09-14 16:14:45 +03:00
jussisaurio
0839211a49 Pass FuncCtx to Insn::Function to keep track of arg count 2024-09-14 12:38:14 +03:00
rjhallsted
dc3d3a492a Fix register positions of binary expression arguments to fix where-like-fn case 2024-09-12 12:03:27 -07:00
rjhallsted
960560dffc Use the same comment for Expr::Like case 2024-09-10 14:26:21 -07:00
rjhallsted
a038d1f700 Add comment on why constant_mask is 1 in ScalarFunc::Like case 2024-09-10 14:24:32 -07:00
rjhallsted
e1b134dd88 Fix the spot that constant_mask was being set to 1 2024-09-10 14:08:15 -07:00
rjhallsted
6ac78dfb03 Cache constructed LIKE regexes if FUNCTION P1 is set 2024-09-10 13:54:52 -07:00
sonhmai
9cc965186f core: support modifiers in date function 2024-09-03 14:28:07 +07:00
Rajiv Harlalka
1de974253b add support for custom date time value as first parameter
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:27:59 +05:30
Rajiv Harlalka
6684fb46e4 FEAT: Implement the unixepoch function
Signed-off-by: Rajiv Harlalka <rajivharlalka009@gmail.com>
2024-08-30 20:27:58 +05:30
Pekka Enberg
596abed93b Merge 'core: support modifiers in time function' from Sonny
this PR is a continue of #252 and #277 to resolve #158.

- supports modifiers in `time(..)` functions

```
limbo> select time('now');
11:35:22

limbo> select time('now', '+2 hours', '-3 hours');
10:35:02

limbo> explain select time('now', '+2 hours', '-3 hours');
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     7     0                    0   Start at 7
1     String8            0     2     0     now            0   r[2]='now'
2     String8            0     3     0     +2 hours       0   r[3]='+2 hours'
3     String8            0     4     0     -3 hours       0   r[4]='-3 hours'
4     Function           1     2     1     time           0   r[1]=func(r[2..])
5     ResultRow          1     1     0                    0   output=r[1]
6     Halt               0     0     0                    0
7     Transaction        0     0     0                    0
8     Goto               0     1     0                    0

```

Closes #305
2024-08-25 13:24:43 +03:00
sonhmai
c32bb91dd5 core: support modifiers in time function 2024-08-24 18:31:34 +07:00
sonhmai
9af811233b core: fix concat function wrong start_register 2024-08-24 16:14:28 +07:00
Kim Seon Woo
8bb2a48cb6 Add support for nullif scalar function 2024-08-20 18:36:06 +02:00
Pekka Enberg
edf0f754f6 Merge 'More structured query planner' from Jussi Saurio
Reader's guide to this PR:

The aim is to have a more structured and maintainable approach to generating bytecode from the query AST so that different parts of the query processing pipeline have clearer responsibilities, so that developing new functionality is easier. E.g.:

- If you want to implement join reordering -> you do it in `Optimizer`
- If you want to implement `GROUP BY` -> you change `QueryPlanNode::Aggregate` to include it, parse it in `Planner` and handle the code generation for it in `Emitter`

The pipeline is:

`SQL text -> Parser -> Planner -> Optimizer -> Emitter`

and this pipeline generates:

`SQL text -> AST -> Logical Plan -> Optimized Logical Plan -> SQLite Bytecode`

---

Module structure:

`plan.rs`: defines the `Operator` enum. An `Operator` is a tree of other `Operators`, e.g. an `Operator::Join` has `left` and `right` children, etc.

`planner.rs`: Parses an `ast::Select` into a `Plan` which is mainly a wrapper for a root `Operator`

`optimizer.rs`: Makes a new `Plan` from an input `Plan` - does predicate pushdown, constant elimination and turns `Scan` nodes into `SeekRowId` nodes where applicable

`emitter.rs`: Generates bytecode instructions from an input `Plan`.

---

Adds feature `EXPLAIN QUERY PLAN <stmt>` which shows the logical query plan instead of the bytecode plan

---

Other changes:

- Almost everything from `select.rs` removed; things like `translate_aggregation()` moved to `expr.rs`
- `where_clause.rs` removed, some things from it like `translate_condition_expr()` moved to `expr.rs`
- i.e.: there is nothing _new_ in `expr.rs`, stuff just moved there

---

Concerns:

- Perf impact: there's a lot more indirection than before (`Operator`s are very "traditional" trees where they refer to other operators via Boxes etc)

Closes #281
2024-08-18 16:36:51 +03:00
jussisaurio
b7fbe57ca7 Move translate_table_columns to expr.rs 2024-08-17 14:16:56 +03:00
JeanArhancet
b6c720c90a feat: add quote function 2024-08-17 09:28:14 +02:00
jussisaurio
17cc3717c8 rebase 2024-08-16 19:43:29 +03:00
jussisaurio
9ab08ee2e6 is_rowid_alias instead of primary_key 2024-08-16 19:42:03 +03:00
jussisaurio
2e32ca0bdb More structured query planner 2024-08-16 19:42:03 +03:00
Kim Seon Woo
48d3c05fb0 Rebase 2024-08-16 21:40:30 +09:00
Pekka Enberg
c9c0d2808c Merge 'Add support for ifnull scalar function' from Kim Seon Woo
Add support for `ifnull` scalar function

### EXPLAIN SELECT ifnull(null, 20);
![image](https://github.com/user-attachments/assets/e367638f-9d70-4dfc-989d-7290b842c2ec)

### Related issue
https://github.com/penberg/limbo/issues/144

Closes #290
2024-08-16 14:37:08 +03:00
Pekka Enberg
ba3acedbc8 Merge 'Add support for substr scalar function' from Kim Seon Woo
Add support for `substr` scalar function. We can reuse the `substring` logic which is already implemted.

## Related issue
https://github.com/penberg/limbo/issues/144

Closes #289
2024-08-16 14:36:55 +03:00
김선우
8fbcd10e0e Add support for ifnull scalar function 2024-08-16 09:25:04 +09:00
김선우
27d9af2bf4 Add support for substr scalar function 2024-08-16 08:26:42 +09:00
김선우
ced664621f Allow char function to have empty args 2024-08-16 06:33:18 +09:00
김선우
77c3d130f3 Add char function support 2024-08-16 06:26:06 +09:00
김선우
28bd0275c0 Run cargo fmt, clippy 2024-08-15 18:56:02 +09:00
김선우
dc48c2e71d Add substring scala function with 2 arg 2024-08-15 18:47:32 +09:00
김선우
3fa3c5c002 Add substr scala function 2024-08-15 18:27:18 +09:00
Vegard Stikbakke
e54fd83f49 Handle FunctionCallStar in analyze_expr 2024-08-11 13:59:49 +02:00
Pekka Enberg
d4d7042373 Merge 'Use the correct integer PK column idx as the row-id alias' from GV
This pull request addresses [issue #256](https://github.com/penberg/limbo/issues/256).

However, it currently breaks insertions into tables that lack a row-id
alias due to the NewRowId not being implemented yet. I have created an
[issue](https://github.com/penberg/limbo/issues/275) to track this
problem and will submit a separate pull request to resolve it soon.

Closes #274
2024-08-06 08:11:10 +03:00
Pekka Enberg
5b7d112e74 Merge 'implementation of json function json(X)' from Jean Arhancet
Add the `json` function `json(X)` (related to the issue https://github.com/penberg/limbo/issues/127)

Closes #230
2024-08-06 08:05:33 +03:00
gandeevanr
2b86f89d8d use the correct integer PK column idx as the row-id alias 2024-08-04 18:53:54 -07:00
JeanArhancet
4050a3ebe2 refactor: impl json5 direclty 2024-08-04 12:47:08 +02:00
JeanArhancet
8dbced6a39 refactor: delete Insn Json 2024-08-04 10:56:51 +02:00
JeanArhancet
552090cb29 feat: add json support 2024-08-04 10:54:27 +02:00
sonhmai
0e7bd95e4e core: fix clippy 2024-08-03 20:14:26 +07:00
sonhmai
789ae4becf feat: add time() scalar function partial support without modifier #158 2024-08-01 13:06:07 +07:00
Pere Diaz Bou
84bf0ea96a core: remove a bunch of warnings
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-31 17:27:02 +02:00
Pere Diaz Bou
affe3443cc core: vbde coroutine generation with rowid insert 2024-07-31 17:25:01 +02:00
macroexpansion
918b99b7a3 feat: add RTRIM(X) and RTRIM(X,Y) scalar function 2024-07-28 21:17:53 +07:00
Jussi Saurio
9a50d53fcb Merge pull request #244 from penberg/fold-columns
core: Fold columns into column_info in Select struct
2024-07-28 10:50:57 +03:00
Pekka Enberg
93d88d6cca core: Fold columns into column_info in Select struct
As a cleanup, fold the columns struct member into column_info by
introducing a `raw_column` in `ColumnInfo` struct.
2024-07-28 10:01:48 +03:00
macroexpansion
750f18be35 feat: add ltrim scalar function 2024-07-27 19:46:27 +07:00
Pekka Enberg
ec6f0224ef Merge pull request #224 from ethanniser/add-unicode 2024-07-25 20:37:39 +03:00