classExplain
final class Explain
implements Statement
uses Snapshot
@visibility public.EXPLAIN (DESCRIBE, DESC) with a statement: the execution plan of a SELECT, TABLE, VALUES, INSERT, REPLACE, UPDATE or DELETE.
Rule: MYSQL-EXPLAIN-001. The explained statement is inspected, not run: 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 are discarded. FOR DATABASE (8.2 and later) explains it as if that database were the current one: it is derived with that database searched for unqualified names. ANALYZE (8.0.18 and later) runs the statement and reports the measured plan. The rows of the report follow MYSQL-EXPLAIN-ROWS-001. Terminates: the explained statement is a strict subtree. Source: https://dev.mysql.com/doc/refman/8.4/en/explain.html. Status: Implemented.
$explain = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('EXPLAIN FORMAT = TREE SELECT 1');
[$explain->field(0)->name?->value, $explain->toString()] // => ['EXPLAIN', 'EXPLAIN FORMAT = TREE SELECT 1']Properties§
public Statement $statementpublic Name|null $format = nullpublic bool $analyze = falsepublic ExplainModifier|null $modifier = nullpublic UserVariable|null $into = nullpublic Name|null $database = nullMethods§
public function __construct(
public Statement $statement,
public Name|null $format = null,
public bool $analyze = false,
public ExplainModifier|null $modifier = null,
public UserVariable|null $into = null,
public Name|null $database = null,
)Parameters
$statement | Statement | The explained statement |
$format | Name|null | The format name after FORMAT = |
$analyze | bool | Whether ANALYZE is written |
$modifier | ExplainModifier|null | The EXTENDED or PARTITIONS keyword of MySQL 5.x |
$into | UserVariable|null | The variable after INTO |
$database | Name|null | The database after FOR DATABASE |
Calls 1
- static-call Check::input() line 58
public function deriveStatement(Derivation $derivation): voidInspects the explained statement and records the rows of the report.
Parameters
$derivation | Derivation |
Calls 5
- method-call Derivation::inspected() line 67
- new Environment line 67
- new AnalysisContext line 67
- method-call ExplainFacts::derive() line 68
- new ExplainFacts line 68
public function render(Output $out): voidWrites EXPLAIN, the options and the explained statement.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 76
- class-const NameUse::Label() line 84
- class-const NameUse::Qualifier() line 90
- method-call Output::node() line 92
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Relations§
Instantiated in 2
- new SqlSemantics\Platform\MySql\Lowering\Utility\Explain\ExplainRule::legacy() packages/sql-semantics-mysql/src/Lowering/Utility/Explain/ExplainRule.php:154
- new SqlSemantics\Platform\MySql\Lowering\Utility\Explain\ExplainRule::modern() packages/sql-semantics-mysql/src/Lowering/Utility/Explain/ExplainRule.php:171