final class Explain
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

EXPLAIN: a request for the execution plan of a statement.

Rule: PG-EXPLAIN-001. Mirrors PostgreSQL's ExplainStmt (query, options). The older syntax writes ANALYZE and VERBOSE as words in that order. Facts: the explained statement is derived as an inspected request, so every part of it has its facts and diagnostics, but its rows and declarations are not those of EXPLAIN. EXPLAIN returns one column named QUERY PLAN, never NULL, whose type follows the last FORMAT option: xml for XML, json for JSON, text otherwise. Diagnostics: an option EXPLAIN does not know in the release; a value the option cannot take; WAL, TIMING or SERIALIZE without ANALYZE; ANALYZE with GENERIC_PLAN. Termination: the statement is derived once. Source: https://www.postgresql.org/docs/17/sql-explain.html. Status: Implemented.

Reading the row EXPLAIN returnsdoctest
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('EXPLAIN (ANALYZE, FORMAT JSON) SELECT 1');
    [$operation->field(0)->name->value, $operation->field(0)->type->descriptor->name(), $operation->toString()] // => ['QUERY PLAN', 'json', 'EXPLAIN (ANALYZE, FORMAT json) SELECT 1']
Refusing words the old syntax does not havedoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Utility\Maintenance\Explain(
        new \SqlSemantics\Platform\PostgreSql\Statement\Utility\Maintenance\Checkpoint(),
        [new \SqlSemantics\Platform\PostgreSql\Statement\Utility\Maintenance\UtilityOption(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('costs'))],
    ) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public list<UtilityOption> $options
public Statement $statement
public OptionSyntax $syntax = OptionSyntax::Words

Methods§

public function __construct(
    public Statement $statement,
    list<UtilityOption> $options = [],
    public OptionSyntax $syntax = OptionSyntax::Words,
)

Parameters

$statementStatementThe explained statement
$optionslist<UtilityOption>The options in the order written
$syntaxOptionSyntaxHow the options are written
Calls 6
public function deriveStatement(Derivation $derivation): void

Derives the explained statement as an inspected request and records the plan row.

Parameters

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

Writes the request.

Parameters

$outOutput
Calls 4

Test cases 2§

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

Dedicated tests 1
Other tests reaching this symbol 1

Relations§

Instantiated in 4
Type declarations 1