Files
turso/testing
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
..
2024-08-03 12:16:34 +03:00
2024-07-16 07:20:35 +03:00
2024-08-16 19:42:03 +03:00
2024-08-04 12:47:08 +02:00
2024-07-16 07:24:28 +03:00
2024-08-17 09:28:14 +02:00