classExplain
final class Explain
implements Statement
uses Snapshot
@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.
$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']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\InvalidConstructionProperties§
public list<UtilityOption> $optionspublic Statement $statementpublic OptionSyntax $syntax = OptionSyntax::WordsMethods§
public function __construct(
public Statement $statement,
list<UtilityOption> $options = [],
public OptionSyntax $syntax = OptionSyntax::Words,
)Parameters
$statement | Statement | The explained statement |
$options | list<UtilityOption> | The options in the order written |
$syntax | OptionSyntax | How the options are written |
Calls 6
- class-const OptionSyntax::Words() line 54
- static-call Check::listOf() line 56
- class-const UtilityOption::class() line 56
- static-call Check::input() line 57
- method-call OptionRules::writable() line 57
- new OptionRules line 57
public function deriveStatement(Derivation $derivation): voidDerives the explained statement as an inspected request and records the plan row.
Parameters
$derivation | Derivation |
Calls 7
- method-call OptionRules::derive() line 65
- new OptionRules line 65
- new ExplainFacts line 66
- method-call ExplainFacts::checks() line 67
- method-call Derivation::inspected() line 68
- method-call Derivation::output() line 69
- method-call ExplainFacts::rows() line 69
public function render(Output $out): voidWrites the request.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 77
- method-call OptionRules::write() line 78
- new OptionRules line 78
- method-call Output::node() line 79
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
ExplainTestcalls
Other tests reaching this symbol 1
Relations§
Instantiated in 4
- new SqlSemantics\Platform\PostgreSql\Lowering\Utility\MaintenanceRule::explain() packages/sql-semantics-postgres/src/Lowering/Utility/MaintenanceRule.php:127
- new SqlSemantics\Platform\PostgreSql\Lowering\Utility\MaintenanceRule::explain() packages/sql-semantics-postgres/src/Lowering/Utility/MaintenanceRule.php:128
- new SqlSemantics\Platform\PostgreSql\Lowering\Utility\MaintenanceRule::explain() packages/sql-semantics-postgres/src/Lowering/Utility/MaintenanceRule.php:129
- new SqlSemantics\Platform\PostgreSql\Lowering\Utility\MaintenanceRule::explain() packages/sql-semantics-postgres/src/Lowering/Utility/MaintenanceRule.php:130