final class Explain
    implements Statement
    uses Snapshot
Public API: explicitly declared with @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.

Inspecting a query and reading the report columnsdoctest
$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 $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

Methods§

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

$statementStatementThe explained statement
$formatName|nullThe format name after FORMAT =
$analyzeboolWhether ANALYZE is written
$modifierExplainModifier|nullThe EXTENDED or PARTITIONS keyword of MySQL 5.x
$intoUserVariable|nullThe variable after INTO
$databaseName|nullThe database after FOR DATABASE
Calls 1
public function deriveStatement(Derivation $derivation): void

Inspects the explained statement and records the rows of the report.

Parameters

$derivationDerivation
Calls 5
public function render(Output $out): void

Writes EXPLAIN, the options and the explained statement.

Parameters

$outOutput
Calls 4

Test cases 3§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 3

Relations§

Instantiated in 2
Type checks 1