classExplain
final class Explain
implements Statement
uses Snapshot
@visibility public.A request to report how SQLite would run a statement instead of running it.
Rule: SQLITE-EXPLAIN-001. EXPLAIN reports the virtual machine program of the statement, EXPLAIN QUERY PLAN the strategy of its queries; they are two different requests. The wrapped statement is inspected, not executed: every part of it is derived as usual, so its name resolutions and diagnostics are facts of the operation, but the rows it would return and the declaration a wrapped CREATE would provide are discarded. The operation returns the rows of the report (SQLITE-EXPLAIN-ROWS-001) and provides no declaration. Source: https://sqlite.org/lang_explain.html, https://sqlite.org/eqp.html. Status: Implemented.
$explain = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('EXPLAIN QUERY PLAN SELECT 1');
[count($explain->fields()), $explain->field(3)->name?->value, $explain->toString()] // => [4, 'detail', 'EXPLAIN QUERY PLAN SELECT 1']$explain = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('EXPLAIN CREATE TABLE t (a)');
[$explain->declarations(), count($explain->fields())] // => [[], 8]Properties§
public ExplainMode $modepublic Statement $statementMethods§
public function __construct(public ExplainMode $mode, public Statement $statement)Parameters
$mode | ExplainMode | Which report is requested |
$statement | Statement | The statement to report on |
public function deriveStatement(Derivation $derivation): voidInspects the wrapped statement and records the rows of the report as the output.
Parameters
$derivation | Derivation |
Calls 4
- method-call Derivation::inspected() line 51
- method-call Derivation::output() line 52
- method-call ExplainRows::fact() line 52
- new ExplainRows line 52
public function render(Output $out): voidWrites the prefix and the wrapped statement.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 60
- class-const ExplainMode::QueryPlan() line 61
- method-call Output::node() line 64
Test cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Other tests reaching this symbol 2
Relations§
Instantiated in 2
- new SqlSemantics\Platform\Sqlite\Lowering\Definition\DefinitionCommands::explained() packages/sql-semantics-sqlite/src/Lowering/Definition/DefinitionCommands.php:81
- new SqlSemantics\Platform\Sqlite\Lowering\Definition\DefinitionCommands::explained() packages/sql-semantics-sqlite/src/Lowering/Definition/DefinitionCommands.php:82