docs: Fold typical_query.md to internals.md

This commit is contained in:
Pekka Enberg 2025-02-10 11:15:57 +02:00
parent c24be74496
commit b7933a956f
2 changed files with 43 additions and 40 deletions

View file

@ -39,9 +39,48 @@ interface to parse the statement and generate a bytecode program, a step
called preparing a statement. When a statement is prepared, it can be executed
using the `sqlite3_step()` function.
To inspect the bytecode program for a SQL statement, you can use the
`EXPLAIN` command in the shell. For our example SQL statement, the bytecode
looks as follows:
To illustrate the different components of Limbo, we can look at the sequence
diagram of a query from the CLI to the bytecode virtual machine (VDBE):
```mermaid
sequenceDiagram
participant main as cli/main
participant Database as core/lib/Database
participant Connection as core/lib/Connection
participant Parser as sql/mod/Parser
participant translate as translate/mod
participant Statement as core/lib/Statement
participant Program as vdbe/mod/Program
main->>Database: open_file
Database->>main: Connection
main->>Connection: query(sql)
Note left of Parser: Parser uses vendored sqlite3-parser
Connection->>Parser: next()
Note left of Parser: Passes the SQL query to Parser
Parser->>Connection: Cmd::Stmt (ast/mod.rs)
Note right of translate: Translates SQL statement into bytecode
Connection->>translate:translate(stmt)
translate->>Connection: Program
Connection->>main: Ok(Some(Rows { Statement }))
note right of main: a Statement with <br />a reference to Program is returned
main->>Statement: step()
Statement->>Program: step()
Note left of Program: Program executes bytecode instructions<br />See https://www.sqlite.org/opcode.html
Program->>Statement: StepResult
Statement->>main: StepResult
```
To drill down into more specifics, we inspect the bytecode program for a SQL
statement using the `EXPLAIN` command in the shell. For our example SQL
statement, the bytecode looks as follows:
```
limbo> EXPLAIN SELECT 'hello, world';
@ -67,6 +106,7 @@ constant `'hello, world'` to register `r[1]`. The `ResultRow` instruction
produces a SQL query result using contents of `r[1]`. Finally, the
program terminates with the `Halt` instruction.
## Frontend
### Parser

View file

@ -1,37 +0,0 @@
The following sequence diagram shows the typical flow of a query from the CLI to the [VDBE](https://www.sqlite.org/opcode.html).
```mermaid
sequenceDiagram
participant main as cli/main
participant Database as core/lib/Database
participant Connection as core/lib/Connection
participant Parser as sql/mod/Parser
participant translate as translate/mod
participant Statement as core/lib/Statement
participant Program as vdbe/mod/Program
main->>Database: open_file
Database->>main: Connection
main->>Connection: query(sql)
Note left of Parser: Parser uses vendored sqlite3-parser
Connection->>Parser: next()
Note left of Parser: Passes the SQL query to Parser
Parser->>Connection: Cmd::Stmt (ast/mod.rs)
Note right of translate: Translates SQL statement into bytecode
Connection->>translate:translate(stmt)
translate->>Connection: Program
Connection->>main: Ok(Some(Rows { Statement }))
note right of main: a Statement with <br />a reference to Program is returned
main->>Statement: step()
Statement->>Program: step()
Note left of Program: Program executes bytecode instructions<br />See https://www.sqlite.org/opcode.html
Program->>Statement: StepResult
Statement->>main: StepResult
```