diff --git a/docs/internals.md b/docs/internals.md index 37838959..fe35fa52 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -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
a reference to Program is returned + +main->>Statement: step() +Statement->>Program: step() +Note left of Program: Program executes bytecode instructions
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 diff --git a/docs/internals/typical_query.md b/docs/internals/typical_query.md deleted file mode 100644 index d4d1c841..00000000 --- a/docs/internals/typical_query.md +++ /dev/null @@ -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
a reference to Program is returned - -main->>Statement: step() -Statement->>Program: step() -Note left of Program: Program executes bytecode instructions
See https://www.sqlite.org/opcode.html -Program->>Statement: StepResult -Statement->>main: StepResult -```